Mercurial > libavcodec.hg
comparison h264.c @ 7407:6288bc103b9f libavcodec
chroma_format_idc=0 aka grayscale support.
Can be disabled by removing #define ALLOW_NOCHROMA in case the extra if()
slow the code down measurably.
Fixes at least
FRExt/HPCAMOLQ_BRCM_B.264
FRExt/HPCVMOLQ_BRCM_B.264
author | michael |
---|---|
date | Sat, 26 Jul 2008 02:27:14 +0000 |
parents | dfe1d1d104eb |
children | f25c192ce081 |
comparison
equal
deleted
inserted
replaced
7406:7b2819083061 | 7407:6288bc103b9f |
---|---|
3077 }else{ | 3077 }else{ |
3078 h->luma_weight[list][i]= luma_def; | 3078 h->luma_weight[list][i]= luma_def; |
3079 h->luma_offset[list][i]= 0; | 3079 h->luma_offset[list][i]= 0; |
3080 } | 3080 } |
3081 | 3081 |
3082 if(CHROMA){ | |
3082 chroma_weight_flag= get_bits1(&s->gb); | 3083 chroma_weight_flag= get_bits1(&s->gb); |
3083 if(chroma_weight_flag){ | 3084 if(chroma_weight_flag){ |
3084 int j; | 3085 int j; |
3085 for(j=0; j<2; j++){ | 3086 for(j=0; j<2; j++){ |
3086 h->chroma_weight[list][i][j]= get_se_golomb(&s->gb); | 3087 h->chroma_weight[list][i][j]= get_se_golomb(&s->gb); |
3093 int j; | 3094 int j; |
3094 for(j=0; j<2; j++){ | 3095 for(j=0; j<2; j++){ |
3095 h->chroma_weight[list][i][j]= chroma_def; | 3096 h->chroma_weight[list][i][j]= chroma_def; |
3096 h->chroma_offset[list][i][j]= 0; | 3097 h->chroma_offset[list][i][j]= 0; |
3097 } | 3098 } |
3099 } | |
3098 } | 3100 } |
3099 } | 3101 } |
3100 if(h->slice_type_nos != FF_B_TYPE) break; | 3102 if(h->slice_type_nos != FF_B_TYPE) break; |
3101 } | 3103 } |
3102 h->use_weight= h->use_weight || h->use_weight_chroma; | 3104 h->use_weight= h->use_weight || h->use_weight_chroma; |
4436 for(x=0; x<16; x++){ | 4438 for(x=0; x<16; x++){ |
4437 tprintf(s->avctx, "LUMA ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8)); | 4439 tprintf(s->avctx, "LUMA ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8)); |
4438 h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= get_bits(&s->gb, 8); | 4440 h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= get_bits(&s->gb, 8); |
4439 } | 4441 } |
4440 } | 4442 } |
4443 if(CHROMA){ | |
4441 for(y=0; y<8; y++){ | 4444 for(y=0; y<8; y++){ |
4442 const int index= 256 + 4*(y&3) + 32*(y>>2); | 4445 const int index= 256 + 4*(y&3) + 32*(y>>2); |
4443 for(x=0; x<8; x++){ | 4446 for(x=0; x<8; x++){ |
4444 tprintf(s->avctx, "CHROMA U ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8)); | 4447 tprintf(s->avctx, "CHROMA U ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8)); |
4445 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8); | 4448 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8); |
4449 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2); | 4452 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2); |
4450 for(x=0; x<8; x++){ | 4453 for(x=0; x<8; x++){ |
4451 tprintf(s->avctx, "CHROMA V ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8)); | 4454 tprintf(s->avctx, "CHROMA V ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8)); |
4452 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8); | 4455 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8); |
4453 } | 4456 } |
4457 } | |
4454 } | 4458 } |
4455 | 4459 |
4456 // In deblocking, the quantizer is 0 | 4460 // In deblocking, the quantizer is 0 |
4457 s->current_picture.qscale_table[mb_xy]= 0; | 4461 s->current_picture.qscale_table[mb_xy]= 0; |
4458 // All coeffs are present | 4462 // All coeffs are present |
4501 }else{ | 4505 }else{ |
4502 h->intra16x16_pred_mode= check_intra_pred_mode(h, h->intra16x16_pred_mode); | 4506 h->intra16x16_pred_mode= check_intra_pred_mode(h, h->intra16x16_pred_mode); |
4503 if(h->intra16x16_pred_mode < 0) | 4507 if(h->intra16x16_pred_mode < 0) |
4504 return -1; | 4508 return -1; |
4505 } | 4509 } |
4506 | 4510 if(CHROMA){ |
4507 pred_mode= check_intra_pred_mode(h, get_ue_golomb(&s->gb)); | 4511 pred_mode= check_intra_pred_mode(h, get_ue_golomb(&s->gb)); |
4508 if(pred_mode < 0) | 4512 if(pred_mode < 0) |
4509 return -1; | 4513 return -1; |
4510 h->chroma_pred_mode= pred_mode; | 4514 h->chroma_pred_mode= pred_mode; |
4515 } | |
4511 }else if(partition_count==4){ | 4516 }else if(partition_count==4){ |
4512 int i, j, sub_partition_count[4], list, ref[2][4]; | 4517 int i, j, sub_partition_count[4], list, ref[2][4]; |
4513 | 4518 |
4514 if(h->slice_type_nos == FF_B_TYPE){ | 4519 if(h->slice_type_nos == FF_B_TYPE){ |
4515 for(i=0; i<4; i++){ | 4520 for(i=0; i<4; i++){ |
4711 if(cbp > 47){ | 4716 if(cbp > 47){ |
4712 av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y); | 4717 av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y); |
4713 return -1; | 4718 return -1; |
4714 } | 4719 } |
4715 | 4720 |
4721 if(CHROMA){ | |
4716 if(IS_INTRA4x4(mb_type)) | 4722 if(IS_INTRA4x4(mb_type)) |
4717 cbp= golomb_to_intra4x4_cbp[cbp]; | 4723 cbp= golomb_to_intra4x4_cbp[cbp]; |
4718 else | 4724 else |
4719 cbp= golomb_to_inter_cbp[cbp]; | 4725 cbp= golomb_to_inter_cbp[cbp]; |
4726 }else{ | |
4727 if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp]; | |
4728 else cbp= golomb_to_inter_cbp_gray[cbp]; | |
4729 } | |
4720 } | 4730 } |
4721 h->cbp = cbp; | 4731 h->cbp = cbp; |
4722 | 4732 |
4723 if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){ | 4733 if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){ |
4724 if(get_bits1(&s->gb)){ | 4734 if(get_bits1(&s->gb)){ |
5576 for(x=0; x<16; x++){ | 5586 for(x=0; x<16; x++){ |
5577 tprintf(s->avctx, "LUMA ICPM LEVEL (%3d)\n", *ptr); | 5587 tprintf(s->avctx, "LUMA ICPM LEVEL (%3d)\n", *ptr); |
5578 h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= *ptr++; | 5588 h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= *ptr++; |
5579 } | 5589 } |
5580 } | 5590 } |
5591 if(CHROMA){ | |
5581 for(y=0; y<8; y++){ | 5592 for(y=0; y<8; y++){ |
5582 const int index= 256 + 4*(y&3) + 32*(y>>2); | 5593 const int index= 256 + 4*(y&3) + 32*(y>>2); |
5583 for(x=0; x<8; x++){ | 5594 for(x=0; x<8; x++){ |
5584 tprintf(s->avctx, "CHROMA U ICPM LEVEL (%3d)\n", *ptr); | 5595 tprintf(s->avctx, "CHROMA U ICPM LEVEL (%3d)\n", *ptr); |
5585 h->mb[index + (x&3) + 16*(x>>2)]= *ptr++; | 5596 h->mb[index + (x&3) + 16*(x>>2)]= *ptr++; |
5589 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2); | 5600 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2); |
5590 for(x=0; x<8; x++){ | 5601 for(x=0; x<8; x++){ |
5591 tprintf(s->avctx, "CHROMA V ICPM LEVEL (%3d)\n", *ptr); | 5602 tprintf(s->avctx, "CHROMA V ICPM LEVEL (%3d)\n", *ptr); |
5592 h->mb[index + (x&3) + 16*(x>>2)]= *ptr++; | 5603 h->mb[index + (x&3) + 16*(x>>2)]= *ptr++; |
5593 } | 5604 } |
5605 } | |
5594 } | 5606 } |
5595 | 5607 |
5596 ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr); | 5608 ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr); |
5597 | 5609 |
5598 // All blocks are present | 5610 // All blocks are present |
5636 if( check_intra4x4_pred_mode(h) < 0 ) return -1; | 5648 if( check_intra4x4_pred_mode(h) < 0 ) return -1; |
5637 } else { | 5649 } else { |
5638 h->intra16x16_pred_mode= check_intra_pred_mode( h, h->intra16x16_pred_mode ); | 5650 h->intra16x16_pred_mode= check_intra_pred_mode( h, h->intra16x16_pred_mode ); |
5639 if( h->intra16x16_pred_mode < 0 ) return -1; | 5651 if( h->intra16x16_pred_mode < 0 ) return -1; |
5640 } | 5652 } |
5653 if(CHROMA){ | |
5641 h->chroma_pred_mode_table[mb_xy] = | 5654 h->chroma_pred_mode_table[mb_xy] = |
5642 pred_mode = decode_cabac_mb_chroma_pre_mode( h ); | 5655 pred_mode = decode_cabac_mb_chroma_pre_mode( h ); |
5643 | 5656 |
5644 pred_mode= check_intra_pred_mode( h, pred_mode ); | 5657 pred_mode= check_intra_pred_mode( h, pred_mode ); |
5645 if( pred_mode < 0 ) return -1; | 5658 if( pred_mode < 0 ) return -1; |
5646 h->chroma_pred_mode= pred_mode; | 5659 h->chroma_pred_mode= pred_mode; |
5660 } | |
5647 } else if( partition_count == 4 ) { | 5661 } else if( partition_count == 4 ) { |
5648 int i, j, sub_partition_count[4], list, ref[2][4]; | 5662 int i, j, sub_partition_count[4], list, ref[2][4]; |
5649 | 5663 |
5650 if( h->slice_type_nos == FF_B_TYPE ) { | 5664 if( h->slice_type_nos == FF_B_TYPE ) { |
5651 for( i = 0; i < 4; i++ ) { | 5665 for( i = 0; i < 4; i++ ) { |
5843 write_back_motion( h, mb_type ); | 5857 write_back_motion( h, mb_type ); |
5844 } | 5858 } |
5845 | 5859 |
5846 if( !IS_INTRA16x16( mb_type ) ) { | 5860 if( !IS_INTRA16x16( mb_type ) ) { |
5847 cbp = decode_cabac_mb_cbp_luma( h ); | 5861 cbp = decode_cabac_mb_cbp_luma( h ); |
5862 if(CHROMA) | |
5848 cbp |= decode_cabac_mb_cbp_chroma( h ) << 4; | 5863 cbp |= decode_cabac_mb_cbp_chroma( h ) << 4; |
5849 } | 5864 } |
5850 | 5865 |
5851 h->cbp_table[mb_xy] = h->cbp = cbp; | 5866 h->cbp_table[mb_xy] = h->cbp = cbp; |
5852 | 5867 |
7128 | 7143 |
7129 sps->profile_idc= profile_idc; | 7144 sps->profile_idc= profile_idc; |
7130 sps->level_idc= level_idc; | 7145 sps->level_idc= level_idc; |
7131 | 7146 |
7132 if(sps->profile_idc >= 100){ //high profile | 7147 if(sps->profile_idc >= 100){ //high profile |
7133 if(get_ue_golomb(&s->gb) == 3) //chroma_format_idc | 7148 sps->chroma_format_idc= get_ue_golomb(&s->gb); |
7149 if(sps->chroma_format_idc == 3) | |
7134 get_bits1(&s->gb); //residual_color_transform_flag | 7150 get_bits1(&s->gb); //residual_color_transform_flag |
7135 get_ue_golomb(&s->gb); //bit_depth_luma_minus8 | 7151 get_ue_golomb(&s->gb); //bit_depth_luma_minus8 |
7136 get_ue_golomb(&s->gb); //bit_depth_chroma_minus8 | 7152 get_ue_golomb(&s->gb); //bit_depth_chroma_minus8 |
7137 sps->transform_bypass = get_bits1(&s->gb); | 7153 sps->transform_bypass = get_bits1(&s->gb); |
7138 decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8); | 7154 decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8); |
7139 }else | 7155 }else{ |
7140 sps->scaling_matrix_present = 0; | 7156 sps->scaling_matrix_present = 0; |
7157 sps->chroma_format_idc= 1; | |
7158 } | |
7141 | 7159 |
7142 sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4; | 7160 sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4; |
7143 sps->poc_type= get_ue_golomb(&s->gb); | 7161 sps->poc_type= get_ue_golomb(&s->gb); |
7144 | 7162 |
7145 if(sps->poc_type == 0){ //FIXME #define | 7163 if(sps->poc_type == 0){ //FIXME #define |
7217 sps->vui_parameters_present_flag= get_bits1(&s->gb); | 7235 sps->vui_parameters_present_flag= get_bits1(&s->gb); |
7218 if( sps->vui_parameters_present_flag ) | 7236 if( sps->vui_parameters_present_flag ) |
7219 decode_vui_parameters(h, sps); | 7237 decode_vui_parameters(h, sps); |
7220 | 7238 |
7221 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ | 7239 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ |
7222 av_log(h->s.avctx, AV_LOG_DEBUG, "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s\n", | 7240 av_log(h->s.avctx, AV_LOG_DEBUG, "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s %s\n", |
7223 sps_id, sps->profile_idc, sps->level_idc, | 7241 sps_id, sps->profile_idc, sps->level_idc, |
7224 sps->poc_type, | 7242 sps->poc_type, |
7225 sps->ref_frame_count, | 7243 sps->ref_frame_count, |
7226 sps->mb_width, sps->mb_height, | 7244 sps->mb_width, sps->mb_height, |
7227 sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"), | 7245 sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"), |
7228 sps->direct_8x8_inference_flag ? "8B8" : "", | 7246 sps->direct_8x8_inference_flag ? "8B8" : "", |
7229 sps->crop_left, sps->crop_right, | 7247 sps->crop_left, sps->crop_right, |
7230 sps->crop_top, sps->crop_bottom, | 7248 sps->crop_top, sps->crop_bottom, |
7231 sps->vui_parameters_present_flag ? "VUI" : "" | 7249 sps->vui_parameters_present_flag ? "VUI" : "", |
7250 ((const char*[]){"Gray","420","422","444"})[sps->chroma_format_idc] | |
7232 ); | 7251 ); |
7233 } | 7252 } |
7234 return 0; | 7253 return 0; |
7235 } | 7254 } |
7236 | 7255 |