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