Revision a8d73e56

View differences:

libavcodec/snow.c
1278 1278
    const int w= b->width;
1279 1279
    const int h= b->height;
1280 1280
    int x, y;
1281

  
1282
#if 1
1281
    
1282
#if 0
1283 1283
    if(orientation==3 && parent && 0){
1284 1284
        int16_t candidate[w*h][2];
1285 1285
        uint8_t state[w*h];
......
1401 1401
    }
1402 1402
#endif
1403 1403
    if(1){
1404
        int w, h;
1405 1404
        int run=0;
1406
        int last_run=0;
1407
        int last_v=1;
1408
        int last_x=0;
1409
        int runs[b->width*b->height];
1405
        int runs[w*h];
1410 1406
        int run_index=0;
1411 1407
                
1412
        if(orientation==1){
1413
            w= b->height;
1414
            h= b->width;
1415
        }else{
1416
            w= b->width;
1417
            h= b->height;
1418
        }
1419

  
1420 1408
        for(y=0; y<h; y++){
1421 1409
            for(x=0; x<w; x++){
1422 1410
                int v, p=0;
1423 1411
                int /*ll=0, */l=0, lt=0, t=0, rt=0;
1424
                if(orientation==1) v= src[y + x*stride];
1425
                else               v= src[x + y*stride];
1412
                v= src[x + y*stride];
1426 1413

  
1427 1414
                if(y){
1428
                    if(orientation==1) t= src[y - 1 + x*stride];
1429
                    else               t= src[x + (y-1)*stride];
1415
                    t= src[x + (y-1)*stride];
1430 1416
                    if(x){
1431
                        if(orientation==1) lt= src[y - 1 + (x-1)*stride];
1432
                        else               lt= src[x - 1 + (y-1)*stride];
1417
                        lt= src[x - 1 + (y-1)*stride];
1433 1418
                    }
1434 1419
                    if(x + 1 < w){
1435
                        if(orientation==1) rt= src[y - 1 + (x+1)*stride];
1436
                        else               rt= src[x + 1 + (y-1)*stride];
1420
                        rt= src[x + 1 + (y-1)*stride];
1437 1421
                    }
1438 1422
                }
1439 1423
                if(x){
1440
                    if(orientation==1) l= src[y + (x-1)*stride];
1441
                    else               l= src[x - 1 + y*stride];
1424
                    l= src[x - 1 + y*stride];
1442 1425
                    /*if(x > 1){
1443 1426
                        if(orientation==1) ll= src[y + (x-2)*stride];
1444 1427
                        else               ll= src[x - 2 + y*stride];
1445 1428
                    }*/
1446 1429
                }
1447 1430
                if(parent){
1448
                    int px= (orientation==1 ? y : x)>>1;
1449
                    int py= (orientation==1 ? x : y)>>1;
1431
                    int px= x>>1;
1432
                    int py= y>>1;
1450 1433
                    if(px<b->parent->width && py<b->parent->height) 
1451 1434
                        p= parent[px + py*2*stride];
1452 1435
                }
......
1470 1453
            for(x=0; x<w; x++){
1471 1454
                int v, p=0;
1472 1455
                int /*ll=0, */l=0, lt=0, t=0, rt=0;
1473
                if(orientation==1) v= src[y + x*stride];
1474
                else               v= src[x + y*stride];
1456
                v= src[x + y*stride];
1475 1457

  
1476 1458
                if(y){
1477
                    if(orientation==1) t= src[y - 1 + x*stride];
1478
                    else               t= src[x + (y-1)*stride];
1459
                    t= src[x + (y-1)*stride];
1479 1460
                    if(x){
1480
                        if(orientation==1) lt= src[y - 1 + (x-1)*stride];
1481
                        else               lt= src[x - 1 + (y-1)*stride];
1461
                        lt= src[x - 1 + (y-1)*stride];
1482 1462
                    }
1483 1463
                    if(x + 1 < w){
1484
                        if(orientation==1) rt= src[y - 1 + (x+1)*stride];
1485
                        else               rt= src[x + 1 + (y-1)*stride];
1464
                        rt= src[x + 1 + (y-1)*stride];
1486 1465
                    }
1487 1466
                }
1488 1467
                if(x){
1489
                    if(orientation==1) l= src[y + (x-1)*stride];
1490
                    else               l= src[x - 1 + y*stride];
1468
                    l= src[x - 1 + y*stride];
1491 1469
                    /*if(x > 1){
1492 1470
                        if(orientation==1) ll= src[y + (x-2)*stride];
1493 1471
                        else               ll= src[x - 2 + y*stride];
1494 1472
                    }*/
1495 1473
                }
1496 1474
                if(parent){
1497
                    int px= (orientation==1 ? y : x)>>1;
1498
                    int py= (orientation==1 ? x : y)>>1;
1475
                    int px= x>>1;
1476
                    int py= y>>1;
1499 1477
                    if(px<b->parent->width && py<b->parent->height) 
1500 1478
                        p= parent[px + py*2*stride];
1501 1479
                }
......
1523 1501
        }
1524 1502
        return;
1525 1503
    }
1526
    if(1){
1527
        int w, h;
1528
        int run=0;
1529
        int last_run=0;
1530
        int last_v=1;
1531
        int last_x=0;
1532
                
1533
        if(orientation==1){
1534
            w= b->height;
1535
            h= b->width;
1536
        }else{
1537
            w= b->width;
1538
            h= b->height;
1539
        }
1540

  
1541
        for(y=0; y<h; y++){
1542
            for(x=0; x<w; x++){
1543
                int v, p;
1544
                if(orientation==1) v= src[y + x*stride];
1545
                else               v= src[x + y*stride];
1546

  
1547
                if(v){
1548
                    int sec=0, pri=0/*, lt=0, rt=0, pri2=0*/;
1549
                    
1550
                    if(y){
1551
                        if(orientation==1) sec= src[y - 1 + x*stride];
1552
                        else               sec= src[x + (y-1)*stride];
1553
/*                        if(x){
1554
                            if(orientation==1) lt= src[y - 1 + (x-1)*stride];
1555
                            else               lt= src[x - 1 + (y-1)*stride];
1556
                        }*/
1557
                    }
1558
/*                    if      (orientation==1 && y + 1 < h && x) rt= src[y + 1 + (x-1)*stride];
1559
                    else if (orientation!=1 && x + 1 < w && y) rt= src[x + 1 + (y-1)*stride];*/
1560
                    if(x){
1561
                        if(orientation==1) pri= src[y + (x-1)*stride];
1562
                        else               pri= src[x - 1 + y*stride];
1563
/*                        if(x > 1){
1564
                            if(orientation==1) pri2= src[y + (x-2)*stride];
1565
                            else               pri2= src[x - 2 + y*stride];
1566
                        }*/
1567
                    }
1568

  
1569
                    put_symbol(&s->c, b->state[ABS(quant7[last_v&0xFF])], run, 0);
1570
//                    context= 3*7 + 3 + quant11[last_v&0xFF] /*+ 7*quant3[(run-1)&0xFF]*/;
1571
//                    if(parent && orientation!=1) context += 3*7+7*quant3[parent[(x>>1) + (y>>1)*2*stride]&0xFF];
1572

  
1573
//                    put_symbol(&s->c, b->state[ABS(quant7[pri&0xFF]) + 4*ABS(quant7[sec&0xFF]) + 8], ABS(v)-1, 0);
1574
                    put_symbol(&s->c, b->state[quant13[(ABS(pri) + ABS(sec))&0x7F] + 8], ABS(v)-1, 0);
1575
                    
1576
//                    context= quant3b[sec&0xFF] + 3*quant3b[pri&0xFF];
1577
//                    put_cabac(&s->c, &b->state[7][ABS(context)], (v^context)<0);
1578
                    put_cabac(&s->c, &b->state[7][1 + 3 + quant3b[sec&0xFF] + 3*quant3b[pri&0xFF]], v<0);
1579
                    last_run=run;
1580
                    last_v=v;
1581

  
1582
                    run=0;
1583
                }else{
1584
                    run++;
1585
                }
1586
            }
1587
        }
1588
        if(run){
1589
            put_symbol(&s->c, b->state[ABS(quant7[last_v&0xFF])], run, 0);
1590
        }
1591
        return;
1592
    }
1593
    
1594
    {
1595
        int run=0;
1596
        int mode=1;
1597
        for(y=0; y<h; y++){
1598
            for(x=0; x<w; x++){
1599
    //            int context=5*11*11 + 5*11+5;
1600
                int context=3*7 + 3 + 1;
1601
                int v= src[x + y*stride];
1602
                
1603
                if(mode){
1604
                    if(v){
1605
                        put_symbol(&s->c, b->state[0], run, 0);                
1606
                        mode=0;
1607
                        run=0;
1608
                    }else{
1609
                        run++;
1610
                        continue;
1611
                    }
1612
                }
1613
                if(x /*&& orientation!=1*/)      context +=      quant7[src[x-1 + y*stride       ]&0xFF];
1614
                if(y /*&& orientation!=2*/)      context +=    7*quant7[src[x   + y*stride-stride]&0xFF];
1615
                
1616
    //            if(x>1)    context += 11*11*quant3 [src[x-2 + y*stride       ]&0xFF];
1617
    //            if(parent) context += 11*11*quant3[parent[(x>>1) + (y>>1)*2*stride]&0xFF];
1618
    
1619
                put_symbol(&s->c, b->state[context], v, 1);
1620
                if(v==0){
1621
                    mode=1;
1622
                }
1623
            }
1624
        }
1625
        if(mode && run)
1626
            put_symbol(&s->c, b->state[0], run, 0);                
1627
    }
1628 1504
}
1629 1505

  
1630
static inline void decode_subbandX(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){
1506
static inline void decode_subband(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){
1631 1507
    const int level= b->level;
1632 1508
    const int w= b->width;
1633 1509
    const int h= b->height;
......
1636 1512
    START_TIMER
1637 1513
    
1638 1514
    if(1){
1639
        int w,h;
1640 1515
        int run;
1641
        int last_run;
1642 1516
                
1643 1517
        for(y=0; y<b->height; y++)
1644 1518
            memset(&src[y*stride], 0, b->width*sizeof(DWTELEM));
1645 1519

  
1646
        if(orientation==1){
1647
            w= b->height;
1648
            h= b->width;
1649
        }else{
1650
            w= b->width;
1651
            h= b->height;
1652
        }
1653
        x=y=0;
1654 1520
        run= get_symbol(&s->c, b->state[1], 0);
1655 1521
        for(y=0; y<h; y++){
1656 1522
            for(x=0; x<w; x++){
......
1658 1524
                int /*ll=0, */l=0, lt=0, t=0, rt=0;
1659 1525

  
1660 1526
                if(y){
1661
                    if(orientation==1) t= src[y - 1 + x*stride];
1662
                    else               t= src[x + (y-1)*stride];
1527
                    t= src[x + (y-1)*stride];
1663 1528
                    if(x){
1664
                        if(orientation==1) lt= src[y - 1 + (x-1)*stride];
1665
                        else               lt= src[x - 1 + (y-1)*stride];
1529
                        lt= src[x - 1 + (y-1)*stride];
1666 1530
                    }
1667 1531
                    if(x + 1 < w){
1668
                        if(orientation==1) rt= src[y - 1 + (x+1)*stride];
1669
                        else               rt= src[x + 1 + (y-1)*stride];
1532
                        rt= src[x + 1 + (y-1)*stride];
1670 1533
                    }
1671 1534
                }
1672 1535
                if(x){
1673
                    if(orientation==1) l= src[y + (x-1)*stride];
1674
                    else               l= src[x - 1 + y*stride];
1536
                    l= src[x - 1 + y*stride];
1675 1537
                    /*if(x > 1){
1676 1538
                        if(orientation==1) ll= src[y + (x-2)*stride];
1677 1539
                        else               ll= src[x - 2 + y*stride];
1678 1540
                    }*/
1679 1541
                }
1680 1542
                if(parent){
1681
                    int px= (orientation==1 ? y : x)>>1;
1682
                    int py= (orientation==1 ? x : y)>>1;
1543
                    int px= x>>1;
1544
                    int py= y>>1;
1683 1545
                    if(px<b->parent->width && py<b->parent->height) 
1684 1546
                        p= parent[px + py*2*stride];
1685 1547
                }
......
1703 1565
                    v= get_symbol(&s->c, b->state[context + 2], 0) + 1;
1704 1566
                    if(get_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]]))
1705 1567
                        v= -v;
1706
                    if(orientation==1) src[y + x*stride]= v;
1707
                    else               src[x + y*stride]= v;
1568
                    src[x + y*stride]= v;
1708 1569
                }
1709 1570
            }
1710 1571
        }
......
1714 1575
        
1715 1576
        return;
1716 1577
    }
1717
    if(1){
1718
        int w,h;
1719
        int last_run=0;
1720
        int last_v=1;
1721
                
1722
        for(y=0; y<b->height; y++)
1723
            memset(&src[y*stride], 0, b->width*sizeof(DWTELEM));
1724

  
1725
        if(orientation==1){
1726
            w= b->height;
1727
            h= b->width;
1728
        }else{
1729
            w= b->width;
1730
            h= b->height;
1731
        }
1732
        x=y=0;
1733
        for(;;){
1734
            int sec=0, pri=0/*, lt=0, rt=0, pri2=0*/;
1735
                    
1736
            last_run= get_symbol(&s->c, b->state[ABS(quant7[last_v&0xFF])], 0);
1737

  
1738
//            context= 3*7 + 3 + quant7[last_v&0xFF]/* + 7*quant7[(last_run-1)&0xFF]*/;
1739
            x += last_run;
1740
            while(x>=w){
1741
                x-= w;
1742
                if(++y>=h) break;
1743
/*                if(orientation!=1)
1744
                    memset(&src[y*stride], 0, w*sizeof(DWTELEM));*/
1745
            }
1746
            if(y>=h) break;
1747
            if(y){
1748
                if(orientation==1) sec= src[y - 1 + x*stride];
1749
                else               sec= src[x + (y-1)*stride];
1750
/*                if(x){
1751
                    if(orientation==1) lt= src[y - 1 + (x-1)*stride];
1752
                    else               lt= src[x - 1 + (y-1)*stride];
1753
                }*/
1754
            }
1755
/*            if      (orientation==1 && y + 1 < h && x) rt= src[y + 1 + (x-1)*stride];
1756
            else if (orientation!=1 && x + 1 < w && y) rt= src[x + 1 + (y-1)*stride];*/
1757
            if(x){
1758
                if(orientation==1) pri= src[y + (x-1)*stride];
1759
                else               pri= src[x - 1 + y*stride];
1760
/*                if(x > 1){
1761
                    if(orientation==1) pri2= src[y + (x-2)*stride];
1762
                    else               pri2= src[x - 2 + y*stride];
1763
                }*/
1764
            }
1765

  
1766
            last_v= get_symbol(&s->c, b->state[quant13[(ABS(pri) + ABS(sec))&0x7F] + 8], 0) + 1;
1767
            if(get_cabac(&s->c, &b->state[7][1 + 3 + quant3b[sec&0xFF] + 3*quant3b[pri&0xFF]])) 
1768
                last_v= -last_v;
1769
            
1770
            if(orientation==1) src[y + x*stride]= last_v;
1771
            else               src[x + y*stride]= last_v;
1772

  
1773
            if(++x==w){
1774
                x=0;
1775
                if(++y>=h) break;
1776
/*                if(orientation!=1)
1777
                    memset(&src[y*stride], 0, w*sizeof(DWTELEM));*/
1778
            }
1779
        }
1780
        
1781
        if(level+1 == s->spatial_decomposition_count){
1782
            STOP_TIMER("decode_subband")
1783
        }
1784
        
1785
        return;
1786
    }
1787
}
1788

  
1789
static void decode_subband(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){
1790
    if(orientation==1) decode_subbandX(s, b, src, parent, stride, 1);
1791
    else               decode_subbandX(s, b, src, parent, stride, 0);
1792 1578
}
1793 1579

  
1794 1580
static void reset_contexts(SnowContext *s){

Also available in: Unified diff