]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pnm.c
Support 64bit pam decoding.
[ffmpeg] / libavcodec / pnm.c
index dfc18d6013858771b674f809211f9e4497fbd0c9..212ec06c21b0756e9d600e84c71bcf2c8b319575 100644 (file)
@@ -93,7 +93,9 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
             } else if (!strcmp(buf1, "MAXVAL")) {
                 pnm_get(s, buf1, sizeof(buf1));
                 maxval = strtol(buf1, NULL, 10);
-            } else if (!strcmp(buf1, "TUPLETYPE")) {
+            } else if (!strcmp(buf1, "TUPLTYPE") ||
+            // FFmpeg used to write invalid files
+                       !strcmp(buf1, "TUPLETYPE")) {
                 pnm_get(s, tuple_type, sizeof(tuple_type));
             } else if (!strcmp(buf1, "ENDHDR")) {
                 break;
@@ -107,21 +109,30 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
 
         avctx->width  = w;
         avctx->height = h;
+        s->maxval     = maxval;
         if (depth == 1) {
-            if (maxval == 1)
+            if (maxval == 1) {
                 avctx->pix_fmt = PIX_FMT_MONOWHITE;
-            else
+            } else if (maxval == 255) {
                 avctx->pix_fmt = PIX_FMT_GRAY8;
+            } else {
+                avctx->pix_fmt = PIX_FMT_GRAY16BE;
+            }
+        } else if (depth == 2) {
+            if (maxval == 255)
+                avctx->pix_fmt = PIX_FMT_GRAY8A;
         } else if (depth == 3) {
             if (maxval < 256) {
             avctx->pix_fmt = PIX_FMT_RGB24;
             } else {
-                av_log(avctx, AV_LOG_ERROR, "16-bit components are only supported for grayscale\n");
-                avctx->pix_fmt = PIX_FMT_NONE;
-                return -1;
+                avctx->pix_fmt = PIX_FMT_RGB48BE;
             }
         } else if (depth == 4) {
-            avctx->pix_fmt = PIX_FMT_RGB32;
+            if (maxval < 256) {
+                avctx->pix_fmt = PIX_FMT_RGB32;
+            } else {
+                avctx->pix_fmt = PIX_FMT_RGBA64BE;
+            }
         } else {
             return -1;
         }