/*****************************************************************************
* quant.c: quantization and level-run
*****************************************************************************
- * Copyright (C) 2005-2010 x264 project
+ * Copyright (C) 2005-2011 x264 project
*
* Authors: Loren Merritt <lorenm@u.washington.edu>
* Fiona Glaser <fiona@x264.com>
}
}
+static ALWAYS_INLINE void idct_dequant_2x2_dconly( dctcoef out[4], dctcoef dct[4], int dequant_mf )
+{
+ int d0 = dct[0] + dct[1];
+ int d1 = dct[2] + dct[3];
+ int d2 = dct[0] - dct[1];
+ int d3 = dct[2] - dct[3];
+ out[0] = (d0 + d1) * dequant_mf >> 5;
+ out[1] = (d0 - d1) * dequant_mf >> 5;
+ out[2] = (d2 + d3) * dequant_mf >> 5;
+ out[3] = (d2 - d3) * dequant_mf >> 5;
+}
+
+static ALWAYS_INLINE int idct_dequant_round_2x2_dc( dctcoef ref[4], dctcoef dct[4], int dequant_mf )
+{
+ dctcoef out[4];
+ idct_dequant_2x2_dconly( out, dct, dequant_mf );
+ return ((ref[0] ^ (out[0]+32))
+ | (ref[1] ^ (out[1]+32))
+ | (ref[2] ^ (out[2]+32))
+ | (ref[3] ^ (out[3]+32))) >> 6;
+}
+
+static int optimize_chroma_dc( dctcoef dct[4], int dequant_mf )
+{
+ /* dequant_mf = h->dequant4_mf[CQM_4IC + b_inter][i_qp%6][0] << i_qp/6, max 32*64 */
+ dctcoef dct_orig[4];
+ int coeff, nz;
+
+ idct_dequant_2x2_dconly( dct_orig, dct, dequant_mf );
+ dct_orig[0] += 32;
+ dct_orig[1] += 32;
+ dct_orig[2] += 32;
+ dct_orig[3] += 32;
+
+ /* If the DC coefficients already round to zero, terminate early. */
+ if( !((dct_orig[0]|dct_orig[1]|dct_orig[2]|dct_orig[3])>>6) )
+ return 0;
+
+ /* Start with the highest frequency coefficient... is this the best option? */
+ for( nz = 0, coeff = 3; coeff >= 0; coeff-- )
+ {
+ int level = dct[coeff];
+ int sign = level>>31 | 1; /* dct2x2[coeff] < 0 ? -1 : 1 */
+
+ while( level )
+ {
+ dct[coeff] = level - sign;
+ if( idct_dequant_round_2x2_dc( dct_orig, dct, dequant_mf ) )
+ {
+ nz = 1;
+ dct[coeff] = level;
+ break;
+ }
+ level -= sign;
+ }
+ }
+
+ return nz;
+}
+
static void x264_denoise_dct( dctcoef *dct, uint32_t *sum, udctcoef *offset, int size )
{
- for( int i = 1; i < size; i++ )
+ for( int i = 0; i < size; i++ )
{
int level = dct[i];
int sign = level>>31;
pf->dequant_4x4_dc = dequant_4x4_dc;
pf->dequant_8x8 = dequant_8x8;
+ pf->optimize_chroma_dc = optimize_chroma_dc;
+
pf->denoise_dct = x264_denoise_dct;
pf->decimate_score15 = x264_decimate_score15;
pf->decimate_score16 = x264_decimate_score16;
#if HIGH_BIT_DEPTH
#if HAVE_MMX
- if( cpu&X264_CPU_MMX )
- {
- pf->quant_4x4 = x264_quant_4x4_mmx;
- pf->quant_8x8 = x264_quant_8x8_mmx;
- }
if( cpu&X264_CPU_MMXEXT )
{
- pf->quant_2x2_dc = x264_quant_2x2_dc_mmxext;
- pf->quant_4x4_dc = x264_quant_4x4_dc_mmxext;
#if ARCH_X86
pf->denoise_dct = x264_denoise_dct_mmx;
pf->decimate_score15 = x264_decimate_score15_mmxext;
pf->decimate_score16 = x264_decimate_score16_mmxext_slowctz;
}
pf->decimate_score64 = x264_decimate_score64_mmxext;
+ pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4_mmxext;
pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_mmxext;
pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16_mmxext;
pf->coeff_last[ DCT_LUMA_8x8] = x264_coeff_last64_mmxext;
pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2;
if( cpu&X264_CPU_LZCNT )
{
+ pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4_mmxext_lzcnt;
pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2_lzcnt;
pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2_lzcnt;
pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2_lzcnt;
pf->dequant_4x4 = x264_dequant_4x4_flat16_sse2;
pf->dequant_8x8 = x264_dequant_8x8_flat16_sse2;
}
+ pf->optimize_chroma_dc = x264_optimize_chroma_dc_sse2;
pf->denoise_dct = x264_denoise_dct_sse2;
pf->decimate_score15 = x264_decimate_score15_sse2;
pf->decimate_score16 = x264_decimate_score16_sse2;
pf->quant_4x4_dc = x264_quant_4x4_dc_ssse3;
pf->quant_4x4 = x264_quant_4x4_ssse3;
pf->quant_8x8 = x264_quant_8x8_ssse3;
+ pf->optimize_chroma_dc = x264_optimize_chroma_dc_ssse3;
pf->denoise_dct = x264_denoise_dct_ssse3;
pf->decimate_score15 = x264_decimate_score15_ssse3;
pf->decimate_score16 = x264_decimate_score16_ssse3;
pf->quant_4x4_dc = x264_quant_4x4_dc_sse4;
pf->quant_4x4 = x264_quant_4x4_sse4;
pf->quant_8x8 = x264_quant_8x8_sse4;
+ pf->optimize_chroma_dc = x264_optimize_chroma_dc_sse4;
+ }
+
+ if( cpu&X264_CPU_AVX )
+ {
+ pf->dequant_4x4 = x264_dequant_4x4_avx;
+ pf->dequant_8x8 = x264_dequant_8x8_avx;
+ pf->dequant_4x4_dc = x264_dequant_4x4dc_avx;
+ pf->optimize_chroma_dc = x264_optimize_chroma_dc_avx;
+ pf->denoise_dct = x264_denoise_dct_avx;
}
#endif // HAVE_MMX