40 #define PALETTE_COUNT 256
41 #define CHECK_STREAM_PTR(n) \
42 if ((stream_ptr + n) > s->size ) { \
43 av_log(s->avctx, AV_LOG_ERROR, " MS Video-1 warning: stream_ptr out of bounds (%d >= %d)\n", \
44 stream_ptr + n, s->size); \
53 const unsigned char *
buf;
71 if (
s->avctx->bits_per_coded_sample == 8) {
90 int block_ptr, pixel_ptr;
94 int blocks_wide, blocks_high;
100 unsigned char byte_a, byte_b;
101 unsigned short flags;
103 unsigned char colors[8];
104 unsigned char *pixels =
s->frame->data[0];
105 int stride =
s->frame->linesize[0];
109 blocks_wide =
s->avctx->width / 4;
110 blocks_high =
s->avctx->height / 4;
111 total_blocks = blocks_wide * blocks_high;
115 for (block_y = blocks_high; block_y > 0; block_y--) {
116 block_ptr = ((block_y * 4) - 1) *
stride;
117 for (block_x = blocks_wide; block_x > 0; block_x--) {
120 block_ptr += block_inc;
126 pixel_ptr = block_ptr;
130 byte_a =
s->buf[stream_ptr++];
131 byte_b =
s->buf[stream_ptr++];
134 if ((byte_a == 0) && (byte_b == 0) && (total_blocks == 0))
136 else if ((byte_b & 0xFC) == 0x84) {
138 skip_blocks = ((byte_b - 0x84) << 8) + byte_a - 1;
139 }
else if (byte_b < 0x80) {
141 flags = (byte_b << 8) | byte_a;
144 colors[0] =
s->buf[stream_ptr++];
145 colors[1] =
s->buf[stream_ptr++];
147 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
148 for (pixel_x = 0; pixel_x < 4; pixel_x++, flags >>= 1)
149 pixels[pixel_ptr++] = colors[(
flags & 0x1) ^ 1];
150 pixel_ptr -= row_dec;
152 }
else if (byte_b >= 0x90) {
154 flags = (byte_b << 8) | byte_a;
157 memcpy(colors, &
s->buf[stream_ptr], 8);
160 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
161 for (pixel_x = 0; pixel_x < 4; pixel_x++, flags >>= 1)
162 pixels[pixel_ptr++] =
163 colors[((pixel_y & 0x2) << 1) +
164 (pixel_x & 0x2) + ((
flags & 0x1) ^ 1)];
165 pixel_ptr -= row_dec;
171 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
172 for (pixel_x = 0; pixel_x < 4; pixel_x++)
173 pixels[pixel_ptr++] = colors[0];
174 pixel_ptr -= row_dec;
178 block_ptr += block_inc;
190 int block_ptr, pixel_ptr;
192 int pixel_x, pixel_y;
193 int block_x, block_y;
194 int blocks_wide, blocks_high;
200 unsigned char byte_a, byte_b;
201 unsigned short flags;
203 unsigned short colors[8];
204 unsigned short *pixels = (
unsigned short *)
s->frame->data[0];
205 int stride =
s->frame->linesize[0] / 2;
209 blocks_wide =
s->avctx->width / 4;
210 blocks_high =
s->avctx->height / 4;
211 total_blocks = blocks_wide * blocks_high;
215 for (block_y = blocks_high; block_y > 0; block_y--) {
216 block_ptr = ((block_y * 4) - 1) *
stride;
217 for (block_x = blocks_wide; block_x > 0; block_x--) {
220 block_ptr += block_inc;
226 pixel_ptr = block_ptr;
230 byte_a =
s->buf[stream_ptr++];
231 byte_b =
s->buf[stream_ptr++];
234 if ((byte_a == 0) && (byte_b == 0) && (total_blocks == 0)) {
236 }
else if ((byte_b & 0xFC) == 0x84) {
238 skip_blocks = ((byte_b - 0x84) << 8) + byte_a - 1;
239 }
else if (byte_b < 0x80) {
241 flags = (byte_b << 8) | byte_a;
244 colors[0] =
AV_RL16(&
s->buf[stream_ptr]);
246 colors[1] =
AV_RL16(&
s->buf[stream_ptr]);
249 if (colors[0] & 0x8000) {
252 colors[2] =
AV_RL16(&
s->buf[stream_ptr]);
254 colors[3] =
AV_RL16(&
s->buf[stream_ptr]);
256 colors[4] =
AV_RL16(&
s->buf[stream_ptr]);
258 colors[5] =
AV_RL16(&
s->buf[stream_ptr]);
260 colors[6] =
AV_RL16(&
s->buf[stream_ptr]);
262 colors[7] =
AV_RL16(&
s->buf[stream_ptr]);
265 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
266 for (pixel_x = 0; pixel_x < 4; pixel_x++, flags >>= 1)
267 pixels[pixel_ptr++] =
268 colors[((pixel_y & 0x2) << 1) +
269 (pixel_x & 0x2) + ((
flags & 0x1) ^ 1)];
270 pixel_ptr -= row_dec;
274 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
275 for (pixel_x = 0; pixel_x < 4; pixel_x++, flags >>= 1)
276 pixels[pixel_ptr++] = colors[(
flags & 0x1) ^ 1];
277 pixel_ptr -= row_dec;
282 colors[0] = (byte_b << 8) | byte_a;
284 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
285 for (pixel_x = 0; pixel_x < 4; pixel_x++)
286 pixels[pixel_ptr++] = colors[0];
287 pixel_ptr -= row_dec;
291 block_ptr += block_inc;
300 const uint8_t *buf = avpkt->
data;
301 int buf_size = avpkt->
size;
309 if (buf_size < (avctx->
width/4) * (avctx->
height/4) / 512) {
345 .
p.
name =
"msvideo1",