Method 3: Accessing Pixel Data Directly
The function IG_image_DIB_raster_pntr_get provides a direct pointer to the pixel data for a raster as it is stored internally by ImageGear. The first raster, raster 0, is the top-most raster in the image. The easiest way to access pixel data directly is to loop over the rasters in the image and call IG_image_DIB_raster_pntr_get for each raster. However, since rasters are stored sequentially in memory, it is possible to retrieve a pointer to the first raster and use it to address the entire image. If you do this, you must be aware of the following details:
- Rasters are stored in memory from top to bottom. (This is the opposite of the previous DIB-based storage system which stored images vertically flipped.)
- Rasters are stored with DWORD padding. That is, if the size of a raster is not a multiple of 4, the end of a raster will be padded with unused bytes until the size is a multiple of 4.
When accessing pixel data directly, the format of the data is the same as when the pixel access functions are used in "new" mode as described in the previous section. However, there is one exception: 1bpp images are always stored internally in a compressed format. If you need to access 1bpp images, you should use DIB import/export or pixel access functions instead of IG_image_DIB_raster_pntr_get. Alternatively, you can work with the compressed data directly as described in the Working with Run Ends Format section.