代码记录——phase16,block32

代码记录——phase16,block32

HRESULT RotateZoom(PBYTE pbSrc,int iWidth,int iHeight,double dbRotate,double dbZoom,PBYTE pbTag)
{
//int phase[17]={0};//8相位,包含端点存在17个距离 //16
//for (int i=0;i<17;i++)
//{
// double i2=1.0*i;
// phase[i]=fs(i2/8)*1024;
//}
int phase[]={,,,,,,,,,-,-,-,-,-,-,-,}; int src1x,src1y,src2x,src2y,src3x,src3y,src4x,src4y;
int drcx[],drcy[];
int angl=;//旋转45度
int middle_height=;
int middle_width=;
int rx=;
int ry=; int newheight=;
int newwidth=;
int rx0=; //插值放大后图像的旋转中心
int ry0=;
for(int y=;y<;y=y+)
{
for(int x=;x<;x=x+)
{
//正向映射入大图像中分块图像所对应的像素点
src1x=x;src1y=y;src2x=x+;src2y=y;src3x=x;src3y=y+;src4x=x+;src4y=y+;
//正向映射公式
int a=dbZoom;
drcx[]=(a*src1x-rx)*angl+(a*src1y-ry)*angl+rx0*;
drcy[]=-(a*src1x-rx)*angl+(a*src1y-ry)*angl+ry0*;
drcx[]=(a*src2x-rx)*angl+(a*src2y-ry)*angl+rx0*;
drcy[]=-(a*src2x-rx)*angl+(a*src2y-ry)*angl+ry0*;
drcx[]=(a*src3x-rx)*angl+(a*src3y-ry)*angl+rx0*;
drcy[]=-(a*src3x-rx)*angl+(a*src3y-ry)*angl+ry0*;
drcx[]=(a*src4x-rx)*angl+(a*src4y-ry)*angl+rx0*;
drcy[]=-(a*src4x-rx)*angl+(a*src4y-ry)*angl+ry0*;
//获得分块图像大范围
drcx[]=(int)(drcx[]/);//截后10位处理?
drcy[]=(int)(drcy[]/);
drcx[]=(int)(drcx[]/);
drcy[]=(int)(drcy[]/);
drcx[]=(int)(drcx[]/);
drcy[]=(int)(drcy[]/);
drcx[]=(int)(drcx[]/);
drcy[]=(int)(drcy[]/);
//放大二倍有边框,不旋转时+1可处理
int max_x,max_y,min_x,min_y;
int srcx,srcy;
max_x=drcx[];max_y=drcy[];min_x=drcx[];min_y=drcy[];
for (int i=;i<;i++)
{
if (min_x>drcx[i])
min_x=drcx[i];
if (min_y>drcy[i])
min_y=drcy[i];
}
min_x=min_x-;min_y=min_y-;
for (int i=;i<;i++)
{
if (max_x<drcx[i])
max_x=drcx[i];
if (max_y<drcy[i])
max_y=drcy[i];
}
max_x=min_x+-;max_y=max_y+; //将范围内的点映射回原图中 同时旋转插值
for (int j=min_y;j<=max_y;j++)
{
for (int i=min_x;i<=max_x;i++)
{
//将点映射回原图中
srcx=((i-rx0)*angl-(j-ry0)*angl+rx*)/;
srcy=((i-rx0)*angl+(j-ry0)*angl+ry*)/;
if ((srcx>=x-)&&(srcx<=x+)&&(srcy>=y-)&&(srcy<=y+)&&(srcx>=)&&(srcy>=)&&(srcx<=iWidth-)&&(srcy<=iHeight-))/*&&(i>=0)&&(j>=0)*/
{
//映射后位置判断区别可能有误
//if(srcx>x+31)
//{
// srcx=x+31;
//}
//if(srcy>y+31)
//{
// srcy=y+31;
//} //if(srcx<x-1)
//{
// srcx=x-1;
//}
//if(srcy<y-1)
//{
// srcy=y-1;
//} //插值:
//计算整数部分和小数部分
int xOr = floor((double)srcx);
int yOr = floor((double)srcy);
double u=srcx-xOr;
double v=srcy-yOr;
//查表双三插值
int phasex=*u;//8相位
int phasey=*v;
int A1,B1,C1,D1,A2,B2,C2,D2; //计算每个点的插值系数
A1=phase[+phasex];B1=phase[phasex];C1=phase[-phasex];D1=phase[-phasex];
A2=phase[+phasey];B2=phase[phasey];C2=phase[-phasey];D2=phase[-phasey]; //由src计算块编号,使用对应编号块内的相对位置
int xnum,ynum;
int x_upleft,y_upleft;//左上起始点坐标
int x_shift,y_shift; xnum=floor(srcx/32.0)+;
ynum=floor(srcy/32.0)+;
x_upleft=(xnum-)*;
y_upleft=(ynum-)*; int imgsrc[]={};//36*36,32*32
int ijk=; for (int n=;n<;n++)
{
for (int m=;m<;m++)
{
imgsrc[ijk]=pbSrc[(y_upleft+n)*iWidth+x_upleft+m];
ijk++;
} }
//块内相对偏移位置
x_shift= xOr-x_upleft;
y_shift= yOr-y_upleft; int middle=imgsrc[(y_shift)*+(x_shift)]; /*imgsrc[(yOr-1)*iWidth+(xOr-1)]*A1*A2+imgsrc[(yOr)*iWidth+(xOr-1)]*A1*B2+imgsrc[(yOr+1)*iWidth+(xOr-1)]*A1*C2+imgsrc[(yOr+2)*iWidth+(xOr-1)]*A1*D2+
imgsrc[(yOr-1)*iWidth+(xOr)]*B1*A2+imgsrc[(yOr)*iWidth+(xOr)]*B1*B2+imgsrc[(yOr+1)*iWidth+(xOr)]*B1*C2+imgsrc[(yOr+2)*iWidth+(xOr)]*B1*D2+
imgsrc[(yOr-1)*iWidth+(xOr+1)]*C1*A2+imgsrc[(yOr)*iWidth+(xOr+1)]*C1*B2+imgsrc[(yOr+1)*iWidth+(xOr+1)]*C1*C2+imgsrc[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
imgsrc[(yOr-1)*iWidth+(xOr+2)]*D1*A2+imgsrc[(yOr)*iWidth+(xOr+2)]*D1*B2+imgsrc[(yOr+1)*iWidth+(xOr+2)]*D1*C2+imgsrc[(yOr+2)*iWidth+(xOr+2)]*D1*D2;*/ /*int middle=pbSrc[(yOr-1)*iWidth+(xOr-1)]*A1*A2+pbSrc[(yOr)*iWidth+(xOr-1)]*A1*B2+pbSrc[(yOr+1)*iWidth+(xOr-1)]*A1*C2+pbSrc[(yOr+2)*iWidth+(xOr-1)]*A1*D2+
pbSrc[(yOr-1)*iWidth+(xOr)]*B1*A2+pbSrc[(yOr)*iWidth+(xOr)]*B1*B2+pbSrc[(yOr+1)*iWidth+(xOr)]*B1*C2+pbSrc[(yOr+2)*iWidth+(xOr)]*B1*D2+
pbSrc[(yOr-1)*iWidth+(xOr+1)]*C1*A2+pbSrc[(yOr)*iWidth+(xOr+1)]*C1*B2+pbSrc[(yOr+1)*iWidth+(xOr+1)]*C1*C2+pbSrc[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
pbSrc[(yOr-1)*iWidth+(xOr+2)]*D1*A2+pbSrc[(yOr)*iWidth+(xOr+2)]*D1*B2+pbSrc[(yOr+1)*iWidth+(xOr+2)]*D1*C2+pbSrc[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
*/
//middle=middle/(1024*1024); if(middle<=&&middle>=)
pbTag[j*newwidth+i]=middle;
else if(middle>)
pbTag[j*newwidth+i]=;
else
pbTag[j*newwidth+i]=;
}
}
}
}
}
return ERROR_SUCCESS;
}
上一篇:双向广搜 POJ 3126 Prime Path


下一篇:nginx+tomcat动静分离结构