typedef struct xlg_pic XLG_pic;

Base definition.


XLG_pic *xlg_pic_open(const char *file);

Reads file into memory. If file is "-", reads from stdin. The expected format is Portable Pixelmap (PPM) in binary encoding ("P6"). To convert an image to PPM, use the ImageMagick conversion tool:

convert bla.png ppm:bla.ppm

The function returns a pointer to an XLG_pic type, or NULL if an error occurs. errno from system calls is preserved.


XLG_pic *xlg_pic_new(int x, int y);

Creates a new XLG_pic of size x * y and returns the pointer to it. The contents of the newly allocated image are undefined.

Returns NULL and sets errno upon error.


XLG_pic *xlg_pic_dup(XLG_pic *p);

Duplicates the picture pointed to by p and returns a pointer to the duplicate.

Returns NULL and sets errno upon error.


XLG_pic *xlg_pic_zero(XLG_pic *p);

Clears the image pointed to by p by setting all RGB triples to zero, resulting in a black color.

Returns p.


XLG_pic *xlg_pic_border(XLG_pic *p);

Adds a 1 pixel gray border by overwriting image edge pixels.

Returns p.


uint8_t *xlg_pic_getpx(XLG_pic *p, int x, int y);

Returns a pointer to the first byte of the RGB triple at (x,y).

Returns NULL if x and/or y are out of bounds.

Example:

uint8_t *q = xlg_pic_getpx(p, x, y);
printf("RGB values at %d,%d: %d,%d,%d\n", x, y, q[0], q[1], q[2]);


uint8_t *xlg_pic_getpxn(XLG_pic *p, int x, int y);

Same as xlg_pic_getpx() except that it returns a pointer to an empty pixel (containing r=0,g=0,b=0) if x or y is out of bounds.


uint8_t xlg_pic_getpx_sw(XLG_pic *p, int x, int y);

Returns the equivalent grayscale value of the RGB triple located at (x,y).

Returns zero (= black) if x and/or y are out of bounds. (Yeah, it is not ideal but whatever. Do the bounds checking yourself if necessary. And in most cases, you want an illegal pixel to be black, like in a matrix.)


uint8_t *xlg_pic_setpx(XLG_pic *p, int x, int y, uint8_t r, uint8_t g, uint8_t b);

Sets the values of the RGB triple at (x,y) to the values in (r,g,b). Returns a pointer to the first byte of the triple.

NULL is returned and no pixel is changed if x/y is out of bounds. The values of r/g/b are squashed before they are written to the image.


uint8_t *xlg_pic_setpxp(XLG_pic *p, int x, int y, uint8_t *c);

Same as xlg_pic_setpx(), but the RGB triple is found in c[0], c[1] and c[2], respectively.

NULL is returned and no pixel is changed if x/y is out of bounds. The values of r/g/b are squashed before they are written to the image.


uint8_t xlg_pic_setpx_sw(XLG_pic *p, int x, int y, uint8_t g);

The (squashed) grayscale value g is stored at (x,y) by setting all three RGB components to g.

Zero is returned if x/y is out of bounds, otherwise g.


int xlg_pic_store(XLG_pic *p, const char *file);

Stores the picture in p into file (in the Portable Pixelmap (PPM) format using binary encoding ("P6"). If file is "-", the data is written to stdout.


void xlg_pic_free(XLG_pic *p);

Frees the picture and all data associated with it.