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 #define op_scale1(x) block[x] = av_clip_pixel( (block[x]*weight + offset) >> log2_denom )
00031 #define op_scale2(x) dst[x] = av_clip_pixel( (src[x]*weights + dst[x]*weightd + offset) >> (log2_denom+1))
00032 #define H264_WEIGHT(W,H) \
00033 static void FUNCC(weight_h264_pixels ## W ## x ## H)(uint8_t *p_block, int stride, int log2_denom, int weight, int offset){ \
00034 int y; \
00035 pixel *block = (pixel*)p_block; \
00036 stride >>= sizeof(pixel)-1; \
00037 offset <<= (log2_denom + (BIT_DEPTH-8)); \
00038 if(log2_denom) offset += 1<<(log2_denom-1); \
00039 for(y=0; y<H; y++, block += stride){ \
00040 op_scale1(0); \
00041 op_scale1(1); \
00042 if(W==2) continue; \
00043 op_scale1(2); \
00044 op_scale1(3); \
00045 if(W==4) continue; \
00046 op_scale1(4); \
00047 op_scale1(5); \
00048 op_scale1(6); \
00049 op_scale1(7); \
00050 if(W==8) continue; \
00051 op_scale1(8); \
00052 op_scale1(9); \
00053 op_scale1(10); \
00054 op_scale1(11); \
00055 op_scale1(12); \
00056 op_scale1(13); \
00057 op_scale1(14); \
00058 op_scale1(15); \
00059 } \
00060 } \
00061 static void FUNCC(biweight_h264_pixels ## W ## x ## H)(uint8_t *_dst, uint8_t *_src, int stride, int log2_denom, int weightd, int weights, int offset){ \
00062 int y; \
00063 pixel *dst = (pixel*)_dst; \
00064 pixel *src = (pixel*)_src; \
00065 stride >>= sizeof(pixel)-1; \
00066 offset <<= (BIT_DEPTH-8); \
00067 offset = ((offset + 1) | 1) << log2_denom; \
00068 for(y=0; y<H; y++, dst += stride, src += stride){ \
00069 op_scale2(0); \
00070 op_scale2(1); \
00071 if(W==2) continue; \
00072 op_scale2(2); \
00073 op_scale2(3); \
00074 if(W==4) continue; \
00075 op_scale2(4); \
00076 op_scale2(5); \
00077 op_scale2(6); \
00078 op_scale2(7); \
00079 if(W==8) continue; \
00080 op_scale2(8); \
00081 op_scale2(9); \
00082 op_scale2(10); \
00083 op_scale2(11); \
00084 op_scale2(12); \
00085 op_scale2(13); \
00086 op_scale2(14); \
00087 op_scale2(15); \
00088 } \
00089 }
00090
00091 H264_WEIGHT(16,16)
00092 H264_WEIGHT(16,8)
00093 H264_WEIGHT(8,16)
00094 H264_WEIGHT(8,8)
00095 H264_WEIGHT(8,4)
00096 H264_WEIGHT(4,8)
00097 H264_WEIGHT(4,4)
00098 H264_WEIGHT(4,2)
00099 H264_WEIGHT(2,4)
00100 H264_WEIGHT(2,2)
00101
00102 #undef op_scale1
00103 #undef op_scale2
00104 #undef H264_WEIGHT
00105
00106 static av_always_inline av_flatten void FUNCC(h264_loop_filter_luma)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta, int8_t *tc0)
00107 {
00108 pixel *pix = (pixel*)p_pix;
00109 int i, d;
00110 xstride >>= sizeof(pixel)-1;
00111 ystride >>= sizeof(pixel)-1;
00112 alpha <<= BIT_DEPTH - 8;
00113 beta <<= BIT_DEPTH - 8;
00114 for( i = 0; i < 4; i++ ) {
00115 const int tc_orig = tc0[i] << (BIT_DEPTH - 8);
00116 if( tc_orig < 0 ) {
00117 pix += inner_iters*ystride;
00118 continue;
00119 }
00120 for( d = 0; d < inner_iters; d++ ) {
00121 const int p0 = pix[-1*xstride];
00122 const int p1 = pix[-2*xstride];
00123 const int p2 = pix[-3*xstride];
00124 const int q0 = pix[0];
00125 const int q1 = pix[1*xstride];
00126 const int q2 = pix[2*xstride];
00127
00128 if( FFABS( p0 - q0 ) < alpha &&
00129 FFABS( p1 - p0 ) < beta &&
00130 FFABS( q1 - q0 ) < beta ) {
00131
00132 int tc = tc_orig;
00133 int i_delta;
00134
00135 if( FFABS( p2 - p0 ) < beta ) {
00136 if(tc_orig)
00137 pix[-2*xstride] = p1 + av_clip( (( p2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - p1, -tc_orig, tc_orig );
00138 tc++;
00139 }
00140 if( FFABS( q2 - q0 ) < beta ) {
00141 if(tc_orig)
00142 pix[ xstride] = q1 + av_clip( (( q2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - q1, -tc_orig, tc_orig );
00143 tc++;
00144 }
00145
00146 i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
00147 pix[-xstride] = av_clip_pixel( p0 + i_delta );
00148 pix[0] = av_clip_pixel( q0 - i_delta );
00149 }
00150 pix += ystride;
00151 }
00152 }
00153 }
00154 static void FUNCC(h264_v_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
00155 {
00156 FUNCC(h264_loop_filter_luma)(pix, stride, sizeof(pixel), 4, alpha, beta, tc0);
00157 }
00158 static void FUNCC(h264_h_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
00159 {
00160 FUNCC(h264_loop_filter_luma)(pix, sizeof(pixel), stride, 4, alpha, beta, tc0);
00161 }
00162 static void FUNCC(h264_h_loop_filter_luma_mbaff)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
00163 {
00164 FUNCC(h264_loop_filter_luma)(pix, sizeof(pixel), stride, 2, alpha, beta, tc0);
00165 }
00166
00167 static av_always_inline av_flatten void FUNCC(h264_loop_filter_luma_intra)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta)
00168 {
00169 pixel *pix = (pixel*)p_pix;
00170 int d;
00171 xstride >>= sizeof(pixel)-1;
00172 ystride >>= sizeof(pixel)-1;
00173 alpha <<= BIT_DEPTH - 8;
00174 beta <<= BIT_DEPTH - 8;
00175 for( d = 0; d < 4 * inner_iters; d++ ) {
00176 const int p2 = pix[-3*xstride];
00177 const int p1 = pix[-2*xstride];
00178 const int p0 = pix[-1*xstride];
00179
00180 const int q0 = pix[ 0*xstride];
00181 const int q1 = pix[ 1*xstride];
00182 const int q2 = pix[ 2*xstride];
00183
00184 if( FFABS( p0 - q0 ) < alpha &&
00185 FFABS( p1 - p0 ) < beta &&
00186 FFABS( q1 - q0 ) < beta ) {
00187
00188 if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){
00189 if( FFABS( p2 - p0 ) < beta)
00190 {
00191 const int p3 = pix[-4*xstride];
00192
00193 pix[-1*xstride] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;
00194 pix[-2*xstride] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;
00195 pix[-3*xstride] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;
00196 } else {
00197
00198 pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
00199 }
00200 if( FFABS( q2 - q0 ) < beta)
00201 {
00202 const int q3 = pix[3*xstride];
00203
00204 pix[0*xstride] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;
00205 pix[1*xstride] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;
00206 pix[2*xstride] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;
00207 } else {
00208
00209 pix[0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
00210 }
00211 }else{
00212
00213 pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
00214 pix[ 0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
00215 }
00216 }
00217 pix += ystride;
00218 }
00219 }
00220 static void FUNCC(h264_v_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta)
00221 {
00222 FUNCC(h264_loop_filter_luma_intra)(pix, stride, sizeof(pixel), 4, alpha, beta);
00223 }
00224 static void FUNCC(h264_h_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta)
00225 {
00226 FUNCC(h264_loop_filter_luma_intra)(pix, sizeof(pixel), stride, 4, alpha, beta);
00227 }
00228 static void FUNCC(h264_h_loop_filter_luma_mbaff_intra)(uint8_t *pix, int stride, int alpha, int beta)
00229 {
00230 FUNCC(h264_loop_filter_luma_intra)(pix, sizeof(pixel), stride, 2, alpha, beta);
00231 }
00232
00233 static av_always_inline av_flatten void FUNCC(h264_loop_filter_chroma)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta, int8_t *tc0)
00234 {
00235 pixel *pix = (pixel*)p_pix;
00236 int i, d;
00237 alpha <<= BIT_DEPTH - 8;
00238 beta <<= BIT_DEPTH - 8;
00239 xstride >>= sizeof(pixel)-1;
00240 ystride >>= sizeof(pixel)-1;
00241 for( i = 0; i < 4; i++ ) {
00242 const int tc = ((tc0[i] - 1) << (BIT_DEPTH - 8)) + 1;
00243 if( tc <= 0 ) {
00244 pix += inner_iters*ystride;
00245 continue;
00246 }
00247 for( d = 0; d < inner_iters; d++ ) {
00248 const int p0 = pix[-1*xstride];
00249 const int p1 = pix[-2*xstride];
00250 const int q0 = pix[0];
00251 const int q1 = pix[1*xstride];
00252
00253 if( FFABS( p0 - q0 ) < alpha &&
00254 FFABS( p1 - p0 ) < beta &&
00255 FFABS( q1 - q0 ) < beta ) {
00256
00257 int delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
00258
00259 pix[-xstride] = av_clip_pixel( p0 + delta );
00260 pix[0] = av_clip_pixel( q0 - delta );
00261 }
00262 pix += ystride;
00263 }
00264 }
00265 }
00266 static void FUNCC(h264_v_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
00267 {
00268 FUNCC(h264_loop_filter_chroma)(pix, stride, sizeof(pixel), 2, alpha, beta, tc0);
00269 }
00270 static void FUNCC(h264_h_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
00271 {
00272 FUNCC(h264_loop_filter_chroma)(pix, sizeof(pixel), stride, 2, alpha, beta, tc0);
00273 }
00274 static void FUNCC(h264_h_loop_filter_chroma_mbaff)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
00275 {
00276 FUNCC(h264_loop_filter_chroma)(pix, sizeof(pixel), stride, 1, alpha, beta, tc0);
00277 }
00278
00279 static av_always_inline av_flatten void FUNCC(h264_loop_filter_chroma_intra)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta)
00280 {
00281 pixel *pix = (pixel*)p_pix;
00282 int d;
00283 xstride >>= sizeof(pixel)-1;
00284 ystride >>= sizeof(pixel)-1;
00285 alpha <<= BIT_DEPTH - 8;
00286 beta <<= BIT_DEPTH - 8;
00287 for( d = 0; d < 4 * inner_iters; d++ ) {
00288 const int p0 = pix[-1*xstride];
00289 const int p1 = pix[-2*xstride];
00290 const int q0 = pix[0];
00291 const int q1 = pix[1*xstride];
00292
00293 if( FFABS( p0 - q0 ) < alpha &&
00294 FFABS( p1 - p0 ) < beta &&
00295 FFABS( q1 - q0 ) < beta ) {
00296
00297 pix[-xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
00298 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
00299 }
00300 pix += ystride;
00301 }
00302 }
00303 static void FUNCC(h264_v_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta)
00304 {
00305 FUNCC(h264_loop_filter_chroma_intra)(pix, stride, sizeof(pixel), 2, alpha, beta);
00306 }
00307 static void FUNCC(h264_h_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta)
00308 {
00309 FUNCC(h264_loop_filter_chroma_intra)(pix, sizeof(pixel), stride, 2, alpha, beta);
00310 }
00311 static void FUNCC(h264_h_loop_filter_chroma_mbaff_intra)(uint8_t *pix, int stride, int alpha, int beta)
00312 {
00313 FUNCC(h264_loop_filter_chroma_intra)(pix, sizeof(pixel), stride, 1, alpha, beta);
00314 }