00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00028 #include "high_bit_depth.h"
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 static av_always_inline void FUNCC(idct_internal)(uint8_t *p_dst, DCTELEM *p_block, int stride, int block_stride, int shift, int add){
00050 int i;
00051 INIT_CLIP
00052 pixel *dst = (pixel*)p_dst;
00053 dctcoef *block = (dctcoef*)p_block;
00054 stride >>= sizeof(pixel)-1;
00055
00056 block[0] += 1<<(shift-1);
00057
00058 for(i=0; i<4; i++){
00059 const int z0= block[i + block_stride*0] + block[i + block_stride*2];
00060 const int z1= block[i + block_stride*0] - block[i + block_stride*2];
00061 const int z2= (block[i + block_stride*1]>>1) - block[i + block_stride*3];
00062 const int z3= block[i + block_stride*1] + (block[i + block_stride*3]>>1);
00063
00064 block[i + block_stride*0]= z0 + z3;
00065 block[i + block_stride*1]= z1 + z2;
00066 block[i + block_stride*2]= z1 - z2;
00067 block[i + block_stride*3]= z0 - z3;
00068 }
00069
00070 for(i=0; i<4; i++){
00071 const int z0= block[0 + block_stride*i] + block[2 + block_stride*i];
00072 const int z1= block[0 + block_stride*i] - block[2 + block_stride*i];
00073 const int z2= (block[1 + block_stride*i]>>1) - block[3 + block_stride*i];
00074 const int z3= block[1 + block_stride*i] + (block[3 + block_stride*i]>>1);
00075
00076 dst[i + 0*stride]= CLIP(add*dst[i + 0*stride] + ((z0 + z3) >> shift));
00077 dst[i + 1*stride]= CLIP(add*dst[i + 1*stride] + ((z1 + z2) >> shift));
00078 dst[i + 2*stride]= CLIP(add*dst[i + 2*stride] + ((z1 - z2) >> shift));
00079 dst[i + 3*stride]= CLIP(add*dst[i + 3*stride] + ((z0 - z3) >> shift));
00080 }
00081 }
00082
00083 void FUNCC(ff_h264_idct_add)(uint8_t *dst, DCTELEM *block, int stride){
00084 FUNCC(idct_internal)(dst, block, stride, 4, 6, 1);
00085 }
00086
00087 void FUNCC(ff_h264_lowres_idct_add)(uint8_t *dst, int stride, DCTELEM *block){
00088 FUNCC(idct_internal)(dst, block, stride, 8, 3, 1);
00089 }
00090
00091 void FUNCC(ff_h264_lowres_idct_put)(uint8_t *dst, int stride, DCTELEM *block){
00092 FUNCC(idct_internal)(dst, block, stride, 8, 3, 0);
00093 }
00094
00095 void FUNCC(ff_h264_idct8_add)(uint8_t *p_dst, DCTELEM *p_block, int stride){
00096 int i;
00097 INIT_CLIP
00098 pixel *dst = (pixel*)p_dst;
00099 dctcoef *block = (dctcoef*)p_block;
00100 stride >>= sizeof(pixel)-1;
00101
00102 block[0] += 32;
00103
00104 for( i = 0; i < 8; i++ )
00105 {
00106 const int a0 = block[i+0*8] + block[i+4*8];
00107 const int a2 = block[i+0*8] - block[i+4*8];
00108 const int a4 = (block[i+2*8]>>1) - block[i+6*8];
00109 const int a6 = (block[i+6*8]>>1) + block[i+2*8];
00110
00111 const int b0 = a0 + a6;
00112 const int b2 = a2 + a4;
00113 const int b4 = a2 - a4;
00114 const int b6 = a0 - a6;
00115
00116 const int a1 = -block[i+3*8] + block[i+5*8] - block[i+7*8] - (block[i+7*8]>>1);
00117 const int a3 = block[i+1*8] + block[i+7*8] - block[i+3*8] - (block[i+3*8]>>1);
00118 const int a5 = -block[i+1*8] + block[i+7*8] + block[i+5*8] + (block[i+5*8]>>1);
00119 const int a7 = block[i+3*8] + block[i+5*8] + block[i+1*8] + (block[i+1*8]>>1);
00120
00121 const int b1 = (a7>>2) + a1;
00122 const int b3 = a3 + (a5>>2);
00123 const int b5 = (a3>>2) - a5;
00124 const int b7 = a7 - (a1>>2);
00125
00126 block[i+0*8] = b0 + b7;
00127 block[i+7*8] = b0 - b7;
00128 block[i+1*8] = b2 + b5;
00129 block[i+6*8] = b2 - b5;
00130 block[i+2*8] = b4 + b3;
00131 block[i+5*8] = b4 - b3;
00132 block[i+3*8] = b6 + b1;
00133 block[i+4*8] = b6 - b1;
00134 }
00135 for( i = 0; i < 8; i++ )
00136 {
00137 const int a0 = block[0+i*8] + block[4+i*8];
00138 const int a2 = block[0+i*8] - block[4+i*8];
00139 const int a4 = (block[2+i*8]>>1) - block[6+i*8];
00140 const int a6 = (block[6+i*8]>>1) + block[2+i*8];
00141
00142 const int b0 = a0 + a6;
00143 const int b2 = a2 + a4;
00144 const int b4 = a2 - a4;
00145 const int b6 = a0 - a6;
00146
00147 const int a1 = -block[3+i*8] + block[5+i*8] - block[7+i*8] - (block[7+i*8]>>1);
00148 const int a3 = block[1+i*8] + block[7+i*8] - block[3+i*8] - (block[3+i*8]>>1);
00149 const int a5 = -block[1+i*8] + block[7+i*8] + block[5+i*8] + (block[5+i*8]>>1);
00150 const int a7 = block[3+i*8] + block[5+i*8] + block[1+i*8] + (block[1+i*8]>>1);
00151
00152 const int b1 = (a7>>2) + a1;
00153 const int b3 = a3 + (a5>>2);
00154 const int b5 = (a3>>2) - a5;
00155 const int b7 = a7 - (a1>>2);
00156
00157 dst[i + 0*stride] = CLIP( dst[i + 0*stride] + ((b0 + b7) >> 6) );
00158 dst[i + 1*stride] = CLIP( dst[i + 1*stride] + ((b2 + b5) >> 6) );
00159 dst[i + 2*stride] = CLIP( dst[i + 2*stride] + ((b4 + b3) >> 6) );
00160 dst[i + 3*stride] = CLIP( dst[i + 3*stride] + ((b6 + b1) >> 6) );
00161 dst[i + 4*stride] = CLIP( dst[i + 4*stride] + ((b6 - b1) >> 6) );
00162 dst[i + 5*stride] = CLIP( dst[i + 5*stride] + ((b4 - b3) >> 6) );
00163 dst[i + 6*stride] = CLIP( dst[i + 6*stride] + ((b2 - b5) >> 6) );
00164 dst[i + 7*stride] = CLIP( dst[i + 7*stride] + ((b0 - b7) >> 6) );
00165 }
00166 }
00167
00168
00169 void FUNCC(ff_h264_idct_dc_add)(uint8_t *p_dst, DCTELEM *block, int stride){
00170 int i, j;
00171 int dc = (((dctcoef*)block)[0] + 32) >> 6;
00172 INIT_CLIP
00173 pixel *dst = (pixel*)p_dst;
00174 stride >>= sizeof(pixel)-1;
00175 for( j = 0; j < 4; j++ )
00176 {
00177 for( i = 0; i < 4; i++ )
00178 dst[i] = CLIP( dst[i] + dc );
00179 dst += stride;
00180 }
00181 }
00182
00183 void FUNCC(ff_h264_idct8_dc_add)(uint8_t *p_dst, DCTELEM *block, int stride){
00184 int i, j;
00185 int dc = (((dctcoef*)block)[0] + 32) >> 6;
00186 INIT_CLIP
00187 pixel *dst = (pixel*)p_dst;
00188 stride >>= sizeof(pixel)-1;
00189 for( j = 0; j < 8; j++ )
00190 {
00191 for( i = 0; i < 8; i++ )
00192 dst[i] = CLIP( dst[i] + dc );
00193 dst += stride;
00194 }
00195 }
00196
00197 void FUNCC(ff_h264_idct_add16)(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 int nnz = nnzc[ scan8[i] ];
00201 if(nnz){
00202 if(nnz==1 && ((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
00203 else FUNCC(idct_internal )(dst + block_offset[i], block + i*16*sizeof(pixel), stride, 4, 6, 1);
00204 }
00205 }
00206 }
00207
00208 void FUNCC(ff_h264_idct_add16intra)(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){
00209 int i;
00210 for(i=0; i<16; i++){
00211 if(nnzc[ scan8[i] ]) FUNCC(idct_internal )(dst + block_offset[i], block + i*16*sizeof(pixel), stride, 4, 6, 1);
00212 else if(((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
00213 }
00214 }
00215
00216 void FUNCC(ff_h264_idct8_add4)(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){
00217 int i;
00218 for(i=0; i<16; i+=4){
00219 int nnz = nnzc[ scan8[i] ];
00220 if(nnz){
00221 if(nnz==1 && ((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct8_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
00222 else FUNCC(ff_h264_idct8_add )(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
00223 }
00224 }
00225 }
00226
00227 void FUNCC(ff_h264_idct_add8)(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){
00228 int i, j;
00229 for(j=1; j<3; j++){
00230 for(i=j*16; i<j*16+4; i++){
00231 if(nnzc[ scan8[i] ])
00232 FUNCC(ff_h264_idct_add )(dest[j-1] + block_offset[i], block + i*16*sizeof(pixel), stride);
00233 else if(((dctcoef*)block)[i*16])
00234 FUNCC(ff_h264_idct_dc_add)(dest[j-1] + block_offset[i], block + i*16*sizeof(pixel), stride);
00235 }
00236 }
00237 }
00241 void FUNCC(ff_h264_luma_dc_dequant_idct)(DCTELEM *p_output, DCTELEM *p_input, int qmul){
00242 #define stride 16
00243 int i;
00244 int temp[16];
00245 static const uint8_t x_offset[4]={0, 2*stride, 8*stride, 10*stride};
00246 dctcoef *input = (dctcoef*)p_input;
00247 dctcoef *output = (dctcoef*)p_output;
00248
00249 for(i=0; i<4; i++){
00250 const int z0= input[4*i+0] + input[4*i+1];
00251 const int z1= input[4*i+0] - input[4*i+1];
00252 const int z2= input[4*i+2] - input[4*i+3];
00253 const int z3= input[4*i+2] + input[4*i+3];
00254
00255 temp[4*i+0]= z0+z3;
00256 temp[4*i+1]= z0-z3;
00257 temp[4*i+2]= z1-z2;
00258 temp[4*i+3]= z1+z2;
00259 }
00260
00261 for(i=0; i<4; i++){
00262 const int offset= x_offset[i];
00263 const int z0= temp[4*0+i] + temp[4*2+i];
00264 const int z1= temp[4*0+i] - temp[4*2+i];
00265 const int z2= temp[4*1+i] - temp[4*3+i];
00266 const int z3= temp[4*1+i] + temp[4*3+i];
00267
00268 output[stride* 0+offset]= ((((z0 + z3)*qmul + 128 ) >> 8));
00269 output[stride* 1+offset]= ((((z1 + z2)*qmul + 128 ) >> 8));
00270 output[stride* 4+offset]= ((((z1 - z2)*qmul + 128 ) >> 8));
00271 output[stride* 5+offset]= ((((z0 - z3)*qmul + 128 ) >> 8));
00272 }
00273 #undef stride
00274 }
00275
00276 void FUNCC(ff_h264_chroma_dc_dequant_idct)(DCTELEM *p_block, int qmul){
00277 const int stride= 16*2;
00278 const int xStride= 16;
00279 int a,b,c,d,e;
00280 dctcoef *block = (dctcoef*)p_block;
00281
00282 a= block[stride*0 + xStride*0];
00283 b= block[stride*0 + xStride*1];
00284 c= block[stride*1 + xStride*0];
00285 d= block[stride*1 + xStride*1];
00286
00287 e= a-b;
00288 a= a+b;
00289 b= c-d;
00290 c= c+d;
00291
00292 block[stride*0 + xStride*0]= ((a+c)*qmul) >> 7;
00293 block[stride*0 + xStride*1]= ((e+b)*qmul) >> 7;
00294 block[stride*1 + xStride*0]= ((a-c)*qmul) >> 7;
00295 block[stride*1 + xStride*1]= ((e-b)*qmul) >> 7;
00296 }