📄 h264.c
字号:
const int z1= temp[4*0+i] - temp[4*2+i]; const int z2= temp[4*1+i] - temp[4*3+i]; const int z3= temp[4*1+i] + temp[4*3+i]; block[stride*0 +offset]= (z0 + z3)>>1; block[stride*2 +offset]= (z1 + z2)>>1; block[stride*8 +offset]= (z1 - z2)>>1; block[stride*10+offset]= (z0 - z3)>>1; }}#undef xStride#undef stridestatic void chroma_dc_dequant_idct_c(DCTELEM *block, int qp){ const int qmul= dequant_coeff[qp][0]; const int stride= 16*2; const int xStride= 16; int a,b,c,d,e; a= block[stride*0 + xStride*0]; b= block[stride*0 + xStride*1]; c= block[stride*1 + xStride*0]; d= block[stride*1 + xStride*1]; e= a-b; a= a+b; b= c-d; c= c+d; block[stride*0 + xStride*0]= ((a+c)*qmul + 0)>>1; block[stride*0 + xStride*1]= ((e+b)*qmul + 0)>>1; block[stride*1 + xStride*0]= ((a-c)*qmul + 0)>>1; block[stride*1 + xStride*1]= ((e-b)*qmul + 0)>>1;}static void chroma_dc_dct_c(DCTELEM *block){ const int stride= 16*2; const int xStride= 16; int a,b,c,d,e; a= block[stride*0 + xStride*0]; b= block[stride*0 + xStride*1]; c= block[stride*1 + xStride*0]; d= block[stride*1 + xStride*1]; e= a-b; a= a+b; b= c-d; c= c+d; block[stride*0 + xStride*0]= (a+c); block[stride*0 + xStride*1]= (e+b); block[stride*1 + xStride*0]= (a-c); block[stride*1 + xStride*1]= (e-b);}/** * gets the chroma qp. */static inline int get_chroma_qp(H264Context *h, int qscale){ return chroma_qp[clip(qscale + h->pps.chroma_qp_index_offset, 0, 51)];}/** * */static void h264_add_idct_c(uint8_t *dst, DCTELEM *block, int stride){ int i; uint8_t *cm = cropTbl + MAX_NEG_CROP; block[0] += 32;#if 1 for(i=0; i<4; i++){ const int z0= block[i + 4*0] + block[i + 4*2]; const int z1= block[i + 4*0] - block[i + 4*2]; const int z2= (block[i + 4*1]>>1) - block[i + 4*3]; const int z3= block[i + 4*1] + (block[i + 4*3]>>1); block[i + 4*0]= z0 + z3; block[i + 4*1]= z1 + z2; block[i + 4*2]= z1 - z2; block[i + 4*3]= z0 - z3; } for(i=0; i<4; i++){ const int z0= block[0 + 4*i] + block[2 + 4*i]; const int z1= block[0 + 4*i] - block[2 + 4*i]; const int z2= (block[1 + 4*i]>>1) - block[3 + 4*i]; const int z3= block[1 + 4*i] + (block[3 + 4*i]>>1); dst[0 + i*stride]= cm[ dst[0 + i*stride] + ((z0 + z3) >> 6) ]; dst[1 + i*stride]= cm[ dst[1 + i*stride] + ((z1 + z2) >> 6) ]; dst[2 + i*stride]= cm[ dst[2 + i*stride] + ((z1 - z2) >> 6) ]; dst[3 + i*stride]= cm[ dst[3 + i*stride] + ((z0 - z3) >> 6) ]; }#else for(i=0; i<4; i++){ const int z0= block[0 + 4*i] + block[2 + 4*i]; const int z1= block[0 + 4*i] - block[2 + 4*i]; const int z2= (block[1 + 4*i]>>1) - block[3 + 4*i]; const int z3= block[1 + 4*i] + (block[3 + 4*i]>>1); block[0 + 4*i]= z0 + z3; block[1 + 4*i]= z1 + z2; block[2 + 4*i]= z1 - z2; block[3 + 4*i]= z0 - z3; } for(i=0; i<4; i++){ const int z0= block[i + 4*0] + block[i + 4*2]; const int z1= block[i + 4*0] - block[i + 4*2]; const int z2= (block[i + 4*1]>>1) - block[i + 4*3]; const int z3= block[i + 4*1] + (block[i + 4*3]>>1); dst[i + 0*stride]= cm[ dst[i + 0*stride] + ((z0 + z3) >> 6) ]; dst[i + 1*stride]= cm[ dst[i + 1*stride] + ((z1 + z2) >> 6) ]; dst[i + 2*stride]= cm[ dst[i + 2*stride] + ((z1 - z2) >> 6) ]; dst[i + 3*stride]= cm[ dst[i + 3*stride] + ((z0 - z3) >> 6) ]; }#endif}static void h264_diff_dct_c(DCTELEM *block, uint8_t *src1, uint8_t *src2, int stride){ int i; //FIXME try int temp instead of block for(i=0; i<4; i++){ const int d0= src1[0 + i*stride] - src2[0 + i*stride]; const int d1= src1[1 + i*stride] - src2[1 + i*stride]; const int d2= src1[2 + i*stride] - src2[2 + i*stride]; const int d3= src1[3 + i*stride] - src2[3 + i*stride]; const int z0= d0 + d3; const int z3= d0 - d3; const int z1= d1 + d2; const int z2= d1 - d2; block[0 + 4*i]= z0 + z1; block[1 + 4*i]= 2*z3 + z2; block[2 + 4*i]= z0 - z1; block[3 + 4*i]= z3 - 2*z2; } for(i=0; i<4; i++){ const int z0= block[0*4 + i] + block[3*4 + i]; const int z3= block[0*4 + i] - block[3*4 + i]; const int z1= block[1*4 + i] + block[2*4 + i]; const int z2= block[1*4 + i] - block[2*4 + i]; block[0*4 + i]= z0 + z1; block[1*4 + i]= 2*z3 + z2; block[2*4 + i]= z0 - z1; block[3*4 + i]= z3 - 2*z2; }}//FIXME need to check that this doesnt overflow signed 32 bit for low qp, iam not sure, its very close//FIXME check that gcc inlines this (and optimizes intra & seperate_dc stuff away)static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int seperate_dc){ int i; const int * const quant_table= quant_coeff[qscale]; const int bias= intra ? (1<<QUANT_SHIFT)/3 : (1<<QUANT_SHIFT)/6; const unsigned int threshold1= (1<<QUANT_SHIFT) - bias - 1; const unsigned int threshold2= (threshold1<<1); int last_non_zero; if(seperate_dc){ if(qscale<=18){ //avoid overflows const int dc_bias= intra ? (1<<(QUANT_SHIFT-2))/3 : (1<<(QUANT_SHIFT-2))/6; const unsigned int dc_threshold1= (1<<(QUANT_SHIFT-2)) - dc_bias - 1; const unsigned int dc_threshold2= (dc_threshold1<<1); int level= block[0]*quant_coeff[qscale+18][0]; if(((unsigned)(level+dc_threshold1))>dc_threshold2){ if(level>0){ level= (dc_bias + level)>>(QUANT_SHIFT-2); block[0]= level; }else{ level= (dc_bias - level)>>(QUANT_SHIFT-2); block[0]= -level; }// last_non_zero = i; }else{ block[0]=0; } }else{ const int dc_bias= intra ? (1<<(QUANT_SHIFT+1))/3 : (1<<(QUANT_SHIFT+1))/6; const unsigned int dc_threshold1= (1<<(QUANT_SHIFT+1)) - dc_bias - 1; const unsigned int dc_threshold2= (dc_threshold1<<1); int level= block[0]*quant_table[0]; if(((unsigned)(level+dc_threshold1))>dc_threshold2){ if(level>0){ level= (dc_bias + level)>>(QUANT_SHIFT+1); block[0]= level; }else{ level= (dc_bias - level)>>(QUANT_SHIFT+1); block[0]= -level; }// last_non_zero = i; }else{ block[0]=0; } } last_non_zero= 0; i=1; }else{ last_non_zero= -1; i=0; } for(; i<16; i++){ const int j= scantable[i]; int level= block[j]*quant_table[j];// if( bias+level >= (1<<(QMAT_SHIFT - 3))// || bias-level >= (1<<(QMAT_SHIFT - 3))){ if(((unsigned)(level+threshold1))>threshold2){ if(level>0){ level= (bias + level)>>QUANT_SHIFT; block[j]= level; }else{ level= (bias - level)>>QUANT_SHIFT; block[j]= -level; } last_non_zero = i; }else{ block[j]=0; } } return last_non_zero;}static void pred4x4_vertical_c(uint8_t *src, uint8_t *topright, int stride){ const uint32_t a= ((uint32_t*)(src-stride))[0]; ((uint32_t*)(src+0*stride))[0]= a; ((uint32_t*)(src+1*stride))[0]= a; ((uint32_t*)(src+2*stride))[0]= a; ((uint32_t*)(src+3*stride))[0]= a;}static void pred4x4_horizontal_c(uint8_t *src, uint8_t *topright, int stride){ ((uint32_t*)(src+0*stride))[0]= src[-1+0*stride]*0x01010101; ((uint32_t*)(src+1*stride))[0]= src[-1+1*stride]*0x01010101; ((uint32_t*)(src+2*stride))[0]= src[-1+2*stride]*0x01010101; ((uint32_t*)(src+3*stride))[0]= src[-1+3*stride]*0x01010101;}static void pred4x4_dc_c(uint8_t *src, uint8_t *topright, int stride){ const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3; ((uint32_t*)(src+0*stride))[0]= ((uint32_t*)(src+1*stride))[0]= ((uint32_t*)(src+2*stride))[0]= ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; }static void pred4x4_left_dc_c(uint8_t *src, uint8_t *topright, int stride){ const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2; ((uint32_t*)(src+0*stride))[0]= ((uint32_t*)(src+1*stride))[0]= ((uint32_t*)(src+2*stride))[0]= ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; }static void pred4x4_top_dc_c(uint8_t *src, uint8_t *topright, int stride){ const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2; ((uint32_t*)(src+0*stride))[0]= ((uint32_t*)(src+1*stride))[0]= ((uint32_t*)(src+2*stride))[0]= ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; }static void pred4x4_128_dc_c(uint8_t *src, uint8_t *topright, int stride){ ((uint32_t*)(src+0*stride))[0]= ((uint32_t*)(src+1*stride))[0]= ((uint32_t*)(src+2*stride))[0]= ((uint32_t*)(src+3*stride))[0]= 128U*0x01010101U;}#define LOAD_TOP_RIGHT_EDGE\ const int t4= topright[0];\ const int t5= topright[1];\ const int t6= topright[2];\ const int t7= topright[3];\#define LOAD_LEFT_EDGE\ const int l0= src[-1+0*stride];\ const int l1= src[-1+1*stride];\ const int l2= src[-1+2*stride];\ const int l3= src[-1+3*stride];\#define LOAD_TOP_EDGE\ const int t0= src[ 0-1*stride];\ const int t1= src[ 1-1*stride];\ const int t2= src[ 2-1*stride];\ const int t3= src[ 3-1*stride];\static void pred4x4_down_right_c(uint8_t *src, uint8_t *topright, int stride){ const int lt= src[-1-1*stride]; LOAD_TOP_EDGE LOAD_LEFT_EDGE src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2; src[0+2*stride]= src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2; src[0+1*stride]= src[1+2*stride]= src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2; src[0+0*stride]= src[1+1*stride]= src[2+2*stride]= src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2; src[1+0*stride]= src[2+1*stride]= src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2; src[2+0*stride]= src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2;}static void pred4x4_down_left_c(uint8_t *src, uint8_t *topright, int stride){ LOAD_TOP_EDGE LOAD_TOP_RIGHT_EDGE // LOAD_LEFT_EDGE src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2; src[1+0*stride]= src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2; src[2+0*stride]= src[1+1*stride]= src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2; src[3+0*stride]= src[2+1*stride]= src[1+2*stride]= src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2; src[3+1*stride]= src[2+2*stride]= src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2; src[3+2*stride]= src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2; src[3+3*stride]=(t6 + 3*t7 + 2)>>2;}static void pred4x4_vertical_right_c(uint8_t *src, uint8_t *topright, int stride){ const int lt= src[-1-1*stride]; LOAD_TOP_EDGE LOAD_LEFT_EDGE const __attribute__((unused)) int unu= l3; src[0+0*stride]= src[1+2*stride]=(lt + t0 + 1)>>1; src[1+0*stride]= src[2+2*stride]=(t0 + t1 + 1)>>1; src[2+0*stride]= src[3+2*stride]=(t1 + t2 + 1)>>1; src[3+0*stride]=(t2 + t3 + 1)>>1; src[0+1*stride]= src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2; src[1+1*stride]= src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2; src[2+1*stride]= src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2; src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2; src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2; src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;}static void pred4x4_vertical_left_c(uint8_t *src, uint8_t *topright, int stride){ LOAD_TOP_EDGE LOAD_TOP_RIGHT_EDGE const __attribute__((unused)) int unu= t7; src[0+0*stride]=(t0 + t1 + 1)>>1; src[1+0*stride]= src[0+2*stride]=(t1 + t2 + 1)>>1; src[2+0*stride]= src[1+2*stride]=(t2 + t3 + 1)>>1; src[3+0*stride]= src[2+2*stride]=(t3 + t4+ 1)>>1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -