|
Hi,
Only half of the image is copied using the following Jocl and OpneCL kernel code.
main program related code lines and OpneCL kernel is shown below.
Thanks a lot.
Main program code (only related code)
-----------------------------------------
....
//load image
BufferedImage image = readImage("lena.png");
assert image.getColorModel().getNumComponents() == 3;
//Image dimensions
int imageWidth = image.getWidth();
int imageHeight = image.getHeight();
//Output image
BufferedImage outputImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
//Create the memory object for the input- and output image
int[] pixels = image.getRaster().getPixels(0, 0, imageWidth, imageHeight, (int[])null);
CLImageFormat format = new CLImageFormat(INTENSITY, UNSIGNED_INT32);
System.out.println("Pixels length: "+pixels.length);
CLImage2d<IntBuffer> imageA = defaultContext.createImage2d(newDirectIntBuffer(pixels), imageWidth, imageHeight, format,READ_ONLY);
CLImage2d<IntBuffer> imageB = defaultContext.createImage2d(newDirectIntBuffer(pixels.length), imageWidth, imageHeight, format,WRITE_ONLY);
CLCommandQueue queue = device.createCommandQueue();
int localWorkSize = Integer.parseInt(args[0]);
int globalWorkSize = imageWidth;
//Setup kernel
kernel.putArgs(imageA,imageB); kernel.putArg(globalWorkSize); kernel.putArg(globalWorkSize);
queue.putWriteImage(imageA, false);
queue.put2DRangeKernel(kernel, 0, 0, globalWorkSize, globalWorkSize, localWorkSize, localWorkSize);
queue.putReadImage(imageB,true);
Kernel Code
----------------------
constant sampler_t imageSampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;
kernel void gamma(read_only image2d_t inputImg, write_only image2d_t outputImg, int ImageWidth, int ImageHeight)
{
int x = get_global_id(0);
int y = get_global_id(1);
if((x >= ImageWidth) || (y>= ImageHeight)) {
return;
}
else
{
int2 coord = (int2)(x,y);
uint4 result = read_imageui(inputImg, imageSampler, coord);
write_imageui(outputImg, coord, result);
}
}
|