comparison huffyuv.c @ 10878:a8620b001ed3 libavcodec

Implement alpha channel decoding for BGR HuffYUV. Since BGR24 is decoded as BGR32, fill its alpha channel with 255 using the appropriate predictors.
author astrange
date Thu, 14 Jan 2010 01:32:49 +0000
parents 95f3daa991a2
children 8a4984c5cacc
comparison
equal deleted inserted replaced
10877:9ad6c1c4455c 10878:a8620b001ed3
37 37
38 #if HAVE_BIGENDIAN 38 #if HAVE_BIGENDIAN
39 #define B 3 39 #define B 3
40 #define G 2 40 #define G 2
41 #define R 1 41 #define R 1
42 #define A 0
42 #else 43 #else
43 #define B 0 44 #define B 0
44 #define G 1 45 #define G 1
45 #define R 2 46 #define R 2
47 #define A 3
46 #endif 48 #endif
47 49
48 typedef enum Predictor{ 50 typedef enum Predictor{
49 LEFT= 0, 51 LEFT= 0,
50 PLANE, 52 PLANE,
404 if(s->bitstream_bpp<24){ 406 if(s->bitstream_bpp<24){
405 for(i=0; i<3; i++){ 407 for(i=0; i<3; i++){
406 s->temp[i]= av_malloc(s->width + 16); 408 s->temp[i]= av_malloc(s->width + 16);
407 } 409 }
408 }else{ 410 }else{
409 s->temp[0]= av_malloc(4*s->width + 16); 411 s->temp[0]= av_mallocz(4*s->width + 16);
410 } 412 }
411 } 413 }
412 414
413 static av_cold int common_init(AVCodecContext *avctx){ 415 static av_cold int common_init(AVCodecContext *avctx){
414 HYuvContext *s = avctx->priv_data; 416 HYuvContext *s = avctx->priv_data;
834 s->temp[0][4*i+B] = get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); 836 s->temp[0][4*i+B] = get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
835 s->temp[0][4*i+G] = get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); 837 s->temp[0][4*i+G] = get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
836 s->temp[0][4*i+R] = get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); 838 s->temp[0][4*i+R] = get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
837 } 839 }
838 if(alpha) 840 if(alpha)
839 get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?! 841 s->temp[0][4*i+A] = get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
840 } 842 }
841 } 843 }
842 844
843 static void decode_bgr_bitstream(HYuvContext *s, int count){ 845 static void decode_bgr_bitstream(HYuvContext *s, int count){
844 if(s->decorrelate){ 846 if(s->decorrelate){
1114 break; 1116 break;
1115 } 1117 }
1116 } 1118 }
1117 }else{ 1119 }else{
1118 int y; 1120 int y;
1119 int leftr, leftg, leftb; 1121 int leftr, leftg, leftb, lefta;
1120 const int last_line= (height-1)*p->linesize[0]; 1122 const int last_line= (height-1)*p->linesize[0];
1121 1123
1122 if(s->bitstream_bpp==32){ 1124 if(s->bitstream_bpp==32){
1123 skip_bits(&s->gb, 8); 1125 lefta= p->data[0][last_line+A]= get_bits(&s->gb, 8);
1124 leftr= p->data[0][last_line+R]= get_bits(&s->gb, 8); 1126 leftr= p->data[0][last_line+R]= get_bits(&s->gb, 8);
1125 leftg= p->data[0][last_line+G]= get_bits(&s->gb, 8); 1127 leftg= p->data[0][last_line+G]= get_bits(&s->gb, 8);
1126 leftb= p->data[0][last_line+B]= get_bits(&s->gb, 8); 1128 leftb= p->data[0][last_line+B]= get_bits(&s->gb, 8);
1127 }else{ 1129 }else{
1128 leftr= p->data[0][last_line+R]= get_bits(&s->gb, 8); 1130 leftr= p->data[0][last_line+R]= get_bits(&s->gb, 8);
1129 leftg= p->data[0][last_line+G]= get_bits(&s->gb, 8); 1131 leftg= p->data[0][last_line+G]= get_bits(&s->gb, 8);
1130 leftb= p->data[0][last_line+B]= get_bits(&s->gb, 8); 1132 leftb= p->data[0][last_line+B]= get_bits(&s->gb, 8);
1133 lefta= p->data[0][last_line+A]= 255;
1131 skip_bits(&s->gb, 8); 1134 skip_bits(&s->gb, 8);
1132 } 1135 }
1133 1136
1134 if(s->bgr32){ 1137 if(s->bgr32){
1135 switch(s->predictor){ 1138 switch(s->predictor){
1136 case LEFT: 1139 case LEFT:
1137 case PLANE: 1140 case PLANE:
1138 decode_bgr_bitstream(s, width-1); 1141 decode_bgr_bitstream(s, width-1);
1139 s->dsp.add_hfyu_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width-1, &leftr, &leftg, &leftb); 1142 s->dsp.add_hfyu_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width-1, &leftr, &leftg, &leftb, &lefta);
1140 1143
1141 for(y=s->height-2; y>=0; y--){ //Yes it is stored upside down. 1144 for(y=s->height-2; y>=0; y--){ //Yes it is stored upside down.
1142 decode_bgr_bitstream(s, width); 1145 decode_bgr_bitstream(s, width);
1143 1146
1144 s->dsp.add_hfyu_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb); 1147 s->dsp.add_hfyu_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb, &lefta);
1145 if(s->predictor == PLANE){ 1148 if(s->predictor == PLANE){
1149 if(s->bitstream_bpp!=32) lefta=0;
1146 if((y&s->interlaced)==0 && y<s->height-1-s->interlaced){ 1150 if((y&s->interlaced)==0 && y<s->height-1-s->interlaced){
1147 s->dsp.add_bytes(p->data[0] + p->linesize[0]*y, 1151 s->dsp.add_bytes(p->data[0] + p->linesize[0]*y,
1148 p->data[0] + p->linesize[0]*y + fake_ystride, fake_ystride); 1152 p->data[0] + p->linesize[0]*y + fake_ystride, fake_ystride);
1149 } 1153 }
1150 } 1154 }