29package com.jogamp.opencl;
32import java.awt.image.BufferedImage;
33import java.io.IOException;
34import java.nio.IntBuffer;
36import javax.imageio.ImageIO;
38import org.junit.BeforeClass;
39import org.junit.FixMethodOrder;
41import org.junit.runners.MethodSorters;
43import com.jogamp.opencl.test.util.MiscUtils;
44import com.jogamp.opencl.test.util.UITestCase;
46import static org.junit.Assert.*;
47import static java.lang.System.*;
48import static com.jogamp.common.nio.Buffers.*;
49import static com.jogamp.opencl.CLImageFormat.ChannelOrder.*;
50import static com.jogamp.opencl.CLImageFormat.ChannelType.*;
56@FixMethodOrder(MethodSorters.NAME_ASCENDING)
59 private static int[] pixels;
62 public static void init() throws IOException {
63 final BufferedImage bi = ImageIO.read(
CLImageTest.class.getResourceAsStream(
"jogamp.png"));
64 pixels =
new int[128*128*4];
65 bi.getData().getPixels(0, 0, 128, 128, pixels);
72 final CLDevice[] devices = platform.listCLDevices();
74 for (
final CLDevice device : devices) {
75 if(device.isImageSupportAvailable()) {
87 final CLDevice device = getCompatibleDevice();
89 out.println(
"WARNING: can not test image api.");
96 assertTrue(formats.length > 0);
97 out.println(
"sample image format: "+formats[0]);
109 final CLDevice device = getCompatibleDevice();
111 out.println(
"WARNING: can not test image api.");
129 final IntBuffer bufferA = imageA.getBuffer();
130 final IntBuffer bufferB = imageB.getBuffer();
132 while(bufferA.hasRemaining()) {
133 assertEquals(bufferA.get(), bufferB.get());
144 final CLDevice device = getCompatibleDevice();
146 out.println(
"WARNING: can not test image api.");
152 "constant sampler_t imageSampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; \n" +
153 "kernel void image2dCopy(read_only image2d_t input, write_only image2d_t output) { \n" +
154 " int2 coord = (int2)(get_global_id(0), get_global_id(1)); \n" +
155 " uint4 temp = read_imageui(input, imageSampler, coord); \n" +
156 " write_imageui(output, coord, temp); \n" +
170 kernel.
putArgs(imageA, imageB);
175 final IntBuffer bufferA = imageA.getBuffer();
176 final IntBuffer bufferB = imageB.getBuffer();
178 while(bufferA.hasRemaining()) {
179 assertEquals(bufferA.get(), bufferB.get());
187 public static void main(
final String[] args)
throws IOException {
188 final String tstname =
CLImageTest.class.getName();
189 org.junit.runner.JUnitCore.
main(tstname);
The command queue is used to queue a set of operations for a specific CLDevice.
CLCommandQueue putWriteImage(final CLImage2d<?> writeImage, final boolean blockingWrite)
Calls {@native clEnqueueWriteImage}.
CLCommandQueue putReadImage(final CLImage2d<?> readImage, final boolean blockingRead)
Calls {@native clEnqueueReadImage}.
CLCommandQueue put2DRangeKernel(final CLKernel kernel, final long globalWorkOffsetX, final long globalWorkOffsetY, final long globalWorkSizeX, final long globalWorkSizeY, final long localWorkSizeX, final long localWorkSizeY)
Calls {@native clEnqueueNDRangeKernel}.
CLCommandQueue putCopyImage(final CLImage2d<?> srcImage, final CLImage2d<?> dstImage)
Calls {@native clEnqueueCopyImage}.
CLContext is responsible for managing objects such as command-queues, memory, program and kernel obje...
CLImageFormat[] getSupportedImage2dFormats(final Mem... flags)
Returns all supported 2d image formats with the (optional) memory allocation flags.
CLProgram createProgram(final String src)
Creates a program from the given sources, the returned program is not build yet.
static CLContext create()
Creates a context on all available devices (CL_DEVICE_TYPE_ALL).
final CLImage2d<?> createImage2d(final int width, final int height, final CLImageFormat format, final Mem... flags)
Creates a CLImage2d with the specified format, dimension and flags.
This object represents an OpenCL device.
CLCommandQueue createCommandQueue()
Test testing CLImage API.
CLDevice getCompatibleDevice()
void supportedImageFormatsTest()
static void main(final String[] args)
void image2dKernelCopyTest()
High level abstraction for an OpenCL Kernel.
CLKernel putArgs(final CLMemory<?>... values)
CLProgram build()
Builds this program for all devices associated with the context.
CLKernel createCLKernel(final String kernelName)
Creates a kernel with the specified kernel name.