From 0bf54ddfa2a0efcf6142ad1292abbfa26fe0bee3 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Mon, 2 Oct 2006 03:42:10 +0000 Subject: cleanup git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@82 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/other/pgmtopbm.c | 5 +- converter/pbm/pbmtogo.c | 4 +- converter/ppm/ppmtompeg/jpeg.c | 1 + doc/HISTORY | 2 + editor/pamaddnoise.c | 4 +- editor/pamditherbw.c | 2 +- editor/pbmreduce.c | 15 +-- editor/pnmremap.c | 2 +- editor/ppmshift.c | 219 ++++++++++++++++++++--------------------- editor/ppmspread.c | 216 +++++++++++++++++++--------------------- generator/pbmtextps.c | 6 +- generator/pgmcrater.c | 7 +- generator/pgmnoise.c | 115 ++++++++++------------ generator/ppmforge.c | 5 +- generator/ppmpat.c | 2 +- lib/libpm.c | 14 ++- lib/libppmfloyd.c | 41 ++++---- lib/pm.h | 3 + lib/ppmfloyd.h | 18 ++-- pm_config.in.h | 28 +----- 20 files changed, 340 insertions(+), 369 deletions(-) diff --git a/converter/other/pgmtopbm.c b/converter/other/pgmtopbm.c index 98bdc332..36b39017 100644 --- a/converter/other/pgmtopbm.c +++ b/converter/other/pgmtopbm.c @@ -11,10 +11,11 @@ */ #include + +#include "shhopt.h" #include "pgm.h" #include "dithers.h" #include "mallocvar.h" -#include "shhopt.h" enum halftone {QT_FS, QT_THRESH, QT_DITHER8, QT_CLUSTER, QT_HILBERT}; @@ -445,7 +446,7 @@ createFsConverter(unsigned int const cols, /* Initialize Floyd-Steinberg error vectors. */ MALLOCARRAY_NOFAIL(stateP->thiserr, cols + 2); MALLOCARRAY_NOFAIL(stateP->nexterr, cols + 2); - srand((int)(time(NULL) ^ getpid())); + srand(pm_randseed()); { /* (random errors in [-fs_scale/8 .. fs_scale/8]) */ diff --git a/converter/pbm/pbmtogo.c b/converter/pbm/pbmtogo.c index b7c12373..a2349176 100644 --- a/converter/pbm/pbmtogo.c +++ b/converter/pbm/pbmtogo.c @@ -214,7 +214,7 @@ main( argc, argv ) fflush(stdout); /* Output the plot data */ - write(1, outbuffer, nout); + fwrite(outbuffer, 1, nout, stdout); /* Reset the counters */ linerepeat = 0; @@ -225,7 +225,7 @@ main( argc, argv ) putchar(linerepeat); printf("%d/", nout+1); fflush(stdout); - write(1, outbuffer, nout); + fwrite(outbuffer, 1, nout, stdout); linerepeat = 0; } } diff --git a/converter/ppm/ppmtompeg/jpeg.c b/converter/ppm/ppmtompeg/jpeg.c index 3aad6364..a6e1eced 100644 --- a/converter/ppm/ppmtompeg/jpeg.c +++ b/converter/ppm/ppmtompeg/jpeg.c @@ -15,6 +15,7 @@ * HEADER FILES * *==============*/ #define _XOPEN_SOURCE /* Make sure stdio.h contains fileno() */ +#include #include #include "all.h" /* With the lossless jpeg patch applied to the Jpeg library diff --git a/doc/HISTORY b/doc/HISTORY index 403f0330..4a355b42 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -6,6 +6,8 @@ CHANGE HISTORY not yet BJH Release 10.37.0 + Fix some compile failures with Irix IDO compiler. + Build: Configure does test links to detect broken libpng-config --ldflags. diff --git a/editor/pamaddnoise.c b/editor/pamaddnoise.c index 9c2d12f7..cf1af815 100644 --- a/editor/pamaddnoise.c +++ b/editor/pamaddnoise.c @@ -208,7 +208,7 @@ main(int argc, char * argv[]) { int argn; const char * inputFilename; int noise_type; - int seed; + unsigned int seed; int i; const char * const usage = "[-type noise_type] [-lsigma x] [-mgsigma x] " "[-sigma1 x] [-sigma2 x] [-lambda x] [-seed n] " @@ -247,7 +247,7 @@ main(int argc, char * argv[]) { pnm_init(&argc, argv); - seed = time(NULL) ^ getpid(); + seed = pm_randseed(); noise_type = GAUSSIAN; argn = 1; diff --git a/editor/pamditherbw.c b/editor/pamditherbw.c index 61c23103..931b475f 100644 --- a/editor/pamditherbw.c +++ b/editor/pamditherbw.c @@ -487,7 +487,7 @@ createFsConverter(struct pam * const graypamP, /* Initialize Floyd-Steinberg error vectors. */ MALLOCARRAY_NOFAIL(stateP->thiserr, graypamP->width + 2); MALLOCARRAY_NOFAIL(stateP->nexterr, graypamP->width + 2); - srand((int)(time(NULL) ^ getpid())); + srand(pm_randseed()); { /* (random errors in [-1/8 .. 1/8]) */ diff --git a/editor/pbmreduce.c b/editor/pbmreduce.c index 15ec2a1b..f49c8d9a 100644 --- a/editor/pbmreduce.c +++ b/editor/pbmreduce.c @@ -91,21 +91,22 @@ main( argc, argv ) pbm_writepbminit( stdout, newcols, newrows, 0 ); newbitrow = pbm_allocrow( newcols ); - if ( halftone == QT_FS ) { + if (halftone == QT_FS) { + unsigned int col; /* Initialize Floyd-Steinberg. */ MALLOCARRAY(thiserr, newcols + 2); MALLOCARRAY(nexterr, newcols + 2); - if ( thiserr == NULL || nexterr == NULL ) - pm_error( "out of memory" ); + if (thiserr == NULL || nexterr == NULL) + pm_error("out of memory"); - srand( (int) ( time( 0 ) ^ getpid( ) ) ); - for ( col = 0; col < newcols + 2; ++col ) - thiserr[col] = ( rand( ) % SCALE - HALFSCALE ) / 4; + srand(pm_randseed()); + for (col = 0; col < newcols + 2; ++col) + thiserr[col] = (rand() % SCALE - HALFSCALE) / 4; /* (random errors in [-SCALE/8 .. SCALE/8]) */ } else { /* These variables are meaningless in this case, and the values should never be used. - */ + */ thiserr = NULL; nexterr = NULL; } diff --git a/editor/pnmremap.c b/editor/pnmremap.c index 2102fe63..e9466fe5 100644 --- a/editor/pnmremap.c +++ b/editor/pnmremap.c @@ -299,7 +299,7 @@ initFserr(struct pam * const pamP, "for Plane %u, size %u", plane, fserrSize); } - srand((int)(time(0) ^ getpid())); + srand(pm_randseed()); { int col; diff --git a/editor/ppmshift.c b/editor/ppmshift.c index 1f8a599b..a765daa5 100644 --- a/editor/ppmshift.c +++ b/editor/ppmshift.c @@ -11,127 +11,122 @@ #include "ppm.h" -/* global variables */ -#ifdef AMIGA -static char *version = "$VER: ppmshift 1.1 (16.11.93)"; /* Amiga version identification */ -#endif - /**************************/ /* start of main function */ /**************************/ -int main(argc, argv) -int argc; -char *argv[]; -{ - FILE* ifp; - time_t timenow; - int argn, rows, cols, format, i = 0, j = 0; - pixel *srcrow, *destrow; - pixel *pP = NULL, *pP2 = NULL; - pixval maxval; - int shift, nowshift; - const char * const usage = "shift [ppmfile]\n shift: maximum number of pixels to shift a line by\n"; - - /* parse in 'default' parameters */ - ppm_init(&argc, argv); - - argn = 1; - - /* parse in shift number */ - if (argn == argc) - pm_usage(usage); - if (sscanf(argv[argn], "%d", &shift) != 1) - pm_usage(usage); - if (shift < 0) - pm_error("shift factor must be 0 or more"); - ++argn; - - /* parse in filename (if present, stdin otherwise) */ - if (argn != argc) - { - ifp = pm_openr(argv[argn]); - ++argn; - } - else - ifp = stdin; - - if (argn != argc) - pm_usage(usage); - - /* read first data from file */ - ppm_readppminit(ifp, &cols, &rows, &maxval, &format); - - if (shift > cols) +int +main(int argc, + char * argv[]) { + + FILE * ifP; + unsigned int row; + int argn, rows, cols, format; + pixel * srcrow; + pixel * destrow; + pixval maxval; + int shift, nowshift; + int shiftArg; + + const char * const usage = "shift [ppmfile]\n shift: maximum number of pixels to shift a line by\n"; + + /* parse in 'default' parameters */ + ppm_init(&argc, argv); + + argn = 1; + + /* parse in shift number */ + if (argn == argc) + pm_usage(usage); + if (sscanf(argv[argn], "%d", &shiftArg) != 1) + pm_usage(usage); + if (shiftArg < 0) + pm_error("shift factor must be 0 or more"); + ++argn; + + /* parse in filename (if present, stdin otherwise) */ + if (argn != argc) { - shift = cols; - pm_message("shift amount is larger than picture width - reset to %d", shift); + ifP = pm_openr(argv[argn]); + ++argn; } + else + ifP = stdin; + + if (argn != argc) + pm_usage(usage); + + /* read first data from file */ + ppm_readppminit(ifP, &cols, &rows, &maxval, &format); + + if (shiftArg > cols) { + shift = cols; + pm_message("shift amount is larger than picture width - reset to %d", + shift); + } else + shift = shiftArg; - /* no error checking required here, ppmlib does it all for us */ - srcrow = ppm_allocrow(cols); + srcrow = ppm_allocrow(cols); - /* allocate a row of pixel data for the new pixels */ - destrow = ppm_allocrow(cols); + destrow = ppm_allocrow(cols); - ppm_writeppminit(stdout, cols, rows, maxval, 0); + ppm_writeppminit(stdout, cols, rows, maxval, 0); - /* get time of day to feed the random number generator */ - timenow = time(NULL); - srand(timenow); + srand(pm_randseed()); - /** now do the shifting **/ - /* the range by which a line is shifted lays in the range from */ - /* -shift/2 .. +shift/2 pixels; however, within this range it is */ + /** now do the shifting **/ + /* the range by which a line is shifted lays in the range from */ + /* -shift/2 .. +shift/2 pixels; however, within this range it is */ /* randomly chosen */ - for (i = 0; i < rows; i++) - { - if (shift != 0) - nowshift = (rand() % (shift+1)) - ((shift+1) / 2); - else - nowshift = 0; - - ppm_readppmrow(ifp, srcrow, cols, maxval, format); - - pP = srcrow; - pP2 = destrow; - - /* if the shift value is less than zero, we take the original pixel line and */ - /* copy it into the destination line translated to the left by x pixels. The */ - /* empty pixels on the right end of the destination line are filled up with */ - /* the pixel that is the right-most in the original pixel line. */ - if (nowshift < 0) - { - pP+= abs(nowshift); - for (j = 0; j < cols; j++) - { - PPM_ASSIGN(*pP2, PPM_GETR(*pP), PPM_GETG(*pP), PPM_GETB(*pP)); - pP2++; - if (j < (cols+nowshift)-1) - pP++; - } - } - /* if the shift value is 0 or positive, the first pixels of the */ - /* destination line are filled with the first pixel from the source line, */ - /* and the rest of the source line is copied to the dest line */ - else - { - for (j = 0; j < cols; j++) - { - PPM_ASSIGN(*pP2, PPM_GETR(*pP), PPM_GETG(*pP), PPM_GETB(*pP)); - pP2++; - if (j >= nowshift) - pP++; - } - } - - /* write out one line of graphic data */ - ppm_writeppmrow(stdout, destrow, cols, maxval, 0); - } - - pm_close(ifp); - ppm_freerow(srcrow); - ppm_freerow(destrow); - - exit(0); -} + for (row = 0; row < rows; ++row) { + pixel * pP; + pixel * pP2; + + if (shift != 0) + nowshift = (rand() % (shift+1)) - ((shift+1) / 2); + else + nowshift = 0; + + ppm_readppmrow(ifP, srcrow, cols, maxval, format); + + pP = &srcrow[0]; + pP2 = &destrow[0]; + + /* if the shift value is less than zero, we take the original + pixel line and copy it into the destination line translated + to the left by x pixels. The empty pixels on the right end + of the destination line are filled up with the pixel that + is the right-most in the original pixel line. + */ + if (nowshift < 0) { + unsigned int col; + pP += abs(nowshift); + for (col = 0; col < cols; ++col) { + PPM_ASSIGN(*pP2, PPM_GETR(*pP), PPM_GETG(*pP), PPM_GETB(*pP)); + ++pP2; + if (col < (cols + nowshift) - 1) + ++pP; + } + } else { + unsigned int col; + /* The shift value is 0 or positive, so fill the first + pixels of the destination line with the + first pixel from the source line, and copy the rest of + the source line to the dest line + */ + for (col = 0; col < cols; ++col) { + PPM_ASSIGN(*pP2, PPM_GETR(*pP), PPM_GETG(*pP), PPM_GETB(*pP)); + ++pP2; + if (col >= nowshift) + ++pP; + } + } + + ppm_writeppmrow(stdout, destrow, cols, maxval, 0); + } + pm_close(ifP); + ppm_freerow(srcrow); + ppm_freerow(destrow); + + return 0; +} diff --git a/editor/ppmspread.c b/editor/ppmspread.c index 569d1266..6753f4fe 100644 --- a/editor/ppmspread.c +++ b/editor/ppmspread.c @@ -9,119 +9,109 @@ /*********************************************************************/ #include + #include "ppm.h" -/* global variables */ -#ifdef AMIGA -static char *version = "$VER: ppmspread 1.1 (16.11.93)"; /* Amiga version identification */ -#endif - -/**************************/ -/* start of main function */ -/**************************/ -int main(argc, argv) -int argc; -char *argv[]; -{ - FILE* ifp; - int argn, rows, cols, i, j; - int xdis, ydis, xnew, ynew; - pixel **destarray, **srcarray; - pixel *pP, *pP2; - pixval maxval; - pixval r1, g1, b1; - int amount; - time_t timenow; - const char * const usage = "amount [ppmfile]\n amount: # of pixels to displace a pixel by at most\n"; - - /* parse in 'default' parameters */ - ppm_init(&argc, argv); - - argn = 1; - - /* parse in amount & seed */ - if (argn == argc) - pm_usage(usage); - if (sscanf(argv[argn], "%d", &amount) != 1) - pm_usage(usage); - if (amount < 0) - pm_error("amount should be a positive number"); - ++argn; - - /* parse in filename (if present, stdin otherwise) */ - if (argn != argc) - { - ifp = pm_openr(argv[argn]); - ++argn; - } - else - ifp = stdin; - - if (argn != argc) - pm_usage(usage); - - /* read entire picture into buffer */ - srcarray = ppm_readppm(ifp, &cols, &rows, &maxval); - - /* allocate an entire picture buffer for dest picture */ - destarray = ppm_allocarray(cols, rows); - - /* clear out the buffer */ - for (i=0; i < rows; i++) - memset(destarray[i], 0, cols * sizeof(pixel)); - - /* set seed for random number generator */ - /* get time of day to feed the random number generator */ - timenow = time(NULL); - srand(timenow); - - /* start displacing pixels */ - for (i = 0; i < rows; i++) - { - pP = srcarray[i]; - - for (j = 0; j < cols; j++) - { - xdis = (rand() % (amount+1)) - ((amount+1) / 2); - ydis = (rand() % (amount+1)) - ((amount+1) / 2); - - xnew = j + xdis; - ynew = i + ydis; - - /* only set the displaced pixel if it's within the bounds of the image */ - if (xnew >= 0 && xnew < cols && ynew >= 0 && ynew < rows) - { - /* displacing a pixel is accomplished by swapping it with another */ - /* pixel in its vicinity - so, first store other pixel's RGB */ - pP2 = srcarray[ynew] + xnew; - r1 = PPM_GETR(*pP2); - g1 = PPM_GETG(*pP2); - b1 = PPM_GETB(*pP2); - /* set second pixel to new value */ - pP2 = destarray[ynew] + xnew; - PPM_ASSIGN(*pP2, PPM_GETR(*pP), PPM_GETG(*pP), PPM_GETB(*pP)); - - /* now, set first pixel to (old) value of second */ - pP2 = destarray[i] + j; - PPM_ASSIGN(*pP2, r1, g1, b1); - } - else - { - /* displaced pixel is out of bounds; leave the old pixel there */ - pP2 = destarray[i] + j; - PPM_ASSIGN(*pP2, PPM_GETR(*pP), PPM_GETG(*pP), PPM_GETB(*pP)); - } - pP++; - } - } - - /* write out entire dest picture in one go */ - ppm_writeppm(stdout, destarray, cols, rows, maxval, 0); - - pm_close(ifp); - ppm_freearray(srcarray, rows); - ppm_freearray(destarray, rows); - - exit(0); -} + +int +main(int argc, + char * argv[]) { + + FILE * ifP; + int argn, rows, cols; + unsigned int row; + pixel ** destarray, ** srcarray; + pixel * pP; + pixel * pP2; + pixval maxval; + pixval r1, g1, b1; + int amount; + const char * const usage = "amount [ppmfile]\n amount: # of pixels to displace a pixel by at most\n"; + + /* parse in 'default' parameters */ + ppm_init(&argc, argv); + + argn = 1; + + /* parse in amount & seed */ + if (argn == argc) + pm_usage(usage); + if (sscanf(argv[argn], "%d", &amount) != 1) + pm_usage(usage); + if (amount < 0) + pm_error("amount should be a positive number"); + ++argn; + + /* parse in filename (if present, stdin otherwise) */ + if (argn != argc) + { + ifP = pm_openr(argv[argn]); + ++argn; + } + else + ifP = stdin; + + if (argn != argc) + pm_usage(usage); + + srcarray = ppm_readppm(ifP, &cols, &rows, &maxval); + + destarray = ppm_allocarray(cols, rows); + + /* clear out the buffer */ + for (row = 0; row < rows; ++row) + memset(destarray[row], 0, cols * sizeof(pixel)); + + srand(pm_randseed()); + + /* start displacing pixels */ + for (row = 0; row < rows; ++row) { + unsigned int col; + pP = &srcarray[row][0]; + + for (col = 0; col < cols; ++col) { + int const xdis = (rand() % (amount+1)) - ((amount+1) / 2); + int const ydis = (rand() % (amount+1)) - ((amount+1) / 2); + + int const xnew = col + xdis; + int const ynew = row + ydis; + + /* only set the displaced pixel if it's within the bounds + of the image + */ + if (xnew >= 0 && xnew < cols && ynew >= 0 && ynew < rows) { + /* displacing a pixel is accomplished by swapping it + with another pixel in its vicinity - so, first + store other pixel's RGB + */ + pP2 = &srcarray[ynew][xnew]; + r1 = PPM_GETR(*pP2); + g1 = PPM_GETG(*pP2); + b1 = PPM_GETB(*pP2); + /* set second pixel to new value */ + pP2 = &destarray[ynew][xnew]; + PPM_ASSIGN(*pP2, PPM_GETR(*pP), PPM_GETG(*pP), PPM_GETB(*pP)); + + /* now, set first pixel to (old) value of second */ + pP2 = &destarray[row][col]; + PPM_ASSIGN(*pP2, r1, g1, b1); + } else { + /* displaced pixel is out of bounds; leave the old + pixel there + */ + pP2 = &destarray[row][col]; + PPM_ASSIGN(*pP2, PPM_GETR(*pP), PPM_GETG(*pP), PPM_GETB(*pP)); + } + ++pP; + } + } + + ppm_writeppm(stdout, destarray, cols, rows, maxval, 0); + + pm_close(ifP); + ppm_freearray(srcarray, rows); + ppm_freearray(destarray, rows); + + return 0; +} diff --git a/generator/pbmtextps.c b/generator/pbmtextps.c index ef8ae008..236427ea 100644 --- a/generator/pbmtextps.c +++ b/generator/pbmtextps.c @@ -17,13 +17,15 @@ */ #define _XOPEN_SOURCE /* Make sure popen() is in stdio.h */ #define _BSD_SOURCE /* Make sure stdrup() is in string.h */ +#include #include #include #include #include -#include "pbm.h" + #include "nstring.h" #include "shhopt.h" +#include "pbm.h" #define BUFFER_SIZE 2048 @@ -233,7 +235,7 @@ static void writeProgram(const char * const psFname, struct cmdlineInfo const cmdline) { - const char *ps; + const char * ps; FILE * psfile; psfile = fopen(psFname, "w"); diff --git a/generator/pgmcrater.c b/generator/pgmcrater.c index 1833e604..ec592381 100644 --- a/generator/pgmcrater.c +++ b/generator/pgmcrater.c @@ -106,11 +106,10 @@ static int modulo(int t, int n) static void initseed() { - int i; + unsigned int i; - i = time(NULL) * 0xF37C; - srand(i); - for (i = 0; i < 7; i++) + srand(pm_randseed()); + for (i = 0; i < 7; ++i) V rand(); } diff --git a/generator/pgmnoise.c b/generator/pgmnoise.c index 3929759b..643f260f 100644 --- a/generator/pgmnoise.c +++ b/generator/pgmnoise.c @@ -11,67 +11,56 @@ #include "pgm.h" -/* global variables */ -#ifdef AMIGA -static char *version = "$VER: pgmnoise 1.1 (16.11.93)"; /* Amiga version identification */ -#endif - -/**************************/ -/* start of main function */ -/**************************/ -int main(argc, argv) -int argc; -char *argv[]; -{ - int argn, rows, cols, i, j; - gray *destrow; - const char * const usage = "width height\n width and height are picture dimensions in pixels\n"; - time_t timenow; - - /* parse in 'default' parameters */ - pgm_init(&argc, argv); - - argn = 1; - - /* parse in dim factor */ - if (argn == argc) - pm_usage(usage); - if (sscanf(argv[argn], "%d", &cols) != 1) - pm_usage(usage); - argn++; - if (argn == argc) - pm_usage(usage); - if (sscanf(argv[argn], "%d", &rows) != 1) - pm_usage(usage); - - if (cols <= 0 || rows <= 0) - pm_error("picture dimensions should be positive numbers"); - ++argn; - - if (argn != argc) - pm_usage(usage); - - /* no error checking required here, ppmlib does it all for us */ - destrow = pgm_allocrow(cols); - - pgm_writepgminit(stdout, cols, rows, PGM_MAXMAXVAL, 0); - - /* get time of day to feed the random number generator */ - timenow = time(NULL); - srand(timenow); - - /* create the (gray) noise */ - for (i = 0; i < rows; i++) - { - for (j = 0; j < cols; j++) - destrow[j] = rand() % PGM_MAXMAXVAL; - - /* write out one line of graphic data */ - pgm_writepgmrow(stdout, destrow, cols, PGM_MAXMAXVAL, 0); - } - - pgm_freerow(destrow); - - exit(0); -} +int main(int argc, + char * argv[]) { + + int argn, rows, cols; + unsigned int row; + gray * destrow; + + const char * const usage = "width height\n width and height are picture dimensions in pixels\n"; + + /* parse in 'default' parameters */ + pgm_init(&argc, argv); + + argn = 1; + + /* parse in dim factor */ + if (argn == argc) + pm_usage(usage); + if (sscanf(argv[argn], "%d", &cols) != 1) + pm_usage(usage); + argn++; + if (argn == argc) + pm_usage(usage); + if (sscanf(argv[argn], "%d", &rows) != 1) + pm_usage(usage); + + if (cols <= 0 || rows <= 0) + pm_error("picture dimensions should be positive numbers"); + ++argn; + + if (argn != argc) + pm_usage(usage); + + destrow = pgm_allocrow(cols); + + pgm_writepgminit(stdout, cols, rows, PGM_MAXMAXVAL, 0); + + srand(pm_randseed()); + + /* create the (gray) noise */ + + for (row = 0; row < rows; ++row) { + unsigned int col; + for (col = 0; col < cols; ++col) + destrow[col] = rand() % PGM_MAXMAXVAL; + + pgm_writepgmrow(stdout, destrow, cols, PGM_MAXMAXVAL, 0); + } + + pgm_freerow(destrow); + + return 0; +} diff --git a/generator/ppmforge.c b/generator/ppmforge.c index 64b1ad79..80e35822 100644 --- a/generator/ppmforge.c +++ b/generator/ppmforge.c @@ -282,10 +282,9 @@ static unsigned int initseed(void) { /* Generate initial random seed. */ - int i; + unsigned int i; - i = time(NULL) ^ 0xF37C; - srand(i); + srand(pm_randseed()); for (i = 0; i < 7; ++i) rand(); return rand(); diff --git a/generator/ppmpat.c b/generator/ppmpat.c index 343100d5..7650bd01 100644 --- a/generator/ppmpat.c +++ b/generator/ppmpat.c @@ -1006,7 +1006,7 @@ main(int argc, char ** argv) { if ( argn != argc ) pm_usage( usage); - srand( (int) ( time( 0 ) ^ getpid( ) ) ); + srand(pm_randseed()); pixels = ppm_allocarray( cols, rows ); switch ( pattern ) diff --git a/lib/libpm.c b/lib/libpm.c index df59e6c4..f36b7a50 100644 --- a/lib/libpm.c +++ b/lib/libpm.c @@ -35,7 +35,9 @@ #define _LARGE_FILE_API /* This makes the the x64() functions available on AIX */ +#include #include +#include #include #include #include @@ -43,6 +45,7 @@ #ifdef __DJGPP__ #include #endif +#include #include "pm_c_util.h" #include "version.h" @@ -782,6 +785,15 @@ pm_arg0toprogname(const char arg0[]) { +unsigned int +pm_randseed(void) { + + return time(NULL) ^ getpid(); + +} + + + /* File open/close that handles "-" as stdin/stdout and checks errors. */ FILE* @@ -986,7 +998,7 @@ pm_make_tmpfile(FILE ** const filePP, const char * dirseparator; const char * error; - fnamelen = strlen (pm_progname) + 10; /* "/" + "_XXXXXX\0" */ + fnamelen = strlen(pm_progname) + 10; /* "/" + "_XXXXXX\0" */ tmpdir = tmpDir(); diff --git a/lib/libppmfloyd.c b/lib/libppmfloyd.c index 071c3c36..ec6256ff 100644 --- a/lib/libppmfloyd.c +++ b/lib/libppmfloyd.c @@ -85,35 +85,36 @@ allocateFi(int const cols) { ppm_fs_info * -ppm_fs_init(int cols, pixval maxval, int flags) { +ppm_fs_init(unsigned int const cols, + pixval const maxval, + unsigned int const flags) { - ppm_fs_info *fi; + ppm_fs_info * fiP; - fi = allocateFi(cols); + fiP = allocateFi(cols); - fi->lefttoright = 1; - fi->cols = cols; - fi->maxval = maxval; - fi->flags = flags; - - if( flags & FS_RANDOMINIT ) { + fiP->lefttoright = 1; + fiP->cols = cols; + fiP->maxval = maxval; + fiP->flags = flags; + + if (flags & FS_RANDOMINIT) { unsigned int i; - srand((int)(time(0) ^ getpid())); - for( i = 0; i < cols +2; i++ ) { + srand(pm_randseed()); + for (i = 0; i < cols +2; ++i) { /* random errors in [-1..+1] */ - fi->thisrederr[i] = rand() % 32 - 16; - fi->thisgreenerr[i] = rand() % 32 - 16; - fi->thisblueerr[i] = rand() % 32 - 16; + fiP->thisrederr[i] = rand() % 32 - 16; + fiP->thisgreenerr[i] = rand() % 32 - 16; + fiP->thisblueerr[i] = rand() % 32 - 16; } - } - else { + } else { unsigned int i; - for( i = 0; i < cols + 2; i++ ) - fi->thisrederr[i] = fi->thisgreenerr[i] = - fi->thisblueerr[i] = 0; + for (i = 0; i < cols + 2; ++i) + fiP->thisrederr[i] = fiP->thisgreenerr[i] = + fiP->thisblueerr[i] = 0; } - return fi; + return fiP; } diff --git a/lib/pm.h b/lib/pm.h index 3850943c..8265c9ea 100644 --- a/lib/pm.h +++ b/lib/pm.h @@ -348,6 +348,9 @@ pm_check(FILE * const file, char * pm_arg0toprogname(const char arg0[]); +unsigned int +pm_randseed(void); + #ifdef __cplusplus } #endif diff --git a/lib/ppmfloyd.h b/lib/ppmfloyd.h index e16ad651..264fc0b6 100644 --- a/lib/ppmfloyd.h +++ b/lib/ppmfloyd.h @@ -15,17 +15,17 @@ struct ppm_fs_info { /* thisXerr and nextXerr are dynamically allocated arrays each of whose dimension is the width of the image plus 2 */ - long *thisrederr; - long *thisgreenerr; - long *thisblueerr; - long *nextrederr; - long *nextgreenerr; - long *nextblueerr; + long * thisrederr; + long * thisgreenerr; + long * thisblueerr; + long * nextrederr; + long * nextgreenerr; + long * nextblueerr; int lefttoright; int cols; pixval maxval; int flags; - pixel *pixrow; + pixel * pixrow; int col_end; pixval red, green, blue; }; @@ -37,7 +37,9 @@ typedef struct ppm_fs_info ppm_fs_info; #define FS_ALTERNATE 0x02 ppm_fs_info * -ppm_fs_init(int cols, pixval maxval, int flags); +ppm_fs_init(unsigned int const cols, + pixval const maxval, + unsigned int const flags); void ppm_fs_free(ppm_fs_info *fi); diff --git a/pm_config.in.h b/pm_config.in.h index 1956f5d3..41546c52 100644 --- a/pm_config.in.h +++ b/pm_config.in.h @@ -119,33 +119,6 @@ extern int rand(); typedef uint32_t uint32n; typedef int32_t int32n; -#include -#include -#include -#include -/* - Before Netpbm 9.0, atoi() and exit() were declared for everybody - except MSDOS and Amiga, and time() and write() were declared for - everybody except MSDOS, Amiga, and __osf__. fcntl.h, time.h, and - stlib.h were included for MSDOS and Amiga, and unistd.h was included - for everyone except VMS, MSDOS, and Amiga. With the netbsd patches, - atoi(), exit(), time(), and write() were not declared for __NetBSD__. - - We're hoping that all current systems have the standard header - files, and will reinstate some of these explicit declarations if we - hear otherwise. - - If it turns out to be this easy, we should just move these inclusions - to the source files that actually need them. - - -Bryan 2000.04.13 - -extern int atoi(); -extern void exit(); -extern long time(); -extern int write(); -*/ - /* CONFIGURE: On most BSD systems, malloc() gets declared in stdlib.h, on ** system V, it gets declared in malloc.h. On some systems, malloc.h ** doesn't declare these, so we have to do it here. On other systems, @@ -263,6 +236,7 @@ extern int write(); # endif #endif +#include /* In GNU, _LFS_LARGEFILE means the "off_t" functions (ftello, etc.) are available. In AIX, _AIXVERSION_430 means it's AIX Version 4.3.0 or better, which seems to mean the "off_t" functions are available. -- cgit 1.4.1