static void computeColorMapFromMap(struct pam * const mappamP, tuple ** const maptuples, tupletable * const colormapP, unsigned int * const newcolorsP) { /*---------------------------------------------------------------------------- Produce a colormap containing the colors that we will use in the output. Make it include exactly those colors that are in the image described by *mappamP and maptuples[][]. Return the number of colors in the returned colormap as *newcolorsP. -----------------------------------------------------------------------------*/ unsigned int colors; if (mappamP->width == 0 || mappamP->height == 0) pm_error("colormap file contains no pixels"); *colormapP = pnm_computetuplefreqtable(mappamP, maptuples, MAXCOLORS, &colors); if (*colormapP == NULL) pm_error("too many colors in colormap!"); pm_message("%u colors found in colormap", colors); *newcolorsP = colors; }
static void computeColorMap(struct pam * const pamP, tuple ** const tupleArray, unsigned int * const numColorsP, tupletable * const colormapP, tuplehash * const colorhashP, bool const show) { unsigned int numColors; tupletable colormap; colormap = pnm_computetuplefreqtable(pamP, tupleArray, 0, &numColors); if (numColors > 0xFF0) pm_error("too many colors; " "use pnmquant to reduce to no more than %u colors", 0xFF0); if (show) { unsigned int colorIndex; fprintf(stderr, "Color map:\n"); fprintf(stderr, " Index Color\n"); for (colorIndex = 0; colorIndex < numColors; ++colorIndex) { unsigned int plane; fprintf(stderr, " %5u ", colorIndex); for (plane = 0; plane < pamP->depth; ++plane) fprintf(stderr, "%3lu ", colormap[colorIndex]->tuple[plane]); fprintf(stderr, "\n"); } } *colorhashP = pnm_computetupletablehash(pamP, colormap, numColors); *numColorsP = numColors; *colormapP = colormap; }
static void computeImageType_cht(struct pam * const pamP, struct cmdlineInfo const cmdline, tuple ** const tuples, enum TGAbaseImageType * const baseImgTypeP, bool * const withAlphaP, tupletable * const chvP, tuplehash * const chtP, int * const ncolorsP) { unsigned int ncolors; enum TGAbaseImageType baseImgType; bool withAlpha; validateTupleType(pamP); withAlpha = (streq(pamP->tuple_type, "RGB_ALPHA")); if (cmdline.defaultFormat) { /* default the image type */ if (withAlpha) { baseImgType = TGA_RGB_TYPE; *chvP = NULL; } else if (pamP->depth > 1) { pm_message("computing colormap..."); *chvP = pnm_computetuplefreqtable(pamP, tuples, MAXCOLORS, &ncolors); if (*chvP == NULL) { pm_message("Too many colors for colormapped TGA. Doing RGB."); baseImgType = TGA_RGB_TYPE; } else baseImgType = TGA_MAP_TYPE; } else { baseImgType = TGA_MONO_TYPE; *chvP = NULL; } } else { baseImgType = cmdline.imgType; if (baseImgType == TGA_MAP_TYPE) { if (withAlpha) pm_error("Can't do a colormap because image has transparency " "information"); pm_message("computing colormap..."); *chvP = pnm_computetuplefreqtable(pamP, tuples, MAXCOLORS, &ncolors); if (*chvP == NULL) pm_error("Too many colors for colormapped TGA. " "Use 'pnmquant %d' to reduce the number of colors.", MAXCOLORS); } else *chvP = NULL; if (baseImgType == TGA_MONO_TYPE && pamP->depth > 1) pm_error("For Mono TGA output, input must be " "GRAYSCALE or BLACKANDWHITE PAM or PBM or PGM"); } if (baseImgType == TGA_MAP_TYPE) { pm_message("%d colors found.", ncolors); /* Make a hash table for fast color lookup. */ *chtP = pnm_computetupletablehash(pamP, *chvP, ncolors); } else *chtP = NULL; *baseImgTypeP = baseImgType; *withAlphaP = withAlpha; *ncolorsP = ncolors; }