[FFmpeg-devel] [PATCH 3/5] dpxenc: fix encoding of packed RGB48/64

Christophe Gisquet christophe.gisquet at gmail.com
Wed Aug 20 10:10:46 CEST 2014


When input had 12 bits, it was invariably treated as packed RGB
with 12 bits per component.
---
 libavcodec/dpxenc.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dpxenc.c b/libavcodec/dpxenc.c
index aca745b..d02684b 100644
--- a/libavcodec/dpxenc.c
+++ b/libavcodec/dpxenc.c
@@ -138,6 +138,38 @@ static void encode_gbrp10(AVCodecContext *avctx, const AVPicture *pic, uint8_t *
     }
 }
 
+static void encode_rgb48_Nbits(AVCodecContext *avctx, const AVPicture *pic,
+                               uint16_t *dst)
+{
+    DPXContext *s = avctx->priv_data;
+    const uint16_t *src = (uint16_t *)pic->data[0];
+    int stride = pic->linesize[0]/2;
+    int x, y, i, pad, shift = 16 - avctx->bits_per_raw_sample;
+
+    pad = avctx->width*6;
+    pad = (FFALIGN(pad, 4) - pad) >> 1;
+    for (y = 0; y < avctx->height; y++) {
+        for (x = 0; x < avctx->width; x++) {
+            uint16_t value[3];
+            // Input is RGB, encode as BGR
+            if (s->big_endian) {
+                value[0] = AV_RB16(src + 3*x+0) << shift;
+                value[1] = AV_RB16(src + 3*x+1) << shift;
+                value[2] = AV_RB16(src + 3*x+2) << shift;
+            } else {
+                value[0] = AV_RL16(src + 3*x+0) << shift;
+                value[1] = AV_RL16(src + 3*x+1) << shift;
+                value[2] = AV_RL16(src + 3*x+2) << shift;
+            }
+            for (i = 0; i < 3; i++)
+                write16(dst++, value[i]);
+        }
+        for (i = 0; i < pad; i++)
+            *dst++ = 0;
+        src += stride;
+    }
+}
+
 static void encode_gbrp12(AVCodecContext *avctx, const AVPicture *pic, uint16_t *dst)
 {
     DPXContext *s = avctx->priv_data;
@@ -254,7 +286,10 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
             encode_rgb48_10bit(avctx, (const AVPicture*)frame, buf + HEADER_SIZE);
         break;
     case 12:
-        encode_gbrp12(avctx, (const AVPicture*)frame, (uint16_t*)(buf + HEADER_SIZE));
+        if (s->planar)
+            encode_gbrp12(avctx, (const AVPicture*)frame, (uint16_t*)(buf + HEADER_SIZE));
+        else
+            encode_rgb48_Nbits(avctx, (const AVPicture*)frame, (uint16_t*)(buf + HEADER_SIZE));
         break;
     default:
         av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", s->bits_per_component);
-- 
1.9.2.msysgit.0



More information about the ffmpeg-devel mailing list