diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2019-06-28 23:45:11 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2019-06-28 23:45:11 +0000 |
commit | cdf6e0151411d887fef61245cb303ef190b29335 (patch) | |
tree | 678c2212e125e66e0a868773e2b4ec460794da4e /other | |
parent | de1311e820dc892f1a3c5c9ae70dbc56868030d8 (diff) | |
download | netpbm-mirror-cdf6e0151411d887fef61245cb303ef190b29335.tar.gz netpbm-mirror-cdf6e0151411d887fef61245cb303ef190b29335.tar.xz netpbm-mirror-cdf6e0151411d887fef61245cb303ef190b29335.zip |
Promote Advanced to Stable
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@3641 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'other')
-rw-r--r-- | other/Makefile | 10 | ||||
-rw-r--r-- | other/pamexec.c | 1 | ||||
-rw-r--r-- | other/pamfix.c | 12 | ||||
-rw-r--r-- | other/pamlookup.c | 16 | ||||
-rw-r--r-- | other/pampick.c | 12 | ||||
-rw-r--r-- | other/pamsplit.c | 1 | ||||
-rw-r--r-- | other/pamx/Makefile | 10 | ||||
-rw-r--r-- | other/pamx/pamx.c | 1 | ||||
-rw-r--r-- | other/pamx/send.c | 119 | ||||
-rw-r--r-- | other/pamx/window.c | 1 | ||||
-rw-r--r-- | other/pnmcolormap.c | 173 |
11 files changed, 205 insertions, 151 deletions
diff --git a/other/Makefile b/other/Makefile index bd2c9dc2..aa0d75bb 100644 --- a/other/Makefile +++ b/other/Makefile @@ -45,6 +45,8 @@ OBJECTS = $(BINARIES:%=%.o) MERGEBINARIES = $(BINARIES) MERGE_OBJECTS = $(MERGEBINARIES:%=%.o2) +HAVE_MERGE_COMPAT=YES + .PHONY: all all: $(BINARIES) $(SUBDIRS:%=%/all) @@ -52,7 +54,7 @@ include $(SRCDIR)/common.mk ppmsvgalib: LDFLAGS_TARGET = $(shell $(LIBOPT) $(LINUXSVGALIB)) -install.bin: install.bin.local +install.bin install.merge: install.bin.local .PHONY: install.bin.local install.bin.local: $(PKGDIR)/bin # Remember that $(SYMLINK) might just be a copy command. @@ -69,4 +71,10 @@ install.bin.local: $(PKGDIR)/bin rm -f pnmdepth$(EXE) ; \ $(SYMLINK) pamdepth$(EXE) pnmdepth$(EXE) +mergecomptrylist: + cat /dev/null >$@ + echo "TRY(\"pnmarith\", main_pamarith);" >>$@ + echo "TRY(\"pnmsplit\", main_pamsplit);" >>$@ + echo "TRY(\"pnmdepth\", main_pamdepth);" >>$@ + FORCE: diff --git a/other/pamexec.c b/other/pamexec.c index d14d8752..c3a1ee78 100644 --- a/other/pamexec.c +++ b/other/pamexec.c @@ -11,6 +11,7 @@ ******************************************************************************/ +#define _DEFAULT_SOURCE 1 /* New name for SVID & BSD source defines */ #define _BSD_SOURCE 1 /* Make sure strdup() is in string.h */ #define _XOPEN_SOURCE 500 /* Make sure strdup() is in string.h */ diff --git a/other/pamfix.c b/other/pamfix.c index 8db67e08..e40f51f4 100644 --- a/other/pamfix.c +++ b/other/pamfix.c @@ -58,7 +58,7 @@ parseCommandLine(int argc, char ** const argv, /* Uses and sets argc, argv, and some of *cmdlineP and others. */ free(option_def); - if (argc-1 == 0) + if (argc-1 == 0) cmdlineP->inputFileName = "-"; else if (argc-1 != 1) pm_error("Program takes zero or one argument (filename). You " @@ -119,7 +119,7 @@ analyzeRaster(const struct pam * const pamP, unsigned int row; jmp_buf jmpbuf; int rc; - + tuplerow = pnm_allocpamrow(pamP); pm_setusererrormsgfn(handleRowErrMsg); @@ -178,13 +178,13 @@ clipPamRow(const struct pam * const pamP, unsigned int plane; for (plane = 0; plane < pamP->depth; ++plane) { if (tuplerow[col][plane] > pamP->maxval) { - if (verbose) + if (verbose) pm_message("Clipping: Row %u Col %u Plane %u. " "Sample value %lu exceeds the " "image maxval of %lu", row, col, plane, tuplerow[col][plane], pamP->maxval); - tuplerow[col][plane] = pamP->maxval; + tuplerow[col][plane] = pamP->maxval; } } } @@ -211,7 +211,7 @@ copyGoodRows(const struct pam * const inpamP, clipPamRow(outpamP, tuplerow, row, verbose); pnm_writepamrow(outpamP, tuplerow); } - + pnm_freepamrow(tuplerow); } @@ -283,7 +283,7 @@ main(int argc, char * argv[]) { copyGoodRows(&tweakedPam, &outpam, cmdline.verbose); pm_close(inpam.file); - + return 0; } diff --git a/other/pamlookup.c b/other/pamlookup.c index 4ceb047f..d57546d9 100644 --- a/other/pamlookup.c +++ b/other/pamlookup.c @@ -99,7 +99,8 @@ fitLookup(tuple ** const inputLookup, /*---------------------------------------------------------------------------- Scale the lookup table image so that it has dimensions 'cols' x 'rows'. -----------------------------------------------------------------------------*/ - const char * pamscaleCommand; + const char * widthArg; + const char * heightArg; struct pamtuples inPamtuples; struct pamtuples outPamtuples; @@ -107,18 +108,21 @@ fitLookup(tuple ** const inputLookup, fitLookuppamP->width = cols; fitLookuppamP->height = rows; - pm_asprintf(&pamscaleCommand, "pamscale -width=%u -height=%u", cols, rows); + pm_asprintf(&widthArg, "-width=%u", cols); + pm_asprintf(&heightArg, "-height=%u", rows); inPamtuples.pamP = (struct pam *) &inputLookuppam; inPamtuples.tuplesP = (tuple ***) &inputLookup; outPamtuples.pamP = fitLookuppamP; outPamtuples.tuplesP = fitLookupP; - pm_system(&pm_feed_from_pamtuples, &inPamtuples, - &pm_accept_to_pamtuples, &outPamtuples, - pamscaleCommand); + pm_system_lp("pamscale", + &pm_feed_from_pamtuples, &inPamtuples, + &pm_accept_to_pamtuples, &outPamtuples, + "pamscale", widthArg, heightArg, NULL); - pm_strfree(pamscaleCommand); + pm_strfree(heightArg); + pm_strfree(widthArg); } diff --git a/other/pampick.c b/other/pampick.c index 61941f06..67d42fc5 100644 --- a/other/pampick.c +++ b/other/pampick.c @@ -58,7 +58,7 @@ isMemberOfUintSet(const struct uintSet * const uintSetP, unsigned int i; retval = FALSE; /* initial assumption */ - + for (i = 0; i < uintSetP->count; ++i) { if (uintSetP->list[i] == searchValue) retval = TRUE; @@ -137,7 +137,7 @@ parseCommandLine(int argc, const char ** argv, if (*endPtr != '\0') pm_error("Garbage in sequence number argument '%s': '%s'", argv[i+1], endPtr); - + if (strtolResult < 0) pm_error("Image sequence number cannot be negative. " "You specified %d", strtolResult); @@ -171,7 +171,7 @@ extractOneImage(FILE * const infileP, struct pam inpam; struct pam outpam; enum pm_check_code checkRetval; - + unsigned int row; tuple * tuplerow; @@ -222,13 +222,13 @@ main(int argc, const char *argv[]) { struct cmdlineInfo cmdline; int eof; /* No more images in input */ - unsigned int imageSeq; + unsigned int imageSeq; /* Sequence of current image in input file. First = 0 */ pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); - + eof = FALSE; for (imageSeq = 0; !eof; ++imageSeq) { if (isMemberOfUintSet(&cmdline.imageSeqList, imageSeq)) { @@ -247,6 +247,6 @@ main(int argc, const char *argv[]) { pm_close(stdin); pm_close(stdout); - + return 0; } diff --git a/other/pamsplit.c b/other/pamsplit.c index 26eb0d59..93c1726a 100644 --- a/other/pamsplit.c +++ b/other/pamsplit.c @@ -9,6 +9,7 @@ Contributed to the public domain by its author. ******************************************************************************/ +#define _DEFAULT_SOURCE 1 /* New name for SVID & BSD source defines */ #define _BSD_SOURCE 1 /* Make sure strdup() is in string.h */ #define _XOPEN_SOURCE 500 /* Make sure strdup() is in string.h */ diff --git a/other/pamx/Makefile b/other/pamx/Makefile index 4e06e0fd..e4892540 100644 --- a/other/pamx/Makefile +++ b/other/pamx/Makefile @@ -9,7 +9,7 @@ include $(BUILDDIR)/config.mk EXTERN_INCLUDE = -ifeq ($(shell pkg-config x11 --modversion --silence-errors),) +ifeq ($(shell $(PKG_CONFIG) x11 --modversion --silence-errors),) # Pkg-config has never heard of X11, or doesn't even exist ifneq ($(X11LIB),NONE) @@ -20,8 +20,8 @@ ifeq ($(shell pkg-config x11 --modversion --silence-errors),) endif else HAVE_X11LIB = Y - X11LIB = $(shell pkg-config x11 --libs) - EXTERN_INCLUDES += $(shell pkg-config x11 --cflags) + X11LIB = $(shell $(PKG_CONFIG) x11 --libs) + EXTERN_INCLUDES += $(shell $(PKG_CONFIG) x11 --cflags) endif ifeq ($(HAVE_X11LIB),Y) @@ -46,10 +46,10 @@ all: $(BINARIES) include $(SRCDIR)/common.mk -ifeq ($(shell pkg-config x11 --libs),) +ifeq ($(shell $(PKG_CONFIG) x11 --libs),) X11_LIBOPTS = $(shell $(LIBOPT) $(LIBOPTR) $(X11LIB)) else - X11_LIBOPTS = $(shell pkg-config x11 --libs) + X11_LIBOPTS = $(shell $(PKG_CONFIG) x11 --libs) endif pamx: image.o send.o window.o diff --git a/other/pamx/pamx.c b/other/pamx/pamx.c index e22693ea..35900f82 100644 --- a/other/pamx/pamx.c +++ b/other/pamx/pamx.c @@ -3,6 +3,7 @@ Copyright information is in the file COPYRIGHT */ +#define _DEFAULT_SOURCE /* New name for SVID & BSD source defines */ #define _XOPEN_SOURCE 500 /* Make sure strdup() is in string.h */ #define _BSD_SOURCE /* Make sure strdup() is in <string.h> */ #include <signal.h> diff --git a/other/pamx/send.c b/other/pamx/send.c index fd50d5e9..3c3852e2 100644 --- a/other/pamx/send.c +++ b/other/pamx/send.c @@ -22,9 +22,10 @@ #include "send.h" #define TRUE_TO_15BIT(PIXEL) \ + ((unsigned short) \ ((((PIXEL) & 0xf80000) >> 9) | \ (((PIXEL) & 0x00f800) >> 6) | \ - (((PIXEL) & 0x0000f8) >> 3)) + (((PIXEL) & 0x0000f8) >> 3))) #define RED_INTENSITY(P) (((P) & 0x7c00) >> 10) #define GREEN_INTENSITY(P) (((P) & 0x03e0) >> 5) @@ -116,63 +117,97 @@ bitsPerPixelAtDepth(Display * const disp, -static Image * -itrueToRGB(Image * const imageP, - unsigned int const ddepth) { - - int y, x, num_pixels, colors; - unsigned long pixel_counts[32786]; - unsigned long pixel_array[32786]; - Pixel pixval; +static void +findColors(const Image * const imageP, + unsigned int * const pixelCt) { +/*---------------------------------------------------------------------------- + Find the colors in the Itrue raster 'raster'; return the histogram of + those colors as 'pixelCt'. +-----------------------------------------------------------------------------*/ + unsigned short color; unsigned char * pixel; - unsigned char * dpixel; - Image * newImageP; - - newImageP = newRGBImage(imageP->width, imageP->height, ddepth); + unsigned int y; - colors = 1 << ddepth; - - memset(pixel_counts, 0, 32768 * sizeof(unsigned long)); + for (color = 0; color < 32768; ++color) + pixelCt[color] = 0; /* initial value */ - pixel= imageP->data; - for (y= 0; y < imageP->height; y++) { + for (y = 0, pixel = imageP->data; y < imageP->height; ++y) { unsigned int x; - for (x= 0; x < imageP->width; x++) { - unsigned int const z = TRUE_TO_15BIT(memToVal(pixel, 3)); - pixel_counts[z]++; + for (x = 0; x < imageP->width; ++x) { + unsigned int const color = TRUE_TO_15BIT(memToVal(pixel, 3)); + ++pixelCt[color]; pixel += 3; } } - num_pixels = 0; - for (x = 0; x < 32768; ++x) { - if (pixel_counts[x] > 0) { - unsigned long const red = RED_INTENSITY(x); - unsigned long const grn = GREEN_INTENSITY(x); - unsigned long const blu = BLUE_INTENSITY(x); - pixel_counts[x] = num_pixels; - *(newImageP->rgb.red + num_pixels) = red<<11; - *(newImageP->rgb.grn + num_pixels) = grn<<11; - *(newImageP->rgb.blu + num_pixels) = blu<<11; - pixel_array[num_pixels++] = (short)x; - if (num_pixels > colors) - break; +} + + + +static Image * +pseudoColorImageFromItrue(Image * const imageP, + unsigned int const ddepth) { +/*---------------------------------------------------------------------------- + A pseudoColor image from the RGB image *imageP. + + We compute the index -- i.e. assign each color in *imageP a number. +-----------------------------------------------------------------------------*/ + unsigned int const maxColorCt = (1 << ddepth); + + unsigned int y; + unsigned int colorCt; + /* Number of colors we've indexed so far */ + unsigned int pixelCt[32768]; + /* colorCt[x] is the number of pixels of color 'x' in the image, + where 'x' is the 15 bit RGB representation of the color. + */ + unsigned int colorIndex[32768]; + /* colorIndex[x] is the color index we assigned to the color 'x', + where 'x' is the 15 bit RGB representation of the color. + */ + Pixel pixval; + unsigned char * dpixel; + Image * newImageP; + unsigned short color; /* A color, in 15 bit RGB */ + unsigned char * pixel; + + newImageP = newRGBImage(imageP->width, imageP->height, ddepth); + + findColors(imageP, pixelCt); + + for (color = 0, colorCt = 0; + color < 32768 && colorCt <= maxColorCt; + ++color) { + if (pixelCt[color] > 0) { + unsigned long const red = RED_INTENSITY(color); + unsigned long const grn = GREEN_INTENSITY(color); + unsigned long const blu = BLUE_INTENSITY(color); + + /* Put the color in the color map */ + newImageP->rgb.red[colorCt] = red<<11; + newImageP->rgb.grn[colorCt] = grn<<11; + newImageP->rgb.blu[colorCt] = blu<<11; + + /* Reverse-index it */ + colorIndex[color] = colorCt; + + ++colorCt; } } - - pixel = imageP->data; - dpixel = newImageP->data; + newImageP->rgb.used = colorCt; - for (y = 0; y < imageP->height; ++y) { + for (y = 0, pixel = imageP->data, dpixel = newImageP->data; + y < imageP->height; + ++y) { + unsigned int x; for (x = 0; x < imageP->width; ++x) { - unsigned int const z = TRUE_TO_15BIT(memToVal(pixel, 3)); - pixval = pixel_counts[z]; + unsigned short const color = TRUE_TO_15BIT(memToVal(pixel, 3)); + pixval = colorIndex[color]; valToMem(pixval, dpixel, newImageP->pixlen); pixel += 3; dpixel += newImageP->pixlen; } } - newImageP->rgb.used = num_pixels; newImageP->rgb.compressed = 1; return newImageP; @@ -197,7 +232,7 @@ makeUsableVisual(Image * const origImageP, *newImagePP = origImageP; break; case PseudoColor: - *newImagePP = itrueToRGB(origImageP, ddepth); + *newImagePP = pseudoColorImageFromItrue(origImageP, ddepth); if (*newImagePP == NULL) pm_error("Unable to convert for Pseudocolor."); break; diff --git a/other/pamx/window.c b/other/pamx/window.c index e2de1577..d907163b 100644 --- a/other/pamx/window.c +++ b/other/pamx/window.c @@ -6,6 +6,7 @@ See COPYRIGHT file for copyright information. */ +#define _DEFAULT_SOURCE /* New name for SVID & BSD source defines */ #define _XOPEN_SOURCE 500 /* Make sure strdup() is in string.h */ #define _BSD_SOURCE /* Make sure strcaseeq() is in nstring.h */ diff --git a/other/pnmcolormap.c b/other/pnmcolormap.c index 57db4329..f687f037 100644 --- a/other/pnmcolormap.c +++ b/other/pnmcolormap.c @@ -50,9 +50,9 @@ struct cmdlineInfo { */ const char *inputFilespec; /* Filespec of input file */ unsigned int allcolors; /* boolean: select all colors from the input */ - unsigned int newcolors; + unsigned int newcolors; /* Number of colors argument; meaningless if allcolors true */ - enum methodForLargest methodForLargest; + enum methodForLargest methodForLargest; /* -spreadintensity/-spreadluminosity options */ enum methodForRep methodForRep; /* -center/-meancolor/-meanpixel options */ @@ -68,7 +68,7 @@ parseCommandLine (int argc, char ** argv, struct cmdlineInfo *cmdlineP) { /*---------------------------------------------------------------------------- parse program command line described in Unix standard form by argc - and argv. Return the information in the options as *cmdlineP. + and argv. Return the information in the options as *cmdlineP. If command line is internally inconsistent (invalid options, etc.), issue error message to stderr and abort program. @@ -89,21 +89,21 @@ parseCommandLine (int argc, char ** argv, MALLOCARRAY_NOFAIL(option_def, 100); option_def_index = 0; /* incremented by OPTENT3 */ - OPTENT3(0, "spreadbrightness", OPT_FLAG, + OPTENT3(0, "spreadbrightness", OPT_FLAG, NULL, &spreadbrightness, 0); - OPTENT3(0, "spreadluminosity", OPT_FLAG, + OPTENT3(0, "spreadluminosity", OPT_FLAG, NULL, &spreadluminosity, 0); - OPTENT3(0, "center", OPT_FLAG, + OPTENT3(0, "center", OPT_FLAG, NULL, ¢er, 0); - OPTENT3(0, "meancolor", OPT_FLAG, + OPTENT3(0, "meancolor", OPT_FLAG, NULL, &meancolor, 0); - OPTENT3(0, "meanpixel", OPT_FLAG, + OPTENT3(0, "meanpixel", OPT_FLAG, NULL, &meanpixel, 0); - OPTENT3(0, "sort", OPT_FLAG, NULL, + OPTENT3(0, "sort", OPT_FLAG, NULL, &cmdlineP->sort, 0 ); - OPTENT3(0, "square", OPT_FLAG, NULL, + OPTENT3(0, "square", OPT_FLAG, NULL, &cmdlineP->square, 0 ); - OPTENT3(0, "verbose", OPT_FLAG, NULL, + OPTENT3(0, "verbose", OPT_FLAG, NULL, &cmdlineP->verbose, 0 ); opt.opt_table = option_def; @@ -114,7 +114,7 @@ parseCommandLine (int argc, char ** argv, /* Uses and sets argc, argv, and some of *cmdline_p and others. */ - if (spreadbrightness && spreadluminosity) + if (spreadbrightness && spreadluminosity) pm_error("You cannot specify both -spreadbrightness and " "spreadluminosity."); if (spreadluminosity) @@ -127,7 +127,7 @@ parseCommandLine (int argc, char ** argv, "-meanpixel."); if (meancolor) cmdlineP->methodForRep = REP_AVERAGE_COLORS; - else if (meanpixel) + else if (meanpixel) cmdlineP->methodForRep = REP_AVERAGE_PIXELS; else cmdlineP->methodForRep = REP_CENTER_BOX; @@ -179,7 +179,7 @@ static unsigned int compareplanePlane; tuples. qsort() doesn't pass any arguments except the two tuples. */ static int -compareplane(const void * const arg1, +compareplane(const void * const arg1, const void * const arg2) { const struct tupleint * const * const comparandPP = arg1; @@ -223,7 +223,7 @@ newColorMap(unsigned int const newcolors, for (i = 0; i < newcolors; ++i) { unsigned int plane; - for (plane = 0; plane < depth; ++plane) + for (plane = 0; plane < depth; ++plane) colormap.table[i]->tuple[plane] = 0; } colormap.size = newcolors; @@ -269,14 +269,14 @@ findBoxBoundaries(tupletable2 const colorfreqtable, minval[plane] = colorfreqtable.table[boxStart]->tuple[plane]; maxval[plane] = minval[plane]; } - + for (i = 1; i < boxSize; ++i) { unsigned int plane; for (plane = 0; plane < depth; ++plane) { sample const v = colorfreqtable.table[boxStart + i]->tuple[plane]; if (v < minval[plane]) minval[plane] = v; if (v > maxval[plane]) maxval[plane] = v; - } + } } } @@ -284,11 +284,11 @@ findBoxBoundaries(tupletable2 const colorfreqtable, static unsigned int largestByNorm(sample minval[], sample maxval[], unsigned int const depth) { - + unsigned int largestDimension; unsigned int plane; - sample largestSpreadSoFar = 0; + sample largestSpreadSoFar = 0; largestDimension = 0; for (plane = 0; plane < depth; ++plane) { sample const spread = maxval[plane]-minval[plane]; @@ -302,11 +302,11 @@ largestByNorm(sample minval[], sample maxval[], unsigned int const depth) { -static unsigned int -largestByLuminosity(sample minval[], sample maxval[], +static unsigned int +largestByLuminosity(sample minval[], sample maxval[], unsigned int const depth) { /*---------------------------------------------------------------------------- - This subroutine presumes that the tuple type is either + This subroutine presumes that the tuple type is either BLACKANDWHITE, GRAYSCALE, or RGB (which implies pamP->depth is 1 or 3). To save time, we don't actually check it. -----------------------------------------------------------------------------*/ @@ -323,7 +323,7 @@ largestByLuminosity(sample minval[], sample maxval[], largestSpreadSoFar = 0.0; for (plane = 0; plane < 3; ++plane) { - double const spread = + double const spread = pnm_lumin_factor[plane] * (maxval[plane]-minval[plane]); if (spread > largestSpreadSoFar) { largestDimension = plane; @@ -340,7 +340,7 @@ largestByLuminosity(sample minval[], sample maxval[], static void centerBox(int const boxStart, int const boxSize, - tupletable2 const colorfreqtable, + tupletable2 const colorfreqtable, unsigned int const depth, tuple const newTuple) { @@ -351,7 +351,7 @@ centerBox(int const boxStart, unsigned int i; minval = maxval = colorfreqtable.table[boxStart]->tuple[plane]; - + for (i = 1; i < boxSize; ++i) { int const v = colorfreqtable.table[boxStart + i]->tuple[plane]; minval = MIN( minval, v); @@ -366,7 +366,7 @@ centerBox(int const boxStart, static void averageColors(int const boxStart, int const boxSize, - tupletable2 const colorfreqtable, + tupletable2 const colorfreqtable, unsigned int const depth, tuple const newTuple) { @@ -378,7 +378,7 @@ averageColors(int const boxStart, sum = 0; - for (i = 0; i < boxSize; ++i) + for (i = 0; i < boxSize; ++i) sum += colorfreqtable.table[boxStart+i]->tuple[plane]; newTuple[plane] = ROUNDDIV(sum, boxSize); @@ -390,7 +390,7 @@ averageColors(int const boxStart, static void averagePixels(int const boxStart, int const boxSize, - tupletable2 const colorfreqtable, + tupletable2 const colorfreqtable, unsigned int const depth, tuple const newTuple) { @@ -411,7 +411,7 @@ averagePixels(int const boxStart, sum = 0; - for (i = 0; i < boxSize; ++i) + for (i = 0; i < boxSize; ++i) sum += colorfreqtable.table[boxStart+i]->tuple[plane] * colorfreqtable.table[boxStart+i]->value; @@ -423,9 +423,9 @@ averagePixels(int const boxStart, static tupletable2 colormapFromBv(unsigned int const newcolors, - boxVector const bv, + boxVector const bv, unsigned int const boxes, - tupletable2 const colorfreqtable, + tupletable2 const colorfreqtable, unsigned int const depth, enum methodForRep const methodForRep) { /* @@ -434,7 +434,7 @@ colormapFromBv(unsigned int const newcolors, ** One would be to choose the center of the box; this ignores any structure ** within the boxes. Another method would be to average all the colors in ** the box - this is the method specified in Heckbert's paper. A third - ** method is to average all the pixels in the box. + ** method is to average all the pixels in the box. */ tupletable2 colormap; unsigned int bi; @@ -443,8 +443,8 @@ colormapFromBv(unsigned int const newcolors, for (bi = 0; bi < boxes; ++bi) { switch (methodForRep) { - case REP_CENTER_BOX: - centerBox(bv[bi].ind, bv[bi].colors, colorfreqtable, depth, + case REP_CENTER_BOX: + centerBox(bv[bi].ind, bv[bi].colors, colorfreqtable, depth, colormap.table[bi]->tuple); break; case REP_AVERAGE_COLORS: @@ -467,7 +467,7 @@ colormapFromBv(unsigned int const newcolors, static unsigned int freqTotal(tupletable2 const freqtable) { - + unsigned int i; unsigned int sum; @@ -481,16 +481,16 @@ freqTotal(tupletable2 const freqtable) { static void -splitBox(boxVector const bv, - unsigned int * const boxesP, +splitBox(boxVector const bv, + unsigned int * const boxesP, unsigned int const bi, - tupletable2 const colorfreqtable, + tupletable2 const colorfreqtable, unsigned int const depth, enum methodForLargest const methodForLargest) { /*---------------------------------------------------------------------------- Split Box 'bi' in the box vector bv (so that bv contains one more box than it did as input). Split it so that each new box represents about - half of the pixels in the distribution given by 'colorfreqtable' for + half of the pixels in the distribution given by 'colorfreqtable' for the colors in the original box, but with distinct colors in each of the two new boxes. @@ -512,7 +512,7 @@ splitBox(boxVector const bv, MALLOCARRAY_NOFAIL(minval, depth); MALLOCARRAY_NOFAIL(maxval, depth); - findBoxBoundaries(colorfreqtable, depth, boxStart, boxSize, + findBoxBoundaries(colorfreqtable, depth, boxStart, boxSize, minval, maxval); /* Find the largest dimension, and sort by that component. I have @@ -521,28 +521,28 @@ splitBox(boxVector const bv, transforming into luminosities before the comparison. */ switch (methodForLargest) { - case LARGE_NORM: + case LARGE_NORM: largestDimension = largestByNorm(minval, maxval, depth); break; - case LARGE_LUM: + case LARGE_LUM: largestDimension = largestByLuminosity(minval, maxval, depth); break; } - + /* TODO: I think this sort should go after creating a box, not before splitting. Because you need the sort to use the REP_CENTER_BOX method of choosing a color to - represent the final boxes + represent the final boxes */ /* Set the gross global variable 'compareplanePlane' as a parameter to compareplane(), which is called by qsort(). */ compareplanePlane = largestDimension; - qsort((char*) &colorfreqtable.table[boxStart], boxSize, - sizeof(colorfreqtable.table[boxStart]), + qsort((char*) &colorfreqtable.table[boxStart], boxSize, + sizeof(colorfreqtable.table[boxStart]), compareplane); - + { /* Now find the median based on the counts, so that about half the pixels (not colors, pixels) are in each subdivision. */ @@ -571,7 +571,7 @@ splitBox(boxVector const bv, static void -mediancut(tupletable2 const colorfreqtable, +mediancut(tupletable2 const colorfreqtable, unsigned int const depth, int const newcolors, enum methodForLargest const methodForLargest, @@ -605,7 +605,7 @@ mediancut(tupletable2 const colorfreqtable, for (bi = 0; bi < boxes && bv[bi].colors < 2; ++bi); if (bi >= boxes) multicolorBoxesExist = FALSE; - else + else splitBox(bv, &boxes, bi, colorfreqtable, depth, methodForLargest); } *colormapP = colormapFromBv(newcolors, bv, boxes, colorfreqtable, depth, @@ -646,7 +646,7 @@ addImageColorsToHash(struct pam * const pamP, tuple * tuplerow; unsigned int row; - + tuplerow = pnm_allocpamrow(pamP); for (row = 0; row < pamP->height; ++row) { @@ -676,7 +676,7 @@ computeHistogram(FILE * const ifP, tupletable2 * const colorfreqtableP) { /*---------------------------------------------------------------------------- Make a histogram of the colors in the image stream in the file '*ifP'. - + Return as *freqPamP a description of the tuple values in the histogram. Only the fields of *freqPamP that describe individual tuples are meaningful (depth, maxval, tuple type); @@ -689,7 +689,7 @@ computeHistogram(FILE * const ifP, tuplehash tuplehash; unsigned int colorCount; int eof; - + pm_message("making histogram..."); tuplehash = pnm_createtuplehash(); @@ -699,7 +699,7 @@ computeHistogram(FILE * const ifP, for (imageSeq = 0; !eof; ++imageSeq) { struct pam inpam; - + pm_message("Scanning image %u", imageSeq); pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); @@ -708,7 +708,7 @@ computeHistogram(FILE * const ifP, firstPam = inpam; else validateCompatibleImage(&inpam, &firstPam, imageSeq); - + addImageColorsToHash(&inpam, tuplehash, &colorCount); pm_message("%u colors so far", colorCount); @@ -722,14 +722,14 @@ computeHistogram(FILE * const ifP, pnm_destroytuplehash(tuplehash); pm_message("%u colors found", colorfreqtableP->size); - + freqPamP->size = sizeof(*freqPamP); freqPamP->len = PAM_STRUCT_SIZE(tuple_type); freqPamP->maxval = firstPam.maxval; freqPamP->bytes_per_sample = pnm_bytespersample(freqPamP->maxval); freqPamP->depth = firstPam.depth; STRSCPY(freqPamP->tuple_type, firstPam.tuple_type); - + *formatP = firstPam.format; } @@ -737,8 +737,8 @@ computeHistogram(FILE * const ifP, static void computeColorMapFromInput(FILE * const ifP, - bool const allColors, - int const reqColors, + bool const allColors, + int const reqColors, enum methodForLargest const methodForLargest, enum methodForRep const methodForRep, int * const formatP, @@ -755,7 +755,7 @@ computeColorMapFromInput(FILE * const ifP, The colormap has the same maxval as the input. - Put the colormap in newly allocated storage as a tupletable2 + Put the colormap in newly allocated storage as a tupletable2 and return its address as *colormapP. Return the number of colors in it as *colorsP and its maxval as *colormapMaxvalP. @@ -766,7 +766,7 @@ computeColorMapFromInput(FILE * const ifP, tupletable2 colorfreqtable; computeHistogram(ifP, formatP, freqPamP, &colorfreqtable); - + if (allColors) { *colormapP = colorfreqtable; } else { @@ -787,16 +787,16 @@ computeColorMapFromInput(FILE * const ifP, static void -sortColormap(tupletable2 const colormap, +sortColormap(tupletable2 const colormap, sample const depth) { /*---------------------------------------------------------------------------- - Sort the colormap in place, in order of ascending Plane 0 value, + Sort the colormap in place, in order of ascending Plane 0 value, the Plane 1 value, etc. Use insertion sort. -----------------------------------------------------------------------------*/ int i; - + pm_message("Sorting %u colors...", colormap.size); for (i = 0; i < colormap.size; ++i) { @@ -806,8 +806,8 @@ sortColormap(tupletable2 const colormap, bool iIsGreater, iIsLess; iIsGreater = FALSE; iIsLess = FALSE; - for (plane = 0; - plane < depth && !iIsGreater && !iIsLess; + for (plane = 0; + plane < depth && !iIsGreater && !iIsLess; ++plane) { if (colormap.table[i]->tuple[plane] > colormap.table[j]->tuple[plane]) @@ -815,7 +815,7 @@ sortColormap(tupletable2 const colormap, else if (colormap.table[i]->tuple[plane] < colormap.table[j]->tuple[plane]) iIsLess = TRUE; - } + } if (iIsGreater) { for (plane = 0; plane < depth; ++plane) { sample const temp = colormap.table[i]->tuple[plane]; @@ -824,21 +824,21 @@ sortColormap(tupletable2 const colormap, colormap.table[j]->tuple[plane] = temp; } } - } + } } } -static void +static void colormapToSquare(struct pam * const pamP, tupletable2 const colormap, tuple *** const outputRasterP) { { unsigned int const intsqrt = (int)sqrt((float)colormap.size); - if (intsqrt * intsqrt == colormap.size) + if (SQR(intsqrt) == colormap.size) pamP->width = intsqrt; - else + else pamP->width = intsqrt + 1; } { @@ -852,17 +852,17 @@ colormapToSquare(struct pam * const pamP, tuple ** outputRaster; unsigned int row; unsigned int colormapIndex; - + outputRaster = pnm_allocpamarray(pamP); colormapIndex = 0; /* initial value */ - + for (row = 0; row < pamP->height; ++row) { unsigned int col; for (col = 0; col < pamP->width; ++col) { unsigned int plane; for (plane = 0; plane < pamP->depth; ++plane) { - outputRaster[row][col][plane] = + outputRaster[row][col][plane] = colormap.table[colormapIndex]->tuple[plane]; } if (colormapIndex < colormap.size-1) @@ -870,24 +870,24 @@ colormapToSquare(struct pam * const pamP, } } *outputRasterP = outputRaster; - } + } } -static void +static void colormapToSingleRow(struct pam * const pamP, tupletable2 const colormap, tuple *** const outputRasterP) { tuple ** outputRaster; unsigned int col; - + pamP->width = colormap.size; pamP->height = 1; - + outputRaster = pnm_allocpamarray(pamP); - + for (col = 0; col < pamP->width; ++col) { int plane; for (plane = 0; plane < pamP->depth; ++plane) @@ -904,7 +904,7 @@ colormapToImage(int const format, tupletable2 const colormap, bool const sort, bool const square, - struct pam * const outpamP, + struct pam * const outpamP, tuple *** const outputRasterP) { /*---------------------------------------------------------------------------- Create a tuple array and pam structure for an image which includes @@ -924,9 +924,9 @@ colormapToImage(int const format, if (sort) sortColormap(colormap, outpamP->depth); - if (square) + if (square) colormapToSquare(outpamP, colormap, outputRasterP); - else + else colormapToSingleRow(outpamP, colormap, outputRasterP); } @@ -950,8 +950,8 @@ main(int argc, char * argv[] ) { ifP = pm_openr(cmdline.inputFilespec); computeColorMapFromInput(ifP, - cmdline.allcolors, cmdline.newcolors, - cmdline.methodForLargest, + cmdline.allcolors, cmdline.newcolors, + cmdline.methodForLargest, cmdline.methodForRep, &format, &colormapPam, &colormap); @@ -964,9 +964,9 @@ main(int argc, char * argv[] ) { pm_message("Generating %u x %u image", outpam.width, outpam.height); outpam.file = stdout; - + pnm_writepam(&outpam, colormapRaster); - + pnm_freetupletable2(&colormapPam, colormap); pnm_freepamarray(colormapRaster, &outpam); @@ -975,3 +975,6 @@ main(int argc, char * argv[] ) { return 0; } + + + |