diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2014-03-30 17:12:47 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2014-03-30 17:12:47 +0000 |
commit | 04afde0b11367018d95be801c543fdcf16420b5d (patch) | |
tree | 8c1ecbdf40aa57ff7fe47234708e3a2995d2b641 /converter | |
parent | fbf4dcdf76bf004ea45a762e8399268cc388ae19 (diff) | |
download | netpbm-mirror-04afde0b11367018d95be801c543fdcf16420b5d.tar.gz netpbm-mirror-04afde0b11367018d95be801c543fdcf16420b5d.tar.xz netpbm-mirror-04afde0b11367018d95be801c543fdcf16420b5d.zip |
Update to current Development release - 10.66.00
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@2172 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter')
-rw-r--r-- | converter/other/cameratopam/camera.c | 15 | ||||
-rw-r--r-- | converter/other/cameratopam/foveon.c | 20 | ||||
-rw-r--r-- | converter/other/pnmtopng.README | 101 | ||||
-rw-r--r-- | converter/other/pstopnm.c | 440 | ||||
-rw-r--r-- | converter/ppm/ppmtompeg/Makefile | 2 |
5 files changed, 277 insertions, 301 deletions
diff --git a/converter/other/cameratopam/camera.c b/converter/other/cameratopam/camera.c index 254b6710..4008dbb2 100644 --- a/converter/other/cameratopam/camera.c +++ b/converter/other/cameratopam/camera.c @@ -687,15 +687,22 @@ static int radc_token (int tree) void kodak_radc_load_raw() { - int row, col, tree, nreps, rep, step, i, c, s, r, x, y, val; + int row, col, tree, nreps, rep, step, c, s, r, x, y, val; + unsigned int i; short last[3] = { 16,16,16 }, mul[3], buf[3][3][386]; init_decoder(); getbits(ifp, -1); - for (i=0; i < sizeof(buf)/sizeof(short); i++) - buf[0][0][i] = 2048; + for (i = 0; i < 3; ++i) { + unsigned int j; + for (j = 0; j < 3; ++j) { + unsigned int k; + buf[i][j][k] = 2048; + } + } for (row=0; row < height; row+=4) { - for (i=0; i < 3; i++) + unsigned int i; + for (i = 0; i < 3; ++i) mul[i] = getbits(ifp, 6); FORC3 { val = ((0x1000000/last[c] + 0x7ff) >> 12) * mul[c]; diff --git a/converter/other/cameratopam/foveon.c b/converter/other/cameratopam/foveon.c index 78e40baf..aa42da36 100644 --- a/converter/other/cameratopam/foveon.c +++ b/converter/other/cameratopam/foveon.c @@ -474,9 +474,13 @@ foveon_interpolate(float coeff[3][4]) { black = calloc (height, sizeof *black); for (row=0; row < height; row++) { - for (i=0; i < 6; i++) - ddft[0][0][i] = ddft[1][0][i] + - row / (height-1.0) * (ddft[2][0][i] - ddft[1][0][i]); + unsigned int i; + for (i=0; i < 3; ++i) { + unsigned int j; + for (j = 0; j < 2; ++j) + ddft[0][i][j] = ddft[1][i][j] + + row / (height-1.0) * (ddft[2][i][j] - ddft[1][i][j]); + } FORC3 black[row][c] = ( foveon_avg (image[row*width]+c, dscr[0], cfilt) + foveon_avg (image[row*width]+c, dscr[1], cfilt) * 3 @@ -522,9 +526,13 @@ foveon_interpolate(float coeff[3][4]) { FORC3 black[row][c] += fsum[c]/2 + total[c]/(total[3]*100.0); for (row=0; row < height; row++) { - for (i=0; i < 6; i++) - ddft[0][0][i] = ddft[1][0][i] + - row / (height-1.0) * (ddft[2][0][i] - ddft[1][0][i]); + unsigned int i; + for (i = 0; i < 3; ++i) { + unsigned int j; + for (j = 0; j < 2; ++j) + ddft[0][i][j] = ddft[1][i][j] + + row / (height-1.0) * (ddft[2][i][j] - ddft[1][i][j]); + } pix = (short*)image[row*width]; memcpy (prev, pix, sizeof prev); frow = row / (height-1.0) * (dim[2]-1); diff --git a/converter/other/pnmtopng.README b/converter/other/pnmtopng.README deleted file mode 100644 index bfa524dc..00000000 --- a/converter/other/pnmtopng.README +++ /dev/null @@ -1,101 +0,0 @@ -Pnmtopng and Pngtopnm are based on programs of the same name in the -Pnmtopng package owned by Alexander Lehmann and Willem Van Schaik, -available at http://www.libpng.org/pub/png/src on 2001.07.14. - -I added it to and adapted it to Netpbm on 2000.03.02 to make it more -easily available to people. I applied a patch on 2000.06.03 to bring -it up the 2.37.4 release of that package. I updated it again on -2001.07.14 to bring it up to Release 2.37.5. There is no process in -place to bring improvements to the base package into the Netpbm -version, but there hasn't been a lot of update activity anyway. - -Attached below is the file README from Release 2.37.5 of the base -package. - -Here are the differences between the base and the Netpbm version: - - I added an "unsigned" to make formal and actual arguments to png_sig_cmp() - match and quiet a compiler warning. - - I fixed an "include" statement so the dependencies work out right. - - I removed the BIGGRAYS stuff, which became obsolete in Netpbm 9.0 - - I replaced a PPM_MAXVAL with PPM_OVERALLMAXAL to handle the new 16 bits - formats. - - macro VERSION is defined directly in pngtopnm.c and pnmtopng.c instead - of being included via file version.h. - - Pnmtopng, since June 2001, reads one row at a time instead of holding - the entire image in memory. That makes it work with large bitmaps - where it would otherwise run out of memory. It also works faster with - bitmaps since a bit takes up only a bit of memory in a cached input - file, but 96 bits of memory after reading it into a Netpbm data - structure. - - The base Pnmtopng ignores -transparent if it specifies a color that - isn't in the image. Netpbm's Pnmtopng selects a nearby color that _is_ - in the image, which is what base Pnmtopng did before October 2000. - Netpbm's Pnmtopng lets you put an '=' sign before the color to specify - that you don't want a nearby color to be chosen, i.e. you want the - base Pnmtopng function. This is consistent with Pnmtogif. - -There were some other changes necessary before Netpbm 9.0, but the change -of the xelval type from 1 byte to 4 made them unnecessary. - - -** PNMTOPNG / PNGTOPNM -** version 2.37.5 - 24 October 2000 - -[This is a semi-official bug-fix and enhancement release; I sort of took over - maintenance of this package while Willem was on an extended bike trip, and - for now I'm continuing with periodic, small updates. Version 2.37 (March - 1998) was never publicly released, partly because Willem had hoped to quiet - gcc's "<var> might be clobbered by `longjmp'" warnings. Those are fixed in - 2.37.2; under Solaris, they resulted in stack corruption even when there was - no error in the image files or libraries. Version 2.37.3 fixes a minor bug - w.r.t. error exits and generally does cleaner error exits (close files, etc.) - Version 2.37.4 fixes a bug that caused 16-shade grayscale images to be written - as 8-bit grayscale instead of (smaller) 4-bit colormapped images (bug report, - analysis and fix by Rafal Rzeczkowski), and it supports the new/upcoming - pbmplus release. Version 2.37.5 fixes a bug in -transparent handling (pnmtopng - no longer chooses an approximate color if the specified one isn't present) and - quiets a gcc warning in the non-16-bit version. - --Greg Roelofs] - -The utilities pnmtopng and pngtopnm are based on other pbm tools and require -the libraries included in the pbmplus/netpbm package. Also required are the -png library and the zlib compression library. - -These can be found at: - ftp://swrinde.nde.swri.edu/pub/png/src/libpng-* - ftp://swrinde.nde.swri.edu/pub/png/src/zlib-* - ftp://ftp.x.org/contrib/utilities/netpbm-1mar1994* -or see - http://www.libpng.org/pub/png/apps/pnmtopng.html - http://netpbm.sourceforge.net/ - http://www.acme.com/software/pbmplus/ [update coming soon?] - -To compile and install a makefile is provided. Do check the directories -where you have put the required libraries. Then either accommodate the -makefile or make links from generic names (e.g., zlib) to version-specific -directories (e.g., zlib-1.1.3), which is the recommended way. - -For testing purposes, have a look at the test-set PngSuite.tar.gz, which -contains a small test-image for every PNG color type and for most PNG chunk -types. It can be found at: - http://www.schaik.com/pngsuite/pngsuite.html - ftp://swrinde.nde.swri.edu/pub/png/images/suite/ - -Other web pages with PNG images are at: - http://www.libpng.org/pub/png/png-textures.html - http://www.libpng.org/pub/png/pngs-img.html - http://www.libpng.org/pub/png/pngpic2.html - http://www.libpng.org/pub/png/colorcube/ - http://www.libpng.org/pub/png/pngmisc.html#images - ------- -Alexander Lehmann <lehmann@usa.net> -Willem van Schaik <willem@schaik.com> -Greg Roelofs <newt@pobox.com> diff --git a/converter/other/pstopnm.c b/converter/other/pstopnm.c index d867b37b..27e98611 100644 --- a/converter/other/pstopnm.c +++ b/converter/other/pstopnm.c @@ -33,6 +33,8 @@ #include "shhopt.h" #include "nstring.h" +static bool verbose; + enum Orientation {PORTRAIT, LANDSCAPE, UNSPECIFIED}; struct Box { /* Description of a rectangle within an image; all coordinates @@ -46,6 +48,19 @@ struct Box { int ury; /* upper right Y coord */ }; +struct Dimensions { +/*---------------------------------------------------------------------------- + Horizontal and vertical dimensions of something, both in pixels and + spatial distance (points). + + Sizes are in pixels. Resolutions are in dots per inch (pixels per inch); +-----------------------------------------------------------------------------*/ + unsigned int xsize; + unsigned int ysize; + unsigned int xres; + unsigned int yres; +}; + struct CmdlineInfo { /* All the information the user supplied in the command line, in a form easy for the program to use. @@ -220,8 +235,7 @@ parseCommandLine(int argc, char ** argv, static void addPsToFileName(char const origFileName[], - const char ** const newFileNameP, - bool const verbose) { + const char ** const newFileNameP) { /*---------------------------------------------------------------------------- If origFileName[] does not name an existing file, but the same name with ".ps" added to the end does, return the name with the .ps @@ -256,30 +270,31 @@ addPsToFileName(char const origFileName[], static void -computeSizeResFromSizeSpec(unsigned int const requestedXsize, - unsigned int const requestedYsize, - unsigned int const imageWidth, - unsigned int const imageHeight, - unsigned int * const xsizeP, - unsigned int * const ysizeP, - unsigned int * const xresP, - unsigned int * const yresP) { +computeSizeResFromSizeSpec(unsigned int const requestedXsize, + unsigned int const requestedYsize, + unsigned int const imageWidth, + unsigned int const imageHeight, + struct Dimensions * const imageDimP) { if (requestedXsize) { - *xsizeP = requestedXsize; - *xresP = (unsigned int) (requestedXsize * 72 / imageWidth + 0.5); + imageDimP->xsize = requestedXsize; + imageDimP->xres = (unsigned int) + (requestedXsize * 72 / imageWidth + 0.5); if (!requestedYsize) { - *yresP = *xresP; - *ysizeP = (unsigned int) (imageHeight * (float)*yresP/72 + 0.5); + imageDimP->yres = imageDimP->xres; + imageDimP->ysize = (unsigned int) + (imageHeight * (float)imageDimP->yres/72 + 0.5); } } if (requestedYsize) { - *ysizeP = requestedYsize; - *yresP = (unsigned int) (requestedYsize * 72 / imageHeight + 0.5); + imageDimP->ysize = requestedYsize; + imageDimP->yres = (unsigned int) + (requestedYsize * 72 / imageHeight + 0.5); if (!requestedXsize) { - *xresP = *yresP; - *xsizeP = (unsigned int) (imageWidth * (float)*xresP/72 + 0.5); + imageDimP->xres = imageDimP->yres; + imageDimP->xsize = (unsigned int) + (imageWidth * (float)imageDimP->xres/72 + 0.5); } } } @@ -287,42 +302,36 @@ computeSizeResFromSizeSpec(unsigned int const requestedXsize, static void -computeSizeResBlind(unsigned int const xmax, - unsigned int const ymax, - unsigned int const imageWidth, - unsigned int const imageHeight, - bool const nocrop, - unsigned int * const xsizeP, - unsigned int * const ysizeP, - unsigned int * const xresP, - unsigned int * const yresP) { - - *xresP = *yresP = MIN(xmax * 72 / imageWidth, - ymax * 72 / imageHeight); +computeSizeResBlind(unsigned int const xmax, + unsigned int const ymax, + unsigned int const imageWidth, + unsigned int const imageHeight, + bool const nocrop, + struct Dimensions * const imageDimP) { + + imageDimP->xres = imageDimP->yres = MIN(xmax * 72 / imageWidth, + ymax * 72 / imageHeight); if (nocrop) { - *xsizeP = xmax; - *ysizeP = ymax; + imageDimP->xsize = xmax; + imageDimP->ysize = ymax; } else { - *xsizeP = (unsigned int) (imageWidth * (float)*xresP / 72 + 0.5); - *ysizeP = (unsigned int) (imageHeight * (float)*yresP / 72 + 0.5); + imageDimP->xsize = (unsigned int) + (imageWidth * (float)imageDimP->xres / 72 + 0.5); + imageDimP->ysize = (unsigned int) + (imageHeight * (float)imageDimP->yres / 72 + 0.5); } } static void -computeSizeRes(struct CmdlineInfo const cmdline, - enum Orientation const orientation, - struct Box const borderedBox, - unsigned int * const xsizeP, - unsigned int * const ysizeP, - unsigned int * const xresP, - unsigned int * const yresP) { +computeSizeRes(struct CmdlineInfo const cmdline, + struct Box const borderedBox, + struct Dimensions * const imageDimP) { /*---------------------------------------------------------------------------- - Figure out how big the output image should be (return as - *xsizeP and *ysizeP) and what output device resolution Ghostscript - should assume (return as *xresP, *yresP). + Figure out how big the output image should be and what output device + resolution Ghostscript should assume (return as *imageDimP). A resolution number is the number of pixels per inch that the a printer prints. Since we're emulating a printed page with a PNM @@ -337,38 +346,33 @@ computeSizeRes(struct CmdlineInfo const cmdline, tell Ghostscript that our horizontal output device resolution is 500 pixels per inch. - *xresP and *yresP are in dots per inch. + X and Y in all returned values is with respect to the image, not the + page. Note that the image might be placed sideways on the page, so that + page X and Y would be reversed from image X and Y. -----------------------------------------------------------------------------*/ - unsigned int sx, sy; - /* The horizontal and vertical sizes of the input image, in points - (1/72 inch) - */ - - if (orientation == LANDSCAPE) { - sx = borderedBox.ury - borderedBox.lly; - sy = borderedBox.urx - borderedBox.llx; - } else { - sx = borderedBox.urx - borderedBox.llx; - sy = borderedBox.ury - borderedBox.lly; - } + /* The horizontal and vertical sizes of the input image, in points + (1/72 inch) + */ + unsigned int const sx = borderedBox.urx - borderedBox.llx; + unsigned int const sy = borderedBox.ury - borderedBox.lly; if (cmdline.dpi) { /* User gave resolution; we figure out output image size */ - *xresP = *yresP = cmdline.dpi; - *xsizeP = (int) (cmdline.dpi * sx / 72 + 0.5); - *ysizeP = (int) (cmdline.dpi * sy / 72 + 0.5); + imageDimP->xres = imageDimP->yres = cmdline.dpi; + imageDimP->xsize = ROUNDU(cmdline.dpi * sx / 72.0); + imageDimP->ysize = ROUNDU(cmdline.dpi * sy / 72.0); } else if (cmdline.xsize || cmdline.ysize) computeSizeResFromSizeSpec(cmdline.xsize, cmdline.ysize, sx, sy, - xsizeP, ysizeP, xresP, yresP); + imageDimP); else computeSizeResBlind(cmdline.xmax, cmdline.ymax, sx, sy, cmdline.nocrop, - xsizeP, ysizeP, xresP, yresP); + imageDimP); if (cmdline.verbose) { pm_message("output is %u pixels wide X %u pixels high", - *xsizeP, *ysizeP); + imageDimP->xsize, imageDimP->ysize); pm_message("output device resolution is %u dpi horiz, %u dpi vert", - *xresP, *yresP); + imageDimP->xres, imageDimP->yres); } } @@ -377,8 +381,7 @@ computeSizeRes(struct CmdlineInfo const cmdline, enum PostscriptLanguage {COMMON_POSTSCRIPT, ENCAPSULATED_POSTSCRIPT}; static enum PostscriptLanguage -languageDeclaration(char const inputFileName[], - bool const verbose) { +languageDeclaration(char const inputFileName[]) { /*---------------------------------------------------------------------------- Return the Postscript language in which the file declares it is written. (Except that if the file is on Standard Input or doesn't validly declare @@ -421,8 +424,7 @@ languageDeclaration(char const inputFileName[], static struct Box computeBoxToExtract(struct Box const cmdlineExtractBox, - char const inputFileName[], - bool const verbose) { + char const inputFileName[]) { struct Box retval; @@ -572,8 +574,7 @@ computeOrientation(struct CmdlineInfo const cmdline, static struct Box addBorders(struct Box const inputBox, float const xborderScale, - float const yborderScale, - bool const verbose) { + float const yborderScale) { /*---------------------------------------------------------------------------- Return a box which is 'inputBox' plus some borders. @@ -592,16 +593,13 @@ addBorders(struct Box const inputBox, assert(inputBox.urx >= inputBox.llx); assert(inputBox.ury >= inputBox.lly); - assert(inputBox.llx >= leftRightBorderSize); - assert(inputBox.lly >= topBottomBorderSize); - - retval.llx = inputBox.llx - leftRightBorderSize; - retval.lly = inputBox.lly - topBottomBorderSize; - retval.urx = inputBox.urx + leftRightBorderSize; - retval.ury = inputBox.ury + topBottomBorderSize; + retval.llx = inputBox.llx - (int)leftRightBorderSize; + retval.lly = inputBox.lly - (int)topBottomBorderSize; + retval.urx = inputBox.urx + (int)leftRightBorderSize; + retval.ury = inputBox.ury + (int)topBottomBorderSize; if (verbose) - pm_message("With borders, extracted box is ((%u,%u),(%u,%u))", + pm_message("With borders, extracted box is ((%d,%d),(%d,%d))", retval.llx, retval.lly, retval.urx, retval.ury); return retval; @@ -609,32 +607,45 @@ addBorders(struct Box const inputBox, -static const char * -computePstrans(struct Box const box, - enum Orientation const orientation, - int const xsize, - int const ysize, - int const xres, - int const yres) { +static void +writePstrans(struct Box const box, + struct Dimensions const d, + enum Orientation const orientation, + FILE * const pipeToGsP) { - const char * retval; + int const xsize = d.xsize; + int const ysize = d.ysize; + int const xres = d.xres; + int const yres = d.yres; - if (orientation == PORTRAIT) { + const char * pstrans; + + switch (orientation) { + case PORTRAIT: { int llx, lly; llx = box.llx - (xsize * 72 / xres - (box.urx - box.llx)) / 2; lly = box.lly - (ysize * 72 / yres - (box.ury - box.lly)) / 2; - pm_asprintf(&retval, "%d neg %d neg translate", llx, lly); - } else { + pm_asprintf(&pstrans, "%d neg %d neg translate", llx, lly); + } break; + case LANDSCAPE: { int llx, ury; - llx = box.llx - (ysize * 72 / yres - (box.urx - box.llx)) / 2; - ury = box.ury + (xsize * 72 / xres - (box.ury - box.lly)) / 2; - pm_asprintf(&retval, "90 rotate %d neg %d neg translate", llx, ury); + llx = box.llx - (xsize * 72 / xres - (box.urx - box.llx)) / 2; + ury = box.ury + (ysize * 72 / yres - (box.ury - box.lly)) / 2; + pm_asprintf(&pstrans, "90 rotate %d neg %d neg translate", llx, ury); + } break; + case UNSPECIFIED: + assert(false); } - if (retval == NULL) + if (pstrans == pm_strsol) pm_error("Unable to allocate memory for pstrans"); - return retval; + if (verbose) + pm_message("Postscript prefix command: '%s'", pstrans); + + fprintf(pipeToGsP, "%s\n", pstrans); + + pm_strfree(pstrans); } @@ -753,16 +764,19 @@ findGhostscriptProg(const char ** const retvalP) { static void -execGhostscript(int const inputPipeFd, - char const ghostscriptDevice[], - char const outfileArg[], - int const xsize, - int const ysize, - int const xres, - int const yres, - unsigned int const textalphabits, - bool const verbose) { - +execGhostscript(int const inputPipeFd, + char const ghostscriptDevice[], + char const outfileArg[], + struct Dimensions const pageDim, + unsigned int const textalphabits) { +/*---------------------------------------------------------------------------- + Exec the Ghostscript program and have it execute the Postscript program + that it receives on 'inputPipeFd', then exit. + + 'pageDim' describes the print area. X and Y in 'pageDim' are with respect + to the page, independent of whether the program we receive on 'inputPipeFd' + puts an image in there sideways. +-----------------------------------------------------------------------------*/ const char * arg0; const char * ghostscriptProg; const char * deviceopt; @@ -781,8 +795,8 @@ execGhostscript(int const inputPipeFd, pm_asprintf(&arg0, "gs"); pm_asprintf(&deviceopt, "-sDEVICE=%s", ghostscriptDevice); pm_asprintf(&outfileopt, "-sOutputFile=%s", outfileArg); - pm_asprintf(&gopt, "-g%dx%d", xsize, ysize); - pm_asprintf(&ropt, "-r%dx%d", xres, yres); + pm_asprintf(&gopt, "-g%dx%d", pageDim.xsize, pageDim.ysize); + pm_asprintf(&ropt, "-r%dx%d", pageDim.xres, pageDim.yres); pm_asprintf(&textalphabitsopt, "-dTextAlphaBits=%u", textalphabits); /* -dSAFER causes Postscript to disable %pipe and file operations, @@ -810,23 +824,120 @@ execGhostscript(int const inputPipeFd, static void -executeGhostscript(char const pstrans[], +feedPsToGhostScript(const char * const inputFileName, + struct Box const borderedBox, + struct Dimensions const imageDim, + enum Orientation const orientation, + int const pipeToGhostscriptFd, + enum PostscriptLanguage const language) { +/*---------------------------------------------------------------------------- + Send a Postscript program to the Ghostscript process running on the + other end of the pipe 'pipeToGhostscriptFd'. That program is mostly + the contents of file 'inputFileName' (special value "-" means Standard + Input), but we may add a little to it. + + The image has dimensions 'imageDim' and is oriented on the page according + to 'orientation' ('imageDim' X and Y are with respect to the image itself, + without regard to how it is oriented on the page). +-----------------------------------------------------------------------------*/ + FILE * pipeToGsP; /* Pipe to Ghostscript's standard input */ + FILE * ifP; + bool eof; /* End of file on input */ + + pipeToGsP = fdopen(pipeToGhostscriptFd, "w"); + if (pipeToGsP == NULL) + pm_error("Unable to open stream on pipe to Ghostscript process."); + + ifP = pm_openr(inputFileName); + /* + In encapsulated Postscript, we the encapsulator are supposed to + handle showing the page (which we do by passing a showpage + statement to Ghostscript). Any showpage statement in the + input must be defined to have no effect. + + See "Enscapsulated PostScript Format File Specification", + v. 3.0, 1 May 1992, in particular Example 2, p. 21. I found + it at + http://partners.adobe.com/asn/developer/pdfs/tn/5002.EPSF_Spec.pdf + The example given is a much fancier solution than we need + here, I think, so I boiled it down a bit. JM + */ + if (language == ENCAPSULATED_POSTSCRIPT) + fprintf(pipeToGsP, "\n/b4_Inc_state save def /showpage { } def\n"); + + writePstrans(borderedBox, imageDim, orientation, pipeToGsP); + + /* If our child dies, it closes the pipe and when we next write to it, + we get a SIGPIPE. We must survive that signal in order to report + on the fate of the child. So we ignore SIGPIPE: + */ + signal(SIGPIPE, SIG_IGN); + + eof = FALSE; + while (!eof) { + char buffer[4096]; + size_t readCt; + + readCt = fread(buffer, 1, sizeof(buffer), ifP); + if (readCt == 0) + eof = TRUE; + else + fwrite(buffer, 1, readCt, pipeToGsP); + } + pm_close(ifP); + + if (language == ENCAPSULATED_POSTSCRIPT) + fprintf(pipeToGsP, "\nb4_Inc_state restore showpage\n"); + + fclose(pipeToGsP); +} + + + +static struct Dimensions +pageDimFromImageDim(struct Dimensions const imageDim, + enum Orientation const orientation) { +/*---------------------------------------------------------------------------- + The dimensions of the page of an image whose dimensions are + 'imageDim', if we place it on the page with orientation 'orientation'. + + (I.e. swap and X and Y if landscape orientation). + + 'orientation' must not be UNSPECIFIED. +-----------------------------------------------------------------------------*/ + struct Dimensions retval; + + switch (orientation) { + case PORTRAIT: + retval = imageDim; + break; + case LANDSCAPE: + retval.xsize = imageDim.ysize; + retval.ysize = imageDim.xsize; + retval.xres = imageDim.yres; + retval.yres = imageDim.xres; + break; + case UNSPECIFIED: + assert(false); + break; + } + + return retval; +} + + + +static void +executeGhostscript(char const inputFileName[], + struct Box const borderedBox, + struct Dimensions const imageDim, + enum Orientation const orientation, char const ghostscriptDevice[], char const outfileArg[], - int const xsize, - int const ysize, - int const xres, - int const yres, unsigned int const textalphabits, - char const inputFileName[], - enum PostscriptLanguage const language, - bool const verbose) { + enum PostscriptLanguage const language) { - int gsTermStatus; /* termination status of Ghostscript process */ - FILE * pipeToGsP; /* Pipe to Ghostscript's standard input */ - FILE * ifP; int rc; - int eof; /* End of file on input */ int pipefd[2]; if (strlen(outfileArg) > 80) @@ -845,65 +956,23 @@ executeGhostscript(char const pstrans[], /* Child process */ close(pipefd[1]); execGhostscript(pipefd[0], ghostscriptDevice, outfileArg, - xsize, ysize, xres, yres, textalphabits, - verbose); + pageDimFromImageDim(imageDim, orientation), + textalphabits); } else { + /* parent process */ pid_t const ghostscriptPid = rc; int const pipeToGhostscriptFd = pipefd[1]; - /* parent process */ - close(pipefd[0]); - - pipeToGsP = fdopen(pipeToGhostscriptFd, "w"); - if (pipeToGsP == NULL) - pm_error("Unable to open stream on pipe to Ghostscript process."); - - ifP = pm_openr(inputFileName); - /* - In encapsulated Postscript, we the encapsulator are supposed to - handle showing the page (which we do by passing a showpage - statement to Ghostscript). Any showpage statement in the - input must be defined to have no effect. - - See "Enscapsulated PostScript Format File Specification", - v. 3.0, 1 May 1992, in particular Example 2, p. 21. I found - it at - http://partners.adobe.com/asn/developer/pdfs/tn/5002.EPSF_Spec.pdf - The example given is a much fancier solution than we need - here, I think, so I boiled it down a bit. JM - */ - if (language == ENCAPSULATED_POSTSCRIPT) - fprintf(pipeToGsP, "\n/b4_Inc_state save def /showpage { } def\n"); - - if (verbose) - pm_message("Postscript prefix command: '%s'", pstrans); - - fprintf(pipeToGsP, "%s\n", pstrans); - /* If our child dies, it closes the pipe and when we next write to it, - we get a SIGPIPE. We must survive that signal in order to report - on the fate of the child. So we ignore SIGPIPE: - */ - signal(SIGPIPE, SIG_IGN); + int gsTermStatus; /* termination status of Ghostscript process */ + pid_t rc; - eof = FALSE; - while (!eof) { - char buffer[4096]; - int bytes_read; - - bytes_read = fread(buffer, 1, sizeof(buffer), ifP); - if (bytes_read == 0) - eof = TRUE; - else - fwrite(buffer, 1, bytes_read, pipeToGsP); - } - pm_close(ifP); + close(pipefd[0]); - if (language == ENCAPSULATED_POSTSCRIPT) - fprintf(pipeToGsP, "\nb4_Inc_state restore showpage\n"); + feedPsToGhostScript(inputFileName, borderedBox, + imageDim, orientation, + pipeToGhostscriptFd, language); - fclose(pipeToGsP); - - waitpid(ghostscriptPid, &gsTermStatus, 0); + rc = waitpid(ghostscriptPid, &gsTermStatus, 0); if (rc < 0) pm_error("Wait for Ghostscript process to terminated failed. " "errno = %d (%s)", errno, strerror(errno)); @@ -930,8 +999,8 @@ main(int argc, char ** argv) { struct CmdlineInfo cmdline; const char * inputFileName; /* malloc'ed */ /* The file specification of our Postscript input file */ - unsigned int xres, yres; /* Resolution in pixels per inch */ - unsigned int xsize, ysize; /* output image size in pixels */ + struct Dimensions imageDim; + /* Size and resolution of the input image */ struct Box extractBox; /* coordinates of the box within the input we are to extract; i.e. that will become the output. @@ -943,30 +1012,25 @@ main(int argc, char ** argv) { enum Orientation orientation; const char * ghostscriptDevice; const char * outfileArg; - const char * pstrans; pnm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); - addPsToFileName(cmdline.inputFileName, &inputFileName, cmdline.verbose); + verbose = cmdline.verbose; + + addPsToFileName(cmdline.inputFileName, &inputFileName); - extractBox = computeBoxToExtract(cmdline.extractBox, inputFileName, - cmdline.verbose); + extractBox = computeBoxToExtract(cmdline.extractBox, inputFileName); - language = languageDeclaration(inputFileName, cmdline.verbose); + language = languageDeclaration(inputFileName); orientation = computeOrientation(cmdline, extractBox); - borderedBox = addBorders(extractBox, cmdline.xborder, cmdline.yborder, - cmdline.verbose); + borderedBox = addBorders(extractBox, cmdline.xborder, cmdline.yborder); - computeSizeRes(cmdline, orientation, borderedBox, - &xsize, &ysize, &xres, &yres); + computeSizeRes(cmdline, borderedBox, &imageDim); - pstrans = computePstrans(borderedBox, orientation, - xsize, ysize, xres, yres); - outfileArg = computeOutfileArg(cmdline); ghostscriptDevice = @@ -974,14 +1038,12 @@ main(int argc, char ** argv) { pm_message("Writing %s format", ghostscriptDevice); - executeGhostscript(pstrans, ghostscriptDevice, outfileArg, - xsize, ysize, xres, yres, cmdline.textalphabits, - inputFileName, - language, cmdline.verbose); + executeGhostscript(inputFileName, borderedBox, imageDim, orientation, + ghostscriptDevice, outfileArg, cmdline.textalphabits, + language); pm_strfree(ghostscriptDevice); pm_strfree(outfileArg); - pm_strfree(pstrans); return 0; } diff --git a/converter/ppm/ppmtompeg/Makefile b/converter/ppm/ppmtompeg/Makefile index a1004fdd..4f244ae9 100644 --- a/converter/ppm/ppmtompeg/Makefile +++ b/converter/ppm/ppmtompeg/Makefile @@ -51,7 +51,7 @@ MP_ENCODE_OBJS = \ MP_OTHER_OBJS = mpeg.o subsample.o param.o rgbtoycc.o \ readframe.o combine.o jrevdct.o frame.o fsize.o frametype.o \ specifics.o rate.o opts.o input.o -ifeq ($(OMIT_NETWORK),y) +ifeq ($(OMIT_NETWORK),Y) MP_OTHER_OBJS += noparallel.o else MP_OTHER_OBJS += parallel.o psocket.o |