/*********************************************************************/ /* pnmflash - brighten a picture up to total whiteout */ /* Frank Neumann, August 1993 */ /* V1.5 27.11.1999 */ /* */ /* version history: */ /* V1.0 ~ 15.August 1993 first version */ /* V1.1 03.09.1993 uses ppm libs & header files */ /* V1.2 03.09.1993 integer arithmetics instead of float */ /* (gains about 50 % speed up) */ /* V1.3 11.10.1993 reads only one line at a time - this */ /* saves LOTS of memory on big picturs */ /* V1.4 16.11.1993 Rewritten to be NetPBM.programming con- */ /* forming */ /* V1.5 27.11.1999 Promoted from ppmflash to pnmflash. */ /*********************************************************************/ #include "pnm.h" /* global variables */ #ifdef AMIGA static char *version = "$VER: pnmflash 1.5 (27.11.99)"; #endif /**************************/ /* start of main function */ /**************************/ int main( int argc, char* argv[] ) { FILE* ifp; int argn, rows, cols, i, j, format, newformat; xel *srcrow, *destrow; xel *xP, *xP2; xelval maxval; double flashfactor; long longfactor; char* usage = "flashfactor [pnmfile]\n flashfactor: 0.0 = original picture, 1.0 = total whiteout\n"; /* parse in 'default' parameters */ pnm_init( &argc, argv ); argn = 1; /* parse in flash factor */ if (argn == argc) pm_usage(usage); if (sscanf(argv[argn], "%lf", &flashfactor) != 1) pm_usage(usage); if (flashfactor < 0.0 || flashfactor > 1.0) pm_error("flash factor must be in the range from 0.0 to 1.0 "); ++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 */ pnm_pbmmaxval = PNM_MAXMAXVAL; /* use larger value for better results */ pnm_readpnminit(ifp, &cols, &rows, &maxval, &format); /* no error checking required here, pnmlib does it all for us */ srcrow = pnm_allocrow(cols); /* Promote PBM files to PGM. */ if ( PNM_FORMAT_TYPE(format) == PBM_TYPE ) { newformat = PGM_TYPE; pm_message( "promoting to PGM" ); } else newformat = format; longfactor = (long)(flashfactor * 65536); /* allocate a row of xel data for the new xels */ destrow = pnm_allocrow(cols); pnm_writepnminit(stdout, cols, rows, maxval, newformat, 0); /** now do the flashing **/ /* the 'float' parameter for flashing is sort of faked - in fact, we */ /* convert it to a range from 0 to 65536 for integer math. Shouldn't */ /* be something you'll have to worry about, though. */ for (i = 0; i < rows; i++) { pnm_readpnmrow(ifp, srcrow, cols, maxval, format); xP = srcrow; xP2 = destrow; for (j = 0; j < cols; j++) { switch ( PNM_FORMAT_TYPE(newformat) ) { case PPM_TYPE: PPM_ASSIGN(*xP2, PPM_GETR(*xP) + (((maxval - PPM_GETR(*xP)) * longfactor) >> 16), PPM_GETG(*xP) + (((maxval - PPM_GETG(*xP)) * longfactor) >> 16), PPM_GETB(*xP) + (((maxval - PPM_GETB(*xP)) * longfactor) >> 16)); break; default: PNM_ASSIGN1(*xP2, PNM_GET1(*xP) + (((maxval - PNM_GET1(*xP)) * longfactor) >> 16)); break; } xP++; xP2++; } /* write out one line of graphic data */ pnm_writepnmrow(stdout, destrow, cols, maxval, newformat, 0); } pm_closer(ifp); pnm_freerow(srcrow); pnm_freerow(destrow); exit(0); }