From 5da1477fa01b8f5eb9804435f26e76ba423624e9 Mon Sep 17 00:00:00 2001 From: Mats Peterson Date: Sun, 17 Jan 2016 22:27:52 +0100 Subject: lavc/rawdec: Use AV_PIX_FMT_PAL8 for 1-bit raw QuickTime video Match the use of AV_PIX_FMT_PAL8 for 1-bit QuickTime Animation in lavc/qtrle. To reiterate, 1-bit video is not necessary black & white in QuickTime, merely bi-level. The two colors can be any color. The palette, either included in the sample description, or the default Macintosh palette (black & white for 1-bit video) will be set in lavf/qtpalette. See the QuickTime File Format Specification for details. Signed-off-by: Michael Niedermayer --- libavcodec/rawdec.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'libavcodec/rawdec.c') diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c index 50cee39aa6..cb0364c56e 100644 --- a/libavcodec/rawdec.c +++ b/libavcodec/rawdec.c @@ -41,7 +41,7 @@ typedef struct RawVideoContext { AVBufferRef *palette; int frame_size; /* size of the frame in bytes */ int flip; - int is_2_4_bpp; // 2 or 4 bpp raw in avi/mov + int is_1_2_4_bpp; // 1 bpp raw in mov, and 2 or 4 bpp raw in avi/mov int is_yuv2; int is_lt_16bpp; // 16bpp pixfmt and bits_per_coded_sample < 16 int tff; @@ -159,12 +159,13 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame, AVFrame *frame = data; - if ((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2) && + if ((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2 + || avctx->bits_per_coded_sample == 1) && avctx->pix_fmt == AV_PIX_FMT_PAL8 && (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))) { - context->is_2_4_bpp = 1; + context->is_1_2_4_bpp = 1; context->frame_size = av_image_get_buffer_size(avctx->pix_fmt, - FFALIGN(avctx->width, 16), + FFALIGN(avctx->width, 32), avctx->height, 1); } else { context->is_lt_16bpp = av_get_bits_per_pixel(desc) == 16 && avctx->bits_per_coded_sample && avctx->bits_per_coded_sample < 16; @@ -174,7 +175,7 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame, if (context->frame_size < 0) return context->frame_size; - need_copy = !avpkt->buf || context->is_2_4_bpp || context->is_yuv2 || context->is_lt_16bpp; + need_copy = !avpkt->buf || context->is_1_2_4_bpp || context->is_yuv2 || context->is_lt_16bpp; frame->pict_type = AV_PICTURE_TYPE_I; frame->key_frame = 1; @@ -201,8 +202,8 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame, if (!frame->buf[0]) return AVERROR(ENOMEM); - //2bpp and 4bpp raw in avi and mov (yes this is ugly ...) - if (context->is_2_4_bpp) { + // 1 bpp raw in mov, and 2 or 4 bpp raw in avi/mov + if (context->is_1_2_4_bpp) { int i; uint8_t *dst = frame->buf[0]->data; buf_size = context->frame_size - AVPALETTE_SIZE; @@ -212,8 +213,7 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame, dst[2 * i + 1] = buf[i] & 15; } linesize_align = 8; - } else { - av_assert0(avctx->bits_per_coded_sample == 2); + } else if (avctx->bits_per_coded_sample == 2) { for (i = 0; 4 * i + 3 < buf_size && isize; i++) { dst[4 * i + 0] = buf[i] >> 6; dst[4 * i + 1] = buf[i] >> 4 & 3; @@ -221,6 +221,19 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame, dst[4 * i + 3] = buf[i] & 3; } linesize_align = 16; + } else { + av_assert0(avctx->bits_per_coded_sample == 1); + for (i = 0; 8 * i + 7 < buf_size && isize; i++) { + dst[8 * i + 0] = buf[i] >> 7 & 1; + dst[8 * i + 1] = buf[i] >> 6 & 1; + dst[8 * i + 2] = buf[i] >> 5 & 1; + dst[8 * i + 3] = buf[i] >> 4 & 1; + dst[8 * i + 4] = buf[i] >> 3 & 1; + dst[8 * i + 5] = buf[i] >> 2 & 1; + dst[8 * i + 6] = buf[i] >> 1 & 1; + dst[8 * i + 7] = buf[i] & 1; + } + linesize_align = 32; } buf = dst; } else if (context->is_lt_16bpp) { -- cgit v1.2.3