X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Fpredict.c;h=cbc018d392ce3452a8f043fd156f46b563069dc7;hb=5e0ca9aa4eab5e2cb4b124774c3ecebbc6f1ae35;hp=782dfa32b9f46690fbe88a6c7b4b91a38f74313f;hpb=f9bc2de28f637fa199424f544c94aeabc551eeb4;p=x264 diff --git a/common/predict.c b/common/predict.c index 782dfa32..cbc018d3 100644 --- a/common/predict.c +++ b/common/predict.c @@ -1,11 +1,12 @@ /***************************************************************************** - * predict.c: h264 encoder + * predict.c: intra prediction ***************************************************************************** - * Copyright (C) 2003-2008 x264 project + * Copyright (C) 2003-2014 x264 project * * Authors: Laurent Aimar * Loren Merritt * Fiona Glaser + * Henrik Gramner * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +21,9 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. + * + * This program is also available under a commercial proprietary license. + * For more information, contact us at licensing@x264.com. *****************************************************************************/ /* predict4x4 are inspired from ffmpeg h264 decoder */ @@ -53,40 +57,40 @@ void x264_predict_16x16_dc_c( pixel *src ) { - pixel4 dc = 0; + int dc = 0; for( int i = 0; i < 16; i++ ) { dc += src[-1 + i * FDEC_STRIDE]; dc += src[i - FDEC_STRIDE]; } - dc = PIXEL_SPLAT_X4( ( dc + 16 ) >> 5 ); + pixel4 dcsplat = PIXEL_SPLAT_X4( ( dc + 16 ) >> 5 ); - PREDICT_16x16_DC( dc ); + PREDICT_16x16_DC( dcsplat ); } static void x264_predict_16x16_dc_left_c( pixel *src ) { - pixel4 dc = 0; + int dc = 0; for( int i = 0; i < 16; i++ ) dc += src[-1 + i * FDEC_STRIDE]; - dc = PIXEL_SPLAT_X4( ( dc + 8 ) >> 4 ); + pixel4 dcsplat = PIXEL_SPLAT_X4( ( dc + 8 ) >> 4 ); - PREDICT_16x16_DC( dc ); + PREDICT_16x16_DC( dcsplat ); } static void x264_predict_16x16_dc_top_c( pixel *src ) { - pixel4 dc = 0; + int dc = 0; for( int i = 0; i < 16; i++ ) dc += src[i - FDEC_STRIDE]; - dc = PIXEL_SPLAT_X4( ( dc + 8 ) >> 4 ); + pixel4 dcsplat = PIXEL_SPLAT_X4( ( dc + 8 ) >> 4 ); - PREDICT_16x16_DC( dc ); + PREDICT_16x16_DC( dcsplat ); } static void x264_predict_16x16_dc_128_c( pixel *src ) { - PREDICT_16x16_DC( PIXEL_SPLAT_X4( 0x80 ) ); + PREDICT_16x16_DC( PIXEL_SPLAT_X4( 1 << (BIT_DEPTH-1) ) ); } void x264_predict_16x16_h_c( pixel *src ) { @@ -116,7 +120,7 @@ void x264_predict_16x16_v_c( pixel *src ) src += FDEC_STRIDE; } } -static void x264_predict_16x16_p_c( pixel *src ) +void x264_predict_16x16_p_c( pixel *src ) { int H = 0, V = 0; @@ -148,60 +152,60 @@ static void x264_predict_16x16_p_c( pixel *src ) /**************************************************************************** - * 8x8 prediction for intra chroma block + * 8x8 prediction for intra chroma block (4:2:0) ****************************************************************************/ static void x264_predict_8x8c_dc_128_c( pixel *src ) { for( int y = 0; y < 8; y++ ) { - MPIXEL_X4( src+0 ) = PIXEL_SPLAT_X4( 0x80 ); - MPIXEL_X4( src+4 ) = PIXEL_SPLAT_X4( 0x80 ); + MPIXEL_X4( src+0 ) = PIXEL_SPLAT_X4( 1 << (BIT_DEPTH-1) ); + MPIXEL_X4( src+4 ) = PIXEL_SPLAT_X4( 1 << (BIT_DEPTH-1) ); src += FDEC_STRIDE; } } static void x264_predict_8x8c_dc_left_c( pixel *src ) { - pixel4 dc0 = 0, dc1 = 0; + int dc0 = 0, dc1 = 0; for( int y = 0; y < 4; y++ ) { dc0 += src[y * FDEC_STRIDE - 1]; dc1 += src[(y+4) * FDEC_STRIDE - 1]; } - dc0 = PIXEL_SPLAT_X4( ( dc0 + 2 ) >> 2 ); - dc1 = PIXEL_SPLAT_X4( ( dc1 + 2 ) >> 2 ); + pixel4 dc0splat = PIXEL_SPLAT_X4( ( dc0 + 2 ) >> 2 ); + pixel4 dc1splat = PIXEL_SPLAT_X4( ( dc1 + 2 ) >> 2 ); for( int y = 0; y < 4; y++ ) { - MPIXEL_X4( src+0 ) = dc0; - MPIXEL_X4( src+4 ) = dc0; + MPIXEL_X4( src+0 ) = dc0splat; + MPIXEL_X4( src+4 ) = dc0splat; src += FDEC_STRIDE; } for( int y = 0; y < 4; y++ ) { - MPIXEL_X4( src+0 ) = dc1; - MPIXEL_X4( src+4 ) = dc1; + MPIXEL_X4( src+0 ) = dc1splat; + MPIXEL_X4( src+4 ) = dc1splat; src += FDEC_STRIDE; } } static void x264_predict_8x8c_dc_top_c( pixel *src ) { - pixel4 dc0 = 0, dc1 = 0; + int dc0 = 0, dc1 = 0; for( int x = 0; x < 4; x++ ) { dc0 += src[x - FDEC_STRIDE]; dc1 += src[x + 4 - FDEC_STRIDE]; } - dc0 = PIXEL_SPLAT_X4( ( dc0 + 2 ) >> 2 ); - dc1 = PIXEL_SPLAT_X4( ( dc1 + 2 ) >> 2 ); + pixel4 dc0splat = PIXEL_SPLAT_X4( ( dc0 + 2 ) >> 2 ); + pixel4 dc1splat = PIXEL_SPLAT_X4( ( dc1 + 2 ) >> 2 ); for( int y = 0; y < 8; y++ ) { - MPIXEL_X4( src+0 ) = dc0; - MPIXEL_X4( src+4 ) = dc1; + MPIXEL_X4( src+0 ) = dc0splat; + MPIXEL_X4( src+4 ) = dc1splat; src += FDEC_STRIDE; } } @@ -266,7 +270,7 @@ void x264_predict_8x8c_v_c( pixel *src ) src += FDEC_STRIDE; } } -static void x264_predict_8x8c_p_c( pixel *src ) +void x264_predict_8x8c_p_c( pixel *src ) { int H = 0, V = 0; @@ -294,6 +298,167 @@ static void x264_predict_8x8c_p_c( pixel *src ) } } +/**************************************************************************** + * 8x16 prediction for intra chroma block (4:2:2) + ****************************************************************************/ + +static void x264_predict_8x16c_dc_128_c( pixel *src ) +{ + for( int y = 0; y < 16; y++ ) + { + MPIXEL_X4( src+0 ) = PIXEL_SPLAT_X4( 1 << (BIT_DEPTH-1) ); + MPIXEL_X4( src+4 ) = PIXEL_SPLAT_X4( 1 << (BIT_DEPTH-1) ); + src += FDEC_STRIDE; + } +} +static void x264_predict_8x16c_dc_left_c( pixel *src ) +{ + for( int i = 0; i < 4; i++ ) + { + int dc = 0; + + for( int y = 0; y < 4; y++ ) + dc += src[y*FDEC_STRIDE - 1]; + + pixel4 dcsplat = PIXEL_SPLAT_X4( (dc + 2) >> 2 ); + + for( int y = 0; y < 4; y++ ) + { + MPIXEL_X4( src+0 ) = dcsplat; + MPIXEL_X4( src+4 ) = dcsplat; + src += FDEC_STRIDE; + } + } +} +static void x264_predict_8x16c_dc_top_c( pixel *src ) +{ + int dc0 = 0, dc1 = 0; + + for(int x = 0; x < 4; x++ ) + { + dc0 += src[x - FDEC_STRIDE]; + dc1 += src[x + 4 - FDEC_STRIDE]; + } + pixel4 dc0splat = PIXEL_SPLAT_X4( ( dc0 + 2 ) >> 2 ); + pixel4 dc1splat = PIXEL_SPLAT_X4( ( dc1 + 2 ) >> 2 ); + + for( int y = 0; y < 16; y++ ) + { + MPIXEL_X4( src+0 ) = dc0splat; + MPIXEL_X4( src+4 ) = dc1splat; + src += FDEC_STRIDE; + } +} +void x264_predict_8x16c_dc_c( pixel *src ) +{ + int s0 = 0, s1 = 0, s2 = 0, s3 = 0, s4 = 0, s5 = 0; + + /* + s0 s1 + s2 + s3 + s4 + s5 + */ + for( int i = 0; i < 4; i++ ) + { + s0 += src[i+0 - FDEC_STRIDE]; + s1 += src[i+4 - FDEC_STRIDE]; + s2 += src[-1 + (i+0) * FDEC_STRIDE]; + s3 += src[-1 + (i+4) * FDEC_STRIDE]; + s4 += src[-1 + (i+8) * FDEC_STRIDE]; + s5 += src[-1 + (i+12) * FDEC_STRIDE]; + } + /* + dc0 dc1 + dc2 dc3 + dc4 dc5 + dc6 dc7 + */ + pixel4 dc0 = PIXEL_SPLAT_X4( ( s0 + s2 + 4 ) >> 3 ); + pixel4 dc1 = PIXEL_SPLAT_X4( ( s1 + 2 ) >> 2 ); + pixel4 dc2 = PIXEL_SPLAT_X4( ( s3 + 2 ) >> 2 ); + pixel4 dc3 = PIXEL_SPLAT_X4( ( s1 + s3 + 4 ) >> 3 ); + pixel4 dc4 = PIXEL_SPLAT_X4( ( s4 + 2 ) >> 2 ); + pixel4 dc5 = PIXEL_SPLAT_X4( ( s1 + s4 + 4 ) >> 3 ); + pixel4 dc6 = PIXEL_SPLAT_X4( ( s5 + 2 ) >> 2 ); + pixel4 dc7 = PIXEL_SPLAT_X4( ( s1 + s5 + 4 ) >> 3 ); + + for( int y = 0; y < 4; y++ ) + { + MPIXEL_X4( src+0 ) = dc0; + MPIXEL_X4( src+4 ) = dc1; + src += FDEC_STRIDE; + } + for( int y = 0; y < 4; y++ ) + { + MPIXEL_X4( src+0 ) = dc2; + MPIXEL_X4( src+4 ) = dc3; + src += FDEC_STRIDE; + } + for( int y = 0; y < 4; y++ ) + { + MPIXEL_X4( src+0 ) = dc4; + MPIXEL_X4( src+4 ) = dc5; + src += FDEC_STRIDE; + } + for( int y = 0; y < 4; y++ ) + { + MPIXEL_X4( src+0 ) = dc6; + MPIXEL_X4( src+4 ) = dc7; + src += FDEC_STRIDE; + } +} +void x264_predict_8x16c_h_c( pixel *src ) +{ + for( int i = 0; i < 16; i++ ) + { + pixel4 v = PIXEL_SPLAT_X4( src[-1] ); + MPIXEL_X4( src+0 ) = v; + MPIXEL_X4( src+4 ) = v; + src += FDEC_STRIDE; + } +} +void x264_predict_8x16c_v_c( pixel *src ) +{ + pixel4 v0 = MPIXEL_X4( src+0-FDEC_STRIDE ); + pixel4 v1 = MPIXEL_X4( src+4-FDEC_STRIDE ); + + for( int i = 0; i < 16; i++ ) + { + MPIXEL_X4( src+0 ) = v0; + MPIXEL_X4( src+4 ) = v1; + src += FDEC_STRIDE; + } +} +void x264_predict_8x16c_p_c( pixel *src ) +{ + int H = 0; + int V = 0; + + for( int i = 0; i < 4; i++ ) + H += ( i + 1 ) * ( src[4 + i - FDEC_STRIDE] - src[2 - i - FDEC_STRIDE] ); + for( int i = 0; i < 8; i++ ) + V += ( i + 1 ) * ( src[-1 + (i+8)*FDEC_STRIDE] - src[-1 + (6-i)*FDEC_STRIDE] ); + + int a = 16 * ( src[-1 + 15*FDEC_STRIDE] + src[7 - FDEC_STRIDE] ); + int b = ( 17 * H + 16 ) >> 5; + int c = ( 5 * V + 32 ) >> 6; + int i00 = a -3*b -7*c + 16; + + for( int y = 0; y < 16; y++ ) + { + int pix = i00; + for( int x = 0; x < 8; x++ ) + { + src[x] = x264_clip_pixel( pix>>5 ); + pix += b; + } + src += FDEC_STRIDE; + i00 += c; + } +} + /**************************************************************************** * 4x4 prediction for intra luma block ****************************************************************************/ @@ -306,7 +471,7 @@ static void x264_predict_8x8c_p_c( pixel *src ) static void x264_predict_4x4_dc_128_c( pixel *src ) { - PREDICT_4x4_DC( PIXEL_SPLAT_X4( 0x80 ) ); + PREDICT_4x4_DC( PIXEL_SPLAT_X4( 1 << (BIT_DEPTH-1) ) ); } static void x264_predict_4x4_dc_left_c( pixel *src ) { @@ -455,7 +620,7 @@ static void x264_predict_4x4_hu_c( pixel *src ) #define PT(x) \ edge[16+x] = F2(SRC(x-1,-1), SRC(x,-1), SRC(x+1,-1)); -static void x264_predict_8x8_filter_c( pixel *src, pixel edge[33], int i_neighbor, int i_filters ) +static void x264_predict_8x8_filter_c( pixel *src, pixel edge[36], int i_neighbor, int i_filters ) { /* edge[7..14] = l7..l0 * edge[15] = lt @@ -469,6 +634,7 @@ static void x264_predict_8x8_filter_c( pixel *src, pixel edge[33], int i_neighbo edge[14] = ((have_lt ? SRC(-1,-1) : SRC(-1,0)) + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2; PL(1) PL(2) PL(3) PL(4) PL(5) PL(6) + edge[6] = edge[7] = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2; } @@ -491,7 +657,8 @@ static void x264_predict_8x8_filter_c( pixel *src, pixel edge[33], int i_neighbo } else { - M64( edge+24 ) = SRC(7,-1) * 0x0101010101010101ULL; + MPIXEL_X4( edge+24 ) = PIXEL_SPLAT_X4( SRC(7,-1) ); + MPIXEL_X4( edge+28 ) = PIXEL_SPLAT_X4( SRC(7,-1) ); edge[32] = SRC(7,-1); } } @@ -521,30 +688,30 @@ static void x264_predict_8x8_filter_c( pixel *src, pixel edge[33], int i_neighbo src += FDEC_STRIDE; \ } -static void x264_predict_8x8_dc_128_c( pixel *src, pixel edge[33] ) +static void x264_predict_8x8_dc_128_c( pixel *src, pixel edge[36] ) { - PREDICT_8x8_DC( PIXEL_SPLAT_X4( 0x80 ) ); + PREDICT_8x8_DC( PIXEL_SPLAT_X4( 1 << (BIT_DEPTH-1) ) ); } -static void x264_predict_8x8_dc_left_c( pixel *src, pixel edge[33] ) +static void x264_predict_8x8_dc_left_c( pixel *src, pixel edge[36] ) { PREDICT_8x8_LOAD_LEFT pixel4 dc = PIXEL_SPLAT_X4( (l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3 ); PREDICT_8x8_DC( dc ); } -static void x264_predict_8x8_dc_top_c( pixel *src, pixel edge[33] ) +static void x264_predict_8x8_dc_top_c( pixel *src, pixel edge[36] ) { PREDICT_8x8_LOAD_TOP pixel4 dc = PIXEL_SPLAT_X4( (t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3 ); PREDICT_8x8_DC( dc ); } -void x264_predict_8x8_dc_c( pixel *src, pixel edge[33] ) +void x264_predict_8x8_dc_c( pixel *src, pixel edge[36] ) { PREDICT_8x8_LOAD_LEFT PREDICT_8x8_LOAD_TOP pixel4 dc = PIXEL_SPLAT_X4( (l0+l1+l2+l3+l4+l5+l6+l7+t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4 ); PREDICT_8x8_DC( dc ); } -void x264_predict_8x8_h_c( pixel *src, pixel edge[33] ) +void x264_predict_8x8_h_c( pixel *src, pixel edge[36] ) { PREDICT_8x8_LOAD_LEFT #define ROW(y) MPIXEL_X4( src+y*FDEC_STRIDE+0 ) =\ @@ -552,13 +719,17 @@ void x264_predict_8x8_h_c( pixel *src, pixel edge[33] ) ROW(0); ROW(1); ROW(2); ROW(3); ROW(4); ROW(5); ROW(6); ROW(7); #undef ROW } -void x264_predict_8x8_v_c( pixel *src, pixel edge[33] ) +void x264_predict_8x8_v_c( pixel *src, pixel edge[36] ) { - uint64_t top = M64( edge+16 ); + pixel4 top[2] = { MPIXEL_X4( edge+16 ), + MPIXEL_X4( edge+20 ) }; for( int y = 0; y < 8; y++ ) - M64( src+y*FDEC_STRIDE ) = top; + { + MPIXEL_X4( src+y*FDEC_STRIDE+0 ) = top[0]; + MPIXEL_X4( src+y*FDEC_STRIDE+4 ) = top[1]; + } } -static void x264_predict_8x8_ddl_c( pixel *src, pixel edge[33] ) +static void x264_predict_8x8_ddl_c( pixel *src, pixel edge[36] ) { PREDICT_8x8_LOAD_TOP PREDICT_8x8_LOAD_TOPRIGHT @@ -578,7 +749,7 @@ static void x264_predict_8x8_ddl_c( pixel *src, pixel edge[33] ) SRC(6,7)=SRC(7,6)= F2(t13,t14,t15); SRC(7,7)= F2(t14,t15,t15); } -static void x264_predict_8x8_ddr_c( pixel *src, pixel edge[33] ) +static void x264_predict_8x8_ddr_c( pixel *src, pixel edge[36] ) { PREDICT_8x8_LOAD_TOP PREDICT_8x8_LOAD_LEFT @@ -600,7 +771,7 @@ static void x264_predict_8x8_ddr_c( pixel *src, pixel edge[33] ) SRC(7,0)= F2(t5,t6,t7); } -static void x264_predict_8x8_vr_c( pixel *src, pixel edge[33] ) +static void x264_predict_8x8_vr_c( pixel *src, pixel edge[36] ) { PREDICT_8x8_LOAD_TOP PREDICT_8x8_LOAD_LEFT @@ -628,7 +799,7 @@ static void x264_predict_8x8_vr_c( pixel *src, pixel edge[33] ) SRC(7,1)= F2(t5,t6,t7); SRC(7,0)= F1(t6,t7); } -static void x264_predict_8x8_hd_c( pixel *src, pixel edge[33] ) +static void x264_predict_8x8_hd_c( pixel *src, pixel edge[36] ) { PREDICT_8x8_LOAD_TOP PREDICT_8x8_LOAD_LEFT @@ -655,7 +826,7 @@ static void x264_predict_8x8_hd_c( pixel *src, pixel edge[33] ) SRC_X4(4,1)= pack_pixel_2to4(p9,p10); SRC_X4(4,0)= pack_pixel_2to4(p10,p11); } -static void x264_predict_8x8_vl_c( pixel *src, pixel edge[33] ) +static void x264_predict_8x8_vl_c( pixel *src, pixel edge[36] ) { PREDICT_8x8_LOAD_TOP PREDICT_8x8_LOAD_TOPRIGHT @@ -682,7 +853,7 @@ static void x264_predict_8x8_vl_c( pixel *src, pixel edge[33] ) SRC(7,6)= F1(t10,t11); SRC(7,7)= F2(t10,t11,t12); } -static void x264_predict_8x8_hu_c( pixel *src, pixel edge[33] ) +static void x264_predict_8x8_hu_c( pixel *src, pixel edge[36] ) { PREDICT_8x8_LOAD_LEFT int p1 = pack_pixel_1to2(F1(l0,l1), F2(l0,l1,l2)); @@ -754,6 +925,21 @@ void x264_predict_8x8c_init( int cpu, x264_predict_t pf[7] ) #endif } +void x264_predict_8x16c_init( int cpu, x264_predict_t pf[7] ) +{ + pf[I_PRED_CHROMA_V ] = x264_predict_8x16c_v_c; + pf[I_PRED_CHROMA_H ] = x264_predict_8x16c_h_c; + pf[I_PRED_CHROMA_DC] = x264_predict_8x16c_dc_c; + pf[I_PRED_CHROMA_P ] = x264_predict_8x16c_p_c; + pf[I_PRED_CHROMA_DC_LEFT]= x264_predict_8x16c_dc_left_c; + pf[I_PRED_CHROMA_DC_TOP ]= x264_predict_8x16c_dc_top_c; + pf[I_PRED_CHROMA_DC_128 ]= x264_predict_8x16c_dc_128_c; + +#if HAVE_MMX + x264_predict_8x16c_init_mmx( cpu, pf ); +#endif +} + void x264_predict_8x8_init( int cpu, x264_predict8x8_t pf[12], x264_predict_8x8_filter_t *predict_filter ) { pf[I_PRED_8x8_V] = x264_predict_8x8_v_c;