LibJAD PGM Routines

#include "jadimg.h"

Overview

LibJAD provides a very basic set of routines and macros for dealing with images in the PGM file format.

Data Structures

COLOR_PIXEL

unsigned char redThe red value of a pixel.
unsigned char greenThe green value of a pixel.
unsigned char blueThe blue value of a pixel.

_IMGDATA

int rowsThe number of rows in the image.
int colsThe number of columns in the image.
char color1 for color pixels, 0 for gray scale.
union pixelsSee union members below
COLOR_PIXEL* pixels.colorAn array of color pixels in row major order.
unsigned char* pixels.grayAn array of gray scale pixels.

typedef struct _IMGDATA_* IMG;

The datatype IMG is a pointer to an _IMGDATA struct. This structure contains members for the rows and columns of the image, and a union called pixels. Depending on whether the image data is grayscale or color this union contains an array of bytes values or an array of color pixels. The array is written in row major order, with pixel 0,0 in the upper left hand corner. Pixel X,Y is thus the Y * cols + X element of either the gray of color array.

Macros

img_color_pixel(G,X,Y)

Resolves to the color pixel structure of image G, column X, row Y.

img_color_red(G,X,Y)

Resolves to the red value of the pixel in image G, column X, row Y.

img_color_blue(G,X,Y)

Resolves to the blue value of the pixel in image G, column X, row Y.

img_color_green(G,X,Y)

Resolves to the green value of the pixel in image G, column X, row Y.

img_color_grey(G,X,Y)

Resolves to the gray value of the pixel in image G, column X, row Y.

Constants

LibJAD provides a set of predefined color structures for conveinance.

Functions

IMG img_load_pxm(const char* filename)

filenameName of the file to load.
returnThe IMG loaded from the file.

Loads an image from a PBM file format. This method understands all six basic variations. It can load black and white, grayscale, and color images in either the plain text or binary formats.

void img_write_pxm(const char* filename, IMG img)

filenameName of the file to write to.
imgThe image to be written.

Write an image to a PBM file. Images are written into either the P5 format for grayscale images, or P6 format for color images. These are both binary formats.

IMG img_alloc(int rows, int cols, int color)

rowsNumber of rows to allocate.
colsNumber of columns to allocate.
colorTrue for color, false for grayscale.

Allocates an image with the given number of rows and colums. If color is true, then the image is in colors. Otherwise a grayscale image is allocated.

void img_free(IMG img)

imgThe image to be freed.

Completely frees up an image. Remember that IMG is itself a pointer type, and this routine frees up both the pixel arrays and the _IMGDATA structure that wraps them.

IMG img_makecolor(IMG img)

imgThe image to be colorized.

Copies the provided image into a new image structure. The new copy is a color image. If the original image was also a color image, this image is an exact copy. If the original image was in grayscale, the value red, green, ad blue values for each pixel will be set to the original grayscale value.

IMG img_composite(IMG img1,IMG img2, double alpha)

img1The first image to be composited.
img2The second image to be composited.
alphaThe blending value, as a percent

Creates a new image that is a composite of the two provided images. Each pixel in the composite image is constructed such that the pixel in img1 has a weight of alpha, and the pixel in img2 has a weight of one minus alpha.

int img_write_jpg(const char* filename, IMG img)

filenameThe name of the file to write.
imgThe image to be written.

Writes the provided image into the designated file in JPEG format. This routine requires that libjpeg be present on the system. The LIBJad must be compiled with _HAS_LIBJPEG_ defined in order for this routine to be present in the library.