From 5e29abf8b7efe6cfeee41d9f5e5f9fc98c1fcb93 Mon Sep 17 00:00:00 2001 From: Roberto Togni Date: Sun, 2 Nov 2003 21:55:38 +0000 Subject: [PATCH] Make avi and asf demuxer export palette in palctrl Originally committed as revision 2465 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavformat/asf.c | 17 +++++++++++++++++ libavformat/avidec.c | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/libavformat/asf.c b/libavformat/asf.c index 044ba72d9b..b069b1d086 100644 --- a/libavformat/asf.c +++ b/libavformat/asf.c @@ -908,6 +908,22 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) 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 @@ static int asf_read_close(AVFormatContext *s) AVStream *st = s->streams[i]; av_free(st->priv_data); av_free(st->codec.extradata); + av_free(st->codec.palctrl); } return 0; } diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 9f235eec4d..c135202720 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -243,6 +243,21 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) 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 @@ static int avi_read_close(AVFormatContext *s) AVStream *st = s->streams[i]; // av_free(st->priv_data); av_free(st->codec.extradata); + av_free(st->codec.palctrl); } if (avi->dv_demux)