From 8cb7d20567052e205406cee5efe98c7269184942 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 5 Oct 2013 01:31:15 +0200 Subject: avcodec/dpx: fix reading 12bit dpx images, which have non zero padding bits Signed-off-by: Michael Niedermayer --- libavcodec/dpx.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'libavcodec/dpx.c') diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c index 6c3d53604a..11f692fea4 100644 --- a/libavcodec/dpx.c +++ b/libavcodec/dpx.c @@ -25,6 +25,18 @@ #include "avcodec.h" #include "internal.h" +static unsigned int read16(const uint8_t **ptr, int is_big) +{ + unsigned int temp; + if (is_big) { + temp = AV_RB16(*ptr); + } else { + temp = AV_RL16(*ptr); + } + *ptr += 2; + return temp; +} + static unsigned int read32(const uint8_t **ptr, int is_big) { unsigned int temp; @@ -159,11 +171,7 @@ static int decode_frame(AVCodecContext *avctx, av_log(avctx, AV_LOG_ERROR, "Packing to 16bit required\n"); return -1; } - if (endian) { - avctx->pix_fmt = AV_PIX_FMT_GBRP12BE; - } else { - avctx->pix_fmt = AV_PIX_FMT_GBRP12LE; - } + avctx->pix_fmt = AV_PIX_FMT_GBRP12; total_size = 2 * avctx->width * avctx->height * elements; break; case 16: @@ -221,18 +229,12 @@ static int decode_frame(AVCodecContext *avctx, (uint16_t*)ptr[1], (uint16_t*)ptr[2]}; for (y = 0; y < avctx->width; y++) { - *dst[2] = *((uint16_t*)buf); - *dst[2] = (*dst[2] >> 4) | (*dst[2] << 12); + *dst[2] = read16(&buf, endian) >> 4; dst[2]++; - buf += 2; - *dst[0] = *((uint16_t*)buf); - *dst[0] = (*dst[0] >> 4) | (*dst[0] << 12); + *dst[0] = read16(&buf, endian) >> 4; dst[0]++; - buf += 2; - *dst[1] = *((uint16_t*)buf); - *dst[1] = (*dst[1] >> 4) | (*dst[1] << 12); + *dst[1] = read16(&buf, endian) >> 4; dst[1]++; - buf += 2; // For 12 bit, ignore alpha if (elements == 4) buf += 2; -- cgit v1.2.3