This is still a study note, the focus of knowledge is to grasp the finish and then knock again better.
OpenEXR through Rgbainputfile This interface to read the RGBA only image file information, the interface through the DataWindow () method to obtain the image boundary coordinate information, through the boundary coordinate information can calculate the image heigth and width.
The data for the image file at this time is not stored in the OPENEXR standard, how does OPENEXR standardize the data? First, define a array2d<rgba> template &pixels,pixels is a reference to an array and then unify the array with the image data through Pixels.resizeerase (height,width). Setting the width-height format of the array, Pixels.resizeerase (height,width) is equivalent to allocating a nominal size space for the array in memory, which is the same as the width and height of the image.
The next step is to map each element of the pixels to each pixel in the image. With File.setframebuffer (pixels,1,width), you can create a pointer for each image pixel, which is stored in the pixels array, and these addresses are contiguous. When we want to access some part of the image data, we can do so by accessing the pointers in the array. For example: Pixels[x][y] You can get a pointer address for a pixel with coordinates (x, y). This protects both the primitive nature of the image data and the flexibility of access. The design of the OPENEXR is indeed in place. Of course, this design is the same as OpenGL.
The next step is to call the File.readpixels (dw.min.y,dw.max.y) and copy the pixels between DW.MIN.Y and dw.max.y to buffer. Since the address recorded in the array is continuous, this design is more suitable for the multi-level buffering characteristics of the CPU, which is an assurance that the image can be processed efficiently.
The above is the simplest use of the OpenEXR Rgbainputfile interface. In the actual work, we just want to see a part of the image, this time we need to take advantage of the characteristics of OpenEXR-clan access.
This example is given in the unit reading an RGBA Image File in chunks:
voidReadRgba2 (Const Charfilename[]) {rgbainputfile file (fileName); Box2i DW=File.datawindow (); intwidth = dw.max.x-dw.min.x +1; intHeight = dw.max.y-dw.min.y +1; Array2D<Rgba> Pixels (Ten, width); while(DW.MIN.Y <=dw.max.y) {File.setframebuffer (&pixels[0][0]-DW.MIN.X-DW.MIN.Y * width,1, width); File.readpixels (DW.MIN.Y, min (dw.min.y+9, dw.max.y));//processpixels (pixels)DW.MIN.Y + =Ten; }}
This code is analyzed below:
First, declare a rgbainputfile function, in which the first definition of a Rgbainputfile class named file is used to read the image information.
It then defines a Box2i object named DW that obtains the boundary information for the image through the DataWindow () method.
The width and height of the image are calculated by the boundary information.
A array2d<> template is used to define an array that is applied to the RGBA struct. The array is named pixels. We also note that the array has a height range of only 10, meaning that the array stores only 10 rows of image data. This is not the same as creating an array that stores all the rows previously. The arrays that are now created clearly take up less storage space and are more flexible in buffer. This means that the CPU cache mechanism is not so powerful that the computer can still easily use the Rgbainputfile interface.
The next piece of code introduces a very subtle while loop, which is interesting. DW.MIN.Y This value can be modified, at the end of the circular sentence has such a sentence: dw.min.y+=10, update the while statement in the judgment condition, but also to ensure that the pixels in each loop recursively in the image of the 10 rows of pixels assigned to the address, Have to lament that the engineers of ILM have a deep skill.
Above.
Read mechanism of OPENEXR