diff options
author | Leo Izen <leo.izen@gmail.com> | 2022-11-16 06:43:06 -0500 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2022-12-27 10:41:25 -0300 |
commit | cd9dd0300639689630171893b3dfb6c9ba63a692 (patch) | |
tree | 6bb3415330e46f9825f685781406f547efad7352 /libavcodec/pnmenc.c | |
parent | 64007595dcb5bb3c5f7bfa74d0b0f2e378f6007e (diff) | |
download | ffmpeg-cd9dd0300639689630171893b3dfb6c9ba63a692.tar.gz |
avcodec/pnm: avoid mirroring PFM images vertically
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 <leo.izen@gmail.com>
Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/pnmenc.c')
-rw-r--r-- | libavcodec/pnmenc.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/libavcodec/pnmenc.c b/libavcodec/pnmenc.c index c998dd410c..4bdd2e032f 100644 --- a/libavcodec/pnmenc.c +++ b/libavcodec/pnmenc.c @@ -136,9 +136,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++) { @@ -148,13 +149,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++) { @@ -162,7 +164,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]; |