JOCL v2.6.0-rc-20250722
JOCL, OpenCL® API Binding for Java™ (public API).
CLImage.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opencl;
30
31import com.jogamp.common.nio.PointerBuffer;
32import com.jogamp.opencl.impl.CLTLInfoAccessor;
33import com.jogamp.opencl.llb.CL;
34import java.nio.Buffer;
35
36import static com.jogamp.opencl.llb.CL.*;
37
38/**
39 *
40 * @author Michael Bien, et al.
41 */
42public abstract class CLImage<B extends Buffer> extends CLMemory<B> {
43
45
46 final CLTLInfoAccessor imageInfo;
47
48 public final int width;
49 public final int height;
50
51 protected CLImage(final CLContext context, final B directBuffer, final CLImageFormat format, final int width, final int height, final long id, final int flags) {
52 this(context, directBuffer, format, createAccessor(context, id), width, height, id, flags);
53 }
54
55 protected CLImage(final CLContext context, final B directBuffer, final CLImageFormat format, final CLImageInfoAccessor accessor, final int width, final int height, final long id, final int flags) {
56 super(context, directBuffer, getSizeImpl(context, id), id, flags);
57 this.imageInfo = accessor;
58 this.format = format;
59 this.width = width;
60 this.height = height;
61 }
62
63 private static CLImageInfoAccessor createAccessor(final CLContext context, final long id) {
64 return new CLImageInfoAccessor(context.getPlatform().getCLBinding(), id);
65 }
66
68 return new CLImageFormat();
69 }
70
71 /**
72 * Returns the image format descriptor specified when image was created.
73 */
75 return format;
76 }
77
78 /**
79 * Returns the size of each element of the image memory object given by image.
80 * An element is made up of n channels. The value of n is given in {@link CLImageFormat} descriptor.
81 */
82 @Override
83 public int getElementSize() {
84 return (int)imageInfo.getLong(CL_IMAGE_ELEMENT_SIZE);
85 }
86
87 /**
88 * Returns the size in bytes of a row of elements of the image object given by image.
89 */
90 public int getRowPitch() {
91 return (int)imageInfo.getLong(CL_IMAGE_ROW_PITCH);
92 }
93
94 /**
95 * Returns width of this image in pixels.
96 */
97 public int getWidth() {
98 return width;
99 }
100
101 /**
102 * Returns the height of this image in pixels.
103 */
104 public int getHeight() {
105 return height;
106 }
107
108
109 protected final static class CLImageInfoAccessor extends CLTLInfoAccessor {
110
111 private final long id;
112 private final CL cl;
113
114 public CLImageInfoAccessor(final CL cl, final long id) {
115 this.cl = cl;
116 this.id = id;
117 }
118 @Override
119 public int getInfo(final int name, final long valueSize, final Buffer value, final PointerBuffer valueSizeRet) {
120 return cl.clGetImageInfo(id, name, valueSize, value, valueSizeRet);
121 }
122 }
123
124
125}
CLContext is responsible for managing objects such as command-queues, memory, program and kernel obje...
Definition: CLContext.java:79
CLPlatform getPlatform()
Returns the CLPlatform this context is running on.
Definition: CLContext.java:569
Represents the OpenCL image format with its channeltype and order.
int getInfo(final int name, final long valueSize, final Buffer value, final PointerBuffer valueSizeRet)
Definition: CLImage.java:119
CLImageInfoAccessor(final CL cl, final long id)
Definition: CLImage.java:114
CLImageFormat getFormat()
Returns the image format descriptor specified when image was created.
Definition: CLImage.java:74
static CLImageFormat createUninitializedImageFormat()
Definition: CLImage.java:67
CLImage(final CLContext context, final B directBuffer, final CLImageFormat format, final CLImageInfoAccessor accessor, final int width, final int height, final long id, final int flags)
Definition: CLImage.java:55
int getElementSize()
Returns the size of each element of the image memory object given by image.
Definition: CLImage.java:83
int getWidth()
Returns width of this image in pixels.
Definition: CLImage.java:97
int getRowPitch()
Returns the size in bytes of a row of elements of the image object given by image.
Definition: CLImage.java:90
int getHeight()
Returns the height of this image in pixels.
Definition: CLImage.java:104
CLImageFormat format
Definition: CLImage.java:44
CLImage(final CLContext context, final B directBuffer, final CLImageFormat format, final int width, final int height, final long id, final int flags)
Definition: CLImage.java:51
Common superclass for all OpenCL memory types.
Definition: CLMemory.java:49
static long getSizeImpl(final CLContext context, final long id)
Definition: CLMemory.java:91
Internal utility for common OpenCL clGetFooInfo calls.
final long getLong(final int key)
Returns the long value for the given key.
Java bindings to OpenCL, the Open Computing Language.
Definition: CL.java:26
int clGetImageInfo(long image, int param_name, long param_value_size, Buffer param_value, PointerBuffer param_value_size_ret)
Interface to C language function: cl_int {@native clGetImageInfo}(cl_mem image, cl_image_info param...