comparison h263.c @ 718:16dab8296293 libavcodec

fixing custom quantizer matrix decoding minor optimizations
author michaelni
date Wed, 02 Oct 2002 22:56:58 +0000
parents e65798d228ea
children 25d7fb7c89be
comparison
equal deleted inserted replaced
717:6cba3b6196f0 718:16dab8296293
1120 put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign); 1120 put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign);
1121 if (bit_size > 0) { 1121 if (bit_size > 0) {
1122 put_bits(&s->pb, bit_size, bits); 1122 put_bits(&s->pb, bit_size, bits);
1123 } 1123 }
1124 } 1124 }
1125
1125 } 1126 }
1126 1127
1127 /* Encode MV differences on H.263+ with Unrestricted MV mode */ 1128 /* Encode MV differences on H.263+ with Unrestricted MV mode */
1128 static void h263p_encode_umotion(MpegEncContext * s, int val) 1129 static void h263p_encode_umotion(MpegEncContext * s, int val)
1129 { 1130 {
2686 }else if(s->mb_intra && s->decoding_error!=DECODING_ACDC_LOST){ 2687 }else if(s->mb_intra && s->decoding_error!=DECODING_ACDC_LOST){
2687 s->ac_pred = s->pred_dir_table[xy]>>7; 2688 s->ac_pred = s->pred_dir_table[xy]>>7;
2688 2689
2689 /* decode each block */ 2690 /* decode each block */
2690 for (i = 0; i < 6; i++) { 2691 for (i = 0; i < 6; i++) {
2691 int ret= mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 1); 2692 int ret= mpeg4_decode_block(s, block[i], i, cbp&32, 1);
2692 if(ret==DECODING_AC_LOST){ 2693 if(ret==DECODING_AC_LOST){
2693 fprintf(stderr, "texture corrupted at %d %d (trying to continue with mc/dc only)\n", s->mb_x, s->mb_y); 2694 fprintf(stderr, "texture corrupted at %d %d (trying to continue with mc/dc only)\n", s->mb_x, s->mb_y);
2694 s->decoding_error=DECODING_AC_LOST; 2695 s->decoding_error=DECODING_AC_LOST;
2695 cbp=0; 2696 cbp=0;
2696 }else if(ret==DECODING_ACDC_LOST){ 2697 }else if(ret==DECODING_ACDC_LOST){
2697 fprintf(stderr, "dc corrupted at %d %d (trying to continue with mc only)\n", s->mb_x, s->mb_y); 2698 fprintf(stderr, "dc corrupted at %d %d (trying to continue with mc only)\n", s->mb_x, s->mb_y);
2698 s->decoding_error=DECODING_ACDC_LOST; 2699 s->decoding_error=DECODING_ACDC_LOST;
2699 break; 2700 break;
2700 } 2701 }
2702 cbp+=cbp;
2701 } 2703 }
2702 }else if(!s->mb_intra){ 2704 }else if(!s->mb_intra){
2703 // s->mcsel= 0; //FIXME do we need to init that 2705 // s->mcsel= 0; //FIXME do we need to init that
2704 2706
2705 s->mv_dir = MV_DIR_FORWARD; 2707 s->mv_dir = MV_DIR_FORWARD;
2709 s->mv_type = MV_TYPE_16X16; 2711 s->mv_type = MV_TYPE_16X16;
2710 } 2712 }
2711 if(s->decoding_error==0 && cbp){ 2713 if(s->decoding_error==0 && cbp){
2712 /* decode each block */ 2714 /* decode each block */
2713 for (i = 0; i < 6; i++) { 2715 for (i = 0; i < 6; i++) {
2714 int ret= mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 0); 2716 int ret= mpeg4_decode_block(s, block[i], i, cbp&32, 0);
2715 if(ret==DECODING_AC_LOST){ 2717 if(ret==DECODING_AC_LOST){
2716 fprintf(stderr, "texture corrupted at %d %d (trying to continue with mc/dc only)\n", s->mb_x, s->mb_y); 2718 fprintf(stderr, "texture corrupted at %d %d (trying to continue with mc/dc only)\n", s->mb_x, s->mb_y);
2717 s->decoding_error=DECODING_AC_LOST; 2719 s->decoding_error=DECODING_AC_LOST;
2718 break; 2720 break;
2719 } 2721 }
2722 cbp+=cbp;
2720 } 2723 }
2721 } 2724 }
2722 } 2725 }
2723 } else { /* I-Frame */ 2726 } else { /* I-Frame */
2724 int i; 2727 int i;
2725 s->mb_intra = 1; 2728 s->mb_intra = 1;
2726 s->ac_pred = s->pred_dir_table[xy]>>7; 2729 s->ac_pred = s->pred_dir_table[xy]>>7;
2727 2730
2728 /* decode each block */ 2731 /* decode each block */
2729 for (i = 0; i < 6; i++) { 2732 for (i = 0; i < 6; i++) {
2730 int ret= mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 1); 2733 int ret= mpeg4_decode_block(s, block[i], i, cbp&32, 1);
2731 if(ret==DECODING_AC_LOST){ 2734 if(ret==DECODING_AC_LOST){
2732 fprintf(stderr, "texture corrupted at %d %d (trying to continue with dc only)\n", s->mb_x, s->mb_y); 2735 fprintf(stderr, "texture corrupted at %d %d (trying to continue with dc only)\n", s->mb_x, s->mb_y);
2733 s->decoding_error=DECODING_AC_LOST; 2736 s->decoding_error=DECODING_AC_LOST;
2734 cbp=0; 2737 cbp=0;
2735 }else if(ret==DECODING_ACDC_LOST){ 2738 }else if(ret==DECODING_ACDC_LOST){
2736 fprintf(stderr, "dc corrupted at %d %d\n", s->mb_x, s->mb_y); 2739 fprintf(stderr, "dc corrupted at %d %d\n", s->mb_x, s->mb_y);
2737 return -1; 2740 return -1;
2738 } 2741 }
2742 cbp+=cbp;
2739 } 2743 }
2740 } 2744 }
2741 2745
2742 return 0; 2746 return 0;
2743 } 2747 }
3160 s->interlaced_dct= get_bits1(&s->gb); 3164 s->interlaced_dct= get_bits1(&s->gb);
3161 3165
3162 /* decode each block */ 3166 /* decode each block */
3163 if (s->h263_pred) { 3167 if (s->h263_pred) {
3164 for (i = 0; i < 6; i++) { 3168 for (i = 0; i < 6; i++) {
3165 if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 1) < 0) 3169 if (mpeg4_decode_block(s, block[i], i, cbp&32, 1) < 0)
3166 return -1; 3170 return -1;
3171 cbp+=cbp;
3167 } 3172 }
3168 } else { 3173 } else {
3169 for (i = 0; i < 6; i++) { 3174 for (i = 0; i < 6; i++) {
3170 if (h263_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0) 3175 if (h263_decode_block(s, block[i], i, cbp&32) < 0)
3171 return -1; 3176 return -1;
3177 cbp+=cbp;
3172 } 3178 }
3173 } 3179 }
3174 return 0; 3180 return 0;
3175 } 3181 }
3176 3182
3177 /* decode each block */ 3183 /* decode each block */
3178 if (s->h263_pred) { 3184 if (s->h263_pred) {
3179 for (i = 0; i < 6; i++) { 3185 for (i = 0; i < 6; i++) {
3180 if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 0) < 0) 3186 if (mpeg4_decode_block(s, block[i], i, cbp&32, 0) < 0)
3181 return -1; 3187 return -1;
3188 cbp+=cbp;
3182 } 3189 }
3183 } else { 3190 } else {
3184 for (i = 0; i < 6; i++) { 3191 for (i = 0; i < 6; i++) {
3185 if (h263_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0) 3192 if (h263_decode_block(s, block[i], i, cbp&32) < 0)
3186 return -1; 3193 return -1;
3194 cbp+=cbp;
3187 } 3195 }
3188 } 3196 }
3189 return 0; 3197 return 0;
3190 } 3198 }
3191 3199
3414 i = 0; 3422 i = 0;
3415 if (!coded) 3423 if (!coded)
3416 goto not_coded; 3424 goto not_coded;
3417 rl = &rl_intra; 3425 rl = &rl_intra;
3418 rl_vlc = rl_intra.rl_vlc[0]; 3426 rl_vlc = rl_intra.rl_vlc[0];
3419 if(s->alternate_scan) 3427 if (s->ac_pred) {
3420 scan_table = s->intra_v_scantable.permutated; /* left */
3421 else if (s->ac_pred) {
3422 if (dc_pred_dir == 0) 3428 if (dc_pred_dir == 0)
3423 scan_table = s->intra_v_scantable.permutated; /* left */ 3429 scan_table = s->intra_v_scantable.permutated; /* left */
3424 else 3430 else
3425 scan_table = s->intra_h_scantable.permutated; /* top */ 3431 scan_table = s->intra_h_scantable.permutated; /* top */
3426 } else { 3432 } else {
3434 s->block_last_index[n] = i; 3440 s->block_last_index[n] = i;
3435 return 0; 3441 return 0;
3436 } 3442 }
3437 rl = &rl_inter; 3443 rl = &rl_inter;
3438 3444
3439 if(s->alternate_scan) 3445 scan_table = s->intra_scantable.permutated;
3440 scan_table = s->intra_v_scantable.permutated; /* left */
3441 else
3442 scan_table = s->intra_scantable.permutated;
3443 3446
3444 if(s->mpeg_quant){ 3447 if(s->mpeg_quant){
3445 qmul=1; 3448 qmul=1;
3446 qadd=0; 3449 qadd=0;
3447 rl_vlc = rl_inter.rl_vlc[0]; 3450 rl_vlc = rl_inter.rl_vlc[0];
4091 s->chroma_inter_matrix[j]= v; 4094 s->chroma_inter_matrix[j]= v;
4092 } 4095 }
4093 4096
4094 /* load custom intra matrix */ 4097 /* load custom intra matrix */
4095 if(get_bits1(&s->gb)){ 4098 if(get_bits1(&s->gb)){
4099 int last=0;
4096 for(i=0; i<64; i++){ 4100 for(i=0; i<64; i++){
4097 v= get_bits(&s->gb, 8); 4101 v= get_bits(&s->gb, 8);
4098 if(v==0) break; 4102 if(v==0) break;
4099 4103
4100 j= s->intra_scantable.permutated[i]; 4104 last= v;
4105 j= s->idct_permutation[ ff_zigzag_direct[i] ];
4101 s->intra_matrix[j]= v; 4106 s->intra_matrix[j]= v;
4102 s->chroma_intra_matrix[j]= v; 4107 s->chroma_intra_matrix[j]= v;
4103 } 4108 }
4109
4110 /* replicate last value */
4111 for(; i<64; i++){
4112 j= s->idct_permutation[ ff_zigzag_direct[i] ];
4113 s->intra_matrix[j]= v;
4114 s->chroma_intra_matrix[j]= v;
4115 }
4104 } 4116 }
4105 4117
4106 /* load custom non intra matrix */ 4118 /* load custom non intra matrix */
4107 if(get_bits1(&s->gb)){ 4119 if(get_bits1(&s->gb)){
4120 int last=0;
4108 for(i=0; i<64; i++){ 4121 for(i=0; i<64; i++){
4109 v= get_bits(&s->gb, 8); 4122 v= get_bits(&s->gb, 8);
4110 if(v==0) break; 4123 if(v==0) break;
4111 4124
4112 j= s->intra_scantable.permutated[i]; 4125 last= v;
4126 j= s->idct_permutation[ ff_zigzag_direct[i] ];
4113 s->inter_matrix[j]= v; 4127 s->inter_matrix[j]= v;
4114 s->chroma_inter_matrix[j]= v; 4128 s->chroma_inter_matrix[j]= v;
4115 } 4129 }
4116 4130
4117 /* replicate last value */ 4131 /* replicate last value */
4118 for(; i<64; i++){ 4132 for(; i<64; i++){
4119 j= s->intra_scantable.permutated[i]; 4133 j= s->idct_permutation[ ff_zigzag_direct[i] ];
4120 s->inter_matrix[j]= v; 4134 s->inter_matrix[j]= last;
4121 s->chroma_inter_matrix[j]= v; 4135 s->chroma_inter_matrix[j]= last;
4122 } 4136 }
4123 } 4137 }
4124 4138
4125 // FIXME a bunch of grayscale shape things 4139 // FIXME a bunch of grayscale shape things
4126 } 4140 }
4319 s->alternate_scan= get_bits1(&s->gb); 4333 s->alternate_scan= get_bits1(&s->gb);
4320 }else 4334 }else
4321 s->alternate_scan= 0; 4335 s->alternate_scan= 0;
4322 } 4336 }
4323 4337
4338 if(s->alternate_scan){
4339 ff_init_scantable(s, &s->inter_scantable , ff_alternate_vertical_scan);
4340 ff_init_scantable(s, &s->intra_scantable , ff_alternate_vertical_scan);
4341 ff_init_scantable(s, &s->intra_h_scantable, ff_alternate_vertical_scan);
4342 ff_init_scantable(s, &s->intra_v_scantable, ff_alternate_vertical_scan);
4343 } else{
4344 ff_init_scantable(s, &s->inter_scantable , ff_zigzag_direct);
4345 ff_init_scantable(s, &s->intra_scantable , ff_zigzag_direct);
4346 ff_init_scantable(s, &s->intra_h_scantable, ff_alternate_horizontal_scan);
4347 ff_init_scantable(s, &s->intra_v_scantable, ff_alternate_vertical_scan);
4348 }
4349
4324 if(s->pict_type == S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){ 4350 if(s->pict_type == S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){
4325 if(s->num_sprite_warping_points){ 4351 if(s->num_sprite_warping_points){
4326 mpeg4_decode_sprite_trajectory(s); 4352 mpeg4_decode_sprite_trajectory(s);
4327 } 4353 }
4328 if(s->sprite_brightness_change) printf("sprite_brightness_change not supported\n"); 4354 if(s->sprite_brightness_change) printf("sprite_brightness_change not supported\n");