diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2021-03-27 19:16:06 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2021-03-27 19:16:06 +0000 |
commit | fcfa49ef6735be96386bda87bab2d0976475f585 (patch) | |
tree | fccbaafc41fb0f98682d4d48f7ff584bdbb81904 /converter/other | |
parent | a7fca291a0c78333da13e855bdb73aa819ba8649 (diff) | |
download | netpbm-mirror-fcfa49ef6735be96386bda87bab2d0976475f585.tar.gz netpbm-mirror-fcfa49ef6735be96386bda87bab2d0976475f585.tar.xz netpbm-mirror-fcfa49ef6735be96386bda87bab2d0976475f585.zip |
Promote Development to Advanced, Release 10.94.00
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@4076 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other')
-rw-r--r-- | converter/other/jpeg2000/libjasper_compat.h | 2 | ||||
-rw-r--r-- | converter/other/jpeg2000/pamtojpeg2k.c | 18 | ||||
-rw-r--r-- | converter/other/pamtowinicon.c | 4 | ||||
-rw-r--r-- | converter/other/pgmtopbm.c | 10 | ||||
-rw-r--r-- | converter/other/pngtopam.c | 24 | ||||
-rw-r--r-- | converter/other/pnmtopng.c | 92 | ||||
-rw-r--r-- | converter/other/pnmtops.c | 4 |
7 files changed, 89 insertions, 65 deletions
diff --git a/converter/other/jpeg2000/libjasper_compat.h b/converter/other/jpeg2000/libjasper_compat.h index 45dd904b..103b1d09 100644 --- a/converter/other/jpeg2000/libjasper_compat.h +++ b/converter/other/jpeg2000/libjasper_compat.h @@ -49,7 +49,7 @@ pmjas_image_decode(jas_stream_t * const in, if (jasperP) { *imagePP = jasperP; - *errorP = errorP; + *errorP = NULL; } else { pm_asprintf(errorP, "Failed. Details may have been written to " "Standard Error"); diff --git a/converter/other/jpeg2000/pamtojpeg2k.c b/converter/other/jpeg2000/pamtojpeg2k.c index a886c390..ee5189ce 100644 --- a/converter/other/jpeg2000/pamtojpeg2k.c +++ b/converter/other/jpeg2000/pamtojpeg2k.c @@ -35,7 +35,7 @@ enum compmode {COMPMODE_INTEGER, COMPMODE_REAL}; enum progression {PROG_LRCP, PROG_RLCP, PROG_RPCL, PROG_PCRL, PROG_CPRL}; -struct cmdlineInfo { +struct CmdlineInfo { /* All the information the user supplied in the command line, in a form easy for the program to use. */ @@ -73,7 +73,7 @@ struct cmdlineInfo { static void parseCommandLine(int argc, char ** argv, - struct cmdlineInfo * const cmdlineP) { + struct CmdlineInfo * const cmdlineP) { /*---------------------------------------------------------------------------- Note that many of the strings that this function returns in the *cmdline_p structure are actually in the supplied argv array. And @@ -372,9 +372,11 @@ convertToJasperImage(struct pam * const inpamP, static void writeJpc(jas_image_t * const jasperP, - struct cmdlineInfo const cmdline, - FILE * const ofP) { - + struct CmdlineInfo const cmdline, + int const ofd) { +/*---------------------------------------------------------------------------- + Write the image *jasperP to open file 'ofd'. +-----------------------------------------------------------------------------*/ jas_stream_t * outStreamP; const char * options; const char * ilyrratesOpt; @@ -459,7 +461,7 @@ writeJpc(jas_image_t * const jasperP, pm_strfree(ilyrratesOpt); /* Open the output image file (Standard Output) */ - outStreamP = jas_stream_fdopen(fileno(ofP), "w+b"); + outStreamP = jas_stream_fdopen(ofd, "w+b"); if (outStreamP == NULL) pm_error("Unable to open output stream. jas_stream_fdopen() " "failed"); @@ -500,7 +502,7 @@ writeJpc(jas_image_t * const jasperP, int main(int argc, char **argv) { - struct cmdlineInfo cmdline; + struct CmdlineInfo cmdline; FILE * ifP; struct pam inpam; jas_image_t * jasperP; @@ -526,7 +528,7 @@ main(int argc, char **argv) convertToJasperImage(&inpam, &jasperP); - writeJpc(jasperP, cmdline, stdout); + writeJpc(jasperP, cmdline, fileno(stdout)); jas_image_destroy(jasperP); diff --git a/converter/other/pamtowinicon.c b/converter/other/pamtowinicon.c index 7df8f60d..3c2c06bf 100644 --- a/converter/other/pamtowinicon.c +++ b/converter/other/pamtowinicon.c @@ -974,6 +974,10 @@ convertOneImage(unsigned int const imageNum, doingPng = pam.width * pam.height >= pngThreshold; + if (verbose) + pm_message("Image %2u: encoding as %s", + imageNum, doingPng ? "PNG" : "BMP"); + readAndScalePam(&pam, doingPng, tuples); determineImageType(&pam, tuples, &getPixel, diff --git a/converter/other/pgmtopbm.c b/converter/other/pgmtopbm.c index 64dc814b..d5f67a06 100644 --- a/converter/other/pgmtopbm.c +++ b/converter/other/pgmtopbm.c @@ -17,6 +17,7 @@ #include "pgm.h" #include "dithers.h" #include "mallocvar.h" +#include "rand.h" enum halftone {QT_FS, QT_THRESH, QT_DITHER8, QT_CLUSTER, QT_HILBERT}; @@ -462,14 +463,19 @@ createFsConverter(unsigned int const cols, /* Initialize Floyd-Steinberg error vectors. */ MALLOCARRAY_NOFAIL(stateP->thiserr, cols + 2); MALLOCARRAY_NOFAIL(stateP->nexterr, cols + 2); - srand(randomSeedSpec ? randomSeed : pm_randseed()); { /* (random errors in [-fs_scale/8 .. fs_scale/8]) */ unsigned int col; + struct pm_randSt randSt; + pm_randinit(&randSt); + pm_srand2(&randSt, randomSeedSpec, randomSeed); + for (col = 0; col < cols + 2; ++col) stateP->thiserr[col] = - (long)(rand() % fs_scale - half_fs_scale) / 4; + (long)(pm_rand(&randSt) % fs_scale - half_fs_scale) / 4; + + pm_randterm(&randSt); } stateP->fs_forward = TRUE; diff --git a/converter/other/pngtopam.c b/converter/other/pngtopam.c index 9098154a..3c0f81a5 100644 --- a/converter/other/pngtopam.c +++ b/converter/other/pngtopam.c @@ -668,10 +668,16 @@ dumpPngInfo(struct pngx * const pngxP) { background.blue); } - if (pngx_chunkIsPresent(pngxP, PNG_INFO_tRNS)) - pm_message("tRNS chunk (transparency): %u entries", - pngx_trns(pngxP).numTrans); - else + if (pngx_chunkIsPresent(pngxP, PNG_INFO_tRNS)) { + struct pngx_trns const trns = pngx_trns(pngxP); + + pm_message("tRNS chunk (transparency):"); + pm_message(" %u palette entries", trns.numTrans); + pm_message(" transparent color = (%u,%u,%u)", + trns.transColor.red, + trns.transColor.green, + trns.transColor.blue); + } else pm_message("tRNS chunk (transparency): not present"); if (pngx_chunkIsPresent(pngxP, PNG_INFO_gAMA)) @@ -868,17 +874,17 @@ paletteHasPartialTransparency(struct pngx * const pngxP) { if (pngx_chunkIsPresent(pngxP, PNG_INFO_tRNS)) { struct pngx_trns const trans = pngx_trns(pngxP); - bool foundGray; + bool foundPartial; unsigned int i; - for (i = 0, foundGray = FALSE; - i < trans.numTrans && !foundGray; + for (i = 0, foundPartial = FALSE; + i < trans.numTrans && !foundPartial; ++i) { if (trans.trans[i] != 0 && trans.trans[i] != pngxP->maxval) { - foundGray = TRUE; + foundPartial = TRUE; } } - retval = foundGray; + retval = foundPartial; } else retval = FALSE; } else diff --git a/converter/other/pnmtopng.c b/converter/other/pnmtopng.c index 8ad21a6a..23bd7d66 100644 --- a/converter/other/pnmtopng.c +++ b/converter/other/pnmtopng.c @@ -56,6 +56,7 @@ #endif /* 2 for warnings (1 == error) */ #include <assert.h> +#include <stdbool.h> #include <string.h> /* strcat() */ #include <limits.h> #include <png.h> @@ -140,12 +141,6 @@ typedef struct _jmpbuf_wrapper { jmp_buf jmpbuf; } jmpbuf_wrapper; -#ifndef TRUE -# define TRUE 1 -#endif -#ifndef FALSE -# define FALSE 0 -#endif #ifndef NONE # define NONE 0 #endif @@ -394,8 +389,8 @@ parseCommandLine(int argc, const char ** argv, opt.opt_table = option_def; - opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ - opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + opt.short_allowed = false; /* We have no short (old-fashioned) options */ + opt.allowNegNum = false; /* We have no parms that are negative numbers */ pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ @@ -511,6 +506,8 @@ parseCommandLine(int argc, const char ** argv, cmdlineP->inputFileName = argv[1]; else pm_error("Program takes at most one argument: input file name"); + + free(option_def); } @@ -671,7 +668,7 @@ lookupColorAlpha(coloralphahash_table const caht, /* The following variables belong to getChv() and freeChv() */ -static bool getChv_computed = FALSE; +static bool getChv_computed = false; static colorhist_vector getChv_chv; @@ -722,7 +719,7 @@ getChv(FILE * const ifP, else pm_message("Too many colors (more than %u) found", maxColors); } - getChv_computed = TRUE; + getChv_computed = true; } *chvP = getChv_chv; *colorsP = getChv_colors; @@ -736,7 +733,7 @@ static void freeChv(void) { if (getChv_chv) ppm_freecolorhist(getChv_chv); - getChv_computed = FALSE; + getChv_computed = false; } @@ -750,7 +747,7 @@ pgmBitsAreRepeated(unsigned int const repeatedSize, xelval const maxval, int const format) { /*---------------------------------------------------------------------------- - Return TRUE iff all the samples in the image in file 'ifP', + Return true iff all the samples in the image in file 'ifP', described by 'cols', 'rows', 'maxval', and 'format', consist in the rightmost 'repeatedSize' * 2 bits of two identical sets of 'repeatedSize' bits. @@ -774,7 +771,7 @@ pgmBitsAreRepeated(unsigned int const repeatedSize, pm_seek2(ifP, &rasterPos, sizeof(rasterPos)); - mayscale = TRUE; /* initial assumption */ + mayscale = true; /* initial assumption */ for (row = 0; row < rows && mayscale; ++row) { unsigned int col; @@ -785,7 +782,7 @@ pgmBitsAreRepeated(unsigned int const repeatedSize, xelval const testbits1 = testbits2 & mask1; /* The lower half of the bits of interest in the sample */ if (((testbits1 << repeatedSize) | testbits1) != testbits2) - mayscale = FALSE; + mayscale = false; } } pnm_freerow(xelrow); @@ -878,7 +875,7 @@ meaningful_bits_ppm(FILE * const ifp, maxMeaningfulBits = pm_maxvaltobits(maxval); if (maxval == 65535) { - mayscale = TRUE; /* initial assumption */ + mayscale = true; /* initial assumption */ pm_seek2(ifp, &rasterPos, sizeof(rasterPos)); for (row = 0; row < rows && mayscale; ++row) { unsigned int col; @@ -888,7 +885,7 @@ meaningful_bits_ppm(FILE * const ifp, if ((PPM_GETR(p) & 0xff) * 0x101 != PPM_GETR(p) || (PPM_GETG(p) & 0xff) * 0x101 != PPM_GETG(p) || (PPM_GETB(p) & 0xff) * 0x101 != PPM_GETB(p)) - mayscale = FALSE; + mayscale = false; } } if (mayscale) @@ -902,7 +899,7 @@ meaningful_bits_ppm(FILE * const ifp, static void -tryTransparentColor(FILE * const ifp, +tryTransparentColor(FILE * const ifP, pm_filepos const rasterPos, int const cols, int const rows, @@ -912,7 +909,14 @@ tryTransparentColor(FILE * const ifp, gray const alphaMaxval, pixel const transcolor, bool * const singleColorIsTransP) { +/*---------------------------------------------------------------------------- + Find out if the transparent pixels identified by alpha mask 'alphaMask' + (whose maxval is 'alphaMaxval') are exactly the pixels of color + 'transcolor'. Return answer as *singleColorIsTransP. + The image we analyze is that on input stream *ifP, starting at position + 'rasterPos', and we leave that stream positioned arbitrarily. +-----------------------------------------------------------------------------*/ int const pnmType = PNM_FORMAT_TYPE(format); xel * xelrow; @@ -922,13 +926,13 @@ tryTransparentColor(FILE * const ifp, xelrow = pnm_allocrow(cols); - pm_seek2(ifp, &rasterPos, sizeof(rasterPos)); + pm_seek2(ifP, &rasterPos, sizeof(rasterPos)); - singleColorIsTrans = TRUE; /* initial assumption */ + singleColorIsTrans = true; /* initial assumption */ for (row = 0; row < rows && singleColorIsTrans; ++row) { int col; - pnm_readpnmrow(ifp, xelrow, cols, maxval, format); + pnm_readpnmrow(ifP, xelrow, cols, maxval, format); for (col = 0 ; col < cols && singleColorIsTrans; ++col) { if (alphaMask[row][col] == 0) { /* transparent */ /* If we have a second transparent color, we're @@ -936,16 +940,16 @@ tryTransparentColor(FILE * const ifp, */ if (pnmType == PPM_TYPE) { if (!PPM_EQUAL(xelrow[col], transcolor)) - singleColorIsTrans = FALSE; + singleColorIsTrans = false; } else { if (PNM_GET1(xelrow[col]) != PNM_GET1(transcolor)) - singleColorIsTrans = FALSE; + singleColorIsTrans = false; } } else if (alphaMask[row][col] != alphaMaxval) { /* Here's an area of the mask that is translucent. That disqualified us. */ - singleColorIsTrans = FALSE; + singleColorIsTrans = false; } else { /* Here's an area of the mask that is opaque. If it's the same color as our candidate transparent color, @@ -953,10 +957,10 @@ tryTransparentColor(FILE * const ifp, */ if (pnmType == PPM_TYPE) { if (PPM_EQUAL(xelrow[col], transcolor)) - singleColorIsTrans = FALSE; + singleColorIsTrans = false; } else { if (PNM_GET1(xelrow[col]) == PNM_GET1(transcolor)) - singleColorIsTrans = FALSE; + singleColorIsTrans = false; } } } @@ -990,8 +994,8 @@ analyzeAlpha(FILE * const ifP, of a certain color fully transparent and every other pixel opaque, we can simply identify that color in the PNG. - We have to do this before any scaling occurs, since alpha is only - possible with 8 and 16-bit. + We have to do this before any scaling occurs, since alpha is possible + only with 8 and 16-bit. -----------------------------------------------------------------------------*/ xel * xelrow; bool foundTransparentPixel; @@ -1034,7 +1038,7 @@ analyzeAlpha(FILE * const ifP, pnm_readpnmrow(ifP, xelrow, cols, maxval, format); for (col = 0; col < cols && !foundTransparentPixel; ++col) { if (alphaMask[row][col] == 0) { - foundTransparentPixel = TRUE; + foundTransparentPixel = true; transcolor = pnm_xeltopixel(xelrow[col], format); } } @@ -1115,16 +1119,16 @@ determineTransparency(struct cmdlineInfo const cmdline, if (alphaCanBeTransparencyIndex && !cmdline.force) { if (verbose) pm_message("converting alpha mask to transparency index"); - *alphaP = FALSE; + *alphaP = false; *transparentP = 2; *transColorP = alphaTranscolor; } else if (allOpaque) { if (verbose) pm_message("Skipping alpha because mask is all opaque"); - *alphaP = FALSE; + *alphaP = false; *transparentP = -1; } else { - *alphaP = TRUE; + *alphaP = true; *transparentP = -1; } *alphaMaxvalP = alphaMaxval; @@ -1134,17 +1138,17 @@ determineTransparency(struct cmdlineInfo const cmdline, use with trans[], which can have stuff in it if the user specified a transparent color. */ - *alphaP = FALSE; + *alphaP = false; *alphaMaxvalP = 255; if (cmdline.transparent) { const char * transstring2; /* The -transparent value, but with possible leading '=' removed */ if (cmdline.transparent[0] == '=') { - *transExactP = TRUE; + *transExactP = true; transstring2 = &cmdline.transparent[1]; } else { - *transExactP = FALSE; + *transExactP = false; transstring2 = cmdline.transparent; } /* We do this funny PPM_DEPTH thing instead of just passing 'maxval' @@ -1206,7 +1210,7 @@ hasColor(FILE * const ifP, for (col = 0; col < cols && isGray; ++col) { xel const p = xelrow[col]; if (PPM_GETR(p) != PPM_GETG(p) || PPM_GETG(p) != PPM_GETB(p)) - isGray = FALSE; + isGray = false; } } @@ -1335,10 +1339,10 @@ compute_nonalpha_palette(colorhist_vector const chv, int j; bool found; - found = FALSE; + found = false; for (j = 0; j < ordered_palette_size && !found; ++j) { if (PNM_EQUAL(ordered_palette[j], chv[colorIndex].color)) - found = TRUE; + found = true; } if (!found) pm_error("failed to find color (%d, %d, %d), which is in the " @@ -1636,7 +1640,7 @@ compute_alpha_palette(FILE * const ifP, MAXPALETTEENTRIES elements. If there are more than MAXPALETTEENTRIES color/alpha pairs in the image, - don't return any palette information -- just return *tooBigP == TRUE. + don't return any palette information -- just return *tooBigP == true. -----------------------------------------------------------------------------*/ colorhist_vector chv; unsigned int colors; @@ -1714,9 +1718,9 @@ makeOneColorTransparentInPalette(xel const transColor, can do a better job when the opaque entries are all last in the color/alpha palette). - If the specified color is not there and exact == TRUE, return + If the specified color is not there and exact == true, return without changing anything, but issue a warning message. If it's - not there and exact == FALSE, just find the closest color. + not there and exact == false, just find the closest color. We assume every entry in the palette is opaque upon entry. @@ -2369,7 +2373,8 @@ writeRaster(struct pngx * const pngxP, /* max: 3 color channels, one alpha channel, 16-bit */ MALLOCARRAY(line, cols * 8); if (line == NULL) - pm_error("out of memory allocating PNG row buffer"); + pm_error("out of memory allocating PNG row buffer for %u columns", + cols); for (pass = 0; pass < pngxP->numPassesRequired; ++pass) { unsigned int row; @@ -2386,6 +2391,7 @@ writeRaster(struct pngx * const pngxP, pngx_writeRow(pngxP, line); } } + free(line); pnm_freerow(xelrow); } @@ -2837,9 +2843,9 @@ convertpnm(struct cmdlineInfo const cmdline, if (verbose) pm_message("Not using color map. %s", noColormapReason); pm_strfree(noColormapReason); - colorMapped = FALSE; + colorMapped = false; } else - colorMapped = TRUE; + colorMapped = true; computeColorMapLookupTable(colorMapped, palettePnm, paletteSize, transPnm, transSize, alpha, alphaMaxval, diff --git a/converter/other/pnmtops.c b/converter/other/pnmtops.c index 8c9167fb..3ca158b5 100644 --- a/converter/other/pnmtops.c +++ b/converter/other/pnmtops.c @@ -9,7 +9,7 @@ We use methods we learned from Dirk Krause's program Bmeps. Previous versions used raster encoding code based on Bmeps - code. This program does not used any code from Bmeps. + code. This program does not use any code from Bmeps. 2) Use our own filters and redefine /readstring . This is aboriginal Netpbm code, from when Postscript was young. The filters are @@ -1268,7 +1268,7 @@ putFilters(unsigned int const postscriptLevel, assert(postscriptLevel > 1); /* We say to decode flate, then rle, so Caller must ensure it encodes - rel, then flate. + rle, then flate. */ if (ascii85) |