This one will probably cause Michael to oppose, but I think it should be
implemented as well. As long as we don't have a "pal1" pixel format,
we'll have to use the somewhat redundant pal8. Below are two sample AVI files, one without a palette, and one with a blue palette.

No palette (black & white):
https://drive.google.com/open?id=0B3_pEBoLs0faelN5RXpKLWtfTnM

Blue palette:
https://drive.google.com/open?id=0B3_pEBoLs0fabnhDeGk0Zl9tSVk

Mats

--
Mats Peterson
http://matsp888.no-ip.org/~mats/
>From 037660e248df46f8e69c3255976e099ee61c72c3 Mon Sep 17 00:00:00 2001
From: Mats Peterson <matsp...@yahoo.com>
Date: Tue, 19 Jan 2016 13:39:45 +0100
Subject: [PATCH] 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 |   12 +++++++++---
 2 files changed, 10 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..f913cad 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,14 @@ 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) {
+                uint32_t *rgb = (uint32_t *)context->palette->data;
+                rgb[0] = 0xffffff;
+                rgb[1] = 0x000000;
+            }
+        }
     }
 
     if ((avctx->extradata_size >= 9 &&
@@ -202,7 +208,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