diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c index 3fa4d7c95b..63b77cd807 100644 --- a/libavcodec/pnm.c +++ b/libavcodec/pnm.c @@ -118,10 +118,8 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) avctx->pix_fmt = AV_PIX_FMT_MONOBLACK; } else if (maxval < 256) { avctx->pix_fmt = AV_PIX_FMT_GRAY8; - } else if (maxval < 65535) { - avctx->pix_fmt = AV_PIX_FMT_GRAY16; } else { - avctx->pix_fmt = AV_PIX_FMT_GRAY16BE; + avctx->pix_fmt = AV_PIX_FMT_GRAY16; } } else if (depth == 2) { if (maxval == 255) @@ -130,13 +128,13 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) if (maxval < 256) { avctx->pix_fmt = AV_PIX_FMT_RGB24; } else { - avctx->pix_fmt = AV_PIX_FMT_RGB48BE; + avctx->pix_fmt = AV_PIX_FMT_RGB48; } } else if (depth == 4) { if (maxval < 256) { avctx->pix_fmt = AV_PIX_FMT_RGBA; } else { - avctx->pix_fmt = AV_PIX_FMT_RGBA64BE; + avctx->pix_fmt = AV_PIX_FMT_RGBA64; } } else { return AVERROR_INVALIDDATA; @@ -164,16 +162,14 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) } if (s->maxval >= 256) { if (avctx->pix_fmt == AV_PIX_FMT_GRAY8) { - avctx->pix_fmt = AV_PIX_FMT_GRAY16BE; - if (s->maxval != 65535) - avctx->pix_fmt = AV_PIX_FMT_GRAY16; + avctx->pix_fmt = AV_PIX_FMT_GRAY16; } else if (avctx->pix_fmt == AV_PIX_FMT_RGB24) { - avctx->pix_fmt = AV_PIX_FMT_RGB48BE; + 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; + avctx->pix_fmt = AV_PIX_FMT_YUV420P9; else if (s->maxval < 1024) - avctx->pix_fmt = AV_PIX_FMT_YUV420P10BE; + avctx->pix_fmt = AV_PIX_FMT_YUV420P10; else avctx->pix_fmt = AV_PIX_FMT_YUV420P16; } else { diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index d0c72954aa..a7b91fd509 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -24,6 +24,17 @@ #include "put_bits.h" #include "pnm.h" +static void samplecpy(void *dst, const void *src, int n, int maxval) +{ + if (maxval <= 255) { + memcpy(dst, src, n); + } else { + int i; + for (i=0; ipix_fmt) { default: return AVERROR(EINVAL); - case AV_PIX_FMT_RGBA64BE: + case AV_PIX_FMT_RGBA64: n = avctx->width * 8; components=4; sample_len=16; goto do_read; - case AV_PIX_FMT_RGB48BE: + case AV_PIX_FMT_RGB48: n = avctx->width * 6; components=3; sample_len=16; @@ -83,8 +94,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, components=2; sample_len=8; goto do_read; - case AV_PIX_FMT_GRAY16BE: - case AV_PIX_FMT_GRAY16LE: + case AV_PIX_FMT_GRAY16: n = avctx->width * 2; components=1; sample_len=16; @@ -124,15 +134,19 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, c = (*s->bytestream++) - '0'; } while (c <= 9); } - put_bits(&pb, sample_len, (((1<maxval>>1))/s->maxval); + if (sample_len == 16) { + ((uint16_t*)ptr)[j] = (((1<maxval>>1))/s->maxval; + } else + put_bits(&pb, sample_len, (((1<maxval>>1))/s->maxval); } - flush_put_bits(&pb); + if (sample_len != 16) + flush_put_bits(&pb); ptr+= linesize; } }else{ for (i = 0; i < avctx->height; i++) { if (!upgrade) - memcpy(ptr, s->bytestream, n); + samplecpy(ptr, s->bytestream, n, s->maxval); else if (upgrade == 1) { unsigned int j, f = (255 * 128 + s->maxval / 2) / s->maxval; for (j = 0; j < n; j++) @@ -150,8 +164,8 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, } break; case AV_PIX_FMT_YUV420P: - case AV_PIX_FMT_YUV420P9BE: - case AV_PIX_FMT_YUV420P10BE: + case AV_PIX_FMT_YUV420P9: + case AV_PIX_FMT_YUV420P10: { unsigned char *ptr1, *ptr2; @@ -163,7 +177,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, if (s->bytestream + n * avctx->height * 3 / 2 > s->bytestream_end) return AVERROR_INVALIDDATA; for (i = 0; i < avctx->height; i++) { - memcpy(ptr, s->bytestream, n); + samplecpy(ptr, s->bytestream, n, s->maxval); s->bytestream += n; ptr += linesize; } @@ -172,9 +186,9 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, n >>= 1; h = avctx->height >> 1; for (i = 0; i < h; i++) { - memcpy(ptr1, s->bytestream, n); + samplecpy(ptr1, s->bytestream, n, s->maxval); s->bytestream += n; - memcpy(ptr2, s->bytestream, n); + samplecpy(ptr2, s->bytestream, n, s->maxval); s->bytestream += n; ptr1 += p->linesize[1]; ptr2 += p->linesize[2]; diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh index 4d5c7dca5c..cd96567325 100755 --- a/tests/lavf-regression.sh +++ b/tests/lavf-regression.sh @@ -235,8 +235,8 @@ if [ -n "$do_pam" ] ; then do_image_formats pam do_image_formats pam "-pix_fmt rgba" do_image_formats pam "-pix_fmt gray" -do_image_formats pam "-pix_fmt gray16be" -do_image_formats pam "-pix_fmt rgb48be" +do_image_formats pam "-pix_fmt gray16be" "-pix_fmt gray16be" +do_image_formats pam "-pix_fmt rgb48be" "-pix_fmt rgb48be" do_image_formats pam "-pix_fmt monob" fi