comparison qtrle.c @ 2964:8f732838179d libavcodec

correctly deal with the alpha channel in 32-bit QT RLE (courtesy of John Koleszar <jkoleszar at on2.com>)
author melanson
date Wed, 14 Dec 2005 08:02:03 +0000
parents 89ce06bb1c87
children 0b546eab515d
comparison
equal deleted inserted replaced
2963:c8fa6a50fca5 2964:8f732838179d
409 int start_line; 409 int start_line;
410 int lines_to_change; 410 int lines_to_change;
411 int rle_code; 411 int rle_code;
412 int row_ptr, pixel_ptr; 412 int row_ptr, pixel_ptr;
413 int row_inc = s->frame.linesize[0]; 413 int row_inc = s->frame.linesize[0];
414 unsigned char r, g, b; 414 unsigned char a, r, g, b;
415 unsigned int argb; 415 unsigned int argb;
416 unsigned char *rgb = s->frame.data[0]; 416 unsigned char *rgb = s->frame.data[0];
417 int pixel_limit = s->frame.linesize[0] * s->avctx->height; 417 int pixel_limit = s->frame.linesize[0] * s->avctx->height;
418 418
419 /* check if this frame is even supposed to change */ 419 /* check if this frame is even supposed to change */
453 CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ 453 CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
454 } else if (rle_code < 0) { 454 } else if (rle_code < 0) {
455 /* decode the run length code */ 455 /* decode the run length code */
456 rle_code = -rle_code; 456 rle_code = -rle_code;
457 CHECK_STREAM_PTR(4); 457 CHECK_STREAM_PTR(4);
458 stream_ptr++; /* skip the alpha (?) byte */ 458 a = s->buf[stream_ptr++];
459 r = s->buf[stream_ptr++]; 459 r = s->buf[stream_ptr++];
460 g = s->buf[stream_ptr++]; 460 g = s->buf[stream_ptr++];
461 b = s->buf[stream_ptr++]; 461 b = s->buf[stream_ptr++];
462 argb = (r << 16) | (g << 8) | (b << 0); 462 argb = (a << 24) | (r << 16) | (g << 8) | (b << 0);
463 463
464 CHECK_PIXEL_PTR(rle_code * 4); 464 CHECK_PIXEL_PTR(rle_code * 4);
465 465
466 while (rle_code--) { 466 while (rle_code--) {
467 *(unsigned int *)(&rgb[pixel_ptr]) = argb; 467 *(unsigned int *)(&rgb[pixel_ptr]) = argb;
471 CHECK_STREAM_PTR(rle_code * 4); 471 CHECK_STREAM_PTR(rle_code * 4);
472 CHECK_PIXEL_PTR(rle_code * 4); 472 CHECK_PIXEL_PTR(rle_code * 4);
473 473
474 /* copy pixels directly to output */ 474 /* copy pixels directly to output */
475 while (rle_code--) { 475 while (rle_code--) {
476 stream_ptr++; /* skip the alpha (?) byte */ 476 a = s->buf[stream_ptr++];
477 r = s->buf[stream_ptr++]; 477 r = s->buf[stream_ptr++];
478 g = s->buf[stream_ptr++]; 478 g = s->buf[stream_ptr++];
479 b = s->buf[stream_ptr++]; 479 b = s->buf[stream_ptr++];
480 argb = (r << 16) | (g << 8) | (b << 0); 480 argb = (a << 24) | (r << 16) | (g << 8) | (b << 0);
481 *(unsigned int *)(&rgb[pixel_ptr]) = argb; 481 *(unsigned int *)(&rgb[pixel_ptr]) = argb;
482 pixel_ptr += 4; 482 pixel_ptr += 4;
483 } 483 }
484 } 484 }
485 } 485 }