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