📄 mc.c.svn-base
字号:
uint8_t *src1 = src[hpel_ref0[qpel_idx]] + offset + ((mvy&3) == 3) * i_src_stride; if( qpel_idx & 5 ) /* qpel interpolation needed */ { uint8_t *src2 = src[hpel_ref1[qpel_idx]] + offset + ((mvx&3) == 3); pixel_avg( dst, *i_dst_stride, src1, i_src_stride, src2, i_src_stride, i_width, i_height ); return dst; } else { *i_dst_stride = i_src_stride; return src1; }}/* full chroma mc (ie until 1/8 pixel)*/static void motion_compensation_chroma( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int mvx, int mvy, int i_width, int i_height ){ uint8_t *srcp; int x, y; const int d8x = mvx&0x07; const int d8y = mvy&0x07; const int cA = (8-d8x)*(8-d8y); const int cB = d8x *(8-d8y); const int cC = (8-d8x)*d8y; const int cD = d8x *d8y; src += (mvy >> 3) * i_src_stride + (mvx >> 3); srcp = &src[i_src_stride]; for( y = 0; y < i_height; y++ ) { for( x = 0; x < i_width; x++ ) { dst[x] = ( cA*src[x] + cB*src[x+1] + cC*srcp[x] + cD*srcp[x+1] + 32 ) >> 6; } dst += i_dst_stride; src = srcp; srcp += i_src_stride; }}#define MC_COPY(W) \static void mc_copy_w##W( uint8_t *dst, int i_dst, uint8_t *src, int i_src, int i_height ) \{ \ mc_copy( src, i_src, dst, i_dst, W, i_height ); \}MC_COPY( 16 )MC_COPY( 8 )MC_COPY( 4 )static void plane_copy( uint8_t *dst, int i_dst, uint8_t *src, int i_src, int w, int h){ while( h-- ) { memcpy( dst, src, w ); dst += i_dst; src += i_src; }}void prefetch_fenc_null( uint8_t *pix_y, int stride_y, uint8_t *pix_uv, int stride_uv, int mb_x ){}void prefetch_ref_null( uint8_t *pix, int stride, int parity ){}void x264_mc_init( int cpu, x264_mc_functions_t *pf ){ pf->mc_luma = mc_luma; pf->get_ref = get_ref; pf->mc_chroma = motion_compensation_chroma; pf->avg[PIXEL_16x16]= pixel_avg_16x16; pf->avg[PIXEL_16x8] = pixel_avg_16x8; pf->avg[PIXEL_8x16] = pixel_avg_8x16; pf->avg[PIXEL_8x8] = pixel_avg_8x8; pf->avg[PIXEL_8x4] = pixel_avg_8x4; pf->avg[PIXEL_4x8] = pixel_avg_4x8; pf->avg[PIXEL_4x4] = pixel_avg_4x4; pf->avg[PIXEL_4x2] = pixel_avg_4x2; pf->avg[PIXEL_2x4] = pixel_avg_2x4; pf->avg[PIXEL_2x2] = pixel_avg_2x2; pf->avg_weight[PIXEL_16x16]= pixel_avg_weight_16x16; pf->avg_weight[PIXEL_16x8] = pixel_avg_weight_16x8; pf->avg_weight[PIXEL_8x16] = pixel_avg_weight_8x16; pf->avg_weight[PIXEL_8x8] = pixel_avg_weight_8x8; pf->avg_weight[PIXEL_8x4] = pixel_avg_weight_8x4; pf->avg_weight[PIXEL_4x8] = pixel_avg_weight_4x8; pf->avg_weight[PIXEL_4x4] = pixel_avg_weight_4x4; pf->avg_weight[PIXEL_4x2] = pixel_avg_weight_4x2; pf->avg_weight[PIXEL_2x4] = pixel_avg_weight_2x4; pf->avg_weight[PIXEL_2x2] = pixel_avg_weight_2x2; pf->copy[PIXEL_16x16] = mc_copy_w16; pf->copy[PIXEL_8x8] = mc_copy_w8; pf->copy[PIXEL_4x4] = mc_copy_w4; pf->plane_copy = plane_copy; pf->prefetch_fenc = prefetch_fenc_null; pf->prefetch_ref = prefetch_ref_null;#ifdef HAVE_MMX if( cpu&X264_CPU_MMXEXT ) { x264_mc_mmxext_init( pf ); pf->mc_chroma = x264_mc_chroma_mmxext; } if( cpu&X264_CPU_SSE2 ) x264_mc_sse2_init( pf );#endif#ifdef ARCH_PPC if( cpu&X264_CPU_ALTIVEC ) x264_mc_altivec_init( pf );#endif}extern void x264_hpel_filter_mmxext( uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint8_t *src, int i_stride, int i_width, int i_height );void x264_frame_filter( int cpu, x264_frame_t *frame, int b_interlaced, int mb_y, int b_end ){ const int x_inc = 16, y_inc = 16; const int stride = frame->i_stride[0] << b_interlaced; int start = (mb_y*16 >> b_interlaced) - 8; int height = ((b_end ? frame->i_lines[0] : mb_y*16) >> b_interlaced) + 8; int x, y; if( mb_y & b_interlaced ) return; mb_y >>= b_interlaced;#ifdef HAVE_MMX if ( cpu & X264_CPU_MMXEXT ) { // buffer = 4 for deblock + 3 for 6tap, rounded to 8 int offs = start*stride - 8; x264_hpel_filter_mmxext( frame->filtered[1] + offs, frame->filtered[2] + offs, frame->filtered[3] + offs, frame->plane[0] + offs, stride, stride - 48, height - start ); } else#endif { for( y = start; y < height; y += y_inc ) { uint8_t *p_in = frame->plane[0] + y * stride - 8; uint8_t *p_h = frame->filtered[1] + y * stride - 8; uint8_t *p_v = frame->filtered[2] + y * stride - 8; uint8_t *p_c = frame->filtered[3] + y * stride - 8; for( x = -8; x < stride - 64 + 8; x += x_inc ) { mc_hh( p_in, stride, p_h, stride, x_inc, y_inc ); mc_hv( p_in, stride, p_v, stride, x_inc, y_inc ); mc_hc( p_in, stride, p_c, stride, x_inc, y_inc ); p_h += x_inc; p_v += x_inc; p_c += x_inc; p_in += x_inc; } } } /* generate integral image: * frame->integral contains 2 planes. in the upper plane, each element is * the sum of an 8x8 pixel region with top-left corner on that point. * in the lower plane, 4x4 sums (needed only with --partitions p4x4). */ if( frame->integral ) { if( start < 0 ) { memset( frame->integral - 32 * stride - 32, 0, stride * sizeof(uint16_t) ); start = -32; } if( b_end ) height += 24; for( y = start; y < height; y++ ) { uint8_t *ref = frame->plane[0] + y * stride - 32; uint16_t *line = frame->integral + (y+1) * stride - 31; uint16_t v = line[0] = 0; for( x = 0; x < stride-1; x++ ) line[x] = v += ref[x] + line[x-stride] - line[x-stride-1]; line -= 8*stride; if( y >= 8-31 ) { uint16_t *sum4 = line + frame->i_stride[0] * (frame->i_lines[0] + 64); for( x = 1; x < stride-8; x++, line++, sum4++ ) { sum4[0] = line[4+4*stride] - line[4] - line[4*stride] + line[0]; line[0] += line[8+8*stride] - line[8] - line[8*stride]; } } } }}void x264_frame_init_lowres( int cpu, x264_frame_t *frame ){ // FIXME: tapfilter? const int i_stride = frame->i_stride[0]; const int i_stride2 = frame->i_stride_lowres; const int i_width2 = i_stride2 - 64; int x, y, i; for( y = 0; y < frame->i_lines_lowres - 1; y++ ) { uint8_t *src0 = &frame->plane[0][2*y*i_stride]; uint8_t *src1 = src0+i_stride; uint8_t *src2 = src1+i_stride; uint8_t *dst0 = &frame->lowres[0][y*i_stride2]; uint8_t *dsth = &frame->lowres[1][y*i_stride2]; uint8_t *dstv = &frame->lowres[2][y*i_stride2]; uint8_t *dstc = &frame->lowres[3][y*i_stride2]; for( x = 0; x < i_width2 - 1; x++ ) { dst0[x] = (src0[2*x ] + src0[2*x+1] + src1[2*x ] + src1[2*x+1] + 2) >> 2; dsth[x] = (src0[2*x+1] + src0[2*x+2] + src1[2*x+1] + src1[2*x+2] + 2) >> 2; dstv[x] = (src1[2*x ] + src1[2*x+1] + src2[2*x ] + src2[2*x+1] + 2) >> 2; dstc[x] = (src1[2*x+1] + src1[2*x+2] + src2[2*x+1] + src2[2*x+2] + 2) >> 2; } dst0[x] = (src0[2*x ] + src0[2*x+1] + src1[2*x ] + src1[2*x+1] + 2) >> 2; dstv[x] = (src1[2*x ] + src1[2*x+1] + src2[2*x ] + src2[2*x+1] + 2) >> 2; dsth[x] = (src0[2*x+1] + src1[2*x+1] + 1) >> 1; dstc[x] = (src1[2*x+1] + src2[2*x+1] + 1) >> 1; } for( i = 0; i < 4; i++ ) memcpy( &frame->lowres[i][y*i_stride2], &frame->lowres[i][(y-1)*i_stride2], i_width2 ); for( y = 0; y < 16; y++ ) for( x = 0; x < 16; x++ ) frame->i_cost_est[x][y] = -1; x264_frame_expand_border_lowres( frame );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -