1 #include "../libzmpeg3.h"
4 get_macroblock_address()
7 while( (zcode = slice_buffer->show_bits(11)) < 24 ) {
8 if( zcode != 15 ) { /* Is not macroblock_stuffing */
9 if( zcode != 8 ) { /* Is not macroblock_escape */
10 //zerrs("invalid macroblock_address_increment code %d\n",zcode);
16 slice_buffer->flush_bits(11);
20 slice_buffer->flush_bit();
26 slice_buffer->flush_bits(MBAtab1[zcode].len);
27 return val + MBAtab1[zcode].val;
31 slice_buffer->flush_bits(MBAtab2[zcode].len);
33 return val + MBAtab2[zcode].val;
36 /* macroblock_type for pictures with spatial scalability */
37 inline int zslice_decoder_t::
40 uint32_t zcode = slice_buffer->show_bits(4);
42 //zerrs("invalid macroblock_type code %d\n",zcode);
47 slice_buffer->flush_bits(spIMBtab[zcode].len);
48 return spIMBtab[zcode].val;
51 inline int zslice_decoder_t::
54 int zcode = slice_buffer->show_bits(7);
56 // zerrs("invalid macroblock_type code %d\n",zcode);
63 slice_buffer->flush_bits(spPMBtab0[zcode].len);
65 return spPMBtab0[zcode].val;
68 slice_buffer->flush_bits(spPMBtab1[zcode].len);
69 return spPMBtab1[zcode].val;
72 inline int zslice_decoder_t::
76 int zcode = slice_buffer->show_bits(9);
79 p = &spBMBtab0[(zcode >> 5) - 2];
80 else if( zcode >= 16 )
81 p = &spBMBtab1[(zcode >> 2) - 4];
83 p = &spBMBtab2[zcode - 8];
85 //zerrs("invalid macroblock_type code %d\n",zcode);
90 slice_buffer->flush_bits(p->len);
94 inline int zslice_decoder_t::
97 if( slice_buffer->get_bit() ) return 1;
98 if( !slice_buffer->get_bit() ) {
99 //zerr("invalid macroblock_type code\n");
107 inline int zslice_decoder_t::
111 if( (zcode = slice_buffer->show_bits(6)) >= 8 ) {
113 slice_buffer->flush_bits(PMBtab0[zcode].len);
114 return PMBtab0[zcode].val;
118 //zerrs("invalid macroblock_type code %d\n",zcode);
123 slice_buffer->flush_bits(PMBtab1[zcode].len);
124 return PMBtab1[zcode].val;
127 inline int zslice_decoder_t::
131 if( (zcode = slice_buffer->show_bits(6)) >= 8 ) {
133 slice_buffer->flush_bits(BMBtab0[zcode].len);
134 return BMBtab0[zcode].val;
138 //zerrs("invalid macroblock_type code %d\n",zcode);
143 slice_buffer->flush_bits(BMBtab1[zcode].len);
144 return BMBtab1[zcode].val;
147 inline int zslice_decoder_t::
150 if( !slice_buffer->get_bit() ) {
151 //zerr("invalid macroblock_type code\n");
160 inline int zslice_decoder_t::
163 int zcode = slice_buffer->show_bits(3);
165 //zerrs("invalid macroblock_type code %d\n",zcode);
169 slice_buffer->flush_bits(SNRMBtab[zcode].len);
170 return SNRMBtab[zcode].val;
173 int zslice_decoder_t::
176 if( video->scalable_mode == sc_SNR )
177 return get_snrmb_type();
178 switch(video->pict_type) {
179 case video_t::pic_type_I:
180 return video->pict_scal ? getsp_imb_type() : get_imb_type();
181 case video_t::pic_type_P:
182 return video->pict_scal ? getsp_pmb_type() : get_pmb_type();
183 case video_t::pic_type_B:
184 return video->pict_scal ? getsp_bmb_type() : get_bmb_type();
185 case video_t::pic_type_D:
186 return get_dmb_type();
187 default: /* MPEG-1 only, not implemented */
188 //zerrs("unknown coding type %d\n",video->pict_type);
195 int zslice_decoder_t::
196 macroblock_modes(int *pmb_type, int *pstwtype, int *pstwclass, int *pmotion_type,
197 int *pmv_count, int *pmv_format, int *pdmv, int *pmvscale, int *pdct_type)
200 int stwtype, stwcode, stwclass;
201 int motion_type, mv_count, mv_format, dmv, mvscale;
203 static uint8_t stwc_table[3][4] = { {6,3,7,4}, {2,1,5,4}, {2,5,7,4} };
204 static uint8_t stwclass_table[9] = {0, 1, 2, 1, 1, 2, 3, 3, 4};
207 /* get macroblock_type */
208 mb_type = get_mb_type();
209 if( fault ) return 1;
211 /* get spatial_temporal_weight_code */
212 if( mb_type & mb_WEIGHT ) {
213 if( video->stwc_table_index == 0 )
216 stwcode = slice_buffer->get_bits(2);
217 stwtype = stwc_table[video->stwc_table_index - 1][stwcode];
221 stwtype = (mb_type & mb_CLASS4) ? 8 : 0;
223 /* derive spatial_temporal_weight_class (Table 7-18) */
224 stwclass = stwclass_table[stwtype];
226 /* get frame/field motion type */
227 if( mb_type & (mb_FORWARD | mb_BACKWARD) ) {
228 if( video->pict_struct == video_t::pics_FRAME_PICTURE ) {
229 /* frame_motion_type */
230 motion_type = video->frame_pred_dct ?
231 mc_FRAME : slice_buffer->get_bits(2);
234 /* field_motion_type */
235 motion_type = slice_buffer->get_bits(2);
238 else if( (mb_type & mb_INTRA) && video->conceal_mv ) {
239 /* concealment motion vectors */
240 motion_type = video->pict_struct == video_t::pics_FRAME_PICTURE ?
244 /* derive mv_count, mv_format and dmv, (table 6-17, 6-18) */
245 if( video->pict_struct == video_t::pics_FRAME_PICTURE ) {
246 mv_count = (motion_type == mc_FIELD && stwclass < 2) ? 2 : 1;
247 mv_format = (motion_type == mc_FRAME) ? mv_FRAME : mv_FIELD;
250 mv_count = (motion_type == mc_16X8) ? 2 : 1;
251 mv_format = mv_FIELD;
254 dmv = motion_type == mc_DMV ? 1 : 0; /* dual prime */
256 /* field mv predictions in frame pictures have to be scaled */
257 mvscale = mv_format == mv_FIELD &&
258 video->pict_struct == video_t::pics_FRAME_PICTURE ? 1 : 0;
260 /* get dct_type (frame DCT / field DCT) */
261 dct_type = video->pict_struct == video_t::pics_FRAME_PICTURE &&
262 !video->frame_pred_dct && (mb_type & (mb_PATTERN | mb_INTRA)) ?
263 slice_buffer->get_bit() : 0;
268 *pstwclass = stwclass;
269 *pmotion_type = motion_type;
270 *pmv_count = mv_count;
271 *pmv_format = mv_format;
274 *pdct_type = dct_type;