From patchwork Thu Feb 11 22:41:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 25594 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5E2AB44A361 for ; Fri, 12 Feb 2021 01:09:23 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2F4DE68ABFE; Fri, 12 Feb 2021 01:09:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 078B068AB98 for ; Fri, 12 Feb 2021 01:09:17 +0200 (EET) Received: by mail-pj1-f50.google.com with SMTP id d2so4319578pjs.4 for ; Thu, 11 Feb 2021 15:09:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=38jC84HLW8ZquD46z0FvDo17BKwvuOJp6BxBz92wgHo=; b=u2oeiWC6GFysbN9/GARMNFQyDldyWYCxUwGk0tK/9ERaUOx/XdxB8Tr/ZuKwuUvzXi gPxJghgaTZ2dz7CN6DK5ELN2yjY53LFyoX4V6p2Ts+6AZfP7hdiYkqEeiekb0BODlaZ4 aVvKVB/GyxLBWPCd2k4hmmdO5gzVf/nOHVqskv9WvkLcmmuYdnBccRPgKIogEI7FmEjw tsob5yhAfbMuMm/oztcwhzM1xur0qlaa8U+bUrPqtKHDZVXMWYUsGHTULOTI2aUeLMgD gY1hjR88cdW87FhzbIFPwpvY5zq2o6gPk2SCsGLOURLN1l+gJTCZr4c1R9l3R0ccqkWI ZQMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=38jC84HLW8ZquD46z0FvDo17BKwvuOJp6BxBz92wgHo=; b=QMAQvorXfVV450VXRzM6Y8t0BAlo43Y9ewgMavCOPGIe3DYYworxW92BQ/P3L2ikxH iXtUJBKd5pF1ZV0h9CC9qS5+hN9t9oqKoVvigc1KyYt4PhHRPHWg8/0YnV50VPOiVUnf 3YPN0XczKExrv2+GGsEJldK+2MDcj8fD4ndvXgzvI+tkz4xfmS3PIC94trD+/T2Aemov s54TYfd90fYiPRUxC3te6hBGgojMRj88B8z1s86A+U3UJTX/lLL4IDeotbiOUHOB2TiW d96BYn+UribnYcpPacnM/JcscAirVw5cKbBTHHQygqrFvTIKeKwWnLclPspyKWt5Jd0w Ytbw== X-Gm-Message-State: AOAM531kE9Oz+8rtygT8Xk1nakMzBh8sLG1illXUWUSFiXA5wBfbkfPd 1ocPaAvcark/5L4SBRW/Km4AZoiT5hgBOBlpOtgX/hvJFfw= X-Google-Smtp-Source: ABdhPJz/RwpVtnhcZ2rv29eoX7cgyme5KD0kwitpNWK4pCIUUbvcUpEEy7fJP80X8LNWvU/00czlVdZpwASn7zH2o7U= X-Received: by 2002:a17:902:7b96:b029:de:7ae6:b8db with SMTP id w22-20020a1709027b96b02900de7ae6b8dbmr121742pll.0.1613083286872; Thu, 11 Feb 2021 14:41:26 -0800 (PST) MIME-Version: 1.0 From: Carl Eugen Hoyos Date: Thu, 11 Feb 2021 23:41:15 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH]lavc/pnm: Support decoding gray float pbm images. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi! Attached patch allows to decode gray float pbm images, sample by ami_stuff. Please comment, Carl Eugen Subject: [PATCH] lavc/pnm: Allow decoding of gray float pbm images. --- libavcodec/pnm.c | 5 ++++- libavcodec/pnmdec.c | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c index aad23c7ae2..5af04965e7 100644 --- a/libavcodec/pnm.c +++ b/libavcodec/pnm.c @@ -72,6 +72,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) s->bytestream[0] != 'P' || (s->bytestream[1] < '1' || s->bytestream[1] > '7' && + s->bytestream[1] != 'f' && s->bytestream[1] != 'F')) { s->bytestream += s->bytestream_end > s->bytestream; s->bytestream += s->bytestream_end > s->bytestream; @@ -82,6 +83,8 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) if (buf1[1] == 'F') { avctx->pix_fmt = AV_PIX_FMT_GBRPF32; + } else if (buf1[1] == 'f') { + avctx->pix_fmt = AV_PIX_FMT_GRAYF32; } else if (s->type==1 || s->type==4) { avctx->pix_fmt = AV_PIX_FMT_MONOWHITE; } else if (s->type==2 || s->type==5) { @@ -177,7 +180,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) if (ret < 0) return ret; - if (avctx->pix_fmt == AV_PIX_FMT_GBRPF32) { + if (avctx->pix_fmt == AV_PIX_FMT_GBRPF32 || avctx->pix_fmt == AV_PIX_FMT_GRAYF32) { pnm_get(s, buf1, sizeof(buf1)); if (av_sscanf(buf1, "%f", &s->scale) != 1 || s->scale == 0.0 || !isfinite(s->scale)) { av_log(avctx, AV_LOG_ERROR, "Invalid scale.\n"); diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index 9add5cfc84..4d5ce0bcb5 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -297,6 +297,30 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, } } break; + case AV_PIX_FMT_GRAYF32: + if (avctx->width * avctx->height * 4 > s->bytestream_end - s->bytestream) + return AVERROR_INVALIDDATA; + scale = 1.f / s->scale; + if (s->endian) { + float *g = (float *)p->data[0]; + for (int i = 0; i < avctx->height; i++) { + for (int j = 0; j < avctx->width; j++) { + g[j] = av_int2float(AV_RL32(s->bytestream)) * scale; + s->bytestream += 4; + } + g += p->linesize[0] / 4; + } + } else { + float *g = (float *)p->data[0]; + for (int i = 0; i < avctx->height; i++) { + for (int j = 0; j < avctx->width; j++) { + g[j] = av_int2float(AV_RB32(s->bytestream)) * scale; + s->bytestream += 4; + } + g += p->linesize[0] / 4; + } + } + break; } *got_frame = 1;