summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorMike Melanson <mike@multimedia.cx>2003-10-30 05:40:58 +0000
committerMike Melanson <mike@multimedia.cx>2003-10-30 05:40:58 +0000
commit2a2bbcb05fde486eef76d070f26eecddd4de0ace (patch)
tree781c3c83552a80cb71014d3ff66ff05df14f5f7e /libavformat
parent9df1d2490d61c273a3ac9573c49cf4d20b4d750e (diff)
revised palette API, courtesy of Roberto Togni (rtogni at freemail.it)
Originally committed as revision 2451 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/idcin.c24
-rw-r--r--libavformat/ipmovie.c11
-rw-r--r--libavformat/wc3movie.c16
3 files changed, 31 insertions, 20 deletions
diff --git a/libavformat/idcin.c b/libavformat/idcin.c
index 6125c64afc..9d13aa5634 100644
--- a/libavformat/idcin.c
+++ b/libavformat/idcin.c
@@ -90,8 +90,7 @@ typedef struct IdcinDemuxContext {
int64_t pts;
- /* keep reference to extradata but never free it */
- void *extradata;
+ AVPaletteControl palctrl;
} IdcinDemuxContext;
static int idcin_probe(AVProbeData *p)
@@ -175,7 +174,7 @@ static int idcin_read_header(AVFormatContext *s,
HUFFMAN_TABLE_SIZE)
return -EIO;
/* save a reference in order to transport the palette */
- idcin->extradata = st->codec.extradata;
+ st->codec.palctrl = &idcin->palctrl;
/* if sample rate is 0, assume no audio */
if (sample_rate) {
@@ -227,9 +226,10 @@ static int idcin_read_packet(AVFormatContext *s,
unsigned int chunk_size;
IdcinDemuxContext *idcin = (IdcinDemuxContext *)s->priv_data;
ByteIOContext *pb = &s->pb;
- AVPaletteControl *palette_control = (AVPaletteControl *)idcin->extradata;
int i;
int palette_scale;
+ unsigned char r, g, b;
+ unsigned char palette_buffer[768];
if (url_feof(&s->pb))
return -EIO;
@@ -240,20 +240,23 @@ static int idcin_read_packet(AVFormatContext *s,
return -EIO;
} else if (command == 1) {
/* trigger a palette change */
- palette_control->palette_changed = 1;
- if (get_buffer(pb, palette_control->palette, 768) != 768)
+ idcin->palctrl.palette_changed = 1;
+ if (get_buffer(pb, palette_buffer, 768) != 768)
return -EIO;
/* scale the palette as necessary */
palette_scale = 2;
for (i = 0; i < 768; i++)
- if (palette_control->palette[i] > 63) {
+ if (palette_buffer[i] > 63) {
palette_scale = 0;
break;
}
- if (palette_scale)
- for (i = 0; i < 768; i++)
- palette_control->palette[i] <<= palette_scale;
+ for (i = 0; i < 256; i++) {
+ r = palette_buffer[i * 3 ] << palette_scale;
+ g = palette_buffer[i * 3 + 1] << palette_scale;
+ b = palette_buffer[i * 3 + 2] << palette_scale;
+ idcin->palctrl.palette[i] = (r << 16) | (g << 8) | (b);
+ }
}
chunk_size = get_le32(pb);
@@ -293,6 +296,7 @@ static int idcin_read_packet(AVFormatContext *s,
static int idcin_read_close(AVFormatContext *s)
{
+
return 0;
}
diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c
index e8ba0b7043..caaa3dd63b 100644
--- a/libavformat/ipmovie.c
+++ b/libavformat/ipmovie.c
@@ -232,6 +232,7 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
int i, j;
int first_color, last_color;
int audio_flags;
+ unsigned char r, g, b;
/* see if there are any pending packets */
chunk_type = load_ipmovie_packet(s, pb, pkt);
@@ -463,9 +464,10 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
for (i = first_color; i <= last_color; i++) {
/* the palette is stored as a 6-bit VGA palette, thus each
* component is shifted up to a 8-bit range */
- s->palette_control.palette[i * 3 + 0] = scratch[j++] * 4;
- s->palette_control.palette[i * 3 + 1] = scratch[j++] * 4;
- s->palette_control.palette[i * 3 + 2] = scratch[j++] * 4;
+ r = scratch[j++] * 4;
+ g = scratch[j++] * 4;
+ b = scratch[j++] * 4;
+ s->palette_control.palette[i] = (r << 16) | (g << 8) | (b);
}
/* indicate a palette change */
s->palette_control.palette_changed = 1;
@@ -573,8 +575,7 @@ static int ipmovie_read_header(AVFormatContext *s,
st->codec.height = ipmovie->video_height;
/* palette considerations */
- st->codec.extradata_size = sizeof(AVPaletteControl);
- st->codec.extradata = &ipmovie->palette_control;
+ st->codec.palctrl = &ipmovie->palette_control;
if (ipmovie->audio_type) {
st = av_new_stream(s, 0);
diff --git a/libavformat/wc3movie.c b/libavformat/wc3movie.c
index 16e4412681..cedb904231 100644
--- a/libavformat/wc3movie.c
+++ b/libavformat/wc3movie.c
@@ -258,8 +258,7 @@ static int wc3_read_header(AVFormatContext *s,
st->codec.height = wc3->height;
/* palette considerations */
- st->codec.extradata_size = sizeof(AVPaletteControl);
- st->codec.extradata = &wc3->palette_control;
+ st->codec.palctrl = &wc3->palette_control;
st = av_new_stream(s, 0);
if (!st)
@@ -294,6 +293,9 @@ static int wc3_read_packet(AVFormatContext *s,
unsigned char preamble[WC3_PREAMBLE_SIZE];
unsigned char text[1024];
unsigned int palette_number;
+ int i;
+ unsigned char r, g, b;
+ int base_palette_index;
while (!packet_read) {
@@ -319,9 +321,13 @@ static int wc3_read_packet(AVFormatContext *s,
palette_number = LE_32(&preamble[0]);
if (palette_number >= wc3->palette_count)
return AVERROR_INVALIDDATA;
- memcpy(wc3->palette_control.palette,
- &wc3->palettes[palette_number * PALETTE_COUNT * 3],
- PALETTE_COUNT * 3);
+ base_palette_index = palette_number * PALETTE_COUNT * 3;
+ for (i = 0; i < PALETTE_COUNT; i++) {
+ r = wc3->palettes[base_palette_index + i * 3 + 0];
+ g = wc3->palettes[base_palette_index + i * 3 + 1];
+ b = wc3->palettes[base_palette_index + i * 3 + 2];
+ wc3->palette_control.palette[i] = (r << 16) | (g << 8) | (b);
+ }
wc3->palette_control.palette_changed = 1;
break;