BitmapImage clRotate(ClCmdQueue& queue, cl::KernelFunctor& rotate, BitmapImage& srcImg, float sinTheta, float cosTheta) throw (cl::Error) { BitmapImage outImg; outImg.resize(srcImg.getWidth(), srcImg.getHeight()); // Create the input, output image, and filter buffers! cl::Image2D srcBuf = queue.makeImage(srcImg.getRow(0), srcImg.getWidth(), srcImg.getHeight(), queue.ROFlags); cl::Image2D outBuf = queue.makeImage(outImg.getRow(0), outImg.getWidth(), outImg.getHeight(), queue.WOFlags); // Setup sampler for source image to control sampler cl::Sampler sampler(queue.getContext(), CL_FALSE, CL_ADDRESS_CLAMP, CL_FILTER_LINEAR); // Now use the OpenCl kernel to perform convolution rotate(srcBuf, outBuf, srcImg.getWidth(), srcImg.getHeight(), sampler, sinTheta, cosTheta); // Copy result image back from the device to host. queue.enqueueMapImage(outBuf); // Return the resulting image back to the caller. return outImg; }
BitmapImage clRotate(ClCmdQueue& queue, cl::KernelFunctor& vrotate, BitmapImage& srcImg, float theta) throw (cl::Error) { // Create a new bitmap and scale it BitmapImage outImg = srcImg; float imgMax = sqrt(pow(srcImg.getWidth(),2) + pow(srcImg.getHeight(),2)); outImg.resize(imgMax, imgMax); // Create the input, output image, and filter buffers! cl::Image2D srcBuf = queue.makeImage(srcImg.getRow(0), srcImg.getWidth(), srcImg.getHeight(), queue.ROFlags); cl::Image2D outBuf = queue.makeImage(outImg.getRow(0), outImg.getWidth(), outImg.getHeight(), queue.WOFlags); // Setup sampler for source image to control sampler cl::Sampler sampler(queue.getContext(), CL_FALSE, CL_ADDRESS_CLAMP, CL_FILTER_NEAREST); // Now use the OpenCl kernel to perform convolution vrotate(srcBuf, outBuf, outImg.getWidth(), outImg.getHeight(), sampler, (float)cos(theta), (float)sin(theta)); // Copy result image back from the device to host. queue.enqueueMapImage(outBuf); // Return the resulting image back to the caller. return outImg; }