日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內(nèi)最全I(xiàn)T社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php框架 > 框架設(shè)計(jì) > OpenCL之圖片旋轉(zhuǎn)的實(shí)現(xiàn)

OpenCL之圖片旋轉(zhuǎn)的實(shí)現(xiàn)

來源:程序員人生   發(fā)布時(shí)間:2015-05-13 08:51:11 閱讀次數(shù):4217次

  • 原理
  • 前期
  • kernel
  • 配置文件
  • 效果
  • 參考

這里做的就是使用OpenCL對圖象旋轉(zhuǎn)90度,也算是1個(gè)比較入門級別的程序。希望對大家有所幫助吧,看著看著這些代碼就熟習(xí)了。

原理

圖象旋轉(zhuǎn)是指把定義的圖象繞某1點(diǎn)以逆時(shí)針或順時(shí)針方向旋轉(zhuǎn)1定的角度,通常是指繞圖象的中心以逆時(shí)針方向旋轉(zhuǎn)。假定圖象的左上角為(left, top),右下角為(right, bottom),則圖象上任意點(diǎn)(x0, y0) 繞其中心(xcenter, ycenter) 逆時(shí)針旋轉(zhuǎn)angle 角度后,新的坐標(biāo)位置(x′, y′) 的計(jì)算公式為:

公式

前期

需要對圖象進(jìn)行處理,那末在這里介紹1個(gè)庫給大家:FreeImage。
不熟習(xí)的請看:請點(diǎn)這里。
使用這個(gè)庫的方法:(通用方法,極有效)

  • 屬性->C/C++->常規(guī)->附加包括目錄:添加.h的路徑。

  • 鏈接器->常規(guī)->附加庫目錄: 添加lib路徑。

  • 鏈接器->輸入->附加依賴項(xiàng): 添加需要的lib名稱。

  • 將dll文件放入exe路徑下。

kernel

#pragma OPENCL EXTENSION cl_amd_printf : enable __kernel void image_rotate( __global uchar * src_data, __global uchar * dest_data, //Data in global memory int W, int H, //Image Dimensions float sinTheta, float cosTheta ) //Rotation Parameters { //Thread gets its index within index space const int ix = get_global_id(0); const int iy = get_global_id(1); int xc = W/2; int yc = H/2; int xpos = ( ix-xc)*cosTheta - (iy-yc)*sinTheta+xc; int ypos = ( ix-xc)*sinTheta + (iy-yc)*cosTheta+yc; if ((xpos>=0) && (xpos< W) && (ypos>=0) && (ypos< H)) //Bound Checking { dest_data[ypos*W+xpos]= src_data[iy*W+ix]; } }

我們把這個(gè)東西和CPU串行處理比較1下可以得到以下:

//CPU旋轉(zhuǎn)圖象:使用CPU來旋轉(zhuǎn)圖片 void cpu_rotate(unsigned char* inbuf, unsigned char* outbuf, int w, int h,float sinTheta, float cosTheta) { int i, j; int xc = w/2; int yc = h/2; for(i = 0; i < h; i++) { for(j=0; j< w; j++) { int xpos = ( j-xc)*cosTheta - (i-yc)*sinTheta+xc; int ypos = (j-xc)*sinTheta + ( i-yc)*cosTheta+yc; if(xpos>=0&&ypos>=0&&xpos<w&&ypos<h) outbuf[ypos*w + xpos] = inbuf[i*w+j]; } } }

對照以后我們發(fā)現(xiàn)OpenCL寫kernel的時(shí)候循環(huán)沒有了,取而代之的就是給出global_id便可。

配置文件

這里還觸及到1些圖片的操作,具體請看FreeImage的使用。

#include "stdafx.h" #include <CL/cl.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <iostream> #include <fstream> #include "gFreeImage.h" using namespace std; #define NWITEMS 4 #pragma comment (lib,"OpenCL.lib") #pragma comment (lib,"FreeImage.lib") //把文本文件讀入1個(gè)string中,其實(shí)就是把運(yùn)行程序傳給從機(jī) int convertToString(const char *filename, std::string& s) { size_t size; char* str; std::fstream f(filename, (std::fstream::in | std::fstream::binary)); if(f.is_open()) { size_t fileSize; f.seekg(0, std::fstream::end); size = fileSize = (size_t)f.tellg(); f.seekg(0, std::fstream::beg); str = new char[size+1]; if(!str) { f.close(); return NULL; } f.read(str, fileSize); f.close(); str[size] = ' 主站蜘蛛池模板: 国产精品成人一区 | 三级波多野结衣护士三级 | 999成人免费视频 | 国产成人网 | 欧美人与性动交α欧美精品济南到 | 国产欧美精品区一区二区三区 | 精品一区二区三区视频 | 日韩一区二区三区视频 | www.69国产| 天天干天天插 | 国产黄色三级毛片 | 国产香蕉视频在线播放 | 三级视频网站 | 精品久久久久一区二区国产 | 久久高清免费 | 动漫一区二区 | 可以免费看的av网站 | 亚洲欧美日韩在线一区 | 色区综合 | 成视频年人免费看黄网站 | 日韩伦理一区二区 | 成人黄色一级毛片 | 成人综合婷婷国产精品 | 久久国产精品99精国产 | 国产精品一区一区 | 亚洲一级一级 | 91看片淫黄大片 | 国产三级久久久 | 91亚洲精品乱码久久久久久蜜桃 | 亚洲第一视频 | 亚洲欧美日韩天堂 | 久久桃色| 亚洲人成人一区二区在线观看 | 国产一二视频 | 天堂av一区二区三区在线播放 | 日本福利在线观看 | 国产精品岛国久久久久久 | 精品欧美| 韩国日本美国免费毛片 | 精品一二区 | 哪里有毛片网站 |