// 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的更多相关文章

  1. RotateZoom.cpp 20180622

    20180622代码加入随意变换图像大小 批处理框架先不看:-B src3.bmp 10 1 30 2  0.1 3 tar.bmp src2.bmp 37.5 2.1 tar // RotateZo ...

  2. Spark集群搭建简配+它到底有多快?【单挑纯C/CPP/HADOOP】

    最近耳闻Spark风生水起,这两天利用休息时间研究了一下,果然还是给人不少惊喜.可惜,笔者不善JAVA,只有PYTHON和SCALA接口.花了不少时间从零开始认识PYTHON和SCALA,不少时间答了 ...

  3. Inter IPP & Opencv 在centos 环境下使用GCC命令行编译c++运行

    Inter IPP & Opencv 的安装看这里:https://www.cnblogs.com/dzzy/p/11332907.html 考虑到服务器一般没有桌面环境,不能用IDE编译,直 ...

  4. 使用“Cocos引擎”创建的cpp工程如何在VS中调试Cocos2d-x源码

    前段时间Cocos2d-x更新了一个Cocos引擎,这是一个集合源码,IDE,Studio这一家老小的整合包,我们可以使用这个Cocos引擎来创建我们的项目. 在Cocos2d-x被整合到Cocos引 ...

  5. Json CPP 中文支持与入门示例

    在每一个Json Cpp自带*.cpp文件头加上: #include "stdafx.h" 将Json Cpp对自带的头文件的引用修改为单引号方式,例如json_reader.cp ...

  6. cpp 调用python

    在用cpp调用python时, 出现致命错误: no module named site  ,  原因解释器在搜索路径下没有找到python库.可以在调用Py_Initialize前,调用 Py_Se ...

  7. nginx+fastcgi+c/cpp

    参考:http://github.tiankonguse.com/blog/2015/01/19/cgi-nginx-three/ 跟着做了一遍,然后根据记忆写的,不清楚有没错漏步骤,希望多多评论多多 ...

  8. APM程序分析-ArduCopter.cpp

    该文件是APM的主文件. #define SCHED_TASK(func, rate_hz, max_time_micros) SCHED_TASK_CLASS(Copter, &copter ...

  9. APM程序分析-AC_WPNav.cpp

    APM程序分析 主程序在ArduCopter.cpp的loop()函数. /// advance_wp_target_along_track - move target location along ...

随机推荐

  1. eval解惑

    let a = 1, b = 2, c = 3; let arr = [a, b, c]; function test(p1, p2, p3) { console.log(`${p1} ~ ${p2} ...

  2. 2019-11-29-C#-在-8.0-对比-string-和-string_-的类型

    title author date CreateTime categories C# 在 8.0 对比 string 和 string? 的类型 lindexi 2019-11-29 8:59:0 + ...

  3. pause模块

    pause模块:暂停脚本执行 # ansible-doc -s pause- name: Pause playbook execution pause: minutes: // 暂停的真实分钟数 pr ...

  4. nova计算服务分布式

    控制节点 #第一步 控制节点下载nova-conpute包 #安装依赖包 #vim /etc/nova/nova.conf [DEFAULT] my_ip=#当前节点IP use_neutron = ...

  5. scp 远程文件复制命令

    scp 远程文件复制工具 1.命令功能 scp用户在不同linux主机间复制文件,他采用ssh协议保障复制的安全性.scp复制是全量完整复制,效率不高,使用与第一次复制,增量复制建议rsync命令. ...

  6. jmeter+ant 实现自动化接口测试环境配置

    前置:安装jdk 1.8以上 一.安装jemeter 下载地址:http://jmeter.apache.org/download_jmeter.cgi 1.1 解压jmeter,放在某个目录,例如D ...

  7. css不常见属性之pointer-events

    MDN 上介绍为 CSS 属性指定在什么情况下 (如果有) 某个特定的图形元素可以成为鼠标事件的 target.pointer-events 属性值有: /* Keyword values */ po ...

  8. ZROI 19.07.30 简单字符串/ll

    写在前面:今天下午药丸--不会字符串,全程掉线/ll 给出字符串\(S\),\(q\)次询问,每次给出\(a,b,c,d\),询问\(S[a,b]\)的所有子串和\(S[c,d]\)最长公共前缀的最大 ...

  9. vue interceptors(拦截器)

    拦截器 顾名思义: 就是半路个您劫持, 拦截器 其实在项目和自己写demo中,总会遇到请求方面需要在请求头里面做判断或者添加一些东西, 这时候 vue 中应用中axios的 interceptors  ...

  10. Python 时间序列

    Python - 时间处理模块 datetime - 常用模块 官方文档 time calendar