1 /*****************************************************************************
2 * macroblock.c: h264 decoder library
3 *****************************************************************************
4 * Copyright (C) 2003 Laurent Aimar
5 * $Id: macroblock.c,v 1.1 2004/06/03 19:27:07 fenrir Exp $
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
29 #include "../core/common.h"
30 #include "../core/vlc.h"
32 #include "macroblock.h"
34 static const uint8_t block_idx_x[16] =
36 0, 1, 0, 1, 2, 3, 2, 3, 0, 1, 0, 1, 2, 3, 2, 3
38 static const uint8_t block_idx_y[16] =
40 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3
42 static const uint8_t block_idx_xy[4][4] =
50 static const int golomb_to_intra4x4_cbp[48]=
52 47, 31, 15, 0, 23, 27, 29, 30, 7, 11, 13, 14, 39, 43, 45, 46,
53 16, 3, 5, 10, 12, 19, 21, 26, 28, 35, 37, 42, 44, 1, 2, 4,
54 8, 17, 18, 20, 24, 6, 9, 22, 25, 32, 33, 34, 36, 40, 38, 41
56 static const int golomb_to_inter_cbp[48]=
58 0, 16, 1, 2, 4, 8, 32, 3, 5, 10, 12, 15, 47, 7, 11, 13,
59 14, 6, 9, 31, 35, 37, 42, 44, 33, 34, 36, 40, 39, 43, 45, 46,
60 17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41
63 static const int i_chroma_qp_table[52] =
65 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
66 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
67 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
68 29, 30, 31, 32, 32, 33, 34, 34, 35, 35,
69 36, 36, 37, 37, 37, 38, 38, 38, 39, 39,
74 void x264_mb_partition_ref_set( x264_macroblock_t *mb, int i_list, int i_part, int i_ref )
80 x264_mb_partition_getxy( mb, i_part, 0, &x, &y );
81 if( mb->i_partition == D_16x16 )
85 else if( mb->i_partition == D_16x8 )
89 else if( mb->i_partition == D_8x16 )
99 for( dx = 0; dx < w; dx++ )
101 for( dy = 0; dy < h; dy++ )
103 mb->partition[x+dx][y+dy].i_ref[i_list] = i_ref;
108 void x264_mb_partition_mv_set( x264_macroblock_t *mb, int i_list, int i_part, int i_sub, int mv[2] )
114 x264_mb_partition_getxy( mb, i_part, i_sub, &x, &y );
115 x264_mb_partition_size ( mb, i_part, i_sub, &w, &h );
117 for( dx = 0; dx < w; dx++ )
119 for( dy = 0; dy < h; dy++ )
121 mb->partition[x+dx][y+dy].mv[i_list][0] = mv[0];
122 mb->partition[x+dx][y+dy].mv[i_list][1] = mv[1];
128 int x264_macroblock_read_cabac( x264_t *h, bs_t *s, x264_macroblock_t *mb )
133 static int x264_macroblock_decode_ipcm( x264_t *h, bs_t *s, x264_macroblock_t *mb )
140 #define BLOCK_INDEX_CHROMA_DC (-1)
141 #define BLOCK_INDEX_LUMA_DC (-2)
143 static int bs_read_vlc( bs_t *s, x264_vlc_table_t *table )
151 i_index = bs_show( s, table->i_lookup_bits );
152 if( i_index >= table->i_lookup )
156 i_value = table->lookup[i_index].i_value;
157 i_bits = table->lookup[i_index].i_size;
164 return( -1 ); // FIXME what to do ?
166 bs_skip( s, table->i_lookup_bits );
169 i_index = bs_show( s, i_nb_bits ) + i_value;
170 if( i_index >= table->i_lookup )
174 i_value = table->lookup[i_index].i_value;
175 i_bits = table->lookup[i_index].i_size;
177 bs_skip( s, i_bits );
182 static int block_residual_read_cavlc( x264_t *h, bs_t *s, x264_macroblock_t *mb,
183 int i_idx, int *l, int i_count )
186 int level[16], run[16];
189 int i_total, i_trailing;
193 for( i = 0; i < i_count; i++ )
199 if( i_idx == BLOCK_INDEX_CHROMA_DC )
203 if( ( i_tt = bs_read_vlc( s, h->x264_coeff_token_lookup[4] )) < 0 )
209 i_trailing = i_tt % 4;
213 /* x264_mb_predict_non_zero_code return 0 <-> (16+16+1)>>1 = 16 */
214 static const int ct_index[17] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,3 };
218 if( i_idx == BLOCK_INDEX_LUMA_DC )
220 nC = x264_mb_predict_non_zero_code( h, mb, 0 );
224 nC = x264_mb_predict_non_zero_code( h, mb, i_idx );
227 if( ( i_tt = bs_read_vlc( s, h->x264_coeff_token_lookup[ct_index[nC]] ) ) < 0 )
233 i_trailing = i_tt % 4;
238 mb->block[i_idx].i_non_zero_count = i_total;
246 i_suffix_length = i_total > 10 && i_trailing < 3 ? 1 : 0;
248 for( i = 0; i < i_trailing; i++ )
250 level[i] = 1 - 2 * bs_read1( s );
253 for( ; i < i_total; i++ )
258 i_prefix = bs_read_vlc( s, h->x264_level_prefix_lookup );
264 else if( i_prefix < 14 )
266 if( i_suffix_length > 0 )
268 i_level_code = (i_prefix << i_suffix_length) + bs_read( s, i_suffix_length );
272 i_level_code = i_prefix;
275 else if( i_prefix == 14 )
277 if( i_suffix_length > 0 )
279 i_level_code = (i_prefix << i_suffix_length) + bs_read( s, i_suffix_length );
283 i_level_code = i_prefix + bs_read( s, 4 );
286 else /* if( i_prefix == 15 ) */
288 i_level_code = (i_prefix << i_suffix_length) + bs_read( s, 12 );
289 if( i_suffix_length == 0 )
294 if( i == i_trailing && i_trailing < 3 )
299 level[i] = i_level_code&0x01 ? -((i_level_code+1)/2) : (i_level_code+2)/2;
301 if( i_suffix_length == 0 )
305 if( abs( level[i] ) > ( 3 << ( i_suffix_length - 1 ) ) && i_suffix_length < 6 )
311 if( i_total < i_count )
313 if( i_idx == BLOCK_INDEX_CHROMA_DC )
315 i_zero_left = bs_read_vlc( s, h->x264_total_zeros_dc_lookup[i_total-1] );
319 i_zero_left = bs_read_vlc( s, h->x264_total_zeros_lookup[i_total-1] );
321 if( i_zero_left < 0 )
331 for( i = 0; i < i_total - 1; i++ )
333 if( i_zero_left <= 0 )
337 run[i] = bs_read_vlc( s, h->x264_run_before_lookup[X264_MIN( i_zero_left - 1, 6 )] );
343 i_zero_left -= run[i];
345 if( i_zero_left < 0 )
350 for( ; i < i_total - 1; i++ )
354 run[i_total-1] = i_zero_left;
357 for( i = i_total - 1; i >= 0; i-- )
359 i_coeff += run[i] + 1;
360 l[i_coeff] = level[i];
366 static inline void array_zero_set( int *l, int i_count )
370 for( i = 0; i < i_count; i++ )
376 int x264_macroblock_read_cavlc( x264_t *h, bs_t *s, x264_macroblock_t *mb )
384 /* read the mb type */
385 switch( h->sh.i_type )
388 i_mb_p_offset = 0; /* shut up gcc */
397 i_mb_i_offset = 23 + 5;
400 fprintf( stderr, "internal error or slice unsupported\n" );
404 i_type = bs_read_ue( s );
406 if( i_type < i_mb_i_offset )
408 if( i_type < i_mb_p_offset )
410 fprintf( stderr, "unsupported mb type(B*)\n" );
411 /* TODO for B frame */
416 i_type -= i_mb_p_offset;
421 mb->i_partition = D_16x16;
423 else if( i_type == 1 )
426 mb->i_partition = D_16x8;
428 else if( i_type == 2 )
431 mb->i_partition = D_8x16;
433 else if( i_type == 3 || i_type == 4 )
436 mb->i_partition = D_8x8;
437 b_sub_ref0 = i_type == 4 ? 1 : 0;
441 fprintf( stderr, "invalid mb type\n" );
448 i_type -= i_mb_i_offset;
454 else if( i_type < 25 )
456 mb->i_type = I_16x16;
458 mb->i_intra16x16_pred_mode = (i_type - 1)%4;
459 mb->i_cbp_chroma = ( (i_type-1) / 4 )%3;
460 mb->i_cbp_luma = ((i_type-1) / 12) ? 0x0f : 0x00;
462 else if( i_type == 25 )
468 fprintf( stderr, "invalid mb type (%d)\n", i_type );
473 if( mb->i_type == I_PCM )
475 return x264_macroblock_decode_ipcm( h, s, mb );
478 if( IS_INTRA( mb->i_type ) )
480 if( mb->i_type == I_4x4 )
482 for( i = 0; i < 16; i++ )
486 b_coded = bs_read1( s );
490 mb->block[i].i_intra4x4_pred_mode = x264_mb_predict_intra4x4_mode( h, mb, i );
494 int i_predicted_mode = x264_mb_predict_intra4x4_mode( h, mb, i );
495 int i_mode = bs_read( s, 3 );
497 if( i_mode >= i_predicted_mode )
499 mb->block[i].i_intra4x4_pred_mode = i_mode + 1;
503 mb->block[i].i_intra4x4_pred_mode = i_mode;
509 mb->i_chroma_pred_mode = bs_read_ue( s );
511 else if( mb->i_type == P_8x8 || mb->i_type == B_8x8)
513 /* FIXME won't work for B_8x8 */
515 for( i = 0; i < 4; i++ )
519 i_sub_partition = bs_read_ue( s );
520 switch( i_sub_partition )
523 mb->i_sub_partition[i] = D_L0_8x8;
526 mb->i_sub_partition[i] = D_L0_8x4;
529 mb->i_sub_partition[i] = D_L0_4x8;
532 mb->i_sub_partition[i] = D_L0_4x4;
535 fprintf( stderr, "invalid i_sub_partition\n" );
539 for( i = 0; i < 4; i++ )
543 i_ref = b_sub_ref0 ? 0 : bs_read_te( s, h->sh.i_num_ref_idx_l0_active - 1 );
544 x264_mb_partition_ref_set( mb, 0, i, i_ref );
546 for( i = 0; i < 4; i++ )
551 x264_mb_partition_get( mb, 0, i, 0, &i_ref, NULL, NULL );
553 for( i_sub = 0; i_sub < x264_mb_partition_count_table[mb->i_sub_partition[i]]; i_sub++ )
557 x264_mb_predict_mv( mb, 0, i, i_sub, mv );
558 mv[0] += bs_read_se( s );
559 mv[1] += bs_read_se( s );
561 x264_mb_partition_mv_set( mb, 0, i, i_sub, mv );
565 else if( mb->i_type != B_DIRECT )
567 /* FIXME will work only for P block */
569 /* FIXME using x264_mb_partition_set/x264_mb_partition_get here are too unoptimised
570 * I should introduce ref and mv get/set */
573 int i_part = x264_mb_partition_count_table[mb->i_partition];
575 for( i = 0; i < i_part; i++ )
579 i_ref = bs_read_te( s, h->sh.i_num_ref_idx_l0_active - 1 );
581 x264_mb_partition_ref_set( mb, 0, i, i_ref );
584 for( i = 0; i < i_part; i++ )
588 x264_mb_predict_mv( mb, 0, i, 0, mv );
590 mv[0] += bs_read_se( s );
591 mv[1] += bs_read_se( s );
593 x264_mb_partition_mv_set( mb, 0, i, 0, mv );
597 if( mb->i_type != I_16x16 )
601 i_cbp = bs_read_ue( s );
604 fprintf( stderr, "invalid cbp\n" );
608 if( mb->i_type == I_4x4 )
610 i_cbp = golomb_to_intra4x4_cbp[i_cbp];
614 i_cbp = golomb_to_inter_cbp[i_cbp];
616 mb->i_cbp_luma = i_cbp&0x0f;
617 mb->i_cbp_chroma = i_cbp >> 4;
620 if( mb->i_cbp_luma > 0 || mb->i_cbp_chroma > 0 || mb->i_type == I_16x16 )
622 mb->i_qp = bs_read_se( s ) + h->pps->i_pic_init_qp + h->sh.i_qp_delta;
625 if( mb->i_type == I_16x16 )
628 if( block_residual_read_cavlc( h, s, mb, BLOCK_INDEX_LUMA_DC , mb->luma16x16_dc, 16 ) < 0 )
633 if( mb->i_cbp_luma != 0 )
636 for( i = 0; i < 16; i++ )
638 if( block_residual_read_cavlc( h, s, mb, i, mb->block[i].residual_ac, 15 ) < 0 )
646 for( i = 0; i < 16; i++ )
648 mb->block[i].i_non_zero_count = 0;
649 array_zero_set( mb->block[i].residual_ac, 15 );
655 for( i = 0; i < 16; i++ )
657 if( mb->i_cbp_luma & ( 1 << ( i / 4 ) ) )
659 if( block_residual_read_cavlc( h, s, mb, i, mb->block[i].luma4x4, 16 ) < 0 )
666 mb->block[i].i_non_zero_count = 0;
667 array_zero_set( mb->block[i].luma4x4, 16 );
672 if( mb->i_cbp_chroma &0x03 ) /* Chroma DC residual present */
674 if( block_residual_read_cavlc( h, s, mb, BLOCK_INDEX_CHROMA_DC, mb->chroma_dc[0], 4 ) < 0 ||
675 block_residual_read_cavlc( h, s, mb, BLOCK_INDEX_CHROMA_DC, mb->chroma_dc[1], 4 ) < 0 )
682 array_zero_set( mb->chroma_dc[0], 4 );
683 array_zero_set( mb->chroma_dc[1], 4 );
685 if( mb->i_cbp_chroma&0x02 ) /* Chroma AC residual present */
687 for( i = 0; i < 8; i++ )
689 if( block_residual_read_cavlc( h, s, mb, 16 + i, mb->block[16+i].residual_ac, 15 ) < 0 )
697 for( i = 0; i < 8; i++ )
699 mb->block[16+i].i_non_zero_count = 0;
700 array_zero_set( mb->block[16+i].residual_ac, 15 );
706 mb->i_qp = h->pps->i_pic_init_qp + h->sh.i_qp_delta;
707 for( i = 0; i < 16; i++ )
709 mb->block[i].i_non_zero_count = 0;
710 array_zero_set( mb->block[i].luma4x4, 16 );
712 array_zero_set( mb->chroma_dc[0], 4 );
713 array_zero_set( mb->chroma_dc[1], 4 );
714 for( i = 0; i < 8; i++ )
716 array_zero_set( mb->block[16+i].residual_ac, 15 );
717 mb->block[16+i].i_non_zero_count = 0;
721 //fprintf( stderr, "mb read type=%d\n", mb->i_type );
729 static int x264_mb_pred_mode16x16_valid( x264_macroblock_t *mb, int i_mode )
731 if( ( mb->i_neighbour & (MB_LEFT|MB_TOP) ) == (MB_LEFT|MB_TOP) )
735 else if( ( mb->i_neighbour & MB_LEFT ) )
737 if( i_mode == I_PRED_16x16_DC )
739 return I_PRED_16x16_DC_LEFT;
741 else if( i_mode == I_PRED_16x16_H )
743 return I_PRED_16x16_H;
746 fprintf( stderr, "invalid 16x16 prediction\n" );
747 return I_PRED_16x16_DC_LEFT;
749 else if( ( mb->i_neighbour & MB_TOP ) )
751 if( i_mode == I_PRED_16x16_DC )
753 return I_PRED_16x16_DC_TOP;
755 else if( i_mode == I_PRED_16x16_V )
757 return I_PRED_16x16_V;
760 fprintf( stderr, "invalid 16x16 prediction\n" );
761 return I_PRED_16x16_DC_TOP;
765 return I_PRED_16x16_DC_128;
769 static int x264_mb_pred_mode8x8_valid( x264_macroblock_t *mb, int i_mode )
771 if( ( mb->i_neighbour & (MB_LEFT|MB_TOP) ) == (MB_LEFT|MB_TOP) )
775 else if( ( mb->i_neighbour & MB_LEFT ) )
777 if( i_mode == I_PRED_CHROMA_DC )
779 return I_PRED_CHROMA_DC_LEFT;
781 else if( i_mode == I_PRED_CHROMA_H )
783 return I_PRED_CHROMA_H;
786 fprintf( stderr, "invalid 8x8 prediction\n" );
787 return I_PRED_CHROMA_DC_LEFT;
789 else if( ( mb->i_neighbour & MB_TOP ) )
791 if( i_mode == I_PRED_CHROMA_DC )
793 return I_PRED_CHROMA_DC_TOP;
795 else if( i_mode == I_PRED_CHROMA_V )
797 return I_PRED_CHROMA_V;
800 fprintf( stderr, "invalid 8x8 prediction\n" );
801 return I_PRED_CHROMA_DC_TOP;
805 return I_PRED_CHROMA_DC_128;
809 static int x264_mb_pred_mode4x4_valid( x264_macroblock_t *mb, int idx, int i_mode, int *pb_emu )
812 static const int needmb[16] =
814 MB_LEFT|MB_TOP, MB_TOP,
816 MB_TOP, MB_TOP|MB_TOPRIGHT,
827 b_a = (needmb[idx]&mb->i_neighbour&MB_LEFT) == (needmb[idx]&MB_LEFT);
828 b_b = (needmb[idx]&mb->i_neighbour&MB_TOP) == (needmb[idx]&MB_TOP);
829 b_c = (needmb[idx]&mb->i_neighbour&(MB_TOPRIGHT|MB_PRIVATE)) == (needmb[idx]&(MB_TOPRIGHT|MB_PRIVATE));
831 if( b_c == 0 && b_b )
837 /* handle I_PRED_4x4_DC */
838 if( i_mode == I_PRED_4x4_DC )
842 return I_PRED_4x4_DC;
846 return I_PRED_4x4_DC_LEFT;
850 return I_PRED_4x4_DC_TOP;
852 return I_PRED_4x4_DC_128;
855 /* handle 1 dir needed only */
856 if( ( b_a && i_mode == I_PRED_4x4_H ) ||
857 ( b_b && i_mode == I_PRED_4x4_V ) )
862 /* handle b_c case (b_b always true) */
863 if( b_c && ( i_mode == I_PRED_4x4_DDL || i_mode == I_PRED_4x4_VL ) )
871 /* I_PRED_4x4_DDR, I_PRED_4x4_VR, I_PRED_4x4_HD, I_PRED_4x4_HU */
875 fprintf( stderr, "invalid 4x4 predict mode(%d, mb:%x-%x idx:%d\n", i_mode, mb->i_mb_x, mb->i_mb_y, idx );
876 return I_PRED_CHROMA_DC_128; /* unefficient */
879 /****************************************************************************
881 ****************************************************************************/
882 static const int scan_zigzag_x[16]={0, 1, 0, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 3, 2, 3};
883 static const int scan_zigzag_y[16]={0, 0, 1, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 2, 3, 3};
885 static inline void unscan_zigzag_4x4full( int16_t dct[4][4], int level[16] )
889 for( i = 0; i < 16; i++ )
891 dct[scan_zigzag_y[i]][scan_zigzag_x[i]] = level[i];
894 static inline void unscan_zigzag_4x4( int16_t dct[4][4], int level[15] )
898 for( i = 1; i < 16; i++ )
900 dct[scan_zigzag_y[i]][scan_zigzag_x[i]] = level[i - 1];
904 static inline void unscan_zigzag_2x2_dc( int16_t dct[2][2], int level[4] )
906 dct[0][0] = level[0];
907 dct[0][1] = level[1];
908 dct[1][0] = level[2];
909 dct[1][1] = level[3];
913 int x264_macroblock_decode( x264_t *h, x264_macroblock_t *mb )
915 x264_mb_context_t *ctx = mb->context;
921 if( !IS_INTRA(mb->i_type ) )
923 /* Motion compensation */
929 if( mb->i_type == I_16x16 )
931 int i_mode = x264_mb_pred_mode16x16_valid( mb, mb->i_intra16x16_pred_mode );
932 int16_t luma[16][4][4];
933 int16_t dct4x4[16+1][4][4];
936 /* do the right prediction */
937 h->predict_16x16[i_mode]( ctx->p_fdec[0], ctx->i_fdec[0] );
940 unscan_zigzag_4x4full( dct4x4[0], mb->luma16x16_dc );
941 h->dctf.idct4x4dc( dct4x4[0], dct4x4[0] );
942 x264_mb_dequant_4x4_dc( dct4x4[0], i_qscale );
944 /* decode the 16x16 macroblock */
945 for( i = 0; i < 16; i++ )
947 unscan_zigzag_4x4( dct4x4[1+i], mb->block[i].residual_ac );
948 x264_mb_dequant_4x4( dct4x4[1+i], i_qscale );
951 dct4x4[1+i][0][0] = dct4x4[0][block_idx_y[i]][block_idx_x[i]];
953 h->dctf.idct4x4( luma[i], dct4x4[i+1] );
955 /* put pixels to fdec */
956 h->pixf.add16x16( ctx->p_fdec[0], ctx->i_fdec[0], luma );
958 else if( mb->i_type == I_4x4 )
960 for( i = 0; i < 16; i++ )
963 int16_t dct4x4[4][4];
969 /* Do the right prediction */
970 p_dst_by = ctx->p_fdec[0] + 4 * block_idx_x[i] + 4 * block_idx_y[i] * ctx->i_fdec[0];
971 i_mode = x264_mb_pred_mode4x4_valid( mb, i, mb->block[i].i_intra4x4_pred_mode, &b_emu );
974 fprintf( stderr, "mmmh b_emu\n" );
975 memset( &p_dst_by[4], p_dst_by[3], 4 );
977 h->predict_4x4[i_mode]( p_dst_by, ctx->i_fdec[0] );
979 if( mb->block[i].i_non_zero_count > 0 )
981 /* decode one 4x4 block */
982 unscan_zigzag_4x4full( dct4x4, mb->block[i].luma4x4 );
984 x264_mb_dequant_4x4( dct4x4, i_qscale );
986 h->dctf.idct4x4( luma, dct4x4 );
988 h->pixf.add4x4( p_dst_by, ctx->i_fdec[0], luma );
994 for( i = 0; i < 16; i++ )
998 int16_t dct4x4[4][4];
1000 if( mb->block[i].i_non_zero_count > 0 )
1002 unscan_zigzag_4x4full( dct4x4, mb->block[i].luma4x4 );
1003 x264_mb_dequant_4x4( dct4x4, i_qscale );
1005 h->dctf.idct4x4( luma, dct4x4 );
1007 p_dst_by = ctx->p_fdec[0] + 4 * block_idx_x[i] + 4 * block_idx_y[i] * ctx->i_fdec[0];
1008 h->pixf.add4x4( p_dst_by, ctx->i_fdec[0], luma );
1014 i_qscale = i_chroma_qp_table[x264_clip3( i_qscale + h->pps->i_chroma_qp_index_offset, 0, 51 )];
1015 if( IS_INTRA( mb->i_type ) )
1017 int i_mode = x264_mb_pred_mode8x8_valid( mb, mb->i_chroma_pred_mode );
1018 /* do the right prediction */
1019 h->predict_8x8[i_mode]( ctx->p_fdec[1], ctx->i_fdec[1] );
1020 h->predict_8x8[i_mode]( ctx->p_fdec[2], ctx->i_fdec[2] );
1023 if( mb->i_cbp_chroma != 0 )
1025 for( ch = 0; ch < 2; ch++ )
1027 int16_t chroma[4][4][4];
1028 int16_t dct2x2[2][2];
1029 int16_t dct4x4[4][4][4];
1032 unscan_zigzag_2x2_dc( dct2x2, mb->chroma_dc[ch] );
1033 h->dctf.idct2x2dc( dct2x2, dct2x2 );
1034 x264_mb_dequant_2x2_dc( dct2x2, i_qscale );
1036 for( i = 0; i < 4; i++ )
1038 unscan_zigzag_4x4( dct4x4[i], mb->block[16+i+ch*4].residual_ac );
1039 x264_mb_dequant_4x4( dct4x4[i], i_qscale );
1042 dct4x4[i][0][0] = dct2x2[block_idx_y[i]][block_idx_x[i]];
1044 h->dctf.idct4x4( chroma[i], dct4x4[i] );
1046 h->pixf.add8x8( ctx->p_fdec[1+ch], ctx->i_fdec[1+ch], chroma );
1053 void x264_macroblock_decode_skip( x264_t *h, x264_macroblock_t *mb )
1059 /* decode it as a 16x16 with no luma/chroma */
1061 mb->i_partition = D_16x16;
1063 mb->i_cbp_chroma = 0;
1064 for( i = 0; i < 16 + 8; i++ )
1066 mb->block[i].i_non_zero_count = 0;
1068 for( i = 0; i < 16; i++ )
1070 array_zero_set( mb->block[i].luma4x4, 16 );
1072 array_zero_set( mb->chroma_dc[0], 4 );
1073 array_zero_set( mb->chroma_dc[1], 4 );
1074 for( i = 0; i < 8; i++ )
1076 array_zero_set( mb->block[16+i].residual_ac, 15 );
1080 for( x = 0; x < 4; x++ )
1082 for( y = 0; y < 4; y++ )
1084 mb->partition[x][y].i_ref[0] = 0;
1088 x264_mb_predict_mv_pskip( mb, mv );
1090 x264_mb_partition_mv_set( mb, 0, 0, 0, mv );
1092 /* Motion compensation */
1093 x264_mb_mc( h, mb );
1095 mb->i_type = P_SKIP;