void ppm_init( int *argcP, char *argv[] );
pixel ** ppm_allocarray( int cols, int rows );
pixel * ppm_allocrow( int cols );
void ppm_freearray( pixel **pixels, int rows );
void ppm_freerow( pixel *pixelrow);
void ppm_readppminit( FILE *fp, int *colsP, int *rowsP, pixval *maxvalP, int *formatP );
void ppm_readppmrow( FILE *fp, pixel *pixelrow, int cols, pixval maxval, int format );
pixel ** ppm_readppm( FILE *fp, int *colsP, int *rowsP, pixvalP *maxvalP );
void ppm_writeppminit( FILE * fp , int cols, int rows, pixval maxval, int forceplain );
void ppm_writeppmrow( FILE *fp, pixel *pixelrow, int cols, pixval maxval, int forceplain );
void ppm_writeppm( FILE *fp, pixel ** pixels, int cols, int rows, pixval maxval, int forceplain );
void ppm_writeppm( FILE *fp, pixel **pixels, int cols, int rows, pixval maxval, int forceplain );
void ppm_nextimage( FILE *file, int * const eofP);
void ppm_check( FILE * file, const enum
pm_check_type check_type, const int format, const int cols, const int rows,
const int maxval,
enum pm_check_code * const retval);
typedef ... pixel; typedef ... pixval;
#define PPM_MAXMAXVAL ...
#define PPM_OVERALLMAXVAL ...
#define PPM_FORMAT ...
#define RPPM_FORMAT ...
#define PPM_TYPE PPM_FORMAT
#define PPM_FORMAT_TYPE(format) ...
extern pixval ppm_pbmmaxval;
pixval PPM_GETR( pixel p) pixval PPM_GETG( pixel p) pixval PPM_GETB( pixel p)
void PPM_ASSIGN( pixel p, pixval red, pixval grn, pixval blu)
int PPM_EQUAL( pixel p, pixel q)
void PPM_DEPTH( pixel newp, pixel p, pixval oldmaxval, pixval newmaxval)
float PPM_LUMIN( pixel p)
float PPM_CHROM_R( pixel p)
float PPM_CHROM_B( pixel p)
pixel ppm_parsecolor( char *colorname, pixval maxval)
char * ppm_colorname( pixel *colorP, pixval maxval, int hexok)
The PPM_ASSIGN macro assigns the given values to the red, green, and blue samples of the given pixel.
The PPM_EQUAL macro tests two pixels for equality.
The PPM_DEPTH macro scales the colors of pixel p according the old and new maxvals and assigns the new values to newp. It is intended to make writing ppmtowhatever easier.
The PPM_LUMIN, PPM_CHROM_R, and PPM_CHROM_B, macros determine the luminance, red chrominance, and blue chrominance, respectively, of the pixel p. The scale of all these values is the same as the scale of the input samples (i.e. 0 to maxval for luminance, -maxval/2 to maxval/2 for chrominance).
Note that the macros do it by floating point multiplication. If you are computing these values over an entire image, it may be significantly faster to do it with multiplication tables instead. Compute all the possible products once up front, then for each pixel, just look up the products in the tables.
All PPM programs must call ppm_init() just after invocation, before they process their arguments.
ppm_allocrow() allocates a row of the given number of pixels.
ppm_freearray() frees the array allocated with ppm_allocarray() containing the given number of rows.
ppm_freerow() frees a row of pixelss allocated with ppm_allocrow().
If a function in this section is called on a PBM or PGM format file, it translates the PBM or PGM file into a PPM file on the fly and functions as if it were called on the equivalent PPM file. The format value returned by ppm_readppminit() is, however, not translated. It represents the actual format of the PBM or PGM file.
ppm_readppminit() reads the header of a PPM file, returning all the information from the header and leaving the file positioned just after the header.
ppm_readppmrow() reads a row of pixels into the pixelrow array. format, cols, and maxval are the values returned by ppm_readppminit().
ppm_readppm() reads an entire PPM image into memory, returning the allocated array as its return value and returning the information from the header as rows, cols, and maxval. This function combines ppm_readppminit(), ppm_allocarray(), and ppm_readppmrow().
forceplain is a logical value that tells ppm_writeppminit() to write a header for a plain PPM format file, as opposed to a raw PPM format file.
ppm_writeppmrow() writes the row pixelrow to a PPM file. For meaningful results, cols, maxval, and forceplain must be the same as was used with ppm_writeppminit().
ppm_writeppm() write the header and all data for a PPM image. This function combines ppm_writeppminit() and ppm_writeppmrow().
ppm_nextimage() positions a PPM input file to the next image in it (so that a subsequent ppm_readppminit() reads its header).
ppm_nextimage() is analogous to pbm_nextimage(), but works on PPM, PGM, and PBM files.
ppm_check() checks for the common file integrity error where the file is the wrong size to contain all the image data.
ppm_check() is analogous to pbm_check(), but works on PPM, PGM, and PBM files.
ppm_colorname() Returns a string that describes the color of the given pixel. If an X11-style color names file (e.g. rgb.txt) is available and the color appears in it, ppm_colorname() returns the name of the color from the file. If the color does not appear in a X11-style color file and hexok is true, ppm_colorname() returns a hexadecimal color specification triple (#rrggbb). If a X11-style color file is available but the color does not appear in it and hexok is false, ppm_colorname() returns the name of the closest matching color in the color file. Finally, if their is no X11-style color file available and hexok is false, ppm_colorname() fails and exits the program with an error message.
The string returned is in static libppm library storage which is overwritten by every call to ppm_colorname().