?? interpolation.cpp
字號:
#include"stdafx.h"
#include"interpolation.h"
#include<math.h>
unsigned char NeighborInterpolation(LPSTR lpDIBBits,LONG width,LONG height,float x,float y)
{
unsigned char temp;
LONG i,j;
LONG LineBytes=(width*8+31)/32*4;
if(x>height-1||y>width-1)
{
if(x>height-1)
x=float(height-1);
else
y=float(width-1);
}
i=(LONG)x;
j=(LONG)y;
temp=*(lpDIBBits+LineBytes*(height-1-i)+j);
return temp;
}
unsigned char BiLinearInterpolation(LPSTR lpDIBBits,LONG width,LONG height,float x,float y)
{
LONG i0,j0,i1,j1;
unsigned char f1,f2,f3,f4;
unsigned char tempy,tempx;
LONG LineBytes;
LineBytes=(width*8+31)/32*4;
if((x>height-1)||(y>width-1))
{
if(x>height-1)
x=float(height-1);
else
y=float(width-1);
}
i0=(LONG)x;
j0=(LONG)y;
i1=i0+1;
j1=j0+1;
if(fabs(x-(height-1))<0.01)
{
if(fabs(y-(width-1))<0.01)
{
f1=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i0)+j0));
return f1;
}
else
{
f1=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i0)+j0));
f2=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i0)+j1));
tempy=(unsigned char)(f1+(y-j0)*(f2-f1));
return tempy;
}
}
else if(fabs(y-(width-1))<0.01)
{
f1=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i0)+j0));
f3=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i1)+j0));
tempx=(unsigned char)(f1+(x-i0)*(f3-f1));
return tempx;
}
else
{
f1=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i0)+j0));
f2=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i0)+j1));
f3=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i1)+j0));
f4=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i1)+j1));
tempx=(unsigned char)(f3+(y-j0)*(f4-f3));
tempy=(unsigned char)(f1+(y-j0)*(f2-f1));
return ((unsigned char)(tempy+(x-i0)*(tempx-tempy)));
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -