From: Loren Merritt Date: Sun, 1 Oct 2006 02:44:36 +0000 (+0000) Subject: move zigzag scan functions to dsp function pointers. X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=a7cd9cf8ba99e4703805d34eef494d47850f9b99;p=x264.git move zigzag scan functions to dsp function pointers. mmx implementation of interlaced zigzag. git-svn-id: svn://svn.videolan.org/x264/trunk@571 df754926-b1dd-0310-bc7b-ec298dee348c --- diff --git a/common/amd64/dct-a.asm b/common/amd64/dct-a.asm index 15783d19..de449cf0 100644 --- a/common/amd64/dct-a.asm +++ b/common/amd64/dct-a.asm @@ -518,3 +518,27 @@ ADD_NxN_IDCT x264_add16x16_idct_mmx, x264_add8x8_idct_mmx, 32, 4, 4, 12 SUB_NxN_DCT x264_sub16x16_dct8_sse2, x264_sub8x8_dct8_sse2, 128, 8, 0, 8 ADD_NxN_IDCT x264_add16x16_idct8_sse2, x264_add8x8_idct8_sse2, 128, 8, 0, 8 + +;----------------------------------------------------------------------------- +; void __cdecl x264_zigzag_scan_4x4_field_sse2( int level[16], int16_t dct[4][4] ) +;----------------------------------------------------------------------------- +ALIGN 16 +cglobal x264_zigzag_scan_4x4_field_sse2 +x264_zigzag_scan_4x4_field_sse2: + punpcklwd xmm0, [parm2q] + punpckhwd xmm1, [parm2q] + punpcklwd xmm2, [parm2q+16] + punpckhwd xmm3, [parm2q+16] + psrad xmm0, 16 + psrad xmm1, 16 + psrad xmm2, 16 + psrad xmm3, 16 + movq [parm1q ], xmm0 + movdqa [parm1q+16], xmm1 + movdqa [parm1q+32], xmm2 + movhlps xmm0, xmm0 + movdqa [parm1q+48], xmm3 + movq [parm1q+12], xmm0 + movd [parm1q+ 8], xmm1 + ret + diff --git a/common/common.h b/common/common.h index f0fb0406..6e145a4a 100644 --- a/common/common.h +++ b/common/common.h @@ -582,6 +582,7 @@ struct x264_t x264_pixel_function_t pixf; x264_mc_functions_t mc; x264_dct_function_t dctf; + x264_zigzag_function_t zigzagf; x264_csp_function_t csp; x264_quant_function_t quantf; x264_deblock_function_t loopf; diff --git a/common/dct.c b/common/dct.c index a9f855ea..8366e4a7 100644 --- a/common/dct.c +++ b/common/dct.c @@ -455,3 +455,148 @@ void x264_dct_init_weights( void ) } } + +#define ZIG(i,y,x) level[i] = dct[x][y]; + +static void zigzag_scan_8x8_frame( int level[64], int16_t dct[8][8] ) +{ + ZIG( 0,0,0) ZIG( 1,0,1) ZIG( 2,1,0) ZIG( 3,2,0) + ZIG( 4,1,1) ZIG( 5,0,2) ZIG( 6,0,3) ZIG( 7,1,2) + ZIG( 8,2,1) ZIG( 9,3,0) ZIG(10,4,0) ZIG(11,3,1) + ZIG(12,2,2) ZIG(13,1,3) ZIG(14,0,4) ZIG(15,0,5) + ZIG(16,1,4) ZIG(17,2,3) ZIG(18,3,2) ZIG(19,4,1) + ZIG(20,5,0) ZIG(21,6,0) ZIG(22,5,1) ZIG(23,4,2) + ZIG(24,3,3) ZIG(25,2,4) ZIG(26,1,5) ZIG(27,0,6) + ZIG(28,0,7) ZIG(29,1,6) ZIG(30,2,5) ZIG(31,3,4) + ZIG(32,4,3) ZIG(33,5,2) ZIG(34,6,1) ZIG(35,7,0) + ZIG(36,7,1) ZIG(37,6,2) ZIG(38,5,3) ZIG(39,4,4) + ZIG(40,3,5) ZIG(41,2,6) ZIG(42,1,7) ZIG(43,2,7) + ZIG(44,3,6) ZIG(45,4,5) ZIG(46,5,4) ZIG(47,6,3) + ZIG(48,7,2) ZIG(49,7,3) ZIG(50,6,4) ZIG(51,5,5) + ZIG(52,4,6) ZIG(53,3,7) ZIG(54,4,7) ZIG(55,5,6) + ZIG(56,6,5) ZIG(57,7,4) ZIG(58,7,5) ZIG(59,6,6) + ZIG(60,5,7) ZIG(61,6,7) ZIG(62,7,6) ZIG(63,7,7) +} + +static void zigzag_scan_8x8_field( int level[64], int16_t dct[8][8] ) +{ + ZIG( 0,0,0) ZIG( 1,1,0) ZIG( 2,2,0) ZIG( 3,0,1) + ZIG( 4,1,1) ZIG( 5,3,0) ZIG( 6,4,0) ZIG( 7,2,1) + ZIG( 8,0,2) ZIG( 9,3,1) ZIG(10,5,0) ZIG(11,6,0) + ZIG(12,7,0) ZIG(13,4,1) ZIG(14,1,2) ZIG(15,0,3) + ZIG(16,2,2) ZIG(17,5,1) ZIG(18,6,1) ZIG(19,7,1) + ZIG(20,3,2) ZIG(21,1,3) ZIG(22,0,4) ZIG(23,2,3) + ZIG(24,4,2) ZIG(25,5,2) ZIG(26,6,2) ZIG(27,7,2) + ZIG(28,3,3) ZIG(29,1,4) ZIG(30,0,5) ZIG(31,2,4) + ZIG(32,4,3) ZIG(33,5,3) ZIG(34,6,3) ZIG(35,7,3) + ZIG(36,3,4) ZIG(37,1,5) ZIG(38,0,6) ZIG(39,2,5) + ZIG(40,4,4) ZIG(41,5,4) ZIG(42,6,4) ZIG(43,7,4) + ZIG(44,3,5) ZIG(45,1,6) ZIG(46,2,6) ZIG(47,4,5) + ZIG(48,5,5) ZIG(49,6,5) ZIG(50,7,5) ZIG(51,3,6) + ZIG(52,0,7) ZIG(53,1,7) ZIG(54,4,6) ZIG(55,5,6) + ZIG(56,6,6) ZIG(57,7,6) ZIG(58,2,7) ZIG(59,3,7) + ZIG(60,4,7) ZIG(61,5,7) ZIG(62,6,7) ZIG(63,7,7) +} + +static void zigzag_scan_4x4_frame( int level[16], int16_t dct[4][4] ) +{ + ZIG( 0,0,0) ZIG( 1,0,1) ZIG( 2,1,0) ZIG( 3,2,0) + ZIG( 4,1,1) ZIG( 5,0,2) ZIG( 6,0,3) ZIG( 7,1,2) + ZIG( 8,2,1) ZIG( 9,3,0) ZIG(10,3,1) ZIG(11,2,2) + ZIG(12,1,3) ZIG(13,2,3) ZIG(14,3,2) ZIG(15,3,3) +} + +static void zigzag_scan_4x4_field( int level[16], int16_t dct[4][4] ) +{ + ZIG( 0,0,0) ZIG( 1,1,0) ZIG( 2,0,1) ZIG( 3,2,0) + ZIG( 4,3,0) ZIG( 5,1,1) ZIG( 6,2,1) ZIG( 7,3,1) + ZIG( 8,0,2) ZIG( 9,1,2) ZIG(10,2,2) ZIG(11,3,2) + ZIG(12,0,3) ZIG(13,1,3) ZIG(14,2,3) ZIG(15,3,3) +} + +static void zigzag_scan_4x4ac_frame( int level[15], int16_t dct[4][4] ) +{ + ZIG( 0,0,1) ZIG( 1,1,0) ZIG( 2,2,0) + ZIG( 3,1,1) ZIG( 4,0,2) ZIG( 5,0,3) ZIG( 6,1,2) + ZIG( 7,2,1) ZIG( 8,3,0) ZIG( 9,3,1) ZIG(10,2,2) + ZIG(11,1,3) ZIG(12,2,3) ZIG(13,3,2) ZIG(14,3,3) +} + +static void zigzag_scan_4x4ac_field( int level[15], int16_t dct[4][4] ) +{ + ZIG( 0,1,0) ZIG( 1,0,1) ZIG( 2,2,0) + ZIG( 3,3,0) ZIG( 4,1,1) ZIG( 5,2,1) ZIG( 6,3,1) + ZIG( 7,0,2) ZIG( 8,1,2) ZIG( 9,2,2) ZIG(10,3,2) + ZIG(11,0,3) ZIG(12,1,3) ZIG(13,2,3) ZIG(14,3,3) +} + +#undef ZIG + +#define ZIG(i,y,x) {\ + int oe = x+y*FENC_STRIDE;\ + int od = x+y*FDEC_STRIDE;\ + level[i] = p_src[oe] - p_dst[od];\ + p_dst[od] = p_src[oe];\ +} + +static void zigzag_sub_4x4_frame( int level[16], const uint8_t *p_src, uint8_t *p_dst ) +{ + ZIG( 0,0,0) ZIG( 1,0,1) ZIG( 2,1,0) ZIG( 3,2,0) + ZIG( 4,1,1) ZIG( 5,0,2) ZIG( 6,0,3) ZIG( 7,1,2) + ZIG( 8,2,1) ZIG( 9,3,0) ZIG(10,3,1) ZIG(11,2,2) + ZIG(12,1,3) ZIG(13,2,3) ZIG(14,3,2) ZIG(15,3,3) +} + +static void zigzag_sub_4x4_field( int level[16], const uint8_t *p_src, uint8_t *p_dst ) +{ + ZIG( 0,0,0) ZIG( 1,1,0) ZIG( 2,0,1) ZIG( 3,2,0) + ZIG( 4,3,0) ZIG( 5,1,1) ZIG( 6,2,1) ZIG( 7,3,1) + ZIG( 8,0,2) ZIG( 9,1,2) ZIG(10,2,2) ZIG(11,3,2) + ZIG(12,0,3) ZIG(13,1,3) ZIG(14,2,3) ZIG(15,3,3) +} + +static void zigzag_sub_4x4ac_frame( int level[15], const uint8_t *p_src, uint8_t *p_dst ) +{ + ZIG( 0,0,1) ZIG( 1,1,0) ZIG( 2,2,0) + ZIG( 3,1,1) ZIG( 4,0,2) ZIG( 5,0,3) ZIG( 6,1,2) + ZIG( 7,2,1) ZIG( 8,3,0) ZIG( 9,3,1) ZIG(10,2,2) + ZIG(11,1,3) ZIG(12,2,3) ZIG(13,3,2) ZIG(14,3,3) +} + +static void zigzag_sub_4x4ac_field( int level[15], const uint8_t *p_src, uint8_t *p_dst ) +{ + ZIG( 0,1,0) ZIG( 1,0,1) ZIG( 2,2,0) + ZIG( 3,3,0) ZIG( 4,1,1) ZIG( 5,2,1) ZIG( 6,3,1) + ZIG( 7,0,2) ZIG( 8,1,2) ZIG( 9,2,2) ZIG(10,3,2) + ZIG(11,0,3) ZIG(12,1,3) ZIG(13,2,3) ZIG(14,3,3) +} + +#undef ZIG + +void x264_zigzag_init( int cpu, x264_zigzag_function_t *pf, int b_interlaced ) +{ + if( b_interlaced ) + { + pf->scan_8x8 = zigzag_scan_8x8_field; + pf->scan_4x4 = zigzag_scan_4x4_field; + pf->scan_4x4ac = zigzag_scan_4x4ac_field; + pf->sub_4x4 = zigzag_sub_4x4_field; + pf->sub_4x4ac = zigzag_sub_4x4ac_field; +#if defined(HAVE_MMXEXT) && defined(ARCH_X86) + if( cpu&X264_CPU_MMX ) + pf->scan_4x4 = x264_zigzag_scan_4x4_field_mmx; +#endif +#if defined(HAVE_SSE2) && defined(ARCH_X86_64) + if( cpu&X264_CPU_SSE2 ) + pf->scan_4x4 = x264_zigzag_scan_4x4_field_sse2; +#endif + } + else + { + pf->scan_8x8 = zigzag_scan_8x8_frame; + pf->scan_4x4 = zigzag_scan_4x4_frame; + pf->scan_4x4ac = zigzag_scan_4x4ac_frame; + pf->sub_4x4 = zigzag_sub_4x4_frame; + pf->sub_4x4ac = zigzag_sub_4x4ac_frame; + } +} diff --git a/common/dct.h b/common/dct.h index ff643042..35d67b80 100644 --- a/common/dct.h +++ b/common/dct.h @@ -106,7 +106,18 @@ typedef struct } x264_dct_function_t; +typedef struct +{ + void (*scan_8x8)( int level[64], int16_t dct[8][8] ); + void (*scan_4x4)( int level[16], int16_t dct[4][4] ); + void (*scan_4x4ac)( int level[15], int16_t dct[4][4] ); + void (*sub_4x4)( int level[16], const uint8_t *p_src, uint8_t *p_dst ); + void (*sub_4x4ac)( int level[15], const uint8_t *p_src, uint8_t *p_dst ); + +} x264_zigzag_function_t; + void x264_dct_init( int cpu, x264_dct_function_t *dctf ); void x264_dct_init_weights( void ); +void x264_zigzag_init( int cpu, x264_zigzag_function_t *pf, int b_interlaced ); #endif diff --git a/common/i386/dct-a.asm b/common/i386/dct-a.asm index 0bd0eddf..9d12e7b2 100644 --- a/common/i386/dct-a.asm +++ b/common/i386/dct-a.asm @@ -695,3 +695,38 @@ ADD_NxN_IDCT x264_add16x16_idct_mmx, x264_add8x8_idct_mmx, 128, 8 SUB_NxN_DCT x264_sub16x16_dct8_mmx, x264_sub8x8_dct8_mmx, 128, 8 ADD_NxN_IDCT x264_add16x16_idct8_mmx, x264_add8x8_idct8_mmx, 128, 8 + +;----------------------------------------------------------------------------- +; void __cdecl x264_zigzag_scan_4x4_field_mmx( int level[16], int16_t dct[4][4] ) +;----------------------------------------------------------------------------- +ALIGN 16 +cglobal x264_zigzag_scan_4x4_field_mmx +x264_zigzag_scan_4x4_field_mmx: + mov edx, [esp+8] + mov ecx, [esp+4] + punpcklwd mm0, [edx] + punpckhwd mm1, [edx] + punpcklwd mm2, [edx+8] + punpckhwd mm3, [edx+8] + punpcklwd mm4, [edx+16] + punpckhwd mm5, [edx+16] + punpcklwd mm6, [edx+24] + punpckhwd mm7, [edx+24] + psrad mm0, 16 + psrad mm1, 16 + psrad mm2, 16 + psrad mm3, 16 + psrad mm4, 16 + psrad mm5, 16 + psrad mm6, 16 + psrad mm7, 16 + movq [ecx ], mm0 + movq [ecx+16], mm2 + movq [ecx+24], mm3 + movq [ecx+32], mm4 + movq [ecx+40], mm5 + movq [ecx+48], mm6 + movq [ecx+56], mm7 + movq [ecx+12], mm1 + movd [ecx+ 8], mm2 + ret diff --git a/common/i386/dct.h b/common/i386/dct.h index 8abbee78..3ca9b82c 100644 --- a/common/i386/dct.h +++ b/common/i386/dct.h @@ -47,4 +47,7 @@ void x264_sub16x16_dct8_sse2( int16_t dct[4][8][8], uint8_t *pix1, uint8_t *pix2 void x264_add8x8_idct8_sse2( uint8_t *dst, int16_t dct[8][8] ); void x264_add16x16_idct8_sse2( uint8_t *dst, int16_t dct[4][8][8] ); +void x264_zigzag_scan_4x4_field_sse2( int level[16], int16_t dct[4][4] ); +void x264_zigzag_scan_4x4_field_mmx( int level[16], int16_t dct[4][4] ); + #endif diff --git a/encoder/encoder.c b/encoder/encoder.c index 7f18c231..147e0eb3 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -642,6 +642,7 @@ x264_t *x264_encoder_open ( x264_param_t *param ) x264_pixel_init( h->param.cpu, &h->pixf ); x264_dct_init( h->param.cpu, &h->dctf ); + x264_zigzag_init( h->param.cpu, &h->zigzagf, h->param.b_interlaced ); x264_mc_init( h->param.cpu, &h->mc ); x264_csp_init( h->param.cpu, h->param.i_csp, &h->csp ); x264_quant_init( h, h->param.cpu, &h->quantf ); diff --git a/encoder/macroblock.c b/encoder/macroblock.c index 63fc64c4..ebfb6be2 100644 --- a/encoder/macroblock.c +++ b/encoder/macroblock.c @@ -47,91 +47,8 @@ static const int def_quant4_mf[6][4][4] = { 7282, 4559, 7282, 4559 }, { 4559, 2893, 4559, 2893 } } }; -/**************************************************************************** - * Scan and Quant functions - ****************************************************************************/ - #define ZIG(i,y,x) level[i] = dct[x][y]; - -static inline void scan_zigzag_8x8full( int level[64], int16_t dct[8][8], int b_interlaced ) -{ - if( b_interlaced ) - { - ZIG( 0,0,0) ZIG( 1,1,0) ZIG( 2,2,0) ZIG( 3,0,1) - ZIG( 4,1,1) ZIG( 5,3,0) ZIG( 6,4,0) ZIG( 7,2,1) - ZIG( 8,0,2) ZIG( 9,3,1) ZIG(10,5,0) ZIG(11,6,0) - ZIG(12,7,0) ZIG(13,4,1) ZIG(14,1,2) ZIG(15,0,3) - ZIG(16,2,2) ZIG(17,5,1) ZIG(18,6,1) ZIG(19,7,1) - ZIG(20,3,2) ZIG(21,1,3) ZIG(22,0,4) ZIG(23,2,3) - ZIG(24,4,2) ZIG(25,5,2) ZIG(26,6,2) ZIG(27,7,2) - ZIG(28,3,3) ZIG(29,1,4) ZIG(30,0,5) ZIG(31,2,4) - ZIG(32,4,3) ZIG(33,5,3) ZIG(34,6,3) ZIG(35,7,3) - ZIG(36,3,4) ZIG(37,1,5) ZIG(38,0,6) ZIG(39,2,5) - ZIG(40,4,4) ZIG(41,5,4) ZIG(42,6,4) ZIG(43,7,4) - ZIG(44,3,5) ZIG(45,1,6) ZIG(46,2,6) ZIG(47,4,5) - ZIG(48,5,5) ZIG(49,6,5) ZIG(50,7,5) ZIG(51,3,6) - ZIG(52,0,7) ZIG(53,1,7) ZIG(54,4,6) ZIG(55,5,6) - ZIG(56,6,6) ZIG(57,7,6) ZIG(58,2,7) ZIG(59,3,7) - ZIG(60,4,7) ZIG(61,5,7) ZIG(62,6,7) ZIG(63,7,7) - } - else - { - ZIG( 0,0,0) ZIG( 1,0,1) ZIG( 2,1,0) ZIG( 3,2,0) - ZIG( 4,1,1) ZIG( 5,0,2) ZIG( 6,0,3) ZIG( 7,1,2) - ZIG( 8,2,1) ZIG( 9,3,0) ZIG(10,4,0) ZIG(11,3,1) - ZIG(12,2,2) ZIG(13,1,3) ZIG(14,0,4) ZIG(15,0,5) - ZIG(16,1,4) ZIG(17,2,3) ZIG(18,3,2) ZIG(19,4,1) - ZIG(20,5,0) ZIG(21,6,0) ZIG(22,5,1) ZIG(23,4,2) - ZIG(24,3,3) ZIG(25,2,4) ZIG(26,1,5) ZIG(27,0,6) - ZIG(28,0,7) ZIG(29,1,6) ZIG(30,2,5) ZIG(31,3,4) - ZIG(32,4,3) ZIG(33,5,2) ZIG(34,6,1) ZIG(35,7,0) - ZIG(36,7,1) ZIG(37,6,2) ZIG(38,5,3) ZIG(39,4,4) - ZIG(40,3,5) ZIG(41,2,6) ZIG(42,1,7) ZIG(43,2,7) - ZIG(44,3,6) ZIG(45,4,5) ZIG(46,5,4) ZIG(47,6,3) - ZIG(48,7,2) ZIG(49,7,3) ZIG(50,6,4) ZIG(51,5,5) - ZIG(52,4,6) ZIG(53,3,7) ZIG(54,4,7) ZIG(55,5,6) - ZIG(56,6,5) ZIG(57,7,4) ZIG(58,7,5) ZIG(59,6,6) - ZIG(60,5,7) ZIG(61,6,7) ZIG(62,7,6) ZIG(63,7,7) - } -} - -static inline void scan_zigzag_4x4full( int level[16], int16_t dct[4][4], int b_interlaced ) -{ - if( b_interlaced ) - { - ZIG( 0,0,0) ZIG( 1,1,0) ZIG( 2,0,1) ZIG( 3,2,0) - ZIG( 4,3,0) ZIG( 5,1,1) ZIG( 6,2,1) ZIG( 7,3,1) - ZIG( 8,0,2) ZIG( 9,1,2) ZIG(10,2,2) ZIG(11,3,2) - ZIG(12,0,3) ZIG(13,1,3) ZIG(14,2,3) ZIG(15,3,3) - } - else - { - ZIG( 0,0,0) ZIG( 1,0,1) ZIG( 2,1,0) ZIG( 3,2,0) - ZIG( 4,1,1) ZIG( 5,0,2) ZIG( 6,0,3) ZIG( 7,1,2) - ZIG( 8,2,1) ZIG( 9,3,0) ZIG(10,3,1) ZIG(11,2,2) - ZIG(12,1,3) ZIG(13,2,3) ZIG(14,3,2) ZIG(15,3,3) - } -} - -static inline void scan_zigzag_4x4( int level[15], int16_t dct[4][4], int b_interlaced ) -{ - if( b_interlaced ) - { - ZIG( 0,1,0) ZIG( 1,0,1) ZIG( 2,2,0) - ZIG( 3,3,0) ZIG( 4,1,1) ZIG( 5,2,1) ZIG( 6,3,1) - ZIG( 7,0,2) ZIG( 8,1,2) ZIG( 9,2,2) ZIG(10,3,2) - ZIG(11,0,3) ZIG(12,1,3) ZIG(13,2,3) ZIG(14,3,3) - } - else - { - ZIG( 0,0,1) ZIG( 1,1,0) ZIG( 2,2,0) - ZIG( 3,1,1) ZIG( 4,0,2) ZIG( 5,0,3) ZIG( 6,1,2) - ZIG( 7,2,1) ZIG( 8,3,0) ZIG( 9,3,1) ZIG(10,2,2) - ZIG(11,1,3) ZIG(12,2,3) ZIG(13,3,2) ZIG(14,3,3) - } -} - -static inline void scan_zigzag_2x2_dc( int level[4], int16_t dct[2][2] ) +static inline void zigzag_scan_2x2_dc( int level[4], int16_t dct[2][2] ) { ZIG(0,0,0) ZIG(1,0,1) @@ -140,50 +57,6 @@ static inline void scan_zigzag_2x2_dc( int level[4], int16_t dct[2][2] ) } #undef ZIG -#define ZIG(i,y,x) {\ - int oe = x+y*FENC_STRIDE;\ - int od = x+y*FDEC_STRIDE;\ - level[i] = p_src[oe] - p_dst[od];\ - p_dst[od] = p_src[oe];\ -} - -static inline void sub_zigzag_4x4full( int level[16], const uint8_t *p_src, uint8_t *p_dst, int b_interlaced ) -{ - if( b_interlaced ) - { - ZIG( 0,0,0) ZIG( 1,1,0) ZIG( 2,0,1) ZIG( 3,2,0) - ZIG( 4,3,0) ZIG( 5,1,1) ZIG( 6,2,1) ZIG( 7,3,1) - ZIG( 8,0,2) ZIG( 9,1,2) ZIG(10,2,2) ZIG(11,3,2) - ZIG(12,0,3) ZIG(13,1,3) ZIG(14,2,3) ZIG(15,3,3) - } - else - { - ZIG( 0,0,0) ZIG( 1,0,1) ZIG( 2,1,0) ZIG( 3,2,0) - ZIG( 4,1,1) ZIG( 5,0,2) ZIG( 6,0,3) ZIG( 7,1,2) - ZIG( 8,2,1) ZIG( 9,3,0) ZIG(10,3,1) ZIG(11,2,2) - ZIG(12,1,3) ZIG(13,2,3) ZIG(14,3,2) ZIG(15,3,3) - } -} - -static inline void sub_zigzag_4x4( int level[15], const uint8_t *p_src, uint8_t *p_dst, int b_interlaced ) -{ - if( b_interlaced ) - { - ZIG( 0,1,0) ZIG( 1,0,1) ZIG( 2,2,0) - ZIG( 3,3,0) ZIG( 4,1,1) ZIG( 5,2,1) ZIG( 6,3,1) - ZIG( 7,0,2) ZIG( 8,1,2) ZIG( 9,2,2) ZIG(10,3,2) - ZIG(11,0,3) ZIG(12,1,3) ZIG(13,2,3) ZIG(14,3,3) - } - else - { - ZIG( 0,0,1) ZIG( 1,1,0) ZIG( 2,2,0) - ZIG( 3,1,1) ZIG( 4,0,2) ZIG( 5,0,3) ZIG( 6,1,2) - ZIG( 7,2,1) ZIG( 8,3,0) ZIG( 9,3,1) ZIG(10,2,2) - ZIG(11,1,3) ZIG(12,2,3) ZIG(13,3,2) ZIG(14,3,3) - } -} -#undef ZIG - static void quant_8x8( x264_t *h, int16_t dct[8][8], int quant_mf[6][8][8], int i_qscale, int b_intra ) { const int i_qbits = 16 + i_qscale / 6; @@ -267,7 +140,7 @@ void x264_mb_encode_i4x4( x264_t *h, int idx, int i_qscale ) if( h->mb.b_lossless ) { - sub_zigzag_4x4full( h->dct.block[idx].luma4x4, p_src, p_dst, h->mb.b_interlaced ); + h->zigzagf.sub_4x4( h->dct.block[idx].luma4x4, p_src, p_dst ); return; } @@ -278,7 +151,7 @@ void x264_mb_encode_i4x4( x264_t *h, int idx, int i_qscale ) else quant_4x4( h, dct4x4, h->quant4_mf[CQM_4IY], i_qscale, 1 ); - scan_zigzag_4x4full( h->dct.block[idx].luma4x4, dct4x4, h->mb.b_interlaced ); + h->zigzagf.scan_4x4( h->dct.block[idx].luma4x4, dct4x4 ); h->quantf.dequant_4x4( dct4x4, h->dequant4_mf[CQM_4IY], i_qscale ); /* output samples to fdec */ @@ -300,7 +173,7 @@ void x264_mb_encode_i8x8( x264_t *h, int idx, int i_qscale ) else quant_8x8( h, dct8x8, h->quant8_mf[CQM_8IY], i_qscale, 1 ); - scan_zigzag_8x8full( h->dct.luma8x8[idx], dct8x8, h->mb.b_interlaced ); + h->zigzagf.scan_8x8( h->dct.luma8x8[idx], dct8x8 ); h->quantf.dequant_8x8( dct8x8, h->dequant8_mf[CQM_8IY], i_qscale ); h->dctf.add8x8_idct8( p_dst, dct8x8 ); } @@ -320,11 +193,11 @@ static void x264_mb_encode_i16x16( x264_t *h, int i_qscale ) { int oe = block_idx_x[i]*4 + block_idx_y[i]*4*FENC_STRIDE; int od = block_idx_x[i]*4 + block_idx_y[i]*4*FDEC_STRIDE; - sub_zigzag_4x4( h->dct.block[i].residual_ac, p_src+oe, p_dst+od, h->mb.b_interlaced ); + h->zigzagf.sub_4x4ac( h->dct.block[i].residual_ac, p_src+oe, p_dst+od ); dct4x4[0][block_idx_x[i]][block_idx_y[i]] = p_src[oe] - p_dst[od]; p_dst[od] = p_src[oe]; } - scan_zigzag_4x4full( h->dct.luma16x16_dc, dct4x4[0], h->mb.b_interlaced ); + h->zigzagf.scan_4x4( h->dct.luma16x16_dc, dct4x4[0] ); return; } @@ -340,13 +213,13 @@ static void x264_mb_encode_i16x16( x264_t *h, int i_qscale ) else quant_4x4( h, dct4x4[1+i], h->quant4_mf[CQM_4IY], i_qscale, 1 ); - scan_zigzag_4x4( h->dct.block[i].residual_ac, dct4x4[1+i], h->mb.b_interlaced ); + h->zigzagf.scan_4x4ac( h->dct.block[i].residual_ac, dct4x4[1+i] ); h->quantf.dequant_4x4( dct4x4[1+i], h->dequant4_mf[CQM_4IY], i_qscale ); } h->dctf.dct4x4dc( dct4x4[0] ); quant_4x4_dc( h, dct4x4[0], h->quant4_mf[CQM_4IY], i_qscale ); - scan_zigzag_4x4full( h->dct.luma16x16_dc, dct4x4[0], h->mb.b_interlaced ); + h->zigzagf.scan_4x4( h->dct.luma16x16_dc, dct4x4[0] ); /* output samples to fdec */ h->dctf.idct4x4dc( dct4x4[0] ); @@ -382,7 +255,7 @@ static void x264_mb_encode_8x8_chroma( x264_t *h, int b_inter, int i_qscale ) { int oe = block_idx_x[i]*4 + block_idx_y[i]*4*FENC_STRIDE; int od = block_idx_x[i]*4 + block_idx_y[i]*4*FDEC_STRIDE; - sub_zigzag_4x4( h->dct.block[16+i+ch*4].residual_ac, p_src+oe, p_dst+od, h->mb.b_interlaced ); + h->zigzagf.sub_4x4ac( h->dct.block[16+i+ch*4].residual_ac, p_src+oe, p_dst+od ); h->dct.chroma_dc[ch][i] = p_src[oe] - p_dst[od]; p_dst[od] = p_src[oe]; } @@ -398,7 +271,7 @@ static void x264_mb_encode_8x8_chroma( x264_t *h, int b_inter, int i_qscale ) /* no trellis; it doesn't seem to help chroma noticeably */ quant_4x4( h, dct4x4[i], h->quant4_mf[CQM_4IC + b_inter], i_qscale, !b_inter ); - scan_zigzag_4x4( h->dct.block[16+i+ch*4].residual_ac, dct4x4[i], h->mb.b_interlaced ); + h->zigzagf.scan_4x4ac( h->dct.block[16+i+ch*4].residual_ac, dct4x4[i] ); if( b_decimate ) { @@ -408,7 +281,7 @@ static void x264_mb_encode_8x8_chroma( x264_t *h, int b_inter, int i_qscale ) h->dctf.dct2x2dc( dct2x2 ); quant_2x2_dc( h, dct2x2, h->quant4_mf[CQM_4IC + b_inter], i_qscale, !b_inter ); - scan_zigzag_2x2_dc( h->dct.chroma_dc[ch], dct2x2 ); + zigzag_scan_2x2_dc( h->dct.chroma_dc[ch], dct2x2 ); /* output samples to fdec */ h->dctf.idct2x2dc( dct2x2 ); @@ -573,10 +446,9 @@ void x264_macroblock_encode( x264_t *h ) { int x = 4*block_idx_x[i4x4]; int y = 4*block_idx_y[i4x4]; - sub_zigzag_4x4full( h->dct.block[i4x4].luma4x4, + h->zigzagf.sub_4x4( h->dct.block[i4x4].luma4x4, h->mb.pic.p_fenc[0]+x+y*FENC_STRIDE, - h->mb.pic.p_fdec[0]+x+y*FDEC_STRIDE, - h->mb.b_interlaced ); + h->mb.pic.p_fdec[0]+x+y*FDEC_STRIDE ); } } else if( h->mb.b_transform_8x8 ) @@ -595,7 +467,7 @@ void x264_macroblock_encode( x264_t *h ) else quant_8x8( h, dct8x8[idx], h->quant8_mf[CQM_8PY], i_qp, 0 ); - scan_zigzag_8x8full( h->dct.luma8x8[idx], dct8x8[idx], h->mb.b_interlaced ); + h->zigzagf.scan_8x8( h->dct.luma8x8[idx], dct8x8[idx] ); if( b_decimate ) { @@ -647,7 +519,7 @@ void x264_macroblock_encode( x264_t *h ) else quant_4x4( h, dct4x4[idx], h->quant4_mf[CQM_4PY], i_qp, 0 ); - scan_zigzag_4x4full( h->dct.block[idx].luma4x4, dct4x4[idx], h->mb.b_interlaced ); + h->zigzagf.scan_4x4( h->dct.block[idx].luma4x4, dct4x4[idx] ); if( b_decimate ) i_decimate_8x8 += x264_mb_decimate_score( h->dct.block[idx].luma4x4, 16 ); @@ -824,7 +696,7 @@ int x264_macroblock_probe_skip( x264_t *h, int b_bidir ) const int idx = i8x8 * 4 + i4x4; quant_4x4( h, dct4x4[idx], (int(*)[4][4])def_quant4_mf, i_qp, 0 ); - scan_zigzag_4x4full( dctscan, dct4x4[idx], h->mb.b_interlaced ); + h->zigzagf.scan_4x4( dctscan, dct4x4[idx] ); i_decimate_mb += x264_mb_decimate_score( dctscan, 16 ); @@ -870,7 +742,7 @@ int x264_macroblock_probe_skip( x264_t *h, int b_bidir ) for( i4x4 = 0, i_decimate_mb = 0; i4x4 < 4; i4x4++ ) { quant_4x4( h, dct4x4[i4x4], (int(*)[4][4])def_quant4_mf, i_qp, 0 ); - scan_zigzag_4x4( dctscan, dct4x4[i4x4], h->mb.b_interlaced ); + h->zigzagf.scan_4x4ac( dctscan, dct4x4[i4x4] ); i_decimate_mb += x264_mb_decimate_score( dctscan, 15 ); if( i_decimate_mb >= 7 ) @@ -962,7 +834,7 @@ void x264_macroblock_encode_p8x8( x264_t *h, int i8 ) int16_t dct8x8[8][8]; h->dctf.sub8x8_dct8( dct8x8, p_fenc, p_fdec ); quant_8x8( h, dct8x8, h->quant8_mf[CQM_8PY], i_qp, 0 ); - scan_zigzag_8x8full( h->dct.luma8x8[i8], dct8x8, h->mb.b_interlaced ); + h->zigzagf.scan_8x8( h->dct.luma8x8[i8], dct8x8 ); if( b_decimate ) nnz8x8 = 4 <= x264_mb_decimate_score( h->dct.luma8x8[i8], 64 ); @@ -985,7 +857,7 @@ void x264_macroblock_encode_p8x8( x264_t *h, int i8 ) quant_4x4( h, dct4x4[2], h->quant4_mf[CQM_4PY], i_qp, 0 ); quant_4x4( h, dct4x4[3], h->quant4_mf[CQM_4PY], i_qp, 0 ); for( i4 = 0; i4 < 4; i4++ ) - scan_zigzag_4x4full( h->dct.block[i8*4+i4].luma4x4, dct4x4[i4], h->mb.b_interlaced ); + h->zigzagf.scan_4x4( h->dct.block[i8*4+i4].luma4x4, dct4x4[i4] ); if( b_decimate ) { @@ -1015,7 +887,7 @@ void x264_macroblock_encode_p8x8( x264_t *h, int i8 ) h->dctf.sub4x4_dct( dct4x4, p_fenc, p_fdec ); quant_4x4( h, dct4x4, h->quant4_mf[CQM_4PC], i_qp, 0 ); - scan_zigzag_4x4( h->dct.block[16+i8+ch*4].residual_ac, dct4x4, h->mb.b_interlaced ); + h->zigzagf.scan_4x4ac( h->dct.block[16+i8+ch*4].residual_ac, dct4x4 ); if( array_non_zero( (int*)dct4x4, sizeof(dct4x4)/sizeof(int) ) ) { h->quantf.dequant_4x4( dct4x4, h->dequant4_mf[CQM_4PC], i_qp ); diff --git a/x264.h b/x264.h index 82e56921..c95b128d 100644 --- a/x264.h +++ b/x264.h @@ -35,7 +35,7 @@ #include -#define X264_BUILD 50 +#define X264_BUILD 51 /* x264_t: * opaque handler for decoder and encoder */