?? mc.c
字號:
/***************************************************************************** * mc.c: h264 encoder library (Motion Compensation) ***************************************************************************** * Copyright (C) 2003 Laurent Aimar * $Id: mc.c,v 1.1 2004/06/03 19:27:07 fenrir Exp $ * * Authors: Laurent Aimar <fenrir@via.ecp.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/#include <stdio.h>#include <string.h>#include "include\common.h"#include "include\clip1.h"
#ifdef ARCH_PPC#include "ppc/mc.h"#endifstatic inline int x264_tapfilter( uint8_t *pix, int i_pix_next ){ return pix[-2*i_pix_next] - 5*pix[-1*i_pix_next] + 20*(pix[0] + pix[1*i_pix_next]) - 5*pix[ 2*i_pix_next] + pix[ 3*i_pix_next];}static inline int x264_tapfilter1( uint8_t *pix ){ return pix[-2] - 5*pix[-1] + 20*(pix[0] + pix[1]) - 5*pix[ 2] + pix[ 3];}static inline void pixel_avg( uint8_t *dst, int i_dst_stride, uint8_t *src1, int i_src1_stride, uint8_t *src2, int i_src2_stride, int i_width, int i_height ){ int x, y; for( y = 0; y < i_height; y++ ) { for( x = 0; x < i_width; x++ ) { dst[x] = ( src1[x] + src2[x] + 1 ) >> 1; } dst += i_dst_stride; src1 += i_src1_stride; src2 += i_src2_stride; }}static inline void pixel_avg_wxh( uint8_t *dst, int i_dst, uint8_t *src, int i_src, int width, int height ){ int x, y; for( y = 0; y < height; y++ ) { for( x = 0; x < width; x++ ) { dst[x] = ( dst[x] + src[x] + 1 ) >> 1; } dst += i_dst; src += i_src; }}#define PIXEL_AVG_C( name, width, height ) \static void name( uint8_t *pix1, int i_stride_pix1, \ uint8_t *pix2, int i_stride_pix2 ) \{ \ pixel_avg_wxh( pix1, i_stride_pix1, pix2, i_stride_pix2, width, height ); \}PIXEL_AVG_C( pixel_avg_16x16, 16, 16 )PIXEL_AVG_C( pixel_avg_16x8, 16, 8 )PIXEL_AVG_C( pixel_avg_8x16, 8, 16 )PIXEL_AVG_C( pixel_avg_8x8, 8, 8 )PIXEL_AVG_C( pixel_avg_8x4, 8, 4 )PIXEL_AVG_C( pixel_avg_4x8, 4, 8 )PIXEL_AVG_C( pixel_avg_4x4, 4, 4 )PIXEL_AVG_C( pixel_avg_4x2, 4, 2 )PIXEL_AVG_C( pixel_avg_2x4, 2, 4 )PIXEL_AVG_C( pixel_avg_2x2, 2, 2 )/* Implicit weighted bipred only: * assumes log2_denom = 5, offset = 0, weight1 + weight2 = 64 */#define op_scale2(x) dst[x] = x264_clip_uint8( (dst[x]*i_weight1 + src[x]*i_weight2 + (1<<5)) >> 6 )static inline void pixel_avg_weight_wxh( uint8_t *dst, int i_dst, uint8_t *src, int i_src, int width, int height, int i_weight1 ){ int y; const int i_weight2 = 64 - i_weight1; for(y=0; y<height; y++, dst += i_dst, src += i_src){ op_scale2(0); op_scale2(1); if(width==2) continue; op_scale2(2); op_scale2(3); if(width==4) continue; op_scale2(4); op_scale2(5); op_scale2(6); op_scale2(7); if(width==8) continue; op_scale2(8); op_scale2(9); op_scale2(10); op_scale2(11); op_scale2(12); op_scale2(13); op_scale2(14); op_scale2(15); }}#define PIXEL_AVG_WEIGHT_C( width, height ) \static void pixel_avg_weight_##width##x##height( \ uint8_t *pix1, int i_stride_pix1, \ uint8_t *pix2, int i_stride_pix2, int i_weight1 ) \{ \ pixel_avg_weight_wxh( pix1, i_stride_pix1, pix2, i_stride_pix2, width, height, i_weight1 ); \}PIXEL_AVG_WEIGHT_C(16,16)PIXEL_AVG_WEIGHT_C(16,8)PIXEL_AVG_WEIGHT_C(8,16)PIXEL_AVG_WEIGHT_C(8,8)PIXEL_AVG_WEIGHT_C(8,4)PIXEL_AVG_WEIGHT_C(4,8)PIXEL_AVG_WEIGHT_C(4,4)PIXEL_AVG_WEIGHT_C(4,2)PIXEL_AVG_WEIGHT_C(2,4)PIXEL_AVG_WEIGHT_C(2,2)#undef op_scale2#undef PIXEL_AVG_WEIGHT_Ctypedef void (*pf_mc_t)(uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height );static void mc_copy( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height ){ int y; for( y = 0; y < i_height; y++ ) { memcpy( dst, src, i_width ); src += i_src_stride; dst += i_dst_stride; }}static inline void mc_hh( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height ){ int x, y; for( y = 0; y < i_height; y++ ) { for( x = 0; x < i_width; x++ ) { dst[x] = x264_mc_clip1( ( x264_tapfilter1( &src[x] ) + 16 ) >> 5 ); } src += i_src_stride; dst += i_dst_stride; }}static inline void mc_hv( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height ){ int x, y; for( y = 0; y < i_height; y++ ) { for( x = 0; x < i_width; x++ ) { dst[x] = x264_mc_clip1( ( x264_tapfilter( &src[x], i_src_stride ) + 16 ) >> 5 ); } src += i_src_stride; dst += i_dst_stride; }}static inline void mc_hc( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height ){ uint8_t *out; uint8_t *pix; int x, y; for( x = 0; x < i_width; x++ ) { int tap[6]; pix = &src[x]; out = &dst[x]; tap[0] = x264_tapfilter1( &pix[-2*i_src_stride] ); tap[1] = x264_tapfilter1( &pix[-1*i_src_stride] ); tap[2] = x264_tapfilter1( &pix[ 0*i_src_stride] ); tap[3] = x264_tapfilter1( &pix[ 1*i_src_stride] ); tap[4] = x264_tapfilter1( &pix[ 2*i_src_stride] ); for( y = 0; y < i_height; y++ ) { tap[5] = x264_tapfilter1( &pix[ 3*i_src_stride] ); *out = x264_mc_clip1( ( tap[0] - 5*tap[1] + 20 * tap[2] + 20 * tap[3] -5*tap[4] + tap[5] + 512 ) >> 10 ); /* Next line */ pix += i_src_stride; out += i_dst_stride; tap[0] = tap[1]; tap[1] = tap[2]; tap[2] = tap[3]; tap[3] = tap[4]; tap[4] = tap[5]; } }}static const int hpel_ref0[16] = {0,1,1,1,0,1,1,1,2,3,3,3,0,1,1,1};static const int hpel_ref1[16] = {0,0,0,0,2,2,3,2,2,2,3,2,2,2,3,2};static void mc_luma( uint8_t *src[4], int i_src_stride, uint8_t *dst, int i_dst_stride, int mvx,int mvy, int i_width, int i_height ){ int qpel_idx = ((mvy&3)<<2) + (mvx&3); int offset = (mvy>>2)*i_src_stride + (mvx>>2); 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 );
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -