Mercurial > libavcodec.hg
comparison msvideo1.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 | 222643544cf1 |
children | 932d306bf1dc |
comparison
equal
deleted
inserted
replaced
1594:6d37b161cf85 | 1595:b2fecae88e84 |
---|---|
23 * Microsoft Video-1 Decoder by Mike Melanson (melanson@pcisys.net) | 23 * Microsoft Video-1 Decoder by Mike Melanson (melanson@pcisys.net) |
24 * For more information about the MS Video-1 format, visit: | 24 * For more information about the MS Video-1 format, visit: |
25 * http://www.pcisys.net/~melanson/codecs/ | 25 * http://www.pcisys.net/~melanson/codecs/ |
26 * | 26 * |
27 * This decoder outputs either PAL8 or RGB555 data, depending on the | 27 * This decoder outputs either PAL8 or RGB555 data, depending on the |
28 * whether a RGB palette was passed through via extradata; if the extradata | 28 * whether a RGB palette was passed through palctrl; |
29 * is present, then the data is PAL8; RGB555 otherwise. | 29 * if it's present, then the data is PAL8; RGB555 otherwise. |
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> |
64 | 64 |
65 unsigned char *buf; | 65 unsigned char *buf; |
66 int size; | 66 int size; |
67 | 67 |
68 int mode_8bit; /* if it's not 8-bit, it's 16-bit */ | 68 int mode_8bit; /* if it's not 8-bit, it's 16-bit */ |
69 unsigned char palette[PALETTE_COUNT * 4]; | |
70 | 69 |
71 } Msvideo1Context; | 70 } Msvideo1Context; |
72 | 71 |
73 static int msvideo1_decode_init(AVCodecContext *avctx) | 72 static int msvideo1_decode_init(AVCodecContext *avctx) |
74 { | 73 { |
75 Msvideo1Context *s = (Msvideo1Context *)avctx->priv_data; | 74 Msvideo1Context *s = (Msvideo1Context *)avctx->priv_data; |
76 int i; | |
77 unsigned char r, g, b; | |
78 unsigned char *raw_palette; | |
79 unsigned int *palette32; | |
80 | 75 |
81 s->avctx = avctx; | 76 s->avctx = avctx; |
82 | 77 |
83 /* figure out the colorspace based on the presence of a palette in | 78 /* figure out the colorspace based on the presence of a palette */ |
84 * extradata */ | 79 if (s->avctx->palctrl) { |
85 if (s->avctx->extradata_size) { | |
86 s->mode_8bit = 1; | 80 s->mode_8bit = 1; |
87 /* load up the palette */ | |
88 palette32 = (unsigned int *)s->palette; | |
89 raw_palette = (unsigned char *)s->avctx->extradata; | |
90 for (i = 0; i < s->avctx->extradata_size / 4; i++) { | |
91 b = *raw_palette++; | |
92 g = *raw_palette++; | |
93 r = *raw_palette++; | |
94 raw_palette++; | |
95 palette32[i] = (r << 16) | (g << 8) | (b); | |
96 } | |
97 avctx->pix_fmt = PIX_FMT_PAL8; | 81 avctx->pix_fmt = PIX_FMT_PAL8; |
98 } else { | 82 } else { |
99 s->mode_8bit = 0; | 83 s->mode_8bit = 0; |
100 avctx->pix_fmt = PIX_FMT_RGB555; | 84 avctx->pix_fmt = PIX_FMT_RGB555; |
101 } | 85 } |
205 total_blocks--; | 189 total_blocks--; |
206 } | 190 } |
207 } | 191 } |
208 | 192 |
209 /* make the palette available on the way out */ | 193 /* make the palette available on the way out */ |
210 if (s->avctx->pix_fmt == PIX_FMT_PAL8) | 194 if (s->avctx->pix_fmt == PIX_FMT_PAL8) { |
211 memcpy(s->frame.data[1], s->palette, PALETTE_COUNT * 4); | 195 memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); |
196 if (s->avctx->palctrl->palette_changed) { | |
197 s->frame.palette_has_changed = 1; | |
198 s->avctx->palctrl->palette_changed = 0; | |
199 } | |
200 } | |
212 } | 201 } |
213 | 202 |
214 static void msvideo1_decode_16bit(Msvideo1Context *s) | 203 static void msvideo1_decode_16bit(Msvideo1Context *s) |
215 { | 204 { |
216 int block_ptr, pixel_ptr; | 205 int block_ptr, pixel_ptr; |
335 if (avctx->get_buffer(avctx, &s->frame)) { | 324 if (avctx->get_buffer(avctx, &s->frame)) { |
336 printf (" MS Video-1 Video: get_buffer() failed\n"); | 325 printf (" MS Video-1 Video: get_buffer() failed\n"); |
337 return -1; | 326 return -1; |
338 } | 327 } |
339 | 328 |
329 if (s->prev_frame.data[0] &&(s->frame.linesize[0] != s->prev_frame.linesize[0])) | |
330 printf (" MS Video-1: Buffer linesize changed: current %u, previous %u.\n" | |
331 " Expect wrong image and/or crash!\n", | |
332 s->frame.linesize[0], s->prev_frame.linesize[0]); | |
333 | |
340 if (s->mode_8bit) | 334 if (s->mode_8bit) |
341 msvideo1_decode_8bit(s); | 335 msvideo1_decode_8bit(s); |
342 else | 336 else |
343 msvideo1_decode_16bit(s); | 337 msvideo1_decode_16bit(s); |
344 | 338 |