From patchwork Wed Nov 16 11:43:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 39296 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp351525pzb; Wed, 16 Nov 2022 03:43:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf4NMqG+/6XMst4+uqzt7thFrtmu1jd4g7tBxYnjUz1NsKpxtfxnNhgUtWjjQVkkGysr6K2S X-Received: by 2002:a05:6402:4027:b0:467:f643:5860 with SMTP id d39-20020a056402402700b00467f6435860mr9770968eda.326.1668599004726; Wed, 16 Nov 2022 03:43:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668599004; cv=none; d=google.com; s=arc-20160816; b=iOWkwHleywy/q6Ny7T2j4BGNGOZLijd/W7DncIasDZyUhlUpTB5yIx0A3BXH00uO3V HvAR6Ui2q7kQeWr72EDwkqzizj5XRhf0pFKXis3hPgXjP/eLv8teKYGx+j9qiRe8erik mPUXNs4ec66b08tLdYO9Fw/ZOwwomt1tJv3Oz0d8gjZJ3+ILBpscPJpwV8L5IiBxbc7c 4LWvk5kuifXACVfk4/8XvpheM6pJIJPKF8PvZAewVmwltKgZcSsO5JhCSh2WDpK1fXKI f5pj754/dmABihKognegIXMRBLN+kVc64kkgnqyGRolfvbrTeoQdi95pe0z/xxJYK7By Ve8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=IsgpbYzyl8NuPJDu7+xWI2cY2s6XxIT/A5xgAzMMBXk=; b=umtsDMyeCjzH4/eLgbH/UoIM/Z14cgxn9bRsrrDYWQhxrLBToLHnTaEV7QSIx0vZV6 lu5GOINxSDyOXns3cEEVl7ol+rnXqwpPZBaTq9pOwUef8NVJ725lAWuWkCAXbmSOpNW/ cNw7uFgYRILK3Nns8s1wCFC9YYh2N4XLsoQX0X8D74RrsrI6mE3OSZm2lnGcxZeZWvPL IOtcKeY+rMfwmyHR98IiSFznHjvcYAY4/42SXcZ9BRN+cz2EGkHyXj4wxG+/+Ey22Rq1 rKPEsNjJaoOwqlJrdc+eHoeYokZb5YKM07BkYV5wTbT9BfpFUOHAfQtb8ptlG9247I97 Yc0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=e8gF9dZ3; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id kl14-20020a170907994e00b007829f6fed9dsi11660374ejc.232.2022.11.16.03.43.23; Wed, 16 Nov 2022 03:43:24 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=e8gF9dZ3; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4BD9C68BCC1; Wed, 16 Nov 2022 13:43:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 88E7D68BA9D for ; Wed, 16 Nov 2022 13:43:13 +0200 (EET) Received: by mail-io1-f53.google.com with SMTP id b2so12944654iof.12 for ; Wed, 16 Nov 2022 03:43:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Gb3MMkpWDItMmbZKI1gB8+VLi1WMMrmgbHxCPWXetho=; b=e8gF9dZ3zCWL/aK4cmkupRqoMBCuMyN1fYfbxJOAkoBtfZyyJYk5dK6PI83iDg3Qfo PLaCLdtN80RMkYO9cxa8TFWpdaH7GYepIFSuUsCdSBE4mf5UOMUsuBJVgKwgFqCYPl8k lMvFZPSiD49ndDDFZtG77m1Bt8Rq1qzi1/2YTsj0+UW7aiSeHhUDJLFY5h/O/HjXHOE7 tcahDux0tLRZCYZVRnjPH3kv86fo0v3DXuNp+bZBr/izew8ZYoiNj6cHhMeVaLSaNvR5 hNY1IcvWEtI9yO/9kBZgX+7h8/T0ooou+D6ywPnAP1i0MD3Kx7HulzH+qHgNdAYGkjeT pgUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Gb3MMkpWDItMmbZKI1gB8+VLi1WMMrmgbHxCPWXetho=; b=DZ3rzHbr1X025IDaKmgTob2RfqYd5z/mkuqhe8EvbRy03OXtbw4nh33uYqrhrl7qgc 0sE6CENejnLb+QIACa9vuLBSCt7q5W+JNTNEd+fjF0D1mGIFL+xUHQbTI+DRyMEF8nVd 94CLoKCA6FOFSAxq8yR/5CYoKp8xZ8qb5lcEpbb6PydMrDsYg6ft9vMMQuIqBxkj7CsO 8/hBnZZN4swiixMjxpPd+Q5mzkJ8k1LH4IBI8+8ZeAzOd1vEaL17vZxgwIkBumnNP4hf WM/BYYBQMiq8UxpnGMIVNmezO0TxrcnR1PkJ4BXPozkI27e5qESxm8lKoa/luyLyUGFu mjBg== X-Gm-Message-State: ANoB5pnTx2wGzGLIpohCK/ASdD+dfIT4fmn4B2IDkVBgn691UsAbxYLa hA7KxLJZhQ4pHK/bCIF8+H8Hhpok+Gc= X-Received: by 2002:a5e:8618:0:b0:6c3:6e0:6a7a with SMTP id z24-20020a5e8618000000b006c306e06a7amr9304677ioj.161.1668598991074; Wed, 16 Nov 2022 03:43:11 -0800 (PST) Received: from gauss.local (c-68-41-54-207.hsd1.mi.comcast.net. [68.41.54.207]) by smtp.gmail.com with ESMTPSA id z15-20020a027a4f000000b00370c2b787a9sm5707480jad.168.2022.11.16.03.43.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Nov 2022 03:43:10 -0800 (PST) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Wed, 16 Nov 2022 06:43:06 -0500 Message-Id: <20221116114306.251999-1-leo.izen@gmail.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/pnm: avoid mirroring PFM images vertically X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Leo Izen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 0rW6v8w6tn/z PFM (aka Portable FloatMap) encodes its scanlines from bottom-to-top, not from top-to-bottom, unlike other NetPBM formats. Without this patch, FFmpeg ignores this exception and decodes/encodes PFM images mirrored vertically from their proper orientation. For reference, see the NetPBM tool pfmtopam, which encodes a .pam from a .pfm, using the correct orientation (and which FFmpeg reads correctly). Also compare ffplay to magick display, which shows the correct orientation as well. See: http://www.pauldebevec.com/Research/HDR/PFM/ and see: https://netpbm.sourceforge.net/doc/pfm.html for descriptions of this image format. Signed-off-by: Leo Izen --- libavcodec/pnmdec.c | 10 ++++++++++ libavcodec/pnmenc.c | 18 ++++++++++-------- tests/ref/lavf/gbrpf32be.pfm | 2 +- tests/ref/lavf/gbrpf32le.pfm | 2 +- tests/ref/lavf/grayf32be.pfm | 2 +- tests/ref/lavf/grayf32le.pfm | 2 +- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index e95b4072eb..978e4c037e 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -346,6 +346,13 @@ static int pnm_decode_frame(AVCodecContext *avctx, AVFrame *p, } } } + /* PFM is encoded from bottom to top */ + p->data[0] += (avctx->height - 1) * p->linesize[0]; + p->data[1] += (avctx->height - 1) * p->linesize[1]; + p->data[2] += (avctx->height - 1) * p->linesize[2]; + p->linesize[0] = -p->linesize[0]; + p->linesize[1] = -p->linesize[1]; + p->linesize[2] = -p->linesize[2]; break; case AV_PIX_FMT_GRAYF32: if (!s->half) { @@ -395,6 +402,9 @@ static int pnm_decode_frame(AVCodecContext *avctx, AVFrame *p, } } } + /* PFM is encoded from bottom to top */ + p->data[0] += (avctx->height - 1) * p->linesize[0]; + p->linesize[0] = -p->linesize[0]; break; } *got_frame = 1; diff --git a/libavcodec/pnmenc.c b/libavcodec/pnmenc.c index 9eb663306d..5fa1f52e1e 100644 --- a/libavcodec/pnmenc.c +++ b/libavcodec/pnmenc.c @@ -133,9 +133,10 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, if ((avctx->pix_fmt == AV_PIX_FMT_GBRPF32LE || avctx->pix_fmt == AV_PIX_FMT_GBRPF32BE) && c == 'F') { - const float *r = (const float *)p->data[2]; - const float *g = (const float *)p->data[0]; - const float *b = (const float *)p->data[1]; + /* PFM is encoded from bottom to top */ + const float *r = (const float *)(p->data[2] + p->linesize[2] * (avctx->height - 1)); + const float *g = (const float *)(p->data[0] + p->linesize[0] * (avctx->height - 1)); + const float *b = (const float *)(p->data[1] + p->linesize[1] * (avctx->height - 1)); for (int i = 0; i < avctx->height; i++) { for (int j = 0; j < avctx->width; j++) { @@ -145,13 +146,14 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, bytestream += 12; } - r += p->linesize[2] / 4; - g += p->linesize[0] / 4; - b += p->linesize[1] / 4; + r -= p->linesize[2] / 4; + g -= p->linesize[0] / 4; + b -= p->linesize[1] / 4; } } else if ((avctx->pix_fmt == AV_PIX_FMT_GRAYF32LE || avctx->pix_fmt == AV_PIX_FMT_GRAYF32BE) && c == 'f') { - const float *g = (const float *)p->data[0]; + /* PFM is encoded from bottom to top */ + const float *g = (const float *)(p->data[0] + p->linesize[0] * (avctx->height - 1)); for (int i = 0; i < avctx->height; i++) { for (int j = 0; j < avctx->width; j++) { @@ -159,7 +161,7 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, bytestream += 4; } - g += p->linesize[0] / 4; + g -= p->linesize[0] / 4; } } else if (avctx->pix_fmt == AV_PIX_FMT_GBRPF32 && c == 'H') { const float *r = (const float *)p->data[2]; diff --git a/tests/ref/lavf/gbrpf32be.pfm b/tests/ref/lavf/gbrpf32be.pfm index ca5e1b1659..aa8d098838 100644 --- a/tests/ref/lavf/gbrpf32be.pfm +++ b/tests/ref/lavf/gbrpf32be.pfm @@ -1,3 +1,3 @@ -6d470f8d6018b95b45afafc14b7d161a *tests/data/images/gbrpf32be.pfm/02.gbrpf32be.pfm +4ac5ecc53ff2ca0c9360031ea4c13236 *tests/data/images/gbrpf32be.pfm/02.gbrpf32be.pfm 1216532 tests/data/images/gbrpf32be.pfm/02.gbrpf32be.pfm tests/data/images/gbrpf32be.pfm/%02d.gbrpf32be.pfm CRC=0x4b73053f diff --git a/tests/ref/lavf/gbrpf32le.pfm b/tests/ref/lavf/gbrpf32le.pfm index b3947a9fcb..fb9f90e883 100644 --- a/tests/ref/lavf/gbrpf32le.pfm +++ b/tests/ref/lavf/gbrpf32le.pfm @@ -1,3 +1,3 @@ -892c5a05e1cbb3d2f7761d51e18b9c4c *tests/data/images/gbrpf32le.pfm/02.gbrpf32le.pfm +887bd04126ce36509578c51e692f3d62 *tests/data/images/gbrpf32le.pfm/02.gbrpf32le.pfm 1216533 tests/data/images/gbrpf32le.pfm/02.gbrpf32le.pfm tests/data/images/gbrpf32le.pfm/%02d.gbrpf32le.pfm CRC=0x95e1053f diff --git a/tests/ref/lavf/grayf32be.pfm b/tests/ref/lavf/grayf32be.pfm index 19a2ca85b6..3ce4ad5133 100644 --- a/tests/ref/lavf/grayf32be.pfm +++ b/tests/ref/lavf/grayf32be.pfm @@ -1,3 +1,3 @@ -0f6df0d68d7dd30e67386b1255f443c9 *tests/data/images/grayf32be.pfm/02.grayf32be.pfm +d2c3a37f7bf52be25f3f56239b5fdd92 *tests/data/images/grayf32be.pfm/02.grayf32be.pfm 405524 tests/data/images/grayf32be.pfm/02.grayf32be.pfm tests/data/images/grayf32be.pfm/%02d.grayf32be.pfm CRC=0xe3fda443 diff --git a/tests/ref/lavf/grayf32le.pfm b/tests/ref/lavf/grayf32le.pfm index aba861ec72..3a883ad2ac 100644 --- a/tests/ref/lavf/grayf32le.pfm +++ b/tests/ref/lavf/grayf32le.pfm @@ -1,3 +1,3 @@ -145715872a894b1fde0105d8a0106191 *tests/data/images/grayf32le.pfm/02.grayf32le.pfm +ea7aad8650d06c7cc8c80cc57cbac672 *tests/data/images/grayf32le.pfm/02.grayf32le.pfm 405525 tests/data/images/grayf32le.pfm/02.grayf32le.pfm tests/data/images/grayf32le.pfm/%02d.grayf32le.pfm CRC=0x5443a443