X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fpnm.c;h=fa43c8d6e96150d05a91f30bed769a49bd66f049;hb=bd36ec55bef7c446079e192655d065fd86483876;hp=dfc18d6013858771b674f809211f9e4497fbd0c9;hpb=7876f14f8be9d78de1875ff38390d2a37ac86ec3;p=ffmpeg diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c index dfc18d60138..fa43c8d6e96 100644 --- a/libavcodec/pnm.c +++ b/libavcodec/pnm.c @@ -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,28 @@ 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 == 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 { + av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth\n"); + return -1; + } } else { return -1; }