--
Mats Peterson
http://matsp888.no-ip.org/~mats/
>From 45624f6249703657bed9788bf1232289ee392f10 Mon Sep 17 00:00:00 2001
From: Mats Peterson <matsp...@yahoo.com>
Date: Fri, 19 Feb 2016 16:22:35 +0100
Subject: [PATCH 1/3] lavf/riffenc: Write space for palette

---
 libavformat/riffenc.c |   23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c
index ceb27f2..2d12f13 100644
--- a/libavformat/riffenc.c
+++ b/libavformat/riffenc.c
@@ -210,6 +210,9 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc,
                       !memcmp(enc->extradata + enc->extradata_size - 9, "BottomUp", 9);
     int extradata_size = enc->extradata_size - 9*keep_height;
 
+    if (!enc->extradata_size && enc->bits_per_coded_sample <= 8)
+        extradata_size = 4 * (1 << enc->bits_per_coded_sample);
+
     /* size */
     avio_wl32(pb, 40 + (ignore_extradata ? 0 :extradata_size));
     avio_wl32(pb, enc->width);
@@ -228,10 +231,22 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc,
     avio_wl32(pb, 0);
 
     if (!ignore_extradata) {
-        avio_write(pb, enc->extradata, extradata_size);
-
-        if (!for_asf && extradata_size & 1)
-            avio_w8(pb, 0);
+        if (enc->extradata_size) {
+            avio_write(pb, enc->extradata, extradata_size);
+            if (!for_asf && extradata_size & 1)
+                avio_w8(pb, 0);
+        } else if (enc->bits_per_coded_sample <= 8) {
+            int i;
+            int64_t *pal_offset = (int64_t *)enc->priv_data;
+            *pal_offset = avio_tell(pb);
+            for (i = 0; i < 1 << enc->bits_per_coded_sample; i++) {
+                /* Initialize 1 bpp palette to black & white */
+                if (!i && enc->bits_per_coded_sample == 1)
+                    avio_wl32(pb, 0xffffff);
+                else
+                    avio_wl32(pb, 0);
+            }
+        }
     }
 }
 
-- 
1.7.10.4

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

Reply via email to