[FFmpeg-devel] [PATCH 3/6] avcodec/rawdec: for 16-bit bayer images, shift pixels according to bits_per_coded_sample

Peter Ross pross at xvid.org
Sat Feb 22 13:41:49 CET 2014


---
 libavcodec/rawdec.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index e1682e3..c0f252b 100644
--- a/libavcodec/rawdec.c
+++ b/libavcodec/rawdec.c
@@ -240,6 +240,39 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
         return AVERROR(EINVAL);
     }
 
+    if (avctx->bits_per_coded_sample && avctx->bits_per_coded_sample < 16) {
+        const uint8_t *buf_end = buf + buf_size;
+        uint8_t *p;
+        switch (avctx->pix_fmt) {
+        case AV_PIX_FMT_GRAY16LE:
+        case AV_PIX_FMT_RGB48LE:
+        case AV_PIX_FMT_BGR48LE:
+        case AV_PIX_FMT_YUV420P16LE:
+        case AV_PIX_FMT_YUV422P16LE:
+        case AV_PIX_FMT_YUV444P16LE:
+        case AV_PIX_FMT_BAYER_BGGR16LE:
+        case AV_PIX_FMT_BAYER_RGGB16LE:
+        case AV_PIX_FMT_BAYER_GBRG16LE:
+        case AV_PIX_FMT_BAYER_GRBG16LE:
+            for (p = (uint8_t *)buf; buf_end - p >= 2; p += 2)
+                AV_WL16(p, AV_RL16(p) << (16 - avctx->bits_per_coded_sample));
+            break;
+        case AV_PIX_FMT_GRAY16BE:
+        case AV_PIX_FMT_RGB48BE:
+        case AV_PIX_FMT_BGR48BE:
+        case AV_PIX_FMT_YUV420P16BE:
+        case AV_PIX_FMT_YUV422P16BE:
+        case AV_PIX_FMT_YUV444P16BE:
+        case AV_PIX_FMT_BAYER_BGGR16BE:
+        case AV_PIX_FMT_BAYER_RGGB16BE:
+        case AV_PIX_FMT_BAYER_GBRG16BE:
+        case AV_PIX_FMT_BAYER_GRBG16BE:
+            for (p = (uint8_t *)buf; buf_end - p >= 2; p += 2)
+                AV_WB16(p, AV_RB16(p) << (16 - avctx->bits_per_coded_sample));
+            break;
+        }
+    }
+
     if ((res = avpicture_fill(picture, buf, avctx->pix_fmt,
                               avctx->width, avctx->height)) < 0) {
         av_buffer_unref(&frame->buf[0]);
-- 
1.8.3.2

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140222/98c7e6aa/attachment.asc>


More information about the ffmpeg-devel mailing list