comparison msrle.c @ 1595:b2fecae88e84 libavcodec

Moved to new palette API Added check to aviod stride change between frames
author rtognimp
date Sun, 02 Nov 2003 21:57:55 +0000
parents 63009885ca88
children 932d306bf1dc
comparison
equal deleted inserted replaced
1594:6d37b161cf85 1595:b2fecae88e84
24 * http://www.pcisys.net/~melanson/codecs/ 24 * http://www.pcisys.net/~melanson/codecs/
25 * 25 *
26 * The MS RLE decoder outputs PAL8 colorspace data. 26 * The MS RLE decoder outputs PAL8 colorspace data.
27 * 27 *
28 * Note that this decoder expects the palette colors from the end of the 28 * Note that this decoder expects the palette colors from the end of the
29 * BITMAPINFO header passed through extradata. 29 * BITMAPINFO header passed through palctrl.
30 */ 30 */
31 31
32 #include <stdio.h> 32 #include <stdio.h>
33 #include <stdlib.h> 33 #include <stdlib.h>
34 #include <string.h> 34 #include <string.h>
44 AVFrame prev_frame; 44 AVFrame prev_frame;
45 45
46 unsigned char *buf; 46 unsigned char *buf;
47 int size; 47 int size;
48 48
49 unsigned int palette[256];
50 } MsrleContext; 49 } MsrleContext;
51 50
52 #define FETCH_NEXT_STREAM_BYTE() \ 51 #define FETCH_NEXT_STREAM_BYTE() \
53 if (stream_ptr >= s->size) \ 52 if (stream_ptr >= s->size) \
54 { \ 53 { \
128 } 127 }
129 } 128 }
130 } 129 }
131 130
132 /* make the palette available */ 131 /* make the palette available */
133 memcpy(s->frame.data[1], s->palette, 256 * 4); 132 memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
133 if (s->avctx->palctrl->palette_changed) {
134 s->frame.palette_has_changed = 1;
135 s->avctx->palctrl->palette_changed = 0;
136 }
134 137
135 /* one last sanity check on the way out */ 138 /* one last sanity check on the way out */
136 if (stream_ptr < s->size) 139 if (stream_ptr < s->size)
137 printf(" MS RLE: ended frame decode with bytes left over (%d < %d)\n", 140 printf(" MS RLE: ended frame decode with bytes left over (%d < %d)\n",
138 stream_ptr, s->size); 141 stream_ptr, s->size);
139 } 142 }
140 143
141 static int msrle_decode_init(AVCodecContext *avctx) 144 static int msrle_decode_init(AVCodecContext *avctx)
142 { 145 {
143 MsrleContext *s = (MsrleContext *)avctx->priv_data; 146 MsrleContext *s = (MsrleContext *)avctx->priv_data;
144 int i, j;
145 unsigned char *palette;
146 147
147 s->avctx = avctx; 148 s->avctx = avctx;
148 149
149 avctx->pix_fmt = PIX_FMT_PAL8; 150 avctx->pix_fmt = PIX_FMT_PAL8;
150 avctx->has_b_frames = 0; 151 avctx->has_b_frames = 0;
151 s->frame.data[0] = s->prev_frame.data[0] = NULL; 152 s->frame.data[0] = s->prev_frame.data[0] = NULL;
152
153 /* convert palette */
154 palette = (unsigned char *)s->avctx->extradata;
155 memset (s->palette, 0, 256 * 4);
156 for (i = 0, j = 0; i < s->avctx->extradata_size / 4; i++, j += 4)
157 s->palette[i] =
158 (palette[j + 2] << 16) |
159 (palette[j + 1] << 8) |
160 (palette[j + 0] << 0);
161 153
162 return 0; 154 return 0;
163 } 155 }
164 156
165 static int msrle_decode_frame(AVCodecContext *avctx, 157 static int msrle_decode_frame(AVCodecContext *avctx,
174 s->frame.reference = 1; 166 s->frame.reference = 1;
175 if (avctx->get_buffer(avctx, &s->frame)) { 167 if (avctx->get_buffer(avctx, &s->frame)) {
176 printf (" MS RLE: get_buffer() failed\n"); 168 printf (" MS RLE: get_buffer() failed\n");
177 return -1; 169 return -1;
178 } 170 }
171
172 if (s->prev_frame.data[0] && (s->frame.linesize[0] != s->prev_frame.linesize[0]))
173 printf (" MS RLE: Buffer linesize changed: current %u, previous %u.\n"
174 " Expect wrong image and/or crash!\n",
175 s->frame.linesize[0], s->prev_frame.linesize[0]);
179 176
180 /* grossly inefficient, but...oh well */ 177 /* grossly inefficient, but...oh well */
181 if (s->prev_frame.data[0] != NULL) 178 if (s->prev_frame.data[0] != NULL)
182 memcpy(s->frame.data[0], s->prev_frame.data[0], 179 memcpy(s->frame.data[0], s->prev_frame.data[0],
183 s->frame.linesize[0] * s->avctx->height); 180 s->frame.linesize[0] * s->avctx->height);