Mercurial > libavcodec.hg
comparison mpeg12.c @ 2617:616d8c4fde6d libavcodec
optimizing non_intra ac coeff decode
author | michael |
---|---|
date | Tue, 19 Apr 2005 11:37:01 +0000 |
parents | 0d88e3f89379 |
children | 943c38487346 |
comparison
equal
deleted
inserted
replaced
2616:ba6530ae8e34 | 2617:616d8c4fde6d |
---|---|
1562 uint8_t * const scantable= s->intra_scantable.permutated; | 1562 uint8_t * const scantable= s->intra_scantable.permutated; |
1563 const uint16_t *quant_matrix= s->inter_matrix; | 1563 const uint16_t *quant_matrix= s->inter_matrix; |
1564 const int qscale= s->qscale; | 1564 const int qscale= s->qscale; |
1565 | 1565 |
1566 { | 1566 { |
1567 int v; | |
1568 OPEN_READER(re, &s->gb); | 1567 OPEN_READER(re, &s->gb); |
1569 i = -1; | 1568 i = -1; |
1570 /* special case for the first coef. no need to add a second vlc table */ | 1569 /* special case for the first coef. no need to add a second vlc table */ |
1571 UPDATE_CACHE(re, &s->gb); | 1570 UPDATE_CACHE(re, &s->gb); |
1572 v= SHOW_UBITS(re, &s->gb, 2); | 1571 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { |
1573 if (v & 2) { | |
1574 LAST_SKIP_BITS(re, &s->gb, 2); | |
1575 level= (3*qscale*quant_matrix[0])>>5; | 1572 level= (3*qscale*quant_matrix[0])>>5; |
1576 level= (level-1)|1; | 1573 level= (level-1)|1; |
1577 if(v&1) | 1574 if(GET_CACHE(re, &s->gb)&0x40000000) |
1578 level= -level; | 1575 level= -level; |
1579 block[0] = level; | 1576 block[0] = level; |
1580 i++; | 1577 i++; |
1578 SKIP_BITS(re, &s->gb, 2); | |
1579 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) | |
1580 goto end; | |
1581 } | 1581 } |
1582 | 1582 |
1583 /* now quantify & encode AC coefs */ | 1583 /* now quantify & encode AC coefs */ |
1584 for(;;) { | 1584 for(;;) { |
1585 UPDATE_CACHE(re, &s->gb); | |
1586 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); | 1585 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
1587 | 1586 |
1588 if(level == 127){ | 1587 if(level != 0) { |
1589 break; | |
1590 } else if(level != 0) { | |
1591 i += run; | 1588 i += run; |
1592 j = scantable[i]; | 1589 j = scantable[i]; |
1593 level= ((level*2+1)*qscale*quant_matrix[j])>>5; | 1590 level= ((level*2+1)*qscale*quant_matrix[j])>>5; |
1594 level= (level-1)|1; | 1591 level= (level-1)|1; |
1595 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | 1592 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
1596 LAST_SKIP_BITS(re, &s->gb, 1); | 1593 SKIP_BITS(re, &s->gb, 1); |
1597 } else { | 1594 } else { |
1598 /* escape */ | 1595 /* escape */ |
1599 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | 1596 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); |
1600 UPDATE_CACHE(re, &s->gb); | 1597 UPDATE_CACHE(re, &s->gb); |
1601 level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); | 1598 level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); |
1602 if (level == -128) { | 1599 if (level == -128) { |
1603 level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8); | 1600 level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8); |
1604 } else if (level == 0) { | 1601 } else if (level == 0) { |
1605 level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8); | 1602 level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8); |
1606 } | 1603 } |
1607 i += run; | 1604 i += run; |
1608 j = scantable[i]; | 1605 j = scantable[i]; |
1609 if(level<0){ | 1606 if(level<0){ |
1610 level= -level; | 1607 level= -level; |
1620 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); | 1617 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
1621 return -1; | 1618 return -1; |
1622 } | 1619 } |
1623 | 1620 |
1624 block[j] = level; | 1621 block[j] = level; |
1625 } | 1622 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) |
1623 break; | |
1624 UPDATE_CACHE(re, &s->gb); | |
1625 } | |
1626 end: | |
1627 LAST_SKIP_BITS(re, &s->gb, 2); | |
1626 CLOSE_READER(re, &s->gb); | 1628 CLOSE_READER(re, &s->gb); |
1627 } | 1629 } |
1628 s->block_last_index[n] = i; | 1630 s->block_last_index[n] = i; |
1629 return 0; | 1631 return 0; |
1630 } | 1632 } |
1635 RLTable *rl = &rl_mpeg1; | 1637 RLTable *rl = &rl_mpeg1; |
1636 uint8_t * const scantable= s->intra_scantable.permutated; | 1638 uint8_t * const scantable= s->intra_scantable.permutated; |
1637 const int qscale= s->qscale; | 1639 const int qscale= s->qscale; |
1638 | 1640 |
1639 { | 1641 { |
1640 int v; | |
1641 OPEN_READER(re, &s->gb); | 1642 OPEN_READER(re, &s->gb); |
1642 i = -1; | 1643 i = -1; |
1643 /* special case for the first coef. no need to add a second vlc table */ | 1644 /* special case for the first coef. no need to add a second vlc table */ |
1644 UPDATE_CACHE(re, &s->gb); | 1645 UPDATE_CACHE(re, &s->gb); |
1645 v= SHOW_UBITS(re, &s->gb, 2); | 1646 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { |
1646 if (v & 2) { | |
1647 LAST_SKIP_BITS(re, &s->gb, 2); | |
1648 level= (3*qscale)>>1; | 1647 level= (3*qscale)>>1; |
1649 level= (level-1)|1; | 1648 level= (level-1)|1; |
1650 if(v&1) | 1649 if(GET_CACHE(re, &s->gb)&0x40000000) |
1651 level= -level; | 1650 level= -level; |
1652 block[0] = level; | 1651 block[0] = level; |
1653 i++; | 1652 i++; |
1653 SKIP_BITS(re, &s->gb, 2); | |
1654 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) | |
1655 goto end; | |
1654 } | 1656 } |
1655 | 1657 |
1656 /* now quantify & encode AC coefs */ | 1658 /* now quantify & encode AC coefs */ |
1657 for(;;) { | 1659 for(;;) { |
1658 UPDATE_CACHE(re, &s->gb); | |
1659 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); | 1660 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
1660 | 1661 |
1661 if(level == 127){ | 1662 if(level != 0) { |
1662 break; | |
1663 } else if(level != 0) { | |
1664 i += run; | 1663 i += run; |
1665 j = scantable[i]; | 1664 j = scantable[i]; |
1666 level= ((level*2+1)*qscale)>>1; | 1665 level= ((level*2+1)*qscale)>>1; |
1667 level= (level-1)|1; | 1666 level= (level-1)|1; |
1668 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | 1667 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
1669 LAST_SKIP_BITS(re, &s->gb, 1); | 1668 SKIP_BITS(re, &s->gb, 1); |
1670 } else { | 1669 } else { |
1671 /* escape */ | 1670 /* escape */ |
1672 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | 1671 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); |
1673 UPDATE_CACHE(re, &s->gb); | 1672 UPDATE_CACHE(re, &s->gb); |
1674 level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); | 1673 level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); |
1675 if (level == -128) { | 1674 if (level == -128) { |
1676 level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8); | 1675 level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8); |
1677 } else if (level == 0) { | 1676 } else if (level == 0) { |
1678 level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8); | 1677 level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8); |
1679 } | 1678 } |
1680 i += run; | 1679 i += run; |
1681 j = scantable[i]; | 1680 j = scantable[i]; |
1682 if(level<0){ | 1681 if(level<0){ |
1683 level= -level; | 1682 level= -level; |
1689 level= (level-1)|1; | 1688 level= (level-1)|1; |
1690 } | 1689 } |
1691 } | 1690 } |
1692 | 1691 |
1693 block[j] = level; | 1692 block[j] = level; |
1694 } | 1693 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) |
1694 break; | |
1695 UPDATE_CACHE(re, &s->gb); | |
1696 } | |
1697 end: | |
1698 LAST_SKIP_BITS(re, &s->gb, 2); | |
1695 CLOSE_READER(re, &s->gb); | 1699 CLOSE_READER(re, &s->gb); |
1696 } | 1700 } |
1697 s->block_last_index[n] = i; | 1701 s->block_last_index[n] = i; |
1698 return 0; | 1702 return 0; |
1699 } | 1703 } |
1711 int mismatch; | 1715 int mismatch; |
1712 | 1716 |
1713 mismatch = 1; | 1717 mismatch = 1; |
1714 | 1718 |
1715 { | 1719 { |
1716 int v; | |
1717 OPEN_READER(re, &s->gb); | 1720 OPEN_READER(re, &s->gb); |
1718 i = -1; | 1721 i = -1; |
1719 if (n < 4) | 1722 if (n < 4) |
1720 quant_matrix = s->inter_matrix; | 1723 quant_matrix = s->inter_matrix; |
1721 else | 1724 else |
1722 quant_matrix = s->chroma_inter_matrix; | 1725 quant_matrix = s->chroma_inter_matrix; |
1723 | 1726 |
1724 /* special case for the first coef. no need to add a second vlc table */ | 1727 /* special case for the first coef. no need to add a second vlc table */ |
1725 UPDATE_CACHE(re, &s->gb); | 1728 UPDATE_CACHE(re, &s->gb); |
1726 v= SHOW_UBITS(re, &s->gb, 2); | 1729 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { |
1727 if (v & 2) { | |
1728 LAST_SKIP_BITS(re, &s->gb, 2); | |
1729 level= (3*qscale*quant_matrix[0])>>5; | 1730 level= (3*qscale*quant_matrix[0])>>5; |
1730 if(v&1) | 1731 if(GET_CACHE(re, &s->gb)&0x40000000) |
1731 level= -level; | 1732 level= -level; |
1732 block[0] = level; | 1733 block[0] = level; |
1733 mismatch ^= level; | 1734 mismatch ^= level; |
1734 i++; | 1735 i++; |
1736 SKIP_BITS(re, &s->gb, 2); | |
1737 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) | |
1738 goto end; | |
1735 } | 1739 } |
1736 | 1740 |
1737 /* now quantify & encode AC coefs */ | 1741 /* now quantify & encode AC coefs */ |
1738 for(;;) { | 1742 for(;;) { |
1739 UPDATE_CACHE(re, &s->gb); | |
1740 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); | 1743 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
1741 | 1744 |
1742 if(level == 127){ | 1745 if(level != 0) { |
1743 break; | |
1744 } else if(level != 0) { | |
1745 i += run; | 1746 i += run; |
1746 j = scantable[i]; | 1747 j = scantable[i]; |
1747 level= ((level*2+1)*qscale*quant_matrix[j])>>5; | 1748 level= ((level*2+1)*qscale*quant_matrix[j])>>5; |
1748 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | 1749 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
1749 LAST_SKIP_BITS(re, &s->gb, 1); | 1750 SKIP_BITS(re, &s->gb, 1); |
1750 } else { | 1751 } else { |
1751 /* escape */ | 1752 /* escape */ |
1752 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | 1753 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); |
1753 UPDATE_CACHE(re, &s->gb); | 1754 UPDATE_CACHE(re, &s->gb); |
1754 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); | 1755 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); |
1767 return -1; | 1768 return -1; |
1768 } | 1769 } |
1769 | 1770 |
1770 mismatch ^= level; | 1771 mismatch ^= level; |
1771 block[j] = level; | 1772 block[j] = level; |
1772 } | 1773 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) |
1774 break; | |
1775 UPDATE_CACHE(re, &s->gb); | |
1776 } | |
1777 end: | |
1778 LAST_SKIP_BITS(re, &s->gb, 2); | |
1773 CLOSE_READER(re, &s->gb); | 1779 CLOSE_READER(re, &s->gb); |
1774 } | 1780 } |
1775 block[63] ^= (mismatch & 1); | 1781 block[63] ^= (mismatch & 1); |
1776 | 1782 |
1777 s->block_last_index[n] = i; | 1783 s->block_last_index[n] = i; |
1790 OPEN_READER(re, &s->gb); | 1796 OPEN_READER(re, &s->gb); |
1791 i = -1; | 1797 i = -1; |
1792 | 1798 |
1793 /* special case for the first coef. no need to add a second vlc table */ | 1799 /* special case for the first coef. no need to add a second vlc table */ |
1794 UPDATE_CACHE(re, &s->gb); | 1800 UPDATE_CACHE(re, &s->gb); |
1795 v= SHOW_UBITS(re, &s->gb, 2); | 1801 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { |
1796 if (v & 2) { | |
1797 LAST_SKIP_BITS(re, &s->gb, 2); | |
1798 level= (3*qscale)>>1; | 1802 level= (3*qscale)>>1; |
1799 if(v&1) | 1803 if(GET_CACHE(re, &s->gb)&0x40000000) |
1800 level= -level; | 1804 level= -level; |
1801 block[0] = level; | 1805 block[0] = level; |
1802 i++; | 1806 i++; |
1807 SKIP_BITS(re, &s->gb, 2); | |
1808 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) | |
1809 goto end; | |
1803 } | 1810 } |
1804 | 1811 |
1805 /* now quantify & encode AC coefs */ | 1812 /* now quantify & encode AC coefs */ |
1806 for(;;) { | 1813 for(;;) { |
1807 UPDATE_CACHE(re, &s->gb); | |
1808 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); | 1814 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
1809 | 1815 |
1810 if(level == 127){ | 1816 if(level != 0) { |
1811 break; | |
1812 } else if(level != 0) { | |
1813 i += run; | 1817 i += run; |
1814 j = scantable[i]; | 1818 j = scantable[i]; |
1815 level= ((level*2+1)*qscale)>>1; | 1819 level= ((level*2+1)*qscale)>>1; |
1816 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | 1820 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
1817 LAST_SKIP_BITS(re, &s->gb, 1); | 1821 SKIP_BITS(re, &s->gb, 1); |
1818 } else { | 1822 } else { |
1819 /* escape */ | 1823 /* escape */ |
1820 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | 1824 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); |
1821 UPDATE_CACHE(re, &s->gb); | 1825 UPDATE_CACHE(re, &s->gb); |
1822 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); | 1826 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); |
1830 level= ((level*2+1)*qscale)>>1; | 1834 level= ((level*2+1)*qscale)>>1; |
1831 } | 1835 } |
1832 } | 1836 } |
1833 | 1837 |
1834 block[j] = level; | 1838 block[j] = level; |
1835 } | 1839 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) |
1840 break; | |
1841 UPDATE_CACHE(re, &s->gb); | |
1842 } | |
1843 end: | |
1844 LAST_SKIP_BITS(re, &s->gb, 2); | |
1836 CLOSE_READER(re, &s->gb); | 1845 CLOSE_READER(re, &s->gb); |
1837 s->block_last_index[n] = i; | 1846 s->block_last_index[n] = i; |
1838 return 0; | 1847 return 0; |
1839 } | 1848 } |
1840 | 1849 |