[FFmpeg-cvslog] avcodec/dpx: fix reading 12bit dpx images, which have non zero padding bits

Michael Niedermayer git at videolan.org
Sat Oct 5 02:03:43 CEST 2013


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat Oct  5 01:31:15 2013 +0200| [8cb7d20567052e205406cee5efe98c7269184942] | committer: Michael Niedermayer

avcodec/dpx: fix reading 12bit dpx images, which have non zero padding bits

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8cb7d20567052e205406cee5efe98c7269184942
---

 libavcodec/dpx.c |   30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
index 6c3d536..11f692f 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;



More information about the ffmpeg-cvslog mailing list