graphicsDeploy api:
deploy.h
Establishes the basic image manipulation environment. Defines Image structs, Pixel, Color, and ImagePoint typedefs, and a few routines to allocate, free, copy, and manipulate them.
struct Image
The Image struct contains a field for actual pixel data, along with row/column counts and an alpha channel, plus the color field for reading/writing PPM files. The stagger and staggervertical paramters affect how the image is drawn when used as a repeated pattern.
struct Image {
   Pixel *data;
   long cols, rows;
   int colors;
   float a;
   float stagger; /* -1.0 to 1.0 */
   short staggervertical; /* TRUE or FALSE */
};
struct Image *allocImage(long n_cols, long n_rows);
struct Image *newCanvas(long num_cols, long num_rows, Color bg_color);
struct Image *copyImage(struct Image *source_image);
void freeImage(struct Image *image);
Pixels, Colors
Pixels have r, g, and b color values; Color is just a Pixel typedef. There are various macros and functions for creating and rendering Pixels and Colors. The PIXEL macro is useful for addressing individual pixels. setPixel() uses alpha channel blending to set a new pixel. In addition to r,g,b color channels, pixels also have a flag used for masking/searching (used in flood fills, for example)
typedef struct {
   unsigned char r, g, b;
   unsigned char flag;
} Pixel;
typedef Pixel Color;
#define newPixel(r,g,b) ((Pixel){r,g,b,0})
#define newColor(r,g,b) (newPixel(r,g,b))
#define PIXEL(image, point) (image->data[(point.x)+image->cols*(point.y)])
void setPixel(struct Image *image, Point point, Pixel color);
Color multIntensity(Color color, double intensity);
#define flagPixel(state,point) (PIXEL(state->canvas,(point)).flag = 1)
#define unflagPixel(state,point) (PIXEL(state->canvas,(point)).flag = 0)
#define flaggedPixel(state,point) (PIXEL(state->canvas,(point)).flag == 1)
#define INTENSITY(pixel) ((int)pixel.r+(int)pixel.g+(int)pixel.b)
#define HUE_r(pixel) ((float)pixel.r/((float)INTENSITY(pixel)))
#define HUE_g(pixel) ((float)pixel.g/((float)INTENSITY(pixel)))
#define HUE_b(pixel) ((float)pixel.b/((float)INTENSITY(pixel)))
Image Points
Screen-coordinate points are addressed with integer x and y.
typedef struct {
   long x, y;
} ImagePoint;
#define newImagePoint(x,y) ((ImagePoint){x,y})
#define IMPEQ(p1,p2) (((p1.x)==(p2.x))&&((p1.y)==(p2.y)))
#define IMPADD(p1,p2) (newImagePoint(p1.x+p2.x,p1.y+p2.y))
#define IMPSUB(p1,p2) (newImagePoint(p1.x-p2.x,p1.y-p2.y))