Commit 349b9e36 authored by pross's avatar pross

Remove AVPaletteControl from ALG MM demuxer/decoder

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@14109 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 01ff07b7
/* /*
* American Laser Games MM Video Decoder * American Laser Games MM Video Decoder
* Copyright (c) 2006 Peter Ross * Copyright (c) 2006,2008 Peter Ross
* *
* This file is part of FFmpeg. * This file is part of FFmpeg.
* *
...@@ -41,10 +41,12 @@ ...@@ -41,10 +41,12 @@
#define MM_TYPE_INTER_HH 0xd #define MM_TYPE_INTER_HH 0xd
#define MM_TYPE_INTRA_HHV 0xe #define MM_TYPE_INTRA_HHV 0xe
#define MM_TYPE_INTER_HHV 0xf #define MM_TYPE_INTER_HHV 0xf
#define MM_TYPE_PALETTE 0x31
typedef struct MmContext { typedef struct MmContext {
AVCodecContext *avctx; AVCodecContext *avctx;
AVFrame frame; AVFrame frame;
int palette[AVPALETTE_COUNT];
} MmContext; } MmContext;
static av_cold int mm_decode_init(AVCodecContext *avctx) static av_cold int mm_decode_init(AVCodecContext *avctx)
...@@ -53,11 +55,6 @@ static av_cold int mm_decode_init(AVCodecContext *avctx) ...@@ -53,11 +55,6 @@ static av_cold int mm_decode_init(AVCodecContext *avctx)
s->avctx = avctx; s->avctx = avctx;
if (s->avctx->palctrl == NULL) {
av_log(avctx, AV_LOG_ERROR, "mmvideo: palette expected.\n");
return -1;
}
avctx->pix_fmt = PIX_FMT_PAL8; avctx->pix_fmt = PIX_FMT_PAL8;
if (avcodec_check_dimensions(avctx, avctx->width, avctx->height)) if (avcodec_check_dimensions(avctx, avctx->width, avctx->height))
...@@ -72,6 +69,17 @@ static av_cold int mm_decode_init(AVCodecContext *avctx) ...@@ -72,6 +69,17 @@ static av_cold int mm_decode_init(AVCodecContext *avctx)
return 0; return 0;
} }
static void mm_decode_pal(MmContext *s, const uint8_t *buf, const uint8_t *buf_end)
{
int i;
buf += 4;
for (i=0; i<128 && buf+2<buf_end; i++) {
s->palette[i] = AV_RB24(buf);
s->palette[i+128] = s->palette[i]<<2;
buf += 3;
}
}
static void mm_decode_intra(MmContext * s, int half_horiz, int half_vert, const uint8_t *buf, int buf_size) static void mm_decode_intra(MmContext * s, int half_horiz, int half_vert, const uint8_t *buf, int buf_size)
{ {
int i, x, y; int i, x, y;
...@@ -153,19 +161,15 @@ static int mm_decode_frame(AVCodecContext *avctx, ...@@ -153,19 +161,15 @@ static int mm_decode_frame(AVCodecContext *avctx,
const uint8_t *buf, int buf_size) const uint8_t *buf, int buf_size)
{ {
MmContext *s = avctx->priv_data; MmContext *s = avctx->priv_data;
AVPaletteControl *palette_control = avctx->palctrl; const uint8_t *buf_end = buf+buf_size;
int type; int type;
if (palette_control->palette_changed) {
memcpy(s->frame.data[1], palette_control->palette, AVPALETTE_SIZE);
palette_control->palette_changed = 0;
}
type = AV_RL16(&buf[0]); type = AV_RL16(&buf[0]);
buf += MM_PREAMBLE_SIZE; buf += MM_PREAMBLE_SIZE;
buf_size -= MM_PREAMBLE_SIZE; buf_size -= MM_PREAMBLE_SIZE;
switch(type) { switch(type) {
case MM_TYPE_PALETTE : mm_decode_pal(s, buf, buf_end); return buf_size;
case MM_TYPE_INTRA : mm_decode_intra(s, 0, 0, buf, buf_size); break; case MM_TYPE_INTRA : mm_decode_intra(s, 0, 0, buf, buf_size); break;
case MM_TYPE_INTRA_HH : mm_decode_intra(s, 1, 0, buf, buf_size); break; case MM_TYPE_INTRA_HH : mm_decode_intra(s, 1, 0, buf, buf_size); break;
case MM_TYPE_INTRA_HHV : mm_decode_intra(s, 1, 1, buf, buf_size); break; case MM_TYPE_INTRA_HHV : mm_decode_intra(s, 1, 1, buf, buf_size); break;
...@@ -176,6 +180,8 @@ static int mm_decode_frame(AVCodecContext *avctx, ...@@ -176,6 +180,8 @@ static int mm_decode_frame(AVCodecContext *avctx,
return -1; return -1;
} }
memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE);
*data_size = sizeof(AVFrame); *data_size = sizeof(AVFrame);
*(AVFrame*)data = s->frame; *(AVFrame*)data = s->frame;
......
...@@ -52,7 +52,6 @@ ...@@ -52,7 +52,6 @@
#define MM_PALETTE_SIZE (MM_PALETTE_COUNT*3) #define MM_PALETTE_SIZE (MM_PALETTE_COUNT*3)
typedef struct { typedef struct {
AVPaletteControl palette_control;
unsigned int audio_pts, video_pts; unsigned int audio_pts, video_pts;
} MmDemuxContext; } MmDemuxContext;
...@@ -101,7 +100,6 @@ static int mm_read_header(AVFormatContext *s, ...@@ -101,7 +100,6 @@ static int mm_read_header(AVFormatContext *s,
st->codec->codec_tag = 0; /* no fourcc */ st->codec->codec_tag = 0; /* no fourcc */
st->codec->width = width; st->codec->width = width;
st->codec->height = height; st->codec->height = height;
st->codec->palctrl = &mm->palette_control;
av_set_pts_info(st, 64, 1, frame_rate); av_set_pts_info(st, 64, 1, frame_rate);
/* audio stream */ /* audio stream */
...@@ -117,7 +115,6 @@ static int mm_read_header(AVFormatContext *s, ...@@ -117,7 +115,6 @@ static int mm_read_header(AVFormatContext *s,
av_set_pts_info(st, 64, 1, 8000); /* 8000 hz */ av_set_pts_info(st, 64, 1, 8000); /* 8000 hz */
} }
mm->palette_control.palette_changed = 0;
mm->audio_pts = 0; mm->audio_pts = 0;
mm->video_pts = 0; mm->video_pts = 0;
return 0; return 0;
...@@ -129,9 +126,7 @@ static int mm_read_packet(AVFormatContext *s, ...@@ -129,9 +126,7 @@ static int mm_read_packet(AVFormatContext *s,
MmDemuxContext *mm = s->priv_data; MmDemuxContext *mm = s->priv_data;
ByteIOContext *pb = s->pb; ByteIOContext *pb = s->pb;
unsigned char preamble[MM_PREAMBLE_SIZE]; unsigned char preamble[MM_PREAMBLE_SIZE];
unsigned char pal[MM_PALETTE_SIZE];
unsigned int type, length; unsigned int type, length;
int i;
while(1) { while(1) {
...@@ -144,22 +139,6 @@ static int mm_read_packet(AVFormatContext *s, ...@@ -144,22 +139,6 @@ static int mm_read_packet(AVFormatContext *s,
switch(type) { switch(type) {
case MM_TYPE_PALETTE : case MM_TYPE_PALETTE :
url_fseek(pb, 4, SEEK_CUR); /* unknown data */
if (get_buffer(pb, pal, MM_PALETTE_SIZE) != MM_PALETTE_SIZE)
return AVERROR(EIO);
url_fseek(pb, length - (4 + MM_PALETTE_SIZE), SEEK_CUR);
for (i=0; i<MM_PALETTE_COUNT; i++) {
int r = pal[i*3 + 0];
int g = pal[i*3 + 1];
int b = pal[i*3 + 2];
mm->palette_control.palette[i] = (r << 16) | (g << 8) | (b);
/* repeat palette, where each components is multiplied by four */
mm->palette_control.palette[i+128] = (r << 18) | (g << 10) | (b<<2);
}
mm->palette_control.palette_changed = 1;
break;
case MM_TYPE_INTER : case MM_TYPE_INTER :
case MM_TYPE_INTRA : case MM_TYPE_INTRA :
case MM_TYPE_INTRA_HH : case MM_TYPE_INTRA_HH :
...@@ -174,7 +153,9 @@ static int mm_read_packet(AVFormatContext *s, ...@@ -174,7 +153,9 @@ static int mm_read_packet(AVFormatContext *s,
return AVERROR(EIO); return AVERROR(EIO);
pkt->size = length + MM_PREAMBLE_SIZE; pkt->size = length + MM_PREAMBLE_SIZE;
pkt->stream_index = 0; pkt->stream_index = 0;
pkt->pts = mm->video_pts++; pkt->pts = mm->video_pts;
if (type!=MM_TYPE_PALETTE)
mm->video_pts++;
return 0; return 0;
case MM_TYPE_AUDIO : case MM_TYPE_AUDIO :
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment