comparison snow.c @ 2198:970c2de19b2e libavcodec

cleanup
author michael
date Sat, 28 Aug 2004 14:24:48 +0000
parents ffa4fa6bebe9
children e0b08bdf565d
comparison
equal deleted inserted replaced
2197:ffa4fa6bebe9 2198:970c2de19b2e
914 b1[i] += (b0[i] + b2[i] + 2)>>2; 914 b1[i] += (b0[i] + b2[i] + 2)>>2;
915 } 915 }
916 } 916 }
917 917
918 static void spatial_decompose53i(int *buffer, int width, int height, int stride){ 918 static void spatial_decompose53i(int *buffer, int width, int height, int stride){
919 int x, y; 919 int y;
920 DWTELEM *b0= buffer + mirror(-2-1, height-1)*stride; 920 DWTELEM *b0= buffer + mirror(-2-1, height-1)*stride;
921 DWTELEM *b1= buffer + mirror(-2 , height-1)*stride; 921 DWTELEM *b1= buffer + mirror(-2 , height-1)*stride;
922 922
923 for(y=-2; y<height; y+=2){ 923 for(y=-2; y<height; y+=2){
924 DWTELEM *b2= buffer + mirror(y+1, height-1)*stride; 924 DWTELEM *b2= buffer + mirror(y+1, height-1)*stride;
1057 b1[i] += (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS; 1057 b1[i] += (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS;
1058 } 1058 }
1059 } 1059 }
1060 1060
1061 static void spatial_decompose97i(int *buffer, int width, int height, int stride){ 1061 static void spatial_decompose97i(int *buffer, int width, int height, int stride){
1062 int x, y; 1062 int y;
1063 DWTELEM *b0= buffer + mirror(-4-1, height-1)*stride; 1063 DWTELEM *b0= buffer + mirror(-4-1, height-1)*stride;
1064 DWTELEM *b1= buffer + mirror(-4 , height-1)*stride; 1064 DWTELEM *b1= buffer + mirror(-4 , height-1)*stride;
1065 DWTELEM *b2= buffer + mirror(-4+1, height-1)*stride; 1065 DWTELEM *b2= buffer + mirror(-4+1, height-1)*stride;
1066 DWTELEM *b3= buffer + mirror(-4+2, height-1)*stride; 1066 DWTELEM *b3= buffer + mirror(-4+2, height-1)*stride;
1067 1067
1166 b1[i] -= (b0[i] + b2[i] + 2)>>2; 1166 b1[i] -= (b0[i] + b2[i] + 2)>>2;
1167 } 1167 }
1168 } 1168 }
1169 1169
1170 static void spatial_compose53i(int *buffer, int width, int height, int stride){ 1170 static void spatial_compose53i(int *buffer, int width, int height, int stride){
1171 int x, y; 1171 int y;
1172 DWTELEM *b0= buffer + mirror(-1-1, height-1)*stride; 1172 DWTELEM *b0= buffer + mirror(-1-1, height-1)*stride;
1173 DWTELEM *b1= buffer + mirror(-1 , height-1)*stride; 1173 DWTELEM *b1= buffer + mirror(-1 , height-1)*stride;
1174 1174
1175 for(y=-1; y<=height; y+=2){ 1175 for(y=-1; y<=height; y+=2){
1176 DWTELEM *b2= buffer + mirror(y+1, height-1)*stride; 1176 DWTELEM *b2= buffer + mirror(y+1, height-1)*stride;
1240 b1[i] -= (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS; 1240 b1[i] -= (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS;
1241 } 1241 }
1242 } 1242 }
1243 1243
1244 static void spatial_compose97i(int *buffer, int width, int height, int stride){ 1244 static void spatial_compose97i(int *buffer, int width, int height, int stride){
1245 int x, y; 1245 int y;
1246 DWTELEM *b0= buffer + mirror(-3-1, height-1)*stride; 1246 DWTELEM *b0= buffer + mirror(-3-1, height-1)*stride;
1247 DWTELEM *b1= buffer + mirror(-3 , height-1)*stride; 1247 DWTELEM *b1= buffer + mirror(-3 , height-1)*stride;
1248 DWTELEM *b2= buffer + mirror(-3+1, height-1)*stride; 1248 DWTELEM *b2= buffer + mirror(-3+1, height-1)*stride;
1249 DWTELEM *b3= buffer + mirror(-3+2, height-1)*stride; 1249 DWTELEM *b3= buffer + mirror(-3+2, height-1)*stride;
1250 1250
1291 case 2: spatial_composeX (buffer, width>>level, height>>level, stride<<level); break; 1291 case 2: spatial_composeX (buffer, width>>level, height>>level, stride<<level); break;
1292 } 1292 }
1293 } 1293 }
1294 } 1294 }
1295 1295
1296 static const int hilbert[16][2]={
1297 {0,0}, {1,0}, {1,1}, {0,1},
1298 {0,2}, {0,3}, {1,3}, {1,2},
1299 {2,2}, {2,3}, {3,3}, {3,2},
1300 {3,1}, {2,1}, {2,0}, {3,0},
1301 };
1302 #if 0
1303 -o o-
1304 | |
1305 o-o
1306
1307 -o-o o-o-
1308 | |
1309 o-o o-o
1310 | |
1311 o o-o o
1312 | | | |
1313 o-o o-o
1314
1315 0112122312232334122323342334
1316 0123456789ABCDEF0123456789AB
1317 RLLRMRRLLRRMRLLMLRRLMLLRRLLM
1318
1319 4 B F 14 1B
1320 4 11 15 20 27
1321
1322 -o o-o-o o-o-o o-
1323 | | | | | |
1324 o-o o-o o-o o-o
1325 | |
1326 o-o o-o o-o o-o
1327 | | | | | |
1328 o o-o-o o-o-o o
1329 | |
1330 o-o o-o-o-o o-o
1331 | | | |
1332 o-o o-o o-o o-o
1333 | | | |
1334 o o-o o o o-o o
1335 | | | | | | | |
1336 o-o o-o o-o o-o
1337
1338 #endif
1339
1340 #define SVI(a, i, x, y) \
1341 {\
1342 a[i][0]= x;\
1343 a[i][1]= y;\
1344 i++;\
1345 }
1346
1347 static int sig_cmp(const void *a, const void *b){
1348 const int16_t* da = (const int16_t *) a;
1349 const int16_t* db = (const int16_t *) b;
1350
1351 if(da[1] != db[1]) return da[1] - db[1];
1352 else return da[0] - db[0];
1353 }
1354
1355 static int deint(unsigned int a){
1356 a &= 0x55555555; //0 1 2 3 4 5 6 7 8 9 A B C D E F
1357 a += a & 0x11111111; // 01 23 45 67 89 AB CD EF
1358 a += 3*(a & 0x0F0F0F0F);// 0123 4567 89AB CDEF
1359 a += 15*(a & 0x00FF00FF);// 01234567 89ABCDEF
1360 a +=255*(a & 0x0000FFFF);// 0123456789ABCDEF
1361 return a>>15;
1362 }
1363
1364 static void encode_subband_z0run(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){
1365 const int level= b->level;
1366 const int w= b->width;
1367 const int h= b->height;
1368 int x, y, pos;
1369
1370 if(1){
1371 int run=0;
1372 int runs[w*h];
1373 int run_index=0;
1374 int count=0;
1375
1376 for(pos=0; ; pos++){
1377 int x= deint(pos );
1378 int y= deint(pos>>1);
1379 int v, p=0, pr=0, pd=0;
1380 int /*ll=0, */l=0, lt=0, t=0/*, rt=0*/;
1381
1382 if(x>=w || y>=h){
1383 if(x>=w && y>=h)
1384 break;
1385 continue;
1386 }
1387 count++;
1388
1389 v= src[x + y*stride];
1390
1391 if(y){
1392 t= src[x + (y-1)*stride];
1393 if(x){
1394 lt= src[x - 1 + (y-1)*stride];
1395 }
1396 if(x + 1 < w){
1397 /*rt= src[x + 1 + (y-1)*stride]*/;
1398 }
1399 }
1400 if(x){
1401 l= src[x - 1 + y*stride];
1402 /*if(x > 1){
1403 if(orientation==1) ll= src[y + (x-2)*stride];
1404 else ll= src[x - 2 + y*stride];
1405 }*/
1406 }
1407 if(parent){
1408 int px= x>>1;
1409 int py= y>>1;
1410 if(px<b->parent->width && py<b->parent->height){
1411 p= parent[px + py*2*stride];
1412 /*if(px+1<b->parent->width)
1413 pr= parent[px + 1 + py*2*stride];
1414 if(py+1<b->parent->height)
1415 pd= parent[px + (py+1)*2*stride];*/
1416 }
1417 }
1418 if(!(/*ll|*/l|lt|t|/*rt|*/p)){
1419 if(v){
1420 runs[run_index++]= run;
1421 run=0;
1422 }else{
1423 run++;
1424 }
1425 }
1426 }
1427 assert(count==w*h);
1428 runs[run_index++]= run;
1429 run_index=0;
1430 run= runs[run_index++];
1431
1432 put_symbol(&s->c, b->state[1], run, 0);
1433
1434 for(pos=0; ; pos++){
1435 int x= deint(pos );
1436 int y= deint(pos>>1);
1437 int v, p=0, pr=0, pd=0;
1438 int /*ll=0, */l=0, lt=0, t=0/*, rt=0*/;
1439
1440 if(x>=w || y>=h){
1441 if(x>=w && y>=h)
1442 break;
1443 continue;
1444 }
1445 v= src[x + y*stride];
1446
1447 if(y){
1448 t= src[x + (y-1)*stride];
1449 if(x){
1450 lt= src[x - 1 + (y-1)*stride];
1451 }
1452 if(x + 1 < w){
1453 // rt= src[x + 1 + (y-1)*stride];
1454 }
1455 }
1456 if(x){
1457 l= src[x - 1 + y*stride];
1458 /*if(x > 1){
1459 if(orientation==1) ll= src[y + (x-2)*stride];
1460 else ll= src[x - 2 + y*stride];
1461 }*/
1462 }
1463
1464 if(parent){
1465 int px= x>>1;
1466 int py= y>>1;
1467 if(px<b->parent->width && py<b->parent->height){
1468 p= parent[px + py*2*stride];
1469 /* if(px+1<b->parent->width)
1470 pr= parent[px + 1 + py*2*stride];
1471 if(py+1<b->parent->height)
1472 pd= parent[px + (py+1)*2*stride];*/
1473 }
1474 }
1475 if(/*ll|*/l|lt|t|/*rt|*/p){
1476 int context= av_log2(/*ABS(ll) + */2*(3*ABS(l) + ABS(lt) + 2*ABS(t) + /*ABS(rt) +*/ ABS(p)));
1477
1478 put_cabac(&s->c, &b->state[0][context], !!v);
1479 }else{
1480 if(!run){
1481 run= runs[run_index++];
1482 put_symbol(&s->c, b->state[1], run, 0);
1483 assert(v);
1484 }else{
1485 run--;
1486 assert(!v);
1487 }
1488 }
1489 if(v){
1490 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + /*ABS(rt) +*/ ABS(p));
1491
1492 put_symbol(&s->c, b->state[context + 2], ABS(v)-1, 0);
1493 put_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]], v<0);
1494 }
1495 }
1496 }
1497 }
1498
1499 static void encode_subband_bp(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){
1500 const int level= b->level;
1501 const int w= b->width;
1502 const int h= b->height;
1503 int x, y;
1504
1505 #if 0
1506 int plane;
1507 for(plane=24; plane>=0; plane--){
1508 int run=0;
1509 int runs[w*h];
1510 int run_index=0;
1511
1512 for(y=0; y<h; y++){
1513 for(x=0; x<w; x++){
1514 int v, lv, p=0;
1515 int d=0, r=0, rd=0, ld=0;
1516 int /*ll=0, */l=0, lt=0, t=0, rt=0;
1517 v= src[x + y*stride];
1518
1519 if(y){
1520 t= src[x + (y-1)*stride];
1521 if(x){
1522 lt= src[x - 1 + (y-1)*stride];
1523 }
1524 if(x + 1 < w){
1525 rt= src[x + 1 + (y-1)*stride];
1526 }
1527 }
1528 if(x){
1529 l= src[x - 1 + y*stride];
1530 /*if(x > 1){
1531 if(orientation==1) ll= src[y + (x-2)*stride];
1532 else ll= src[x - 2 + y*stride];
1533 }*/
1534 }
1535 if(y+1<h){
1536 d= src[x + (y+1)*stride];
1537 if(x) ld= src[x - 1 + (y+1)*stride];
1538 if(x + 1 < w) rd= src[x + 1 + (y+1)*stride];
1539 }
1540 if(x + 1 < w)
1541 r= src[x + 1 + y*stride];
1542 if(parent){
1543 int px= x>>1;
1544 int py= y>>1;
1545 if(px<b->parent->width && py<b->parent->height)
1546 p= parent[px + py*2*stride];
1547 }
1548 #define HIDE(c, plane) c= c>=0 ? c&((-1)<<(plane)) : -((-c)&((-1)<<(plane)));
1549 lv=v;
1550 HIDE( v, plane)
1551 HIDE(lv, plane+1)
1552 HIDE( p, plane)
1553 HIDE( l, plane)
1554 HIDE(lt, plane)
1555 HIDE( t, plane)
1556 HIDE(rt, plane)
1557 HIDE( r, plane+1)
1558 HIDE(rd, plane+1)
1559 HIDE( d, plane+1)
1560 HIDE(ld, plane+1)
1561 if(!(/*ll|*/l|lt|t|rt|r|rd|ld|d|p|lv)){
1562 if(v){
1563 runs[run_index++]= run;
1564 run=0;
1565 }else{
1566 run++;
1567 }
1568 }
1569 }
1570 }
1571 runs[run_index++]= run;
1572 run_index=0;
1573 run= runs[run_index++];
1574
1575 put_symbol(&s->c, b->state[1], run, 0);
1576
1577 for(y=0; y<h; y++){
1578 for(x=0; x<w; x++){
1579 int v, p=0, lv;
1580 int /*ll=0, */l=0, lt=0, t=0, rt=0;
1581 int d=0, r=0, rd=0, ld=0;
1582 v= src[x + y*stride];
1583
1584 if(y){
1585 t= src[x + (y-1)*stride];
1586 if(x){
1587 lt= src[x - 1 + (y-1)*stride];
1588 }
1589 if(x + 1 < w){
1590 rt= src[x + 1 + (y-1)*stride];
1591 }
1592 }
1593 if(x){
1594 l= src[x - 1 + y*stride];
1595 /*if(x > 1){
1596 if(orientation==1) ll= src[y + (x-2)*stride];
1597 else ll= src[x - 2 + y*stride];
1598 }*/
1599 }
1600 if(y+1<h){
1601 d= src[x + (y+1)*stride];
1602 if(x) ld= src[x - 1 + (y+1)*stride];
1603 if(x + 1 < w) rd= src[x + 1 + (y+1)*stride];
1604 }
1605 if(x + 1 < w)
1606 r= src[x + 1 + y*stride];
1607
1608 if(parent){
1609 int px= x>>1;
1610 int py= y>>1;
1611 if(px<b->parent->width && py<b->parent->height)
1612 p= parent[px + py*2*stride];
1613 }
1614 lv=v;
1615 HIDE( v, plane)
1616 HIDE(lv, plane+1)
1617 HIDE( p, plane)
1618 HIDE( l, plane)
1619 HIDE(lt, plane)
1620 HIDE( t, plane)
1621 HIDE(rt, plane)
1622 HIDE( r, plane+1)
1623 HIDE(rd, plane+1)
1624 HIDE( d, plane+1)
1625 HIDE(ld, plane+1)
1626 if(/*ll|*/l|lt|t|rt|r|rd|ld|d|p|lv){
1627 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p)
1628 +3*ABS(r) + ABS(rd) + 2*ABS(d) + ABS(ld));
1629
1630 if(lv) put_cabac(&s->c, &b->state[99][context + 8*(av_log2(ABS(lv))-plane)], !!(v-lv));
1631 else put_cabac(&s->c, &b->state[ 0][context], !!v);
1632 }else{
1633 assert(!lv);
1634 if(!run){
1635 run= runs[run_index++];
1636 put_symbol(&s->c, b->state[1], run, 0);
1637 assert(v);
1638 }else{
1639 run--;
1640 assert(!v);
1641 }
1642 }
1643 if(v && !lv){
1644 int context= clip(quant3b[l&0xFF] + quant3b[r&0xFF], -1,1)
1645 + 3*clip(quant3b[t&0xFF] + quant3b[d&0xFF], -1,1);
1646 put_cabac(&s->c, &b->state[0][16 + 1 + 3 + context], v<0);
1647 }
1648 }
1649 }
1650 }
1651 return;
1652 #endif
1653 }
1654
1655 static void encode_subband_X(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){
1656 const int level= b->level;
1657 const int w= b->width;
1658 const int h= b->height;
1659 int x, y;
1660
1661 #if 0
1662 if(orientation==3 && parent && 0){
1663 int16_t candidate[w*h][2];
1664 uint8_t state[w*h];
1665 int16_t boarder[3][w*h*4][2];
1666 int16_t significant[w*h][2];
1667 int candidate_count=0;
1668 int boarder_count[3]={0,0,0};
1669 int significant_count=0;
1670 int rle_pos=0;
1671 int v, last_v;
1672 int primary= orientation==1;
1673
1674 memset(candidate, 0, sizeof(candidate));
1675 memset(state, 0, sizeof(state));
1676 memset(boarder, 0, sizeof(boarder));
1677
1678 for(y=0; y<h; y++){
1679 for(x=0; x<w; x++){
1680 if(parent[(x>>1) + (y>>1)*2*stride])
1681 SVI(candidate, candidate_count, x, y)
1682 }
1683 }
1684
1685 for(;;){
1686 while(candidate_count && !boarder_count[0] && !boarder_count[1] && !boarder_count[2]){
1687 candidate_count--;
1688 x= candidate[ candidate_count][0];
1689 y= candidate[ candidate_count][1];
1690 if(state[x + y*w])
1691 continue;
1692 state[x + y*w]= 1;
1693 v= !!src[x + y*stride];
1694 put_cabac(&s->c, &b->state[0][0], v);
1695 if(v){
1696 SVI(significant, significant_count, x,y)
1697 if(x && !state[x - 1 + y *w]) SVI(boarder[0],boarder_count[0],x-1,y )
1698 if(y && !state[x + (y-1)*w]) SVI(boarder[1],boarder_count[1],x ,y-1)
1699 if(x+1<w && !state[x + 1 + y *w]) SVI(boarder[0],boarder_count[0],x+1,y )
1700 if(y+1<h && !state[x + (y+1)*w]) SVI(boarder[1],boarder_count[1],x ,y+1)
1701 if(x && y && !state[x - 1 + (y-1)*w]) SVI(boarder[2],boarder_count[2],x-1,y-1)
1702 if(x && y+1<h && !state[x - 1 + (y+1)*w]) SVI(boarder[2],boarder_count[2],x-1,y+1)
1703 if(x+1<w && y+1<h && !state[x + 1 + (y+1)*w]) SVI(boarder[2],boarder_count[2],x+1,y+1)
1704 if(x+1<w && y && !state[x + 1 + (y-1)*w]) SVI(boarder[2],boarder_count[2],x+1,y-1)
1705 }
1706 }
1707 while(!boarder_count[0] && !boarder_count[1] && !boarder_count[2] && rle_pos < w*h){
1708 int run=0;
1709 for(; rle_pos < w*h;){
1710 x= rle_pos % w; //FIXME speed
1711 y= rle_pos / w;
1712 rle_pos++;
1713 if(state[x + y*w])
1714 continue;
1715 state[x + y*w]= 1;
1716 v= !!src[x + y*stride];
1717 if(v){
1718 put_symbol(&s->c, b->state[1], run, 0);
1719 SVI(significant, significant_count, x,y)
1720 if(x && !state[x - 1 + y *w]) SVI(boarder[0],boarder_count[0],x-1,y )
1721 if(y && !state[x + (y-1)*w]) SVI(boarder[1],boarder_count[1],x ,y-1)
1722 if(x+1<w && !state[x + 1 + y *w]) SVI(boarder[0],boarder_count[0],x+1,y )
1723 if(y+1<h && !state[x + (y+1)*w]) SVI(boarder[1],boarder_count[1],x ,y+1)
1724 if(x && y && !state[x - 1 + (y-1)*w]) SVI(boarder[2],boarder_count[2],x-1,y-1)
1725 if(x && y+1<h && !state[x - 1 + (y+1)*w]) SVI(boarder[2],boarder_count[2],x-1,y+1)
1726 if(x+1<w && y+1<h && !state[x + 1 + (y+1)*w]) SVI(boarder[2],boarder_count[2],x+1,y+1)
1727 if(x+1<w && y && !state[x + 1 + (y-1)*w]) SVI(boarder[2],boarder_count[2],x+1,y-1)
1728 break;
1729 //FIXME note only right & down can be boarders
1730 }
1731 run++;
1732 }
1733 }
1734 if(!boarder_count[0] && !boarder_count[1] && !boarder_count[2])
1735 break;
1736
1737 while(boarder_count[0] || boarder_count[1] || boarder_count[2]){
1738 int index;
1739
1740 if (boarder_count[ primary]) index= primary;
1741 else if(boarder_count[1-primary]) index=1-primary;
1742 else index=2;
1743
1744 boarder_count[index]--;
1745 x= boarder[index][ boarder_count[index] ][0];
1746 y= boarder[index][ boarder_count[index] ][1];
1747 if(state[x + y*w]) //FIXME maybe check earlier
1748 continue;
1749 state[x + y*w]= 1;
1750 v= !!src[x + y*stride];
1751 put_cabac(&s->c, &b->state[0][index+1], v);
1752 if(v){
1753 SVI(significant, significant_count, x,y)
1754 if(x && !state[x - 1 + y *w]) SVI(boarder[0],boarder_count[0],x-1,y )
1755 if(y && !state[x + (y-1)*w]) SVI(boarder[1],boarder_count[1],x ,y-1)
1756 if(x+1<w && !state[x + 1 + y *w]) SVI(boarder[0],boarder_count[0],x+1,y )
1757 if(y+1<h && !state[x + (y+1)*w]) SVI(boarder[1],boarder_count[1],x ,y+1)
1758 if(x && y && !state[x - 1 + (y-1)*w]) SVI(boarder[2],boarder_count[2],x-1,y-1)
1759 if(x && y+1<h && !state[x - 1 + (y+1)*w]) SVI(boarder[2],boarder_count[2],x-1,y+1)
1760 if(x+1<w && y+1<h && !state[x + 1 + (y+1)*w]) SVI(boarder[2],boarder_count[2],x+1,y+1)
1761 if(x+1<w && y && !state[x + 1 + (y-1)*w]) SVI(boarder[2],boarder_count[2],x+1,y-1)
1762 }
1763 }
1764 }
1765 //FIXME sort significant coeffs maybe
1766 if(1){
1767 qsort(significant, significant_count, sizeof(int16_t[2]), sig_cmp);
1768 }
1769
1770 last_v=1;
1771 while(significant_count){
1772 int context= 3 + quant7[last_v&0xFF]; //use significance of suroundings
1773 significant_count--;
1774 x= significant[significant_count][0];//FIXME try opposit direction
1775 y= significant[significant_count][1];
1776 v= src[x + y*stride];
1777 put_symbol(&s->c, b->state[context + 2], v, 1); //FIXME try to avoid first bit, try this with the old code too!!
1778 last_v= v;
1779 }
1780 }
1781 #endif
1782 }
1783
1784 static void encode_subband_c0run(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){ 1296 static void encode_subband_c0run(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){
1785 const int level= b->level;
1786 const int w= b->width; 1297 const int w= b->width;
1787 const int h= b->height; 1298 const int h= b->height;
1788 int x, y; 1299 int x, y;
1789 1300
1790 if(1){ 1301 if(1){
1896 encode_subband_c0run(s, b, src, parent, stride, orientation); 1407 encode_subband_c0run(s, b, src, parent, stride, orientation);
1897 // encode_subband_dzr(s, b, src, parent, stride, orientation); 1408 // encode_subband_dzr(s, b, src, parent, stride, orientation);
1898 } 1409 }
1899 1410
1900 static inline void decode_subband(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){ 1411 static inline void decode_subband(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){
1901 const int level= b->level;
1902 const int w= b->width; 1412 const int w= b->width;
1903 const int h= b->height; 1413 const int h= b->height;
1904 int x,y; 1414 int x,y;
1905 const int qlog= clip(s->qlog + b->qlog, 0, 128); 1415 const int qlog= clip(s->qlog + b->qlog, 0, 128);
1906 int qmul= qexp[qlog&7]<<(qlog>>3); 1416 int qmul= qexp[qlog&7]<<(qlog>>3);
2340 } 1850 }
2341 } 1851 }
2342 1852
2343 static void decode_q_branch(SnowContext *s, int level, int x, int y){ 1853 static void decode_q_branch(SnowContext *s, int level, int x, int y){
2344 const int w= s->b_width << s->block_max_depth; 1854 const int w= s->b_width << s->block_max_depth;
2345 const int h= s->b_height<< s->block_max_depth;
2346 const int rem_depth= s->block_max_depth - level; 1855 const int rem_depth= s->block_max_depth - level;
2347 const int index= (x + y*w) << rem_depth; 1856 const int index= (x + y*w) << rem_depth;
2348 static BlockNode null_block= { //FIXME add border maybe 1857 static BlockNode null_block= { //FIXME add border maybe
2349 .color= {128,128,128}, 1858 .color= {128,128,128},
2350 .mx= 0, 1859 .mx= 0,
2351 .my= 0, 1860 .my= 0,
2352 .type= 0, 1861 .type= 0,
2353 .level= 0, 1862 .level= 0,
2354 }; 1863 };
2355 int trx= (x+1)<<rem_depth; 1864 int trx= (x+1)<<rem_depth;
2356 int try= (y+1)<<rem_depth;
2357 BlockNode *left = x ? &s->block[index-1] : &null_block; 1865 BlockNode *left = x ? &s->block[index-1] : &null_block;
2358 BlockNode *top = y ? &s->block[index-w] : &null_block; 1866 BlockNode *top = y ? &s->block[index-w] : &null_block;
2359 BlockNode *tl = y && x ? &s->block[index-w-1] : left; 1867 BlockNode *tl = y && x ? &s->block[index-w-1] : left;
2360 BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt 1868 BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt
2361 int s_context= 2*left->level + 2*top->level + tl->level + tr->level; 1869 int s_context= 2*left->level + 2*top->level + tl->level + tr->level;
2674 // STOP_TIMER("quantize") 2182 // STOP_TIMER("quantize")
2675 } 2183 }
2676 } 2184 }
2677 2185
2678 static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){ 2186 static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){
2679 const int level= b->level;
2680 const int w= b->width; 2187 const int w= b->width;
2681 const int h= b->height; 2188 const int h= b->height;
2682 const int qlog= clip(s->qlog + b->qlog, 0, 128); 2189 const int qlog= clip(s->qlog + b->qlog, 0, 128);
2683 const int qmul= qexp[qlog&7]<<(qlog>>3); 2190 const int qmul= qexp[qlog&7]<<(qlog>>3);
2684 const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; 2191 const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT;
2935 2442
2936 2443
2937 static void calculate_vissual_weight(SnowContext *s, Plane *p){ 2444 static void calculate_vissual_weight(SnowContext *s, Plane *p){
2938 int width = p->width; 2445 int width = p->width;
2939 int height= p->height; 2446 int height= p->height;
2940 int i, level, orientation, x, y; 2447 int level, orientation, x, y;
2941 2448
2942 for(level=0; level<s->spatial_decomposition_count; level++){ 2449 for(level=0; level<s->spatial_decomposition_count; level++){
2943 for(orientation=level ? 1 : 0; orientation<4; orientation++){ 2450 for(orientation=level ? 1 : 0; orientation<4; orientation++){
2944 SubBand *b= &p->band[level][orientation]; 2451 SubBand *b= &p->band[level][orientation];
2945 DWTELEM *buf= b->buf; 2452 DWTELEM *buf= b->buf;
2962 } 2469 }
2963 2470
2964 static int encode_init(AVCodecContext *avctx) 2471 static int encode_init(AVCodecContext *avctx)
2965 { 2472 {
2966 SnowContext *s = avctx->priv_data; 2473 SnowContext *s = avctx->priv_data;
2967 int i; 2474 int plane_index;
2968 int level, orientation, plane_index;
2969 2475
2970 if(avctx->strict_std_compliance >= 0){ 2476 if(avctx->strict_std_compliance >= 0){
2971 av_log(avctx, AV_LOG_ERROR, "this codec is under development, files encoded with it wont be decodeable with future versions!!!\n" 2477 av_log(avctx, AV_LOG_ERROR, "this codec is under development, files encoded with it wont be decodeable with future versions!!!\n"
2972 "use vstrict=-1 to use it anyway\n"); 2478 "use vstrict=-1 to use it anyway\n");
2973 return -1; 2479 return -1;
3042 SnowContext *s = avctx->priv_data; 2548 SnowContext *s = avctx->priv_data;
3043 CABACContext * const c= &s->c; 2549 CABACContext * const c= &s->c;
3044 AVFrame *pict = data; 2550 AVFrame *pict = data;
3045 const int width= s->avctx->width; 2551 const int width= s->avctx->width;
3046 const int height= s->avctx->height; 2552 const int height= s->avctx->height;
3047 int used_count= 0; 2553 int level, orientation, plane_index;
3048 int log2_threshold, level, orientation, plane_index, i;
3049 2554
3050 ff_init_cabac_encoder(c, buf, buf_size); 2555 ff_init_cabac_encoder(c, buf, buf_size);
3051 ff_init_cabac_states(c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); 2556 ff_init_cabac_states(c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64);
3052 2557
3053 s->input_picture = *pict; 2558 s->input_picture = *pict;
3069 2574
3070 if(pict->pict_type == P_TYPE){ 2575 if(pict->pict_type == P_TYPE){
3071 int block_width = (width +15)>>4; 2576 int block_width = (width +15)>>4;
3072 int block_height= (height+15)>>4; 2577 int block_height= (height+15)>>4;
3073 int stride= s->current_picture.linesize[0]; 2578 int stride= s->current_picture.linesize[0];
3074 uint8_t *src_plane= s->input_picture.data[0];
3075 int src_stride= s->input_picture.linesize[0];
3076 int x,y;
3077 2579
3078 assert(s->current_picture.data[0]); 2580 assert(s->current_picture.data[0]);
3079 assert(s->last_picture.data[0]); 2581 assert(s->last_picture.data[0]);
3080 2582
3081 s->m.avctx= s->avctx; 2583 s->m.avctx= s->avctx;
3122 for(plane_index=0; plane_index<3; plane_index++){ 2624 for(plane_index=0; plane_index<3; plane_index++){
3123 Plane *p= &s->plane[plane_index]; 2625 Plane *p= &s->plane[plane_index];
3124 int w= p->width; 2626 int w= p->width;
3125 int h= p->height; 2627 int h= p->height;
3126 int x, y; 2628 int x, y;
3127 int bits= put_bits_count(&s->c.pb); 2629 // int bits= put_bits_count(&s->c.pb);
3128 2630
3129 //FIXME optimize 2631 //FIXME optimize
3130 if(pict->data[plane_index]) //FIXME gray hack 2632 if(pict->data[plane_index]) //FIXME gray hack
3131 for(y=0; y<h; y++){ 2633 for(y=0; y<h; y++){
3132 for(x=0; x<w; x++){ 2634 for(x=0; x<w; x++){
3261 } 2763 }
3262 2764
3263 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){ 2765 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){
3264 SnowContext *s = avctx->priv_data; 2766 SnowContext *s = avctx->priv_data;
3265 CABACContext * const c= &s->c; 2767 CABACContext * const c= &s->c;
3266 const int width= s->avctx->width;
3267 const int height= s->avctx->height;
3268 int bytes_read; 2768 int bytes_read;
3269 AVFrame *picture = data; 2769 AVFrame *picture = data;
3270 int log2_threshold, level, orientation, plane_index; 2770 int level, orientation, plane_index;
3271 2771
3272 2772
3273 /* no supplementary picture */ 2773 /* no supplementary picture */
3274 if (buf_size == 0) 2774 if (buf_size == 0)
3275 return 0; 2775 return 0;