1 /*****************************************************************************
2 * macroblock.c: h264 encoder library
3 *****************************************************************************
4 * Copyright (C) 2003-2008 x264 project
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
7 * Loren Merritt <lorenm@u.washington.edu>
8 * Fiona Glaser <fiona@x264.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
23 *****************************************************************************/
25 #include "common/common.h"
26 #include "macroblock.h"
28 /* These chroma DC functions don't have assembly versions and are only used here. */
30 #define ZIG(i,y,x) level[i] = dct[x][y];
31 static inline void zigzag_scan_2x2_dc( int16_t level[4], int16_t dct[2][2] )
40 #define IDCT_DEQUANT_START \
41 int d0 = dct[0][0] + dct[0][1]; \
42 int d1 = dct[1][0] + dct[1][1]; \
43 int d2 = dct[0][0] - dct[0][1]; \
44 int d3 = dct[1][0] - dct[1][1]; \
45 int dmf = dequant_mf[i_qp%6][0][0]; \
46 int qbits = i_qp/6 - 5; \
53 static inline void idct_dequant_2x2_dc( int16_t dct[2][2], int16_t dct4x4[4][4][4], int dequant_mf[6][4][4], int i_qp )
56 dct4x4[0][0][0] = (d0 + d1) * dmf >> -qbits;
57 dct4x4[1][0][0] = (d0 - d1) * dmf >> -qbits;
58 dct4x4[2][0][0] = (d2 + d3) * dmf >> -qbits;
59 dct4x4[3][0][0] = (d2 - d3) * dmf >> -qbits;
62 static inline void idct_dequant_2x2_dconly( int16_t dct[2][2], int dequant_mf[6][4][4], int i_qp )
65 dct[0][0] = (d0 + d1) * dmf >> -qbits;
66 dct[0][1] = (d0 - d1) * dmf >> -qbits;
67 dct[1][0] = (d2 + d3) * dmf >> -qbits;
68 dct[1][1] = (d2 - d3) * dmf >> -qbits;
71 static inline void dct2x2dc( int16_t d[2][2], int16_t dct4x4[4][4][4] )
73 int d0 = dct4x4[0][0][0] + dct4x4[1][0][0];
74 int d1 = dct4x4[2][0][0] + dct4x4[3][0][0];
75 int d2 = dct4x4[0][0][0] - dct4x4[1][0][0];
76 int d3 = dct4x4[2][0][0] - dct4x4[3][0][0];
87 static ALWAYS_INLINE int x264_quant_4x4( x264_t *h, int16_t dct[4][4], int i_qp, int i_ctxBlockCat, int b_intra, int idx )
89 int i_quant_cat = b_intra ? CQM_4IY : CQM_4PY;
91 return x264_quant_4x4_trellis( h, dct, i_quant_cat, i_qp, i_ctxBlockCat, b_intra, idx );
93 return h->quantf.quant_4x4( dct, h->quant4_mf[i_quant_cat][i_qp], h->quant4_bias[i_quant_cat][i_qp] );
96 static ALWAYS_INLINE int x264_quant_8x8( x264_t *h, int16_t dct[8][8], int i_qp, int b_intra, int idx )
98 int i_quant_cat = b_intra ? CQM_8IY : CQM_8PY;
100 return x264_quant_8x8_trellis( h, dct, i_quant_cat, i_qp, b_intra, idx );
102 return h->quantf.quant_8x8( dct, h->quant8_mf[i_quant_cat][i_qp], h->quant8_bias[i_quant_cat][i_qp] );
105 /* All encoding functions must output the correct CBP and NNZ values.
106 * The entropy coding functions will check CBP first, then NNZ, before
107 * actually reading the DCT coefficients. NNZ still must be correct even
108 * if CBP is zero because of the use of NNZ values for context selection.
109 * "NNZ" need only be 0 or 1 rather than the exact coefficient count because
110 * that is only needed in CAVLC, and will be calculated by CAVLC's residual
111 * coding and stored as necessary. */
113 /* This means that decimation can be done merely by adjusting the CBP and NNZ
114 * rather than memsetting the coefficients. */
116 void x264_mb_encode_i4x4( x264_t *h, int idx, int i_qp )
119 uint8_t *p_src = &h->mb.pic.p_fenc[0][block_idx_xy_fenc[idx]];
120 uint8_t *p_dst = &h->mb.pic.p_fdec[0][block_idx_xy_fdec[idx]];
121 DECLARE_ALIGNED_16( int16_t dct4x4[4][4] );
123 if( h->mb.b_lossless )
125 h->zigzagf.sub_4x4( h->dct.luma4x4[idx], p_src, p_dst );
126 nz = array_non_zero( h->dct.luma4x4[idx] );
127 h->mb.cache.non_zero_count[x264_scan8[idx]] = nz;
128 h->mb.i_cbp_luma |= nz<<(idx>>2);
132 h->dctf.sub4x4_dct( dct4x4, p_src, p_dst );
134 nz = x264_quant_4x4( h, dct4x4, i_qp, DCT_LUMA_4x4, 1, idx );
135 h->mb.cache.non_zero_count[x264_scan8[idx]] = nz;
138 h->mb.i_cbp_luma |= 1<<(idx>>2);
139 h->zigzagf.scan_4x4( h->dct.luma4x4[idx], dct4x4 );
140 h->quantf.dequant_4x4( dct4x4, h->dequant4_mf[CQM_4IY], i_qp );
141 h->dctf.add4x4_idct( p_dst, dct4x4 );
145 #define STORE_8x8_NNZ(idx,nz)\
147 *(uint16_t*)&h->mb.cache.non_zero_count[x264_scan8[idx*4+0]] = nz * 0x0101;\
148 *(uint16_t*)&h->mb.cache.non_zero_count[x264_scan8[idx*4+2]] = nz * 0x0101;\
151 void x264_mb_encode_i8x8( x264_t *h, int idx, int i_qp )
154 int y = 8 * (idx>>1);
156 uint8_t *p_src = &h->mb.pic.p_fenc[0][x+y*FENC_STRIDE];
157 uint8_t *p_dst = &h->mb.pic.p_fdec[0][x+y*FDEC_STRIDE];
158 DECLARE_ALIGNED_16( int16_t dct8x8[8][8] );
160 if( h->mb.b_lossless )
162 h->zigzagf.sub_8x8( h->dct.luma8x8[idx], p_src, p_dst );
163 nz = array_non_zero( h->dct.luma8x8[idx] );
164 STORE_8x8_NNZ(idx,nz);
165 h->mb.i_cbp_luma |= nz<<idx;
169 h->dctf.sub8x8_dct8( dct8x8, p_src, p_dst );
171 nz = x264_quant_8x8( h, dct8x8, i_qp, 1, idx );
174 h->mb.i_cbp_luma |= 1<<idx;
175 h->zigzagf.scan_8x8( h->dct.luma8x8[idx], dct8x8 );
176 h->quantf.dequant_8x8( dct8x8, h->dequant8_mf[CQM_8IY], i_qp );
177 h->dctf.add8x8_idct8( p_dst, dct8x8 );
178 STORE_8x8_NNZ(idx,1);
181 STORE_8x8_NNZ(idx,0);
184 static void x264_mb_encode_i16x16( x264_t *h, int i_qp )
186 uint8_t *p_src = h->mb.pic.p_fenc[0];
187 uint8_t *p_dst = h->mb.pic.p_fdec[0];
189 DECLARE_ALIGNED_16( int16_t dct4x4[16][4][4] );
190 DECLARE_ALIGNED_16( int16_t dct_dc4x4[4][4] );
193 int b_decimate = h->sh.i_type == SLICE_TYPE_B || (h->param.analyse.b_dct_decimate && h->sh.i_type == SLICE_TYPE_P);
194 int decimate_score = b_decimate ? 0 : 9;
196 if( h->mb.b_lossless )
198 for( i = 0; i < 16; i++ )
200 int oe = block_idx_xy_fenc[i];
201 int od = block_idx_xy_fdec[i];
202 h->zigzagf.sub_4x4( h->dct.luma4x4[i], p_src+oe, p_dst+od );
203 dct_dc4x4[0][block_idx_yx_1d[i]] = h->dct.luma4x4[i][0];
204 h->dct.luma4x4[i][0] = 0;
205 nz = array_non_zero( h->dct.luma4x4[i] );
206 h->mb.cache.non_zero_count[x264_scan8[i]] = nz;
207 h->mb.i_cbp_luma |= nz;
209 h->mb.i_cbp_luma *= 0xf;
210 h->mb.cache.non_zero_count[x264_scan8[24]] = array_non_zero( dct_dc4x4 );
211 h->zigzagf.scan_4x4( h->dct.luma16x16_dc, dct_dc4x4 );
215 h->dctf.sub16x16_dct( dct4x4, p_src, p_dst );
217 for( i = 0; i < 16; i++ )
220 dct_dc4x4[0][block_idx_xy_1d[i]] = dct4x4[i][0][0];
223 /* quant/scan/dequant */
224 nz = x264_quant_4x4( h, dct4x4[i], i_qp, DCT_LUMA_AC, 1, i );
225 h->mb.cache.non_zero_count[x264_scan8[i]] = nz;
228 h->zigzagf.scan_4x4( h->dct.luma4x4[i], dct4x4[i] );
229 h->quantf.dequant_4x4( dct4x4[i], h->dequant4_mf[CQM_4IY], i_qp );
230 if( decimate_score < 6 ) decimate_score += h->quantf.decimate_score15( h->dct.luma4x4[i] );
231 h->mb.i_cbp_luma = 0xf;
235 /* Writing the 16 CBFs in an i16x16 block is quite costly, so decimation can save many bits. */
236 /* More useful with CAVLC, but still useful with CABAC. */
237 if( decimate_score < 6 )
239 h->mb.i_cbp_luma = 0;
240 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 0]] = 0;
241 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 2]] = 0;
242 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 8]] = 0;
243 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[10]] = 0;
246 h->dctf.dct4x4dc( dct_dc4x4 );
247 if( h->mb.b_trellis )
248 nz = x264_quant_dc_trellis( h, (int16_t*)dct_dc4x4, CQM_4IY, i_qp, DCT_LUMA_DC, 1);
250 nz = h->quantf.quant_4x4_dc( dct_dc4x4, h->quant4_mf[CQM_4IY][i_qp][0]>>1, h->quant4_bias[CQM_4IY][i_qp][0]<<1 );
252 h->mb.cache.non_zero_count[x264_scan8[24]] = nz;
255 h->zigzagf.scan_4x4( h->dct.luma16x16_dc, dct_dc4x4 );
257 /* output samples to fdec */
258 h->dctf.idct4x4dc( dct_dc4x4 );
259 h->quantf.dequant_4x4_dc( dct_dc4x4, h->dequant4_mf[CQM_4IY], i_qp ); /* XXX not inversed */
260 if( h->mb.i_cbp_luma )
261 for( i = 0; i < 16; i++ )
262 dct4x4[i][0][0] = dct_dc4x4[0][block_idx_xy_1d[i]];
265 /* put pixels to fdec */
266 if( h->mb.i_cbp_luma )
267 h->dctf.add16x16_idct( p_dst, dct4x4 );
269 h->dctf.add16x16_idct_dc( p_dst, dct_dc4x4 );
272 void x264_mb_encode_8x8_chroma( x264_t *h, int b_inter, int i_qp )
274 int i, ch, nz, nz_dc;
275 int b_decimate = b_inter && (h->sh.i_type == SLICE_TYPE_B || h->param.analyse.b_dct_decimate);
276 h->mb.i_cbp_chroma = 0;
278 for( ch = 0; ch < 2; ch++ )
280 uint8_t *p_src = h->mb.pic.p_fenc[1+ch];
281 uint8_t *p_dst = h->mb.pic.p_fdec[1+ch];
282 int i_decimate_score = 0;
285 DECLARE_ALIGNED_16( int16_t dct2x2[2][2] );
286 DECLARE_ALIGNED_16( int16_t dct4x4[4][4][4] );
288 if( h->mb.b_lossless )
290 for( i = 0; i < 4; i++ )
292 int oe = block_idx_x[i]*4 + block_idx_y[i]*4*FENC_STRIDE;
293 int od = block_idx_x[i]*4 + block_idx_y[i]*4*FDEC_STRIDE;
294 h->zigzagf.sub_4x4( h->dct.luma4x4[16+i+ch*4], p_src+oe, p_dst+od );
295 h->dct.chroma_dc[ch][i] = h->dct.luma4x4[16+i+ch*4][0];
296 h->dct.luma4x4[16+i+ch*4][0] = 0;
297 nz = array_non_zero( h->dct.luma4x4[16+i+ch*4] );
298 h->mb.cache.non_zero_count[x264_scan8[16+i+ch*4]] = nz;
299 h->mb.i_cbp_chroma |= nz;
301 h->mb.cache.non_zero_count[x264_scan8[25]+ch] = array_non_zero( h->dct.chroma_dc[ch] );
305 h->dctf.sub8x8_dct( dct4x4, p_src, p_dst );
306 dct2x2dc( dct2x2, dct4x4 );
307 /* calculate dct coeffs */
308 for( i = 0; i < 4; i++ )
310 if( h->mb.b_trellis )
311 nz = x264_quant_4x4_trellis( h, dct4x4[i], CQM_4IC+b_inter, i_qp, DCT_CHROMA_AC, !b_inter, 0 );
313 nz = h->quantf.quant_4x4( dct4x4[i], h->quant4_mf[CQM_4IC+b_inter][i_qp], h->quant4_bias[CQM_4IC+b_inter][i_qp] );
314 h->mb.cache.non_zero_count[x264_scan8[16+i+ch*4]] = nz;
318 h->zigzagf.scan_4x4( h->dct.luma4x4[16+i+ch*4], dct4x4[i] );
319 h->quantf.dequant_4x4( dct4x4[i], h->dequant4_mf[CQM_4IC + b_inter], i_qp );
321 i_decimate_score += h->quantf.decimate_score15( h->dct.luma4x4[16+i+ch*4] );
325 if( h->mb.b_trellis )
326 nz_dc = x264_quant_dc_trellis( h, (int16_t*)dct2x2, CQM_4IC+b_inter, i_qp, DCT_CHROMA_DC, !b_inter );
328 nz_dc = h->quantf.quant_2x2_dc( dct2x2, h->quant4_mf[CQM_4IC+b_inter][i_qp][0]>>1, h->quant4_bias[CQM_4IC+b_inter][i_qp][0]<<1 );
330 h->mb.cache.non_zero_count[x264_scan8[25]+ch] = nz_dc;
332 if( (b_decimate && i_decimate_score < 7) || !nz_ac )
334 /* Decimate the block */
335 h->mb.cache.non_zero_count[x264_scan8[16+0]+24*ch] = 0;
336 h->mb.cache.non_zero_count[x264_scan8[16+1]+24*ch] = 0;
337 h->mb.cache.non_zero_count[x264_scan8[16+2]+24*ch] = 0;
338 h->mb.cache.non_zero_count[x264_scan8[16+3]+24*ch] = 0;
339 if( !nz_dc ) /* Whole block is empty */
342 zigzag_scan_2x2_dc( h->dct.chroma_dc[ch], dct2x2 );
343 idct_dequant_2x2_dconly( dct2x2, h->dequant4_mf[CQM_4IC + b_inter], i_qp );
344 h->dctf.add8x8_idct_dc( p_dst, dct2x2 );
348 h->mb.i_cbp_chroma = 1;
351 zigzag_scan_2x2_dc( h->dct.chroma_dc[ch], dct2x2 );
352 idct_dequant_2x2_dc( dct2x2, dct4x4, h->dequant4_mf[CQM_4IC + b_inter], i_qp );
354 h->dctf.add8x8_idct( p_dst, dct4x4 );
358 if( h->mb.i_cbp_chroma )
359 h->mb.i_cbp_chroma = 2; /* dc+ac (we can't do only ac) */
360 else if( h->mb.cache.non_zero_count[x264_scan8[25]] |
361 h->mb.cache.non_zero_count[x264_scan8[26]] )
362 h->mb.i_cbp_chroma = 1; /* dc only */
365 static void x264_macroblock_encode_skip( x264_t *h )
367 h->mb.i_cbp_luma = 0x00;
368 h->mb.i_cbp_chroma = 0x00;
369 memset( h->mb.cache.non_zero_count, 0, X264_SCAN8_SIZE );
371 h->mb.cbp[h->mb.i_mb_xy] = 0;
374 /*****************************************************************************
375 * x264_macroblock_encode_pskip:
376 * Encode an already marked skip block
377 *****************************************************************************/
378 static void x264_macroblock_encode_pskip( x264_t *h )
380 const int mvx = x264_clip3( h->mb.cache.mv[0][x264_scan8[0]][0],
381 h->mb.mv_min[0], h->mb.mv_max[0] );
382 const int mvy = x264_clip3( h->mb.cache.mv[0][x264_scan8[0]][1],
383 h->mb.mv_min[1], h->mb.mv_max[1] );
385 /* don't do pskip motion compensation if it was already done in macroblock_analyse */
386 if( !h->mb.b_skip_mc )
388 h->mc.mc_luma( h->mb.pic.p_fdec[0], FDEC_STRIDE,
389 h->mb.pic.p_fref[0][0], h->mb.pic.i_stride[0],
392 h->mc.mc_chroma( h->mb.pic.p_fdec[1], FDEC_STRIDE,
393 h->mb.pic.p_fref[0][0][4], h->mb.pic.i_stride[1],
396 h->mc.mc_chroma( h->mb.pic.p_fdec[2], FDEC_STRIDE,
397 h->mb.pic.p_fref[0][0][5], h->mb.pic.i_stride[2],
401 x264_macroblock_encode_skip( h );
404 /*****************************************************************************
405 * Intra prediction for predictive lossless mode.
406 *****************************************************************************/
408 /* Note that these functions take a shortcut (mc.copy instead of actual pixel prediction) which assumes
409 * that the edge pixels of the reconstructed frame are the same as that of the source frame. This means
410 * they will only work correctly if the neighboring blocks are losslessly coded. In practice, this means
411 * lossless mode cannot be mixed with lossy mode within a frame. */
412 /* This can be resolved by explicitly copying the edge pixels after doing the mc.copy, but this doesn't
413 * need to be done unless we decide to allow mixing lossless and lossy compression. */
415 void x264_predict_lossless_8x8_chroma( x264_t *h, int i_mode )
417 int stride = h->fenc->i_stride[1] << h->mb.b_interlaced;
418 if( i_mode == I_PRED_CHROMA_V )
420 h->mc.copy[PIXEL_8x8]( h->mb.pic.p_fdec[1], FDEC_STRIDE, h->mb.pic.p_fenc_plane[1]-stride, stride, 8 );
421 h->mc.copy[PIXEL_8x8]( h->mb.pic.p_fdec[2], FDEC_STRIDE, h->mb.pic.p_fenc_plane[2]-stride, stride, 8 );
423 else if( i_mode == I_PRED_CHROMA_H )
425 h->mc.copy[PIXEL_8x8]( h->mb.pic.p_fdec[1], FDEC_STRIDE, h->mb.pic.p_fenc_plane[1]-1, stride, 8 );
426 h->mc.copy[PIXEL_8x8]( h->mb.pic.p_fdec[2], FDEC_STRIDE, h->mb.pic.p_fenc_plane[2]-1, stride, 8 );
430 h->predict_8x8c[i_mode]( h->mb.pic.p_fdec[1] );
431 h->predict_8x8c[i_mode]( h->mb.pic.p_fdec[2] );
435 void x264_predict_lossless_4x4( x264_t *h, uint8_t *p_dst, int idx, int i_mode )
437 int stride = h->fenc->i_stride[0] << h->mb.b_interlaced;
438 uint8_t *p_src = h->mb.pic.p_fenc_plane[0] + block_idx_x[idx]*4 + block_idx_y[idx]*4 * stride;
440 if( i_mode == I_PRED_4x4_V )
441 h->mc.copy[PIXEL_4x4]( p_dst, FDEC_STRIDE, p_src-stride, stride, 4 );
442 else if( i_mode == I_PRED_4x4_H )
443 h->mc.copy[PIXEL_4x4]( p_dst, FDEC_STRIDE, p_src-1, stride, 4 );
445 h->predict_4x4[i_mode]( p_dst );
448 void x264_predict_lossless_8x8( x264_t *h, uint8_t *p_dst, int idx, int i_mode, uint8_t edge[33] )
450 int stride = h->fenc->i_stride[0] << h->mb.b_interlaced;
451 uint8_t *p_src = h->mb.pic.p_fenc_plane[0] + (idx&1)*8 + (idx>>1)*8*stride;
453 if( i_mode == I_PRED_8x8_V )
454 h->mc.copy[PIXEL_8x8]( p_dst, FDEC_STRIDE, p_src-stride, stride, 8 );
455 else if( i_mode == I_PRED_8x8_H )
456 h->mc.copy[PIXEL_8x8]( p_dst, FDEC_STRIDE, p_src-1, stride, 8 );
458 h->predict_8x8[i_mode]( p_dst, edge );
461 void x264_predict_lossless_16x16( x264_t *h, int i_mode )
463 int stride = h->fenc->i_stride[0] << h->mb.b_interlaced;
464 if( i_mode == I_PRED_16x16_V )
465 h->mc.copy[PIXEL_16x16]( h->mb.pic.p_fdec[0], FDEC_STRIDE, h->mb.pic.p_fenc_plane[0]-stride, stride, 16 );
466 else if( i_mode == I_PRED_16x16_H )
467 h->mc.copy_16x16_unaligned( h->mb.pic.p_fdec[0], FDEC_STRIDE, h->mb.pic.p_fenc_plane[0]-1, stride, 16 );
469 h->predict_16x16[i_mode]( h->mb.pic.p_fdec[0] );
472 /*****************************************************************************
473 * x264_macroblock_encode:
474 *****************************************************************************/
475 void x264_macroblock_encode( x264_t *h )
478 int i_qp = h->mb.i_qp;
479 int b_decimate = h->sh.i_type == SLICE_TYPE_B || h->param.analyse.b_dct_decimate;
480 int b_force_no_skip = 0;
482 h->mb.i_cbp_luma = 0;
483 h->mb.cache.non_zero_count[x264_scan8[24]] = 0;
486 && h->mb.i_mb_xy == h->sh.i_first_mb + h->mb.i_mb_stride
487 && IS_SKIP(h->mb.type[h->sh.i_first_mb]) )
489 /* The first skip is predicted to be a frame mb pair.
490 * We don't yet support the aff part of mbaff, so force it to non-skip
491 * so that we can pick the aff flag. */
493 if( IS_SKIP(h->mb.i_type) )
495 if( h->mb.i_type == P_SKIP )
497 else if( h->mb.i_type == B_SKIP )
498 h->mb.i_type = B_DIRECT;
502 if( h->mb.i_type == P_SKIP )
505 x264_macroblock_encode_pskip( h );
508 if( h->mb.i_type == B_SKIP )
510 /* don't do bskip motion compensation if it was already done in macroblock_analyse */
511 if( !h->mb.b_skip_mc )
513 x264_macroblock_encode_skip( h );
517 if( h->mb.i_type == I_16x16 )
519 const int i_mode = h->mb.i_intra16x16_pred_mode;
520 h->mb.b_transform_8x8 = 0;
522 if( h->mb.b_lossless )
523 x264_predict_lossless_16x16( h, i_mode );
525 h->predict_16x16[i_mode]( h->mb.pic.p_fdec[0] );
527 /* encode the 16x16 macroblock */
528 x264_mb_encode_i16x16( h, i_qp );
530 else if( h->mb.i_type == I_8x8 )
532 DECLARE_ALIGNED_16( uint8_t edge[33] );
533 h->mb.b_transform_8x8 = 1;
534 /* If we already encoded 3 of the 4 i8x8 blocks, we don't have to do them again. */
535 if( h->mb.i_skip_intra )
537 h->mc.copy[PIXEL_16x16]( h->mb.pic.p_fdec[0], FDEC_STRIDE, h->mb.pic.i8x8_fdec_buf, 16, 16 );
538 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 0]] = h->mb.pic.i8x8_nnz_buf[0];
539 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 2]] = h->mb.pic.i8x8_nnz_buf[1];
540 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 8]] = h->mb.pic.i8x8_nnz_buf[2];
541 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[10]] = h->mb.pic.i8x8_nnz_buf[3];
542 h->mb.i_cbp_luma = h->mb.pic.i8x8_cbp;
543 /* In RD mode, restore the now-overwritten DCT data. */
544 if( h->mb.i_skip_intra == 2 )
545 h->mc.memcpy_aligned( h->dct.luma8x8, h->mb.pic.i8x8_dct_buf, sizeof(h->mb.pic.i8x8_dct_buf) );
547 for( i = h->mb.i_skip_intra ? 3 : 0 ; i < 4; i++ )
549 uint8_t *p_dst = &h->mb.pic.p_fdec[0][8 * (i&1) + 8 * (i>>1) * FDEC_STRIDE];
550 int i_mode = h->mb.cache.intra4x4_pred_mode[x264_scan8[4*i]];
551 x264_predict_8x8_filter( p_dst, edge, h->mb.i_neighbour8[i], x264_pred_i4x4_neighbors[i_mode] );
553 if( h->mb.b_lossless )
554 x264_predict_lossless_8x8( h, p_dst, i, i_mode, edge );
556 h->predict_8x8[i_mode]( p_dst, edge );
558 x264_mb_encode_i8x8( h, i, i_qp );
561 else if( h->mb.i_type == I_4x4 )
563 h->mb.b_transform_8x8 = 0;
564 /* If we already encoded 15 of the 16 i4x4 blocks, we don't have to do them again. */
565 if( h->mb.i_skip_intra )
567 h->mc.copy[PIXEL_16x16]( h->mb.pic.p_fdec[0], FDEC_STRIDE, h->mb.pic.i4x4_fdec_buf, 16, 16 );
568 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 0]] = h->mb.pic.i4x4_nnz_buf[0];
569 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 2]] = h->mb.pic.i4x4_nnz_buf[1];
570 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 8]] = h->mb.pic.i4x4_nnz_buf[2];
571 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[10]] = h->mb.pic.i4x4_nnz_buf[3];
572 h->mb.i_cbp_luma = h->mb.pic.i4x4_cbp;
573 /* In RD mode, restore the now-overwritten DCT data. */
574 if( h->mb.i_skip_intra == 2 )
575 h->mc.memcpy_aligned( h->dct.luma4x4, h->mb.pic.i4x4_dct_buf, sizeof(h->mb.pic.i4x4_dct_buf) );
577 for( i = h->mb.i_skip_intra ? 15 : 0 ; i < 16; i++ )
579 uint8_t *p_dst = &h->mb.pic.p_fdec[0][block_idx_xy_fdec[i]];
580 int i_mode = h->mb.cache.intra4x4_pred_mode[x264_scan8[i]];
582 if( (h->mb.i_neighbour4[i] & (MB_TOPRIGHT|MB_TOP)) == MB_TOP )
583 /* emulate missing topright samples */
584 *(uint32_t*) &p_dst[4-FDEC_STRIDE] = p_dst[3-FDEC_STRIDE] * 0x01010101U;
586 if( h->mb.b_lossless )
587 x264_predict_lossless_4x4( h, p_dst, i, i_mode );
589 h->predict_4x4[i_mode]( p_dst );
590 x264_mb_encode_i4x4( h, i, i_qp );
596 int i_decimate_mb = 0;
598 /* Don't repeat motion compensation if it was already done in non-RD transform analysis */
599 if( !h->mb.b_skip_mc )
602 if( h->mb.b_lossless )
604 if( h->mb.b_transform_8x8 )
605 for( i8x8 = 0; i8x8 < 4; i8x8++ )
609 h->zigzagf.sub_8x8( h->dct.luma8x8[i8x8],
610 h->mb.pic.p_fenc[0]+x+y*FENC_STRIDE,
611 h->mb.pic.p_fdec[0]+x+y*FDEC_STRIDE );
612 nz = array_non_zero( h->dct.luma8x8[i8x8] );
613 STORE_8x8_NNZ(i8x8,nz);
614 h->mb.i_cbp_luma |= nz << i8x8;
617 for( i4x4 = 0; i4x4 < 16; i4x4++ )
619 h->zigzagf.sub_4x4( h->dct.luma4x4[i4x4],
620 h->mb.pic.p_fenc[0]+block_idx_xy_fenc[i4x4],
621 h->mb.pic.p_fdec[0]+block_idx_xy_fdec[i4x4] );
622 nz = array_non_zero( h->dct.luma4x4[i4x4] );
623 h->mb.cache.non_zero_count[x264_scan8[i4x4]] = nz;
624 h->mb.i_cbp_luma |= nz << (i4x4>>2);
627 else if( h->mb.b_transform_8x8 )
629 DECLARE_ALIGNED_16( int16_t dct8x8[4][8][8] );
630 b_decimate &= !h->mb.b_trellis; // 8x8 trellis is inherently optimal decimation
631 h->dctf.sub16x16_dct8( dct8x8, h->mb.pic.p_fenc[0], h->mb.pic.p_fdec[0] );
632 h->nr_count[1] += h->mb.b_noise_reduction * 4;
634 for( idx = 0; idx < 4; idx++ )
636 if( h->mb.b_noise_reduction )
637 h->quantf.denoise_dct( *dct8x8[idx], h->nr_residual_sum[1], h->nr_offset[1], 64 );
638 nz = x264_quant_8x8( h, dct8x8[idx], i_qp, 0, idx );
642 h->zigzagf.scan_8x8( h->dct.luma8x8[idx], dct8x8[idx] );
645 int i_decimate_8x8 = h->quantf.decimate_score64( h->dct.luma8x8[idx] );
646 i_decimate_mb += i_decimate_8x8;
647 if( i_decimate_8x8 >= 4 )
648 h->mb.i_cbp_luma |= 1<<idx;
651 h->mb.i_cbp_luma |= 1<<idx;
655 if( i_decimate_mb < 6 && b_decimate )
657 h->mb.i_cbp_luma = 0;
658 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 0]] = 0;
659 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 2]] = 0;
660 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 8]] = 0;
661 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[10]] = 0;
665 for( idx = 0; idx < 4; idx++ )
667 if( h->mb.i_cbp_luma&(1<<idx) )
669 h->quantf.dequant_8x8( dct8x8[idx], h->dequant8_mf[CQM_8PY], i_qp );
670 h->dctf.add8x8_idct8( &h->mb.pic.p_fdec[0][(idx&1)*8 + (idx>>1)*8*FDEC_STRIDE], dct8x8[idx] );
671 STORE_8x8_NNZ(idx,1);
674 STORE_8x8_NNZ(idx,0);
680 DECLARE_ALIGNED_16( int16_t dct4x4[16][4][4] );
681 h->dctf.sub16x16_dct( dct4x4, h->mb.pic.p_fenc[0], h->mb.pic.p_fdec[0] );
682 h->nr_count[0] += h->mb.b_noise_reduction * 16;
684 for( i8x8 = 0; i8x8 < 4; i8x8++ )
686 int i_decimate_8x8 = 0;
689 /* encode one 4x4 block */
690 for( i4x4 = 0; i4x4 < 4; i4x4++ )
692 idx = i8x8 * 4 + i4x4;
694 if( h->mb.b_noise_reduction )
695 h->quantf.denoise_dct( *dct4x4[idx], h->nr_residual_sum[0], h->nr_offset[0], 16 );
696 nz = x264_quant_4x4( h, dct4x4[idx], i_qp, DCT_LUMA_4x4, 0, idx );
697 h->mb.cache.non_zero_count[x264_scan8[idx]] = nz;
701 h->zigzagf.scan_4x4( h->dct.luma4x4[idx], dct4x4[idx] );
702 h->quantf.dequant_4x4( dct4x4[idx], h->dequant4_mf[CQM_4PY], i_qp );
703 if( b_decimate && i_decimate_8x8 < 6 )
704 i_decimate_8x8 += h->quantf.decimate_score16( h->dct.luma4x4[idx] );
709 /* decimate this 8x8 block */
710 i_decimate_mb += i_decimate_8x8;
713 if( i_decimate_8x8 < 4 )
714 STORE_8x8_NNZ(i8x8,0)
716 h->mb.i_cbp_luma |= 1<<i8x8;
720 h->dctf.add8x8_idct( &h->mb.pic.p_fdec[0][(i8x8&1)*8 + (i8x8>>1)*8*FDEC_STRIDE], &dct4x4[i8x8*4] );
721 h->mb.i_cbp_luma |= 1<<i8x8;
727 if( i_decimate_mb < 6 )
729 h->mb.i_cbp_luma = 0;
730 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 0]] = 0;
731 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 2]] = 0;
732 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[ 8]] = 0;
733 *(uint32_t*)&h->mb.cache.non_zero_count[x264_scan8[10]] = 0;
737 for( i8x8 = 0; i8x8 < 4; i8x8++ )
738 if( h->mb.i_cbp_luma&(1<<i8x8) )
739 h->dctf.add8x8_idct( &h->mb.pic.p_fdec[0][(i8x8&1)*8 + (i8x8>>1)*8*FDEC_STRIDE], &dct4x4[i8x8*4] );
746 if( IS_INTRA( h->mb.i_type ) )
748 const int i_mode = h->mb.i_chroma_pred_mode;
749 if( h->mb.b_lossless )
750 x264_predict_lossless_8x8_chroma( h, i_mode );
753 h->predict_8x8c[i_mode]( h->mb.pic.p_fdec[1] );
754 h->predict_8x8c[i_mode]( h->mb.pic.p_fdec[2] );
758 /* encode the 8x8 blocks */
759 x264_mb_encode_8x8_chroma( h, !IS_INTRA( h->mb.i_type ), h->mb.i_chroma_qp );
761 if( h->param.b_cabac )
763 i_cbp_dc = h->mb.cache.non_zero_count[x264_scan8[24]]
764 | h->mb.cache.non_zero_count[x264_scan8[25]] << 1
765 | h->mb.cache.non_zero_count[x264_scan8[26]] << 2;
769 h->mb.cbp[h->mb.i_mb_xy] = (i_cbp_dc << 8) | (h->mb.i_cbp_chroma << 4) | h->mb.i_cbp_luma;
772 * XXX: in the me perhaps we should take x264_mb_predict_mv_pskip into account
773 * (if multiple mv give same result)*/
774 if( !b_force_no_skip )
776 if( h->mb.i_type == P_L0 && h->mb.i_partition == D_16x16 &&
777 !(h->mb.i_cbp_luma | h->mb.i_cbp_chroma) &&
778 *(uint32_t*)h->mb.cache.mv[0][x264_scan8[0]] == *(uint32_t*)h->mb.cache.pskip_mv
779 && h->mb.cache.ref[0][x264_scan8[0]] == 0 )
781 h->mb.i_type = P_SKIP;
784 /* Check for B_SKIP */
785 if( h->mb.i_type == B_DIRECT && !(h->mb.i_cbp_luma | h->mb.i_cbp_chroma) )
787 h->mb.i_type = B_SKIP;
792 /*****************************************************************************
793 * x264_macroblock_probe_skip:
794 * Check if the current MB could be encoded as a [PB]_SKIP (it supposes you use
796 *****************************************************************************/
797 int x264_macroblock_probe_skip( x264_t *h, int b_bidir )
799 DECLARE_ALIGNED_16( int16_t dct4x4[4][4][4] );
800 DECLARE_ALIGNED_16( int16_t dct2x2[2][2] );
801 DECLARE_ALIGNED_16( int16_t dctscan[16] );
803 int i_qp = h->mb.i_qp;
813 mvp[0] = x264_clip3( h->mb.cache.pskip_mv[0], h->mb.mv_min[0], h->mb.mv_max[0] );
814 mvp[1] = x264_clip3( h->mb.cache.pskip_mv[1], h->mb.mv_min[1], h->mb.mv_max[1] );
816 /* Motion compensation */
817 h->mc.mc_luma( h->mb.pic.p_fdec[0], FDEC_STRIDE,
818 h->mb.pic.p_fref[0][0], h->mb.pic.i_stride[0],
819 mvp[0], mvp[1], 16, 16 );
822 for( i8x8 = 0, i_decimate_mb = 0; i8x8 < 4; i8x8++ )
824 int fenc_offset = (i8x8&1) * 8 + (i8x8>>1) * FENC_STRIDE * 8;
825 int fdec_offset = (i8x8&1) * 8 + (i8x8>>1) * FDEC_STRIDE * 8;
827 h->dctf.sub8x8_dct( dct4x4, h->mb.pic.p_fenc[0] + fenc_offset,
828 h->mb.pic.p_fdec[0] + fdec_offset );
829 /* encode one 4x4 block */
830 for( i4x4 = 0; i4x4 < 4; i4x4++ )
832 if( !h->quantf.quant_4x4( dct4x4[i4x4], h->quant4_mf[CQM_4PY][i_qp], h->quant4_bias[CQM_4PY][i_qp] ) )
834 h->zigzagf.scan_4x4( dctscan, dct4x4[i4x4] );
835 i_decimate_mb += h->quantf.decimate_score16( dctscan );
836 if( i_decimate_mb >= 6 )
842 i_qp = h->mb.i_chroma_qp;
843 thresh = (x264_lambda2_tab[i_qp] + 32) >> 6;
845 for( ch = 0; ch < 2; ch++ )
847 uint8_t *p_src = h->mb.pic.p_fenc[1+ch];
848 uint8_t *p_dst = h->mb.pic.p_fdec[1+ch];
852 h->mc.mc_chroma( h->mb.pic.p_fdec[1+ch], FDEC_STRIDE,
853 h->mb.pic.p_fref[0][0][4+ch], h->mb.pic.i_stride[1+ch],
854 mvp[0], mvp[1], 8, 8 );
857 /* there is almost never a termination during chroma, but we can't avoid the check entirely */
858 /* so instead we check SSD and skip the actual check if the score is low enough. */
859 ssd = h->pixf.ssd[PIXEL_8x8]( p_dst, FDEC_STRIDE, p_src, FENC_STRIDE );
863 h->dctf.sub8x8_dct( dct4x4, p_src, p_dst );
865 /* calculate dct DC */
866 dct2x2dc( dct2x2, dct4x4 );
867 if( h->quantf.quant_2x2_dc( dct2x2, h->quant4_mf[CQM_4PC][i_qp][0]>>1, h->quant4_bias[CQM_4PC][i_qp][0]<<1 ) )
870 /* If there wasn't a termination in DC, we can check against a much higher threshold. */
874 /* calculate dct coeffs */
875 for( i4x4 = 0, i_decimate_mb = 0; i4x4 < 4; i4x4++ )
877 if( !h->quantf.quant_4x4( dct4x4[i4x4], h->quant4_mf[CQM_4PC][i_qp], h->quant4_bias[CQM_4PC][i_qp] ) )
879 h->zigzagf.scan_4x4( dctscan, dct4x4[i4x4] );
880 i_decimate_mb += h->quantf.decimate_score15( dctscan );
881 if( i_decimate_mb >= 7 )
890 /****************************************************************************
891 * DCT-domain noise reduction / adaptive deadzone
893 ****************************************************************************/
895 void x264_noise_reduction_update( x264_t *h )
898 for( cat = 0; cat < 2; cat++ )
900 int size = cat ? 64 : 16;
901 const uint16_t *weight = cat ? x264_dct8_weight2_tab : x264_dct4_weight2_tab;
903 if( h->nr_count[cat] > (cat ? (1<<16) : (1<<18)) )
905 for( i = 0; i < size; i++ )
906 h->nr_residual_sum[cat][i] >>= 1;
907 h->nr_count[cat] >>= 1;
910 for( i = 0; i < size; i++ )
911 h->nr_offset[cat][i] =
912 ((uint64_t)h->param.analyse.i_noise_reduction * h->nr_count[cat]
913 + h->nr_residual_sum[cat][i]/2)
914 / ((uint64_t)h->nr_residual_sum[cat][i] * weight[i]/256 + 1);
918 /*****************************************************************************
919 * RD only; 4 calls to this do not make up for one macroblock_encode.
920 * doesn't transform chroma dc.
921 *****************************************************************************/
922 void x264_macroblock_encode_p8x8( x264_t *h, int i8 )
924 int i_qp = h->mb.i_qp;
925 uint8_t *p_fenc = h->mb.pic.p_fenc[0] + (i8&1)*8 + (i8>>1)*8*FENC_STRIDE;
926 uint8_t *p_fdec = h->mb.pic.p_fdec[0] + (i8&1)*8 + (i8>>1)*8*FDEC_STRIDE;
927 int b_decimate = h->sh.i_type == SLICE_TYPE_B || h->param.analyse.b_dct_decimate;
931 x264_mb_mc_8x8( h, i8 );
933 if( h->mb.b_lossless )
936 if( h->mb.b_transform_8x8 )
938 h->zigzagf.sub_8x8( h->dct.luma8x8[i8], p_fenc, p_fdec );
939 nnz8x8 = array_non_zero( h->dct.luma8x8[i8] );
940 STORE_8x8_NNZ(i8,nnz8x8);
944 for( i4 = i8*4; i4 < i8*4+4; i4++ )
947 h->zigzagf.sub_4x4( h->dct.luma4x4[i4],
948 h->mb.pic.p_fenc[0]+block_idx_xy_fenc[i4],
949 h->mb.pic.p_fdec[0]+block_idx_xy_fdec[i4] );
950 nz = array_non_zero( h->dct.luma4x4[i4] );
951 h->mb.cache.non_zero_count[x264_scan8[i4]] = nz;
955 for( ch = 0; ch < 2; ch++ )
957 p_fenc = h->mb.pic.p_fenc[1+ch] + (i8&1)*4 + (i8>>1)*4*FENC_STRIDE;
958 p_fdec = h->mb.pic.p_fdec[1+ch] + (i8&1)*4 + (i8>>1)*4*FDEC_STRIDE;
959 h->zigzagf.sub_4x4( h->dct.luma4x4[16+i8+ch*4], p_fenc, p_fdec );
960 h->dct.luma4x4[16+i8+ch*4][0] = 0;
961 h->mb.cache.non_zero_count[x264_scan8[16+i8+ch*4]] = array_non_zero( h->dct.luma4x4[16+i8+ch*4] );
966 if( h->mb.b_transform_8x8 )
968 DECLARE_ALIGNED_16( int16_t dct8x8[8][8] );
969 h->dctf.sub8x8_dct8( dct8x8, p_fenc, p_fdec );
970 nnz8x8 = x264_quant_8x8( h, dct8x8, i_qp, 0, i8 );
973 h->zigzagf.scan_8x8( h->dct.luma8x8[i8], dct8x8 );
975 if( b_decimate && !h->mb.b_trellis )
976 nnz8x8 = 4 <= h->quantf.decimate_score64( h->dct.luma8x8[i8] );
980 h->quantf.dequant_8x8( dct8x8, h->dequant8_mf[CQM_8PY], i_qp );
981 h->dctf.add8x8_idct8( p_fdec, dct8x8 );
993 int i_decimate_8x8 = 0;
994 DECLARE_ALIGNED_16( int16_t dct4x4[4][4][4] );
995 h->dctf.sub8x8_dct( dct4x4, p_fenc, p_fdec );
996 for( i4 = 0; i4 < 4; i4++ )
998 nz = x264_quant_4x4( h, dct4x4[i4], i_qp, DCT_LUMA_4x4, 0, i8*4+i4 );
999 h->mb.cache.non_zero_count[x264_scan8[i8*4+i4]] = nz;
1002 h->zigzagf.scan_4x4( h->dct.luma4x4[i8*4+i4], dct4x4[i4] );
1003 h->quantf.dequant_4x4( dct4x4[i4], h->dequant4_mf[CQM_4PY], i_qp );
1005 i_decimate_8x8 += h->quantf.decimate_score16( h->dct.luma4x4[i8*4+i4] );
1010 if( b_decimate && i_decimate_8x8 < 4 )
1014 h->dctf.add8x8_idct( p_fdec, dct4x4 );
1016 STORE_8x8_NNZ(i8,0);
1019 i_qp = h->mb.i_chroma_qp;
1021 for( ch = 0; ch < 2; ch++ )
1023 DECLARE_ALIGNED_16( int16_t dct4x4[4][4] );
1024 p_fenc = h->mb.pic.p_fenc[1+ch] + (i8&1)*4 + (i8>>1)*4*FENC_STRIDE;
1025 p_fdec = h->mb.pic.p_fdec[1+ch] + (i8&1)*4 + (i8>>1)*4*FDEC_STRIDE;
1027 h->dctf.sub4x4_dct( dct4x4, p_fenc, p_fdec );
1030 if( h->mb.b_trellis )
1031 nz = x264_quant_4x4_trellis( h, dct4x4, CQM_4PC, i_qp, DCT_CHROMA_AC, 0, 0 );
1033 nz = h->quantf.quant_4x4( dct4x4, h->quant4_mf[CQM_4PC][i_qp], h->quant4_bias[CQM_4PC][i_qp] );
1035 h->mb.cache.non_zero_count[x264_scan8[16+i8+ch*4]] = nz;
1038 h->zigzagf.scan_4x4( h->dct.luma4x4[16+i8+ch*4], dct4x4 );
1039 h->quantf.dequant_4x4( dct4x4, h->dequant4_mf[CQM_4PC], i_qp );
1040 h->dctf.add4x4_idct( p_fdec, dct4x4 );
1044 h->mb.i_cbp_luma &= ~(1 << i8);
1045 h->mb.i_cbp_luma |= nnz8x8 << i8;
1046 h->mb.i_cbp_chroma = 0x02;
1049 /*****************************************************************************
1050 * RD only, luma only
1051 *****************************************************************************/
1052 void x264_macroblock_encode_p4x4( x264_t *h, int i4 )
1054 int i_qp = h->mb.i_qp;
1055 uint8_t *p_fenc = &h->mb.pic.p_fenc[0][block_idx_xy_fenc[i4]];
1056 uint8_t *p_fdec = &h->mb.pic.p_fdec[0][block_idx_xy_fdec[i4]];
1057 const int i_ref = h->mb.cache.ref[0][x264_scan8[i4]];
1058 const int mvx = x264_clip3( h->mb.cache.mv[0][x264_scan8[i4]][0], h->mb.mv_min[0], h->mb.mv_max[0] );
1059 const int mvy = x264_clip3( h->mb.cache.mv[0][x264_scan8[i4]][1], h->mb.mv_min[1], h->mb.mv_max[1] );
1062 h->mc.mc_luma( p_fdec, FDEC_STRIDE, h->mb.pic.p_fref[0][i_ref], h->mb.pic.i_stride[0], mvx + 4*4*block_idx_x[i4], mvy + 4*4*block_idx_y[i4], 4, 4 );
1064 if( h->mb.b_lossless )
1066 h->zigzagf.sub_4x4( h->dct.luma4x4[i4], p_fenc, p_fdec );
1067 h->mb.cache.non_zero_count[x264_scan8[i4]] = array_non_zero( h->dct.luma4x4[i4] );
1071 DECLARE_ALIGNED_16( int16_t dct4x4[4][4] );
1072 h->dctf.sub4x4_dct( dct4x4, p_fenc, p_fdec );
1073 nz = x264_quant_4x4( h, dct4x4, i_qp, DCT_LUMA_4x4, 0, i4 );
1074 h->mb.cache.non_zero_count[x264_scan8[i4]] = nz;
1077 h->zigzagf.scan_4x4( h->dct.luma4x4[i4], dct4x4 );
1078 h->quantf.dequant_4x4( dct4x4, h->dequant4_mf[CQM_4PY], i_qp );
1079 h->dctf.add4x4_idct( p_fdec, dct4x4 );