JOCL v2.6.0-rc-20250722
JOCL, OpenCL® API Binding for Java™ (public API).
CLImageFormat.java
Go to the documentation of this file.
1/*
2 * Copyright 2009 - 2010 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.opencl.llb.impl.CLImageFormatImpl;
32
33import static com.jogamp.opencl.llb.CL.*;
34
35/**
36 * Represents the OpenCL image format with its channeltype and order.
37 * @author Michael Bien
38 * @see CLContext#getSupportedImage2dFormats(com.jogamp.opencl.CLMemory.Mem[])
39 * @see CLContext#getSupportedImage3dFormats(com.jogamp.opencl.CLMemory.Mem[])
40 */
41public final class CLImageFormat {
42
43 private final CLImageFormatImpl format;
44
46 format = CLImageFormatImpl.create();
47 }
48
49 CLImageFormat(final CLImageFormatImpl format) {
50 this.format = format;
51 }
52
53 public CLImageFormat(final ChannelOrder order, final ChannelType type) {
54 format = CLImageFormatImpl.create();
57 }
58
60 format.setImageChannelOrder(order.ORDER);
61 return this;
62 }
63
65 format.setImageChannelDataType(type.TYPE);
66 return this;
67 }
68
71 }
72
75 }
76
77 /**
78 * Returns the struct accessor for the cl_image_format struct.
79 */
81 return format;
82 }
83
84 @Override
85 public String toString() {
86 return "CLImageFormat["+getImageChannelOrder()+" "+getImageChannelDataType()+"]";
87 }
88
89 @Override
90 public boolean equals(final Object obj) {
91 if (obj == null) {
92 return false;
93 }
94 if (getClass() != obj.getClass()) {
95 return false;
96 }
97 final CLImageFormat other = (CLImageFormat) obj;
99 return false;
100 }
101 if (this.getImageChannelOrder() != other.getImageChannelOrder()) {
102 return false;
103 }
104 return true;
105 }
106
107 @Override
108 public int hashCode() {
109 int hash = 5;
110 hash = 47 * hash + (this.getImageChannelDataType() != null ? this.getImageChannelDataType().hashCode() : 0);
111 hash = 47 * hash + (this.getImageChannelOrder() != null ? this.getImageChannelOrder().hashCode() : 0);
112 return hash;
113 }
114
115 /**
116 * Specifies the number of channels and the channel layout i.e. the memory
117 * layout in which channels are stored in the image.
118 */
119 public enum ChannelOrder {
120
121 /**
122 *
123 */
124 R(CL_R),
125
126 /**
127 *
128 */
129 Rx(CL_Rx),
130
131 /**
132 *
133 */
134 A(CL_A),
135
136 /**
137 *
138 */
139 RG(CL_RG),
140
141 /**
142 *
143 */
144 RGx(CL_RGx),
145
146 /**
147 *
148 */
149 RA(CL_RA),
150
151 /**
152 * This format can only be used if channel data type is one of the following values:
153 * {@link ChannelType#UNORM_SHORT_565}, {@link ChannelType#UNORM_SHORT_555}
154 * or {@link ChannelType#UNORM_INT_101010}.
155 */
156 RGB(CL_RGB),
157
158 /**
159 *
160 */
161 RGBx(CL_RGBx),
162
163 /**
164 *
165 */
166 RGBA(CL_RGBA),
167
168 /**
169 * This format can only be used if channel data type is one of the following values:
170 * {@link ChannelType#UNORM_INT8}, {@link ChannelType#SNORM_INT8}, {@link ChannelType#SIGNED_INT8}
171 * or {@link ChannelType#UNSIGNED_INT8}.
172 */
173 ARGB(CL_ARGB),
174
175 /**
176 * @see #ARGB
177 */
178 BGRA(CL_BGRA),
179
180 /**
181 * This format can only be used if channel data type is one of the following values:
182 * {@link ChannelType#UNORM_INT8}, {@link ChannelType#UNORM_INT16}, {@link ChannelType#SNORM_INT8},
183 * {@link ChannelType#SNORM_INT16}, {@link ChannelType#HALF_FLOAT}, or {@link ChannelType#FLOAT}.
184 */
185 INTENSITY(CL_INTENSITY),
186
187 /**
188 * This format can only be used if channel data type is one of the following values:
189 * {@link ChannelType#UNORM_INT8}, {@link ChannelType#UNORM_INT16}, {@link ChannelType#SNORM_INT8},
190 * {@link ChannelType#SNORM_INT16}, {@link ChannelType#HALF_FLOAT}, or {@link ChannelType#FLOAT}.
191 */
192 LUMINANCE(CL_LUMINANCE);
193
194
195 /**
196 * Value of wrapped OpenCL flag.
197 */
198 public final int ORDER;
199
200 private ChannelOrder(final int order) {
201 this.ORDER = order;
202 }
203
204 public static ChannelOrder valueOf(final int orderFlag) {
205 switch (orderFlag) {
206 case CL_R:
207 return R;
208 case CL_Rx:
209 return Rx;
210 case CL_A:
211 return A;
212 case CL_INTENSITY:
213 return INTENSITY;
214 case CL_LUMINANCE:
215 return LUMINANCE;
216 case CL_RG:
217 return RG;
218 case CL_RGx:
219 return RGx;
220 case CL_RA:
221 return RA;
222 case CL_RGB:
223 return RGB;
224 case CL_RGBx:
225 return RGBx;
226 case CL_RGBA:
227 return RGBA;
228 case CL_ARGB:
229 return ARGB;
230 case CL_BGRA:
231 return BGRA;
232 }
233 return null;
234 }
235
236 }
237
238
239 /**
240 * Describes the size of the channel data type.
241 */
242 public enum ChannelType {
243
244 /**
245 * Each channel component is a normalized signed 8-bit integer value.
246 */
247 SNORM_INT8(CL_SNORM_INT8),
248
249 /**
250 * Each channel component is a normalized signed 16-bit integer value.
251 */
252 SNORM_INT16(CL_SNORM_INT16),
253
254 /**
255 * Each channel component is a normalized unsigned 8-bit integer value.
256 */
257 UNORM_INT8(CL_UNORM_INT8),
258
259 /**
260 * Each channel component is a normalized unsigned 16-bit integer value.
261 */
262 UNORM_INT16(CL_UNORM_INT16),
263
264 /**
265 * Represents a normalized 5-6-5 3-channel RGB image. The channel order must
266 * be {@link ChannelOrder#RGB}.
267 */
268 UNORM_SHORT_565(CL_UNORM_SHORT_565),
269
270 /**
271 * Represents a normalized x-5-5-5 4-channel xRGB image. The channel order must
272 * be {@link ChannelOrder#RGB}.
273 */
274 UNORM_SHORT_555(CL_UNORM_SHORT_555),
275
276 /**
277 * Represents a normalized x-10-10-10 4-channel xRGB image. The channel order
278 * must be {@link ChannelOrder#RGB}.
279 */
280 UNORM_INT_101010(CL_UNORM_INT_101010),
281
282 /**
283 * Each channel component is an unnormalized signed 8-bit integer value.
284 */
285 SIGNED_INT8(CL_SIGNED_INT8),
286
287 /**
288 * Each channel component is an unnormalized signed 16-bit integer value.
289 */
290 SIGNED_INT16(CL_SIGNED_INT16),
291
292 /**
293 * Each channel component is an unnormalized signed 32-bit integer value.
294 */
295 SIGNED_INT32(CL_SIGNED_INT32),
296
297 /**
298 * Each channel component is an unnormalized unsigned 8-bit integer value.
299 */
300 UNSIGNED_INT8(CL_UNSIGNED_INT8),
301
302 /**
303 * Each channel component is an unnormalized unsigned 16-bit integer value.
304 */
305 UNSIGNED_INT16(CL_UNSIGNED_INT16),
306
307 /**
308 * Each channel component is an unnormalized unsigned 32-bit integer value.
309 */
310 UNSIGNED_INT32(CL_UNSIGNED_INT32),
311
312 /**
313 * Each channel component is a 16-bit half-float value.
314 */
315 HALF_FLOAT(CL_HALF_FLOAT),
316
317 /**
318 * Each channel component is a single precision floating-point value.
319 */
320 FLOAT(CL_FLOAT);
321
322 /**
323 * Value of wrapped OpenCL flag.
324 */
325 public final int TYPE;
326
327 private ChannelType(final int channel) {
328 this.TYPE = channel;
329 }
330
331 public static ChannelType valueOf(final int channelFlag) {
332 switch (channelFlag) {
333 case CL_SNORM_INT8:
334 return SNORM_INT8;
335 case CL_SNORM_INT16:
336 return SNORM_INT16;
337 case CL_UNORM_INT8:
338 return UNORM_INT8;
339 case CL_UNORM_INT16:
340 return UNORM_INT16;
341 case CL_UNORM_SHORT_565:
342 return UNORM_SHORT_565;
343 case CL_UNORM_SHORT_555:
344 return UNORM_SHORT_555;
345 case CL_UNORM_INT_101010:
346 return UNORM_INT_101010;
347 case CL_SIGNED_INT8:
348 return SIGNED_INT8;
349 case CL_SIGNED_INT16:
350 return SIGNED_INT16;
351 case CL_SIGNED_INT32:
352 return SIGNED_INT32;
353 case CL_UNSIGNED_INT8:
354 return UNSIGNED_INT8;
355 case CL_UNSIGNED_INT16:
356 return UNSIGNED_INT16;
357 case CL_UNSIGNED_INT32:
358 return UNSIGNED_INT32;
359 case CL_HALF_FLOAT:
360 return HALF_FLOAT;
361 case CL_FLOAT:
362 return FLOAT;
363 }
364 return null;
365 }
366
367 }
368}
Represents the OpenCL image format with its channeltype and order.
boolean equals(final Object obj)
CLImageFormat(final ChannelOrder order, final ChannelType type)
CLImageFormat setImageChannelDataType(final ChannelType type)
CLImageFormat setImageChannelOrder(final ChannelOrder order)
CLImageFormatImpl getFormatImpl()
Returns the struct accessor for the cl_image_format struct.
Struct accessor for cl_image_format.
static CLImageFormatImpl create()
Returns a new instance with all bytes set to zero.
final CLImageFormatImpl setImageChannelDataType(int src)
Setter for native field imageChannelDataType, being a struct owned IntType.
final int getImageChannelDataType()
Getter for native field imageChannelDataType, being a struct owned IntType.
final int getImageChannelOrder()
Getter for native field imageChannelOrder, being a struct owned IntType.
final CLImageFormatImpl setImageChannelOrder(int src)
Setter for native field imageChannelOrder, being a struct owned IntType.
Specifies the number of channels and the channel layout i.e.
final int ORDER
Value of wrapped OpenCL flag.
INTENSITY
This format can only be used if channel data type is one of the following values: ChannelType#UNORM_I...
LUMINANCE
This format can only be used if channel data type is one of the following values: ChannelType#UNORM_I...
RGB
This format can only be used if channel data type is one of the following values: ChannelType#UNORM_S...
ARGB
This format can only be used if channel data type is one of the following values: ChannelType#UNORM_I...
static ChannelOrder valueOf(final int orderFlag)
Describes the size of the channel data type.
UNSIGNED_INT8
Each channel component is an unnormalized unsigned 8-bit integer value.
UNORM_INT8
Each channel component is a normalized unsigned 8-bit integer value.
HALF_FLOAT
Each channel component is a 16-bit half-float value.
static ChannelType valueOf(final int channelFlag)
UNORM_SHORT_555
Represents a normalized x-5-5-5 4-channel xRGB image.
UNSIGNED_INT32
Each channel component is an unnormalized unsigned 32-bit integer value.
SNORM_INT16
Each channel component is a normalized signed 16-bit integer value.
UNORM_SHORT_565
Represents a normalized 5-6-5 3-channel RGB image.
UNORM_INT_101010
Represents a normalized x-10-10-10 4-channel xRGB image.
SIGNED_INT32
Each channel component is an unnormalized signed 32-bit integer value.
UNSIGNED_INT16
Each channel component is an unnormalized unsigned 16-bit integer value.
SIGNED_INT8
Each channel component is an unnormalized signed 8-bit integer value.
final int TYPE
Value of wrapped OpenCL flag.
UNORM_INT16
Each channel component is a normalized unsigned 16-bit integer value.
SNORM_INT8
Each channel component is a normalized signed 8-bit integer value.
FLOAT
Each channel component is a single precision floating-point value.
SIGNED_INT16
Each channel component is an unnormalized signed 16-bit integer value.