RotateZoom.cpp——Inter

// RotateZoom.cpp : Defines the entry point for the console application.
// #include "stdafx.h"
#include "RotateZoom.h" #ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include <atlimage.h>
#include <locale.h> // The one and only application object CWinApp theApp; using namespace std;
//双三次插值系数
double fs(double w)
{
double a=-0.5;
double fs;
if (abs(w)<=)
fs=(a+)*pow(abs(w),)-(a+)*pow(abs(w),)+;
else if (abs(w)>&&abs(w)<=)
fs=a*pow(abs(w),)-*a*pow(abs(w),)+*a*abs(w)-*a;
else
fs=;
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 = ; 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 x,y;
PBYTE pbSrc=NULL,pbTag=NULL;
PBYTE pbImage=NULL;
PDWORD pdwImage=NULL;
double dbRotate=,dbZoom=;
do{
if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), ))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = ;
break;
}
// TODO: code your application's behavior here.
if(argc<)
{
_tprintf(_T("使用方法:RotateZoom 源图像文件 旋转角度 缩放倍数 输出文件\n"));
nRetCode= -;
break;
} _stscanf(argv[],_T("%lf"),&dbRotate);
_stscanf(argv[],_T("%lf"),&dbZoom);
if(!((dbRotate> && dbRotate<) && (dbZoom>=0.25 && dbZoom<=)))
{
_tprintf(_T("“旋转角度” 或 “缩放倍数”参数错误!\n"));
nRetCode= -;
break;
} hResult=cImage.Load(argv[]);
if(hResult!=ERROR_SUCCESS)
{
_tprintf(_T("源图像文件名错误!\n"));
nRetCode= -;
break;
} iWidth=cImage.GetWidth();
iHeight=cImage.GetHeight();
pbSrc = (PBYTE)malloc(iWidth*iHeight);//存原图数据大小没问题
if(dbZoom>) pbTag = (PBYTE)malloc(ceil(iWidth*dbZoom)*ceil(iHeight*dbZoom));
else pbTag = (PBYTE)malloc(iWidth*iHeight);
if(pbSrc==NULL || pbTag==NULL )
{
_tprintf(_T("内存申请错误!\n"));
nRetCode= -;
break;
}
iPitch=cImage.GetPitch();
iBytePerPixel=(cImage.GetBPP()+)/;
if(iBytePerPixel==)
{
for(y=;y<iHeight;y++)
{
pbImage=(PBYTE)(PBYTE(cImage.GetBits())+iPitch*y);//得到的是图像初始像素地址
for(x=;x<iWidth;x++)
{
//pbSrc[y*iWidth+x]=pbImage[3*x]; //B
//pbSrc[y*iWidth+x]=pbImage[3*x+1]; //G
//pbSrc[y*iWidth+x]=pbImage[3*x+2]; //R //pbSrc[y*iWidth+x]=pbImage[3*x];
//pbSrc[y*iWidth+x+1]=pbImage[3*x+1];
//pbSrc[y*iWidth+x+2]=pbImage[3*x+2]; pbSrc[y*iWidth+x]=(pbImage[*x]*0.15+pbImage[*x+]*0.55+pbImage[*x+]*0.3);//转换成灰度就是单个像素了,分配大小还是原来的?。
}
}
}
cImage.Destroy();
hResult=RotateZoom(pbSrc,iWidth,iHeight,dbRotate,dbZoom,pbTag);
if(hResult!=ERROR_SUCCESS)
{
_tprintf(_T("图像处理错误!\n"));
nRetCode= -;
break;
}
iWidth=ceil(iWidth*dbZoom);
iHeight=ceil(iHeight*dbZoom);
cImage.Create(iWidth,-iHeight,);
iPitch=cImage.GetPitch();
for(y=;y<iHeight;y++)
{
pdwImage=(PDWORD)(PBYTE(cImage.GetBits())+iPitch*y);
for(x=;x<iWidth;x++)
{
pdwImage[x]=pbTag[y*iWidth+x]*0x10101;
}
}
CString csTagName=argv[];
csTagName.Trim();
csTagName.MakeUpper();
if(csTagName.Right()!=_T(".BMP") ) csTagName.Append(_T(".BMP"));
hResult=cImage.Save(csTagName);
if(hResult!=ERROR_SUCCESS)
{
_tprintf(_T("图像结果保存错误!\n"));
nRetCode= -;
break;
}
_tprintf(_T("图像处理成功!\n"));
nRetCode= ERROR_SUCCESS;
break;
}while();
if(pbSrc) free(pbSrc);
if(pbTag) free(pbTag);
}
else
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
nRetCode = ;
}
getchar();
return nRetCode;
}
HRESULT RotateZoom(PBYTE pbSrc,int iWidth,int iHeight,double dbRotate,double dbZoom,PBYTE pbTag)
{
int size;
if(dbZoom>)
{
size=iWidth*iHeight;
}
else
{
size=ceil(iWidth*dbZoom)*ceil(iHeight*dbZoom);
}
//旋转中心为图像中心
double rx0=iWidth;
double ry0=iHeight;
double srcx,srcy,u,v;
int xOr,yOr;
dbRotate=dbRotate*3.1415926/180.0;
for (int y=;y<dbZoom*iHeight;y++)
{
for (int x=;x<dbZoom*iWidth;x++)
{
srcx=(double)((x-rx0)*cos(dbRotate) - (y-ry0)*sin(dbRotate) + rx0) ;
srcy=(double)((x-rx0)*sin(dbRotate) + (y-ry0)*cos(dbRotate) + ry0) ;
srcx=srcx*/dbZoom;
srcy=srcy*/dbZoom;
xOr = floor(srcx);
yOr = floor(srcy);
u=srcx-xOr;
v=srcy-yOr;
// if( !(xOr-1>=0 && xOr+2<=iWidth && yOr-1>=0 && yOr+2<=iHeight))
if( !(srcx>= && srcx<=iWidth && srcy>= && srcy<=iHeight))
pbTag[y**iWidth+x]=;//
else
{
pbTag[y**iWidth+x]=
pbSrc[(yOr-)*iWidth+(xOr-)]*fs(+u)*fs(+v)+
pbSrc[(yOr)*iWidth+(xOr-)]*fs(+u)*fs(v)+
pbSrc[(yOr+)*iWidth+(xOr-)]*fs(+u)*fs(-v)+
pbSrc[(yOr+)*iWidth+(xOr-)]*fs(+u)*fs(-v)+ pbSrc[(yOr-)*iWidth+(xOr)]*fs(u)*fs(+v)+
pbSrc[(yOr)*iWidth+(xOr)]*fs(u)*fs(v)+
pbSrc[(yOr+)*iWidth+(xOr)]*fs(u)*fs(-v)+
pbSrc[(yOr+)*iWidth+(xOr)]*fs(u)*fs(-v)+ pbSrc[(yOr-)*iWidth+(xOr+)]*fs(-u)*fs(+v)+
pbSrc[(yOr)*iWidth+(xOr+)]*fs(-u)*fs(v)+
pbSrc[(yOr+)*iWidth+(xOr+)]*fs(-u)*fs(-v)+
pbSrc[(yOr+)*iWidth+(xOr+)]*fs(-u)*fs(-v)+ pbSrc[(yOr-)*iWidth+(xOr+)]*fs(-u)*fs(+v)+
pbSrc[(yOr)*iWidth+(xOr+)]*fs(-u)*fs(v)+
pbSrc[(yOr+)*iWidth+(xOr+)]*fs(-u)*fs(-v)+
pbSrc[(yOr+)*iWidth+(xOr+)]*fs(-u)*fs(-v); if(pbTag[y**iWidth+x]>)
pbTag[y**iWidth+x]=;
}
}
}
//memcpy(pbTag,pbSrc,size);
return ERROR_SUCCESS;
}
RotateZoom.cpp——Inter的更多相关文章
- RotateZoom.cpp 20180622
20180622代码加入随意变换图像大小 批处理框架先不看:-B src3.bmp 10 1 30 2 0.1 3 tar.bmp src2.bmp 37.5 2.1 tar // RotateZo ...
- Spark集群搭建简配+它到底有多快?【单挑纯C/CPP/HADOOP】
最近耳闻Spark风生水起,这两天利用休息时间研究了一下,果然还是给人不少惊喜.可惜,笔者不善JAVA,只有PYTHON和SCALA接口.花了不少时间从零开始认识PYTHON和SCALA,不少时间答了 ...
- Inter IPP & Opencv 在centos 环境下使用GCC命令行编译c++运行
Inter IPP & Opencv 的安装看这里:https://www.cnblogs.com/dzzy/p/11332907.html 考虑到服务器一般没有桌面环境,不能用IDE编译,直 ...
- 使用“Cocos引擎”创建的cpp工程如何在VS中调试Cocos2d-x源码
前段时间Cocos2d-x更新了一个Cocos引擎,这是一个集合源码,IDE,Studio这一家老小的整合包,我们可以使用这个Cocos引擎来创建我们的项目. 在Cocos2d-x被整合到Cocos引 ...
- Json CPP 中文支持与入门示例
在每一个Json Cpp自带*.cpp文件头加上: #include "stdafx.h" 将Json Cpp对自带的头文件的引用修改为单引号方式,例如json_reader.cp ...
- cpp 调用python
在用cpp调用python时, 出现致命错误: no module named site , 原因解释器在搜索路径下没有找到python库.可以在调用Py_Initialize前,调用 Py_Se ...
- nginx+fastcgi+c/cpp
参考:http://github.tiankonguse.com/blog/2015/01/19/cgi-nginx-three/ 跟着做了一遍,然后根据记忆写的,不清楚有没错漏步骤,希望多多评论多多 ...
- APM程序分析-ArduCopter.cpp
该文件是APM的主文件. #define SCHED_TASK(func, rate_hz, max_time_micros) SCHED_TASK_CLASS(Copter, &copter ...
- APM程序分析-AC_WPNav.cpp
APM程序分析 主程序在ArduCopter.cpp的loop()函数. /// advance_wp_target_along_track - move target location along ...
随机推荐
- Python基础——函数的迭代器和生成器
等待更新…………………… 后面再写
- FMDB-FMDatabaseQueue
FMDB封装了SQLite3的方法,操作数据库变得很简单. 增删改查变简单之后,那么问题来了,如何使用多线程优化对数据库的操作? 这是我们的第一反应估计是dispatch_async(). 那么问题又 ...
- 交叉工具链和makefile
交叉工具链: arm-linux-gcc:交叉编译器 arm-linux-ld:交叉连接器 arm-linux-readelf:交叉ELF文件工具 arm-linux-objdump:交叉反汇编器 a ...
- Centos6 修复grub损坏故障
1.查看系统中的/boot/grub/grub.conf # grub.conf generated by anaconda # # Note that you do not have to reru ...
- pycharm 的一个小问题
版本:PyCharm 2018.3.7 (Professional Edition) 这段时间用pycharm写python代码,运行网上copy的代码.报错了也就是少个模块或者Python2的语法在 ...
- Spring Boot JPA - Querydsl
https://lufficc.com/blog/spring-boot-jpa-querydsl
- 枚举类enum应用以及注解@transient应用
1.增加枚举类 public enum RightTypeEnum { AUTHORITY("访问权限") private String type; RightTypeEnum(S ...
- JAVA利用递归的方法删除一个文件夹以及文件夹下所有的子文件
public static boolean deleteFolder(String url) { File file = new File(url); if (!file.exists()) { re ...
- c++列举出本地打印机和网络打印机名称
主要使用EnumPrinters函数 该函数枚举可用的打印机,打印服务器,域或印刷服务供应商. 代码:(开箱即用) #include <Windows.h> #include <st ...
- Quartz(二)
1 SchedulerFactory 1.1 概述 Quartz是以模块的方式构建的,因为,要使它运行,几个组件必须很好的组合在一起.非常幸运的是,已经有了一些现存的助手可以完成这些工作. 所有Sch ...