Revision 29df2599 libavcodec/mpeg12.c

View differences:

libavcodec/mpeg12.c
1564 1564
    const int qscale= s->qscale;
1565 1565

  
1566 1566
    {
1567
        int v;
1568 1567
        OPEN_READER(re, &s->gb);
1569 1568
        i = -1;
1570 1569
        /* special case for the first coef. no need to add a second vlc table */
1571 1570
        UPDATE_CACHE(re, &s->gb);
1572
        v= SHOW_UBITS(re, &s->gb, 2);
1573
        if (v & 2) {
1574
            LAST_SKIP_BITS(re, &s->gb, 2);
1571
        if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
1575 1572
            level= (3*qscale*quant_matrix[0])>>5;
1576 1573
            level= (level-1)|1;
1577
            if(v&1)
1574
            if(GET_CACHE(re, &s->gb)&0x40000000)
1578 1575
                level= -level;
1579 1576
            block[0] = level;
1580 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 1583
        /* now quantify & encode AC coefs */
1584 1584
        for(;;) {
1585
            UPDATE_CACHE(re, &s->gb);
1586 1585
            GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
1587 1586
            
1588
            if(level == 127){
1589
                break;
1590
            } else if(level != 0) {
1587
            if(level != 0) {
1591 1588
                i += run;
1592 1589
                j = scantable[i];
1593 1590
                level= ((level*2+1)*qscale*quant_matrix[j])>>5;
1594 1591
                level= (level-1)|1;
1595 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 1594
            } else {
1598 1595
                /* escape */
1599 1596
                run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
1600 1597
                UPDATE_CACHE(re, &s->gb);
1601 1598
                level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
1602 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 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 1604
                i += run;
1608 1605
                j = scantable[i];
......
1622 1619
            }
1623 1620

  
1624 1621
            block[j] = level;
1622
            if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
1623
                break;
1624
            UPDATE_CACHE(re, &s->gb);
1625 1625
        }
1626
end:
1627
        LAST_SKIP_BITS(re, &s->gb, 2);
1626 1628
        CLOSE_READER(re, &s->gb);
1627 1629
    }
1628 1630
    s->block_last_index[n] = i;
......
1637 1639
    const int qscale= s->qscale;
1638 1640

  
1639 1641
    {
1640
        int v;
1641 1642
        OPEN_READER(re, &s->gb);
1642 1643
        i = -1;
1643 1644
        /* special case for the first coef. no need to add a second vlc table */
1644 1645
        UPDATE_CACHE(re, &s->gb);
1645
        v= SHOW_UBITS(re, &s->gb, 2);
1646
        if (v & 2) {
1647
            LAST_SKIP_BITS(re, &s->gb, 2);
1646
        if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
1648 1647
            level= (3*qscale)>>1;
1649 1648
            level= (level-1)|1;
1650
            if(v&1)
1649
            if(GET_CACHE(re, &s->gb)&0x40000000)
1651 1650
                level= -level;
1652 1651
            block[0] = level;
1653 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 1658
        /* now quantify & encode AC coefs */
1657 1659
        for(;;) {
1658
            UPDATE_CACHE(re, &s->gb);
1659 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
                break;
1663
            } else if(level != 0) {
1662
            if(level != 0) {
1664 1663
                i += run;
1665 1664
                j = scantable[i];
1666 1665
                level= ((level*2+1)*qscale)>>1;
1667 1666
                level= (level-1)|1;
1668 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 1669
            } else {
1671 1670
                /* escape */
1672 1671
                run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
1673 1672
                UPDATE_CACHE(re, &s->gb);
1674 1673
                level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
1675 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 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 1679
                i += run;
1681 1680
                j = scantable[i];
......
1691 1690
            }
1692 1691

  
1693 1692
            block[j] = level;
1693
            if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
1694
                break;
1695
            UPDATE_CACHE(re, &s->gb);
1694 1696
        }
1697
end:
1698
        LAST_SKIP_BITS(re, &s->gb, 2);
1695 1699
        CLOSE_READER(re, &s->gb);
1696 1700
    }
1697 1701
    s->block_last_index[n] = i;
......
1713 1717
    mismatch = 1;
1714 1718

  
1715 1719
    {
1716
        int v;
1717 1720
        OPEN_READER(re, &s->gb);
1718 1721
        i = -1;
1719 1722
        if (n < 4)
......
1723 1726

  
1724 1727
        /* special case for the first coef. no need to add a second vlc table */
1725 1728
        UPDATE_CACHE(re, &s->gb);
1726
        v= SHOW_UBITS(re, &s->gb, 2);
1727
        if (v & 2) {
1728
            LAST_SKIP_BITS(re, &s->gb, 2);
1729
        if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
1729 1730
            level= (3*qscale*quant_matrix[0])>>5;
1730
            if(v&1)
1731
            if(GET_CACHE(re, &s->gb)&0x40000000)
1731 1732
                level= -level;
1732 1733
            block[0] = level;
1733 1734
            mismatch ^= level;
1734 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 1741
        /* now quantify & encode AC coefs */
1738 1742
        for(;;) {
1739
            UPDATE_CACHE(re, &s->gb);
1740 1743
            GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
1741 1744
            
1742
            if(level == 127){
1743
                break;
1744
            } else if(level != 0) {
1745
            if(level != 0) {
1745 1746
                i += run;
1746 1747
                j = scantable[i];
1747 1748
                level= ((level*2+1)*qscale*quant_matrix[j])>>5;
1748 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 1751
            } else {
1751 1752
                /* escape */
1752 1753
                run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
......
1769 1770
            
1770 1771
            mismatch ^= level;
1771 1772
            block[j] = level;
1773
            if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
1774
                break;
1775
            UPDATE_CACHE(re, &s->gb);
1772 1776
        }
1777
end:
1778
        LAST_SKIP_BITS(re, &s->gb, 2);
1773 1779
        CLOSE_READER(re, &s->gb);
1774 1780
    }
1775 1781
    block[63] ^= (mismatch & 1);
......
1792 1798

  
1793 1799
    /* special case for the first coef. no need to add a second vlc table */
1794 1800
    UPDATE_CACHE(re, &s->gb);
1795
    v= SHOW_UBITS(re, &s->gb, 2);
1796
    if (v & 2) {
1797
        LAST_SKIP_BITS(re, &s->gb, 2);
1801
    if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
1798 1802
        level= (3*qscale)>>1;
1799
        if(v&1)
1803
        if(GET_CACHE(re, &s->gb)&0x40000000)
1800 1804
            level= -level;
1801 1805
        block[0] = level;
1802 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 1812
    /* now quantify & encode AC coefs */
1806 1813
    for(;;) {
1807
        UPDATE_CACHE(re, &s->gb);
1808 1814
        GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
1809 1815
        
1810
        if(level == 127){
1811
            break;
1812
        } else if(level != 0) {
1816
        if(level != 0) {
1813 1817
            i += run;
1814 1818
            j = scantable[i];
1815 1819
            level= ((level*2+1)*qscale)>>1;
1816 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 1822
        } else {
1819 1823
            /* escape */
1820 1824
            run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
......
1832 1836
        }
1833 1837
        
1834 1838
        block[j] = level;
1839
        if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
1840
            break;
1841
        UPDATE_CACHE(re, &s->gb);
1835 1842
    }
1843
end:
1844
    LAST_SKIP_BITS(re, &s->gb, 2);    
1836 1845
    CLOSE_READER(re, &s->gb);
1837 1846
    s->block_last_index[n] = i;
1838 1847
    return 0;

Also available in: Unified diff