comparison postproc/postprocess.c @ 3032:6de073cf52b5

oops, too much cleanup ;)
author michael
date Tue, 20 Nov 2001 18:07:13 +0000
parents 86e1a0f4f0bc
children 3fc9a8b9f178
comparison
equal deleted inserted replaced
3031:86e1a0f4f0bc 3032:6de073cf52b5
857 } 857 }
858 */ 858 */
859 #endif 859 #endif
860 } 860 }
861 861
862 /**
863 * Experimental Filter 1 (Horizontal)
864 * will not damage linear gradients
865 * Flat blocks should look like they where passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter
866 * can only smooth blocks at the expected locations (it cant smooth them if they did move)
867 * MMX2 version does correct clipping C version doesnt
868 * not identical with the vertical one
869 */
870 static inline void horizX1Filter(uint8_t *src, int stride, int QP)
871 {
872 int y;
873 //FIXME (has little in common with the mmx2 version)
874 for(y=0; y<BLOCK_SIZE; y++)
875 {
876 int a= src[1] - src[2];
877 int b= src[3] - src[4];
878 int c= src[5] - src[6];
879
880 int d= MAX(ABS(b) - (ABS(a) + ABS(c))/2, 0);
881
882 if(d < QP)
883 {
884 int v = d * SIGN(-b);
885
886 src[1] +=v/8;
887 src[2] +=v/4;
888 src[3] +=3*v/8;
889 src[4] -=3*v/8;
890 src[5] -=v/4;
891 src[6] -=v/8;
892
893 }
894 src+=stride;
895 }
896 }
897
898
862 static inline void doVertDefFilter(uint8_t src[], int stride, int QP) 899 static inline void doVertDefFilter(uint8_t src[], int stride, int QP)
863 { 900 {
864 #if defined (HAVE_MMX2) || defined (HAVE_3DNOW) 901 #if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
865 /* 902 /*
866 uint8_t tmp[16]; 903 uint8_t tmp[16];
1435 } 1472 }
1436 src++; 1473 src++;
1437 } 1474 }
1438 #endif 1475 #endif
1439 } 1476 }
1477
1478 /**
1479 * Check if the given 8x8 Block is mostly "flat"
1480 */
1481 static inline int isHorizDC(uint8_t src[], int stride)
1482 {
1483 int numEq= 0;
1484 int y;
1485 for(y=0; y<BLOCK_SIZE; y++)
1486 {
1487 if(((src[0] - src[1] + 1) & 0xFFFF) < 3) numEq++;
1488 if(((src[1] - src[2] + 1) & 0xFFFF) < 3) numEq++;
1489 if(((src[2] - src[3] + 1) & 0xFFFF) < 3) numEq++;
1490 if(((src[3] - src[4] + 1) & 0xFFFF) < 3) numEq++;
1491 if(((src[4] - src[5] + 1) & 0xFFFF) < 3) numEq++;
1492 if(((src[5] - src[6] + 1) & 0xFFFF) < 3) numEq++;
1493 if(((src[6] - src[7] + 1) & 0xFFFF) < 3) numEq++;
1494 src+= stride;
1495 }
1496 return numEq > hFlatnessThreshold;
1497 }
1498
1499 static inline int isHorizMinMaxOk(uint8_t src[], int stride, int QP)
1500 {
1501 if(abs(src[0] - src[7]) > 2*QP) return 0;
1502
1503 return 1;
1504 }
1505
1506 static inline void doHorizDefFilter(uint8_t dst[], int stride, int QP)
1507 {
1508 int y;
1509 for(y=0; y<BLOCK_SIZE; y++)
1510 {
1511 const int middleEnergy= 5*(dst[4] - dst[5]) + 2*(dst[2] - dst[5]);
1512
1513 if(ABS(middleEnergy) < 8*QP)
1514 {
1515 const int q=(dst[3] - dst[4])/2;
1516 const int leftEnergy= 5*(dst[2] - dst[1]) + 2*(dst[0] - dst[3]);
1517 const int rightEnergy= 5*(dst[6] - dst[5]) + 2*(dst[4] - dst[7]);
1518
1519 int d= ABS(middleEnergy) - MIN( ABS(leftEnergy), ABS(rightEnergy) );
1520 d= MAX(d, 0);
1521
1522 d= (5*d + 32) >> 6;
1523 d*= SIGN(-middleEnergy);
1524
1525 if(q>0)
1526 {
1527 d= d<0 ? 0 : d;
1528 d= d>q ? q : d;
1529 }
1530 else
1531 {
1532 d= d>0 ? 0 : d;
1533 d= d<q ? q : d;
1534 }
1535
1536 dst[3]-= d;
1537 dst[4]+= d;
1538 }
1539 dst+= stride;
1540 }
1541 }
1542
1543 /**
1544 * Do a horizontal low pass filter on the 10x8 block (dst points to middle 8x8 Block)
1545 * using the 9-Tap Filter (1,1,2,2,4,2,2,1,1)/16 (C version)
1546 */
1547 static inline void doHorizLowPass(uint8_t dst[], int stride, int QP)
1548 {
1549
1550 int y;
1551 for(y=0; y<BLOCK_SIZE; y++)
1552 {
1553 const int first= ABS(dst[-1] - dst[0]) < QP ? dst[-1] : dst[0];
1554 const int last= ABS(dst[8] - dst[7]) < QP ? dst[8] : dst[7];
1555
1556 int sums[9];
1557 sums[0] = first + dst[0];
1558 sums[1] = dst[0] + dst[1];
1559 sums[2] = dst[1] + dst[2];
1560 sums[3] = dst[2] + dst[3];
1561 sums[4] = dst[3] + dst[4];
1562 sums[5] = dst[4] + dst[5];
1563 sums[6] = dst[5] + dst[6];
1564 sums[7] = dst[6] + dst[7];
1565 sums[8] = dst[7] + last;
1566
1567 dst[0]= ((sums[0]<<2) + ((first + sums[2])<<1) + sums[4] + 8)>>4;
1568 dst[1]= ((dst[1]<<2) + ((first + sums[0] + sums[3])<<1) + sums[5] + 8)>>4;
1569 dst[2]= ((dst[2]<<2) + ((first + sums[1] + sums[4])<<1) + sums[6] + 8)>>4;
1570 dst[3]= ((dst[3]<<2) + ((sums[2] + sums[5])<<1) + sums[0] + sums[7] + 8)>>4;
1571 dst[4]= ((dst[4]<<2) + ((sums[3] + sums[6])<<1) + sums[1] + sums[8] + 8)>>4;
1572 dst[5]= ((dst[5]<<2) + ((last + sums[7] + sums[4])<<1) + sums[2] + 8)>>4;
1573 dst[6]= (((last + dst[6])<<2) + ((dst[7] + sums[5])<<1) + sums[3] + 8)>>4;
1574 dst[7]= ((sums[8]<<2) + ((last + sums[6])<<1) + sums[4] + 8)>>4;
1575
1576 dst+= stride;
1577 }
1578 }
1579
1440 1580
1441 static inline void dering(uint8_t src[], int stride, int QP) 1581 static inline void dering(uint8_t src[], int stride, int QP)
1442 { 1582 {
1443 #if defined (HAVE_MMX2) || defined (HAVE_3DNOW) 1583 #if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
1444 asm volatile( 1584 asm volatile(