source:
trunk/Patches/ffmpeg-bgr24-huffyuv.diff
@
1198
| Revision 1198, 9.4 KB checked in by astrange, 4 years ago (diff) |
|---|
-
libavcodec/huffyuv.c
39 39 #define B 3 40 40 #define G 2 41 41 #define R 1 42 #define A 0 42 43 #else 43 44 #define B 0 44 45 #define G 1 45 46 #define R 2 47 #define A 3 46 48 #endif 47 49 48 50 typedef enum Predictor{ … … 61 63 int bitstream_bpp; 62 64 int version; 63 65 int yuy2; //use yuy2 instead of 422P 64 int bgr32; //use bgr32 instead of bgr2465 66 int width, height; 66 67 int flags; 67 68 int context; … … 406 407 s->temp[i]= av_malloc(s->width + 16); 407 408 } 408 409 }else{ 409 s->temp[0]= av_malloc(4*s->width + 16); 410 int bytes = (s->bitstream_bpp==24) ? 3 : 4; 411 s->temp[0]= av_malloc(bytes*s->width + 16); 410 412 } 411 413 } 412 414 … … 436 438 avctx->coded_frame= &s->picture; 437 439 s->interlaced= s->height > 288; 438 440 439 s->bgr32=1;440 441 //if(avctx->extradata) 441 442 // printf("extradata:%X, extradata_size:%d\n", *(uint32_t*)avctx->extradata, avctx->extradata_size); 442 443 if(avctx->extradata_size){ … … 504 505 } 505 506 break; 506 507 case 24: 508 avctx->pix_fmt = PIX_FMT_BGR24; 509 break; 507 510 case 32: 508 if(s->bgr32){ 509 avctx->pix_fmt = PIX_FMT_RGB32; 510 }else{ 511 avctx->pix_fmt = PIX_FMT_BGR24; 512 } 511 avctx->pix_fmt = PIX_FMT_RGB32; 513 512 break; 514 513 default: 515 514 assert(0); … … 820 819 } 821 820 #endif /* CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER */ 822 821 823 static av_always_inline void decode_bgr_1 (HYuvContext *s, int count, int decorrelate, int alpha){822 static av_always_inline void decode_bgr_1_32(HYuvContext *s, int count, int decorrelate){ 824 823 int i; 825 824 for(i=0; i<count; i++){ 826 825 int code = get_vlc2(&s->gb, s->vlc[3].table, VLC_BITS, 1); … … 835 834 s->temp[0][4*i+G] = get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); 836 835 s->temp[0][4*i+R] = get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); 837 836 } 838 if(alpha) 839 get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?! 837 s->temp[0][4*i+A] = get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); 840 838 } 841 839 } 842 840 841 static av_always_inline void decode_bgr_1_24(HYuvContext *s, int count, int decorrelate){ 842 int i; 843 for(i=0; i<count; i++){ 844 int code = get_vlc2(&s->gb, s->vlc[3].table, VLC_BITS, 1); 845 if(code != -1){ 846 *(uint32_t*)&s->temp[0][3*i] = AV_RL32(&s->pix_bgr_map[code]); 847 }else if(decorrelate){ 848 // B = 0, G = 1, R = 2 for BGR24 no matter the endianness 849 s->temp[0][3*i+1] = get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); 850 s->temp[0][3*i+0] = get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][3*i+1]; 851 s->temp[0][3*i+2] = get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][3*i+1]; 852 }else{ 853 s->temp[0][3*i+0] = get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); 854 s->temp[0][3*i+1] = get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); 855 s->temp[0][3*i+2] = get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); 856 } 857 } 858 } 859 843 860 static void decode_bgr_bitstream(HYuvContext *s, int count){ 844 861 if(s->decorrelate){ 845 862 if(s->bitstream_bpp==24) 846 decode_bgr_1 (s, count, 1, 0);863 decode_bgr_1_24(s, count, 1); 847 864 else 848 decode_bgr_1 (s, count, 1, 1);865 decode_bgr_1_32(s, count, 1); 849 866 }else{ 850 867 if(s->bitstream_bpp==24) 851 decode_bgr_1 (s, count, 0, 0);868 decode_bgr_1_24(s, count, 0); 852 869 else 853 decode_bgr_1 (s, count, 0, 1);870 decode_bgr_1_32(s, count, 0); 854 871 } 855 872 } 856 873 … … 1116 1133 } 1117 1134 }else{ 1118 1135 int y; 1119 int leftr, leftg, leftb ;1136 int leftr, leftg, leftb, lefta; 1120 1137 const int last_line= (height-1)*p->linesize[0]; 1121 1138 1122 1139 if(s->bitstream_bpp==32){ 1123 skip_bits(&s->gb, 8);1140 lefta= p->data[0][last_line+A]= get_bits(&s->gb, 8); 1124 1141 leftr= p->data[0][last_line+R]= get_bits(&s->gb, 8); 1125 1142 leftg= p->data[0][last_line+G]= get_bits(&s->gb, 8); 1126 1143 leftb= p->data[0][last_line+B]= get_bits(&s->gb, 8); 1127 1144 }else{ 1128 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);1130 leftb= p->data[0][last_line+ B]= get_bits(&s->gb, 8);1145 leftr= p->data[0][last_line+2]= get_bits(&s->gb, 8); 1146 leftg= p->data[0][last_line+1]= get_bits(&s->gb, 8); 1147 leftb= p->data[0][last_line+0]= get_bits(&s->gb, 8); 1131 1148 skip_bits(&s->gb, 8); 1132 1149 } 1133 1150 1134 if(s->bgr32){1135 1151 switch(s->predictor){ 1136 1152 case LEFT: 1137 1153 case PLANE: 1138 1154 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); 1155 if(s->bitstream_bpp==32) 1156 s->dsp.add_hfyu_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width-1, &leftr, &leftg, &leftb, &lefta); 1157 else 1158 s->dsp.add_hfyu_left_prediction_bgr24(p->data[0] + last_line+3, s->temp[0], width-1, &leftr, &leftg, &leftb); 1140 1159 1160 1141 1161 for(y=s->height-2; y>=0; y--){ //Yes it is stored upside down. 1142 1162 decode_bgr_bitstream(s, width); 1143 1163 1144 s->dsp.add_hfyu_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb); 1164 if(s->bitstream_bpp==32) 1165 s->dsp.add_hfyu_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb, &lefta); 1166 else 1167 s->dsp.add_hfyu_left_prediction_bgr24(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb); 1145 1168 if(s->predictor == PLANE){ 1146 1169 if((y&s->interlaced)==0 && y<s->height-1-s->interlaced){ 1147 1170 s->dsp.add_bytes(p->data[0] + p->linesize[0]*y, … … 1154 1177 default: 1155 1178 av_log(avctx, AV_LOG_ERROR, "prediction type not supported!\n"); 1156 1179 } 1157 }else{1158 1159 av_log(avctx, AV_LOG_ERROR, "BGR24 output is not implemented yet\n");1160 return -1;1161 }1162 1180 } 1163 1181 emms_c(); 1164 1182 -
libavcodec/dsputil.c
3627 3627 return acc; 3628 3628 } 3629 3629 3630 static inline void add_hfyu_left_prediction_bgr24_c(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue){ 3631 int i; 3632 int r,g,b; 3633 r= *red; 3634 g= *green; 3635 b= *blue; 3636 3637 for(i=0; i<w; i++){ 3638 b+= src[3*i+0]; 3639 g+= src[3*i+1]; 3640 r+= src[3*i+2]; 3641 3642 dst[3*i+0]= b; 3643 dst[3*i+1]= g; 3644 dst[3*i+2]= r; 3645 } 3646 3647 *red= r; 3648 *green= g; 3649 *blue= b; 3650 } 3651 3630 3652 #if HAVE_BIGENDIAN 3631 3653 #define B 3 3632 3654 #define G 2 3633 3655 #define R 1 3656 #define A 0 3634 3657 #else 3635 3658 #define B 0 3636 3659 #define G 1 3637 3660 #define R 2 3661 #define A 3 3638 3662 #endif 3639 static void add_hfyu_left_prediction_bgr32_c(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue ){3663 static void add_hfyu_left_prediction_bgr32_c(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha){ 3640 3664 int i; 3641 int r,g,b ;3665 int r,g,b,a; 3642 3666 r= *red; 3643 3667 g= *green; 3644 3668 b= *blue; 3669 a= *alpha; 3645 3670 3646 3671 for(i=0; i<w; i++){ 3647 3672 b+= src[4*i+B]; 3648 3673 g+= src[4*i+G]; 3649 3674 r+= src[4*i+R]; 3675 a+= src[4*i+A]; 3650 3676 3651 3677 dst[4*i+B]= b; 3652 3678 dst[4*i+G]= g; 3653 3679 dst[4*i+R]= r; 3680 dst[4*i+A]= a; 3654 3681 } 3655 3682 3656 3683 *red= r; 3657 3684 *green= g; 3658 3685 *blue= b; 3686 *alpha= a; 3659 3687 } 3660 3688 #undef B 3661 3689 #undef G 3662 3690 #undef R 3691 #undef A 3663 3692 3664 3693 #define BUTTERFLY2(o1,o2,i1,i2) \ 3665 3694 o1= (i1)+(i2);\ … … 4791 4820 c->add_hfyu_median_prediction= add_hfyu_median_prediction_c; 4792 4821 c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c; 4793 4822 c->add_hfyu_left_prediction = add_hfyu_left_prediction_c; 4823 c->add_hfyu_left_prediction_bgr24 = add_hfyu_left_prediction_bgr24_c; 4794 4824 c->add_hfyu_left_prediction_bgr32 = add_hfyu_left_prediction_bgr32_c; 4795 4825 c->bswap_buf= bswap_buf; 4796 4826 #if CONFIG_PNG_DECODER -
libavcodec/dsputil.h
350 350 void (*sub_hfyu_median_prediction)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top); 351 351 void (*add_hfyu_median_prediction)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top); 352 352 int (*add_hfyu_left_prediction)(uint8_t *dst, const uint8_t *src, int w, int left); 353 void (*add_hfyu_left_prediction_bgr32)(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue); 353 void (*add_hfyu_left_prediction_bgr24)(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue); 354 void (*add_hfyu_left_prediction_bgr32)(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha); 354 355 /* this might write to dst[w] */ 355 356 void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp); 356 357 void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
Note: See TracBrowser
for help on using the repository browser.
