/* $Id$ */

#ifndef PPM_H__
#define PPM_H__

#define PPM_OFFSET(ppm,x,y) (ppm->width * (y) + (x))
#define PPM_PIXEL(ppm,x,y) ppm->data[PPM_OFFSET(ppm,x,y)]
#define PPM_SUBPIXEL(ppm,x,y,chan) PPM_PIXEL(ppm,x,y).rgb[chan]

typedef unsigned long ppm_size_t;
typedef unsigned char ppm_subpixel_t;

typedef struct
{
	ppm_subpixel_t rgb[3];
} __attribute__((packed)) ppm_pixel_t;

typedef struct
{
	ppm_size_t width, height;
	ppm_pixel_t *data;
} ppm_t;

ppm_t *ppm_alloc(ppm_size_t width, ppm_size_t height);
ppm_t *ppm_load(const char *path);
int ppm_save(const ppm_t *ppm, const char *path);
void ppm_free(ppm_t *ppm);

#endif
