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 ... 
随机推荐
- java 并发编程lock使用详解
			浅谈Synchronized: synchronized是Java的一个关键字,也就是Java语言内置的特性,如果一个代码块被synchronized修饰了,当一个线程获取了对应的锁,执行代码块时,其 ... 
- 万兴神剪手 Wondershare Filmora v9.2.11.6 简体中文版
			目录 1. 介绍 2. 简体中文9.2.1.10汉化版下载 3. 安装和激活说明 1. 介绍 万兴神剪手 Filmora 是一款界面简洁时尚.功能强大的视频编辑软件,它是深圳万兴科技公司近年来的代表作 ... 
- centos7安装部署jumpserver
			一.系统环境准备1.查看系统版本 # cat /etc/redhat-release // 查看系统版本 CentOS Linux release (Core) # uname -a // 查看系统信 ... 
- jQuery+Ajax实现图片的预览和上传
			jQuery+Ajax实现图片的预览和上传 1.配置Spring-web.xml <!-- springmvc上传图片 --> <bean id="multipartRes ... 
- linux 下 SpiderMonkey 1.7.0 编译和安装
			wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz tar xf js-1.7.0.tar.gz cd js/src make ... 
- AIX中的服务管理
			1.SRC AIX系统使用资源控制器(SRC,system resource controller),控制各种服务子系统,包括启动,停止进程,搜集进程状态信息等. AIX系统中服务有子系统组 ... 
- [DllImport("kernel32.dll")]使用
			C#中读取ini配置文件 [DllImport("kernel32.dll")] using System;using System.Collections.Generic;usi ... 
- 【洛谷P2447】外星千足虫
			题目大意:给定一个 M 个含 N 个未知数的异或方程组,保证有解,若存在唯一解,给出至少需要几个方程才能得出唯一解,若不存在,直接输出不存在. 题解:异或方程组也满足类似初等行变换的操作,只不过所有的 ... 
- HDU-2389-Rain on your Parade (最大匹配,kopcroft-karp)
			链接: https://vjudge.net/problem/HDU-2389 题意: You're giving a party in the garden of your villa by the ... 
- Docker(四):Docker常用命令
			除过以上我们使用的Docker命令外,Docker还有一些其它常用的命令 拉取docker镜像 docker pull image_name 查看宿主机上的镜像,Docker镜像保存在/var/lib ... 
