\ .\" This man page was generated by the Netpbm tool 'makeman' from HTML source. .\" Do not hand-hack it! If you have bug fixes or improvements, please find .\" the corresponding HTML page on the Netpbm website, generate a patch .\" against that, and send it to the Netpbm maintainer. .TH "User manual for old ppm functions" 3 "8 May 2009" "netpbm documentation" .SH NAME libppm - functions for PPM programs .UN synopsis .SH SYNOPSIS \fB#include \fP .PP \fBvoid ppm_init(\fP\fBint *\fP \fIargcP\fP\fB,\fP \fBchar *\fP \fIargv\fP\fB[]\fP\fB);\fP .PP \fBpixel ** ppm_allocarray(\fP \fBint \fP\fIcols\fP\fB,\fP\fBint\fP \fIrows\fP\fB);\fP .PP \fBpixel * ppm_allocrow(\fP\fBint\fP \fIcols\fP\fB);\fP .PP \fBvoid ppm_freearray(\fP\fBpixel **\fP \fIpixels\fP\fB,\fP \fBint\fP \fIrows\fP\fB);\fP .PP \fBvoid ppm_freerow(\fP\fBpixel *\fP \fIpixelrow\fP\fB);\fP .PP \fBvoid ppm_readppminit(\fP\fBFILE *\fP \fIfp\fP\fB,\fP \fBint *\fP \fIcolsP\fP\fB,\fP \fBint *\fP \fIrowsP\fP\fB,\fP \fBpixval *\fP \fImaxvalP\fP\fB,\fP\fBint *\fP \fIformatP\fP\fB );\fP .PP \fBvoid ppm_readppmrow(\fP\fBFILE *\fP\fIfp\fP\fB,\fP \fBpixel *\fP \fIpixelrow\fP\fB,\fP \fBint \fP\fIcols\fP\fB,\fP \fBpixval \fP\fImaxval\fP\fB,\fP \fBint \fP\fIformat\fP\fB);\fP .PP \fBpixel ** ppm_readppm(\fP\fBFILE *\fP \fIfp\fP\fB,\fP \fBint *\fP \fIcolsP\fP\fB,\fP \fBint *\fP \fIrowsP\fP\fB,\fP \fBpixvalP *\fP \fImaxvalP\fP\fB);\fP .PP \fBvoid ppm_writeppminit(\fP\fBFILE * \fIfp\fP,\fP \fBint\fP \fIcols\fP\fB,\fP \fBint\fP \fIrows\fP\fB,\fP \fBpixval\fP \fImaxval\fP\fB,\fP \fBint\fP \fIforceplain\fP\fB);\fP .PP \fBvoid ppm_writeppmrow(\fP\fBFILE *\fP \fIfp\fP\fB,\fP \fBpixel *\fP \fIpixelrow\fP\fB,\fP \fBint\fP \fIcols\fP\fB,\fP \fBpixval\fP \fImaxval\fP\fB,\fP \fBint\fP \fIforceplain\fP\fB);\fP .PP \fBvoid ppm_writeppm(\fP\fBFILE *\fP \fIfp\fP\fB,\fP \fBpixel **\fP \fIpixels\fP\fB,\fP \fBint\fP \fIcols\fP\fB,\fP \fBint\fP \fIrows\fP\fB,\fP \fBpixval\fP \fImaxval\fP\fB,\fP \fBint\fP \fIforceplain\fP\fB);\fP .PP \fBvoid ppm_writeppm(\fP\fBFILE *\fP \fIfp\fP\fB,\fP \fBpixel **\fP \fIpixels\fP\fB,\fP \fBint\fP \fIcols\fP\fB,\fP \fBint\fP \fIrows\fP\fB,\fP \fBpixval\fP \fImaxval\fP\fB,\fP \fBint\fP \fIforceplain\fP\fB);\fP .PP \fBvoid ppm_nextimage(\fP\fBFILE *\fP \fIfile\fP\fB,\fP \fBint * const\fP \fIeofP\fP\fB);\fP .PP \fBvoid ppm_check(\fP\fBFILE *\fP \fIfile\fP\fB,\fP \fBconst enum pm_check_type\fP \fIcheck_type\fP\fB,\fP \fBconst int\fP \fIformat\fP\fB,\fP \fBconst int\fP \fIcols\fP\fB,\fP \fBconst int\fP \fIrows\fP\fB,\fP \fBconst int\fP \fImaxval\fP\fB,\fP \fBenum pm_check_code * const\fP \fIretval\fP\fB);\fP .PP \fBtypedef ... pixel;\fP \fBtypedef ... pixval;\fP .PP \fB#define PPM_MAXMAXVAL ...\fP .PP \fB#define PPM_OVERALLMAXVAL ...\fP .PP \fB#define PPM_FORMAT ...\fP .PP \fB#define RPPM_FORMAT ...\fP .PP \fB#define PPM_TYPE PPM_FORMAT\fP .PP \fB#define\fP \fBPPM_FORMAT_TYPE(\fP\fIformat\fP\fB)\fP \fB...\fP .PP \fBpixval PPM_GETR(pixel\fP \fIp\fP\fB)\fP .PP \fBpixval PPM_GETG(pixel\fP \fIp\fP\fB)\fP .PP \fBpixval PPM_GETB(pixel\fP \fIp\fP\fB)\fP .PP \fBvoid PPM_ASSIGN(pixel\fP \fIp\fP\fB,\fP \fBpixval\fP \fIred\fP\fB,\fP \fBpixval\fP \fIgrn\fP\fB,\fP \fBpixval\fP \fIblu\fP\fB)\fP .PP \fBint PPM_EQUAL(pixel\fP \fIp\fP\fB,\fP \fBpixel\fP \fIq\fP\fB)\fP .PP \fBint PPM_ISGRAY(pixel\fP \fIp\fP\fB)\fP .PP \fBvoid\fP \fBPPM_DEPTH(pixel\fP \fInewp\fP\fB,\fP \fBpixel\fP \fIp\fP\fB,\fP \fBpixval\fP \fIoldmaxval\fP\fB,\fP \fBpixval\fP \fInewmaxval\fP\fB)\fP .PP \fBpixel ppm_parsecolor(char *\fP \fIcolorname\fP\fB,\fP \fBpixval\fP \fImaxval\fP\fB)\fP .PP \fBchar * ppm_colorname(pixel *\fP \fIcolorP\fP\fB,\fP \fBpixval\fP \fImaxval\fP\fB,\fP \fBint\fP \fIhexok\fP\fB)\fP .PP \fBvoid ppm_readcolornamefile(\fP \fBconst char *\fP\fIfileName\fP, \fBint\fP \fImustOpen\fP, \fBcolorhash_table *\fP \fIchtP\fP, \fBconst char ***\fP \fIcolornamesP\fP \fB)\fP .UN description .SH DESCRIPTION .PP These library functions are part of .BR Netpbm (1) . .UN types .SS TYPES AND CONSTANTS Each \fBpixel\fP contains three \fBpixval\fPs, each of which should contain only the values between \fB0\fP and \fBPPM_MAXMAXVAL\fP. .UN manipulating_pixels .SS MANIPULATING PIXELS .PP The macros \fBPPM_GETR\fP, \fBPPM_GETG\fP, and \fBPPM_GETB\fP retrieve the red, green, or blue sample, respectively, from the given pixel. .PP The \fBPPM_ASSIGN\fP macro assigns the given values to the red, green, and blue samples of the given pixel. .PP The \fBPPM_EQUAL\fP macro tests two pixels for equality. .PP The \fBPPM_ISGRAY\fP macro tests a pixel for being gray. It returns true if and only if the color of pixel \fIp\fP is black, white, or gray. .PP The \fBPPM_DEPTH\fP macro scales the colors of pixel \fIp\fP according the old and new maxvals and assigns the new values to \fInewp\fP. It is intended to make writing ppmtowhatever easier. .PP The \fBPPM_LUMIN\fP, \fBPPM_CHROM_R\fP, and \fBPPM_CHROM_B\fP macros determine the luminance, red chrominance, and blue chrominance, respectively, of the pixel \fIp\fP. 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). .PP 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. .UN initialization .SS INITIALIZATION .PP \fBppm_init()\fP is obsolete (at least since Netpbm 9.25 (March 2002)). Use .UR libpm.html#initialization \fBpm_proginit()\fP .UE \& instead. .PP \fBppm_init()\fP is identical to \fBpm_proginit\fP. .UN memorymanagement .SS MEMORY MANAGEMENT \fBppm_allocarray()\fP allocates an array of pixels. .PP \fBppm_allocrow()\fP allocates a row of the given number of pixels. .PP \fBppm_freearray()\fP frees the array allocated with \fBppm_allocarray()\fP containing the given number of rows. .PP \fBppm_freerow()\fP frees a row of pixelss allocated with \fBppm_allocrow()\fP. .UN readingfiles .SS READING FILES .PP 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 \fIformat\fP value returned by \fBppm_readppminit()\fP is, however, not translated. It represents the actual format of the PBM or PGM file. .PP \fBppm_readppminit()\fP reads the header of a PPM file, returning all the information from the header and leaving the file positioned just after the header. .PP \fBppm_readppmrow()\fP reads a row of pixels into the \fIpixelrow\fP array. \fIformat\fP, \fIcols\fP, and \fImaxval\fP are the values returned by \fBppm_readppminit()\fP. .PP \fBppm_readppm()\fP reads an entire PPM image into memory, returning the allocated array as its return value and returning the information from the header as \fIrows\fP, \fIcols\fP, and \fImaxval\fP. This function combines \fBppm_readppminit()\fP, \fBppm_allocarray()\fP, and \fBppm_readppmrow()\fP. .UN writingfiles .SS WRITING FILES \fBppm_writeppminit()\fP writes the header for a PPM file and leaves it positioned just after the header. .PP \fIforceplain\fP is a logical value that tells \fBppm_writeppminit() \fP to write a header for a plain PPM format file, as opposed to a raw PPM format file. .PP \fBppm_writeppmrow()\fP writes the row \fIpixelrow\fP to a PPM file. For meaningful results, \fIcols\fP, \fImaxval\fP, and \fIforceplain\fP must be the same as was used with \fBppm_writeppminit()\fP. .PP \fBppm_writeppm()\fP write the header and all data for a PPM image. This function combines \fBppm_writeppminit()\fP and \fBppm_writeppmrow()\fP. .UN miscellaneous .SS MISCELLANEOUS .PP \fBppm_nextimage()\fP positions a PPM input file to the next image in it (so that a subsequent \fBppm_readppminit()\fP reads its header). .PP \fBppm_nextimage()\fP is analogous to \fBpbm_nextimage()\fP, but works on PPM, PGM, and PBM files. .PP \fBppm_check() \fP checks for the common file integrity error where the file is the wrong size to contain all the image data. .PP \fBppm_check() \fP is analogous to \fBpbm_check()\fP, but works on PPM, PGM, and PBM files. .UN color .SS COLOR .UN luminance .B Luminance, Chrominance (YcbCr) .nf \f(CW float PPM_LUMIN(pixel p); float PPM_CHROM_B(pixel p); float PPM_CHROM_R(pixel p); \fP .fi .PP \fBPPM_LUMIN\fP takes a \fBpixel\fP as an argument and returns the luminance of that pixel, with the same maxval as the pixel (e.g. if the pixel's maxval is 255, a \fBPPM_LUMIN\fP value of 255 means fully luminant). .PP \fBPPM_CHROM_B\fP and \fBPPM_CHROM_R\fP are similar, for the red and blue chrominance values. .nf \f(CW pixel ppm_color_from_ycbcr(unsigned int y, int cb, int cr); \fP .fi .PP \fBppm_color_from_ycbcr()\fP converts in the other direction. Given luminance and chrominance, it returns a pixel value. .UN hsv .B Hue, Saturation, Value (HSV) .nf \f(CW struct hsv { double h; /* hue (degrees) 0..360 */ double s; /* saturation (0-1) */ double v; /* value (0-1) */ }; \fP .fi .nf \f(CW pixel ppm_color_from_hsv(struct hsv const hsv, pixval const maxval); \fP .fi .nf \f(CW struct hsv ppm_hsv_from_color(pixel const color, pixval const maxval); \fP .fi .PP These convert a color between from \fBpixel\fP (RGB) form and HSV. .nf \f(CW pixval ppm_saturation(pixel const p, pixval const maxval); \fP .fi .PP This gives you the saturation of a color, as a pixval. (e.g. if the saturation of \fIp\fP is 50% and \fImaxval\fP is 100, \fBppm_saturation()\fP returns 50). .UN berlinkay .B Berlin-Kay Color .PP Brent Berlin and Paul Kay in 1969 did a study which identified a set of 11 basic colors people universally recognize. They are: .IP \(bu black .IP \(bu gray .IP \(bu white .IP \(bu red .IP \(bu orange .IP \(bu yellow .IP \(bu green .IP \(bu blue .IP \(bu violet .IP \(bu purple .IP \(bu brown .PP The \fBbk_color\fP type represents a color from this set: .nf \f(CW typedef enum { BKCOLOR_BLACK = 0, BKCOLOR_GRAY, BKCOLOR_WHITE, BKCOLOR_RED, BKCOLOR_ORANGE, BKCOLOR_YELLOW, BKCOLOR_GREEN, BKCOLOR_BLUE, BKCOLOR_VIOLET, BKCOLOR_PURPLE, BKCOLOR_BROWN } bk_color; \fP .fi .PP You can use this as an index of an array, in which case you might also want macro \fBBKCOLOR_COUNT\fP, which is the number of colors in the set (11). .PP To translate between the \fBbk_color\fP type and the English names of the colors, use \fBppm_bk_color_from_name()\fP and \fBppm_name_from_bk_color()\fP: .nf \f(CW bk_color ppm_bk_color_from_name(const char * name); const char * ppm_name_from_bk_color(bk_color bkColor); \fP .fi .PP \fBppm_bk_color_from_color()\fP tells you to which Berlin-Kay color a certain color is closest, by way of a fuzzy color matching algorithm: .nf \f(CW bk_color ppm_bk_color_from_color(pixel color, pixval maxval); \fP .fi .PP \fImaxval\fP is the maxval on which \fIcolor\fP is based. .PP \fBppm_color_from_bk_color()\fP converts the opposite way: given a Berlin-Kay color, it gives the color, in \fBpixel\fP form, that best represents it. .nf \f(CW pixel ppm_color_from_bk_color(bk_color bkColor, pixval maxval); \fP .fi .PP \fImaxval\fP is the maxval on which the returned color is based. .PP All of the facilities in this section were new in Netpbm 10.34 (June 2006). .UN colorname .SS COLOR NAMES .UN dictionary .B System Color Dictionary .PP Netpbm uses the system's X11 color dictionary (usually in \fB/usr/lib/X11/rgb.txt\fP). This is the same file the X Window System typically uses to associate colors with their names. .PP The color dictionary that Netpbm uses is in the file whose name is the value of the \fBRGBDEF\fP environment variable. If \fBRGBDEF\fP is not set, Netpbm defaults to the first existing file from this list: .IP \(bu \fB/usr/lib/X11/rgb.txt\fP .IP \(bu \fB/usr/openwinlib/rgb.txt\fP .IP \(bu \fB/usr/X11R6/lib/X11/rgb.txt\fP .PP You can see the color names from a typical X11 color dictionary, which is probably very close to what is on your system, along with the colors, .UR http://www.swiss.ai.mit.edu/~jaffer/Color/x11.pdf here .UE \&. .BR This website (1) shows a bunch of other versions you could use. .PP Netpbm is packaged with a color dictionary. A standard Netpbm installation installs this file as "misc/rgb.txt" in the Netpbm directory. This color dictionary has colors from everywhere the Netpbm maintainer could find them, and is a superset of XFree 86's color dictionary. .UN ppm_parsecolor .B ppm_parsecolor .PP \fBppm_parsecolor()\fP interprets a color specification and returns a pixel of the color that it indicates. The color specification is ASCII text, in one of these formats: .IP \(bu a name, as defined in the .UR #rgb.txt system color dictionary .UE \&. .IP \(bu An X11-style hexadecimal specifier: \f(CWrgb:\fIr\fP/\fIg\fP/\fIb\fP\fP, where \fIr\fP, \fIg\fP, and \fIb\fP are each 1- to 4-digit hexadecimal numbers. For each, the maxval is the maximum number that can be represented in the number of hexadecimal digits given. Example: \f(CWrgb:01/ff/8000\fP specifies 1/255 red intensity, maximum green intensity, and about half blue intensity. .IP \(bu An X11-style decimal specifier: \f(CWrgbi:\fIr\fP/\fIg\fP/\fIb\fP\fP, where \fIr\fP, \fIg\fP, and \fIb\fP are floating point numbers from 0 to 1. .IP \(bu an old-X11-style hexadecimal triple: \f(CW#rgb\fP, \f(CW#rrggbb\fP, \f(CW#rrrgggbbb\fP, or \f(CW#rrrrggggbbbb\fP. .IP \(bu A triplet of decimal floating point numbers from 0.0 to 1.0, representing red, green, and blue intensities respectively, separated by commas. E.g. \f(CW1.0,0.5,.25\fP. This is for backwards compatibility; it was in use before MIT came up with the similar and preferred rgbi style). .PP If the color specification does not conform to any of these formats, including the case that it is a name, but is not in the system color dictionary, \fBppm_parsecolor()\fP .BR throws an error (1) . .UN ppm_colorname .B ppm_colorname .PP \fBppm_colorname()\fP returns a string that describes the color of the given pixel. If a .UR #rgb.txt system color dictionary .UE \& is available and the color appears in it, \fBppm_colorname()\fP returns the name of the color from the file. If the color does not appear in a system color dictionary and \fIhexok\fP is true, \fBppm_colorname()\fP returns a hexadecimal color specification triple (#rrggbb). If a system color dictionary is available but the color does not appear in it and \fIhexok\fP is false, \fBppm_colorname()\fP returns the name of the closest matching color in the color file. Finally, if there is no system color dictionary available and \fIhexok\fP is false, \fBppm_colorname()\fP fails and .UR liberror.html#error throws an error .UE \&. .PP The string returned is in static libppm library storage which is overwritten by every call to \fBppm_colorname()\fP. .UN ppm_readcolornamefile .B ppm_readcolornamefile .PP \fBppm_readcolornamefile()\fP reads the entire contents of the color dictionary in the file named \fIfileName\fP into data structures you can use to access it easily. .PP The function returns all the color names as an array of null-terminated strings. It mallocs the space for this array and returns its address at \fIcolornamesP\fP. \fB(*colornamesP)[\fP\fIi\fP\fB]\fP is the address of the first character in the null-terminated string that is the name of the \fIi\fPth color in the dictionary. .PP The function also returns a \fBcolorhash_table\fP (see .UR #colorindex COLOR INDEXING .UE \&) that matches all these color names up to the colors they represent. It mallocs the space for the \fBcolorhash_table\fP and returns its address at \fIchtP\fP. The number that the \fBcolorhash_table\fP associates with each color is the index into the color name array described above of the name of that color. .PP You may specify a null pointer for \fIfileName\fP to indicate the default color dictionary. .PP \fImustOpen\fP is a boolean. If it is nonzero, the function fails and aborts the program if it is unable to open the specified color dictionary file. If it is zero, though, it simply treats an unopenable color dictionary as an empty one. The colorhash and color name array it returns contain no colors or names. .PP \fBppm_readcolornamefile()\fP was new in Netpbm 10.15 (April 2003). .UN colorindex .SS COLOR INDEXING .PP Sometimes in processing images, you want to associate a value with a particular color. Most often, that's because you're generating a color mapped graphics format. In a color mapped graphics format, the raster contains small numbers, and the file contains a color map that tells what color each of those small numbers refers to. If your image has only 256 colors, but each color takes 24 bits to describe, this can make your output file much smaller than a straightforward RGB raster would. .PP So, continuing the above example, say you have a \fBpixel\fP value for chartreuse and in your output file and you are going to represent chartreuse by the number 12. You need a data structure that allows your program quickly to find out that the number for a chartreuse \fBpixel\fP is 12. Netpbm's color indexing data types and functions give you that. .PP \fBcolorhash_table\fP is a C data type that associates an integer with each of an arbitrary number of colors. It is a hash table, so it uses far less space than an array indexed by the color's RGB values would. .PP The problem with a \fBcolorhash_table\fP is that you can only look things up in it. You can't find out what colors are in it. So Netpbm has another data type for representing the same information, the poorly but historically named \fBcolorhist_vector\fP. A \fBcolorhist_vector\fP is just an array. Each entry represents a color and contains the color's value (as a \fBpixel\fP) and the integer value associated with it. The entries are filled in starting with subscript 0 and going consecutively up for the number of colors in the histogram. .PP (The reason the name is poor is because a color histogram is only one of many things that could be represented by it). .PP \fBcolorhash_table ppm_alloccolorhash()\fP .PP This creates a \fBcolorhash_table\fP using dynamically allocated storage. There are no colors in it. If there is not enough storage, .UR liberror.html#error throws an error .UE \&. .PP \fBvoid ppm_freecolorhash()\fP .PP This destroys a \fBppm_freecolorhash \fP and frees all the storage associated with it. .PP \fBint ppm_addtocolorhash( colorhash_table cht, const pixel * const colorP, const int value)\fP .PP This adds the specified color to the specified \fBcolorhash_table \fP and associates the specified value with it. .PP You must ensure that the color you are adding isn't already present in the \fBcolorhash_table\fP. .PP There is no way to update an entry or delete an entry from a \fBcolorhash_table\fP. .PP \fBint ppm_lookupcolor( const colorhash_table cht, const pixel * const colorP )\fP .PP This looks up the specified color in the specified \fBcolorhash_table\fP. It returns the integer value associated with that color. .PP If the specified color is not in the hash table, the function returns -1. (So if you assign the value -1 to a color, the return value is ambiguous). .PP \fBcolorhist_vector ppm_colorhashtocolorhist( const colorhash_table cht,\fP \fBconst int ncolors )\fP .PP This converts a \fBcolorhash_table\fP to a \fBcolorhist_vector\fP. The return value is a new \fBcolorhist_vector\fP which you must eventually free with \fBppm_freecolorhist()\fP. .PP \fBncolors\fP is the number of colors in \fBcht\fP. If it has more colors than that, \fBppm_colorhashtocolorhist\fP does not create a \fBcolorhist_vector\fP and returns NULL. .PP \fBcolorhash_table ppm_colorhisttocolorhash( const colorhist_vector chv, const int ncolors ) \fP .PP This poorly named function does \fInot\fP convert from a \fBcolorhist_vector\fP to a \fBcolorhash_table\fP. .PP It does create a \fBcolorhash_table\fP based on a \fBcolorhist_vector\fP input, but the integer value for a given color in the output is not the same as the integer value for that same color in the input. \fBppm_colorhisttocolorhash()\fP ignores the integer values in the input. In the output, the integer value for a color is the index in the input \fBcolorhist_vector\fP for that color. .PP You can easily create a color map for an image by running \fBppm_computecolorhist() \fP over the image, then \fBppm_colorhisttocolorhash()\fP over the result. Now you can use \fBppm_lookupcolor()\fP to find a unique color index for any pixel in the input. .PP If the same color appears twice in the input, \fBppm_colorhisttocolorhash()\fP .UR liberror.html#error throws an error .UE \&. .PP \fBncolors\fP is the number of colors in \fBchv\fP. .PP The return value is a new \fBcolorhash_table\fP which you must eventually free with \fBppm_freecolorhash()\fP. .UN histogram .SS COLOR HISTOGRAMS .PP The Netpbm libraries give you functions to examine a Netpbm image and determine what colors are in it and how many pixels of each color are in it. This information is known as a color histogram. Netpbm uses its \fBcolorhash_table\fP data type to represent a color histogram. .PP \fBcolorhash_table ppm_computecolorhash( pixel ** const pixels, const int cols, const int rows, const int maxcolors, int* const colorsP )\fP .PP This poorly but historically named function generates a \fBcolorhash_table\fP whose value for each color is the number of pixels in a specified image that have that color. (I.e. a color histogram). As a bonus, it returns the number of colors in the image. .PP (It's poorly named because not all \fBcolorhash_table\fPs are color histograms, but that's all it generates). .PP \fBpixels\fP, \fBcols\fP, and \fBrows\fP describe the input image. .PP \fBmaxcolors\fP is the maximum number of colors you want processed. If there are more colors that that in the input image, \fBppm_computecolorhash()\fP returns NULL as its return value and stops processing as soon as it discovers this. This makes it run faster and use less memory. One use for \fBmaxcolors\fP is when you just want to find out whether or not the image has more than N colors and don't want to wait to generate a huge color table if so. If you don't want any limit on the number of colors, specify \fBmaxcolors\fP=\fB0\fP. .PP \fBppm_computecolorhash()\fP returns the actual number of colors in the image as \fB*colorsP\fP, but only if it is less than or equal to \fBmaxcolors\fP. .PP \fBcolorhash_table ppm_computecolorhash2( FILE * const ifp, const int cols, const int rows, const pixval maxval, const int format,\fP \fBconst int maxcolors, int* const colorsP )\fP .PP This is the same as \fBppm_computecolorhash()\fP except that instead of feeding it an array of pixels in storage, you give it an open file stream and it reads the image from the file. The file must be positioned after the header, at the raster. Upon return, the file is still open, but its position is undefined. .PP \fBmaxval\fP and \fBformat\fP are the values for the image (i.e. information from the file's header). .PP \fBcolorhist_vector ppm_computecolorhist( pixel ** pixels, int cols, int rows, int maxcolors, int * colorsP )\fP .PP This is like \fBppm_computecolorhash()\fP except that it creates a \fBcolorhist_vector\fP instead of a \fBcolorhash_table\fP. .PP If you supply a nonzero \fBmaxcolors\fP argument, that is the maximum number of colors you expect to find in the input image. If there are more colors than you say in the image, \fBppm_computecolorhist()\fP returns a null pointer as its return value and nothing meaningful as \fB*colorsP\fP. .PP If not, the function returns the new \fBcolorhist_vector \fP as its return value and the actual number of colors in the image as \fB*colorsP\fP. The returned array has space allocated for the specified number of colors regardless of how many actually exist. The extra space is at the high end of the array and is available for your use in expanding the \fBcolorhist_vector\fP. .PP If you specify \fBmaxcolors\fP=\fB0\fP, there is no limit on the number of colors returned and the return array has space for 5 extra colors at the high end for your use in expanding the \fBcolorhist_vector\fP. .PP \fBcolorhist_vector ppm_computecolorhist2( FILE * ifp, int cols, int rows, int maxcolors, pixval maxval, int format, int * colorsP )\fP .PP This is the same as \fBppm_computecolorhist()\fP except that instead of feeding it an array of pixels in storage, you give it an open file stream and it reads the image from the file. The file must be positioned after the header, at the raster. Upon return, the file is still open, but its position is undefined. .UN seealso .SH SEE ALSO .BR pbm (5) , .BR pgm (5) , .BR libpbm (3) .UN author .SH AUTHOR Copyright (C) 1989, 1991 by Tony Hansen and Jef Poskanzer.