comparison mpeg12.c @ 706:e65798d228ea libavcodec

idct permutation cleanup, idct can be selected per context now fixing some threadunsafe code
author michaelni
date Sun, 29 Sep 2002 22:44:22 +0000
parents 20810b0193ef
children 97377ab86647
comparison
equal deleted inserted replaced
705:107a56aa74f5 706:e65798d228ea
540 540
541 /* now quantify & encode AC coefs */ 541 /* now quantify & encode AC coefs */
542 last_non_zero = i - 1; 542 last_non_zero = i - 1;
543 543
544 for(;i<=last_index;i++) { 544 for(;i<=last_index;i++) {
545 j = zigzag_direct[i]; 545 j = s->intra_scantable.permutated[i];
546 level = block[j]; 546 level = block[j];
547 next_coef: 547 next_coef:
548 #if 0 548 #if 0
549 if (level != 0) 549 if (level != 0)
550 dprintf("level[%d]=%d\n", i, level); 550 dprintf("level[%d]=%d\n", i, level);
551 #endif 551 #endif
552 /* encode using VLC */ 552 /* encode using VLC */
553 if (level != 0) { 553 if (level != 0) {
554 run = i - last_non_zero - 1; 554 run = i - last_non_zero - 1;
555 #ifdef ARCH_X86 555
556 asm volatile( 556 alevel= level;
557 "movl %2, %1 \n\t" 557 MASK_ABS(sign, alevel)
558 "movl %1, %0 \n\t" 558 sign&=1;
559 "addl %1, %1 \n\t" 559
560 "sbbl %1, %1 \n\t"
561 "xorl %1, %0 \n\t"
562 "subl %1, %0 \n\t"
563 "andl $1, %1 \n\t"
564 : "=&r" (alevel), "=&r" (sign)
565 : "g" (level)
566 );
567 #else
568 sign = 0;
569 alevel = level;
570 if (alevel < 0) {
571 sign = 1;
572 alevel = -alevel;
573 }
574 #endif
575 // code = get_rl_index(rl, 0, run, alevel); 560 // code = get_rl_index(rl, 0, run, alevel);
576 if (alevel > mpeg1_max_level[0][run]) 561 if (alevel > mpeg1_max_level[0][run])
577 code= 111; /*rl->n*/ 562 code= 111; /*rl->n*/
578 else 563 else
579 code= mpeg1_index_run[0][run] + alevel - 1; 564 code= mpeg1_index_run[0][run] + alevel - 1;
1038 int n) 1023 int n)
1039 { 1024 {
1040 int level, dc, diff, i, j, run; 1025 int level, dc, diff, i, j, run;
1041 int code, component; 1026 int code, component;
1042 RLTable *rl = &rl_mpeg1; 1027 RLTable *rl = &rl_mpeg1;
1028 UINT8 * const scantable= s->intra_scantable.permutated;
1043 1029
1044 if (s->mb_intra) { 1030 if (s->mb_intra) {
1045 /* DC coef */ 1031 /* DC coef */
1046 component = (n <= 3 ? 0 : n - 4 + 1); 1032 component = (n <= 3 ? 0 : n - 4 + 1);
1047 diff = decode_dc(s, component); 1033 diff = decode_dc(s, component);
1097 i += run; 1083 i += run;
1098 if (i >= 64) 1084 if (i >= 64)
1099 return -1; 1085 return -1;
1100 add_coef: 1086 add_coef:
1101 dprintf("%d: run=%d level=%d\n", n, run, level); 1087 dprintf("%d: run=%d level=%d\n", n, run, level);
1102 j = zigzag_direct[i]; 1088 j = scantable[i];
1103 block[j] = level; 1089 block[j] = level;
1104 i++; 1090 i++;
1105 } 1091 }
1106 s->block_last_index[n] = i-1; 1092 s->block_last_index[n] = i-1;
1107 return 0; 1093 return 0;
1119 const UINT8 *scan_table; 1105 const UINT8 *scan_table;
1120 const UINT16 *matrix; 1106 const UINT16 *matrix;
1121 int mismatch; 1107 int mismatch;
1122 1108
1123 if (s->alternate_scan) 1109 if (s->alternate_scan)
1124 scan_table = ff_alternate_vertical_scan; 1110 scan_table = s->intra_v_scantable.permutated;
1125 else 1111 else
1126 scan_table = zigzag_direct; 1112 scan_table = s->intra_scantable.permutated;
1127 mismatch = 1; 1113 mismatch = 1;
1128 1114
1129 { 1115 {
1130 int v; 1116 int v;
1131 OPEN_READER(re, &s->gb); 1117 OPEN_READER(re, &s->gb);
1138 /* special case for the first coef. no need to add a second vlc table */ 1124 /* special case for the first coef. no need to add a second vlc table */
1139 UPDATE_CACHE(re, &s->gb); 1125 UPDATE_CACHE(re, &s->gb);
1140 v= SHOW_UBITS(re, &s->gb, 2); 1126 v= SHOW_UBITS(re, &s->gb, 2);
1141 if (v & 2) { 1127 if (v & 2) {
1142 run = 0; 1128 run = 0;
1143 level = 1 - ((v & 1) << 1); 1129 level = 5 - (v << 1);
1144 SKIP_BITS(re, &s->gb, 2); 1130 SKIP_BITS(re, &s->gb, 2);
1145 CLOSE_READER(re, &s->gb); 1131 CLOSE_READER(re, &s->gb);
1146 goto add_coef; 1132 goto add_coef;
1147 } 1133 }
1148 CLOSE_READER(re, &s->gb); 1134 CLOSE_READER(re, &s->gb);
1189 block[j] = level; 1175 block[j] = level;
1190 i++; 1176 i++;
1191 } 1177 }
1192 block[63] ^= (mismatch & 1); 1178 block[63] ^= (mismatch & 1);
1193 s->block_last_index[n] = i; 1179 s->block_last_index[n] = i;
1180
1194 return 0; 1181 return 0;
1195 } 1182 }
1196 1183
1197 static int mpeg2_decode_block_intra(MpegEncContext *s, 1184 static int mpeg2_decode_block_intra(MpegEncContext *s,
1198 DCTELEM *block, 1185 DCTELEM *block,
1204 const UINT8 *scan_table; 1191 const UINT8 *scan_table;
1205 const UINT16 *matrix; 1192 const UINT16 *matrix;
1206 int mismatch; 1193 int mismatch;
1207 1194
1208 if (s->alternate_scan) 1195 if (s->alternate_scan)
1209 scan_table = ff_alternate_vertical_scan; 1196 scan_table = s->intra_v_scantable.permutated;
1210 else 1197 else
1211 scan_table = zigzag_direct; 1198 scan_table = s->intra_scantable.permutated;
1212 1199
1213 /* DC coef */ 1200 /* DC coef */
1214 component = (n <= 3 ? 0 : n - 4 + 1); 1201 component = (n <= 3 ? 0 : n - 4 + 1);
1215 diff = decode_dc(s, component); 1202 diff = decode_dc(s, component);
1216 if (diff >= 0xffff) 1203 if (diff >= 0xffff)
1400 dprintf("matrix extension\n"); 1387 dprintf("matrix extension\n");
1401 1388
1402 if (get_bits1(&s->gb)) { 1389 if (get_bits1(&s->gb)) {
1403 for(i=0;i<64;i++) { 1390 for(i=0;i<64;i++) {
1404 v = get_bits(&s->gb, 8); 1391 v = get_bits(&s->gb, 8);
1405 j = zigzag_direct[i]; 1392 j = s->intra_scantable.permutated[i];
1406 s->intra_matrix[j] = v; 1393 s->intra_matrix[j] = v;
1407 s->chroma_intra_matrix[j] = v; 1394 s->chroma_intra_matrix[j] = v;
1408 } 1395 }
1409 } 1396 }
1410 if (get_bits1(&s->gb)) { 1397 if (get_bits1(&s->gb)) {
1411 for(i=0;i<64;i++) { 1398 for(i=0;i<64;i++) {
1412 v = get_bits(&s->gb, 8); 1399 v = get_bits(&s->gb, 8);
1413 j = zigzag_direct[i]; 1400 j = s->intra_scantable.permutated[i];
1414 s->inter_matrix[j] = v; 1401 s->inter_matrix[j] = v;
1415 s->chroma_inter_matrix[j] = v; 1402 s->chroma_inter_matrix[j] = v;
1416 } 1403 }
1417 } 1404 }
1418 if (get_bits1(&s->gb)) { 1405 if (get_bits1(&s->gb)) {
1419 for(i=0;i<64;i++) { 1406 for(i=0;i<64;i++) {
1420 v = get_bits(&s->gb, 8); 1407 v = get_bits(&s->gb, 8);
1421 j = zigzag_direct[i]; 1408 j = s->intra_scantable.permutated[i];
1422 s->chroma_intra_matrix[j] = v; 1409 s->chroma_intra_matrix[j] = v;
1423 } 1410 }
1424 } 1411 }
1425 if (get_bits1(&s->gb)) { 1412 if (get_bits1(&s->gb)) {
1426 for(i=0;i<64;i++) { 1413 for(i=0;i<64;i++) {
1427 v = get_bits(&s->gb, 8); 1414 v = get_bits(&s->gb, 8);
1428 j = zigzag_direct[i]; 1415 j = s->intra_scantable.permutated[i];
1429 s->chroma_inter_matrix[j] = v; 1416 s->chroma_inter_matrix[j] = v;
1430 } 1417 }
1431 } 1418 }
1432 } 1419 }
1433 1420
1634 1621
1635 /* get matrix */ 1622 /* get matrix */
1636 if (get_bits1(&s->gb)) { 1623 if (get_bits1(&s->gb)) {
1637 for(i=0;i<64;i++) { 1624 for(i=0;i<64;i++) {
1638 v = get_bits(&s->gb, 8); 1625 v = get_bits(&s->gb, 8);
1639 j = zigzag_direct[i]; 1626 j = s->intra_scantable.permutated[i];
1640 s->intra_matrix[j] = v; 1627 s->intra_matrix[j] = v;
1641 s->chroma_intra_matrix[j] = v; 1628 s->chroma_intra_matrix[j] = v;
1642 } 1629 }
1643 #ifdef DEBUG 1630 #ifdef DEBUG
1644 dprintf("intra matrix present\n"); 1631 dprintf("intra matrix present\n");
1646 dprintf(" %d", s->intra_matrix[zigzag_direct[i]]); 1633 dprintf(" %d", s->intra_matrix[zigzag_direct[i]]);
1647 printf("\n"); 1634 printf("\n");
1648 #endif 1635 #endif
1649 } else { 1636 } else {
1650 for(i=0;i<64;i++) { 1637 for(i=0;i<64;i++) {
1638 int j= s->idct_permutation[i];
1651 v = ff_mpeg1_default_intra_matrix[i]; 1639 v = ff_mpeg1_default_intra_matrix[i];
1652 s->intra_matrix[i] = v; 1640 s->intra_matrix[j] = v;
1653 s->chroma_intra_matrix[i] = v; 1641 s->chroma_intra_matrix[j] = v;
1654 } 1642 }
1655 } 1643 }
1656 if (get_bits1(&s->gb)) { 1644 if (get_bits1(&s->gb)) {
1657 for(i=0;i<64;i++) { 1645 for(i=0;i<64;i++) {
1658 v = get_bits(&s->gb, 8); 1646 v = get_bits(&s->gb, 8);
1659 j = zigzag_direct[i]; 1647 j = s->intra_scantable.permutated[i];
1660 s->inter_matrix[j] = v; 1648 s->inter_matrix[j] = v;
1661 s->chroma_inter_matrix[j] = v; 1649 s->chroma_inter_matrix[j] = v;
1662 } 1650 }
1663 #ifdef DEBUG 1651 #ifdef DEBUG
1664 dprintf("non intra matrix present\n"); 1652 dprintf("non intra matrix present\n");
1666 dprintf(" %d", s->inter_matrix[zigzag_direct[i]]); 1654 dprintf(" %d", s->inter_matrix[zigzag_direct[i]]);
1667 printf("\n"); 1655 printf("\n");
1668 #endif 1656 #endif
1669 } else { 1657 } else {
1670 for(i=0;i<64;i++) { 1658 for(i=0;i<64;i++) {
1659 int j= s->idct_permutation[i];
1671 v = ff_mpeg1_default_non_intra_matrix[i]; 1660 v = ff_mpeg1_default_non_intra_matrix[i];
1672 s->inter_matrix[i] = v; 1661 s->inter_matrix[j] = v;
1673 s->chroma_inter_matrix[i] = v; 1662 s->chroma_inter_matrix[j] = v;
1674 } 1663 }
1675 } 1664 }
1676 1665
1677 /* we set mpeg2 parameters so that it emulates mpeg1 */ 1666 /* we set mpeg2 parameters so that it emulates mpeg1 */
1678 s->progressive_sequence = 1; 1667 s->progressive_sequence = 1;