⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mc.c.svn-base

📁 现在关于h.264的源码很多
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * 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. *****************************************************************************/#ifdef HAVE_STDINT_H#include <stdint.h>#else#include <inttypes.h>#endif#include <stdlib.h>#include <stdio.h>#include <string.h>#include <stdarg.h>#include "x264.h"#include "pixel.h"#include "mc.h"#include "clip1.h"#include "frame.h"#ifdef HAVE_MMXEXT#include "i386/mc.h"#endif#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 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 ){    uint8_t *src1, *src2;    int correction = (mvx&1) && (mvy&1) && ((mvx&2) ^ (mvy&2));    int hpel1x = mvx>>1;    int hpel1y = (mvy+1-correction)>>1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -