From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 4909843045 for ; Wed, 16 Nov 2022 11:43:23 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1086F68BCBE; Wed, 16 Nov 2022 13:43:20 +0200 (EET) 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-Google-Smtp-Source: AA0mqf6XO7EhTpwvybpjT8t+6wxpC/fd+VJja+yBgmeTdd42pT+9Dqc9QDtmGgaswMBonqryOb/e3A== 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 -- 2.38.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".