#ifndef MYPGM_H #define MYPGM_H #include "datatypes.h" #define PGM_MAXMAXVAL 255 /* The header of a pgm file consists of the type on the first line. * Optional comments with a beginning hash (#) character in next line(s). * The number of columns followed by the number of rows in next line. * The maximum value by itself on the next line (ex: 255, 4096, etc). * The actual pixels in raw binary or ascii format depending on type */ #define MAX_NUM_COMMENTS 5 /* for data, internally the image is written sequentially by row. * That is, first goes row 1, then row 2, and so on, until last row. */ typedef struct { int num_comments; char comment[MAX_NUM_COMMENTS][512]; int rows, cols; uint8 max_val; uint8* data; } pgm_image; /* functions must be called before using image */ void pgm_init(pgm_image* the_image); /* set pixel in position row, col to given value */ void pgm_setpixel(pgm_image* the_image, int row, int col, uint8 val); /* return value located at given row and col */ uint8 pgm_getpixel(pgm_image* the_image, int row, int col); /* get the array for given row */ uint8* pgm_getrow(pgm_image* the_image, int row); /* flip the image upsidedown */ void pgm_flipud(pgm_image* the_image); /* read a pgm file from given file handle */ void pgm_readfile(pgm_image* the_image, char* filename); /* write a pgm file to given file handle */ /* if raw is true, then image is written as raw binary (P5 type) * otherwise if false, then image is written as ascii (P2 type) */ void pgm_writefile(pgm_image* the_image, char* filename, int raw); #endif