In the previous chapter, we computed the RGB histogram of an input image on an OpenCL buffer object. In this chapter, we will discuss the same with input as an OpenCL image object. The input image is read into a contiguous buffer and an image object is created using the clCreateImage
function. At the kernel side the pixel values can be sampled using read_image
OpenCL built-in. The next diagram illustrates how an image is read and processed in the example code. The input image from the file system is read into a contiguous buffer, row wise as shown by step 1 in the diagram. The input image can be of any format BMP, PNG, or JPEG. The raw image pixel buffer is then used to create an OpenCL image object using the clCreateImage
function. The CL_MEM_USE_HOST_PTR flag is passed. This is shown as step 2 in the diagram. Finally each kernel instance executes on the image buffer as shown by step 3.
Take a look at the following histogram_image_kernel OpenCL kernel. This kernel...