Mercurial > libavcodec.hg
comparison flicvideo.c @ 4364:05e932ddaaa9 libavcodec
rename BE/LE_8/16/32 to AV_RL/B_8/16/32
author | alex |
---|---|
date | Fri, 19 Jan 2007 22:12:59 +0000 |
parents | 92bf2ce5794a |
children | 956ccc32d4e9 |
comparison
equal
deleted
inserted
replaced
4363:9b7662fa4905 | 4364:05e932ddaaa9 |
---|---|
85 int depth; | 85 int depth; |
86 | 86 |
87 s->avctx = avctx; | 87 s->avctx = avctx; |
88 avctx->has_b_frames = 0; | 88 avctx->has_b_frames = 0; |
89 | 89 |
90 s->fli_type = LE_16(&fli_header[4]); /* Might be overridden if a Magic Carpet FLC */ | 90 s->fli_type = AV_RL16(&fli_header[4]); /* Might be overridden if a Magic Carpet FLC */ |
91 depth = LE_16(&fli_header[12]); | 91 depth = AV_RL16(&fli_header[12]); |
92 | 92 |
93 if (depth == 0) { | 93 if (depth == 0) { |
94 depth = 8; /* Some FLC generators set depth to zero, when they mean 8Bpp. Fix up here */ | 94 depth = 8; /* Some FLC generators set depth to zero, when they mean 8Bpp. Fix up here */ |
95 } | 95 } |
96 | 96 |
170 } | 170 } |
171 | 171 |
172 pixels = s->frame.data[0]; | 172 pixels = s->frame.data[0]; |
173 pixel_limit = s->avctx->height * s->frame.linesize[0]; | 173 pixel_limit = s->avctx->height * s->frame.linesize[0]; |
174 | 174 |
175 frame_size = LE_32(&buf[stream_ptr]); | 175 frame_size = AV_RL32(&buf[stream_ptr]); |
176 stream_ptr += 6; /* skip the magic number */ | 176 stream_ptr += 6; /* skip the magic number */ |
177 num_chunks = LE_16(&buf[stream_ptr]); | 177 num_chunks = AV_RL16(&buf[stream_ptr]); |
178 stream_ptr += 10; /* skip padding */ | 178 stream_ptr += 10; /* skip padding */ |
179 | 179 |
180 frame_size -= 16; | 180 frame_size -= 16; |
181 | 181 |
182 /* iterate through the chunks */ | 182 /* iterate through the chunks */ |
183 while ((frame_size > 0) && (num_chunks > 0)) { | 183 while ((frame_size > 0) && (num_chunks > 0)) { |
184 chunk_size = LE_32(&buf[stream_ptr]); | 184 chunk_size = AV_RL32(&buf[stream_ptr]); |
185 stream_ptr += 4; | 185 stream_ptr += 4; |
186 chunk_type = LE_16(&buf[stream_ptr]); | 186 chunk_type = AV_RL16(&buf[stream_ptr]); |
187 stream_ptr += 2; | 187 stream_ptr += 2; |
188 | 188 |
189 switch (chunk_type) { | 189 switch (chunk_type) { |
190 case FLI_256_COLOR: | 190 case FLI_256_COLOR: |
191 case FLI_COLOR: | 191 case FLI_COLOR: |
198 if ((chunk_type == FLI_256_COLOR) && (s->fli_type != FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE)) | 198 if ((chunk_type == FLI_256_COLOR) && (s->fli_type != FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE)) |
199 color_shift = 0; | 199 color_shift = 0; |
200 else | 200 else |
201 color_shift = 2; | 201 color_shift = 2; |
202 /* set up the palette */ | 202 /* set up the palette */ |
203 color_packets = LE_16(&buf[stream_ptr]); | 203 color_packets = AV_RL16(&buf[stream_ptr]); |
204 stream_ptr += 2; | 204 stream_ptr += 2; |
205 palette_ptr = 0; | 205 palette_ptr = 0; |
206 for (i = 0; i < color_packets; i++) { | 206 for (i = 0; i < color_packets; i++) { |
207 /* first byte is how many colors to skip */ | 207 /* first byte is how many colors to skip */ |
208 palette_ptr += buf[stream_ptr++]; | 208 palette_ptr += buf[stream_ptr++]; |
239 | 239 |
240 break; | 240 break; |
241 | 241 |
242 case FLI_DELTA: | 242 case FLI_DELTA: |
243 y_ptr = 0; | 243 y_ptr = 0; |
244 compressed_lines = LE_16(&buf[stream_ptr]); | 244 compressed_lines = AV_RL16(&buf[stream_ptr]); |
245 stream_ptr += 2; | 245 stream_ptr += 2; |
246 while (compressed_lines > 0) { | 246 while (compressed_lines > 0) { |
247 line_packets = LE_16(&buf[stream_ptr]); | 247 line_packets = AV_RL16(&buf[stream_ptr]); |
248 stream_ptr += 2; | 248 stream_ptr += 2; |
249 if ((line_packets & 0xC000) == 0xC000) { | 249 if ((line_packets & 0xC000) == 0xC000) { |
250 // line skip opcode | 250 // line skip opcode |
251 line_packets = -line_packets; | 251 line_packets = -line_packets; |
252 y_ptr += line_packets * s->frame.linesize[0]; | 252 y_ptr += line_packets * s->frame.linesize[0]; |
288 } | 288 } |
289 break; | 289 break; |
290 | 290 |
291 case FLI_LC: | 291 case FLI_LC: |
292 /* line compressed */ | 292 /* line compressed */ |
293 starting_line = LE_16(&buf[stream_ptr]); | 293 starting_line = AV_RL16(&buf[stream_ptr]); |
294 stream_ptr += 2; | 294 stream_ptr += 2; |
295 y_ptr = 0; | 295 y_ptr = 0; |
296 y_ptr += starting_line * s->frame.linesize[0]; | 296 y_ptr += starting_line * s->frame.linesize[0]; |
297 | 297 |
298 compressed_lines = LE_16(&buf[stream_ptr]); | 298 compressed_lines = AV_RL16(&buf[stream_ptr]); |
299 stream_ptr += 2; | 299 stream_ptr += 2; |
300 while (compressed_lines > 0) { | 300 while (compressed_lines > 0) { |
301 pixel_ptr = y_ptr; | 301 pixel_ptr = y_ptr; |
302 pixel_countdown = s->avctx->width; | 302 pixel_countdown = s->avctx->width; |
303 line_packets = buf[stream_ptr++]; | 303 line_packets = buf[stream_ptr++]; |
464 } | 464 } |
465 | 465 |
466 pixels = s->frame.data[0]; | 466 pixels = s->frame.data[0]; |
467 pixel_limit = s->avctx->height * s->frame.linesize[0]; | 467 pixel_limit = s->avctx->height * s->frame.linesize[0]; |
468 | 468 |
469 frame_size = LE_32(&buf[stream_ptr]); | 469 frame_size = AV_RL32(&buf[stream_ptr]); |
470 stream_ptr += 6; /* skip the magic number */ | 470 stream_ptr += 6; /* skip the magic number */ |
471 num_chunks = LE_16(&buf[stream_ptr]); | 471 num_chunks = AV_RL16(&buf[stream_ptr]); |
472 stream_ptr += 10; /* skip padding */ | 472 stream_ptr += 10; /* skip padding */ |
473 | 473 |
474 frame_size -= 16; | 474 frame_size -= 16; |
475 | 475 |
476 /* iterate through the chunks */ | 476 /* iterate through the chunks */ |
477 while ((frame_size > 0) && (num_chunks > 0)) { | 477 while ((frame_size > 0) && (num_chunks > 0)) { |
478 chunk_size = LE_32(&buf[stream_ptr]); | 478 chunk_size = AV_RL32(&buf[stream_ptr]); |
479 stream_ptr += 4; | 479 stream_ptr += 4; |
480 chunk_type = LE_16(&buf[stream_ptr]); | 480 chunk_type = AV_RL16(&buf[stream_ptr]); |
481 stream_ptr += 2; | 481 stream_ptr += 2; |
482 | 482 |
483 switch (chunk_type) { | 483 switch (chunk_type) { |
484 case FLI_256_COLOR: | 484 case FLI_256_COLOR: |
485 case FLI_COLOR: | 485 case FLI_COLOR: |
490 break; | 490 break; |
491 | 491 |
492 case FLI_DELTA: | 492 case FLI_DELTA: |
493 case FLI_DTA_LC: | 493 case FLI_DTA_LC: |
494 y_ptr = 0; | 494 y_ptr = 0; |
495 compressed_lines = LE_16(&buf[stream_ptr]); | 495 compressed_lines = AV_RL16(&buf[stream_ptr]); |
496 stream_ptr += 2; | 496 stream_ptr += 2; |
497 while (compressed_lines > 0) { | 497 while (compressed_lines > 0) { |
498 line_packets = LE_16(&buf[stream_ptr]); | 498 line_packets = AV_RL16(&buf[stream_ptr]); |
499 stream_ptr += 2; | 499 stream_ptr += 2; |
500 if (line_packets < 0) { | 500 if (line_packets < 0) { |
501 line_packets = -line_packets; | 501 line_packets = -line_packets; |
502 y_ptr += line_packets * s->frame.linesize[0]; | 502 y_ptr += line_packets * s->frame.linesize[0]; |
503 } else { | 503 } else { |
510 pixel_ptr += (pixel_skip*2); /* Pixel is 2 bytes wide */ | 510 pixel_ptr += (pixel_skip*2); /* Pixel is 2 bytes wide */ |
511 pixel_countdown -= pixel_skip; | 511 pixel_countdown -= pixel_skip; |
512 byte_run = (signed char)(buf[stream_ptr++]); | 512 byte_run = (signed char)(buf[stream_ptr++]); |
513 if (byte_run < 0) { | 513 if (byte_run < 0) { |
514 byte_run = -byte_run; | 514 byte_run = -byte_run; |
515 pixel = LE_16(&buf[stream_ptr]); | 515 pixel = AV_RL16(&buf[stream_ptr]); |
516 stream_ptr += 2; | 516 stream_ptr += 2; |
517 CHECK_PIXEL_PTR(byte_run); | 517 CHECK_PIXEL_PTR(byte_run); |
518 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) { | 518 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) { |
519 *((signed short*)(&pixels[pixel_ptr])) = pixel; | 519 *((signed short*)(&pixels[pixel_ptr])) = pixel; |
520 pixel_ptr += 2; | 520 pixel_ptr += 2; |
521 } | 521 } |
522 } else { | 522 } else { |
523 CHECK_PIXEL_PTR(byte_run); | 523 CHECK_PIXEL_PTR(byte_run); |
524 for (j = 0; j < byte_run; j++, pixel_countdown--) { | 524 for (j = 0; j < byte_run; j++, pixel_countdown--) { |
525 *((signed short*)(&pixels[pixel_ptr])) = LE_16(&buf[stream_ptr]); | 525 *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[stream_ptr]); |
526 stream_ptr += 2; | 526 stream_ptr += 2; |
527 pixel_ptr += 2; | 527 pixel_ptr += 2; |
528 } | 528 } |
529 } | 529 } |
530 } | 530 } |
584 * This doesnt give us any good oportunity to perform word endian conversion | 584 * This doesnt give us any good oportunity to perform word endian conversion |
585 * during decompression. So if its requried (ie, this isnt a LE target, we do | 585 * during decompression. So if its requried (ie, this isnt a LE target, we do |
586 * a second pass over the line here, swapping the bytes. | 586 * a second pass over the line here, swapping the bytes. |
587 */ | 587 */ |
588 pixel = 0xFF00; | 588 pixel = 0xFF00; |
589 if (0xFF00 != LE_16(&pixel)) /* Check if its not an LE Target */ | 589 if (0xFF00 != AV_RL16(&pixel)) /* Check if its not an LE Target */ |
590 { | 590 { |
591 pixel_ptr = y_ptr; | 591 pixel_ptr = y_ptr; |
592 pixel_countdown = s->avctx->width; | 592 pixel_countdown = s->avctx->width; |
593 while (pixel_countdown > 0) { | 593 while (pixel_countdown > 0) { |
594 *((signed short*)(&pixels[pixel_ptr])) = LE_16(&buf[pixel_ptr]); | 594 *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[pixel_ptr]); |
595 pixel_ptr += 2; | 595 pixel_ptr += 2; |
596 } | 596 } |
597 } | 597 } |
598 y_ptr += s->frame.linesize[0]; | 598 y_ptr += s->frame.linesize[0]; |
599 } | 599 } |
609 pixel_countdown = s->avctx->width; /* Width is in pixels, not bytes */ | 609 pixel_countdown = s->avctx->width; /* Width is in pixels, not bytes */ |
610 | 610 |
611 while (pixel_countdown > 0) { | 611 while (pixel_countdown > 0) { |
612 byte_run = (signed char)(buf[stream_ptr++]); | 612 byte_run = (signed char)(buf[stream_ptr++]); |
613 if (byte_run > 0) { | 613 if (byte_run > 0) { |
614 pixel = LE_16(&buf[stream_ptr]); | 614 pixel = AV_RL16(&buf[stream_ptr]); |
615 stream_ptr += 2; | 615 stream_ptr += 2; |
616 CHECK_PIXEL_PTR(byte_run); | 616 CHECK_PIXEL_PTR(byte_run); |
617 for (j = 0; j < byte_run; j++) { | 617 for (j = 0; j < byte_run; j++) { |
618 *((signed short*)(&pixels[pixel_ptr])) = pixel; | 618 *((signed short*)(&pixels[pixel_ptr])) = pixel; |
619 pixel_ptr += 2; | 619 pixel_ptr += 2; |
624 } | 624 } |
625 } else { /* copy pixels if byte_run < 0 */ | 625 } else { /* copy pixels if byte_run < 0 */ |
626 byte_run = -byte_run; | 626 byte_run = -byte_run; |
627 CHECK_PIXEL_PTR(byte_run); | 627 CHECK_PIXEL_PTR(byte_run); |
628 for (j = 0; j < byte_run; j++) { | 628 for (j = 0; j < byte_run; j++) { |
629 *((signed short*)(&pixels[pixel_ptr])) = LE_16(&buf[stream_ptr]); | 629 *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[stream_ptr]); |
630 stream_ptr += 2; | 630 stream_ptr += 2; |
631 pixel_ptr += 2; | 631 pixel_ptr += 2; |
632 pixel_countdown--; | 632 pixel_countdown--; |
633 if (pixel_countdown < 0) | 633 if (pixel_countdown < 0) |
634 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n", | 634 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n", |
654 y_ptr += s->frame.linesize[0]) { | 654 y_ptr += s->frame.linesize[0]) { |
655 | 655 |
656 pixel_countdown = s->avctx->width; | 656 pixel_countdown = s->avctx->width; |
657 pixel_ptr = 0; | 657 pixel_ptr = 0; |
658 while (pixel_countdown > 0) { | 658 while (pixel_countdown > 0) { |
659 *((signed short*)(&pixels[y_ptr + pixel_ptr])) = LE_16(&buf[stream_ptr+pixel_ptr]); | 659 *((signed short*)(&pixels[y_ptr + pixel_ptr])) = AV_RL16(&buf[stream_ptr+pixel_ptr]); |
660 pixel_ptr += 2; | 660 pixel_ptr += 2; |
661 pixel_countdown--; | 661 pixel_countdown--; |
662 } | 662 } |
663 stream_ptr += s->avctx->width*2; | 663 stream_ptr += s->avctx->width*2; |
664 } | 664 } |