Mercurial > libavcodec.hg
comparison mpeg12.c @ 59:efd3c19f6d62 libavcodec
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
| author | glantau |
|---|---|
| date | Sun, 12 Aug 2001 00:52:01 +0000 |
| parents | 0e0a24def67a |
| children | 5aa6292a1660 |
comparison
equal
deleted
inserted
replaced
| 58:0e0a24def67a | 59:efd3c19f6d62 |
|---|---|
| 552 if (s->pict_type == P_TYPE) { | 552 if (s->pict_type == P_TYPE) { |
| 553 /* if P type, zero motion vector is implied */ | 553 /* if P type, zero motion vector is implied */ |
| 554 s->mv_dir = MV_DIR_FORWARD; | 554 s->mv_dir = MV_DIR_FORWARD; |
| 555 s->mv[0][0][0] = s->mv[0][0][1] = 0; | 555 s->mv[0][0][0] = s->mv[0][0][1] = 0; |
| 556 s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0; | 556 s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0; |
| 557 s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0; | |
| 557 } else { | 558 } else { |
| 558 /* if B type, reuse previous vectors and directions */ | 559 /* if B type, reuse previous vectors and directions */ |
| 559 s->mv[0][0][0] = s->last_mv[0][0][0]; | 560 s->mv[0][0][0] = s->last_mv[0][0][0]; |
| 560 s->mv[0][0][1] = s->last_mv[0][0][1]; | 561 s->mv[0][0][1] = s->last_mv[0][0][1]; |
| 561 s->mv[1][0][0] = s->last_mv[1][0][0]; | 562 s->mv[1][0][0] = s->last_mv[1][0][0]; |
| 979 if (i >= 64) | 980 if (i >= 64) |
| 980 return -1; | 981 return -1; |
| 981 add_coef: | 982 add_coef: |
| 982 j = scan_table[i]; | 983 j = scan_table[i]; |
| 983 dprintf("%d: run=%d level=%d\n", n, run, level); | 984 dprintf("%d: run=%d level=%d\n", n, run, level); |
| 984 level = ((level * 2 + 1) * s->qscale * matrix[j]) / 32; | 985 /* XXX: optimize */ |
| 986 if (level > 0) { | |
| 987 level = ((level * 2 + 1) * s->qscale * matrix[j]) >> 5; | |
| 988 } else { | |
| 989 level = ((-level * 2 + 1) * s->qscale * matrix[j]) >> 5; | |
| 990 level = -level; | |
| 991 } | |
| 985 /* XXX: is it really necessary to saturate since the encoder | 992 /* XXX: is it really necessary to saturate since the encoder |
| 986 knows whats going on ? */ | 993 knows whats going on ? */ |
| 987 mismatch ^= level; | 994 mismatch ^= level; |
| 988 block[j] = level; | 995 block[j] = level; |
| 989 i++; | 996 i++; |
| 1027 rl = &rl_mpeg1; | 1034 rl = &rl_mpeg1; |
| 1028 if (n < 4) | 1035 if (n < 4) |
| 1029 matrix = s->intra_matrix; | 1036 matrix = s->intra_matrix; |
| 1030 else | 1037 else |
| 1031 matrix = s->chroma_intra_matrix; | 1038 matrix = s->chroma_intra_matrix; |
| 1032 | 1039 |
| 1033 /* now quantify & encode AC coefs */ | 1040 /* now quantify & encode AC coefs */ |
| 1034 for(;;) { | 1041 for(;;) { |
| 1035 code = get_vlc(&s->gb, &rl->vlc); | 1042 code = get_vlc(&s->gb, &rl->vlc); |
| 1036 if (code < 0) | 1043 if (code < 0) |
| 1037 return -1; | 1044 return -1; |
| 1181 | 1188 |
| 1182 static void mpeg_decode_quant_matrix_extension(MpegEncContext *s) | 1189 static void mpeg_decode_quant_matrix_extension(MpegEncContext *s) |
| 1183 { | 1190 { |
| 1184 int i, v, j; | 1191 int i, v, j; |
| 1185 | 1192 |
| 1193 dprintf("matrix extension\n"); | |
| 1194 | |
| 1186 if (get_bits1(&s->gb)) { | 1195 if (get_bits1(&s->gb)) { |
| 1187 for(i=0;i<64;i++) { | 1196 for(i=0;i<64;i++) { |
| 1188 v = get_bits(&s->gb, 8); | 1197 v = get_bits(&s->gb, 8); |
| 1189 j = block_permute_op(i); | 1198 j = zigzag_direct[i]; |
| 1190 s->intra_matrix[j] = v; | 1199 s->intra_matrix[j] = v; |
| 1191 s->chroma_intra_matrix[j] = v; | 1200 s->chroma_intra_matrix[j] = v; |
| 1192 } | 1201 } |
| 1193 } | 1202 } |
| 1194 if (get_bits1(&s->gb)) { | 1203 if (get_bits1(&s->gb)) { |
| 1195 for(i=0;i<64;i++) { | 1204 for(i=0;i<64;i++) { |
| 1196 v = get_bits(&s->gb, 8); | 1205 v = get_bits(&s->gb, 8); |
| 1197 j = block_permute_op(i); | 1206 j = zigzag_direct[i]; |
| 1198 s->non_intra_matrix[j] = v; | 1207 s->non_intra_matrix[j] = v; |
| 1199 s->chroma_non_intra_matrix[j] = v; | 1208 s->chroma_non_intra_matrix[j] = v; |
| 1200 } | 1209 } |
| 1201 } | 1210 } |
| 1202 if (get_bits1(&s->gb)) { | 1211 if (get_bits1(&s->gb)) { |
| 1203 for(i=0;i<64;i++) { | 1212 for(i=0;i<64;i++) { |
| 1204 v = get_bits(&s->gb, 8); | 1213 v = get_bits(&s->gb, 8); |
| 1205 j = block_permute_op(i); | 1214 j = zigzag_direct[i]; |
| 1206 s->chroma_intra_matrix[j] = v; | 1215 s->chroma_intra_matrix[j] = v; |
| 1207 } | 1216 } |
| 1208 } | 1217 } |
| 1209 if (get_bits1(&s->gb)) { | 1218 if (get_bits1(&s->gb)) { |
| 1210 for(i=0;i<64;i++) { | 1219 for(i=0;i<64;i++) { |
| 1211 v = get_bits(&s->gb, 8); | 1220 v = get_bits(&s->gb, 8); |
| 1212 j = block_permute_op(i); | 1221 j = zigzag_direct[i]; |
| 1213 s->chroma_non_intra_matrix[j] = v; | 1222 s->chroma_non_intra_matrix[j] = v; |
| 1214 } | 1223 } |
| 1215 } | 1224 } |
| 1216 } | 1225 } |
| 1217 | 1226 |
| 1232 s->alternate_scan = get_bits1(&s->gb); | 1241 s->alternate_scan = get_bits1(&s->gb); |
| 1233 s->repeat_first_field = get_bits1(&s->gb); | 1242 s->repeat_first_field = get_bits1(&s->gb); |
| 1234 s->chroma_420_type = get_bits1(&s->gb); | 1243 s->chroma_420_type = get_bits1(&s->gb); |
| 1235 s->progressive_frame = get_bits1(&s->gb); | 1244 s->progressive_frame = get_bits1(&s->gb); |
| 1236 /* composite display not parsed */ | 1245 /* composite display not parsed */ |
| 1237 dprintf("dc_preci=%d\n", s->intra_dc_precision); | 1246 dprintf("intra_dc_precion=%d\n", s->intra_dc_precision); |
| 1238 dprintf("pict_structure=%d\n", s->picture_structure); | 1247 dprintf("picture_structure=%d\n", s->picture_structure); |
| 1239 dprintf("conceal=%d\n", s->concealment_motion_vectors); | 1248 dprintf("conceal=%d\n", s->concealment_motion_vectors); |
| 1240 dprintf("intrafmt=%d\n", s->intra_vlc_format); | 1249 dprintf("intra_vlc_format=%d\n", s->intra_vlc_format); |
| 1250 dprintf("alternate_scan=%d\n", s->alternate_scan); | |
| 1241 dprintf("frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct); | 1251 dprintf("frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct); |
| 1242 } | 1252 } |
| 1243 | 1253 |
| 1244 static void mpeg_decode_extension(AVCodecContext *avctx, | 1254 static void mpeg_decode_extension(AVCodecContext *avctx, |
| 1245 UINT8 *buf, int buf_size) | 1255 UINT8 *buf, int buf_size) |
| 1400 | 1410 |
| 1401 /* get matrix */ | 1411 /* get matrix */ |
| 1402 if (get_bits1(&s->gb)) { | 1412 if (get_bits1(&s->gb)) { |
| 1403 for(i=0;i<64;i++) { | 1413 for(i=0;i<64;i++) { |
| 1404 v = get_bits(&s->gb, 8); | 1414 v = get_bits(&s->gb, 8); |
| 1405 j = block_permute_op(i); | 1415 j = zigzag_direct[i]; |
| 1406 s->intra_matrix[j] = v; | 1416 s->intra_matrix[j] = v; |
| 1407 s->chroma_intra_matrix[j] = v; | 1417 s->chroma_intra_matrix[j] = v; |
| 1408 } | 1418 } |
| 1419 #ifdef DEBUG | |
| 1420 dprintf("intra matrix present\n"); | |
| 1421 for(i=0;i<64;i++) | |
| 1422 dprintf(" %d", s->intra_matrix[zigzag_direct[i]]); | |
| 1423 printf("\n"); | |
| 1424 #endif | |
| 1409 } else { | 1425 } else { |
| 1410 for(i=0;i<64;i++) { | 1426 for(i=0;i<64;i++) { |
| 1411 v = default_intra_matrix[i]; | 1427 v = default_intra_matrix[i]; |
| 1412 s->intra_matrix[i] = v; | 1428 s->intra_matrix[i] = v; |
| 1413 s->chroma_intra_matrix[i] = v; | 1429 s->chroma_intra_matrix[i] = v; |
| 1414 } | 1430 } |
| 1415 } | 1431 } |
| 1416 if (get_bits1(&s->gb)) { | 1432 if (get_bits1(&s->gb)) { |
| 1417 for(i=0;i<64;i++) { | 1433 for(i=0;i<64;i++) { |
| 1418 v = get_bits(&s->gb, 8); | 1434 v = get_bits(&s->gb, 8); |
| 1419 j = block_permute_op(i); | 1435 j = zigzag_direct[i]; |
| 1420 s->non_intra_matrix[j] = v; | 1436 s->non_intra_matrix[j] = v; |
| 1421 s->chroma_non_intra_matrix[j] = v; | 1437 s->chroma_non_intra_matrix[j] = v; |
| 1422 } | 1438 } |
| 1439 #ifdef DEBUG | |
| 1440 dprintf("non intra matrix present\n"); | |
| 1441 for(i=0;i<64;i++) | |
| 1442 dprintf(" %d", s->non_intra_matrix[zigzag_direct[i]]); | |
| 1443 printf("\n"); | |
| 1444 #endif | |
| 1423 } else { | 1445 } else { |
| 1424 for(i=0;i<64;i++) { | 1446 for(i=0;i<64;i++) { |
| 1425 v = default_non_intra_matrix[i]; | 1447 v = default_non_intra_matrix[i]; |
| 1426 s->non_intra_matrix[i] = v; | 1448 s->non_intra_matrix[i] = v; |
| 1427 s->chroma_non_intra_matrix[i] = v; | 1449 s->chroma_non_intra_matrix[i] = v; |
