[FFmpeg-devel] [PATCH 3/5] rawdec: adjust image pixels according to bits_per_coded_sample
Peter Ross
pross at xvid.org
Sun Dec 16 02:49:20 CET 2012
---
libavcodec/raw.c | 13 +++++++++++++
libavcodec/rawdec.c | 35 ++++++++++++++++++++++++++++++++++-
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/libavcodec/raw.c b/libavcodec/raw.c
index e23dbea..2412e46 100644
--- a/libavcodec/raw.c
+++ b/libavcodec/raw.c
@@ -166,6 +166,19 @@ const PixelFormatTag ff_raw_pix_fmt_tags[] = {
{ AV_PIX_FMT_YUVA444P16LE, MKTAG('Y', '4', 0 , 16 ) },
{ AV_PIX_FMT_YUVA444P16BE, MKTAG(16 , 0 , '4', 'Y') },
+ { AV_PIX_FMT_BAYER_BGGR8, MKTAG(0xBA, 'B', 'G', 8 ) },
+ { AV_PIX_FMT_BAYER_BGGR16LE, MKTAG(0xBA, 'B', 'G', 16 ) },
+ { AV_PIX_FMT_BAYER_BGGR16BE, MKTAG(16 , 'G', 'B', 0xBA) },
+ { AV_PIX_FMT_BAYER_RGGB8, MKTAG(0xBA, 'R', 'G', 8 ) },
+ { AV_PIX_FMT_BAYER_RGGB16LE, MKTAG(0xBA, 'R', 'G', 16 ) },
+ { AV_PIX_FMT_BAYER_RGGB16BE, MKTAG(16 , 'G', 'R', 0xBA) },
+ { AV_PIX_FMT_BAYER_GBRG8, MKTAG(0xBA, 'G', 'B', 8 ) },
+ { AV_PIX_FMT_BAYER_GBRG16LE, MKTAG(0xBA, 'G', 'B', 16 ) },
+ { AV_PIX_FMT_BAYER_GBRG16BE, MKTAG(16, 'B', 'G', 0xBA) },
+ { AV_PIX_FMT_BAYER_GRBG8, MKTAG(0xBA, 'G', 'R', 8 ) },
+ { AV_PIX_FMT_BAYER_GRBG16LE, MKTAG(0xBA, 'G', 'R', 16 ) },
+ { AV_PIX_FMT_BAYER_GRBG16BE, MKTAG(16, 'R', 'G', 0xBA) },
+
/* quicktime */
{ AV_PIX_FMT_YUV420P, MKTAG('R', '4', '2', '0') }, /* Radius DV YUV PAL */
{ AV_PIX_FMT_YUV411P, MKTAG('R', '4', '1', '1') }, /* Radius DV YUV NTSC */
diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index 5002ccc..3381574 100644
--- a/libavcodec/rawdec.c
+++ b/libavcodec/rawdec.c
@@ -152,7 +152,7 @@ static int raw_decode(AVCodecContext *avctx,
void *data, int *got_frame,
AVPacket *avpkt)
{
- const uint8_t *buf = avpkt->data;
+ uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
int linesize_align = 4;
RawVideoContext *context = avctx->priv_data;
@@ -212,6 +212,39 @@ static int raw_decode(AVCodecContext *avctx,
return AVERROR(EINVAL);
}
+ if (avctx->bits_per_coded_sample && avctx->bits_per_coded_sample < 16) {
+ uint8_t *buf_end = buf + buf_size;
+ uint8_t *p = buf;
+ 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 = 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 = 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)
return res;
--
1.8.0
-- 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/20121216/4333443e/attachment.asc>
More information about the ffmpeg-devel
mailing list