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 red | The red value of a pixel. |
unsigned char green | The green value of a pixel. |
unsigned char blue | The blue value of a pixel. |
_IMGDATA
int rows | The number of rows in the image. |
int cols | The number of columns in the image. |
char color | 1 for color pixels, 0 for gray scale. |
union pixels | See union members below |
COLOR_PIXEL* pixels.color | An array of color pixels in row major order. |
unsigned char* pixels.gray | An 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.
- img_red
- img_blue
- img_green
- img_yellow
- img_white
- img_black
Functions
IMG img_load_pxm(const char* filename)
filename | Name of the file to load. |
return | The 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)
filename | Name of the file to write to. |
img | The 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)
rows | Number of rows to allocate. |
cols | Number of columns to allocate. |
color | True 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)
img | The 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)
img | The 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)
img1 | The first image to be composited. |
img2 | The second image to be composited. |
alpha | The 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)
filename | The name of the file to write. |
img | The 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.