00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00028 #include "bit_depth_template.c"
00029
00030 #ifndef AVCODEC_H264IDCT_INTERNAL_H
00031 #define AVCODEC_H264IDCT_INTERNAL_H
00032
00033 static const uint8_t scan8[16*3]={
00034 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8,
00035 6+ 1*8, 7+ 1*8, 6+ 2*8, 7+ 2*8,
00036 4+ 3*8, 5+ 3*8, 4+ 4*8, 5+ 4*8,
00037 6+ 3*8, 7+ 3*8, 6+ 4*8, 7+ 4*8,
00038 4+ 6*8, 5+ 6*8, 4+ 7*8, 5+ 7*8,
00039 6+ 6*8, 7+ 6*8, 6+ 7*8, 7+ 7*8,
00040 4+ 8*8, 5+ 8*8, 4+ 9*8, 5+ 9*8,
00041 6+ 8*8, 7+ 8*8, 6+ 9*8, 7+ 9*8,
00042 4+11*8, 5+11*8, 4+12*8, 5+12*8,
00043 6+11*8, 7+11*8, 6+12*8, 7+12*8,
00044 4+13*8, 5+13*8, 4+14*8, 5+14*8,
00045 6+13*8, 7+13*8, 6+14*8, 7+14*8
00046 };
00047 #endif
00048
00049 void FUNCC(ff_h264_idct_add)(uint8_t *_dst, DCTELEM *_block, int stride)
00050 {
00051 int i;
00052 INIT_CLIP
00053 pixel *dst = (pixel*)_dst;
00054 dctcoef *block = (dctcoef*)_block;
00055 stride >>= sizeof(pixel)-1;
00056
00057 block[0] += 1 << 5;
00058
00059 for(i=0; i<4; i++){
00060 const int z0= block[i + 4*0] + block[i + 4*2];
00061 const int z1= block[i + 4*0] - block[i + 4*2];
00062 const int z2= (block[i + 4*1]>>1) - block[i + 4*3];
00063 const int z3= block[i + 4*1] + (block[i + 4*3]>>1);
00064
00065 block[i + 4*0]= z0 + z3;
00066 block[i + 4*1]= z1 + z2;
00067 block[i + 4*2]= z1 - z2;
00068 block[i + 4*3]= z0 - z3;
00069 }
00070
00071 for(i=0; i<4; i++){
00072 const int z0= block[0 + 4*i] + block[2 + 4*i];
00073 const int z1= block[0 + 4*i] - block[2 + 4*i];
00074 const int z2= (block[1 + 4*i]>>1) - block[3 + 4*i];
00075 const int z3= block[1 + 4*i] + (block[3 + 4*i]>>1);
00076
00077 dst[i + 0*stride]= CLIP(dst[i + 0*stride] + ((z0 + z3) >> 6));
00078 dst[i + 1*stride]= CLIP(dst[i + 1*stride] + ((z1 + z2) >> 6));
00079 dst[i + 2*stride]= CLIP(dst[i + 2*stride] + ((z1 - z2) >> 6));
00080 dst[i + 3*stride]= CLIP(dst[i + 3*stride] + ((z0 - z3) >> 6));
00081 }
00082 }
00083
00084 void FUNCC(ff_h264_idct8_add)(uint8_t *_dst, DCTELEM *_block, int stride){
00085 int i;
00086 INIT_CLIP
00087 pixel *dst = (pixel*)_dst;
00088 dctcoef *block = (dctcoef*)_block;
00089 stride >>= sizeof(pixel)-1;
00090
00091 block[0] += 32;
00092
00093 for( i = 0; i < 8; i++ )
00094 {
00095 const int a0 = block[i+0*8] + block[i+4*8];
00096 const int a2 = block[i+0*8] - block[i+4*8];
00097 const int a4 = (block[i+2*8]>>1) - block[i+6*8];
00098 const int a6 = (block[i+6*8]>>1) + block[i+2*8];
00099
00100 const int b0 = a0 + a6;
00101 const int b2 = a2 + a4;
00102 const int b4 = a2 - a4;
00103 const int b6 = a0 - a6;
00104
00105 const int a1 = -block[i+3*8] + block[i+5*8] - block[i+7*8] - (block[i+7*8]>>1);
00106 const int a3 = block[i+1*8] + block[i+7*8] - block[i+3*8] - (block[i+3*8]>>1);
00107 const int a5 = -block[i+1*8] + block[i+7*8] + block[i+5*8] + (block[i+5*8]>>1);
00108 const int a7 = block[i+3*8] + block[i+5*8] + block[i+1*8] + (block[i+1*8]>>1);
00109
00110 const int b1 = (a7>>2) + a1;
00111 const int b3 = a3 + (a5>>2);
00112 const int b5 = (a3>>2) - a5;
00113 const int b7 = a7 - (a1>>2);
00114
00115 block[i+0*8] = b0 + b7;
00116 block[i+7*8] = b0 - b7;
00117 block[i+1*8] = b2 + b5;
00118 block[i+6*8] = b2 - b5;
00119 block[i+2*8] = b4 + b3;
00120 block[i+5*8] = b4 - b3;
00121 block[i+3*8] = b6 + b1;
00122 block[i+4*8] = b6 - b1;
00123 }
00124 for( i = 0; i < 8; i++ )
00125 {
00126 const int a0 = block[0+i*8] + block[4+i*8];
00127 const int a2 = block[0+i*8] - block[4+i*8];
00128 const int a4 = (block[2+i*8]>>1) - block[6+i*8];
00129 const int a6 = (block[6+i*8]>>1) + block[2+i*8];
00130
00131 const int b0 = a0 + a6;
00132 const int b2 = a2 + a4;
00133 const int b4 = a2 - a4;
00134 const int b6 = a0 - a6;
00135
00136 const int a1 = -block[3+i*8] + block[5+i*8] - block[7+i*8] - (block[7+i*8]>>1);
00137 const int a3 = block[1+i*8] + block[7+i*8] - block[3+i*8] - (block[3+i*8]>>1);
00138 const int a5 = -block[1+i*8] + block[7+i*8] + block[5+i*8] + (block[5+i*8]>>1);
00139 const int a7 = block[3+i*8] + block[5+i*8] + block[1+i*8] + (block[1+i*8]>>1);
00140
00141 const int b1 = (a7>>2) + a1;
00142 const int b3 = a3 + (a5>>2);
00143 const int b5 = (a3>>2) - a5;
00144 const int b7 = a7 - (a1>>2);
00145
00146 dst[i + 0*stride] = CLIP( dst[i + 0*stride] + ((b0 + b7) >> 6) );
00147 dst[i + 1*stride] = CLIP( dst[i + 1*stride] + ((b2 + b5) >> 6) );
00148 dst[i + 2*stride] = CLIP( dst[i + 2*stride] + ((b4 + b3) >> 6) );
00149 dst[i + 3*stride] = CLIP( dst[i + 3*stride] + ((b6 + b1) >> 6) );
00150 dst[i + 4*stride] = CLIP( dst[i + 4*stride] + ((b6 - b1) >> 6) );
00151 dst[i + 5*stride] = CLIP( dst[i + 5*stride] + ((b4 - b3) >> 6) );
00152 dst[i + 6*stride] = CLIP( dst[i + 6*stride] + ((b2 - b5) >> 6) );
00153 dst[i + 7*stride] = CLIP( dst[i + 7*stride] + ((b0 - b7) >> 6) );
00154 }
00155 }
00156
00157
00158 void FUNCC(ff_h264_idct_dc_add)(uint8_t *p_dst, DCTELEM *block, int stride){
00159 int i, j;
00160 int dc = (((dctcoef*)block)[0] + 32) >> 6;
00161 INIT_CLIP
00162 pixel *dst = (pixel*)p_dst;
00163 stride >>= sizeof(pixel)-1;
00164 for( j = 0; j < 4; j++ )
00165 {
00166 for( i = 0; i < 4; i++ )
00167 dst[i] = CLIP( dst[i] + dc );
00168 dst += stride;
00169 }
00170 }
00171
00172 void FUNCC(ff_h264_idct8_dc_add)(uint8_t *p_dst, DCTELEM *block, int stride){
00173 int i, j;
00174 int dc = (((dctcoef*)block)[0] + 32) >> 6;
00175 INIT_CLIP
00176 pixel *dst = (pixel*)p_dst;
00177 stride >>= sizeof(pixel)-1;
00178 for( j = 0; j < 8; j++ )
00179 {
00180 for( i = 0; i < 8; i++ )
00181 dst[i] = CLIP( dst[i] + dc );
00182 dst += stride;
00183 }
00184 }
00185
00186 void FUNCC(ff_h264_idct_add16)(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){
00187 int i;
00188 for(i=0; i<16; i++){
00189 int nnz = nnzc[ scan8[i] ];
00190 if(nnz){
00191 if(nnz==1 && ((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
00192 else FUNCC(ff_h264_idct_add )(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
00193 }
00194 }
00195 }
00196
00197 void FUNCC(ff_h264_idct_add16intra)(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){
00198 int i;
00199 for(i=0; i<16; i++){
00200 if(nnzc[ scan8[i] ]) FUNCC(ff_h264_idct_add )(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
00201 else if(((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
00202 }
00203 }
00204
00205 void FUNCC(ff_h264_idct8_add4)(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){
00206 int i;
00207 for(i=0; i<16; i+=4){
00208 int nnz = nnzc[ scan8[i] ];
00209 if(nnz){
00210 if(nnz==1 && ((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct8_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
00211 else FUNCC(ff_h264_idct8_add )(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
00212 }
00213 }
00214 }
00215
00216 void FUNCC(ff_h264_idct_add8)(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){
00217 int i, j;
00218 for(j=1; j<3; j++){
00219 for(i=j*16; i<j*16+4; i++){
00220 if(nnzc[ scan8[i] ])
00221 FUNCC(ff_h264_idct_add )(dest[j-1] + block_offset[i], block + i*16*sizeof(pixel), stride);
00222 else if(((dctcoef*)block)[i*16])
00223 FUNCC(ff_h264_idct_dc_add)(dest[j-1] + block_offset[i], block + i*16*sizeof(pixel), stride);
00224 }
00225 }
00226 }
00227
00228 void FUNCC(ff_h264_idct_add8_422)(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){
00229 int i, j;
00230
00231 for(j=1; j<3; j++){
00232 for(i=j*16; i<j*16+4; i++){
00233 if(nnzc[ scan8[i] ])
00234 FUNCC(ff_h264_idct_add )(dest[j-1] + block_offset[i], block + i*16*sizeof(pixel), stride);
00235 else if(((dctcoef*)block)[i*16])
00236 FUNCC(ff_h264_idct_dc_add)(dest[j-1] + block_offset[i], block + i*16*sizeof(pixel), stride);
00237 }
00238 }
00239
00240 for(j=1; j<3; j++){
00241 for(i=j*16+4; i<j*16+8; i++){
00242 if(nnzc[ scan8[i+4] ])
00243 FUNCC(ff_h264_idct_add )(dest[j-1] + block_offset[i+4], block + i*16*sizeof(pixel), stride);
00244 else if(((dctcoef*)block)[i*16])
00245 FUNCC(ff_h264_idct_dc_add)(dest[j-1] + block_offset[i+4], block + i*16*sizeof(pixel), stride);
00246 }
00247 }
00248 }
00249
00254 void FUNCC(ff_h264_luma_dc_dequant_idct)(DCTELEM *p_output, DCTELEM *p_input, int qmul){
00255 #define stride 16
00256 int i;
00257 int temp[16];
00258 static const uint8_t x_offset[4]={0, 2*stride, 8*stride, 10*stride};
00259 dctcoef *input = (dctcoef*)p_input;
00260 dctcoef *output = (dctcoef*)p_output;
00261
00262 for(i=0; i<4; i++){
00263 const int z0= input[4*i+0] + input[4*i+1];
00264 const int z1= input[4*i+0] - input[4*i+1];
00265 const int z2= input[4*i+2] - input[4*i+3];
00266 const int z3= input[4*i+2] + input[4*i+3];
00267
00268 temp[4*i+0]= z0+z3;
00269 temp[4*i+1]= z0-z3;
00270 temp[4*i+2]= z1-z2;
00271 temp[4*i+3]= z1+z2;
00272 }
00273
00274 for(i=0; i<4; i++){
00275 const int offset= x_offset[i];
00276 const int z0= temp[4*0+i] + temp[4*2+i];
00277 const int z1= temp[4*0+i] - temp[4*2+i];
00278 const int z2= temp[4*1+i] - temp[4*3+i];
00279 const int z3= temp[4*1+i] + temp[4*3+i];
00280
00281 output[stride* 0+offset]= ((((z0 + z3)*qmul + 128 ) >> 8));
00282 output[stride* 1+offset]= ((((z1 + z2)*qmul + 128 ) >> 8));
00283 output[stride* 4+offset]= ((((z1 - z2)*qmul + 128 ) >> 8));
00284 output[stride* 5+offset]= ((((z0 - z3)*qmul + 128 ) >> 8));
00285 }
00286 #undef stride
00287 }
00288
00289 void FUNCC(ff_h264_chroma422_dc_dequant_idct)(DCTELEM *_block, int qmul){
00290 const int stride= 16*2;
00291 const int xStride= 16;
00292 int i;
00293 int temp[8];
00294 static const uint8_t x_offset[2]={0, 16};
00295 dctcoef *block = (dctcoef*)_block;
00296
00297 for(i=0; i<4; i++){
00298 temp[2*i+0] = block[stride*i + xStride*0] + block[stride*i + xStride*1];
00299 temp[2*i+1] = block[stride*i + xStride*0] - block[stride*i + xStride*1];
00300 }
00301
00302 for(i=0; i<2; i++){
00303 const int offset= x_offset[i];
00304 const int z0= temp[2*0+i] + temp[2*2+i];
00305 const int z1= temp[2*0+i] - temp[2*2+i];
00306 const int z2= temp[2*1+i] - temp[2*3+i];
00307 const int z3= temp[2*1+i] + temp[2*3+i];
00308
00309 block[stride*0+offset]= ((z0 + z3)*qmul + 128) >> 8;
00310 block[stride*1+offset]= ((z1 + z2)*qmul + 128) >> 8;
00311 block[stride*2+offset]= ((z1 - z2)*qmul + 128) >> 8;
00312 block[stride*3+offset]= ((z0 - z3)*qmul + 128) >> 8;
00313 }
00314 }
00315
00316 void FUNCC(ff_h264_chroma_dc_dequant_idct)(DCTELEM *_block, int qmul){
00317 const int stride= 16*2;
00318 const int xStride= 16;
00319 int a,b,c,d,e;
00320 dctcoef *block = (dctcoef*)_block;
00321
00322 a= block[stride*0 + xStride*0];
00323 b= block[stride*0 + xStride*1];
00324 c= block[stride*1 + xStride*0];
00325 d= block[stride*1 + xStride*1];
00326
00327 e= a-b;
00328 a= a+b;
00329 b= c-d;
00330 c= c+d;
00331
00332 block[stride*0 + xStride*0]= ((a+c)*qmul) >> 7;
00333 block[stride*0 + xStride*1]= ((e+b)*qmul) >> 7;
00334 block[stride*1 + xStride*0]= ((a-c)*qmul) >> 7;
00335 block[stride*1 + xStride*1]= ((e-b)*qmul) >> 7;
00336 }