Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__H264__App
diff libavcodec/h264_idct.c @ 2:897f711a7157
rearrange to work with autoconf
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 25 Sep 2012 15:55:33 +0200 |
| parents | |
| children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libavcodec/h264_idct.c Tue Sep 25 15:55:33 2012 +0200 1.3 @@ -0,0 +1,270 @@ 1.4 +/* 1.5 + * H.264 IDCT 1.6 + * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> 1.7 + * 1.8 + * This file is part of FFmpeg. 1.9 + * 1.10 + * FFmpeg is free software; you can redistribute it and/or 1.11 + * modify it under the terms of the GNU Lesser General Public 1.12 + * License as published by the Free Software Foundation; either 1.13 + * version 2.1 of the License, or (at your option) any later version. 1.14 + * 1.15 + * FFmpeg is distributed in the hope that it will be useful, 1.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1.18 + * Lesser General Public License for more details. 1.19 + * 1.20 + * You should have received a copy of the GNU Lesser General Public 1.21 + * License along with FFmpeg; if not, write to the Free Software 1.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 1.23 + */ 1.24 + 1.25 +/** 1.26 + * @file 1.27 + * H.264 IDCT. 1.28 + * @author Michael Niedermayer <michaelni@gmx.at> 1.29 + */ 1.30 + 1.31 +#include "dsputil.h" 1.32 +#include "h264_data.h" 1.33 + 1.34 +static av_always_inline void idct_internal(uint8_t *dst, DCTELEM *block, int stride, int block_stride, int shift, int add){ 1.35 + int i; 1.36 + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; 1.37 + 1.38 + block[0] += 1<<(shift-1); 1.39 + 1.40 + for(i=0; i<4; i++){ 1.41 + const int z0= block[0 + block_stride*i] + block[2 + block_stride*i]; 1.42 + const int z1= block[0 + block_stride*i] - block[2 + block_stride*i]; 1.43 + const int z2= (block[1 + block_stride*i]>>1) - block[3 + block_stride*i]; 1.44 + const int z3= block[1 + block_stride*i] + (block[3 + block_stride*i]>>1); 1.45 + 1.46 + block[0 + block_stride*i]= z0 + z3; 1.47 + block[1 + block_stride*i]= z1 + z2; 1.48 + block[2 + block_stride*i]= z1 - z2; 1.49 + block[3 + block_stride*i]= z0 - z3; 1.50 + } 1.51 + 1.52 + for(i=0; i<4; i++){ 1.53 + const int z0= block[i + block_stride*0] + block[i + block_stride*2]; 1.54 + const int z1= block[i + block_stride*0] - block[i + block_stride*2]; 1.55 + const int z2= (block[i + block_stride*1]>>1) - block[i + block_stride*3]; 1.56 + const int z3= block[i + block_stride*1] + (block[i + block_stride*3]>>1); 1.57 + 1.58 + dst[i + 0*stride]= cm[ add*dst[i + 0*stride] + ((z0 + z3) >> shift) ]; 1.59 + dst[i + 1*stride]= cm[ add*dst[i + 1*stride] + ((z1 + z2) >> shift) ]; 1.60 + dst[i + 2*stride]= cm[ add*dst[i + 2*stride] + ((z1 - z2) >> shift) ]; 1.61 + dst[i + 3*stride]= cm[ add*dst[i + 3*stride] + ((z0 - z3) >> shift) ]; 1.62 + } 1.63 +} 1.64 + 1.65 +void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride){ 1.66 + idct_internal(dst, block, stride, 4, 6, 1); 1.67 +} 1.68 + 1.69 +void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block){ 1.70 + idct_internal(dst, block, stride, 8, 3, 1); 1.71 +} 1.72 + 1.73 +void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block){ 1.74 + idct_internal(dst, block, stride, 8, 3, 0); 1.75 +} 1.76 + 1.77 +void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride){ 1.78 + int i; 1.79 + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; 1.80 + 1.81 + block[0] += 32; 1.82 + 1.83 + for( i = 0; i < 8; i++ ) 1.84 + { 1.85 + const int a0 = block[0+i*8] + block[4+i*8]; 1.86 + const int a2 = block[0+i*8] - block[4+i*8]; 1.87 + const int a4 = (block[2+i*8]>>1) - block[6+i*8]; 1.88 + const int a6 = (block[6+i*8]>>1) + block[2+i*8]; 1.89 + 1.90 + const int b0 = a0 + a6; 1.91 + const int b2 = a2 + a4; 1.92 + const int b4 = a2 - a4; 1.93 + const int b6 = a0 - a6; 1.94 + 1.95 + const int a1 = -block[3+i*8] + block[5+i*8] - block[7+i*8] - (block[7+i*8]>>1); 1.96 + const int a3 = block[1+i*8] + block[7+i*8] - block[3+i*8] - (block[3+i*8]>>1); 1.97 + const int a5 = -block[1+i*8] + block[7+i*8] + block[5+i*8] + (block[5+i*8]>>1); 1.98 + const int a7 = block[3+i*8] + block[5+i*8] + block[1+i*8] + (block[1+i*8]>>1); 1.99 + 1.100 + const int b1 = (a7>>2) + a1; 1.101 + const int b3 = a3 + (a5>>2); 1.102 + const int b5 = (a3>>2) - a5; 1.103 + const int b7 = a7 - (a1>>2); 1.104 + 1.105 + block[0+i*8] = b0 + b7; 1.106 + block[7+i*8] = b0 - b7; 1.107 + block[1+i*8] = b2 + b5; 1.108 + block[6+i*8] = b2 - b5; 1.109 + block[2+i*8] = b4 + b3; 1.110 + block[5+i*8] = b4 - b3; 1.111 + block[3+i*8] = b6 + b1; 1.112 + block[4+i*8] = b6 - b1; 1.113 + } 1.114 + for( i = 0; i < 8; i++ ) 1.115 + { 1.116 + const int a0 = block[i+0*8] + block[i+4*8]; 1.117 + const int a2 = block[i+0*8] - block[i+4*8]; 1.118 + const int a4 = (block[i+2*8]>>1) - block[i+6*8]; 1.119 + const int a6 = (block[i+6*8]>>1) + block[i+2*8]; 1.120 + 1.121 + const int b0 = a0 + a6; 1.122 + const int b2 = a2 + a4; 1.123 + const int b4 = a2 - a4; 1.124 + const int b6 = a0 - a6; 1.125 + 1.126 + const int a1 = -block[i+3*8] + block[i+5*8] - block[i+7*8] - (block[i+7*8]>>1); 1.127 + const int a3 = block[i+1*8] + block[i+7*8] - block[i+3*8] - (block[i+3*8]>>1); 1.128 + const int a5 = -block[i+1*8] + block[i+7*8] + block[i+5*8] + (block[i+5*8]>>1); 1.129 + const int a7 = block[i+3*8] + block[i+5*8] + block[i+1*8] + (block[i+1*8]>>1); 1.130 + 1.131 + const int b1 = (a7>>2) + a1; 1.132 + const int b3 = a3 + (a5>>2); 1.133 + const int b5 = (a3>>2) - a5; 1.134 + const int b7 = a7 - (a1>>2); 1.135 + 1.136 + dst[i + 0*stride] = cm[ dst[i + 0*stride] + ((b0 + b7) >> 6) ]; 1.137 + dst[i + 1*stride] = cm[ dst[i + 1*stride] + ((b2 + b5) >> 6) ]; 1.138 + dst[i + 2*stride] = cm[ dst[i + 2*stride] + ((b4 + b3) >> 6) ]; 1.139 + dst[i + 3*stride] = cm[ dst[i + 3*stride] + ((b6 + b1) >> 6) ]; 1.140 + dst[i + 4*stride] = cm[ dst[i + 4*stride] + ((b6 - b1) >> 6) ]; 1.141 + dst[i + 5*stride] = cm[ dst[i + 5*stride] + ((b4 - b3) >> 6) ]; 1.142 + dst[i + 6*stride] = cm[ dst[i + 6*stride] + ((b2 - b5) >> 6) ]; 1.143 + dst[i + 7*stride] = cm[ dst[i + 7*stride] + ((b0 - b7) >> 6) ]; 1.144 + } 1.145 +} 1.146 + 1.147 +// assumes all AC coefs are 0 1.148 +void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride){ 1.149 + int i, j; 1.150 + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; 1.151 + int dc = (block[0] + 32) >> 6; 1.152 + for( j = 0; j < 4; j++ ) 1.153 + { 1.154 + for( i = 0; i < 4; i++ ) 1.155 + dst[i] = cm[ dst[i] + dc ]; 1.156 + dst += stride; 1.157 + } 1.158 +} 1.159 + 1.160 +void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride){ 1.161 + int i, j; 1.162 + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; 1.163 + int dc = (block[0] + 32) >> 6; 1.164 + for( j = 0; j < 8; j++ ) 1.165 + { 1.166 + for( i = 0; i < 8; i++ ) 1.167 + dst[i] = cm[ dst[i] + dc ]; 1.168 + dst += stride; 1.169 + } 1.170 +} 1.171 + 1.172 +void ff_h264_idct_add16_c(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){ 1.173 + int i; 1.174 + for(i=0; i<16; i++){ 1.175 + int nnz = nnzc[ scan8[i] ]; 1.176 + if(nnz){ 1.177 + if(nnz==1 && block[i*16]) ff_h264_idct_dc_add_c(dst + block_offset[i], block + i*16, stride); 1.178 + else idct_internal (dst + block_offset[i], block + i*16, stride, 4, 6, 1); 1.179 + } 1.180 + } 1.181 +} 1.182 + 1.183 +void ff_h264_idct_add16intra_c(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){ 1.184 + int i; 1.185 + for(i=0; i<16; i++){ 1.186 + if(nnzc[ scan8[i] ]) idct_internal (dst + block_offset[i], block + i*16, stride, 4, 6, 1); 1.187 + else if(block[i*16]) ff_h264_idct_dc_add_c(dst + block_offset[i], block + i*16, stride); 1.188 + } 1.189 +} 1.190 + 1.191 +void ff_h264_idct8_add4_c(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){ 1.192 + int i; 1.193 + for(i=0; i<16; i+=4){ 1.194 + int nnz = nnzc[ scan8[i] ]; 1.195 + if(nnz){ 1.196 + if(nnz==1 && block[i*16]) ff_h264_idct8_dc_add_c(dst + block_offset[i], block + i*16, stride); 1.197 + else ff_h264_idct8_add_c (dst + block_offset[i], block + i*16, stride); 1.198 + } 1.199 + } 1.200 +} 1.201 + 1.202 +void ff_h264_idct_add8_c(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){ 1.203 + int i; 1.204 + for(i=16; i<16+8; i++){ 1.205 + if(nnzc[ scan8[i] ]) 1.206 + ff_h264_idct_add_c (dest[(i&4)>>2] + block_offset[i], block + i*16, stride); 1.207 + else if(block[i*16]) 1.208 + ff_h264_idct_dc_add_c(dest[(i&4)>>2] + block_offset[i], block + i*16, stride); 1.209 + } 1.210 +} 1.211 + 1.212 +/** 1.213 +* IDCT transforms the 16 dc values and dequantizes them. 1.214 +* @param qp quantization parameter 1.215 +*/ 1.216 +void h264_luma_dc_dequant_idct_c(DCTELEM *block, int qmul){ 1.217 + #define stride 16 1.218 + int i; 1.219 + int temp[16]; //FIXME check if this is a good idea 1.220 + static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride}; 1.221 + static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride}; 1.222 + 1.223 + //return; 1.224 + for(i=0; i<4; i++){ 1.225 + const int offset= y_offset[i]; 1.226 + const int z0= block[offset+stride*0] + block[offset+stride*4]; 1.227 + const int z1= block[offset+stride*0] - block[offset+stride*4]; 1.228 + const int z2= block[offset+stride*1] - block[offset+stride*5]; 1.229 + const int z3= block[offset+stride*1] + block[offset+stride*5]; 1.230 + 1.231 + temp[4*i+0]= z0+z3; 1.232 + temp[4*i+1]= z1+z2; 1.233 + temp[4*i+2]= z1-z2; 1.234 + temp[4*i+3]= z0-z3; 1.235 + } 1.236 + 1.237 + for(i=0; i<4; i++){ 1.238 + const int offset= x_offset[i]; 1.239 + const int z0= temp[4*0+i] + temp[4*2+i]; 1.240 + const int z1= temp[4*0+i] - temp[4*2+i]; 1.241 + const int z2= temp[4*1+i] - temp[4*3+i]; 1.242 + const int z3= temp[4*1+i] + temp[4*3+i]; 1.243 + 1.244 + block[stride*0 +offset]= ((((z0 + z3)*qmul + 128 ) >> 8)); //FIXME think about merging this into decode_residual 1.245 + block[stride*2 +offset]= ((((z1 + z2)*qmul + 128 ) >> 8)); 1.246 + block[stride*8 +offset]= ((((z1 - z2)*qmul + 128 ) >> 8)); 1.247 + block[stride*10+offset]= ((((z0 - z3)*qmul + 128 ) >> 8)); 1.248 + } 1.249 +} 1.250 + 1.251 +#undef xStride 1.252 +#undef stride 1.253 + 1.254 +void chroma_dc_dequant_idct_c(DCTELEM *block, int qmul){ 1.255 + const int stride= 16*2; 1.256 + const int xStride= 16; 1.257 + int a,b,c,d,e; 1.258 + 1.259 + a= block[stride*0 + xStride*0]; 1.260 + b= block[stride*0 + xStride*1]; 1.261 + c= block[stride*1 + xStride*0]; 1.262 + d= block[stride*1 + xStride*1]; 1.263 + 1.264 + e= a-b; 1.265 + a= a+b; 1.266 + b= c-d; 1.267 + c= c+d; 1.268 + 1.269 + block[stride*0 + xStride*0]= ((a+c)*qmul) >> 7; 1.270 + block[stride*0 + xStride*1]= ((e+b)*qmul) >> 7; 1.271 + block[stride*1 + xStride*0]= ((a-c)*qmul) >> 7; 1.272 + block[stride*1 + xStride*1]= ((e-b)*qmul) >> 7; 1.273 +}
