当前位置: 首页>>代码示例>>C++>>正文


C++ PNG::Free方法代码示例

本文整理汇总了C++中PNG::Free方法的典型用法代码示例。如果您正苦于以下问题:C++ PNG::Free方法的具体用法?C++ PNG::Free怎么用?C++ PNG::Free使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PNG的用法示例。


在下文中一共展示了PNG::Free方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int arg, char* args[])
{
	int filterWidth = 10;
	int filterHeight = 10;
	int platformId = 0;
	if (arg > 1)
	{
		platformId = atoi(args[1]);
	}
	if (arg > 3)
	{
		filterWidth = std::atoi(args[2]);
		filterHeight = std::atoi(args[3]);
	}

	std::vector<cl::Platform> platforms;
	cl::Platform::get(&platforms);
	if (platforms.size() == 0)
	{
		std::cout << "No OpenCL platforms found" << std::endl;//This means you do not have an OpenCL compatible platform on your system.
		exit(1);
	}
	std::vector<cl::Device> devices;
	platforms[platformId].getDevices(CL_DEVICE_TYPE_ALL, &devices);
	cl::Device device = devices[0];
	std::cout << "Using device: " << device.getInfo<CL_DEVICE_NAME>() << std::endl;
	std::cout << "Using platform: " << platforms[platformId].getInfo<CL_PLATFORM_NAME>() << std::endl;
	cl::Context context(device);

	//load our image
	PNG inPng("Lenna.png");

	//store width and height so we can use them for our output image later
	const unsigned int w = inPng.w;
	const unsigned int h = inPng.h;

	//input image
	const cl::ImageFormat format(CL_RGBA, CL_UNSIGNED_INT8);
	cl::Image2D in(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, format, w, h, 0, &inPng.data[0]);

	//we are done with the image so free up its memory
	inPng.Free();

	//output image
	cl::Image2D out(context, CL_MEM_WRITE_ONLY, format, w, h, 0, NULL);

	cl::Program::Sources sources;
	std::string kernel_code = readFile("cl_tutorial_3_boxFilter.cl");
	//Add your program source
	sources.push_back({ kernel_code.c_str(),kernel_code.length() });

	//Create your OpenCL program and build it.
	cl::Program program(context, sources);
	if (program.build({ device }) != CL_SUCCESS)
	{
		std::cout << " Error building: " << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(device) << std::endl;//print the build log to find any issues with your source
		exit(1);//Quit if your program doesn't compile
	}

	//create command queue
	cl::CommandQueue queue(context, device, CL_QUEUE_PROFILING_ENABLE, NULL);

	//set the kernel arguments
	cl::Kernel kernelboxFilter(program, "boxFilter");
	kernelboxFilter.setArg(0, in);
	kernelboxFilter.setArg(1, out);
	kernelboxFilter.setArg(2, w);
	kernelboxFilter.setArg(3, h);
	kernelboxFilter.setArg(4, filterWidth);
	kernelboxFilter.setArg(5, filterHeight);

	cl::Event timer;

	//execute kernel
	queue.enqueueNDRangeKernel(kernelboxFilter, cl::NullRange, cl::NDRange(w, h), cl::NullRange, NULL, &timer);

	//wait for kernel to finish
	timer.wait();

	cl_ulong time_start, time_end;
	double total_time;

	time_start = timer.getProfilingInfo<CL_PROFILING_COMMAND_START>();
	time_end = timer.getProfilingInfo<CL_PROFILING_COMMAND_END>();
	total_time = time_end - time_start;

	printf("\nExecution time in milliseconds = %0.3f ms\n", (total_time / 1000000.0));

	//start and end coordinates for reading our image (I really do not like how the c++ wrapper does this)
	cl::size_t<3> origin;
	cl::size_t<3> size;
	origin[0] = 0;
	origin[1] = 0;
	origin[2] = 0;
	size[0] = w;
	size[1] = h;
	size[2] = 1;

	//output png
	PNG outPng;
//.........这里部分代码省略.........
开发者ID:Ragmest,项目名称:OpenCL-CUDA-Tutorials,代码行数:101,代码来源:main.cpp


注:本文中的PNG::Free方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。