Mercurial > libavcodec.hg
comparison vp3.c @ 1236:d6e4784ffc16 libavcodec
dump the shady binary search logic (the part that binary searches
through unsorted data)
author | tmmm |
---|---|
date | Sat, 10 May 2003 16:06:33 +0000 |
parents | 5d66713e97e2 |
children | 6eab0df78d47 |
comparison
equal
deleted
inserted
replaced
1235:8bb75c3c2f21 | 1236:d6e4784ffc16 |
---|---|
275 int *macroblock_fragments; | 275 int *macroblock_fragments; |
276 /* This is an array of flags indicating whether a particular | 276 /* This is an array of flags indicating whether a particular |
277 * macroblock is coded. */ | 277 * macroblock is coded. */ |
278 unsigned char *macroblock_coded; | 278 unsigned char *macroblock_coded; |
279 | 279 |
280 int first_coded_y_fragment; | |
281 int first_coded_c_fragment; | |
282 int last_coded_y_fragment; | |
283 int last_coded_c_fragment; | |
284 | |
280 } Vp3DecodeContext; | 285 } Vp3DecodeContext; |
281 | 286 |
282 /************************************************************************ | 287 /************************************************************************ |
283 * VP3 specific functions | 288 * VP3 specific functions |
284 ************************************************************************/ | 289 ************************************************************************/ |
1195 } | 1200 } |
1196 | 1201 |
1197 /* figure out which fragments are coded; iterate through each | 1202 /* figure out which fragments are coded; iterate through each |
1198 * superblock (all planes) */ | 1203 * superblock (all planes) */ |
1199 s->coded_fragment_list_index = 0; | 1204 s->coded_fragment_list_index = 0; |
1205 s->first_coded_y_fragment = s->first_coded_c_fragment = 0; | |
1206 s->last_coded_y_fragment = s->last_coded_c_fragment = -1; | |
1200 memset(s->macroblock_coded, 0, s->macroblock_count); | 1207 memset(s->macroblock_coded, 0, s->macroblock_count); |
1201 for (i = 0; i < s->superblock_count; i++) { | 1208 for (i = 0; i < s->superblock_count; i++) { |
1202 | 1209 |
1203 /* iterate through all 16 fragments in a superblock */ | 1210 /* iterate through all 16 fragments in a superblock */ |
1204 for (j = 0; j < 16; j++) { | 1211 for (j = 0; j < 16; j++) { |
1223 | 1230 |
1224 if (bit) { | 1231 if (bit) { |
1225 /* mode will be decoded in the next phase */ | 1232 /* mode will be decoded in the next phase */ |
1226 s->all_fragments[current_fragment].coding_method = | 1233 s->all_fragments[current_fragment].coding_method = |
1227 MODE_INTER_NO_MV; | 1234 MODE_INTER_NO_MV; |
1228 s->coded_fragment_list[s->coded_fragment_list_index++] = | 1235 s->coded_fragment_list[s->coded_fragment_list_index] = |
1229 current_fragment; | 1236 current_fragment; |
1237 if ((current_fragment >= s->u_fragment_start) && | |
1238 (s->last_coded_y_fragment == -1)) { | |
1239 s->first_coded_c_fragment = s->coded_fragment_list_index; | |
1240 s->last_coded_y_fragment = s->first_coded_c_fragment - 1; | |
1241 } | |
1242 s->coded_fragment_list_index++; | |
1230 s->macroblock_coded[s->all_fragments[current_fragment].macroblock] = 1; | 1243 s->macroblock_coded[s->all_fragments[current_fragment].macroblock] = 1; |
1231 debug_block_coding(" superblock %d is partially coded, fragment %d is coded\n", | 1244 debug_block_coding(" superblock %d is partially coded, fragment %d is coded\n", |
1232 i, current_fragment); | 1245 i, current_fragment); |
1233 } else { | 1246 } else { |
1234 /* not coded; copy this fragment from the prior frame */ | 1247 /* not coded; copy this fragment from the prior frame */ |
1244 | 1257 |
1245 /* fragments are fully coded in this superblock; actual | 1258 /* fragments are fully coded in this superblock; actual |
1246 * coding will be determined in next step */ | 1259 * coding will be determined in next step */ |
1247 s->all_fragments[current_fragment].coding_method = | 1260 s->all_fragments[current_fragment].coding_method = |
1248 MODE_INTER_NO_MV; | 1261 MODE_INTER_NO_MV; |
1249 s->coded_fragment_list[s->coded_fragment_list_index++] = | 1262 s->coded_fragment_list[s->coded_fragment_list_index] = |
1250 current_fragment; | 1263 current_fragment; |
1264 if ((current_fragment >= s->u_fragment_start) && | |
1265 (s->last_coded_y_fragment == -1)) { | |
1266 s->first_coded_c_fragment = s->coded_fragment_list_index; | |
1267 s->last_coded_y_fragment = s->first_coded_c_fragment - 1; | |
1268 } | |
1269 s->coded_fragment_list_index++; | |
1251 s->macroblock_coded[s->all_fragments[current_fragment].macroblock] = 1; | 1270 s->macroblock_coded[s->all_fragments[current_fragment].macroblock] = 1; |
1252 debug_block_coding(" superblock %d is fully coded, fragment %d is coded\n", | 1271 debug_block_coding(" superblock %d is fully coded, fragment %d is coded\n", |
1253 i, current_fragment); | 1272 i, current_fragment); |
1254 } | 1273 } |
1255 } | 1274 } |
1256 } | 1275 } |
1257 } | 1276 } |
1277 | |
1278 if (s->first_coded_c_fragment == 0) | |
1279 /* no C fragments coded */ | |
1280 s->last_coded_y_fragment = s->coded_fragment_list_index - 1; | |
1281 else | |
1282 s->last_coded_c_fragment = s->coded_fragment_list_index - 1; | |
1283 debug_block_coding(" %d total coded fragments, y: %d -> %d, c: %d -> %d\n", | |
1284 s->coded_fragment_list_index, | |
1285 s->first_coded_y_fragment, | |
1286 s->last_coded_y_fragment, | |
1287 s->first_coded_c_fragment, | |
1288 s->last_coded_c_fragment); | |
1258 } | 1289 } |
1259 | 1290 |
1260 /* | 1291 /* |
1261 * This function unpacks all the coding mode data for individual macroblocks | 1292 * This function unpacks all the coding mode data for individual macroblocks |
1262 * from the bitstream. | 1293 * from the bitstream. |
1563 int token; | 1594 int token; |
1564 int zero_run; | 1595 int zero_run; |
1565 DCTELEM coeff; | 1596 DCTELEM coeff; |
1566 Vp3Fragment *fragment; | 1597 Vp3Fragment *fragment; |
1567 | 1598 |
1568 for (i = first_fragment; i < last_fragment; i++) { | 1599 for (i = first_fragment; i <= last_fragment; i++) { |
1569 | 1600 |
1570 fragment = &s->all_fragments[s->coded_fragment_list[i]]; | 1601 fragment = &s->all_fragments[s->coded_fragment_list[i]]; |
1571 if (fragment->coeff_count > coeff_index) | 1602 if (fragment->coeff_count > coeff_index) |
1572 continue; | 1603 continue; |
1573 | 1604 |
1608 int dc_c_table; | 1639 int dc_c_table; |
1609 int ac_y_table; | 1640 int ac_y_table; |
1610 int ac_c_table; | 1641 int ac_c_table; |
1611 int residual_eob_run = 0; | 1642 int residual_eob_run = 0; |
1612 | 1643 |
1613 /* for the binary search */ | |
1614 int left, middle, right, found; | |
1615 /* this indicates the first fragment of the color plane data */ | |
1616 int plane_split = 0; | |
1617 | |
1618 debug_vp3(" vp3: unpacking DCT coefficients\n"); | |
1619 | |
1620 /* find the plane split (the first color plane fragment) using a binary | |
1621 * search; test the boundaries first */ | |
1622 if (s->coded_fragment_list_index == 0) | |
1623 return; | |
1624 if (s->u_fragment_start <= s->coded_fragment_list[0]) | |
1625 plane_split = 0; /* this means no Y fragments */ | |
1626 else if (s->coded_fragment_list[s->coded_fragment_list_index - 1] > | |
1627 s->u_fragment_start) { | |
1628 | |
1629 left = 0; | |
1630 right = s->coded_fragment_list_index - 1; | |
1631 found = 0; | |
1632 do { | |
1633 middle = (left + right + 1) / 2; | |
1634 if ((s->coded_fragment_list[middle] >= s->u_fragment_start) && | |
1635 (s->coded_fragment_list[middle - 1] < s->u_fragment_start)) | |
1636 found = 1; | |
1637 else if (s->coded_fragment_list[middle] < s->u_fragment_start) | |
1638 left = middle; | |
1639 else | |
1640 right = middle; | |
1641 } while (!found); | |
1642 | |
1643 plane_split = middle; | |
1644 } | |
1645 | |
1646 debug_vp3(" plane split @ index %d (fragment %d)\n", plane_split, | |
1647 s->coded_fragment_list[plane_split]); | |
1648 | |
1649 /* fetch the DC table indices */ | 1644 /* fetch the DC table indices */ |
1650 dc_y_table = get_bits(gb, 4); | 1645 dc_y_table = get_bits(gb, 4); |
1651 dc_c_table = get_bits(gb, 4); | 1646 dc_c_table = get_bits(gb, 4); |
1652 | 1647 |
1653 /* unpack the Y plane DC coefficients */ | 1648 /* unpack the Y plane DC coefficients */ |
1654 debug_vp3(" vp3: unpacking Y plane DC coefficients using table %d\n", | 1649 debug_vp3(" vp3: unpacking Y plane DC coefficients using table %d\n", |
1655 dc_y_table); | 1650 dc_y_table); |
1656 residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_y_table], 0, | 1651 residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_y_table], 0, |
1657 0, plane_split, residual_eob_run); | 1652 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); |
1658 | 1653 |
1659 /* unpack the C plane DC coefficients */ | 1654 /* unpack the C plane DC coefficients */ |
1660 debug_vp3(" vp3: unpacking C plane DC coefficients using table %d\n", | 1655 debug_vp3(" vp3: unpacking C plane DC coefficients using table %d\n", |
1661 dc_c_table); | 1656 dc_c_table); |
1662 residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_c_table], 0, | 1657 residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_c_table], 0, |
1663 plane_split, s->coded_fragment_list_index, residual_eob_run); | 1658 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); |
1664 | 1659 |
1665 /* fetch the AC table indices */ | 1660 /* fetch the AC table indices */ |
1666 ac_y_table = get_bits(gb, 4); | 1661 ac_y_table = get_bits(gb, 4); |
1667 ac_c_table = get_bits(gb, 4); | 1662 ac_c_table = get_bits(gb, 4); |
1668 | 1663 |
1670 for (i = 1; i <= 5; i++) { | 1665 for (i = 1; i <= 5; i++) { |
1671 | 1666 |
1672 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", | 1667 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", |
1673 i, ac_y_table); | 1668 i, ac_y_table); |
1674 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_y_table], i, | 1669 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_y_table], i, |
1675 0, plane_split, residual_eob_run); | 1670 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); |
1676 | 1671 |
1677 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", | 1672 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", |
1678 i, ac_c_table); | 1673 i, ac_c_table); |
1679 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_c_table], i, | 1674 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_c_table], i, |
1680 plane_split, s->coded_fragment_list_index, residual_eob_run); | 1675 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); |
1681 } | 1676 } |
1682 | 1677 |
1683 /* unpack the group 2 AC coefficients (coeffs 6-14) */ | 1678 /* unpack the group 2 AC coefficients (coeffs 6-14) */ |
1684 for (i = 6; i <= 14; i++) { | 1679 for (i = 6; i <= 14; i++) { |
1685 | 1680 |
1686 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", | 1681 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", |
1687 i, ac_y_table); | 1682 i, ac_y_table); |
1688 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_y_table], i, | 1683 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_y_table], i, |
1689 0, plane_split, residual_eob_run); | 1684 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); |
1690 | 1685 |
1691 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", | 1686 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", |
1692 i, ac_c_table); | 1687 i, ac_c_table); |
1693 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_c_table], i, | 1688 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_c_table], i, |
1694 plane_split, s->coded_fragment_list_index, residual_eob_run); | 1689 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); |
1695 } | 1690 } |
1696 | 1691 |
1697 /* unpack the group 3 AC coefficients (coeffs 15-27) */ | 1692 /* unpack the group 3 AC coefficients (coeffs 15-27) */ |
1698 for (i = 15; i <= 27; i++) { | 1693 for (i = 15; i <= 27; i++) { |
1699 | 1694 |
1700 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", | 1695 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", |
1701 i, ac_y_table); | 1696 i, ac_y_table); |
1702 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_y_table], i, | 1697 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_y_table], i, |
1703 0, plane_split, residual_eob_run); | 1698 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); |
1704 | 1699 |
1705 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", | 1700 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", |
1706 i, ac_c_table); | 1701 i, ac_c_table); |
1707 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_c_table], i, | 1702 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_c_table], i, |
1708 plane_split, s->coded_fragment_list_index, residual_eob_run); | 1703 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); |
1709 } | 1704 } |
1710 | 1705 |
1711 /* unpack the group 4 AC coefficients (coeffs 28-63) */ | 1706 /* unpack the group 4 AC coefficients (coeffs 28-63) */ |
1712 for (i = 28; i <= 63; i++) { | 1707 for (i = 28; i <= 63; i++) { |
1713 | 1708 |
1714 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", | 1709 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", |
1715 i, ac_y_table); | 1710 i, ac_y_table); |
1716 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_y_table], i, | 1711 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_y_table], i, |
1717 0, plane_split, residual_eob_run); | 1712 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); |
1718 | 1713 |
1719 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", | 1714 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", |
1720 i, ac_c_table); | 1715 i, ac_c_table); |
1721 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_c_table], i, | 1716 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_c_table], i, |
1722 plane_split, s->coded_fragment_list_index, residual_eob_run); | 1717 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); |
1723 } | 1718 } |
1724 } | 1719 } |
1725 | 1720 |
1726 /* | 1721 /* |
1727 * This function reverses the DC prediction for each coded fragment in | 1722 * This function reverses the DC prediction for each coded fragment in |