Image Read and Write Functions

Built-in functions to read, write, and query image memory objects. Click an item in the table below for details about that function.

read_imagef for 1D Do an element lookup in the 1D image object with or without a sampler, returning floating-point values (including optional mipmap support).
read_image{i|ui} for 1D Do an element lookup in the 1D image object with or without a sampler, returning unnormalized signed integer and unsigned integer values (including optional mipmap support).
read_imageh for 1D OPTIONAL function to do an element lookup in the 1D image object with or without a sampler, returning floating-point values. Enabled with cl_khr_fp16.
write_image {f|i|ui|h} for 1D Write color value to location in the 2D image object (including optional mipmap support). The half type is enabled with cl_khr_fp16.
read_imagef for 2D Do an element lookup in the 2D image object with or without a sampler, returning floating-point values (including optional mipmap support).
read_image{i|ui} for 2D Do an element lookup in the 2D image object with or without a sampler, returning unnormalized signed integer and unsigned integer values (including optional mipmap support).
read_imageh for 2D OPTIONAL function to do an element lookup in the 2D image object with or without a sampler, returning floating-point values. Enabled with cl_khr_fp16.
write_image {f|i|ui|h} for 2D Write color value to location in the 2D image object (including optional mipmap support). The half type is enabled with cl_khr_fp16.
read_imagef for 3D Do an element lookup in the 3D image object with or without a sampler, returning floating-point values (including optional mipmap support).
read_image{i|ui} for 3D Do an element lookup in the 3D image object with or without a sampler, returning unnormalized signed integer and unsigned integer values (including optional mipmap support).
read_imageh for 3D OPTIONAL function to do an element lookup in the 3D image object with or without a sampler, returning floating-point values. Enabled with cl_khr_fp16.
write_image {f|i|ui|h} for 3D Write color value to location in the 2D image object (including optional mipmap support). The half type is enabled with cl_khr_fp16.
get_image_width Return the image width in pixels
get_image_height Return the image height in pixels.
get_image_depth Return the 3D image depth in pixels
get_image_channel_data_type Return the image channel data type
get_image_channel_order Return the image channel order
get_image_dim Return the image dimensions
get_image_array_size Return the number of images in an image array
get_image_num_mip_levels Return the number of mip-levels. Enabled with extension cl_khr_mipmap_image
get_image_num_samples Return the number of samples in the 2D MSAA image. Enabled with extension cl_khr_gl_msaa_sharing

Notes

The built-in functions defined in this section can only be used with image memory objects. An image memory object can be accessed by specific function calls that read from and/or write to specific locations in the image.

Note that image writes to sRGB images are only supported if the cl_khr_srgb_image_writes extension is supported; otherwise the behavior of writing to a sRGB image is undefined.

Image memory objects that are being read by a kernel should be declared with the read_only qualifier. write_image calls to image memory objects declared with the read_only qualifier will generate a compilation error. Image memory objects that are being written to by a kernel should be declared with the write_only qualifier. read_image calls to image memory objects declared with the write_only qualifier will generate a compilation error. read_image and write_image calls to the same image memory object in a kernel are not supported. Image memory objects that are being read and written by a kernel should be declared with the read_write qualifier.

The read_image calls returns a four component floating-point, integer or unsigned integer color value. The color values returned by read_image are identified as x, y, z, w where x refers to the red component, y refers to the green component, z refers to the blue component and w refers to the alpha component.

sRGB Images

The built-in image read functions will perform sRGB to linear RGB conversions if the image is an sRGB image. Writing to sRGB images from a kernel is an optional extension. The cl_khr_srgb_image_writes extension will be reported in the CL_DEVICE_EXTENSIONS string if a device supports writing to sRGB images using write_imagef. clGetSupportedImageFormats will return the supported sRGB images if CL_MEM_READ_WRITE or CL_MEM_WRITE_ONLY is specified in flags argument and the device supports writing to an sRGB image. If cl_khr_srgb_image_writes is supported, the built-in image write functions will perform the linear to sRGB conversion.

Only the R, G and B components are converted from linear to sRGB and vice-versa. The alpha component is returned as is.

The samplerless read image functions behave exactly as the corresponding read image functions that take integer coordinates and a sampler with filter mode set to CLK_FILTER_NEAREST, normalized coordinates set to CLK_NORMALIZED_COORDS_FALSE and addressing mode to CLK_ADDRESS_NONE.

Specification

OpenCL Specification

Also see

sampler_t, cl_khr_3d_image_writes, cl_khr_mipmap_image

Copyright © 2007-2013 The Khronos Group Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.