本文整理汇总了C++中cl::CommandQueue::enqueueCopyBufferToImage方法的典型用法代码示例。如果您正苦于以下问题:C++ CommandQueue::enqueueCopyBufferToImage方法的具体用法?C++ CommandQueue::enqueueCopyBufferToImage怎么用?C++ CommandQueue::enqueueCopyBufferToImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cl::CommandQueue
的用法示例。
在下文中一共展示了CommandQueue::enqueueCopyBufferToImage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: laplacian
/**
* Computes the laplacian of the gaussian convolution
* with an image (using openCL).
* @param ctx An openCL context object.
* @param cmdQueue An openCL command queue.
* @param inputImage The image to blur
* @param energyMatrix An openCL buffer to store the output in.
* @param sampler An openCL image sampler object.
* @param height The height of the input image.
* @param width The width of the input image.
* @return A buffer containing the gradient interpreted as a matrix of size height * width.
*/
void laplacian(cl::Context &ctx,
cl::CommandQueue &cmdQueue,
cl::Image2D &inputImage,
cl::Buffer &energyMatrix,
cl::Sampler &sampler,
int height,
int width) {
// Setup kernel
cl::Kernel kernel = setup::kernel(ctx, std::string("LaplacianGaussianKernel.cl"),
std::string("gaussian_laplacian"));
cl_int errNum;
// Set kernel arguments
errNum = kernel.setArg(0, inputImage);
errNum |= kernel.setArg(1, energyMatrix);
errNum |= kernel.setArg(2, sampler);
errNum |= kernel.setArg(3, width);
errNum |= kernel.setArg(4, height);
if (errNum != CL_SUCCESS) {
std::cerr << "Error setting laplacian kernel arguments." << std::endl;
exit(-1);
}
cl::NDRange offset = cl::NDRange(0, 0);
cl::NDRange localWorkSize = cl::NDRange(16, 16);
cl::NDRange globalWorkSize = cl::NDRange(math::roundUp(localWorkSize[0], width),
math::roundUp(localWorkSize[1], height));
errNum = cmdQueue.enqueueNDRangeKernel(kernel,
offset,
globalWorkSize,
localWorkSize);
if (errNum != CL_SUCCESS) {
std::cerr << "Error enqueuing laplacian kernel for execution." << std::endl;
exit(-1);
}
// TODO(amidvidy): make this debugging code
// Read data into an image object
cl::Image2D gradientImage = cl::Image2D(ctx,
(cl_mem_flags) CL_MEM_READ_WRITE,
cl::ImageFormat(CL_INTENSITY, CL_FLOAT),
width,
height,
0,
NULL,
&errNum);
if (errNum != CL_SUCCESS) {
std::cerr << "Error creating laplacian output image" << std::endl;
exit(-1);
}
cl::size_t<3> origin;
origin.push_back(0);
origin.push_back(0);
origin.push_back(0);
cl::size_t<3> region;
region.push_back(width);
region.push_back(height);
region.push_back(1);
errNum = cmdQueue.enqueueCopyBufferToImage(energyMatrix,
gradientImage,
0,
origin,
region,
NULL,
NULL);
if (errNum != CL_SUCCESS) {
std::cerr << "Error copying laplacian image from buffer" << std::endl;
std::cerr << "ERROR_CODE = " << errNum << std::endl;
}
image::save(cmdQueue, gradientImage, std::string("gradient_output.tif"), height, width);
/** END DEBUGGING */
} // End of laplacian method.