/* motion.c, motion estimation */
/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
/*
* Disclaimer of Warranty
*
* These software programs are available to the user without any license fee or
* royalty on an "as is" basis. The MPEG Software Simulation Group disclaims
* any and all warranties, whether express, implied, or statuary, including any
* implied warranties or merchantability or of fitness for a particular
* purpose. In no event shall the copyright-holder be liable for any
* incidental, punitive, or consequential damages of any kind whatsoever
* arising from the use of these programs.
*
* This disclaimer of warranty extends to the user of these programs and user's
* customers, employees, agents, transferees, successors, and assigns.
*
* The MPEG Software Simulation Group does not represent or warrant that the
* programs furnished hereunder are free of infringement of any third-party
* patents.
*
* Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
* are subject to royalty fees to patent holders. Many of these patents are
* general enough such that they are unavoidable regardless of implementation
* design.
*
*/
#include <stdio.h>
#include "config.h"
#include "global.h"
/* private prototypes */
static void frame_ME _ANSI_ARGS_((unsigned char *oldorg, unsigned char *neworg,
unsigned char *oldref, unsigned char *newref, unsigned char *cur,
int i, int j, int sxf, int syf, int sxb, int syb, struct mbinfo *mbi));
static void field_ME _ANSI_ARGS_((unsigned char *oldorg, unsigned char *neworg,
unsigned char *oldref, unsigned char *newref, unsigned char *cur,
unsigned char *curref, int i, int j, int sxf, int syf, int sxb, int syb,
struct mbinfo *mbi, int secondfield, int ipflag));
static void frame_estimate _ANSI_ARGS_((unsigned char *org,
unsigned char *ref, unsigned char *mb,
int i, int j,
int sx, int sy, int *iminp, int *jminp, int *imintp, int *jmintp,
int *iminbp, int *jminbp, int *dframep, int *dfieldp,
int *tselp, int *bselp, int imins[2][2], int jmins[2][2]));
static void field_estimate _ANSI_ARGS_((unsigned char *toporg,
unsigned char *topref, unsigned char *botorg, unsigned char *botref,
unsigned char *mb, int i, int j, int sx, int sy, int ipflag,
int *iminp, int *jminp, int *imin8up, int *jmin8up, int *imin8lp,
int *jmin8lp, int *dfieldp, int *d8p, int *selp, int *sel8up, int *sel8lp,
int *iminsp, int *jminsp, int *dsp));
static void dpframe_estimate _ANSI_ARGS_((unsigned char *ref,
unsigned char *mb, int i, int j, int iminf[2][2], int jminf[2][2],
int *iminp, int *jminp, int *imindmvp, int *jmindmvp,
int *dmcp, int *vmcp));
static void dpfield_estimate _ANSI_ARGS_((unsigned char *topref,
unsigned char *botref, unsigned char *mb,
int i, int j, int imins, int jmins, int *imindmvp, int *jmindmvp,
int *dmcp, int *vmcp));
static int fullsearch _ANSI_ARGS_((unsigned char *org, unsigned char *ref,
unsigned char *blk,
int lx, int i0, int j0, int sx, int sy, int h, int xmax, int ymax,
int *iminp, int *jminp));
static int dist1 _ANSI_ARGS_((unsigned char *blk1, unsigned char *blk2,
int lx, int hx, int hy, int h, int distlim));
static int dist2 _ANSI_ARGS_((unsigned char *blk1, unsigned char *blk2,
int lx, int hx, int hy, int h));
static int bdist1 _ANSI_ARGS_((unsigned char *pf, unsigned char *pb,
unsigned char *p2, int lx, int hxf, int hyf, int hxb, int hyb, int h));
static int bdist2 _ANSI_ARGS_((unsigned char *pf, unsigned char *pb,
unsigned char *p2, int lx, int hxf, int hyf, int hxb, int hyb, int h));
static int variance _ANSI_ARGS_((unsigned char *p, int lx));
/*
* motion estimation for progressive and interlaced frame pictures
*
* oldorg: source frame for forward prediction (used for P and B frames)
* neworg: source frame for backward prediction (B frames only)
* oldref: reconstructed frame for forward prediction (P and B frames)
* newref: reconstructed frame for backward prediction (B frames only)
* cur: current frame (the one for which the prediction is formed)
* sxf,syf: forward search window (frame coordinates)
* sxb,syb: backward search window (frame coordinates)
* mbi: pointer to macroblock info structure
*
* results:
* mbi->
* mb_type: 0, MB_INTRA, MB_FORWARD, MB_BACKWARD, MB_FORWARD|MB_BACKWARD
* MV[][][]: motion vectors (frame format)
* mv_field_sel: top/bottom field (for field prediction)
* motion_type: MC_FRAME, MC_FIELD
*
* uses global vars: pict_type, frame_pred_dct
*/
void motion_estimation(oldorg,neworg,oldref,newref,cur,curref,
sxf,syf,sxb,syb,mbi,secondfield,ipflag)
unsigned char *oldorg,*neworg,*oldref,*newref,*cur,*curref;
int sxf,syf,sxb,syb;
struct mbinfo *mbi;
int secondfield,ipflag;
{
int i, j;
/* loop through all macroblocks of the picture */
for (j=0; j<height2; j+=16)
{
for (i=0; i<width; i+=16)
{
if (pict_struct==FRAME_PICTURE)
frame_ME(oldorg,neworg,oldref,newref,cur,i,j,sxf,syf,sxb,syb,mbi);
else
field_ME(oldorg,neworg,oldref,newref,cur,curref,i,j,sxf,syf,sxb,syb,
mbi,secondfield,ipflag);
mbi++;
}
if (!quiet)
{
putc('.',stderr);
fflush(stderr);
}
}
if (!quiet)
putc('\n',stderr);
}
static void frame_ME(oldorg,neworg,oldref,newref,cur,i,j,sxf,syf,sxb,syb,mbi)
unsigned char *oldorg,*neworg,*oldref,*newref,*cur;
int i,j,sxf,syf,sxb,syb;
struct mbinfo *mbi;
{
int imin,jmin,iminf,jminf,iminr,jminr;
int imint,jmint,iminb,jminb;
int imintf,jmintf,iminbf,jminbf;
int imintr,jmintr,iminbr,jminbr;
int var,v0;
int dmc,dmcf,dmcr,dmci,vmc,vmcf,vmcr,vmci;
int dmcfield,dmcfieldf,dmcfieldr,dmcfieldi;
int tsel,bsel,tself,bself,tselr,bselr;
unsigned char *mb;
int imins[2][2],jmins[2][2];
int imindp,jmindp,imindmv,jmindmv,dmc_dp,vmc_dp;
mb = cur + i + width*j;
var = variance(mb,width);
if (pict_type==I_TYPE)
mbi->mb_type = MB_INTRA;
else if (pict_type==P_TYPE)
{
if (frame_pred_dct)
{
dmc = fullsearch(oldorg,oldref,mb,
width,i,j,sxf,syf,16,width,height,&imin,&jmin);
vmc = dist2(oldref+(imin>>1)+width*(jmin>>1),mb,
width,imin&1,jmin&1,16);
mbi->motion_type = MC_FRAME;
}
else
{
frame_estimate(oldorg,oldref,mb,i,j,sxf,syf,
&imin,&jmin,&imint,&jmint,&iminb,&jminb,
&dmc,&dmcfield,&tsel,&bsel,imins,jmins);
if (M==1)
dpframe_estimate(oldref,mb,i,j>>1,imins,jmins,
&imindp,&jmindp,&imindmv,&jmindmv,&dmc_dp,&vmc_dp);
/* select between dual prime, frame and field prediction */
if (M==1 && dmc_dp<dmc && dmc_dp<dmcfield)
{
mbi->motion_type = MC_DMV;
dmc = dmc_dp;
vmc = vmc_dp;
}
else if (dmc<=dmcfield)
{
mbi->motion_type = MC_FRAME;
vmc = dist2(oldref+(imin>>1)+width*(jmin>>1),mb,
width,imin&1,jmin&1,16);
}
else
{
mbi->motion_type = MC_FIELD;
dmc = dmcfield;
vmc = dist2(oldref+(tsel?width:0)+(imint>>1)+(width<<1)*(jmint>>1),
mb,width<<1,imint&1,jmint&1,8);
vmc+= dist2(oldref+(bsel?width:0)+(iminb>>1)+(width<<1)*(jminb>>1),
mb+width,width<<1,iminb&1,jminb&1,8);
}
}
/* select between intra or non-intra coding:
*
* selection is based on intra block variance (var) vs.
* prediction error variance (vmc)
*
* blocks with small prediction error are always coded non-intra
* even if variance is smaller (is this reasonable?)
*/
if (vmc>var && vmc>=9*256)
mbi->mb_type = MB_INTRA;
else
{
/* select between MC / No-MC
*
* use No-MC if var(No-MC) <= 1.25*var(MC)
* (i.e slightly biased towards No-MC)
*
* blocks with small prediction error are always coded as No-MC
* (requires no mot
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
mpeg2v12.zip (91个子文件)
bin
mpeg2enc.exe 148KB
emu387 36KB
mpeg2dec.exe 128KB
readme.pc 2KB
src
mpeg2dec
getpic.c 33KB
IEEE1180 11KB
mpeg2dec.h 4KB
mpeg2dec.c 18KB
gethdr.c 29KB
config.h 2KB
display.c 33KB
recon.c 15KB
idct.c 6KB
getvlc.c 15KB
store.c 15KB
TODO 2KB
verify.c 8KB
getvlc.h 20KB
EXAMPLES 1KB
motion.c 7KB
getbits.c 4KB
getblk.c 12KB
README 1KB
global.h 13KB
spatscal.c 9KB
systems.c 5KB
CHANGES 3KB
SPATIAL.DOC 6KB
idctref.c 3KB
test.m2v 7KB
subspic.c 10KB
Makefile 3KB
mpeg2enc
putvlc.c 6KB
conform.c 9KB
mpeg2enc.c 15KB
putmpg.c 4KB
fdctref.c 3KB
config.h 1KB
putpic.c 11KB
readpic.c 13KB
transfrm.c 7KB
idct.c 6KB
writepic.c 2KB
quantize.c 5KB
putbits.c 2KB
TODO 197B
ratectl.c 13KB
stats.c 11KB
predict.c 16KB
vlc.h 11KB
motion.c 47KB
global.h 11KB
puthdr.c 7KB
CHANGES 754B
Makefile.wat 2KB
putseq.c 10KB
Makefile 2KB
mpeg2enc.h 3KB
verify
test0.U 4KB
recon0.V 4KB
test1.V 4KB
recon2.U 4KB
recon2.V 4KB
recon2.Y 16KB
recon1.V 4KB
recon1.U 4KB
test0.V 4KB
recon0.U 4KB
test2.V 4KB
verify 633B
test2.Y 16KB
test.par 3KB
recon1.Y 16KB
README 342B
test2.U 4KB
test.m2v 7KB
recon0.Y 16KB
test0.Y 16KB
test1.U 4KB
test1.Y 16KB
README 9KB
par
PAL.par 3KB
inter.mat 192B
MPEG-1.par 3KB
intra.mat 192B
NTSC.par 3KB
doc
m2d_old.doc 8KB
BUGS 85B
mpeg2enc.doc 24KB
ARCHITECTURE 7KB
Makefile 2KB
共 91 条
- 1
虎子呵呵
- 粉丝: 573
- 资源: 30
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- kernel-ml-6.8.8-1.el7.elrepo.x86-64.rpm
- Labview基本框架之状态机
- HM2309B-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- Git安全实践:保护你的代码仓库个人学习笔记.md
- 自动驾驶定位系列教程九:后端优化.pdf
- 三国志5威力加强版-windows
- HM2309A-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- HM2306-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- Git进阶技巧:提升团队协作效率个人学习笔记.md
- 自动驾驶定位系列教程八:建图系统结构优化.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页