Mercurial > libavcodec.hg
comparison huffyuv.c @ 10370:6009feb54020 libavcodec
Move HuffYUV left prediction to dsputil.
Patch by Nathan Caldwell, saintdev gmail
author | cehoyos |
---|---|
date | Tue, 06 Oct 2009 16:06:15 +0000 |
parents | 38cfe222e1a4 |
children | 9d31db7bec63 |
comparison
equal
deleted
inserted
replaced
10369:71a38fce15bc | 10370:6009feb54020 |
---|---|
126 7,128,127,105,123,116, 35, 34, 33,145, 31, 79, 42,146, 78, 26, | 126 7,128,127,105,123,116, 35, 34, 33,145, 31, 79, 42,146, 78, 26, |
127 83, 48, 49, 50, 44, 47, 26, 31, 30, 18, 17, 19, 21, 24, 25, 13, | 127 83, 48, 49, 50, 44, 47, 26, 31, 30, 18, 17, 19, 21, 24, 25, 13, |
128 14, 16, 17, 18, 20, 21, 12, 14, 15, 9, 10, 6, 9, 6, 5, 8, | 128 14, 16, 17, 18, 20, 21, 12, 14, 15, 9, 10, 6, 9, 6, 5, 8, |
129 6, 12, 8, 10, 7, 9, 6, 4, 6, 2, 2, 3, 3, 3, 3, 2, | 129 6, 12, 8, 10, 7, 9, 6, 4, 6, 2, 2, 3, 3, 3, 3, 2, |
130 }; | 130 }; |
131 | |
132 static inline int add_left_prediction(uint8_t *dst, uint8_t *src, int w, int acc){ | |
133 int i; | |
134 | |
135 for(i=0; i<w-1; i++){ | |
136 acc+= src[i]; | |
137 dst[i]= acc; | |
138 i++; | |
139 acc+= src[i]; | |
140 dst[i]= acc; | |
141 } | |
142 | |
143 for(; i<w; i++){ | |
144 acc+= src[i]; | |
145 dst[i]= acc; | |
146 } | |
147 | |
148 return acc; | |
149 } | |
150 | |
151 static inline void add_left_prediction_bgr32(uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue){ | |
152 int i; | |
153 int r,g,b; | |
154 r= *red; | |
155 g= *green; | |
156 b= *blue; | |
157 | |
158 for(i=0; i<w; i++){ | |
159 b+= src[4*i+B]; | |
160 g+= src[4*i+G]; | |
161 r+= src[4*i+R]; | |
162 | |
163 dst[4*i+B]= b; | |
164 dst[4*i+G]= g; | |
165 dst[4*i+R]= r; | |
166 } | |
167 | |
168 *red= r; | |
169 *green= g; | |
170 *blue= b; | |
171 } | |
172 | 131 |
173 static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int left){ | 132 static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int left){ |
174 int i; | 133 int i; |
175 if(w<32){ | 134 if(w<32){ |
176 for(i=0; i<w; i++){ | 135 for(i=0; i<w; i++){ |
1033 | 992 |
1034 switch(s->predictor){ | 993 switch(s->predictor){ |
1035 case LEFT: | 994 case LEFT: |
1036 case PLANE: | 995 case PLANE: |
1037 decode_422_bitstream(s, width-2); | 996 decode_422_bitstream(s, width-2); |
1038 lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); | 997 lefty= s->dsp.add_hfyu_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); |
1039 if(!(s->flags&CODEC_FLAG_GRAY)){ | 998 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1040 leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); | 999 leftu= s->dsp.add_hfyu_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); |
1041 leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); | 1000 leftv= s->dsp.add_hfyu_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); |
1042 } | 1001 } |
1043 | 1002 |
1044 for(cy=y=1; y<s->height; y++,cy++){ | 1003 for(cy=y=1; y<s->height; y++,cy++){ |
1045 uint8_t *ydst, *udst, *vdst; | 1004 uint8_t *ydst, *udst, *vdst; |
1046 | 1005 |
1047 if(s->bitstream_bpp==12){ | 1006 if(s->bitstream_bpp==12){ |
1048 decode_gray_bitstream(s, width); | 1007 decode_gray_bitstream(s, width); |
1049 | 1008 |
1050 ydst= p->data[0] + p->linesize[0]*y; | 1009 ydst= p->data[0] + p->linesize[0]*y; |
1051 | 1010 |
1052 lefty= add_left_prediction(ydst, s->temp[0], width, lefty); | 1011 lefty= s->dsp.add_hfyu_left_prediction(ydst, s->temp[0], width, lefty); |
1053 if(s->predictor == PLANE){ | 1012 if(s->predictor == PLANE){ |
1054 if(y>s->interlaced) | 1013 if(y>s->interlaced) |
1055 s->dsp.add_bytes(ydst, ydst - fake_ystride, width); | 1014 s->dsp.add_bytes(ydst, ydst - fake_ystride, width); |
1056 } | 1015 } |
1057 y++; | 1016 y++; |
1063 ydst= p->data[0] + p->linesize[0]*y; | 1022 ydst= p->data[0] + p->linesize[0]*y; |
1064 udst= p->data[1] + p->linesize[1]*cy; | 1023 udst= p->data[1] + p->linesize[1]*cy; |
1065 vdst= p->data[2] + p->linesize[2]*cy; | 1024 vdst= p->data[2] + p->linesize[2]*cy; |
1066 | 1025 |
1067 decode_422_bitstream(s, width); | 1026 decode_422_bitstream(s, width); |
1068 lefty= add_left_prediction(ydst, s->temp[0], width, lefty); | 1027 lefty= s->dsp.add_hfyu_left_prediction(ydst, s->temp[0], width, lefty); |
1069 if(!(s->flags&CODEC_FLAG_GRAY)){ | 1028 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1070 leftu= add_left_prediction(udst, s->temp[1], width2, leftu); | 1029 leftu= s->dsp.add_hfyu_left_prediction(udst, s->temp[1], width2, leftu); |
1071 leftv= add_left_prediction(vdst, s->temp[2], width2, leftv); | 1030 leftv= s->dsp.add_hfyu_left_prediction(vdst, s->temp[2], width2, leftv); |
1072 } | 1031 } |
1073 if(s->predictor == PLANE){ | 1032 if(s->predictor == PLANE){ |
1074 if(cy>s->interlaced){ | 1033 if(cy>s->interlaced){ |
1075 s->dsp.add_bytes(ydst, ydst - fake_ystride, width); | 1034 s->dsp.add_bytes(ydst, ydst - fake_ystride, width); |
1076 if(!(s->flags&CODEC_FLAG_GRAY)){ | 1035 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1084 | 1043 |
1085 break; | 1044 break; |
1086 case MEDIAN: | 1045 case MEDIAN: |
1087 /* first line except first 2 pixels is left predicted */ | 1046 /* first line except first 2 pixels is left predicted */ |
1088 decode_422_bitstream(s, width-2); | 1047 decode_422_bitstream(s, width-2); |
1089 lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); | 1048 lefty= s->dsp.add_hfyu_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); |
1090 if(!(s->flags&CODEC_FLAG_GRAY)){ | 1049 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1091 leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); | 1050 leftu= s->dsp.add_hfyu_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); |
1092 leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); | 1051 leftv= s->dsp.add_hfyu_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); |
1093 } | 1052 } |
1094 | 1053 |
1095 cy=y=1; | 1054 cy=y=1; |
1096 | 1055 |
1097 /* second line is left predicted for interlaced case */ | 1056 /* second line is left predicted for interlaced case */ |
1098 if(s->interlaced){ | 1057 if(s->interlaced){ |
1099 decode_422_bitstream(s, width); | 1058 decode_422_bitstream(s, width); |
1100 lefty= add_left_prediction(p->data[0] + p->linesize[0], s->temp[0], width, lefty); | 1059 lefty= s->dsp.add_hfyu_left_prediction(p->data[0] + p->linesize[0], s->temp[0], width, lefty); |
1101 if(!(s->flags&CODEC_FLAG_GRAY)){ | 1060 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1102 leftu= add_left_prediction(p->data[1] + p->linesize[2], s->temp[1], width2, leftu); | 1061 leftu= s->dsp.add_hfyu_left_prediction(p->data[1] + p->linesize[2], s->temp[1], width2, leftu); |
1103 leftv= add_left_prediction(p->data[2] + p->linesize[1], s->temp[2], width2, leftv); | 1062 leftv= s->dsp.add_hfyu_left_prediction(p->data[2] + p->linesize[1], s->temp[2], width2, leftv); |
1104 } | 1063 } |
1105 y++; cy++; | 1064 y++; cy++; |
1106 } | 1065 } |
1107 | 1066 |
1108 /* next 4 pixels are left predicted too */ | 1067 /* next 4 pixels are left predicted too */ |
1109 decode_422_bitstream(s, 4); | 1068 decode_422_bitstream(s, 4); |
1110 lefty= add_left_prediction(p->data[0] + fake_ystride, s->temp[0], 4, lefty); | 1069 lefty= s->dsp.add_hfyu_left_prediction(p->data[0] + fake_ystride, s->temp[0], 4, lefty); |
1111 if(!(s->flags&CODEC_FLAG_GRAY)){ | 1070 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1112 leftu= add_left_prediction(p->data[1] + fake_ustride, s->temp[1], 2, leftu); | 1071 leftu= s->dsp.add_hfyu_left_prediction(p->data[1] + fake_ustride, s->temp[1], 2, leftu); |
1113 leftv= add_left_prediction(p->data[2] + fake_vstride, s->temp[2], 2, leftv); | 1072 leftv= s->dsp.add_hfyu_left_prediction(p->data[2] + fake_vstride, s->temp[2], 2, leftv); |
1114 } | 1073 } |
1115 | 1074 |
1116 /* next line except the first 4 pixels is median predicted */ | 1075 /* next line except the first 4 pixels is median predicted */ |
1117 lefttopy= p->data[0][3]; | 1076 lefttopy= p->data[0][3]; |
1118 decode_422_bitstream(s, width-4); | 1077 decode_422_bitstream(s, width-4); |
1176 if(s->bgr32){ | 1135 if(s->bgr32){ |
1177 switch(s->predictor){ | 1136 switch(s->predictor){ |
1178 case LEFT: | 1137 case LEFT: |
1179 case PLANE: | 1138 case PLANE: |
1180 decode_bgr_bitstream(s, width-1); | 1139 decode_bgr_bitstream(s, width-1); |
1181 add_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width-1, &leftr, &leftg, &leftb); | 1140 s->dsp.add_hfyu_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width-1, &leftr, &leftg, &leftb); |
1182 | 1141 |
1183 for(y=s->height-2; y>=0; y--){ //Yes it is stored upside down. | 1142 for(y=s->height-2; y>=0; y--){ //Yes it is stored upside down. |
1184 decode_bgr_bitstream(s, width); | 1143 decode_bgr_bitstream(s, width); |
1185 | 1144 |
1186 add_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb); | 1145 s->dsp.add_hfyu_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb); |
1187 if(s->predictor == PLANE){ | 1146 if(s->predictor == PLANE){ |
1188 if((y&s->interlaced)==0 && y<s->height-1-s->interlaced){ | 1147 if((y&s->interlaced)==0 && y<s->height-1-s->interlaced){ |
1189 s->dsp.add_bytes(p->data[0] + p->linesize[0]*y, | 1148 s->dsp.add_bytes(p->data[0] + p->linesize[0]*y, |
1190 p->data[0] + p->linesize[0]*y + fake_ystride, fake_ystride); | 1149 p->data[0] + p->linesize[0]*y + fake_ystride, fake_ystride); |
1191 } | 1150 } |