[FFmpeg-devel] [PATCH]Support more pnm files

Carl Eugen Hoyos cehoyos at ag.or.at
Mon Jul 29 00:49:44 CEST 2013


Hi!

Attached patch fixes the sample from ticket #1897 for me.

Please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c
index 3fa4d7c..91a214c 100644
--- a/libavcodec/pnm.c
+++ b/libavcodec/pnm.c
@@ -129,12 +129,16 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
         } else if (depth == 3) {
             if (maxval < 256) {
                 avctx->pix_fmt = AV_PIX_FMT_RGB24;
+            } else if (maxval < 65535) {
+                avctx->pix_fmt = AV_PIX_FMT_RGB48;
             } else {
                 avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
             }
         } else if (depth == 4) {
             if (maxval < 256) {
                 avctx->pix_fmt = AV_PIX_FMT_RGBA;
+            } else if (maxval < 65535) {
+                avctx->pix_fmt = AV_PIX_FMT_RGBA64;
             } else {
                 avctx->pix_fmt = AV_PIX_FMT_RGBA64BE;
             }
@@ -169,6 +173,8 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
                     avctx->pix_fmt = AV_PIX_FMT_GRAY16;
             } else if (avctx->pix_fmt == AV_PIX_FMT_RGB24) {
                 avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
+                if (s->maxval != 65535)
+                    avctx->pix_fmt = AV_PIX_FMT_RGB48;
             } else if (avctx->pix_fmt == AV_PIX_FMT_YUV420P && s->maxval < 65536) {
                 if (s->maxval < 512)
                     avctx->pix_fmt = AV_PIX_FMT_YUV420P9BE;
diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c
index d0c7295..ef0f50d 100644
--- a/libavcodec/pnmdec.c
+++ b/libavcodec/pnmdec.c
@@ -52,14 +52,20 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
     default:
         return AVERROR(EINVAL);
     case AV_PIX_FMT_RGBA64BE:
+    case AV_PIX_FMT_RGBA64LE:
         n = avctx->width * 8;
         components=4;
         sample_len=16;
+        if (s->maxval < 65535)
+            upgrade = 2;
         goto do_read;
     case AV_PIX_FMT_RGB48BE:
+    case AV_PIX_FMT_RGB48LE:
         n = avctx->width * 6;
         components=3;
         sample_len=16;
+        if (s->maxval < 65535)
+            upgrade = 2;
         goto do_read;
     case AV_PIX_FMT_RGBA:
         n = avctx->width * 4;
@@ -70,6 +76,8 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
         n = avctx->width * 3;
         components=3;
         sample_len=8;
+        if (s->maxval < 255)
+            upgrade = 1;
         goto do_read;
     case AV_PIX_FMT_GRAY8:
         n = avctx->width;


More information about the ffmpeg-devel mailing list