Mercurial > libavcodec.hg
comparison snow.c @ 2144:e33371c1e2b4 libavcodec
better context model (0.2-1% lower bitrate)
a tiny bit cleanup
author | michael |
---|---|
date | Tue, 27 Jul 2004 01:30:44 +0000 |
parents | 7c1d807e686d |
children | b288cdc2ad68 |
comparison
equal
deleted
inserted
replaced
2143:8eae8e652584 | 2144:e33371c1e2b4 |
---|---|
1418 } | 1418 } |
1419 | 1419 |
1420 for(y=0; y<h; y++){ | 1420 for(y=0; y<h; y++){ |
1421 for(x=0; x<w; x++){ | 1421 for(x=0; x<w; x++){ |
1422 int v, p; | 1422 int v, p; |
1423 int l=0, t=0, lt=0, rt=0/*, pri2=0*/; | 1423 int /*ll=0, */l=0, lt=0, t=0, rt=0; |
1424 if(orientation==1) v= src[y + x*stride]; | 1424 if(orientation==1) v= src[y + x*stride]; |
1425 else v= src[x + y*stride]; | 1425 else v= src[x + y*stride]; |
1426 | 1426 |
1427 if(y){ | 1427 if(y){ |
1428 if(orientation==1) t= src[y - 1 + x*stride]; | 1428 if(orientation==1) t= src[y - 1 + x*stride]; |
1437 } | 1437 } |
1438 } | 1438 } |
1439 if(x){ | 1439 if(x){ |
1440 if(orientation==1) l= src[y + (x-1)*stride]; | 1440 if(orientation==1) l= src[y + (x-1)*stride]; |
1441 else l= src[x - 1 + y*stride]; | 1441 else l= src[x - 1 + y*stride]; |
1442 /* if(x > 1){ | 1442 /*if(x > 1){ |
1443 if(orientation==1) pri2= src[y + (x-2)*stride]; | 1443 if(orientation==1) ll= src[y + (x-2)*stride]; |
1444 else pri2= src[x - 2 + y*stride]; | 1444 else ll= src[x - 2 + y*stride]; |
1445 }*/ | 1445 }*/ |
1446 } | 1446 } |
1447 if(!(lt|rt|t|l)){ | 1447 if(!(/*ll|*/l|lt|t|rt)){ |
1448 if(v){ | 1448 if(v){ |
1449 runs[run_index++]= run; | 1449 runs[run_index++]= run; |
1450 run=0; | 1450 run=0; |
1451 }else{ | 1451 }else{ |
1452 run++; | 1452 run++; |
1456 } | 1456 } |
1457 runs[run_index++]= run; | 1457 runs[run_index++]= run; |
1458 run_index=0; | 1458 run_index=0; |
1459 run= runs[run_index++]; | 1459 run= runs[run_index++]; |
1460 | 1460 |
1461 put_symbol(&s->c, b->state[1+7], run, 0); | 1461 put_symbol(&s->c, b->state[1], run, 0); |
1462 | 1462 |
1463 for(y=0; y<h; y++){ | 1463 for(y=0; y<h; y++){ |
1464 for(x=0; x<w; x++){ | 1464 for(x=0; x<w; x++){ |
1465 int v, p; | 1465 int v, p; |
1466 int l=0, t=0, lt=0, rt=0/*, pri2=0*/; | 1466 int /*ll=0, */l=0, lt=0, t=0, rt=0; |
1467 if(orientation==1) v= src[y + x*stride]; | 1467 if(orientation==1) v= src[y + x*stride]; |
1468 else v= src[x + y*stride]; | 1468 else v= src[x + y*stride]; |
1469 | 1469 |
1470 if(y){ | 1470 if(y){ |
1471 if(orientation==1) t= src[y - 1 + x*stride]; | 1471 if(orientation==1) t= src[y - 1 + x*stride]; |
1480 } | 1480 } |
1481 } | 1481 } |
1482 if(x){ | 1482 if(x){ |
1483 if(orientation==1) l= src[y + (x-1)*stride]; | 1483 if(orientation==1) l= src[y + (x-1)*stride]; |
1484 else l= src[x - 1 + y*stride]; | 1484 else l= src[x - 1 + y*stride]; |
1485 /* if(x > 1){ | 1485 /*if(x > 1){ |
1486 if(orientation==1) pri2= src[y + (x-2)*stride]; | 1486 if(orientation==1) ll= src[y + (x-2)*stride]; |
1487 else pri2= src[x - 2 + y*stride]; | 1487 else ll= src[x - 2 + y*stride]; |
1488 }*/ | 1488 }*/ |
1489 } | 1489 } |
1490 if(lt|rt|t|l){ | 1490 if(/*ll|*/l|lt|t|rt){ |
1491 put_cabac(&s->c, &b->state[0][(!l) + 2*(!t) + 4*(!lt) + 8*(!rt)], !v); | 1491 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt)); |
1492 | |
1493 put_cabac(&s->c, &b->state[0][context], !!v); | |
1492 }else{ | 1494 }else{ |
1493 if(!run){ | 1495 if(!run){ |
1494 run= runs[run_index++]; | 1496 run= runs[run_index++]; |
1495 put_symbol(&s->c, b->state[1+7], run, 0); | 1497 put_symbol(&s->c, b->state[1], run, 0); |
1496 assert(v); | 1498 assert(v); |
1497 }else{ | 1499 }else{ |
1498 run--; | 1500 run--; |
1499 assert(!v); | 1501 assert(!v); |
1500 } | 1502 } |
1501 } | 1503 } |
1502 if(v){ | 1504 if(v){ |
1503 put_symbol(&s->c, b->state[quant13[(ABS(l) + ABS(t))&0x7F] + 1], ABS(v)-1, 0); | 1505 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt)); |
1506 | |
1507 put_symbol(&s->c, b->state[context + 2], ABS(v)-1, 0); | |
1504 put_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]], v<0); | 1508 put_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]], v<0); |
1505 } | 1509 } |
1506 } | 1510 } |
1507 } | 1511 } |
1508 return; | 1512 return; |
1633 }else{ | 1637 }else{ |
1634 w= b->width; | 1638 w= b->width; |
1635 h= b->height; | 1639 h= b->height; |
1636 } | 1640 } |
1637 x=y=0; | 1641 x=y=0; |
1638 run= get_symbol(&s->c, b->state[1+7], 0); | 1642 run= get_symbol(&s->c, b->state[1], 0); |
1639 for(y=0; y<h; y++){ | 1643 for(y=0; y<h; y++){ |
1640 for(x=0; x<w; x++){ | 1644 for(x=0; x<w; x++){ |
1641 int v, p; | 1645 int v, p; |
1642 int l=0, t=0, lt=0, rt=0/*, pri2=0*/; | 1646 int /*ll=0, */l=0, lt=0, t=0, rt=0; |
1643 | 1647 |
1644 if(y){ | 1648 if(y){ |
1645 if(orientation==1) t= src[y - 1 + x*stride]; | 1649 if(orientation==1) t= src[y - 1 + x*stride]; |
1646 else t= src[x + (y-1)*stride]; | 1650 else t= src[x + (y-1)*stride]; |
1647 if(x){ | 1651 if(x){ |
1654 } | 1658 } |
1655 } | 1659 } |
1656 if(x){ | 1660 if(x){ |
1657 if(orientation==1) l= src[y + (x-1)*stride]; | 1661 if(orientation==1) l= src[y + (x-1)*stride]; |
1658 else l= src[x - 1 + y*stride]; | 1662 else l= src[x - 1 + y*stride]; |
1659 /* if(x > 1){ | 1663 /*if(x > 1){ |
1660 if(orientation==1) pri2= src[y + (x-2)*stride]; | 1664 if(orientation==1) ll= src[y + (x-2)*stride]; |
1661 else pri2= src[x - 2 + y*stride]; | 1665 else ll= src[x - 2 + y*stride]; |
1662 }*/ | 1666 }*/ |
1663 } | 1667 } |
1664 if(lt|rt|t|l){ | 1668 if(/*ll|*/l|lt|t|rt){ |
1665 v=!get_cabac(&s->c, &b->state[0][(!l) + 2*(!t) + 4*(!lt) + 8*(!rt)]); | 1669 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt)); |
1670 | |
1671 v=get_cabac(&s->c, &b->state[0][context]); | |
1666 }else{ | 1672 }else{ |
1667 if(!run){ | 1673 if(!run){ |
1668 run= get_symbol(&s->c, b->state[1+7], 0); | 1674 run= get_symbol(&s->c, b->state[1], 0); |
1669 //FIXME optimize this here | 1675 //FIXME optimize this here |
1670 //FIXME try to store a more naive run | 1676 //FIXME try to store a more naive run |
1671 v=1; | 1677 v=1; |
1672 }else{ | 1678 }else{ |
1673 run--; | 1679 run--; |
1674 v=0; | 1680 v=0; |
1675 } | 1681 } |
1676 } | 1682 } |
1677 if(v){ | 1683 if(v){ |
1678 v= get_symbol(&s->c, b->state[quant13[(ABS(l) + ABS(t))&0x7F] + 1], 0) + 1; | 1684 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt)); |
1685 v= get_symbol(&s->c, b->state[context + 2], 0) + 1; | |
1679 if(get_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]])) | 1686 if(get_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]])) |
1680 v= -v; | 1687 v= -v; |
1681 if(orientation==1) src[y + x*stride]= v; | 1688 if(orientation==1) src[y + x*stride]= v; |
1682 else src[x + y*stride]= v; | 1689 else src[x + y*stride]= v; |
1683 } | 1690 } |