From 2370ca3409fa2bb893cef32391629a9e08ed607d Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 09 2020 23:29:04 +0000 Subject: Prepare for a new update Reverting patches so we can apply the latest update and changes can be seen in the spec file and sources. --- diff --git a/analyzer/pgmtexture.c b/analyzer/pgmtexture.c index c9576f5..84c6bf4 100644 --- a/analyzer/pgmtexture.c +++ b/analyzer/pgmtexture.c @@ -98,8 +98,6 @@ vector(unsigned int const nl, assert(nh >= nl); - overflow_add(nh - nl, 1); - MALLOCARRAY(v, (unsigned) (nh - nl + 1)); if (v == NULL) @@ -131,7 +129,6 @@ matrix (unsigned int const nrl, assert(nrh >= nrl); /* allocate pointers to rows */ - overflow_add(nrh - nrl, 1); MALLOCARRAY(m, (unsigned) (nrh - nrl + 1)); if (m == NULL) pm_error("Unable to allocate memory for a matrix."); @@ -140,7 +137,6 @@ matrix (unsigned int const nrl, assert (nch >= ncl); - overflow_add(nch - ncl, 1); /* allocate rows and set pointers to them */ for (i = nrl; i <= nrh; ++i) { MALLOCARRAY(m[i], (unsigned) (nch - ncl + 1)); diff --git a/buildtools/Makefile b/buildtools/Makefile index 8d6166f..0490865 100644 --- a/buildtools/Makefile +++ b/buildtools/Makefile @@ -44,7 +44,7 @@ genfontc:%:%.o $(NETPBMLIB) $(LD_FOR_BUILD) -o $@ $(LDFLAGS_FOR_BUILD) $< $(NETPBMLIB) $(BUILDPROGS):%:%.o - $(LD_FOR_BUILD) -o $@ $(LDFLAGSPRE) $< + $(LD_FOR_BUILD) -o $@ $(LDFLAGS_FOR_BUILD) $< distclean clean: cleanlocal .PHONY: cleanlocal diff --git a/buildtools/endiangen.c b/buildtools/endiangen.c index b870201..6b88b89 100644 --- a/buildtools/endiangen.c +++ b/buildtools/endiangen.c @@ -87,6 +87,7 @@ main(int argc, char **argv) { byteOrder() == ENDIAN_LITTLE ? "LITTLE_ENDIAN" : "BIG_ENDIAN"); printf("#endif\n"); printf("\n"); + printf("#define BITS_PER_LONG %u\n", bitsPerLong()); return 0; } diff --git a/config.mk.in b/config.mk.in index 08eced8..ee69233 100644 --- a/config.mk.in +++ b/config.mk.in @@ -128,7 +128,7 @@ INSTALL = $(SRCDIR)/buildtools/install.sh # STRIPFLAG is the option you pass to the above install program to make it # strip unnecessary information out of binaries. -STRIPFLAG = +STRIPFLAG = -s # If you don't want to strip the binaries, just leave it null: #STRIPFLAG = @@ -482,12 +482,12 @@ JBIGLIB = $(INTERNAL_JBIGLIB) JBIGHDR_DIR = $(INTERNAL_JBIGHDR_DIR) # The Jasper JPEG-2000 image compression library (aka JasPer): -JASPERLIB = "" -JASPERHDR_DIR = "/usr/include/jasper" +JASPERLIB = $(INTERNAL_JASPERLIB) +JASPERHDR_DIR = $(INTERNAL_JASPERHDR_DIR) # JASPERDEPLIBS is the libraries (-l options or file names) on which # The Jasper library depends -- i.e. what you have to link into any # executable that links in the Jasper library. -JASPERDEPLIBS = -ljasper +JASPERDEPLIBS = #JASPERDEPLIBS = -ljpeg # And the Utah Raster Toolkit (aka URT aka RLE) library: diff --git a/converter/other/anytopnm b/converter/other/anytopnm index 32c3ce3..e5de85c 100755 --- a/converter/other/anytopnm +++ b/converter/other/anytopnm @@ -537,8 +537,9 @@ else fi -tempdir=$(mktemp -d -t anytopnm.XXXXXXXX) || +tempdir=$(mktemp -d "${TMPDIR:-/tmp}/anytopnm.XXXXXXXX") || ( echo "Could not create temporary file. Exiting." 1>&2; exit 1; ) +trap 'rm -rf $tempdir' 0 # Take out all spaces # Find the filename extension for last-ditch efforts later @@ -564,17 +565,9 @@ if [ "$filetype" = "unknown" ]; then echo "$progname: unknown file type. " \ "'file' says mime type is '$mimeType', " 1>&2 echo "type description is '$typeDescription'" 1>&2 - if [ -d "$tempdir" ] ; then - rm -rf "$tempdir" - fi - exit 1 fi convertIt $file $filetype -if [ -d "$tempdir" ] ; then - rm -rf "$tempdir" -fi - exit 0 diff --git a/converter/other/bmptopnm.c b/converter/other/bmptopnm.c index b6102cb..018b832 100644 --- a/converter/other/bmptopnm.c +++ b/converter/other/bmptopnm.c @@ -1409,7 +1409,7 @@ readBmp(FILE * const ifP, xel ** const colormapP, bool const verbose) { - xel * colormap = NULL; /* malloc'ed */ + xel * colormap; /* malloc'ed */ unsigned int pos; /* Current byte position in the BMP file */ diff --git a/converter/other/fiasco/config.h b/converter/other/fiasco/config.h index 74fede5..57b3518 100644 --- a/converter/other/fiasco/config.h +++ b/converter/other/fiasco/config.h @@ -19,7 +19,7 @@ #define STDC_HEADERS 1 /* Define if you can safely include both and . */ -/* #undef TIME_WITH_SYS_TIME */ +#define TIME_WITH_SYS_TIME 1 /* Define if the X Window System is missing or not being used. */ #define X_DISPLAY_MISSING 1 @@ -72,7 +72,7 @@ #define HAVE_STRING_H 1 /* Define if you have the header file. */ -/* #undef HAVE_SYS_TIME_H */ +#define HAVE_SYS_TIME_H 1 /* Define if you have the header file. */ #define HAVE_UNISTD_H 1 diff --git a/converter/other/fiasco/lib/error.c b/converter/other/fiasco/lib/error.c index b56eb50..08291ce 100644 --- a/converter/other/fiasco/lib/error.c +++ b/converter/other/fiasco/lib/error.c @@ -89,10 +89,8 @@ set_error(const char *format, ...) { } else if (*str == 'c') { (void)va_arg(args, int); len += 1; - } else { - va_end(args); + } else return; - } ++str; } va_end(args); @@ -206,10 +204,8 @@ warning (const char *format, ...) VA_START (args, format); - if (verboselevel == FIASCO_NO_VERBOSITY) { - va_end (args); + if (verboselevel == FIASCO_NO_VERBOSITY) return; - } fprintf (stderr, "Warning: "); vfprintf (stderr, format, args); @@ -228,10 +224,8 @@ message (const char *format, ...) VA_START (args, format); - if (verboselevel == FIASCO_NO_VERBOSITY) { - va_end(args); + if (verboselevel == FIASCO_NO_VERBOSITY) return; - } vfprintf (stderr, format, args); fputc ('\n', stderr); @@ -248,10 +242,8 @@ debug_message (const char *format, ...) VA_START (args, format); - if (verboselevel < FIASCO_ULTIMATE_VERBOSITY) { - va_end (args); + if (verboselevel < FIASCO_ULTIMATE_VERBOSITY) return; - } fprintf (stderr, "*** "); vfprintf (stderr, format, args); @@ -269,10 +261,8 @@ info (const char *format, ...) VA_START (args, format); - if (verboselevel == FIASCO_NO_VERBOSITY) { - va_end (args); + if (verboselevel == FIASCO_NO_VERBOSITY) return; - } vfprintf (stderr, format, args); fflush (stderr); diff --git a/converter/other/fiasco/lib/image.h b/converter/other/fiasco/lib/image.h index 3d6ac04..a87a3c0 100644 --- a/converter/other/fiasco/lib/image.h +++ b/converter/other/fiasco/lib/image.h @@ -29,7 +29,7 @@ typedef struct image * Image data */ { - char id [8]; + char id [7]; unsigned reference_count; unsigned width; /* Width of the image */ unsigned height; /* Height of the image */ diff --git a/converter/other/gemtopnm.c b/converter/other/gemtopnm.c index fc96882..aac7479 100644 --- a/converter/other/gemtopnm.c +++ b/converter/other/gemtopnm.c @@ -101,13 +101,11 @@ main(argc, argv) if (planes == 1) type = PBM_TYPE; - else + else type = PPM_TYPE; - pnm_writepnminit( stdout, cols, rows, MAXVAL, type, 0 ); - + pnm_writepnminit( stdout, cols, rows, MAXVAL, type, 0 ); - overflow_add(cols, padright); { /* allocate input row data structure */ int plane; diff --git a/converter/other/jbig/Makefile b/converter/other/jbig/Makefile index 748a387..c4d7e9d 100644 --- a/converter/other/jbig/Makefile +++ b/converter/other/jbig/Makefile @@ -11,9 +11,8 @@ include $(BUILDDIR)/config.mk # INTERNAL_JBIGLIB must be relative to the current directory, because it # may end up in MERGE_OBJECTS, which must be relative. -INTERNAL_JBIGLIB = -INTERNAL_JBIGHDR_DIR = /usr/include -#INTERNAL_JBIGHDR_DIR = $(SRCDIR)/$(SUBDIR)/libjbig/include +INTERNAL_JBIGLIB = libjbig/libjbig.a +INTERNAL_JBIGHDR_DIR = $(SRCDIR)/$(SUBDIR)/libjbig/include EXTERN_INCLUDES = ifneq ($(JBIGHDR_DIR),NONE) @@ -36,6 +35,7 @@ SCRIPTS = ifeq ($(JBIGLIB),$(INTERNAL_JBIGLIB)) JBIGLIB_DEP = $(JBIGLIB) + SUBDIRS += libjbig else # It's not our internal version; user's on his own to make sure it's built endif @@ -49,3 +49,10 @@ include $(SRCDIR)/common.mk $(BINARIES): %: %.o $(JBIGLIB_DEP) $(LIBOPT) $(BINARIES): LDFLAGS_TARGET = $(shell $(LIBOPT) $(JBIGLIB)) + +$(INTERNAL_JBIGLIB): $(BUILDDIR)/$(SUBDIR)/libjbig FORCE + $(MAKE) -f $(SRCDIR)/$(SUBDIR)/libjbig/Makefile \ + -C $(dir $@) $(notdir $@) + +.PHONY: FORCE +FORCE: diff --git a/converter/other/jbig/jbigtopnm.c b/converter/other/jbig/jbigtopnm.c index 8fa076e..733ba22 100644 --- a/converter/other/jbig/jbigtopnm.c +++ b/converter/other/jbig/jbigtopnm.c @@ -279,7 +279,6 @@ int main (int argc, char **argv) } pm_close(fout); - pm_close(fin); jbg_dec_free(&s); diff --git a/converter/other/jbig/libjbig/jbig.c b/converter/other/jbig/libjbig/jbig.c index ba9c645..0d29f77 100644 --- a/converter/other/jbig/libjbig/jbig.c +++ b/converter/other/jbig/libjbig/jbig.c @@ -887,7 +887,7 @@ void jbg_enc_options(struct jbg_enc_state *s, int order, int options, if (order >= 0 && order <= 0x0f) s->order = order; if (options >= 0) s->options = options; if (l0 > 0) s->l0 = l0; - if (mx >= 0 && mx < 128) s->mx = mx; + if (mx >= 0 && my < 128) s->mx = mx; if (my >= 0 && my < 256) s->my = my; return; diff --git a/converter/other/jpeg2000/jpeg2ktopam.c b/converter/other/jpeg2000/jpeg2ktopam.c index 0a94f80..b727624 100644 --- a/converter/other/jpeg2000/jpeg2ktopam.c +++ b/converter/other/jpeg2000/jpeg2ktopam.c @@ -135,11 +135,11 @@ readJ2k(const char * const inputFilename, jasperP = jas_image_decode(instreamP, jas_image_getfmt(instreamP), (char*)options); - if (jasperP == NULL) { + if (jasperP == NULL) pm_error("Unable to interpret JPEG-2000 input. " "The Jasper library jas_image_decode() subroutine failed."); - } - jas_stream_close(instreamP); + + jas_stream_close(instreamP); *jasperPP = jasperP; } diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_util.c b/converter/other/jpeg2000/libjasper/jpc/jpc_util.c index 08ac238..82f4b28 100644 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_util.c +++ b/converter/other/jpeg2000/libjasper/jpc/jpc_util.c @@ -151,7 +151,7 @@ int jpc_atoaf(const char *s, int *numvalues, double **values) if ((cp = strtok(buf, delim))) { ++n; while ((cp = strtok(0, delim))) { - if (*cp != '\0') { + if (cp != '\0') { ++n; } } @@ -169,7 +169,7 @@ int jpc_atoaf(const char *s, int *numvalues, double **values) vs[n] = atof(cp); ++n; while ((cp = strtok(0, delim))) { - if (*cp != '\0') { + if (cp != '\0') { vs[n] = atof(cp); ++n; } diff --git a/converter/other/jpeg2000/pamtojpeg2k.c b/converter/other/jpeg2000/pamtojpeg2k.c index 066cc7d..3d8a97a 100644 --- a/converter/other/jpeg2000/pamtojpeg2k.c +++ b/converter/other/jpeg2000/pamtojpeg2k.c @@ -355,7 +355,7 @@ convertToJasperImage(struct pam * const inpamP, JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_B)); } } else { - if (strncmp(inpamP->tuple_type, "GRAYSCALE", 9) == 0 || + if (strncmp(inpamP->tuple_type, "GRAYSCALE", 9 == 0) || strncmp(inpamP->tuple_type, "BLACKANDWHITE", 13) == 0) { jas_image_setclrspc(jasperP, JAS_CLRSPC_GENGRAY); jas_image_setcmpttype(jasperP, 0, @@ -532,5 +532,7 @@ main(int argc, char **argv) pm_close(ifP); + pm_close(stdout); + return 0; } diff --git a/converter/other/jpegtopnm.c b/converter/other/jpegtopnm.c index 311298c..98552c0 100644 --- a/converter/other/jpegtopnm.c +++ b/converter/other/jpegtopnm.c @@ -862,8 +862,6 @@ convertImage(FILE * const ofP, /* Calculate output image dimensions so we can allocate space */ jpeg_calc_output_dimensions(cinfoP); - overflow2(cinfoP->output_width, cinfoP->output_components); - /* Start decompressor */ jpeg_start_decompress(cinfoP); diff --git a/converter/other/pbmtopgm.c b/converter/other/pbmtopgm.c index 382a487..69b20fb 100644 --- a/converter/other/pbmtopgm.c +++ b/converter/other/pbmtopgm.c @@ -47,7 +47,6 @@ main(int argc, char *argv[]) { "than the image height (%u rows)", height, rows); outrow = pgm_allocrow(cols) ; - overflow2(width, height); maxval = MIN(PGM_OVERALLMAXVAL, width*height); pgm_writepgminit(stdout, cols, rows, maxval, 0) ; diff --git a/converter/other/pnmtoddif.c b/converter/other/pnmtoddif.c index a2f045b..ac02e42 100644 --- a/converter/other/pnmtoddif.c +++ b/converter/other/pnmtoddif.c @@ -629,7 +629,6 @@ main(int argc, char *argv[]) { switch (PNM_FORMAT_TYPE(format)) { case PBM_TYPE: ip.bits_per_pixel = 1; - overflow_add(cols, 7); ip.bytes_per_line = (cols + 7) / 8; ip.spectral = 2; ip.components = 1; @@ -645,7 +644,6 @@ main(int argc, char *argv[]) { ip.polarity = 2; break; case PPM_TYPE: - overflow2(cols, 3); ip.bytes_per_line = 3 * cols; ip.bits_per_pixel = 24; ip.spectral = 5; diff --git a/converter/other/pnmtojpeg.c b/converter/other/pnmtojpeg.c index 757d08d..4482624 100644 --- a/converter/other/pnmtojpeg.c +++ b/converter/other/pnmtojpeg.c @@ -606,11 +606,7 @@ read_scan_script(j_compress_ptr const cinfo, want JPOOL_PERMANENT. */ const unsigned int scan_info_size = nscans * sizeof(jpeg_scan_info); - const jpeg_scan_info * scan_info; - - overflow2(nscans, sizeof(jpeg_scan_info)); - - scan_info = + jpeg_scan_info * const scan_info = (jpeg_scan_info *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, scan_info_size); @@ -942,8 +938,6 @@ compute_rescaling_array(JSAMPLE ** const rescale_p, const pixval maxval, const long half_maxval = maxval / 2; long val; - overflow_add(maxval, 1); - overflow2(maxval+1, sizeof(JSAMPLE)); *rescale_p = (JSAMPLE *) (cinfo.mem->alloc_small) ((j_common_ptr) &cinfo, JPOOL_IMAGE, (size_t) (((long) maxval + 1L) * @@ -1022,7 +1016,6 @@ convert_scanlines(struct jpeg_compress_struct * const cinfo_p, */ /* Allocate the libpnm output and compressor input buffers */ - overflow2(cinfo_p->image_width, cinfo_p->input_components); buffer = (*cinfo_p->mem->alloc_sarray) ((j_common_ptr) cinfo_p, JPOOL_IMAGE, (unsigned int) cinfo_p->image_width * cinfo_p->input_components, diff --git a/converter/other/pnmtops.c b/converter/other/pnmtops.c index 09c28d5..de0dfd8 100644 --- a/converter/other/pnmtops.c +++ b/converter/other/pnmtops.c @@ -294,21 +294,17 @@ parseCommandLine(int argc, const char ** argv, validateCompDimension(width, 72, "-width value"); validateCompDimension(height, 72, "-height value"); - overflow2(width, 72); cmdlineP->width = width * 72; - overflow2(height, 72); cmdlineP->height = height * 72; if (imagewidthSpec) { validateCompDimension(imagewidth, 72, "-imagewidth value"); - overflow2(imagewidth, 72); cmdlineP->imagewidth = imagewidth * 72; } else cmdlineP->imagewidth = 0; if (imageheightSpec) { - validateCompDimension(imageheight, 72, "-imageheight value"); - overflow2(imageheight, 72); + validateCompDimension(imagewidth, 72, "-imageheight value"); cmdlineP->imageheight = imageheight * 72; } else diff --git a/converter/other/pnmtotiffcmyk.c b/converter/other/pnmtotiffcmyk.c index 7b5a903..b7e3228 100644 --- a/converter/other/pnmtotiffcmyk.c +++ b/converter/other/pnmtotiffcmyk.c @@ -967,8 +967,8 @@ int main( int argc, char **argv ) { if ( (err = parseOpts( argc, argv, rt )) ) goto exit ; - if ( (err = (rt->in->open)( rt->in, rt )) ) goto exit ; - if ( (err = (rt->out->open)( rt->out, rt )) ) goto exit ; + if ( (err = rt->in->open( rt->in, rt )) ) goto exit ; + if ( (err = rt->out->open( rt->out, rt )) ) goto exit ; while ( rt->in->hasMore( rt->in ) ) { if ( (err = rt->in->next( rt->in, &r, &g, &b )) ) goto exit ; diff --git a/converter/other/pstopnm.c b/converter/other/pstopnm.c index f6d330e..e19a0fa 100644 --- a/converter/other/pstopnm.c +++ b/converter/other/pstopnm.c @@ -811,11 +811,11 @@ execGhostscript(int const inputPipeFd, ghostscriptProg, arg0, deviceopt, outfileopt, gopt, ropt, textalphabitsopt, "-q", "-dNOPAUSE", - "-dPARANOIDSAFER", "-"); + "-dSAFER", "-"); } execl(ghostscriptProg, arg0, deviceopt, outfileopt, gopt, ropt, "-q", - "-dNOPAUSE", "-dPARANOIDSAFER", "-", NULL); + "-dNOPAUSE", "-dSAFER", "-", NULL); pm_error("execl() of Ghostscript ('%s') failed, errno=%d (%s)", ghostscriptProg, errno, strerror(errno)); diff --git a/converter/other/rletopnm.c b/converter/other/rletopnm.c index 35ea7f7..018456c 100644 --- a/converter/other/rletopnm.c +++ b/converter/other/rletopnm.c @@ -19,8 +19,6 @@ * If you modify this software, you should include a notice giving the * name of the person performing the modification, the date of modification, * and the reason for such modification. - * - * 2002-12-19: Fix maths wrapping bugs. Alan Cox */ /* * rletopnm - A conversion program to convert from Utah's "rle" image format diff --git a/converter/other/sirtopnm.c b/converter/other/sirtopnm.c index 9fe49d0..fafcc91 100644 --- a/converter/other/sirtopnm.c +++ b/converter/other/sirtopnm.c @@ -69,7 +69,6 @@ char* argv[]; } break; case PPM_TYPE: - overflow3(cols, rows, 3); picsize = cols * rows * 3; planesize = cols * rows; if ( !( sirarray = (unsigned char*) malloc( picsize ) ) ) diff --git a/converter/other/svgtopam.c b/converter/other/svgtopam.c index 1d4081a..ca6f4dc 100644 --- a/converter/other/svgtopam.c +++ b/converter/other/svgtopam.c @@ -784,17 +784,12 @@ createCanvas(unsigned int const width, MALLOCVAR_NOFAIL(canvasP); - if(canvasP != NULL){ - canvasP->width = width; - canvasP->height = height; - canvasP->pixels = ppm_allocarray(width, height); - canvasP->maxval = maxval; - - *canvasPP = canvasP; - } else { - pm_error("can't allocate memory for canvas"); - } + canvasP->width = width; + canvasP->height = height; + canvasP->pixels = ppm_allocarray(width, height); + canvasP->maxval = maxval; + *canvasPP = canvasP; } diff --git a/converter/other/tifftopnm.c b/converter/other/tifftopnm.c index ef9253b..c1e7af8 100644 --- a/converter/other/tifftopnm.c +++ b/converter/other/tifftopnm.c @@ -1372,9 +1372,7 @@ convertRasterByRows(pnmOut * const pnmOutP, if (scanbuf == NULL) pm_error("can't allocate memory for scanline buffer"); - /* samplebuf is unsigned int * !!! */ - samplebuf = (unsigned int *) malloc3(cols , sizeof(unsigned int) , spp); - + MALLOCARRAY(samplebuf, cols * spp); if (samplebuf == NULL) pm_error("can't allocate memory for row buffer"); diff --git a/converter/other/xwdtopnm.c b/converter/other/xwdtopnm.c index c0c5b46..df3c737 100644 --- a/converter/other/xwdtopnm.c +++ b/converter/other/xwdtopnm.c @@ -210,10 +210,6 @@ processX10Header(X10WDFileHeader * const h10P, *colorsP = pnm_allocrow(2); PNM_ASSIGN1((*colorsP)[0], 0); PNM_ASSIGN1((*colorsP)[1], *maxvalP); - overflow_add(h10P->pixmap_width, 15); - if(h10P->pixmap_width < 0) - pm_error("assert: negative width"); - overflow2((((h10P->pixmap_width + 15) / 16) * 16 - h10P->pixmap_width), 8); *padrightP = (((h10P->pixmap_width + 15) / 16) * 16 - h10P->pixmap_width) * 8; *bits_per_itemP = 16; @@ -639,7 +635,6 @@ processX11Header(X11WDFileHeader * const h11P, *colsP = h11FixedP->pixmap_width; *rowsP = h11FixedP->pixmap_height; - overflow2(h11FixedP->bytes_per_line, 8); *padrightP = h11FixedP->bytes_per_line * 8 - h11FixedP->pixmap_width * h11FixedP->bits_per_pixel; @@ -1031,7 +1026,7 @@ pixelReader_getbits(pixelReader * const rdrP, unsigned long const bitsToTakeMask = lsbmask[nBitsToTake]; /* E.g. if nbitsToTake is 4, this is 0x0000000F */ - unsigned int bitsToTake; + unsigned long bitsToTake; /* The actual bits we take, in the 'nBitsToTake' low bits */ assert(nBitsToTake <= 32); diff --git a/converter/pbm/cmuwmtopbm.c b/converter/pbm/cmuwmtopbm.c index 021cc56..be8a7fc 100644 --- a/converter/pbm/cmuwmtopbm.c +++ b/converter/pbm/cmuwmtopbm.c @@ -18,7 +18,7 @@ This program does not check the pad bits at the end of each row. */ -#include + #include "pbm.h" /*-------------------------- @@ -42,7 +42,7 @@ readCmuwmHeader(FILE * const ifP, "CMU window manager header EOF / read error"; uint32_t const cmuwmMagic = 0xf10040bb; - uint32_t l; + long l; short s; int rc; diff --git a/converter/pbm/mdatopbm.c b/converter/pbm/mdatopbm.c index 12c7468..d8e0657 100644 --- a/converter/pbm/mdatopbm.c +++ b/converter/pbm/mdatopbm.c @@ -245,13 +245,10 @@ main(int argc, char **argv) { pm_readlittleshort(infile, &yy); nInCols = yy; } - overflow2(nOutCols, 8); nOutCols = 8 * nInCols; nOutRows = nInRows; - if (bScale) { - overflow2(nOutRows, 2); + if (bScale) nOutRows *= 2; - } data = pbm_allocarray(nOutCols, nOutRows); diff --git a/converter/pbm/mgrtopbm.c b/converter/pbm/mgrtopbm.c index 60e8477..9f7004a 100644 --- a/converter/pbm/mgrtopbm.c +++ b/converter/pbm/mgrtopbm.c @@ -65,8 +65,6 @@ readMgrHeader(FILE * const ifP, if (head.h_high < ' ' || head.l_high < ' ') pm_error("Invalid width field in MGR header"); - overflow_add(*colsP, pad); - *colsP = (((int)head.h_wide - ' ') << 6) + ((int)head.l_wide - ' '); *rowsP = (((int)head.h_high - ' ') << 6) + ((int) head.l_high - ' '); *padrightP = ( ( *colsP + pad - 1 ) / pad ) * pad - *colsP; diff --git a/converter/pbm/pbmto4425.c b/converter/pbm/pbmto4425.c index c4c8cbb..1d97ac6 100644 --- a/converter/pbm/pbmto4425.c +++ b/converter/pbm/pbmto4425.c @@ -2,7 +2,6 @@ #include "nstring.h" #include "pbm.h" -#include static char bit_table[2][3] = { {1, 4, 0x10}, @@ -161,7 +160,7 @@ main(int argc, char * argv[]) { xres = vmap_width * 2; yres = vmap_height * 3; - vmap = malloc3(vmap_width, vmap_height, sizeof(char)); + vmap = malloc(vmap_width * vmap_height * sizeof(char)); if(vmap == NULL) { pm_error( "Cannot allocate memory" ); diff --git a/converter/pbm/pbmtoepson.c b/converter/pbm/pbmtoepson.c index 5d67746..122a438 100644 --- a/converter/pbm/pbmtoepson.c +++ b/converter/pbm/pbmtoepson.c @@ -75,7 +75,7 @@ parseCommandLine(int argc, &dpiSpec, 0); OPTENT3(0, "adjacent", OPT_FLAG, NULL, &adjacentSpec, 0); - OPTENT3(0, "noadjacent", OPT_FLAG, NULL, + OPTENT3(0, "nonadjacent", OPT_FLAG, NULL, &nonadjacentSpec, 0); opt.opt_table = option_def; diff --git a/converter/pbm/pbmtogem.c b/converter/pbm/pbmtogem.c index 13b0257..9eab041 100644 --- a/converter/pbm/pbmtogem.c +++ b/converter/pbm/pbmtogem.c @@ -79,7 +79,6 @@ putinit (int const rows, int const cols) bitsperitem = 0; bitshift = 7; outcol = 0; - overflow_add(cols, 7); outmax = (cols + 7) / 8; outrow = (unsigned char *) pm_allocrow (outmax, sizeof (unsigned char)); lastrow = (unsigned char *) pm_allocrow (outmax, sizeof (unsigned char)); diff --git a/converter/pbm/pbmtogo.c b/converter/pbm/pbmtogo.c index d2ee91f..23b2ee9 100644 --- a/converter/pbm/pbmtogo.c +++ b/converter/pbm/pbmtogo.c @@ -158,7 +158,6 @@ main(int argc, bitrow = pbm_allocrow(cols); /* Round cols up to the nearest multiple of 8. */ - overflow_add(cols, 7); rucols = ( cols + 7 ) / 8; bytesperrow = rucols; /* GraphOn uses bytes */ rucols = rucols * 8; diff --git a/converter/pbm/pbmtolj.c b/converter/pbm/pbmtolj.c index 0b51932..3cd7670 100644 --- a/converter/pbm/pbmtolj.c +++ b/converter/pbm/pbmtolj.c @@ -120,11 +120,7 @@ parseCommandLine(int argc, char ** argv, static void allocateBuffers(unsigned int const cols) { - overflow_add(cols, 8); rowBufferSize = (cols + 7) / 8; - overflow_add(rowBufferSize, 128); - overflow_add(rowBufferSize, rowBufferSize+128); - overflow_add(rowBufferSize+10, rowBufferSize/8); packBufferSize = rowBufferSize + (rowBufferSize + 127) / 128 + 1; deltaBufferSize = rowBufferSize + rowBufferSize / 8 + 10; diff --git a/converter/pbm/pbmtoln03.c b/converter/pbm/pbmtoln03.c index 1b4c56b..f7cf53c 100644 --- a/converter/pbm/pbmtoln03.c +++ b/converter/pbm/pbmtoln03.c @@ -80,25 +80,22 @@ output_sixel_record (unsigned char * record, int width) { /* Do an encoding */ record[j++] = '!' ; sprintf (repeated_str, "%d", i - start_repeat) ; - for (p = repeated_str ; *p ; p++) { + for (p = repeated_str ; *p ; p++) record[j++] = *p ; - } - record[j++] = last_char ; + record[j++] = last_char ; } - } else { + else { for (k = 0 ; k < repeated ; k++) - record[j++] = last_char ; - } + record[j++] = last_char ; } start_repeat = i ; - last_char = record[i] ; + last_char = record[i] ; } } - } fwrite ((char *) record, j, 1, stdout) ; putchar ('-') ; /* DECGNL (graphics new-line) */ putchar ('\n') ; -} + } static void diff --git a/converter/pbm/pbmtomacp.c b/converter/pbm/pbmtomacp.c index 64f918b..df5cbb0 100644 --- a/converter/pbm/pbmtomacp.c +++ b/converter/pbm/pbmtomacp.c @@ -177,7 +177,7 @@ calculateCropPad(struct CmdlineInfo const cmdline, pm_message("Specified -bottom value %u is beyond edge of " "input image", cmdline.bottom); - bottom = MIN3(cmdline.bottom, rows - 1, top + MACP_ROWS - 1); + bottom = MIN3(cmdline.bottom, rows - 1, top + MACP_ROWS - 1); } else bottom = MIN(rows - 1, top + MACP_ROWS - 1); diff --git a/converter/pbm/pbmtomda.c b/converter/pbm/pbmtomda.c index 9efe5cf..3ad5149 100644 --- a/converter/pbm/pbmtomda.c +++ b/converter/pbm/pbmtomda.c @@ -179,7 +179,6 @@ int main(int argc, char **argv) nOutRowsUnrounded = bScale ? nInRows/2 : nInRows; - overflow_add(nOutRowsUnrounded, 3); nOutRows = ((nOutRowsUnrounded + 3) / 4) * 4; /* MDA wants rows a multiple of 4 */ nOutCols = nInCols / 8; diff --git a/converter/pbm/pbmtoppa/pbm.c b/converter/pbm/pbmtoppa/pbm.c index 32802d4..2f8a42b 100644 --- a/converter/pbm/pbmtoppa/pbm.c +++ b/converter/pbm/pbmtoppa/pbm.c @@ -12,7 +12,6 @@ #include #include -#include "ppm.h" #include "ppapbm.h" int make_pbm_stat(pbm_stat* pbm,FILE* fptr) @@ -107,7 +106,6 @@ int pbm_readline(pbm_stat* pbm,unsigned char* data) return 0; case P4: - overflow_add(pbm->width, 7); tmp=(pbm->width+7)/8; tmp2=fread(data,1,tmp,pbm->fptr); if(tmp2 == tmp) @@ -132,7 +130,6 @@ void pbm_unreadline (pbm_stat *pbm, void *data) return; pbm->unread = 1; - overflow_add(pbm->width, 7); pbm->revdata = malloc ((pbm->width+7)/8); memcpy (pbm->revdata, data, (pbm->width+7)/8); pbm->current_line--; diff --git a/converter/pbm/pbmtoppa/pbmtoppa.c b/converter/pbm/pbmtoppa/pbmtoppa.c index aa510ec..ff4a599 100644 --- a/converter/pbm/pbmtoppa/pbmtoppa.c +++ b/converter/pbm/pbmtoppa/pbmtoppa.c @@ -453,7 +453,6 @@ main(int argc, char *argv[]) { pm_error("main(): unrecognized parameter '%s'", argv[argn]); } - overflow_add(Width, 7); Pwidth=(Width+7)/8; printer.fptr=out; diff --git a/converter/pbm/pbmtoxbm.c b/converter/pbm/pbmtoxbm.c index fc0eb9c..ecb72b3 100644 --- a/converter/pbm/pbmtoxbm.c +++ b/converter/pbm/pbmtoxbm.c @@ -352,8 +352,6 @@ convertRaster(FILE * const ifP, unsigned char * bitrow; unsigned int row; - - overflow_add(cols, padright); putinit(xbmVersion); diff --git a/converter/pbm/pktopbm.c b/converter/pbm/pktopbm.c index b6fcb02..712f339 100644 --- a/converter/pbm/pktopbm.c +++ b/converter/pbm/pktopbm.c @@ -280,7 +280,6 @@ main(int argc, char *argv[]) { if (flagbyte == 7) { /* long form preamble */ integer packetlength = get32() ; /* character packet length */ car = get32() ; /* character number */ - overflow_add(packetlength, pktopbm_pkloc); endofpacket = packetlength + pktopbm_pkloc; /* calculate end of packet */ if ((car >= MAXPKCHAR) || !filename[car]) { diff --git a/converter/pbm/thinkjettopbm.l b/converter/pbm/thinkjettopbm.l index 7f31de5..5de4f2b 100644 --- a/converter/pbm/thinkjettopbm.l +++ b/converter/pbm/thinkjettopbm.l @@ -114,9 +114,7 @@ DIG [0-9] \033\*b{DIG}+W { int l; if (rowCount >= rowCapacity) { - overflow_add(rowCapacity, 100); - rowCapacity += 100; - overflow2(rowCapacity, sizeof *rows); + rowCapacity += 100; rows = realloc (rows, rowCapacity * sizeof *rows); if (rows == NULL) pm_error ("Out of memory."); @@ -228,8 +226,6 @@ yywrap (void) /* * Quite simple since ThinkJet bit arrangement matches PBM */ - - overflow2(maxRowLength, 8); pbm_writepbminit(stdout, maxRowLength*8, rowCount, 0); packed_bitrow = malloc(maxRowLength); diff --git a/converter/pbm/ybmtopbm.c b/converter/pbm/ybmtopbm.c index cf1ff03..2a42908 100644 --- a/converter/pbm/ybmtopbm.c +++ b/converter/pbm/ybmtopbm.c @@ -43,7 +43,6 @@ getinit(FILE * const ifP, pm_error("EOF / read error"); *depthP = 1; - overflow_add(*colsP, 15); } diff --git a/converter/pgm/lispmtopgm.c b/converter/pgm/lispmtopgm.c index b5469f7..40dd3fb 100644 --- a/converter/pgm/lispmtopgm.c +++ b/converter/pgm/lispmtopgm.c @@ -58,7 +58,6 @@ main( argc, argv ) pm_error( "depth (%d bits) is too large", depth); pgm_writepgminit( stdout, cols, rows, (gray) maxval, 0 ); - overflow_add(cols, 7); grayrow = pgm_allocrow( ( cols + 7 ) / 8 * 8 ); for ( row = 0; row < rows; ++row ) @@ -103,8 +102,6 @@ getinit( file, colsP, rowsP, depthP, padrightP ) if ( *depthP == 0 ) *depthP = 1; /* very old file */ - - overflow_add((int)colsP, 31); *padrightP = ( ( *colsP + 31 ) / 32 ) * 32 - *colsP; diff --git a/converter/pgm/psidtopgm.c b/converter/pgm/psidtopgm.c index 25bb311..07417d1 100644 --- a/converter/pgm/psidtopgm.c +++ b/converter/pgm/psidtopgm.c @@ -78,7 +78,6 @@ main(int argc, pm_error("bits/sample (%d) is too large.", bitspersample); pgm_writepgminit(stdout, cols, rows, maxval, 0); - overflow_add(cols, 7); grayrow = pgm_allocrow((cols + 7) / 8 * 8); for (row = 0; row < rows; ++row) { unsigned int col; diff --git a/converter/ppm/Makefile b/converter/ppm/Makefile index f68170f..003ef8d 100644 --- a/converter/ppm/Makefile +++ b/converter/ppm/Makefile @@ -7,11 +7,11 @@ VPATH=.:$(SRCDIR)/$(SUBDIR) include $(BUILDDIR)/config.mk -SUBDIRS = hpcdtoppm +SUBDIRS = hpcdtoppm ppmtompeg PORTBINARIES = 411toppm eyuvtoppm gouldtoppm ilbmtoppm imgtoppm \ leaftoppm mtvtoppm neotoppm \ - pcxtoppm pc1toppm pi1toppm pjtoppm \ + pcxtoppm pc1toppm pi1toppm picttoppm pjtoppm \ ppmtoacad ppmtoapplevol ppmtoarbtxt ppmtoascii \ ppmtobmp ppmtoeyuv ppmtogif ppmtoicr ppmtoilbm \ ppmtoleaf ppmtolj ppmtomitsu ppmtoneo \ diff --git a/converter/ppm/ilbmtoppm.c b/converter/ppm/ilbmtoppm.c index 2a86efc..662be0b 100644 --- a/converter/ppm/ilbmtoppm.c +++ b/converter/ppm/ilbmtoppm.c @@ -606,7 +606,6 @@ decode_row(FILE * const ifP, rawtype *chp; cols = bmhdP->w; - overflow_add(cols, 15); bytes = RowBytes(cols); for( plane = 0; plane < nPlanes; plane++ ) { int mask; @@ -694,23 +693,6 @@ decode_mask(FILE * const ifP, Multipalette handling ****************************************************************************/ -static void * -xmalloc2(x, y) - int x; - int y; -{ - void *mem; - - overflow2(x,y); - if( x * y == 0 ) - return NULL; - - mem = malloc2(x,y); - if( mem == NULL ) - pm_error("out of memory allocating %d bytes", x * y); - return mem; -} - static void multi_adjust(cmap, row, palchange) @@ -1373,9 +1355,6 @@ dcol_to_ppm(FILE * const ifP, if( redmaxval != maxval || greenmaxval != maxval || bluemaxval != maxval ) pm_message("scaling colors to %d bits", pm_maxvaltobits(maxval)); - overflow_add(redmaxval, 1); - overflow_add(greenmaxval, 1); - overflow_add(bluemaxval, 1); MALLOCARRAY_NOFAIL(redtable, redmaxval +1); MALLOCARRAY_NOFAIL(greentable, greenmaxval +1); MALLOCARRAY_NOFAIL(bluetable, bluemaxval +1); @@ -1805,9 +1784,7 @@ PCHG_ConvertSmall(PCHG, cmap, mask, datasize) ChangeCount32 = *data++; datasize -= 2; - overflow_add(ChangeCount16, ChangeCount32); changes = ChangeCount16 + ChangeCount32; - overflow_add(changes, 1); for( i = 0; i < changes; i++ ) { if( totalchanges >= PCHG->TotalChanges ) goto fail; if( datasize < 2 ) goto fail; @@ -2072,9 +2049,6 @@ read_pchg(FILE * const ifP, cmap->mp_change[i] = NULL; if( PCHG.StartLine < 0 ) { int nch; - if(PCHG.MaxReg < PCHG.MinReg) - pm_error("assert: MinReg > MaxReg"); - overflow_add(PCHG.MaxReg-PCHG.MinReg, 2); nch = PCHG.MaxReg - PCHG.MinReg +1; MALLOCARRAY_NOFAIL(cmap->mp_init, nch + 1); for( i = 0; i < nch; i++ ) @@ -2151,7 +2125,6 @@ process_body( FILE * const ifP, if (typeid == ID_ILBM) { int isdeep; - overflow_add(bmhdP->w, 15); MALLOCARRAY_NOFAIL(ilbmrow, RowBytes(bmhdP->w)); *viewportmodesP |= fakeviewport; /* -isham/-isehb */ diff --git a/converter/ppm/imgtoppm.c b/converter/ppm/imgtoppm.c index eb8509e..7078b88 100644 --- a/converter/ppm/imgtoppm.c +++ b/converter/ppm/imgtoppm.c @@ -84,7 +84,6 @@ main(int argc, char ** argv) { len = atoi((char*) buf ); if ( fread( buf, len, 1, ifp ) != 1 ) pm_error( "bad colormap buf" ); - overflow2(cmaplen, 3); if ( cmaplen * 3 != len ) { pm_message( @@ -106,7 +105,6 @@ main(int argc, char ** argv) { pm_error( "bad pixel data header" ); buf[8] = '\0'; len = atoi((char*) buf ); - overflow2(cols, rows); if ( len != cols * rows ) pm_message( "pixel data length (%d) does not match image size (%d)", diff --git a/converter/ppm/pcxtoppm.c b/converter/ppm/pcxtoppm.c index 270ae3b..e252ba2 100644 --- a/converter/ppm/pcxtoppm.c +++ b/converter/ppm/pcxtoppm.c @@ -409,7 +409,6 @@ pcx_planes_to_pixels(pixels, bitplanes, bytesperline, planes, bitsperpixel) /* * clear the pixel buffer */ - overflow2(bytesperline, 8); npixels = (bytesperline * 8) / bitsperpixel; p = pixels; while (--npixels >= 0) @@ -471,7 +470,6 @@ pcx_16col_to_ppm(FILE * const ifP, } /* BytesPerLine should be >= BitsPerPixel * cols / 8 */ - overflow2(BytesPerLine, 8); rawcols = BytesPerLine * 8 / BitsPerPixel; if (headerCols > rawcols) { pm_message("warning - BytesPerLine = %d, " diff --git a/converter/ppm/picttoppm.c b/converter/ppm/picttoppm.c index a59bf77..d412038 100644 --- a/converter/ppm/picttoppm.c +++ b/converter/ppm/picttoppm.c @@ -1,4 +1,3 @@ -#error "Unfixable. Don't ship me" /* * picttoppm.c -- convert a MacIntosh PICT file to PPM format. * diff --git a/converter/ppm/pjtoppm.c b/converter/ppm/pjtoppm.c index abec4db..7b694fb 100644 --- a/converter/ppm/pjtoppm.c +++ b/converter/ppm/pjtoppm.c @@ -11,7 +11,6 @@ */ #include "ppm.h" -#include "pm.h" #include "mallocvar.h" static char usage[] = "[paintjetfile]"; @@ -128,22 +127,20 @@ main(argc, argv) case 'V': /* send plane */ case 'W': /* send last plane */ if (rows == -1 || r >= rows || image == NULL) { - if (rows == -1 || r >= rows) { - overflow_add(rows, 100); + if (rows == -1 || r >= rows) rows += 100; - } - if (image == NULL) { - image = (unsigned char **) - malloc3(rows , planes , sizeof(unsigned char *)); - imlen = (int *) malloc3(rows , planes, sizeof(int)); + MALLOCARRAY(image, rows * planes); + MALLOCARRAY(imlen, rows * planes); } else { - overflow2(rows,planes); - image = (unsigned char **) - realloc2(image, rows * planes, - sizeof(unsigned char *)); - imlen = (int *) realloc2(imlen, rows * planes, sizeof(int)); } + image = (unsigned char **) + realloc(image, + rows * planes * + sizeof(unsigned char *)); + imlen = (int *) + realloc(imlen, rows * planes * sizeof(int)); + } } if (image == NULL || imlen == NULL) pm_error("out of memory"); @@ -215,10 +212,8 @@ main(argc, argv) for (i = 0, c = 0; c < imlen[p + r * planes]; c += 2) for (cmd = image[p + r * planes][c], val = image[p + r * planes][c+1]; - cmd >= 0 && i < newcols; cmd--, i++) { + cmd >= 0 && i < newcols; cmd--, i++) buf[i] = val; - overflow_add(i, 1); - } cols = cols > i ? cols : i; free(image[p + r * planes]); /* @@ -229,7 +224,6 @@ main(argc, argv) image[p + r * planes] = (unsigned char *) realloc(buf, i); } } - overflow2(cols, 8); cols *= 8; } diff --git a/converter/ppm/ppmtoeyuv.c b/converter/ppm/ppmtoeyuv.c index 6f072be..f5ce115 100644 --- a/converter/ppm/ppmtoeyuv.c +++ b/converter/ppm/ppmtoeyuv.c @@ -114,7 +114,6 @@ create_multiplication_tables(const pixval maxval) { int index; - overflow_add(maxval, 1); MALLOCARRAY_NOFAIL(mult299 , maxval+1); MALLOCARRAY_NOFAIL(mult587 , maxval+1); MALLOCARRAY_NOFAIL(mult114 , maxval+1); diff --git a/converter/ppm/ppmtolj.c b/converter/ppm/ppmtolj.c index b4e7db1..7ed814e 100644 --- a/converter/ppm/ppmtolj.c +++ b/converter/ppm/ppmtolj.c @@ -182,7 +182,6 @@ int main(int argc, char *argv[]) { ppm_readppminit( ifp, &cols, &rows, &maxval, &format ); pixelrow = ppm_allocrow( cols ); - overflow2(cols, 6); obuf = (unsigned char *) pm_allocrow(cols * 3, sizeof(unsigned char)); cbuf = (unsigned char *) pm_allocrow(cols * 6, sizeof(unsigned char)); if (mode == C_TRANS_MODE_DELTA) diff --git a/converter/ppm/ppmtomitsu.c b/converter/ppm/ppmtomitsu.c index 4be1c1c..e59f09b 100644 --- a/converter/ppm/ppmtomitsu.c +++ b/converter/ppm/ppmtomitsu.c @@ -651,10 +651,9 @@ main(int argc, char * argv[]) { dpi300 = TRUE; else if (pm_keymatch(argv[argn], "-tiny", 2)) tiny = TRUE; - else + else pm_usage(usage); - - ++argn; + ++argn; } if (argn < argc) { @@ -686,8 +685,6 @@ main(int argc, char * argv[]) { medias = MSize_User; if (dpi300) { - overflow2(medias.maxcols, 2); - overflow2(medias.maxrows, 2); medias.maxcols *= 2; medias.maxrows *= 2; } diff --git a/converter/ppm/ppmtopcx.c b/converter/ppm/ppmtopcx.c index 97dfb2b..fa68edc 100644 --- a/converter/ppm/ppmtopcx.c +++ b/converter/ppm/ppmtopcx.c @@ -425,8 +425,6 @@ ppmTo16ColorPcx(pixel ** const pixels, else Planes = 1; } } - overflow2(BitsPerPixel, cols); - overflow_add(BitsPerPixel * cols, 7); BytesPerLine = ((cols * BitsPerPixel) + 7) / 8; MALLOCARRAY_NOFAIL(indexRow, cols); MALLOCARRAY_NOFAIL(planesrow, BytesPerLine); diff --git a/converter/ppm/ppmtopict.c b/converter/ppm/ppmtopict.c index c91ccf2..36464b6 100644 --- a/converter/ppm/ppmtopict.c +++ b/converter/ppm/ppmtopict.c @@ -450,8 +450,6 @@ main(int argc, const char ** argv) { putShort(stdout, 0); /* mode */ /* Finally, write out the data. */ - overflow_add(cols/MAX_COUNT, 1); - overflow_add(cols, cols/MAX_COUNT+1); outBuf = malloc((unsigned)(cols+cols/MAX_COUNT+1)); for (row = 0, oc = 0; row < rows; ++row) { unsigned int rowSize; diff --git a/converter/ppm/ppmtopj.c b/converter/ppm/ppmtopj.c index fc84cac..d116773 100644 --- a/converter/ppm/ppmtopj.c +++ b/converter/ppm/ppmtopj.c @@ -179,7 +179,6 @@ char *argv[]; pixels = ppm_readppm( ifp, &cols, &rows, &maxval ); pm_close( ifp ); - overflow2(cols,2); obuf = (unsigned char *) pm_allocrow(cols, sizeof(unsigned char)); cbuf = (unsigned char *) pm_allocrow(cols * 2, sizeof(unsigned char)); diff --git a/converter/ppm/ppmtopjxl.c b/converter/ppm/ppmtopjxl.c index 72d0027..90bcef0 100644 --- a/converter/ppm/ppmtopjxl.c +++ b/converter/ppm/ppmtopjxl.c @@ -267,9 +267,6 @@ main(int argc, const char * argv[]) { if (maxval > PCL_MAXVAL) pm_error("color range too large; reduce with ppmcscale"); - if (cols < 0 || rows < 0) - pm_error("negative size is not possible"); - /* Figure out the colormap. */ pm_message("Computing colormap..."); chv = ppm_computecolorhist(pixels, cols, rows, MAXCOLORS, &colors); @@ -289,8 +286,6 @@ main(int argc, const char * argv[]) { case 0: /* direct mode (no palette) */ bpp = bitsperpixel(maxval); /* bits per pixel */ bpg = bpp; bpb = bpp; - overflow2(bpp, 3); - overflow_add(bpp*3, 7); bpp = (bpp*3+7)>>3; /* bytes per pixel now */ bpr = (bpp<<3)-bpg-bpb; bpp *= cols; /* bytes per row now */ @@ -300,13 +295,9 @@ main(int argc, const char * argv[]) { case 3: case 7: pclindex++; default: bpp = 8/pclindex; - overflow_add(cols, bpp); - if(bpp == 0) - pm_error("assert: no bpp"); bpp = (cols+bpp-1)/bpp; /* bytes per row */ } } - overflow2(bpp,2); inrow = (char *)malloc((unsigned)bpp); outrow = (char *)malloc((unsigned)bpp*2); runcnt = (signed char *)malloc((unsigned)bpp); diff --git a/converter/ppm/ppmtowinicon.c b/converter/ppm/ppmtowinicon.c index af2b445..c673798 100644 --- a/converter/ppm/ppmtowinicon.c +++ b/converter/ppm/ppmtowinicon.c @@ -12,7 +12,6 @@ #include #include -#include #include "pm_c_util.h" #include "winico.h" @@ -215,7 +214,6 @@ createAndBitmap (gray ** const ba, int const cols, int const rows, MALLOCARRAY_NOFAIL(rowData, rows); icBitmap->xBytes = xBytes; icBitmap->data = rowData; - overflow2(xBytes, rows); icBitmap->size = xBytes * rows; for (y=0;yxBytes = xBytes; icBitmap->data = rowData; - overflow2(xBytes, rows); icBitmap->size = xBytes * rows; for (y=0;yxBytes = xBytes; icBitmap->data = rowData; - overflow2(xBytes, rows); icBitmap->size = xBytes * rows; for (y=0;ybitcount = bpp; entry->ih = createInfoHeader(entry, xorBitmap, andBitmap); entry->colors = palette->colors; - overflow2(4, entry->color_count); - overflow_add(xorBitmap->size, andBitmap->size); - overflow_add(xorBitmap->size + andBitmap->size, 40); - overflow_add(xorBitmap->size + andBitmap->size + 40, 4 * entry->color_count); - entry->size_in_bytes = + entry->size_in_bytes = xorBitmap->size + andBitmap->size + 40 + (4 * entry->color_count); if (verbose) pm_message("entry->size_in_bytes = %d + %d + %d = %d", diff --git a/converter/ppm/ppmtoxpm.c b/converter/ppm/ppmtoxpm.c index 1b3923f..0e31692 100644 --- a/converter/ppm/ppmtoxpm.c +++ b/converter/ppm/ppmtoxpm.c @@ -198,7 +198,6 @@ genNumstr(unsigned int const input, int const digits) { unsigned int i; /* Allocate memory for printed number. Abort if error. */ - overflow_add(digits, 1); if (!(str = (char *) malloc(digits + 1))) pm_error("out of memory"); @@ -316,7 +315,6 @@ genCmap(colorhist_vector const chv, unsigned int charsPerPixel; unsigned int xpmMaxval; - if (includeTransparent) overflow_add(ncolors, 1); MALLOCARRAY(cmap, cmapSize); if (cmapP == NULL) pm_error("Out of memory allocating %u bytes for a color map.", diff --git a/converter/ppm/qrttoppm.c b/converter/ppm/qrttoppm.c index 653084c..935463e 100644 --- a/converter/ppm/qrttoppm.c +++ b/converter/ppm/qrttoppm.c @@ -46,7 +46,7 @@ main( argc, argv ) ppm_writeppminit( stdout, cols, rows, maxval, 0 ); pixelrow = ppm_allocrow( cols ); - buf = (unsigned char *) malloc2( 3 , cols ); + buf = (unsigned char *) malloc( 3 * cols ); if ( buf == (unsigned char *) 0 ) pm_error( "out of memory" ); diff --git a/converter/ppm/sldtoppm.c b/converter/ppm/sldtoppm.c index 2a482be..2dc049f 100644 --- a/converter/ppm/sldtoppm.c +++ b/converter/ppm/sldtoppm.c @@ -154,85 +154,127 @@ vscale(int * const px, +static void +upcase(const char * const sname, + char * const uname) { + + unsigned int i; + const char * ip; + + for (i = 0, ip = sname; i < 31; ++i) { + char const ch = *ip++; + + if (ch != EOS) + uname[i] = islower(ch) ? toupper(ch) : ch; + } + uname[i] = EOS; +} + + + +static void +skipBytes(FILE * const fileP, + unsigned int const count) { + + unsigned int i; + + for (i = 0; i < count; ++i) + getc(fileP); +} + + + +static void +scanDirectory(FILE * const slFileP, + long const dirPos, + bool const dirOnly, + const char * const uname, + bool * const foundP) { +/*---------------------------------------------------------------------------- + Scan the directory at the current position in *slFileP, either listing + the directory ('dirOnly' true) or searching for a slide named + 'uname' ('dirOnly' false). + + 'dirPos' is the offset in the file of the directory, i.e. the current + position of *slFileP. + + In the latter case, return as *foundP whether the slide name is there. +-----------------------------------------------------------------------------*/ + bool found; + bool eof; + long pos; + unsigned char libent[36]; + + for (found = false, eof = false, pos = dirPos; !found && !eof; ) { + size_t readCt; + readCt = fread(libent, 36, 1, slFileP); + if (readCt != 1) + eof = true; + else { + /* The directory entry is 32 bytes of NUL-terminated slide name + followed by 4 bytes of offset of the next directory entry. + */ + const char * const slideName = (const char *)(&libent[0]); + if (pm_strnlen(slideName, 32) == 32) + pm_error("Invalid input: slide name field is not " + "nul-terminated"); + else { + if (strlen(slideName) == 0) + eof = true; + else { + pos += 36; + if (dirOnly) { + pm_message(" %s", slideName); + } else if (streq(slideName, uname)) { + long const dpos = + (((((libent[35] << 8) | libent[34]) << 8) | + libent[33]) << 8) | libent[32]; + + if ((slFileP == stdin) || + (fseek(slFileP, dpos, 0) == -1)) { + + skipBytes(slFileP, dpos - pos); + } + found = true; + } + } + } + } + } + *foundP = found; +} + /* SLIDEFIND -- Find a slide in a library or, if DIRONLY is nonzero, print a directory listing of the library. If UCASEN is nonzero, the requested slide name is converted to upper case. */ static void -slidefind(const char * const sname, - bool const dironly, +slidefind(const char * const slideName, + bool const dirOnly, bool const ucasen) { - char uname[32]; - unsigned char libent[36]; - long pos; + char uname[32]; /* upper case translation of 'slideName' */ + char header[32]; /* (supposed) header read from file */ bool found; - bool eof; - if (dironly) + if (dirOnly) pm_message("Slides in library:"); else { - unsigned int i; - const char * ip; - - ip = sname; /* initial value */ - - for (i = 0; i < 31; ++i) { - char const ch = *ip++; - if (ch == EOS) - break; - - { - char const upperCh = - ucasen && islower(ch) ? toupper(ch) : ch; - - uname[i] = upperCh; - } - } - uname[i] = EOS; + upcase(slideName, uname); } /* Read slide library header and verify. */ - - if ((fread(libent, 32, 1, slfile) != 1) || - (!streq((char *)libent, "AutoCAD Slide Library 1.0\015\012\32"))) { + + if ((fread(header, 32, 1, slfile) != 1) || + (!STRSEQ(header, "AutoCAD Slide Library 1.0\r\n\32"))) { pm_error("not an AutoCAD slide library file."); } - pos = 32; - - /* Search for a slide with the requested name or list the directory */ - - for (found = false, eof = false; !found && !eof; ) { - size_t readCt; - readCt = fread(libent, 36, 1, slfile); - if (readCt != 1) - eof = true; - else if (strlen((char *)libent) == 0) - eof = true; - } - if (!eof) { - pos += 36; - if (dironly) { - pm_message(" %s", libent); - } else if (streq((char *)libent, uname)) { - long dpos; - - dpos = (((((libent[35] << 8) | libent[34]) << 8) | - libent[33]) << 8) | libent[32]; - - if ((slfile == stdin) || (fseek(slfile, dpos, 0) == -1)) { - dpos -= pos; - - while (dpos-- > 0) - getc(slfile); - } - found = true; - } - } - if (!found && !dironly) - pm_error("slide '%s' not in library.", sname); + scanDirectory(slfile, 32, dirOnly, ucasen ? uname : slideName, &found); + + if (!found && !dirOnly) + pm_error("slide '%s' not in library.", slideName); } @@ -350,7 +392,7 @@ slider(slvecfn slvec, /* Verify that slide format is compatible with this program. */ - if (streq(slfrof.slh, slhi.slh)) + if (!STRSEQ(slfrof.slh, slhi.slh)) pm_error("this is not an AutoCAD slide file."); /* Verify that the number format and file level in the header are @@ -464,8 +506,6 @@ slider(slvecfn slvec, /* Allocate image buffer and clear it to black. */ - overflow_add(ixdots, 1); - overflow_add(iydots, 1); pixels = ppm_allocarray(pixcols = ixdots + 1, pixrows = iydots + 1); PPM_ASSIGN(rgbcolor, 0, 0, 0); ppmd_filledrectangle(pixels, pixcols, pixrows, pixmaxval, 0, 0, diff --git a/converter/ppm/tgatoppm.c b/converter/ppm/tgatoppm.c index 0601402..3660e64 100644 --- a/converter/ppm/tgatoppm.c +++ b/converter/ppm/tgatoppm.c @@ -168,8 +168,8 @@ get_pixel(FILE * const ifP, pixel * dest, int Size, gray *alpha_p) { Red = getbyte( ifP ); if ( Size == 32 ) Alpha = getbyte( ifP ); - else - Alpha = 0; + else + Alpha = 0; l = 0; break; diff --git a/converter/ppm/ximtoppm.c b/converter/ppm/ximtoppm.c index 5758739..75faac6 100644 --- a/converter/ppm/ximtoppm.c +++ b/converter/ppm/ximtoppm.c @@ -118,7 +118,6 @@ ReadXimHeader(FILE * const in_fp, header->bits_channel = atoi(a_head.bits_per_channel); header->alpha_flag = atoi(a_head.alpha_channel); if (strlen(a_head.author)) { - overflow_add(strlen(a_head.author),1); if (!(header->author = calloc((unsigned int)strlen(a_head.author)+1, 1))) { pm_message("ReadXimHeader: can't calloc author string" ); @@ -128,7 +127,6 @@ ReadXimHeader(FILE * const in_fp, strncpy(header->author, a_head.author, strlen(a_head.author)); } if (strlen(a_head.date)) { - overflow_add(strlen(a_head.date),1); if (!(header->date =calloc((unsigned int)strlen(a_head.date)+1,1))){ pm_message("ReadXimHeader: can't calloc date string" ); return(0); @@ -137,7 +135,6 @@ ReadXimHeader(FILE * const in_fp, strncpy(header->date, a_head.date, strlen(a_head.date)); } if (strlen(a_head.program)) { - overflow_add(strlen(a_head.program),1); if (!(header->program = calloc( (unsigned int)strlen(a_head.program) + 1, 1))) { pm_message("ReadXimHeader: can't calloc program string" ); @@ -164,7 +161,6 @@ ReadXimHeader(FILE * const in_fp, if (header->nchannels == 3 && header->bits_channel == 8) header->ncolors = 0; else if (header->nchannels == 1 && header->bits_channel == 8) { - overflow2(header->ncolors, sizeof(Color)); header->colors = (Color *)calloc((unsigned int)header->ncolors, sizeof(Color)); if (header->colors == NULL) { diff --git a/converter/ppm/xpmtoppm.c b/converter/ppm/xpmtoppm.c index 52eaca1..9471ec7 100644 --- a/converter/ppm/xpmtoppm.c +++ b/converter/ppm/xpmtoppm.c @@ -941,8 +941,8 @@ convertRaster(FILE * const ifP, if (imageOutFileP) ppm_writeppmrow(imageOutFileP, pixrow, cols, PPM_MAXMAXVAL, 0); - if (alphaOutFileP) - pbm_writepbmrow(alphaOutFileP, alpharow, cols, 0); + if (alphaOutFileP) + pbm_writepbmrow(alphaOutFileP, alpharow, cols, 0); } pbm_freerow(alpharow); diff --git a/editor/pamcut.c b/editor/pamcut.c index 72df687..7c41af3 100644 --- a/editor/pamcut.c +++ b/editor/pamcut.c @@ -655,8 +655,6 @@ cutOneImage(FILE * const ifP, outpam = inpam; /* Initial value -- most fields should be same */ outpam.file = ofP; - overflow_add(rightcol, 1); - overflow_add(bottomrow, 1); outpam.width = rightcol - leftcol + 1; outpam.height = bottomrow - toprow + 1; diff --git a/editor/pamstretch-gen b/editor/pamstretch-gen index 7928588..dac3da7 100755 --- a/editor/pamstretch-gen +++ b/editor/pamstretch-gen @@ -34,10 +34,12 @@ if [ "$1" = "" ]; then exit 1 fi -tempfile=$(mktemp /tmp/pnmig.XXXXXXXX) || +tempdir=$(mktemp -d "${TMPDIR:-/tmp}/netpbm.XXXXXXXX") || ( echo "Could not create temporary file. Exiting." 1>&2; exit 1; ) trap 'rm -rf $tempdir' 0 1 3 15 +tempfile=$tempdir/pnmig + if ! cat $2 >$tempfile 2>/dev/null; then echo 'pamstretch-gen: error reading file' 1>&2 exit 1 diff --git a/editor/pnmconvol.c b/editor/pnmconvol.c index b1d8e02..98ec3a6 100644 --- a/editor/pnmconvol.c +++ b/editor/pnmconvol.c @@ -733,7 +733,7 @@ parsePlaneFileLine(const char * const line, "-matrix value is not a valid floating point " "number", colCt, line); - ++colCt; + ++colCt; } pm_strfree(token); } diff --git a/editor/pnmgamma.c b/editor/pnmgamma.c index ec612d3..b357b0d 100644 --- a/editor/pnmgamma.c +++ b/editor/pnmgamma.c @@ -596,7 +596,6 @@ createGammaTables(enum transferFunction const transferFunction, xelval ** const btableP) { /* Allocate space for the tables. */ - overflow_add(maxval, 1); MALLOCARRAY(*rtableP, maxval+1); MALLOCARRAY(*gtableP, maxval+1); MALLOCARRAY(*btableP, maxval+1); diff --git a/editor/pnmhisteq.c b/editor/pnmhisteq.c index 0c8d6e5..8af4201 100644 --- a/editor/pnmhisteq.c +++ b/editor/pnmhisteq.c @@ -107,7 +107,6 @@ computeLuminosityHistogram(xel * const * const xels, unsigned int pixelCount; unsigned int * lumahist; - overflow_add(maxval, 1); MALLOCARRAY(lumahist, maxval + 1); if (lumahist == NULL) pm_error("Out of storage allocating array for %u histogram elements", diff --git a/editor/pnmindex.csh b/editor/pnmindex.csh index c513a84..c6f1e84 100755 --- a/editor/pnmindex.csh +++ b/editor/pnmindex.csh @@ -1,7 +1,5 @@ #!/bin/csh -f # -echo "Unsafe code, needs debugging, do not ship" -exit 1 # pnmindex - build a visual index of a bunch of anymaps # # Copyright (C) 1991 by Jef Poskanzer. diff --git a/editor/pnmpad.c b/editor/pnmpad.c index 1aa578c..9c7a77e 100644 --- a/editor/pnmpad.c +++ b/editor/pnmpad.c @@ -634,8 +634,6 @@ main(int argc, const char ** argv) { computePadSizes(cmdline, cols, rows, &lpad, &rpad, &tpad, &bpad); - overflow_add(cols, lpad); - overflow_add(cols + lpad, rpad); newcols = cols + lpad + rpad; if (PNM_FORMAT_TYPE(format) == PBM_TYPE) diff --git a/editor/pnmremap.c b/editor/pnmremap.c index cbb8d0e..59b1e84 100644 --- a/editor/pnmremap.c +++ b/editor/pnmremap.c @@ -468,7 +468,6 @@ fserr_init(struct pam * const pamP, unsigned int const fserrSize = pamP->width + 2; - overflow_add(pamP->width, 2); fserrP->width = pamP->width; MALLOCARRAY(fserrP->thiserr, pamP->depth); @@ -506,7 +505,6 @@ floydInitRow(struct pam * const pamP, struct Fserr * const fserrP) { int col; - overflow_add(pamP->width, 2); for (col = 0; col < pamP->width + 2; ++col) { unsigned int plane; for (plane = 0; plane < pamP->depth; ++plane) diff --git a/editor/pnmscalefixed.c b/editor/pnmscalefixed.c index 747cd8f..884ca31 100644 --- a/editor/pnmscalefixed.c +++ b/editor/pnmscalefixed.c @@ -214,7 +214,6 @@ compute_output_dimensions(const struct cmdline_info cmdline, const int rows, const int cols, int * newrowsP, int * newcolsP) { - overflow2(rows, cols); if (cmdline.pixels) { if (rows * cols <= cmdline.pixels) { *newrowsP = rows; @@ -266,8 +265,6 @@ compute_output_dimensions(const struct cmdline_info cmdline, if (*newcolsP < 1) *newcolsP = 1; if (*newrowsP < 1) *newrowsP = 1; - - overflow2(*newcolsP, *newrowsP); } @@ -449,9 +446,6 @@ main(int argc, char **argv ) { unfilled. We can address that by stretching, whereas the other case would require throwing away some of the input. */ - - overflow2(newcols, SCALE); - overflow2(newrows, SCALE); sxscale = SCALE * newcols / cols; syscale = SCALE * newrows / rows; diff --git a/editor/ppmdither.c b/editor/ppmdither.c index e701e09..ec1b977 100644 --- a/editor/ppmdither.c +++ b/editor/ppmdither.c @@ -356,11 +356,6 @@ dithMatrix(unsigned int const dithPower) { (dithDim * sizeof(*dithMat)) + /* pointers */ (dithDim * dithDim * sizeof(**dithMat)); /* data */ - - overflow2(dithDim, sizeof(*dithMat)); - overflow3(dithDim, dithDim, sizeof(**dithMat)); - overflow_add(dithDim * sizeof(*dithMat), dithDim * dithDim * sizeof(**dithMat)); - dithMat = malloc(dithMatSize); if (dithMat == NULL) diff --git a/editor/ppmfade b/editor/ppmfade index 27589a9..dcd7bf2 100755 --- a/editor/ppmfade +++ b/editor/ppmfade @@ -40,7 +40,6 @@ exec perl -w -x -S -- "$0" "$@" # ############################################################################## use strict; -use File::Temp "tempdir"; sub doVersionHack($) { my ($argvR) = @_; @@ -84,7 +83,7 @@ for ($n = 0; $n < @ARGV; $n++) { if (-e $first_file) { } else { print "I can't find first file '$first_file'\n"; - exit 1; + exit 20; } } elsif ($ARGV[$n] eq "-l") { $n++; @@ -92,7 +91,7 @@ for ($n = 0; $n < @ARGV; $n++) { if (-e $last_file) { } else { print "I can't find last file '$last_file'\n"; - exit 1; + exit 20; } } elsif ($ARGV[$n] eq "-base") { $n++; @@ -113,12 +112,9 @@ for ($n = 0; $n < @ARGV; $n++) { $mode = $BLOCK; } elsif ("$ARGV[$n]" eq "-mix") { $mode = $MIX; - } elsif ($ARGV[$n] eq "-help" || $ARGV[$n] eq "--help" || $ARGV[$n] eq "-h") { - print "ppmfade: Use 'man ppmfade' for help.\n"; - exit 1; } else { print "Unknown argument: $ARGV[$n]\n"; - exit 1; + exit 100; } } # @@ -137,42 +133,36 @@ if ($first_file ne "undefined") { $width = $1; $height = $2; } else { print("Unrecognized results from pnmfile on $first_file.\n"); - exit 1; + exit(50); } } elsif ($last_file ne "undefined") { if ((`pnmfile $last_file` =~ m{\b(\d+)\sby\s(\d+)} )) { $width = $1; $height = $2; } else { print("Unrecognized results from pnmfile on $first_file.\n"); - exit 1; + exit(50); } } else { print("ppmfade: You must specify -f or -l (or both)\n"); - exit 1; + exit(90); } print("Frames are " . $width . "W x " . $height . "H\n"); -# -# We create a tmp-directory right here -# -my $tmpdir = tempdir("ppmfade.XXXXXX", CLEANUP => 1); - - if ($first_file eq "undefined") { print "Fading from black to "; - system("ppmmake \\#000 $width $height >$tmpdir/junk1$$.ppm"); + system("ppmmake \\#000 $width $height >junk1$$.ppm"); } else { print "Fading from $first_file to "; - system("cp", $first_file, "$tmpdir/junk1$$.ppm"); + system("cp", $first_file, "junk1$$.ppm"); } if ($last_file eq "undefined") { print "black.\n"; - system("ppmmake \\#000 $width $height >$tmpdir/junk2$$.ppm"); + system("ppmmake \\#000 $width $height >junk2$$.ppm"); } else { print "$last_file\n"; - system("cp", $last_file, "$tmpdir/junk2$$.ppm"); + system("cp", $last_file, "junk2$$.ppm"); } # @@ -180,14 +170,14 @@ if ($last_file eq "undefined") { # # Here's what our temporary files are: -# $tmpdir/junk1$$.ppm: The original (fade-from) image -# $tmpdir/junk2$$.ppm: The target (fade-from) image -# $tmpdir/junk3$$.ppm: The frame of the fade for the current iteration of the -# the for loop. -# $tmpdir/junk1a$$.ppm: If the fade involves a ppmmix sequence from one intermediate -# image to another, this is the first frame of that -# sequence. -# $tmpdir/junk2a$$.ppm: This is the last frame of the above-mentioned ppmmix sequence +# junk1$$.ppm: The original (fade-from) image +# junk2$$.ppm: The target (fade-from) image +# junk3$$.ppm: The frame of the fade for the current iteration of the +# the for loop. +# junk1a$$.ppm: If the fade involves a ppmmix sequence from one intermediate +# image to another, this is the first frame of that +# sequence. +# junk2a$$.ppm: This is the last frame of the above-mentioned ppmmix sequence my $i; # Frame number for ($i = 1; $i <= $nframes; $i++) { @@ -195,147 +185,147 @@ for ($i = 1; $i <= $nframes; $i++) { if ($mode eq $SPREAD) { if ($i <= 10) { my $n = $spline20[$i] * 100; - system("ppmspread $n $tmpdir/junk1$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmspread $n junk1$$.ppm >junk3$$.ppm"); } elsif ($i <= 20) { my $n; $n = $spline20[$i] * 100; - system("ppmspread $n $tmpdir/junk1$$.ppm >$tmpdir/junk1a$$.ppm"); + system("ppmspread $n junk1$$.ppm >junk1a$$.ppm"); $n = (1-$spline20[$i-10]) * 100; - system("ppmspread $n $tmpdir/junk2$$.ppm >$tmpdir/junk2a$$.ppm"); + system("ppmspread $n junk2$$.ppm >junk2a$$.ppm"); $n = $spline10[$i-10]; - system("ppmmix $n $tmpdir/junk1a$$.ppm $tmpdir/junk2a$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm"); } else { my $n = (1-$spline20[$i-10])*100; - system("ppmspread $n $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmspread $n junk2$$.ppm >junk3$$.ppm"); } } elsif ($mode eq $SHIFT) { if ($i <= 10) { my $n = $spline20[$i] * 100; - system("ppmshift $n $tmpdir/junk1$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmshift $n junk1$$.ppm >junk3$$.ppm"); } elsif ($i <= 20) { my $n; $n = $spline20[$i] * 100; - system("ppmshift $n $tmpdir/junk1$$.ppm >$tmpdir/junk1a$$.ppm"); + system("ppmshift $n junk1$$.ppm >junk1a$$.ppm"); $n = (1-$spline20[$i-10])*100; - system("ppmshift $n $tmpdir/junk2$$.ppm >$tmpdir/junk2a$$.ppm"); + system("ppmshift $n junk2$$.ppm >junk2a$$.ppm"); $n = $spline10[$i-10]; - system("ppmmix $n $tmpdir/junk1a$$.ppm $tmpdir/junk2a$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm"); } else { my $n = (1-$spline20[$i-10]) * 100; - system("ppmshift $n $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmshift $n junk2$$.ppm >junk3$$.ppm"); } } elsif ($mode eq $RELIEF) { if ($i == 1) { - system("ppmrelief $tmpdir/junk1$$.ppm >$tmpdir/junk1r$$.ppm"); + system("ppmrelief junk1$$.ppm >junk1r$$.ppm"); } if ($i <= 10) { my $n = $spline10[$i]; - system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1r$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk1$$.ppm junk1r$$.ppm >junk3$$.ppm"); } elsif ($i <= 20) { my $n = $spline10[$i-10]; - system("ppmmix $n $tmpdir/junk1r$$.ppm $tmpdir/junk2r$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk1r$$.ppm junk2r$$.ppm >junk3$$.ppm"); } else { my $n = $spline10[$i-20]; - system("ppmmix $n $tmpdir/junk2r$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk2r$$.ppm junk2$$.ppm >junk3$$.ppm"); } if ($i == 10) { - system("ppmrelief $tmpdir/junk2$$.ppm >$tmpdir/junk2r$$.ppm"); + system("ppmrelief junk2$$.ppm >junk2r$$.ppm"); } } elsif ($mode eq $OIL) { if ($i == 1) { - system("ppmtopgm $tmpdir/junk1$$.ppm | pgmoil >$tmpdir/junko$$.ppm"); - system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " . - ">$tmpdir/junk1o$$.ppm"); + system("ppmtopgm junk1$$.ppm | pgmoil >junko$$.ppm"); + system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " . + ">junk1o$$.ppm"); } if ($i <= 10) { my $n = $spline10[$i]; - system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1o$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm"); } elsif ($i <= 20) { my $n = $spline10[$i-10]; - system("ppmmix $n $tmpdir/junk1o$$.ppm $tmpdir/junk2o$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm"); } else { my $n = $spline10[$i-20]; - system("ppmmix $n $tmpdir/junk2o$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm"); } if ($i == 10) { - system("ppmtopgm $tmpdir/junk2$$.ppm | pgmoil >$tmpdir/junko$$.ppm"); - system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " . - ">$tmpdir/junk2o$$.ppm"); + system("ppmtopgm junk2$$.ppm | pgmoil >junko$$.ppm"); + system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " . + ">junk2o$$.ppm"); } } elsif ($mode eq $EDGE) { if ($i == 1) { - system("ppmtopgm $tmpdir/junk1$$.ppm | pgmedge >$tmpdir/junko$$.ppm"); - system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " . - ">$tmpdir/junk1o$$.ppm"); + system("ppmtopgm junk1$$.ppm | pgmedge >junko$$.ppm"); + system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " . + ">junk1o$$.ppm"); } if ($i <= 10) { my $n = $spline10[$i]; - system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1o$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm"); } elsif ($i <= 20) { my $n = $spline10[$i-10]; - system("ppmmix $n $tmpdir/junk1o$$.ppm $tmpdir/junk2o$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm"); } else { my $n = $spline10[$i-20]; - system("ppmmix $n $tmpdir/junk2o$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm"); } if ($i == 10) { - system("ppmtopgm $tmpdir/junk2$$.ppm | pgmedge >$tmpdir/junko$$.ppm"); - system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " . - ">$tmpdir/junk2o$$.ppm"); + system("ppmtopgm junk2$$.ppm | pgmedge >junko$$.ppm"); + system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " . + ">junk2o$$.ppm"); } } elsif ($mode eq $BENTLEY) { if ($i == 1) { - system("ppmtopgm $tmpdir/junk1$$.ppm | pgmbentley >$tmpdir/junko$$.ppm"); - system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " . - ">$tmpdir/junk1o$$.ppm"); + system("ppmtopgm junk1$$.ppm | pgmbentley >junko$$.ppm"); + system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " . + ">junk1o$$.ppm"); } if ($i <= 10) { my $n = $spline10[$i]; - system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1o$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm"); } elsif ($i <= 20) { my $n = $spline10[$i-10]; - system("ppmmix $n $tmpdir/junk1o$$.ppm $tmpdir/junk2o$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm"); } else { my $n = $spline10[$i-20]; - system("ppmmix $n $tmpdir/junk2o$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm"); } if ($i == 10) { - system("ppmtopgm $tmpdir/junk2$$.ppm | pgmbentley >$tmpdir/junko$$.ppm"); - system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " . - ">$tmpdir/junk2o$$.ppm"); + system("ppmtopgm junk2$$.ppm | pgmbentley >junko$$.ppm"); + system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " . + ">junk2o$$.ppm"); } } elsif ($mode eq $BLOCK) { if ($i <= 10) { my $n = 1 - 1.9*$spline20[$i]; - system("pamscale $n $tmpdir/junk1$$.ppm | " . - "pamscale -width $width -height $height >$tmpdir/junk3$$.ppm"); + system("pamscale $n junk1$$.ppm | " . + "pamscale -width $width -height $height >junk3$$.ppm"); } elsif ($i <= 20) { my $n = $spline10[$i-10]; - system("ppmmix $n $tmpdir/junk1a$$.ppm $tmpdir/junk2a$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm"); } else { my $n = 1 - 1.9*$spline20[31-$i]; - system("pamscale $n $tmpdir/junk2$$.ppm | " . - "pamscale -width $width -height $height >$tmpdir/junk3$$.ppm"); + system("pamscale $n junk2$$.ppm | " . + "pamscale -width $width -height $height >junk3$$.ppm"); } if ($i == 10) { - system("cp", "$tmpdir/junk3$$.ppm", "$tmpdir/junk1a$$.ppm"); - system("pamscale $n $tmpdir/junk2$$.ppm | " . - "pamscale -width $width -height $height >$tmpdir/junk2a$$.ppm"); + system("cp", "junk3$$.ppm", "junk1a$$.ppm"); + system("pamscale $n junk2$$.ppm | " . + "pamscale -width $width -height $height >junk2a$$.ppm"); } } elsif ($mode eq $MIX) { my $fade_factor = sqrt(1/($nframes-$i+1)); - system("ppmmix $fade_factor $tmpdir/junk1$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm"); + system("ppmmix $fade_factor junk1$$.ppm junk2$$.ppm >junk3$$.ppm"); } else { print("Internal error: impossible mode value '$mode'\n"); } my $outfile = sprintf("%s.%04d.ppm", $base_name, $i); - system("cp", "$tmpdir/junk3$$.ppm", $outfile); + system("cp", "junk3$$.ppm", $outfile); } # # Clean up shop. # -system("rm $tmpdir/junk*$$.ppm"); +system("rm junk*$$.ppm"); exit(0); diff --git a/editor/ppmshadow b/editor/ppmshadow index 7615282..ae6b1b0 100755 --- a/editor/ppmshadow +++ b/editor/ppmshadow @@ -194,12 +194,11 @@ my $tmpdir = $ENV{TMPDIR} || "/tmp"; my $ourtmp; if ($keeptemp) { - $ourtmp = chomp($ourtmp = `mktemp -d -t PPMshadow.XXXXXX`); - if($? >> 8) { - die "Can't create directory for temporary files"; - } + $ourtmp = "$tmpdir/ppmshadow$$"; + mkdir($ourtmp, 0777) or + die("Unable to create directory for temporary files '$ourtmp"); } else { - $ourtmp = File::Temp::tempdir("$tmpdir/PPMshadow.XXXXXX", UNLINK=>1); + $ourtmp = File::Temp::tempdir("$tmpdir/ppmshadowXXXX", UNLINK=>1); } # Apply defaults for arguments not specified diff --git a/editor/specialty/pamoil.c b/editor/specialty/pamoil.c index 6f4bde9..6cb8d3a 100644 --- a/editor/specialty/pamoil.c +++ b/editor/specialty/pamoil.c @@ -112,7 +112,6 @@ main(int argc, char *argv[] ) { tuples = pnm_readpam(ifp, &inpam, PAM_STRUCT_SIZE(tuple_type)); pm_close(ifp); - overflow_add(inpam.maxval, 1); MALLOCARRAY(hist, inpam.maxval + 1); if (hist == NULL) pm_error("Unable to allocate memory for histogram."); diff --git a/generator/pbmtext.c b/generator/pbmtext.c index b2579d1..0fe8ad6 100644 --- a/generator/pbmtext.c +++ b/generator/pbmtext.c @@ -404,7 +404,7 @@ fixControlChars(const PM_WCHAR * const input, output[outCursor++] = L' '; } else if (currentChar > fontP->maxglyph || !fontP->glyph[currentChar]) { - if (currentChar > PM_FONT2_MAXGLYPH){ + if (currentChar > PM_FONT2_MAXGLYPH) pm_message("code point %X is beyond what this program " "can handle. Max=%X", (unsigned int)currentChar, PM_FONT2_MAXGLYPH); @@ -420,15 +420,15 @@ fixControlChars(const PM_WCHAR * const input, (unsigned int) currentChar ); output[outCursor++] = ' '; } - } } else output[outCursor++] = input[inCursor]; - + assert(outCursor <= outputSize); } output[outCursor++] = L'\0'; assert(outCursor <= outputSize); + *outputP = output; } diff --git a/lib/libpam.c b/lib/libpam.c index e6986f1..a8f140b 100644 --- a/lib/libpam.c +++ b/lib/libpam.c @@ -225,8 +225,7 @@ allocPamRow(const struct pam * const pamP) { unsigned int const bytesPerTuple = allocationDepth(pamP) * sizeof(sample); tuple * tuplerow; - overflow_add(sizeof(tuple *), bytesPerTuple); - tuplerow = malloc2(pamP->width, (sizeof(tuple *) + bytesPerTuple)); + tuplerow = malloc(pamP->width * (sizeof(tuple *) + bytesPerTuple)); if (tuplerow != NULL) { /* Now we initialize the pointers to the individual tuples diff --git a/lib/libpammap.c b/lib/libpammap.c index ba27a4c..2222491 100644 --- a/lib/libpammap.c +++ b/lib/libpammap.c @@ -108,9 +108,7 @@ allocTupleIntListItem(struct pam * const pamP) { */ struct tupleint_list_item * retval; - overflow2(pamP->depth, sizeof(sample)); - overflow_add(sizeof(*retval)-sizeof(retval->tupleint.tuple), pamP->depth*sizeof(sample)); - unsigned int const size = + unsigned int const size = sizeof(*retval) - sizeof(retval->tupleint.tuple) + pamP->depth * sizeof(sample); diff --git a/lib/libpm.c b/lib/libpm.c index 14d5e38..f9aa1ae 100644 --- a/lib/libpm.c +++ b/lib/libpm.c @@ -437,10 +437,9 @@ pm_maxvaltobits(int const maxval) { return 15; else if ( (long) maxval <= 65535L ) return 16; - else { + else pm_error( "maxval of %d is too large!", maxval ); return -1; /* Should never come here */ - } } int @@ -889,53 +888,5 @@ pm_parse_height(const char * const arg) { return height; } -/* - * Maths wrapping - */ - -void __overflow2(int a, int b) -{ - if(a < 0 || b < 0) - pm_error("object too large"); - if(b == 0) - return; - if(a > INT_MAX / b) - pm_error("object too large"); -} -void overflow3(int a, int b, int c) -{ - overflow2(a,b); - overflow2(a*b, c); -} - -void overflow_add(int a, int b) -{ - if( a > INT_MAX - b) - pm_error("object too large"); -} - -void *malloc2(int a, int b) -{ - overflow2(a, b); - if(a*b == 0) - pm_error("Zero byte allocation"); - return malloc(a*b); -} - -void *malloc3(int a, int b, int c) -{ - overflow3(a, b, c); - if(a*b*c == 0) - pm_error("Zero byte allocation"); - return malloc(a*b*c); -} - -void *realloc2(void * a, int b, int c) -{ - overflow2(b, c); - if(b*c == 0) - pm_error("Zero byte allocation"); - return realloc(a, b*c); -} diff --git a/lib/pm.h b/lib/pm.h index da54391..47cbfe8 100644 --- a/lib/pm.h +++ b/lib/pm.h @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -435,12 +434,5 @@ pm_parse_height(const char * const arg); } #endif -void *malloc2(int, int); -void *malloc3(int, int, int); -#define overflow2(a,b) __overflow2(a,b) -void __overflow2(int, int); -void overflow3(int, int, int); -void overflow_add(int, int); - #endif diff --git a/other/pamfix.c b/other/pamfix.c index 4225ba1..8db67e0 100644 --- a/other/pamfix.c +++ b/other/pamfix.c @@ -184,7 +184,7 @@ clipPamRow(const struct pam * const pamP, "image maxval of %lu", row, col, plane, tuplerow[col][plane], pamP->maxval); - tuplerow[col][plane] = pamP->maxval; + tuplerow[col][plane] = pamP->maxval; } } } diff --git a/other/pnmcolormap.c b/other/pnmcolormap.c index d1cbca7..57db432 100644 --- a/other/pnmcolormap.c +++ b/other/pnmcolormap.c @@ -838,10 +838,8 @@ colormapToSquare(struct pam * const pamP, unsigned int const intsqrt = (int)sqrt((float)colormap.size); if (intsqrt * intsqrt == colormap.size) pamP->width = intsqrt; - else { + else pamP->width = intsqrt + 1; - overflow_add(intsqrt, 1); - } } { unsigned int const intQuotient = colormap.size / pamP->width; diff --git a/test/Makefile b/test/Makefile index 7ad3a46..4f0c063 100644 --- a/test/Makefile +++ b/test/Makefile @@ -18,7 +18,7 @@ testrandom.o: testrandom.c $(CC_FOR_BUILD) -c -o $@ $(CFLAGS_FOR_BUILD) $< testrandom: testrandom.o - $(LD_FOR_BUILD) -o $@ $(LDFLAGSPRE) $< + $(LD_FOR_BUILD) -o $@ $(LDFLAGS_FOR_BUILD) $< RAND_VARIETY ?= $(shell ./testrandom -x) diff --git a/urt/Runput.c b/urt/Runput.c index 645a376..3bc562a 100644 --- a/urt/Runput.c +++ b/urt/Runput.c @@ -202,11 +202,10 @@ RunSetup(rle_hdr * the_hdr) if ( the_hdr->background != 0 ) { register int i; - register rle_pixel *background; - register int *bg_color; - - overflow_add(the_hdr->ncolors,1); - background = (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) ); /* + register rle_pixel *background = + (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) ); + register int *bg_color; + /* * If even number of bg color bytes, put out one more to get to * 16 bit boundary. */ @@ -225,7 +224,7 @@ RunSetup(rle_hdr * the_hdr) /* Big-endian machines are harder */ register int i, nmap = (1 << the_hdr->cmaplen) * the_hdr->ncmap; - register char *h_cmap = (char *)malloc2( nmap, 2 ); + register char *h_cmap = (char *)malloc( nmap * 2 ); if ( h_cmap == NULL ) { fprintf( stderr, diff --git a/urt/rle.h b/urt/rle.h index ac65b94..0766d22 100644 --- a/urt/rle.h +++ b/urt/rle.h @@ -31,7 +31,6 @@ #define RLE_H #include /* Declare FILE. */ -#include enum rle_dispatch { NO_DISPATCH = -1, @@ -161,17 +160,6 @@ rle_hdr /* End of typedef. */ */ extern rle_hdr rle_dflt_hdr; -/* - * Provided by pm library - */ - -extern void overflow_add(int, int); -#define overflow2(a,b) __overflow2(a,b) -extern void __overflow2(int, int); -extern void overflow3(int, int, int); -extern void *malloc2(int, int); -extern void *malloc3(int, int, int); -extern void *realloc2(void *, int, int); /* Declare RLE library routines. */ diff --git a/urt/rle_addhist.c b/urt/rle_addhist.c index e09ed94..b165175 100644 --- a/urt/rle_addhist.c +++ b/urt/rle_addhist.c @@ -70,18 +70,13 @@ rle_addhist(char * argv[], return; length = 0; - for (i = 0; argv[i]; ++i) { - overflow_add(length, strlen(argv[i])); - overflow_add(length+1, strlen(argv[i])); + for (i = 0; argv[i]; ++i) length += strlen(argv[i]) +1; /* length of each arg plus space. */ - } time(&temp); timedate = ctime(&temp); length += strlen(timedate); /* length of date and time in ASCII. */ - overflow_add(strlen(padding), 4); - overflow_add(strlen(histoire), strlen(padding) + 4); - overflow_add(length, strlen(histoire) + strlen(padding) + 4); + length += strlen(padding) + 3 + strlen(histoire) + 1; /* length of padding, "on " and length of history name plus "="*/ if (in_hdr) /* if we are interested in the old comments... */ @@ -89,10 +84,8 @@ rle_addhist(char * argv[], else old = NULL; - if (old && *old) { - overflow_add(length, strlen(old)); + if (old && *old) length += strlen(old); /* add length if there. */ - } ++length; /*Cater for the null. */ diff --git a/urt/rle_getrow.c b/urt/rle_getrow.c index cc1f5cb..679811c 100644 --- a/urt/rle_getrow.c +++ b/urt/rle_getrow.c @@ -160,7 +160,6 @@ rle_get_setup(rle_hdr * const the_hdr) { char * cp; VAXSHORT(comlen, infile); /* get comment length */ - overflow_add(comlen, 1); evenlen = (comlen + 1) & ~1; /* make it even */ if (evenlen) { MALLOCARRAY(comment_buf, evenlen); diff --git a/urt/rle_hdr.c b/urt/rle_hdr.c index 7c9c010..1611324 100644 --- a/urt/rle_hdr.c +++ b/urt/rle_hdr.c @@ -80,10 +80,7 @@ int img_num; /* Fill in with copies of the strings. */ if ( the_hdr->cmd != pgmname ) { - char *tmp; - - overflow_add(strlen(pgmname), 1); - tmp = malloc( strlen(pgmname) + 1 ); + char *tmp = (char *)malloc( strlen( pgmname ) + 1 ); RLE_CHECK_ALLOC( pgmname, tmp, 0 ); strcpy( tmp, pgmname ); the_hdr->cmd = tmp; @@ -91,10 +88,8 @@ int img_num; if ( the_hdr->file_name != fname ) { - char *tmp; - overflow_add(strlen(fname), 1); - tmp = malloc( strlen( fname ) + 1 ); - RLE_CHECK_ALLOC( pgmname, tmp, 0 ); + char *tmp = (char *)malloc( strlen( fname ) + 1 ); + RLE_CHECK_ALLOC( pgmname, tmp, 0 ); strcpy( tmp, fname ); the_hdr->file_name = tmp; } @@ -158,7 +153,6 @@ rle_hdr *from_hdr, *to_hdr; if ( to_hdr->bg_color ) { int size = to_hdr->ncolors * sizeof(int); - overflow2(to_hdr->ncolors, sizeof(int)); to_hdr->bg_color = (int *)malloc( size ); RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->bg_color, "background color" ); memcpy( to_hdr->bg_color, from_hdr->bg_color, size ); @@ -167,7 +161,7 @@ rle_hdr *from_hdr, *to_hdr; if ( to_hdr->cmap ) { int size = to_hdr->ncmap * (1 << to_hdr->cmaplen) * sizeof(rle_map); - to_hdr->cmap = (rle_map *)malloc3( to_hdr->ncmap, 1<cmaplen, sizeof(rle_map)); + to_hdr->cmap = (rle_map *)malloc( size ); RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->cmap, "color map" ); memcpy( to_hdr->cmap, from_hdr->cmap, size ); } @@ -179,17 +173,12 @@ rle_hdr *from_hdr, *to_hdr; { int size = 0; CONST_DECL char **cp; - for ( cp=to_hdr->comments; *cp; cp++ ) - { - overflow_add(size, 1); + for ( cp=to_hdr->comments; *cp; cp++ ) size++; /* Count the comments. */ - } /* Check if there are really any comments. */ if ( size ) { - overflow_add(size, 1); size++; /* Copy the NULL pointer, too. */ - overflow2(size, sizeof(char *)); size *= sizeof(char *); to_hdr->comments = (CONST_DECL char **)malloc( size ); RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->comments, "comments" ); diff --git a/urt/rle_open_f.c b/urt/rle_open_f.c index c2ef37d..ae8548b 100644 --- a/urt/rle_open_f.c +++ b/urt/rle_open_f.c @@ -163,7 +163,65 @@ dealWithSubprocess(const char * const file_name, FILE ** const fpP, bool * const noSubprocessP, const char ** const errorP) { + +#ifdef NO_OPEN_PIPES *noSubprocessP = TRUE; +#else + const char *cp; + + reapChildren(catchingChildrenP, pids); + + /* Real file, not stdin or stdout. If name ends in ".Z", + * pipe from/to un/compress (depending on r/w mode). + * + * If it starts with "|", popen that command. + */ + + cp = file_name + strlen(file_name) - 2; + /* Pipe case. */ + if (file_name[0] == '|') { + pid_t thepid; /* PID from my_popen */ + + *noSubprocessP = FALSE; + + *fpP = my_popen(file_name + 1, mode, &thepid); + if (*fpP == NULL) + *errorP = "%s: can't invoke <<%s>> for %s: "; + else { + /* One more child to catch, eventually. */ + if (*catchingChildrenP < MAX_CHILDREN) + pids[(*catchingChildrenP)++] = thepid; + } + } else if (cp > file_name && *cp == '.' && *(cp + 1) == 'Z' ) { + /* Compress case. */ + pid_t thepid; /* PID from my_popen. */ + const char * command; + + *noSubprocessP = FALSE; + + if (*mode == 'w') + pm_asprintf(&command, "compress > %s", file_name); + else if (*mode == 'a') + pm_asprintf(&command, "compress >> %s", file_name); + else + pm_asprintf(&command, "compress -d < %s", file_name); + + *fpP = my_popen(command, mode, &thepid); + + if (*fpP == NULL) + *errorP = "%s: can't invoke 'compress' program, " + "trying to open %s for %s"; + else { + /* One more child to catch, eventually. */ + if (*catchingChildrenP < MAX_CHILDREN) + pids[(*catchingChildrenP)++] = thepid; + } + pm_strfree(command); + } else { + *noSubprocessP = TRUE; + *errorP = NULL; + } +#endif } diff --git a/urt/rle_putcom.c b/urt/rle_putcom.c index ce83615..ab2eb20 100644 --- a/urt/rle_putcom.c +++ b/urt/rle_putcom.c @@ -98,14 +98,12 @@ rle_putcom(const char * const value, const char * v; const char ** old_comments; int i; - for (i = 2, cp = the_hdr->comments; *cp != NULL; ++i, ++cp) { - overflow_add(i, 1); + for (i = 2, cp = the_hdr->comments; *cp != NULL; ++i, ++cp) if (match(value, *cp) != NULL) { v = *cp; *cp = value; return v; } - } /* Not found */ /* Can't realloc because somebody else might be pointing to this * comments block. Of course, if this were true, then the diff --git a/urt/scanargs.c b/urt/scanargs.c index 5e114bb..f3af334 100644 --- a/urt/scanargs.c +++ b/urt/scanargs.c @@ -62,8 +62,9 @@ typedef int *ptr; /* * Storage allocation macros */ -#define NEW( type, cnt ) (type *) malloc2( (cnt) , sizeof( type ) ) -#define RENEW( type, ptr, cnt ) (type *) realloc2( ptr, (cnt), sizeof( type ) ) +#define NEW( type, cnt ) (type *) malloc( (cnt) * sizeof( type ) ) +#define RENEW( type, ptr, cnt ) (type *) realloc( ptr, (cnt) * sizeof( type ) ) + static CONST_DECL char * prformat( CONST_DECL char *, int ); static int isnum( CONST_DECL char *, int, int ); static int _do_scanargs( int argc, char **argv, CONST_DECL char *format, diff --git a/userguide/avstopam.html b/userguide/avstopam.html index f69fdaa..9ec5e41 100644 --- a/userguide/avstopam.html +++ b/userguide/avstopam.html @@ -1,7 +1,8 @@ - + Avstopam User Manual + diff --git a/userguide/cameratopam.html b/userguide/cameratopam.html index f26338f..4a34817 100644 --- a/userguide/cameratopam.html +++ b/userguide/cameratopam.html @@ -25,10 +25,10 @@ cameratopam - convert raw camera image to PAM [-balance_camera] [-red_scale=float] [-blue_scale=float] -[-bright=fraction] +[-brightness=fraction] [-no_clip_color] [-rgb] -[-use_secondary] +[-secondary] [-linear] [-verbose] @@ -106,7 +106,7 @@ the default.
Further adjust the color balance by multiplying the red and blue channels by these values. Both default to 1.0. -
-bright=float +
-brightness=float
Change the output brightness. Default is 1.0. @@ -114,14 +114,14 @@ channels by these values. Both default to 1.0.
By default, cameratoapm clips all colors to prevent pink hues in the highlights. Combine this option with --bright=0.25 to leave the image data completely unclipped. +-brightness=0.25 to leave the image data completely unclipped.
-rgb
Write raw camera colors to the output file. By default, cameratoapm converts to sRGB colorspace. -
-use_secondary +
-secondary
For cameras based on the Fuji Super CCD SR, this option causes cameratopam to use the secondary sensors, in effect diff --git a/userguide/escp2topbm.html b/userguide/escp2topbm.html index c66fc99..186e032 100644 --- a/userguide/escp2topbm.html +++ b/userguide/escp2topbm.html @@ -6,7 +6,6 @@ Updated: 14 July 2015
Table Of Contents -

NAME

escp2topbm - convert an ESC/P2 printer file to a PBM image

SYNOPSIS

diff --git a/userguide/faxformat.html b/userguide/faxformat.html index 4113470..cb5d710 100644 --- a/userguide/faxformat.html +++ b/userguide/faxformat.html @@ -5,11 +5,10 @@ Updated: 03 December 2008
-

SYNOPSIS

This page, part of the Netpbm user's guide, describes FAX formats in relation to Netpbm facilities. -

DESCRIPTION

+

The ITU (formerly CCITT) publishes standards for operation of fax machines (the idea is to provide a way to be sure that a fax machine is able to receive a fax sent by another). These standards incidentally specify graphics file diff --git a/userguide/fiascotopnm.html b/userguide/fiascotopnm.html index ea75b29..d8e2551 100644 --- a/userguide/fiascotopnm.html +++ b/userguide/fiascotopnm.html @@ -51,7 +51,7 @@ the output file(s) are written to the first (writable) directory of this list. Otherwise, the current directory is used to store the output file(s). -

-r, --fast +
-z, --fast
Decompress images in the 4:2:0 format; i.e., each chroma channel is decompressed to an image of halved width and height. Use this option @@ -83,7 +83,7 @@ given amount N. N is 1 (minimum) to 100 (maximum); default is 70. When N=0, then the smoothing amount specified in the FIASCO file is used (defined by the FIASCO coder). -
-F N, --framerate=N +
-F N, --fps=N
Set number of frames per second to N. When using this option, the frame rate specified in the FIASCO file is overridden. @@ -113,8 +113,13 @@ following methods (in the specified order):
  • --config=name -
    -h, --help -Print help, then exit. +
    -h, --info +
    +Print brief help, then exit. + +
    -H, --help +
    +Print detailed help, then exit. diff --git a/userguide/libnetpbm_ug.html b/userguide/libnetpbm_ug.html index bb1c77e..94d4fd4 100644 --- a/userguide/libnetpbm_ug.html +++ b/userguide/libnetpbm_ug.html @@ -374,7 +374,7 @@ plain format.

    Reference

    The Libnetpbm Netpbm Image -Processing Manual describes the libnetpbm functions for +Processing Manual describes the the libnetpbm functions for processing image data.

    The Libnetpbm Utility Manual diff --git a/userguide/pamfunc.html b/userguide/pamfunc.html index a4e2300..3440861 100644 --- a/userguide/pamfunc.html +++ b/userguide/pamfunc.html @@ -57,7 +57,7 @@ output image. and bit string (such as and with 01001000). For the arithmetic functions, the function arguments and results are the fraction that a sample is of the maxval, i.e. normal interpretation of PAM tuples. But for the bit string -functions, the value is the bit string whose value as a binary cipher is +functions, the value is the the bit string whose value as a binary cipher is the sample value, and the maxval indicates the width of the bit string.

    Arithmetic functions

    diff --git a/userguide/pampaintspill.html b/userguide/pampaintspill.html index f62011f..c71db55 100644 --- a/userguide/pampaintspill.html +++ b/userguide/pampaintspill.html @@ -1,7 +1,8 @@ - + Pampaintspill User Manual + @@ -10,7 +11,6 @@

    Table Of Contents

    -

    NAME

    pampaintspill - smoothly spill colors into the background

    SYNOPSIS

    diff --git a/userguide/pamperspective.html b/userguide/pamperspective.html index bb6cb58..9f5e9f0 100644 --- a/userguide/pamperspective.html +++ b/userguide/pamperspective.html @@ -220,7 +220,7 @@ default rectangle as the "frame." The visible part is always a rectangle the axes of which are parallel to those of the frame.

    The frame options are additive. All the parts of the image -specified by either margin options, --frame_include, or +specified by either margin options, --include_frame, or --include (or their defaults) are in the visible part. The visible part is the smallest possible rectangle that contains the parts specified those three ways. diff --git a/userguide/pamrecolor.html b/userguide/pamrecolor.html index c6ec0eb..b06536b 100644 --- a/userguide/pamrecolor.html +++ b/userguide/pamrecolor.html @@ -1,7 +1,8 @@ - + Pamrecolor User Manual + @@ -10,7 +11,7 @@

    Updated: 31 July 2010

    -

    Table Of Contents

    +

    Table Of Contents

    NAME

    diff --git a/userguide/pamsistoaglyph.html b/userguide/pamsistoaglyph.html index cebfaa0..8487717 100644 --- a/userguide/pamsistoaglyph.html +++ b/userguide/pamsistoaglyph.html @@ -1,7 +1,8 @@ - + Pamsistoaglyph User Manual + diff --git a/userguide/pamstereogram.html b/userguide/pamstereogram.html index 95012c3..4193a0d 100644 --- a/userguide/pamstereogram.html +++ b/userguide/pamstereogram.html @@ -1,5 +1,5 @@ - - + + Pamstereogram User Manual @@ -10,7 +10,7 @@

    Updated: 19 June 2015

    -

    Table Of Contents

    +

    Table Of Contents

    NAME

    diff --git a/userguide/pamtoavs.html b/userguide/pamtoavs.html index c8c63cb..4f1b63e 100644 --- a/userguide/pamtoavs.html +++ b/userguide/pamtoavs.html @@ -1,5 +1,5 @@ - + Pamtoavs User Manual diff --git a/userguide/pamtooctaveimg.html b/userguide/pamtooctaveimg.html index 69b09cb..9cadc13 100644 --- a/userguide/pamtooctaveimg.html +++ b/userguide/pamtooctaveimg.html @@ -1,7 +1,8 @@ - + Pamtooctaveimg User Manual + diff --git a/userguide/pbmtextps.html b/userguide/pbmtextps.html index bfce49f..a93ede8 100644 --- a/userguide/pbmtextps.html +++ b/userguide/pbmtextps.html @@ -185,7 +185,7 @@ edge of the type. See Margins for details.
    -ascent=n
    -descent=n
    -These options control the margins added to the image, measured from +These options control the the margins added to the image, measured from the text baseline. See Margins for details.

    Sizes are in points, as a floating point number. diff --git a/userguide/pbmtoepson.html b/userguide/pbmtoepson.html index c0df7c4..6895d33 100644 --- a/userguide/pbmtoepson.html +++ b/userguide/pbmtoepson.html @@ -18,7 +18,7 @@ pbmtoepson - convert a PBM image into Epson printer graphics [-dpi=n] [-protocol={escp9|escp}] [-adjacent] -[-noadjacent] +[-nonadjacent] [pbmfile] @@ -74,7 +74,7 @@ print density for you consistent with your other options.

    This option was new in Netpbm 10.23 (July 2004).

    -adjacent -
    -noadjacent +
    -nonadjacent
    These options determine whether the output uses "adjacent dot printing" or not, whatever that is. diff --git a/userguide/pbmtog3.html b/userguide/pbmtog3.html index 3b23517..ee2bd6b 100644 --- a/userguide/pbmtog3.html +++ b/userguide/pbmtog3.html @@ -77,7 +77,7 @@ You cannot specify both.

    HISTORY

    Before Netpbm 10.79 (June 2017), there was a different program by the same -name in Netpbm, which was written by Paul Haeberli +name in Netpbm, which was written by by Paul Haeberli <paul@manray.sgi.com> in 1989 and then modified extensively by others. diff --git a/userguide/pnmflip.html b/userguide/pnmflip.html index eb0b896..53c365c 100644 --- a/userguide/pnmflip.html +++ b/userguide/pnmflip.html @@ -4,11 +4,9 @@

    pnmflip


    -

    NAME

    pnmflip was replaced in Netpbm 10.13 (December 2002) by pamflip. -

    DESCRIPTION

    pamflip is mostly backward compatible with pnmflip, but works on PAM images too. diff --git a/userguide/pnmmercator.html b/userguide/pnmmercator.html index 9ac6c5b..e9e7165 100644 --- a/userguide/pnmmercator.html +++ b/userguide/pnmmercator.html @@ -1,6 +1,7 @@ - + + PnmMercator User Manual diff --git a/userguide/ppmtogif.html b/userguide/ppmtogif.html index 1d33072..84b5163 100644 --- a/userguide/ppmtogif.html +++ b/userguide/ppmtogif.html @@ -4,14 +4,11 @@

    ppmtogif


    -

    NAME

    ppmtogif was replaced in Netpbm 10.37 (December 2006) by pamtogif. -

    SYNOPSIS

    pamtogif is mostly backward compatible with ppmtogif. -

    DESCRIPTION

    One way pamtogif is not backward compatible with ppmtogif is that to specify a transparency (alpha) mask with ppmtogif, you supply the transparency as a separate pseudo-PGM image and use the diff --git a/userguide/ppmtompeg.html b/userguide/ppmtompeg.html new file mode 100644 index 0000000..a1ce767 --- /dev/null +++ b/userguide/ppmtompeg.html @@ -0,0 +1,1291 @@ + + + +Ppmtompeg User Manual + + +

    Ppmtompeg

    +Updated: 23 July 2006 +
    +Table Of Contents + +

    NAME

    +ppmtompeg - encode an MPEG-1 bitstream + +

    SYNOPSIS

    + +ppmtompeg +[options] +parameter-file + +

    DESCRIPTION

    + +

    This program is part of Netpbm. + +

    ppmtompeg produces an MPEG-1 video stream. MPEG-1 is the +first great video compression method, and is what is used in Video CDs +(VCD). ppmtompeg originated in the year 1995. DVD uses a more +advanced method, MPEG-2. There is an even newer method called MPEG-4 +which is also called Divx. I don't know where one finds that used. + +

    There's technically a difference between a compression method for +video and an actual file (stream) format for a movie, and I don't know +if it can be validly said that the format of the stream +ppmtompeg produces is MPEG-1. + +

    Mencoder from the Mplayer +package is probably superior for most video format generation +needs, if for no other reason than that it is more popular. + +

    The programming library PM2V +generates MPEG-2 streams. + +

    Use Mplayer (not part of Netpbm) +to do the reverse conversion: to create a series of PNM files from an MPEG +stream. + +

    param_file is a parameter file which includes a list of +input files and other parameters. The file is described in detail +below. + +

    To understand this program, you need to understand something about +the complex MPEG-1 format. One source of information about this +standard format is the section Introduction to MPEG in the Compression FAQ. + +

    OPTIONS

    + +

    The -gop, -combine_gops, -frames, and +-combine_frames options are all mutually exclusive. + +

    +
    -stat stat_file + +
    This option causes ppmtompeg to append the statistics that +it write to Standard Output to the file stat_file as well. The +statistics use the following abbreviations: bits per block (bpb), bits +per frame (bpf), seconds per frame (spf), and bits per second (bps). + +

    These statistics include how many I, P, and B frames there were, +and information about compression and quality. + + +

    -quiet num_seconds + +
    causes ppmtompeg not to report remaining time more often +than every num_seconds seconds (unless the time estimate rises, +which will happen near the beginning of the run). A negative value +tells ppmtompeg not to report at all. 0 is the default +(reports once after each frame). Note that the time remaining is an +estimate and does not take into account time to read in frames. + +
    -realquiet
    causes ppmtompeg to run silently, +with the only screen output being errors. Particularly useful when +reading input from stdin. + +
    +-no_frame_summary + +
    This option prevents ppmtompeg from printing a summary +line for each frame + +
    -float_dct + +
    forces ppmtompeg to use a more accurate, yet more +computationally expensive version of the DCT. + +
    -gop gop_num +
    +causes ppmtompeg to encode only the numbered GOP (first GOP is 0). The +parameter file is the same as for normal usage. The output file will be +the normal output file with the suffix .gop.gop_num. +ppmtompeg does not output any sequence information. + +
    -combine_gops + +
    causes ppmtompeg simply to combine some GOP files into a +single MPEG output stream. ppmtompeg inserts a sequence header +and trailer. In this case, the parameter file needs only to contain +the SIZE value, an output file, and perhaps a list of input GOP +files (see below). + +If you don't supply a list of input GOP files is used, then +ppmtompeg assumes you're using the same parameter file you used +when you created the input (with the -gop option) and +calculates the corresponding gop filenames itself. If this is not the +case, you can specify input GOP files in the same manner as normal +input files -- except instead of using INPUT_DIR, INPUT, and +END_INPUT, use GOP_INPUT_DIR, GOP_INPUT, and GOP_END_INPUT. If no +input GOP files are specified, then the default is to use the output +file name with suffix .gop.gop_num, with gop_num +starting from 0, as the input files. + +

    Thus, unless you're mixing and matching GOP files from different +sources, you can simply use the same parameter file for creating the +GOP files (-gop) and for later turning them into an MPEG stream +(-combine_gops). + + +

    -frames first_frame last_frame + +
    This option causes ppmtompeg to encode only the frames numbered +first_frame to last_frame, inclusive. The parameter +file is the same as for normal usage. The output will be placed in +separate files, one per frame, with the file names being the normal +output file name with the suffix .frame.frame_num. No +GOP header information is output. (Thus, the parameter file need not +include the GOP_SIZE value) + +

    Use ppmtompeg -combine_frames to combine these frames later into +an MPEG stream. + + +

    -combine_frames + +
    This option causes ppmtompeg simply to combine some +individual MPEG frames (such as you might have created with an earlier +run of ppmtompeg -frames) into a single MPEG stream. Sequence +and GOP headers are inserted appropriately. In this case, the +parameter file needs to contain only the SIZE value, the GOP_SIZE +value, an output file, and perhaps a list of frame files (see below). + +

    The parameter file may specify input frame files in the same manner +as normal input files -- except instead of using INPUT_DIR, INPUT, and +END_INPUT, use FRAME_INPUT_DIR, FRAME_INPUT, and FRAME_END_INPUT. If +no input frame files are specified, then the default is to use the +output file name with suffix .frame.frame_num, with +frame_num starting from 0, as the input files. + + + +

    -nice + +
    This option causes ppmtompeg to run any remote processes +"nicely," i.e. at low priority. (This is relevant only if you are +running ppmtompeg in parallel mode. Otherwise, there are no +remote processes). See 'man nice.' + +
    -max_machines num_machines + +
    This option causes ppmtompeg to use no more than +num_machines machines as slaves for use in parallel encoding. + +
    -snr + +
    This option causes ppmtompeg to include the signal-to-noise +ratio in the reported statistics. Prints SNR (Y U V) and peak SNR (Y +U V) for each frame. In summary, prints averages of luminance only +(Y). SNR is defined as 10*log(variance of original/variance of +error). Peak SNR is defined as 20*log(255/RMSE). Note that +ppmtompeg runs a little slower when you use this option. + +
    -mse + +
    This option causes ppmtompeg to report the mean squared +error per block. It also automatically reports the quality of the +images, so there is no need to specify -snr then. + +
    -bit_rate_info rate_file + +
    This option makes ppmtompeg write bit rate information +into the file rate_file. Bit rate information is bits per frame, and +also bits per I-frame-to-I-frame. + +
    -mv_histogram + +
    This option causes ppmtompeg to print a histogram of the +motion vectors as part of statistics. There are three histograms -- +one for P frame, one for forward B frame, and one for backward B frame +motion vectors. + +

    The output is in the form of a matrix, each entry corresponding to one +motion vector in the search window. The center of the matrix +represents (0,0) motion vectors. + +

    -debug_sockets + +
    This option causes ppmtompeg to print to Standard Output +messages that narrate the communication between the machines when you run +ppmtompeg in parallel mode. + +
    -debug_machines + +
    This option causes ppmtompeg to print to Standard Output +messages that narrate the progress of the conversion on the various +machines when you run ppmtompeg in parallel +mode. + +
    + +

    PARAMETER FILE

    + +

    The parameter file must contain the following +lines (except when using the -combine_gops or -combine_frames +options): + +

    + +
    PATTERN pattern + +
    This statement specifies the pattern (sequence) of I frames, P frames, +and B frames. pattern is just a sequence of the letters I, P, and +B with nothing between. Example: + +
    +    PATTERN IBBPBBPBBPBBPBB
    +
    + +

    See I Frames, P Frames, B Frames. + +

    OUTPUT output file +
    This names the file where the output MPEG stream goes. + +
    INPUT_DIR directory + +
    This statement tells where the input images (frames) come from. +If each frame is in a separate file, directory is the directory +where they all are. You may use . to refer to the current +directory. A null directory refers to the root directory of the +system file tree. + +

    To have ppmtompeg read all the frames serially from Standard +Input, specify +

    +    INPUT_DIR stdin
    +
    + +
    INPUT +
    +This line must be followed by a list of the input files (in display order) +and then the line END_INPUT. + +

    There are three types of lines between INPUT and END_INPUT. First, +a line may simply be the name of an input file. Second, the line +may be of the form single_star_expr +[x-y]. +single_star_expr can have a single * in it. It is +replaced by all the numbers between x and y inclusive. So, for +example, the line tennis*.ppm [12-15] refers to the files +tennis12.ppm, tennis13.ppm, tennis14.ppm, tennis15.ppm. + +

    Uniform zero-padding occurs, as well. For example, the line +football.*.ppm [001-130] refers to the files football.001.ppm, +football.002.ppm, ..., football.009.ppm, football.010.ppm, ..., +football.130.ppm. + +

    The third type of line is: single_star_expr +[x-y+s], where the +line is treated exactly as above, except that we skip by s. Thus, the +line football.*.ppm [001-130+4] refers to the files +football.001.ppm, football.005.ppm, football.009.ppm, +football.013.ppm, etc. + +

    Furthermore, a line may specify a shell command to execute to +generate lines to be interpreted as described above, as if those lines +were in the parameter file instead. Use back ticks, like in the +Bourne Shell, like this: + +

    +    `cat myfilelist`
    +
    + +

    +If input is from Standard Input (per the INPUT_DIR statement), +ppmtompeg ignores the INPUT/END_INPUT block, but +it still must be present. + +

    BASE_FILE_FORMAT {PPM | PNM | YUV | + JPEG | JMOVIE} + +
    ppmtompeg must convert all input files to one of the +following formats as a first step of processing: PNM, YUV, JPEG(v4), +or JMOVIE. (The conversion may be trivial if your input files are +already in one of these formats). This line specifies which of the +four formats. PPM is actually a subset of PNM. The separate +specification is allowed for backward compatibility. Use PNM instead +of PPM in new applications. + +
    INPUT_CONVERT conversion_command + +
    You must specify how to convert a file to the base file format. +If no conversion is necessary, then you would just say: + +
    +     INPUT_CONVERT *
    +     
    + +

    Otherwise, conversion_command is a shell command that causes +an image in the format your specified with BASE_FILE_FORMAT to +be written to Standard Output. ppmtompeg executes the command +once for each line between INPUT and END_INPUT (which is +normally, but not necessarily, a file name). In the conversion +command, ppmtompeg replaces each '*' with the contents of that +line. + + If you had a bunch of gif files, you might say: +

    +     INPUT_CONVERT giftopnm *
    +     
    + + If you have a bunch of separate a.Y, a.U, and a.V files (where + the U and V have already been subsampled), then you might say: + +
    +     INPUT_CONVERT cat *.Y *.U *.V
    +     
    + +

    Input conversion is not allowed with input from stdin, so use + +

    +     INPUT_CONVERT *
    +     
    + +as described above. + +
    SIZE widthxheight + +
    + +

    width and height are the width and height of each +frame in pixels. + +

    When ppmtompeg can get this information from the input image +files, it ignores the SIZE parameter and you may omit it. + +

    When the image files are in YUV format, the files don't contain +dimension information, so SIZE is required. + +

    When ppmtompeg is running in parallel mode, not all of the +processes in the network have access to the image files, so +SIZE is required and must give the same dimensions as the +input image files. + +

    YUV_SIZE widthxheight + +
    This is an obsolete synonym of SIZE. + +
    YUV_FORMAT {ABEKAS | PHILLIPS | UCB | + EYUV | pattern} + +
    This is meaningful only when BASE_FILE_FORMAT specifies +YUV format, and then it is required. It specifies the sub-format of +the YUV class. + + +
    GOP_SIZE n + +
    n is the number of frames in a Group of Pictures. Except that +because a GOP must start with an I frame, ppmtompeg makes a GOP as +much longer than n as it has to to make the next GOP start with an +I frame. + +

    Normally, it makes sense to make your GOP size a multiple of your +pattern length (the latter is determined by the PATTERN parameter file +statement). + +

    See Group Of Pictures. + +

    SLICES_PER_FRAME n +
    n is roughly the number of slices per frame. Note, at +least one MPEG player may complain if slices do not start at the left +side of an image. To ensure this does not happen, make sure the +number of rows is divisible by SLICES_PER_FRAME. + +
    PIXEL {FULL | HALF} + +
    use half-pixel motion vectors, or just full-pixel ones It is +usually important that you use half-pixel motion vectors, because it +results in both better quality and better compression. + + +
    RANGE n +
    Use a search range of n pixels in each of the four directions +from a subject pixel. (So the search window is a square n*2 pixels +on a side). + +
    PSEARCH_ALG {EXHAUSTIVE | TWOLEVEL | + SUBSAMPLE | LOGARITHMIC} + +
    This statement tells ppmtompeg what kind of search + technique (algorithm) to use for P frames. You select the desired + combination of speed and compression. EXHAUSTIVE gives the + best compression, but LOGARITHMIC is the fastest. + TWOLEVEL is an exhaustive full-pixel search, followed by a + local half- pixel search around the best full-pixel vector (the + PIXEL option is ignored for this search technique). + +
    BSEARCH_ALG {SIMPLE | CROSS2 | EXHAUSTIVE} + +
    This statement tells ppmtompeg what kind of search + technique (algorithm) to use for B frames. SIMPLE means + find best forward and backward vectors, then interpolate. + CROSS2 means find those two vectors, then see what backward + vector best matches the best forward vector, and vice versa. + EXHAUSTIVE does an n-squared search and is + extremely slow in relation to the others (CROSS2 + is about half as fast as SIMPLE). + +
    IQSCALE n +
    Use n as the qscale for I frames. + See Qscale. + +
    PQSCALE n +
    Use n as the qscale for P frames. + See Qscale. + +
    BQSCALE n +
    Use n as the qscale for B frames. + See Qscale. + +
    REFERENCE_FRAME {ORIGINAL | DECODED}
    This +statement determines whether ppmtompeg uses the original images +or the decoded images when computing motion vectors. Using decoded +images is more accurate and should increase the playback quality of +the output, but it makes the encoding take longer and seems to give +worse compression. It also causes some complications with parallel +encoding. (see the section on parallel encoding). One thing you can +do as a trade-off is select ORIGINAL here, and lower the +qscale (see QSCALE if the quality is not good enough. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Original or Decoded? (Normalized)
    ReferenceCompressionSpeedQuality IQuality PQuality B
    Decoded100010001000969919
    Original88513731000912884
    + + + +
    + +

    The following lines are optional: + +

    + +
    FORCE_ENCODE_LAST_FRAME + +
    This statement is obsolete. It does nothing. + +

    Before Netpbm 10.26 (January 2005), ppmtompeg would drop +trailing B frames from your movie, since a movie can't end with a B +frame. (See I Frames, P Frames, B Frames. +You would have to specify FORCE_ENCODE_LAST_FRAME to stop +that from happening and get the same function that ppmtompeg +has today. + + +

    NIQTABLE + +
    This statement specifies a custom non-intra quantization table. +If you don't specify this statement, ppmtompeg uses a default +non-intra quantization table. + +

    +The 8 lines immediately following NIQTABLE specify the quantization +table. Each line defines a table row and consists of 8 integers, +whitespace-delimited, which define the table columns. + +

    IQTABLE + +
    This is analogous to NIQTABLE, but for the intra quantization table. + +
    ASPECT_RATIO ratio + +
    This statement specifies the aspect ratio for ppmtompeg to +specify in the MPEG output. I'm not sure what this is used for. + +

    ratio must be 1.0, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, +0.8935, 0.9157, 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, or 1.2015. + +

    FRAME_RATE rate +
    This specifies the frame rate for ppmtompeg to specify in the +MPEG output. Some players use this value to determine the playback rate. + +

    rate must be 23.976, 24, 25, 29.97, 30, 50, 59.94, or 60. + +

    BIT_RATE rate +
    This specifies the bit rate for Constant Bit Rate (CBR) encoding. + +

    rate must be an integer. + +

    BUFFER_SIZE size + +
    This specifies the value +ppmtompeg is to specify in the MPEG output for the Video +Buffering Verifier (VBV) buffer size needed to decode the sequence. + +

    A Video Verifying Buffer is a buffer in which a decoder keeps the +decoded bits in order to match the uneven speed of the decoding with +the required constant playback speed. + +

    As ppmtompeg encodes the image, it simulates the decoding +process in terms of how many bits would be in the VBV as each frame gets +decoded, assuming a VBV of the size you indicate. + +

    If you specify the WARN_VBV_UNDERFLOW statement, +ppmtompeg issues a warning each time the simulation underflows +the buffer, which suggests that an underflow would occur on playback, +which suggests the buffer is too small. + +

    If you specify the WARN_VBV_OVERFLOW statement, +ppmtompeg issues a warning each time the simulation overflows +the buffer, which suggests that an overflow would occur on playback, +which suggests the buffer is too small. + +

    WARN_VBV_UNDERFLOW +
    WARN_VBV_OVERFLOW + +
    See BUFFER_SIZE. + +

    These options were new in Netpbm 10.26 (January 2005). Before that, +ppmtompeg issued the warnings always. + +

    + + +The following statements apply only to parallel operation: + +
    + +
    PARALLEL + +
    This statement, paired with END PARALLEL, is what causes +ppmtompeg to operate in parallel mode. See Parallel Operation. + +
    END PARALLEL + +
    This goes with PARALLEL. + +
    PARALLEL_TEST_FRAMES n + +
    The master starts off by measuring each slave's speed. It does +this by giving each slave n frames to encode and noting how +long the slave takes to finish. These are not just test frames, +though -- they're real frames and the results become part of the +output. +ppmtompeg is old and measures time in undivided seconds, so +to get useful timings, specify enough frames that it will take at +least 5 seconds to process them. The default is 10. + +

    If you specify FORCE_I_ALIGN, ppmtompeg will increase +the test frames value enough to maintain the alignment. + +

    If there aren't enough frames for every slave to have the indicated +number of test frames, ppmtompeg will give some slaves fewer. + + +

    PARALLEL_TIME_CHUNKS t + +
    When you specify this statement, the master attempts to feed work +to the slaves in chunks that take t seconds to process. It uses +the speed measurement it made when it started up (see PARALLEL_TEST_FRAMES) +to decide how many frames to put in the chunk. This statement obviously +doesn't affect the first batch of work sent to each slave, which is the +one used to measure the slave's speed. + +

    Smaller values of t increase communication, but improve load +balancing. The default is 30 seconds. + +

    You may specify only one of PARALLEL_TIME_CHUNKS, PARALLEL_CHUNK_TAPER, +and PARALLEL_PERFECT. PARALLEL_CHUNK_TAPER is usually best. + +

    PARALLEL_CHUNK_TAPER + +
    When you specify this statement, the master distributes work like +with PARALLEL_TIME_CHUNKS, except that the master chooses the number +of seconds for the chunks. It starts with a large number and, as it +gets closer to finishing the job, reduces it. That way, it reduces +scheduling overhead when precise scheduling isn't helpful, but still +prevents a slave from finishing early after all the work has already +been handed out to the other slaves, and then sitting idle while +there's still work to do. + +

    You may specify only one of PARALLEL_TIME_CHUNKS, PARALLEL_CHUNK_TAPER, +and PARALLEL_PERFECT. PARALLEL_CHUNK_TAPER is usually best. + + +

    PARALLEL_PERFECT + +
    If this statement is present, ppmtompeg schedules on the +assumption that each machine is about the same speed. The master will +simply divide up the frames evenly between the slaves -- each +slave gets the same number of frames. If some slaves are faster than +others, they will finish first and remain idle while the slower slaves +continue. + +

    This has the advantage of minimal scheduling overhead. Where slaves +have different speeds, though, it makes inefficient use of the fast +ones. Where slaves are the same speed, it also has the disadvantage +that they all finish at the same time and feed their output to the +single Combine Server in a burst, which makes less efficient use of +the Combine Server and thus can increase the total elapsed time. + +

    You may specify only one of PARALLEL_TIME_CHUNKS, PARALLEL_CHUNK_TAPER, +and PARALLEL_PERFECT. PARALLEL_CHUNK_TAPER is usually best. + +

    RSH remote_shell_command + +
    ppmtompeg executes the shell command +remote_shell_command to start a process on another machine. +The default command is rsh, and whatever command you specify +must have compatible semantics. ssh is usually compatible. +The command ppmtompeg uses is one like this: +ssh remote.host.com -l username shellcommand. + +

    Be sure to set up .rhosts files or SSH key authorizations +where needed. Otherwise, you'll have to type in passwords. + +

    On some HP machines, rsh is the restricted shell, and you want +to specify remsh. + +

    FORCE_I_ALIGN + +
    This statement forces each slave to encode a chunk of frames which +is a multiple of the pattern length (see PATTERN). Since the +first frame in any pattern is an I frame, this forces each chunk +encoded by a slave to begin with an I frame. + +

    This document used to say there was an argument to +FORCE_I_ALIGN which was the number of frames ppmtompeg +would use (and was required to be a multiple of the pattern length). +But ppmtompeg has apparently always ignored that argument, and +it does now. + +

    KEEP_TEMP_FILES + +
    This statement causes ppmtompeg not to delete the temporary +files it uses to transmit encoded frames to the combine server. This +means you will be left with a file for each frame, the same as you +would get with the -frames option. + +

    This is mostly useful for debugging. + +

    This works only if you're using a shared filesystem to communicate +between the servers. + +

    This option was new in Netpbm 10.26 (January 2005). + +

    + + +

    Parameter File Notes

    + +

    If you use the -combine_gops option, then you need to specify +only the SIZE and OUTPUT values in the parameter file. In +addition, the parameter file may specify input GOP files in the same +manner as normal input files -- except instead of using INPUT_DIR, +INPUT, and END_INPUT, use GOP_INPUT_DIR, GOP_INPUT, and GOP_END_INPUT. +If you specify no input GOP files, then ppmtompeg uses by default the +output file name with suffix .gop.gop_num, with gop_num +starting from 0, as the input files. + +

    If you use the -combine_frames option, then you need to +specify only the SIZE, GOP_SIZE, and OUTPUT values in the +parameter file. In addition, the parameter file may specify input +frame files in the same manner as normal input files -- except instead +of using INPUT_DIR, INPUT, and END_INPUT, use FRAME_INPUT_DIR, +FRAME_INPUT, and FRAME_END_INPUT. If no input frame files are +specified, then the default is to use the output file name with suffix +.frame.frame_num, with frame_num starting from 0, +as the input files. + +

    Any number of spaces and tabs may come between each option and value. Lines +beginning with # are ignored. Any other lines are ignored except for +those between INPUT and END_INPUT. This allows you to use the same +parameter file for normal usage and for -combine_gops and +-combine_frames. + +

    The file format is case-sensitive so all keywords should be in +upper case. + +

    The statements may appear in any order, except that the order within +a block statement (such as INPUT ... END INPUT) is significant. + +

    ppmtompeg is prepared to handle up to 16 B frames between +reference frames when encoding with input from stdin. (To build a +modified ppmtompeg with a higher limit, change the constant +B_FRAME_RUN in frame.c and recompile). + +

    GENERAL USAGE INFORMATION

    + +

    Qscale

    + +

    The quantization scale values (qscale) give a trade-off between +quality and compression. Using different Qscale values has very little +effect on speed. The qscale values can be set separately for I, P, and +B frames. + +

    You select the qscale values with the IQSCALE, +PQSCALE, and BSCALE parameter file statements. + +

    A qscale value is an integer from 1 to 31. Larger numbers give +better compression, but worse quality. In the following, the quality +numbers are peak signal-to-noise ratio, defined as: +signal-to-noise formula +where MSE is the mean squared error. + + +

    Flower garden tests: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Qscale vs Quality
    QscaleI FramesP FramesB Frames
    143.246.346.5
    632.634.634.3
    1128.629.530.0
    1626.326.828.6
    2124.725.027.9
    2623.523.927.5
    3122.623.027.3
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Qscale vs Compression
    QscaleI FramesP FramesB Frames
    1222
    671015
    11111843
    16152997
    211941173
    262456256
    312873330
    + + +

    Search Techniques

    + +

    There are several different motion vector search techniques +available. There are different techniques available for P frame +search and B frame search. Using different search techniques present +little difference in quality, but a large difference in compression +and speed. + +

    There are 4 types of P frame search: Exhaustive, TwoLevel, +SubSample, and Logarithmic. + +

    There are 3 types of B frame search: Exhaustive, Cross2, and +Simple. + +The recommended search techniques are TwoLevel and Logarithmic for +P frame search, and Cross2 and Simple for B frame search. Here are +some numbers comparing the different search methods: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    P frame Motion Vector Search (Normalized)
    TechniqueCompression1Speed 2Quality 3
    Exhaustive100010001000
    SubSample100824561000
    TwoLevel100932371000
    Logarithmic10858229998
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    B frame Motion Vector Search (Normalized)
    TechniqueCompression1Speed2Quality3
    Exhaustive100010001000
    Cross29751000996
    Simple9381765991
    + + 1Smaller numbers are better +compression. + + 2Larger numbers mean faster +execution. + + 3Larger numbers mean better quality. + +

    For some reason, Simple seems to give better compression, but it +depends on the image sequence. + +

    Select the search techniques with the PSEARCH_ALG and +BSEARCH_ALG parameter file statements. + + + +

    Group Of Pictures (GOP)

    + +

    A Group of Pictures (GOP) is a roughly independently decodable +sequence of frames. An MPEG video stream is made of one or more +GOP's. You may specify how many frames should be in each GOP with the +GOP_SIZE parameter file statement. A GOP always starts with an +I frame. + +

    Instead of encoding an entire sequence, you can encode a single +GOP. To do this, use the -gop command option. You can later +join the resulting GOP files at any time by running ppmtompeg +with the -combine_gops command option. + + +

    Slices

    + +

    A slice is an independently decodable unit in a frame. It can be +as small as one macroblock, or it can be as big as the entire frame. +Barring transmission error, adding slices does not change quality or +speed; the only effect is slightly worse compression. More slices are +used for noisy transmission so that errors are more recoverable. Since +usually errors are not such a problem, we usually just use one slice +per frame. + +

    Control the slice size with the SLICES_PER_FRAME parameter +file statement. + +

    Some MPEG playback systems require that each slice consist of whole +rows of macroblocks. If you are encoding for this kind of player, if +the height of the image is H pixels, then you should set the +SLICES_PER_FRAME to some number which divides H/16. For example, if +the image is 240 pixels (15 macroblocks) high, then you should use +only 15, 5, 3, or 1 slices per frame. + +

    Note: these MPEG playback systems are really wrong, since the MPEG +standard says this doesn't have to be so. + + + +

    Search Window

    + +

    The search window is the window in which ppmtompeg searches +for motion vectors. The window is a square. You can specify the size +of the square, and whether to allow half-pixel motion vectors or not, +with the RANGE and PIXEL parameter file statements. + +

    I Frames, P Frames, B Frames

    + +

    In MPEG-1, a movie is represented as a sequence of MPEG frames, +each of which is an I Frame, a P Frame, or a B Frame. Each represents +an actual frame of the movie (don't get confused by the dual use of +the word "frame." A movie frame is a graphical image. An MPEG frame +is a set of data that describes a movie frame). + +

    An I frame ("intra" frame) describes a movie frame in isolation -- +without respect to any other frame in the movie. A P frame +("predictive" frame) describes a movie frame by describing how it +differs from the movie frame described by the latest preceding I or +P frame. A B frame ("bidirectional" frame) describes a movie frame by +describing how it differs from the movie frames described by the +nearest I or P frame before and after it. + +

    Note that the first frame of a movie must be described by an I +frame (because there is no previous movie frame) and the last movie +frame must be described by an I or P frame (because there is no +subsequent movie frame). + +

    Beyond that, you can choose which frames are represented by which +types. You specify a pattern, such as IBPBP and ppmtompeg +simply repeats it over and over throughout the movie. The pattern +affects speed, quality, and stream size. Here is a chart which shows +some of the trade-offs: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Comparison of I/P/B Frames (Normalized)
    Frame TypeSizeSpeedQuality
    I frames100010001000
    P frames409609969
    B frames72260919
    + +(this is with constant qscale) + +

    A standard sequence is IBBPBBPBBPBBPBB. + +

    Select the sequence with the PATTERN parameter file statement. + +

    Since the last MPEG frame cannot be a B frame (see above), if the +pattern you specify indicates a B frame for the last movie frame of +the movie, ppmtompeg makes it an I frame instead. + +

    Before Netpbm 10.26 (January 2005), ppmtompeg instead drops +the trailing B frames by default, and you need the +FORCE_ENCODE_LAST_FRAME parameter file statement to make it do +this. + +

    The MPEG frames don't appear in the MPEG-1 stream in the same order that +the corresponding movie frames appear in the movie -- the B frames come after +the I and P frames on which they are based. For example, if the movie is +4 frames that you will represent with the pattern IBBP, the MPEG-1 stream +will start with an I frame describing movie frame 0. The next frame in +the MPEG-1 stream is a P frame describing movie frame 3. The last two +frames in the MPEG-1 stream are B frames describing movie frames 1 and 2, +respectively. + + +

    Specifying Input and Output Files

    + +

    Specify the input frame images with the INPUT_DIR, +INPUT, END_INPUT, BASE_FILE_FORMAT, +SIZE, YUV_FORMAT and INPUT_CONVERT parameter +file statements. + +

    Specify the output file with the OUTPUT parameter file statement. + + +

    Statistics

    + +

    ppmtompeg can generate a variety of statistics about the +encoding. See the -stat, -snr, -mv_histogram, +-quiet, -no_frame_summary, and -bit_rate_info +options. + + +

    PARALLEL OPERATION

    + +

    You can run ppmtompeg on multiple machines at once, encoding +the same MPEG stream. When you do, the machines are used as shown in +the following diagram. We call this "parallel mode." + +

    ppmtompeg-par.gif + +

    To do parallel processing, put the statement + +

    +    PARALLEL
    +
    + +in the parameter file, followed by a listing of the machines, one +machine per line, then + +
    +    END_PARALLEL
    +
    + +Each of the machine lines must be in one of two forms. If the machine +has filesystem access to the input files, then the line is: + +

    +machine user executable + +

    The executable is normally ppmtompeg (you may need to give +the complete path if you've built for different architectures). If +the machine does not have filesystem access to the input files, the line +is: + +

    REMOTE machine user executable +parameter file + +

    The -max_machines command option limits the number of +machines ppmtompeg will use. If you specify more machines in +the parameter file than -max_machines allows, ppmtompeg +uses only the machines listed first. This is handy if you want to +experiment with different amounts of parallelism. + +

    In general, you should use full path file names when describing +executables and parameter files. This includes the parameter +file argument on the original invocation of ppmtompeg. + +

    All file names must be the same on all systems (so if e.g. you're +using an NFS filesystem, you must make sure it is mounted at the same +mountpoint on all systems). + +

    Because not all of the processes involved in parallel operation +have easy access to the input files, you must specify the SIZE +parameter file statement when you do parallel operation. + +

    The machine on which you originally invoke ppmtompeg is the +master machine. It hosts a "combine server,", a +"decode server," and a number of "i/o servers," +all as separate processes. The other machines in the network (listed +in the parameter file) are slave machines. Each hosts a single +process that continuously requests work from the master and does it. +The slave process does the computation to encode MPEG frames. It +processes frames in batches identified by the master. + +

    The master uses a remote shell command to start a process on a +slave machine. By default, it uses an rsh shell command to do +this. But use the RSH parameter file statement to control +this. The shell command the master executes remotely is +ppmtompeg, but with options to indicate that it is to perform +slave functions. + +

    The various machines talk to each other over TCP connections. Each +machine finds and binds to a free TCP port number and tells its +partners the port number. These port numbers are at least 2048. + +

    Use the PARALLEL_TEST_FRAMES, PARALLEL_TIME_CHUNKS, and +PARALLEL_PERFECT parameter file statements to control the way the +master divides up work among the slaves. + +

    Use the -nice command option to cause all slave processes to run +"nicely," i.e. as low priority processes. That way, this substantial and +long-running CPU load will have minimal impact on other, possibly +interactive, users of the systems. + +  +

    SPEED

    + +

    Here is a look at ppmtompeg speed, in single-node (not parallel) +operation: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Compression Speed
    Machine TypeMacroblocks per second1
    HP 9000/755280
    DEC 3000/400247
    HP 9000/750191
    Sparc 10104
    DEC 500068
    +1A macroblock is a 16x16 pixel square + +

    The measurements in the table are with inputs and outputs via a +conventional locally attached filesystem. If you are using a network +filesystem over a single 10 MB/s Ethernet, that constrains your speed more +than your CPU speed. In that case, don't expect to get better than 4 +or 5 frames per second no matter how fast your CPUs are. + +

    Network speed is even more of a bottleneck when the slaves do not +have filesystem access to the input files -- i.e. you declare them +REMOTE. + +

    Where I/O is the bottleneck, size of the input frames can make a big +difference. So YUV input is better than PPM, and JPEG is better than +both. + +

    When you're first trying to get parallel mode working, be sure to +use the -debug_machines option so you can see what's going on. +Also, -debug_sockets can help you diagnose communication +problems. + + +

    AUTHORS

    + + + +
    +  +

    Table Of Contents

    + + +