Simplified the setting of the default palette for 1-bit AVI files in raw_init_decoder().

Mats
>From d2ffdb87a32be74c1a3e1e9a996fa0b1cdda8b87 Mon Sep 17 00:00:00 2001
From: Mats Peterson <matsp...@yahoo.com>
Date: Tue, 19 Jan 2016 18:48:06 +0100
Subject: [PATCH v2] lavc/rawdec: Use AV_PIX_FMT_PAL8 for 1-bit raw AVI video

The stuff about 1-bit video not necessarily being black & white in
QuickTime goes for AVI as well. Being 1 bit per pixel only means that
the data is bi-level. The two colors can be any color. Since many
1 bpp AVI files don't have a palette following the BITMAPINFOHEADER,
I'm setting a "default" black & white palette in raw_init().

Mats

---
 libavcodec/raw.c    |    2 +-
 libavcodec/rawdec.c |    9 ++++++---
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavcodec/raw.c b/libavcodec/raw.c
index 3f2cc11..3979c5c 100644
--- a/libavcodec/raw.c
+++ b/libavcodec/raw.c
@@ -242,7 +242,7 @@ unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat fmt)
 }
 
 const PixelFormatTag avpriv_pix_fmt_bps_avi[] = {
-    { AV_PIX_FMT_MONOWHITE, 1 },
+    { AV_PIX_FMT_PAL8,    1 },
     { AV_PIX_FMT_PAL8,    2 },
     { AV_PIX_FMT_PAL8,    4 },
     { AV_PIX_FMT_PAL8,    8 },
diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index cb0364c..141a551 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_1_2_4_bpp; // 1 bpp raw in mov, and 2 or 4 bpp raw in avi/mov
+    int is_1_2_4_bpp; // 1, 2 and 4 bpp raw in avi/mov
     int is_yuv2;
     int is_lt_16bpp; // 16bpp pixfmt and bits_per_coded_sample < 16
     int tff;
@@ -94,8 +94,11 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
             return AVERROR(ENOMEM);
         if (desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL)
             avpriv_set_systematic_pal2((uint32_t*)context->palette->data, avctx->pix_fmt);
-        else
+        else {
             memset(context->palette->data, 0, AVPALETTE_SIZE);
+            if (avctx->bits_per_coded_sample == 1)
+                memset(context->palette->data, 0xff, 4);
+        }
     }
 
     if ((avctx->extradata_size >= 9 &&
@@ -202,7 +205,7 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
     if (!frame->buf[0])
         return AVERROR(ENOMEM);
 
-    // 1 bpp raw in mov, and 2 or 4 bpp raw in avi/mov
+    // 1, 2 and 4 bpp raw in avi/mov
     if (context->is_1_2_4_bpp) {
         int i;
         uint8_t *dst = frame->buf[0]->data;
-- 
1.7.10.4

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to