双线性插值算法,谁能解释下?

jinlsg 2012-03-20 11:02:09
void PicZoom_Bilinear1(const TPixels32Ref& Dst,const TPixels32Ref& Src)
{
if ( (0==Dst.width)||(0==Dst.height)
||(0==Src.width)||(0==Src.height)) return;

long xrIntFloat_16=((Src.width)<<16)/Dst.width+1;
long yrIntFloat_16=((Src.height)<<16)/Dst.height+1;
const long csDErrorX=-(1<<15)+(xrIntFloat_16>>1);
const long csDErrorY=-(1<<15)+(yrIntFloat_16>>1);

long dst_width=Dst.width;

Color32* pDstLine=Dst.pdata;
long srcy_16=csDErrorY;
long y;
for (y=0;y<Dst.height;++y)
{
long srcx_16=csDErrorX;
for (long x=0;x<dst_width;++x)
{
Bilinear1(Src,srcx_16,srcy_16,&pDstLine[x]); //border
srcx_16+=xrIntFloat_16;
}
srcy_16+=yrIntFloat_16;
((UInt8*&)pDstLine)+=Dst.byte_width;
}
}

must_inline void Bilinear1(const TPixels32Ref& pic,const long x_16,const long y_16,Color32* result)
{
long x=x_16>>16;
long y=y_16>>16;
Color32 Color0=pic.getPixelsBorder(x,y);
Color32 Color2=pic.getPixelsBorder(x+1,y);
Color32 Color1=pic.getPixelsBorder(x,y+1);
Color32 Color3=pic.getPixelsBorder(x+1,y+1);

unsigned long u_8=(x_16 & 0xFFFF)>>8;
unsigned long v_8=(y_16 & 0xFFFF)>>8;
unsigned long pm3_16=(u_8*v_8);
unsigned long pm2_16=(u_8*(unsigned long)(256-v_8));
unsigned long pm1_16=(v_8*(unsigned long)(256-u_8));
unsigned long pm0_16=((256-u_8)*(256-v_8));

result->a=(UInt8)((pm0_16*Color0.a+pm1_16*Color1.a+pm2_16*Color2.a+pm3_16*Color3.a)>>16);
result->r=(UInt8)((pm0_16*Color0.r+pm1_16*Color1.r+pm2_16*Color2.r+pm3_16*Color3.r)>>16);
result->g=(UInt8)((pm0_16*Color0.g+pm1_16*Color1.g+pm2_16*Color2.g+pm3_16*Color3.g)>>16);
result->b=(UInt8)((pm0_16*Color0.b+pm1_16*Color1.b+pm2_16*Color2.b+pm3_16*Color3.b)>>16);
}

那位高手能解释下:
long xrIntFloat_16=((Src.width)<<16)/Dst.width+1;
long yrIntFloat_16=((Src.height)<<16)/Dst.height+1;
const long csDErrorX=-(1<<15)+(xrIntFloat_16>>1);
const long csDErrorY=-(1<<15)+(yrIntFloat_16>>1);
这四句代码的意思?
我以前看到的双线插值算法都是使用浮点数保存源宽度和目标宽度的比值的。
...全文
302 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinlsg 2012-03-22
  • 打赏
  • 举报
回复
自己顶起来!

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧