changeset 297:85d558a18134 libavformat

Make avi and asf demuxer export palette in palctrl
author rtognimp
date Sun, 02 Nov 2003 21:55:38 +0000
parents 252946de6d3f
children 0b2eed7b1210
files asf.c avidec.c
diffstat 2 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/asf.c	Fri Oct 31 22:26:26 2003 +0000
+++ b/asf.c	Sun Nov 02 21:55:38 2003 +0000
@@ -908,6 +908,22 @@
 		    st->codec.extradata = av_mallocz(st->codec.extradata_size);
 		    get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
 		}
+
+        /* Extract palette from extradata if bpp <= 8 */
+        /* This code assumes that extradata contains only palette */
+        /* This is true for all paletted codecs implemented in ffmpeg */
+        if (st->codec.extradata_size && (st->codec.bits_per_sample <= 8)) {
+            st->codec.palctrl = av_mallocz(sizeof(AVPaletteControl));
+#ifdef WORDS_BIGENDIAN
+            for (i = 0; i < FFMIN(st->codec.extradata_size / 4, 256); i++)
+                st->codec.palctrl->palette[i] = bswap_32(st->codec.extradata)[i * 4]);
+#else
+            memcpy(st->codec.palctrl->palette, st->codec.extradata,
+                   FFMIN(st->codec.extradata_size, AVPALETTE_SIZE));
+#endif
+            st->codec.palctrl->palette_changed = 1;
+        }
+
                 st->codec.codec_tag = tag1;
 		st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1);
             }
@@ -1226,6 +1242,7 @@
 	AVStream *st = s->streams[i];
 	av_free(st->priv_data);
 	av_free(st->codec.extradata);
+    av_free(st->codec.palctrl);
     }
     return 0;
 }
--- a/avidec.c	Fri Oct 31 22:26:26 2003 +0000
+++ b/avidec.c	Sun Nov 02 21:55:38 2003 +0000
@@ -243,6 +243,21 @@
                     if(st->codec.extradata_size & 1) //FIXME check if the encoder really did this correctly
                         get_byte(pb);
 
+                    /* Extract palette from extradata if bpp <= 8 */
+                    /* This code assumes that extradata contains only palette */
+                    /* This is true for all paletted codecs implemented in ffmpeg */
+                    if (st->codec.extradata_size && (st->codec.bits_per_sample <= 8)) {
+                        st->codec.palctrl = av_mallocz(sizeof(AVPaletteControl));
+#ifdef WORDS_BIGENDIAN
+                        for (i = 0; i < FFMIN(st->codec.extradata_size / 4, 256); i++)
+                            st->codec.palctrl->palette[i] = bswap_32(st->codec.extradata)[i * 4]);
+#else
+                        memcpy(st->codec.palctrl->palette, st->codec.extradata,
+                               FFMIN(st->codec.extradata_size, AVPALETTE_SIZE));
+#endif
+                        st->codec.palctrl->palette_changed = 1;
+                    }
+
 #ifdef DEBUG
                     print_tag("video", tag1, 0);
 #endif
@@ -382,6 +397,7 @@
         AVStream *st = s->streams[i];
 //        av_free(st->priv_data);
         av_free(st->codec.extradata);
+        av_free(st->codec.palctrl);
     }
 
     if (avi->dv_demux)