Mercurial > libavcodec.hg
comparison snow.c @ 2148:678be5a8f282 libavcodec
use parent sample to predict significance & magnitude
1% bitrate reduction (foreman@352x288 qscale 1 & 8)
author | michael |
---|---|
date | Tue, 27 Jul 2004 13:40:16 +0000 |
parents | b288cdc2ad68 |
children | 48dc4ec06e88 |
comparison
equal
deleted
inserted
replaced
2147:f980082baeaa | 2148:678be5a8f282 |
---|---|
1417 h= b->height; | 1417 h= b->height; |
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=0; |
1423 int /*ll=0, */l=0, lt=0, t=0, rt=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){ |
1442 /*if(x > 1){ | 1442 /*if(x > 1){ |
1443 if(orientation==1) ll= src[y + (x-2)*stride]; | 1443 if(orientation==1) ll= src[y + (x-2)*stride]; |
1444 else ll= src[x - 2 + y*stride]; | 1444 else ll= src[x - 2 + y*stride]; |
1445 }*/ | 1445 }*/ |
1446 } | 1446 } |
1447 if(!(/*ll|*/l|lt|t|rt)){ | 1447 if(parent){ |
1448 int px= (orientation==1 ? y : x)>>1; | |
1449 int py= (orientation==1 ? x : y)>>1; | |
1450 if(px<b->parent->width && py<b->parent->height) | |
1451 p= parent[px + py*2*stride]; | |
1452 } | |
1453 if(!(/*ll|*/l|lt|t|rt|p)){ | |
1448 if(v){ | 1454 if(v){ |
1449 runs[run_index++]= run; | 1455 runs[run_index++]= run; |
1450 run=0; | 1456 run=0; |
1451 }else{ | 1457 }else{ |
1452 run++; | 1458 run++; |
1460 | 1466 |
1461 put_symbol(&s->c, b->state[1], run, 0); | 1467 put_symbol(&s->c, b->state[1], run, 0); |
1462 | 1468 |
1463 for(y=0; y<h; y++){ | 1469 for(y=0; y<h; y++){ |
1464 for(x=0; x<w; x++){ | 1470 for(x=0; x<w; x++){ |
1465 int v, p; | 1471 int v, p=0; |
1466 int /*ll=0, */l=0, lt=0, t=0, rt=0; | 1472 int /*ll=0, */l=0, lt=0, t=0, rt=0; |
1467 if(orientation==1) v= src[y + x*stride]; | 1473 if(orientation==1) v= src[y + x*stride]; |
1468 else v= src[x + y*stride]; | 1474 else v= src[x + y*stride]; |
1469 | 1475 |
1470 if(y){ | 1476 if(y){ |
1485 /*if(x > 1){ | 1491 /*if(x > 1){ |
1486 if(orientation==1) ll= src[y + (x-2)*stride]; | 1492 if(orientation==1) ll= src[y + (x-2)*stride]; |
1487 else ll= src[x - 2 + y*stride]; | 1493 else ll= src[x - 2 + y*stride]; |
1488 }*/ | 1494 }*/ |
1489 } | 1495 } |
1490 if(/*ll|*/l|lt|t|rt){ | 1496 if(parent){ |
1491 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt)); | 1497 int px= (orientation==1 ? y : x)>>1; |
1498 int py= (orientation==1 ? x : y)>>1; | |
1499 if(px<b->parent->width && py<b->parent->height) | |
1500 p= parent[px + py*2*stride]; | |
1501 } | |
1502 if(/*ll|*/l|lt|t|rt|p){ | |
1503 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p)); | |
1492 | 1504 |
1493 put_cabac(&s->c, &b->state[0][context], !!v); | 1505 put_cabac(&s->c, &b->state[0][context], !!v); |
1494 }else{ | 1506 }else{ |
1495 if(!run){ | 1507 if(!run){ |
1496 run= runs[run_index++]; | 1508 run= runs[run_index++]; |
1500 run--; | 1512 run--; |
1501 assert(!v); | 1513 assert(!v); |
1502 } | 1514 } |
1503 } | 1515 } |
1504 if(v){ | 1516 if(v){ |
1505 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt)); | 1517 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p)); |
1506 | 1518 |
1507 put_symbol(&s->c, b->state[context + 2], ABS(v)-1, 0); | 1519 put_symbol(&s->c, b->state[context + 2], ABS(v)-1, 0); |
1508 put_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]], v<0); | 1520 put_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]], v<0); |
1509 } | 1521 } |
1510 } | 1522 } |
1640 } | 1652 } |
1641 x=y=0; | 1653 x=y=0; |
1642 run= get_symbol(&s->c, b->state[1], 0); | 1654 run= get_symbol(&s->c, b->state[1], 0); |
1643 for(y=0; y<h; y++){ | 1655 for(y=0; y<h; y++){ |
1644 for(x=0; x<w; x++){ | 1656 for(x=0; x<w; x++){ |
1645 int v, p; | 1657 int v, p=0; |
1646 int /*ll=0, */l=0, lt=0, t=0, rt=0; | 1658 int /*ll=0, */l=0, lt=0, t=0, rt=0; |
1647 | 1659 |
1648 if(y){ | 1660 if(y){ |
1649 if(orientation==1) t= src[y - 1 + x*stride]; | 1661 if(orientation==1) t= src[y - 1 + x*stride]; |
1650 else t= src[x + (y-1)*stride]; | 1662 else t= src[x + (y-1)*stride]; |
1663 /*if(x > 1){ | 1675 /*if(x > 1){ |
1664 if(orientation==1) ll= src[y + (x-2)*stride]; | 1676 if(orientation==1) ll= src[y + (x-2)*stride]; |
1665 else ll= src[x - 2 + y*stride]; | 1677 else ll= src[x - 2 + y*stride]; |
1666 }*/ | 1678 }*/ |
1667 } | 1679 } |
1668 if(/*ll|*/l|lt|t|rt){ | 1680 if(parent){ |
1669 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt)); | 1681 int px= (orientation==1 ? y : x)>>1; |
1682 int py= (orientation==1 ? x : y)>>1; | |
1683 if(px<b->parent->width && py<b->parent->height) | |
1684 p= parent[px + py*2*stride]; | |
1685 } | |
1686 if(/*ll|*/l|lt|t|rt|p){ | |
1687 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p)); | |
1670 | 1688 |
1671 v=get_cabac(&s->c, &b->state[0][context]); | 1689 v=get_cabac(&s->c, &b->state[0][context]); |
1672 }else{ | 1690 }else{ |
1673 if(!run){ | 1691 if(!run){ |
1674 run= get_symbol(&s->c, b->state[1], 0); | 1692 run= get_symbol(&s->c, b->state[1], 0); |
1679 run--; | 1697 run--; |
1680 v=0; | 1698 v=0; |
1681 } | 1699 } |
1682 } | 1700 } |
1683 if(v){ | 1701 if(v){ |
1684 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt)); | 1702 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p)); |
1685 v= get_symbol(&s->c, b->state[context + 2], 0) + 1; | 1703 v= get_symbol(&s->c, b->state[context + 2], 0) + 1; |
1686 if(get_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]])) | 1704 if(get_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]])) |
1687 v= -v; | 1705 v= -v; |
1688 if(orientation==1) src[y + x*stride]= v; | 1706 if(orientation==1) src[y + x*stride]= v; |
1689 else src[x + y*stride]= v; | 1707 else src[x + y*stride]= v; |