Image memory format_v0.2 - FoxelSA/libgnomonic GitHub Wiki

Overview

The images memory format considered by the library is historical binary bitmaps. This page gives the library expected standards for images storage and manipulation according to bitmap format.

Image memory format

The memory format expected by the library corresponds to historical bitmap structure. As a result, images rows have to follow a specific constraint. An image row length, with all its chromatic components, have to be a multiple of four. This impose padding bytes at each end of row when the constraint is not satisfied.

Considering an image stored in memory using historical bitmap format with width w, height h and with c chromatic channels, a pixel offset located at coordinates (x,y) in the k chromatic channel is computed as follows :

Offset = b + p · y + c · x + k

where b is the offset of the first byte of the image and where :

if (c · w)[4] = 0 : p = c · w
if (c · w)[4] ≠ 0 : p = c · w + 4 - (c · w)[4]

In case of a 32-bit image, such as rgba images, the constraint on rows is always satisfied.