Image Data Structure
T ## Image buffer model
Data is stored in an unsigned char* buffer in row-order of a (\(width * height * N\)) size.
- The image has
heightrows andwidthcolumns. - Each pixel has
Ncomponents. - In this project,
N = 3for RGB. - Data is row-major, from top-left to bottom-right.
The buffer size is:
width * height * N
To manipulate image, you will have to use an ’unsigned char *’ which points to the pixel data. The pixel data consists of HEIGHT lines of WIDTH pixels, with each pixel consisting of N components. In our case, we will use N = 3 for RGB components. The first pixel pointed to is top-left-most in the image.

Data is stored flat

IO functions
int read_image_data(const char *filename, unsigned char **data, int *width, int *height, int *nbChannels);
int write_image_data(const char *filename, unsigned char *data, int width, int height);Parameters:
filename: image file pathdata: pixel bufferwidth: image widthheight: image heightnbChannels: number of channels
Pixel helper structure
At the end of Milestone 1, you should introduce a helper structure:
typedef struct _pixelRGB {
unsigned char R;
unsigned char G;
unsigned char B;
} pixelRGB;This structure simplifies component-level access and supports helper functions such as getPixel(x, y).
Index formula
For pixel at (x, y) with channel count n, the starting index in data is:
(y * width + x) * n
Then channels are:
R:data[idx]G:data[idx + 1]B:data[idx + 2]