16x16分块
// RotateZoom.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "RotateZoom.h"#ifdef _DEBUG#define new DEBUG_NEW#endif#include#include // The one and only application objectCWinApp theApp;using namespace std;//双三次插值系数double fs(double w){ double a=-0.5; double fs; if (abs(w)<=1) fs=(a+2)*pow(abs(w),3)-(a+3)*pow(abs(w),2)+1; else if (abs(w)>1&&abs(w)<=2) fs=a*pow(abs(w),3)-5*a*pow(abs(w),2)+8*a*abs(w)-4*a; else fs=0; return fs;}HRESULT RotateZoom(PBYTE pbSrc,int iWidth,int iHeight,double dbRotate,double dbZoom,PBYTE pbTag);int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]){ int nRetCode = 0; setlocale(LC_ALL,"chs"); HMODULE hModule = ::GetModuleHandle(NULL); if (hModule != NULL) { // initialize MFC and print and error on failure CImage cImage; HRESULT hResult; int iWidth,iHeight,iBytePerPixel,iPitch; int i,j,x,y,w,h; PBYTE pbSrc=NULL,pbTag=NULL; PBYTE pbImage=NULL; PDWORD pdwImage=NULL; double dbRotate=0,dbZoom=0; double dbRotateStart=0,dbRotateEnd=0,dbRotateStep; double dbZoomStart=0,dbZoomEnd=0,dbZoomStep; BOOL bBenchWork=FALSE; CString csSrcName,csTagName,csNameRoot; TCHAR *ptChar; do{ if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed\n")); nRetCode = 1; break; } // TODO: code your application's behavior here. if(argc!=6 && argc!=10 ) { _tprintf(_T("使用方法:\n RotateZoom -S 源图像文件 旋转角度 缩放倍数 输出文件\n或:\n RotateZoom -B 源图像文件 旋转起始角度 步长 旋转终止角度 缩放起始倍数 步长 缩放终止倍数 输出文件\n")); nRetCode= -1; break; } if(_tcsnicmp(argv[1],_T("-B"),2)==0) { bBenchWork=TRUE; } else if(_tcsnicmp(argv[1],_T("-S"),2)==0) { bBenchWork=FALSE; } else { _tprintf(_T("使用方法:\n RotateZoom -S 源图像文件 旋转角度 缩放倍数 输出文件\n或:\nRotateZoom -B 源图像文件 旋转起始角度 步长 旋转终止角度 缩放起始倍数 步长 缩放终止倍数 输出文件\n")); nRetCode= -1; break; } if(bBenchWork) { csSrcName=argv[2]; _stscanf(argv[3],_T("%lf"),&dbRotateStart); _stscanf(argv[4],_T("%lf"),&dbRotateStep); _stscanf(argv[5],_T("%lf"),&dbRotateEnd); _stscanf(argv[6],_T("%lf"),&dbZoomStart); _stscanf(argv[7],_T("%lf"),&dbZoomStep); _stscanf(argv[8],_T("%lf"),&dbZoomEnd); dbZoom=dbZoomStart>dbZoomEnd?dbZoomStart:dbZoomEnd; csTagName=argv[9]; if(!((dbRotateStart>=0 && dbRotateStart<360) && (dbRotateEnd>=0 && dbRotateEnd<360) && (dbZoomStart>=0.26 && dbZoomStart<=16) && (dbZoomStart>=0.25 && dbZoomStart<=16) && (dbRotateStep>=0.01) && (dbZoomEnd>=0.01))) { _tprintf(_T("旋转角度范围(0~360),缩放倍数范围(0.25~16),步长范围(>=0.01)。输入参数超出范围!\n")); nRetCode= -2; break; } } else { csSrcName=argv[2]; _stscanf(argv[3],_T("%lf"),&dbRotate); _stscanf(argv[4],_T("%lf"),&dbZoom); csTagName=argv[5]; if(!((dbRotate>=0 && dbRotate<360) && (dbZoom>=0.25 && dbZoom<=16))) { _tprintf(_T("旋转角度范围(0~360),缩放倍数范围(0.25~16)。输入参数超出范围!\n")); nRetCode= -2; break; } } hResult=cImage.Load(csSrcName); if(hResult!=ERROR_SUCCESS) { _tprintf(_T("源图像文件名错误!\n")); nRetCode= -3; break; } iWidth=cImage.GetWidth(); iHeight=cImage.GetHeight(); pbSrc = (PBYTE)malloc(iWidth*iHeight);//存原图数据大小没问题 if(dbZoom>1) pbTag = (PBYTE)malloc(ceil(iWidth*dbZoom)*ceil(iHeight*dbZoom)); else pbTag = (PBYTE)malloc(iWidth*iHeight); if(pbSrc==NULL || pbTag==NULL ) { _tprintf(_T("内存申请错误!\n")); nRetCode= -4; break; } iPitch=cImage.GetPitch(); iBytePerPixel=(cImage.GetBPP()+7)/8; if(iBytePerPixel==3) { for(y=0;y 1) { size=iWidth*iHeight; } else { size=ceil(iWidth*dbZoom)*ceil(iHeight*dbZoom); } int newWidth=ceil(dbZoom*iWidth); //旋转中心为图像中心 double rx0=ceil(dbZoom*iWidth)*0.5; double ry0=ceil(dbZoom*iHeight)*0.5; double srcx,srcy,u,v; int xOr,yOr; dbRotate=dbRotate*3.1415926/180.0; int xo=0,yo=0; for (int y=yo;y =0+16*(i-1) && xOr<=16*i && yOr-1>=0+16*(i-1) && yOr<=16*i)) { pbTag[y*newWidth+x]=255-20*i; } } } } //memcpy(pbTag,pbSrc,size); return ERROR_SUCCESS;}