comparison mmvideo.c @ 7221:c36517d7608f libavcodec

Remove AVPaletteControl from ALG MM demuxer/decoder
author pross
date Tue, 08 Jul 2008 12:44:08 +0000
parents e943e1409077
children 2acf0ae7b041
comparison
equal deleted inserted replaced
7220:a94b2cf78a2e 7221:c36517d7608f
1 /* 1 /*
2 * American Laser Games MM Video Decoder 2 * American Laser Games MM Video Decoder
3 * Copyright (c) 2006 Peter Ross 3 * Copyright (c) 2006,2008 Peter Ross
4 * 4 *
5 * This file is part of FFmpeg. 5 * This file is part of FFmpeg.
6 * 6 *
7 * FFmpeg is free software; you can redistribute it and/or 7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
39 #define MM_TYPE_INTRA 0x8 39 #define MM_TYPE_INTRA 0x8
40 #define MM_TYPE_INTRA_HH 0xc 40 #define MM_TYPE_INTRA_HH 0xc
41 #define MM_TYPE_INTER_HH 0xd 41 #define MM_TYPE_INTER_HH 0xd
42 #define MM_TYPE_INTRA_HHV 0xe 42 #define MM_TYPE_INTRA_HHV 0xe
43 #define MM_TYPE_INTER_HHV 0xf 43 #define MM_TYPE_INTER_HHV 0xf
44 #define MM_TYPE_PALETTE 0x31
44 45
45 typedef struct MmContext { 46 typedef struct MmContext {
46 AVCodecContext *avctx; 47 AVCodecContext *avctx;
47 AVFrame frame; 48 AVFrame frame;
49 int palette[AVPALETTE_COUNT];
48 } MmContext; 50 } MmContext;
49 51
50 static av_cold int mm_decode_init(AVCodecContext *avctx) 52 static av_cold int mm_decode_init(AVCodecContext *avctx)
51 { 53 {
52 MmContext *s = avctx->priv_data; 54 MmContext *s = avctx->priv_data;
53 55
54 s->avctx = avctx; 56 s->avctx = avctx;
55
56 if (s->avctx->palctrl == NULL) {
57 av_log(avctx, AV_LOG_ERROR, "mmvideo: palette expected.\n");
58 return -1;
59 }
60 57
61 avctx->pix_fmt = PIX_FMT_PAL8; 58 avctx->pix_fmt = PIX_FMT_PAL8;
62 59
63 if (avcodec_check_dimensions(avctx, avctx->width, avctx->height)) 60 if (avcodec_check_dimensions(avctx, avctx->width, avctx->height))
64 return -1; 61 return -1;
68 av_log(s->avctx, AV_LOG_ERROR, "mmvideo: get_buffer() failed\n"); 65 av_log(s->avctx, AV_LOG_ERROR, "mmvideo: get_buffer() failed\n");
69 return -1; 66 return -1;
70 } 67 }
71 68
72 return 0; 69 return 0;
70 }
71
72 static void mm_decode_pal(MmContext *s, const uint8_t *buf, const uint8_t *buf_end)
73 {
74 int i;
75 buf += 4;
76 for (i=0; i<128 && buf+2<buf_end; i++) {
77 s->palette[i] = AV_RB24(buf);
78 s->palette[i+128] = s->palette[i]<<2;
79 buf += 3;
80 }
73 } 81 }
74 82
75 static void mm_decode_intra(MmContext * s, int half_horiz, int half_vert, const uint8_t *buf, int buf_size) 83 static void mm_decode_intra(MmContext * s, int half_horiz, int half_vert, const uint8_t *buf, int buf_size)
76 { 84 {
77 int i, x, y; 85 int i, x, y;
151 static int mm_decode_frame(AVCodecContext *avctx, 159 static int mm_decode_frame(AVCodecContext *avctx,
152 void *data, int *data_size, 160 void *data, int *data_size,
153 const uint8_t *buf, int buf_size) 161 const uint8_t *buf, int buf_size)
154 { 162 {
155 MmContext *s = avctx->priv_data; 163 MmContext *s = avctx->priv_data;
156 AVPaletteControl *palette_control = avctx->palctrl; 164 const uint8_t *buf_end = buf+buf_size;
157 int type; 165 int type;
158
159 if (palette_control->palette_changed) {
160 memcpy(s->frame.data[1], palette_control->palette, AVPALETTE_SIZE);
161 palette_control->palette_changed = 0;
162 }
163 166
164 type = AV_RL16(&buf[0]); 167 type = AV_RL16(&buf[0]);
165 buf += MM_PREAMBLE_SIZE; 168 buf += MM_PREAMBLE_SIZE;
166 buf_size -= MM_PREAMBLE_SIZE; 169 buf_size -= MM_PREAMBLE_SIZE;
167 170
168 switch(type) { 171 switch(type) {
172 case MM_TYPE_PALETTE : mm_decode_pal(s, buf, buf_end); return buf_size;
169 case MM_TYPE_INTRA : mm_decode_intra(s, 0, 0, buf, buf_size); break; 173 case MM_TYPE_INTRA : mm_decode_intra(s, 0, 0, buf, buf_size); break;
170 case MM_TYPE_INTRA_HH : mm_decode_intra(s, 1, 0, buf, buf_size); break; 174 case MM_TYPE_INTRA_HH : mm_decode_intra(s, 1, 0, buf, buf_size); break;
171 case MM_TYPE_INTRA_HHV : mm_decode_intra(s, 1, 1, buf, buf_size); break; 175 case MM_TYPE_INTRA_HHV : mm_decode_intra(s, 1, 1, buf, buf_size); break;
172 case MM_TYPE_INTER : mm_decode_inter(s, 0, 0, buf, buf_size); break; 176 case MM_TYPE_INTER : mm_decode_inter(s, 0, 0, buf, buf_size); break;
173 case MM_TYPE_INTER_HH : mm_decode_inter(s, 1, 0, buf, buf_size); break; 177 case MM_TYPE_INTER_HH : mm_decode_inter(s, 1, 0, buf, buf_size); break;
174 case MM_TYPE_INTER_HHV : mm_decode_inter(s, 1, 1, buf, buf_size); break; 178 case MM_TYPE_INTER_HHV : mm_decode_inter(s, 1, 1, buf, buf_size); break;
175 default : 179 default :
176 return -1; 180 return -1;
177 } 181 }
182
183 memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE);
178 184
179 *data_size = sizeof(AVFrame); 185 *data_size = sizeof(AVFrame);
180 *(AVFrame*)data = s->frame; 186 *(AVFrame*)data = s->frame;
181 187
182 return buf_size; 188 return buf_size;