Mercurial > libavcodec.hg
comparison h264.c @ 8216:018299720403 libavcodec
Move encoder-specific quantize_c and related tables to the H.264 encoder.
author | diego |
---|---|
date | Wed, 26 Nov 2008 10:22:55 +0000 |
parents | 5f399949a6a6 |
children | 0df3402e6b41 |
comparison
equal
deleted
inserted
replaced
8215:a8ce4cbc3283 | 8216:018299720403 |
---|---|
1583 /** | 1583 /** |
1584 * gets the chroma qp. | 1584 * gets the chroma qp. |
1585 */ | 1585 */ |
1586 static inline int get_chroma_qp(H264Context *h, int t, int qscale){ | 1586 static inline int get_chroma_qp(H264Context *h, int t, int qscale){ |
1587 return h->pps.chroma_qp_table[t][qscale]; | 1587 return h->pps.chroma_qp_table[t][qscale]; |
1588 } | |
1589 | |
1590 //FIXME need to check that this does not overflow signed 32 bit for low qp, I am not sure, it's very close | |
1591 //FIXME check that gcc inlines this (and optimizes intra & separate_dc stuff away) | |
1592 static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int separate_dc){ | |
1593 int i; | |
1594 const int * const quant_table= quant_coeff[qscale]; | |
1595 const int bias= intra ? (1<<QUANT_SHIFT)/3 : (1<<QUANT_SHIFT)/6; | |
1596 const unsigned int threshold1= (1<<QUANT_SHIFT) - bias - 1; | |
1597 const unsigned int threshold2= (threshold1<<1); | |
1598 int last_non_zero; | |
1599 | |
1600 if(separate_dc){ | |
1601 if(qscale<=18){ | |
1602 //avoid overflows | |
1603 const int dc_bias= intra ? (1<<(QUANT_SHIFT-2))/3 : (1<<(QUANT_SHIFT-2))/6; | |
1604 const unsigned int dc_threshold1= (1<<(QUANT_SHIFT-2)) - dc_bias - 1; | |
1605 const unsigned int dc_threshold2= (dc_threshold1<<1); | |
1606 | |
1607 int level= block[0]*quant_coeff[qscale+18][0]; | |
1608 if(((unsigned)(level+dc_threshold1))>dc_threshold2){ | |
1609 if(level>0){ | |
1610 level= (dc_bias + level)>>(QUANT_SHIFT-2); | |
1611 block[0]= level; | |
1612 }else{ | |
1613 level= (dc_bias - level)>>(QUANT_SHIFT-2); | |
1614 block[0]= -level; | |
1615 } | |
1616 // last_non_zero = i; | |
1617 }else{ | |
1618 block[0]=0; | |
1619 } | |
1620 }else{ | |
1621 const int dc_bias= intra ? (1<<(QUANT_SHIFT+1))/3 : (1<<(QUANT_SHIFT+1))/6; | |
1622 const unsigned int dc_threshold1= (1<<(QUANT_SHIFT+1)) - dc_bias - 1; | |
1623 const unsigned int dc_threshold2= (dc_threshold1<<1); | |
1624 | |
1625 int level= block[0]*quant_table[0]; | |
1626 if(((unsigned)(level+dc_threshold1))>dc_threshold2){ | |
1627 if(level>0){ | |
1628 level= (dc_bias + level)>>(QUANT_SHIFT+1); | |
1629 block[0]= level; | |
1630 }else{ | |
1631 level= (dc_bias - level)>>(QUANT_SHIFT+1); | |
1632 block[0]= -level; | |
1633 } | |
1634 // last_non_zero = i; | |
1635 }else{ | |
1636 block[0]=0; | |
1637 } | |
1638 } | |
1639 last_non_zero= 0; | |
1640 i=1; | |
1641 }else{ | |
1642 last_non_zero= -1; | |
1643 i=0; | |
1644 } | |
1645 | |
1646 for(; i<16; i++){ | |
1647 const int j= scantable[i]; | |
1648 int level= block[j]*quant_table[j]; | |
1649 | |
1650 // if( bias+level >= (1<<(QMAT_SHIFT - 3)) | |
1651 // || bias-level >= (1<<(QMAT_SHIFT - 3))){ | |
1652 if(((unsigned)(level+threshold1))>threshold2){ | |
1653 if(level>0){ | |
1654 level= (bias + level)>>QUANT_SHIFT; | |
1655 block[j]= level; | |
1656 }else{ | |
1657 level= (bias - level)>>QUANT_SHIFT; | |
1658 block[j]= -level; | |
1659 } | |
1660 last_non_zero = i; | |
1661 }else{ | |
1662 block[j]=0; | |
1663 } | |
1664 } | |
1665 | |
1666 return last_non_zero; | |
1667 } | 1588 } |
1668 | 1589 |
1669 static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, int chroma_height, int delta, int list, | 1590 static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, int chroma_height, int delta, int list, |
1670 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | 1591 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
1671 int src_x_offset, int src_y_offset, | 1592 int src_x_offset, int src_y_offset, |