*** pnmscale.c.orig Sat Aug 19 12:12:28 2006 --- pnmscale.c Fri Feb 2 23:54:56 2024 *************** *** 18,23 **** --- 18,24 ---- */ + #define DOUBL double #include #include *************** *** 227,240 **** *newcolsP = cols; } else { const double scale = ! sqrt( (float) cmdline.pixels / ((float) cols * (float) rows)); *newrowsP = rows * scale; *newcolsP = cols * scale; } } else if (cmdline.xbox) { ! const double aspect_ratio = (float) cols / (float) rows; const double box_aspect_ratio = ! (float) cmdline.xbox / (float) cmdline.ybox; if (box_aspect_ratio > aspect_ratio) { *newrowsP = cmdline.ybox; --- 228,241 ---- *newcolsP = cols; } else { const double scale = ! sqrt( (DOUBL) cmdline.pixels / ((DOUBL) cols * (DOUBL) rows)); *newrowsP = rows * scale; *newcolsP = cols * scale; } } else if (cmdline.xbox) { ! const double aspect_ratio = (DOUBL) cols / (DOUBL) rows; const double box_aspect_ratio = ! (DOUBL) cmdline.xbox / (DOUBL) cmdline.ybox; if (box_aspect_ratio > aspect_ratio) { *newrowsP = cmdline.ybox; *************** *** 249,255 **** else if (cmdline.xscale) *newcolsP = cmdline.xscale * cols + .5; else if (cmdline.ysize) ! *newcolsP = cols * ((float) cmdline.ysize/rows) +.5; else *newcolsP = cols; --- 250,256 ---- else if (cmdline.xscale) *newcolsP = cmdline.xscale * cols + .5; else if (cmdline.ysize) ! *newcolsP = cols * ((DOUBL) cmdline.ysize/rows) +.5; else *newcolsP = cols; *************** *** 258,264 **** else if (cmdline.yscale) *newrowsP = cmdline.yscale * rows +.5; else if (cmdline.xsize) ! *newrowsP = rows * ((float) cmdline.xsize/cols) +.5; else *newrowsP = rows; } --- 259,265 ---- else if (cmdline.yscale) *newrowsP = cmdline.yscale * rows +.5; else if (cmdline.xsize) ! *newrowsP = rows * ((DOUBL) cmdline.xsize/cols) +.5; else *newrowsP = rows; } *************** *** 278,284 **** static void horizontal_scale(const xel inputxelrow[], xel newxelrow[], ! const int cols, const int newcols, const float xscale, const int format, const xelval maxval, float * const stretchP) { /*---------------------------------------------------------------------------- --- 279,285 ---- static void horizontal_scale(const xel inputxelrow[], xel newxelrow[], ! const int cols, const int newcols, const DOUBL xscale, const int format, const xelval maxval, float * const stretchP) { /*---------------------------------------------------------------------------- *************** *** 289,296 **** 'format' and 'maxval' describe the Netpbm format of the both input and output rows. -----------------------------------------------------------------------------*/ ! float r, g, b; ! float fraccoltofill, fraccolleft; unsigned int col; unsigned int newcol; --- 290,297 ---- 'format' and 'maxval' describe the Netpbm format of the both input and output rows. -----------------------------------------------------------------------------*/ ! DOUBL r, g, b; ! DOUBL fraccoltofill, fraccolleft; unsigned int col; unsigned int newcol; *************** *** 342,347 **** --- 343,349 ---- r += fraccolleft * PPM_GETR(inputxelrow[col]); g += fraccolleft * PPM_GETG(inputxelrow[col]); b += fraccolleft * PPM_GETB(inputxelrow[col]); + b = (float)b; break; default: *************** *** 403,409 **** static void ! accumOutputRow(xel * const xelrow, float const fraction, float rs[], float gs[], float bs[], int const cols, int const format) { /*---------------------------------------------------------------------------- --- 405,411 ---- static void ! accumOutputRow(xel * const xelrow, DOUBL const fraction, float rs[], float gs[], float bs[], int const cols, int const format) { /*---------------------------------------------------------------------------- *************** *** 468,474 **** xelval const maxval, int const format, int const newcols, int const newrows, xelval const newmaxval, int const newformat, ! float const xscale, float const yscale, bool const verbose) { /*---------------------------------------------------------------------------- Scale the image on input file 'ifP' (which is described by --- 470,476 ---- xelval const maxval, int const format, int const newcols, int const newrows, xelval const newmaxval, int const newformat, ! DOUBL const xscale, DOUBL const yscale, bool const verbose) { /*---------------------------------------------------------------------------- Scale the image on input file 'ifP' (which is described by *************** *** 523,536 **** scaling */ xel* newxelrow; ! float rowsleft; /* The number of rows of output that need to be formed from the current input row (the one in xelrow[]), less the number that have already been formed (either in the rs/gs/bs accumulators or output to the file). This can be fractional because of the way we define rows as having height. */ ! float fracrowtofill; /* The fraction of the current output row (the one in vertScaledRow[]) that hasn't yet been filled in from an input row. */ --- 525,538 ---- scaling */ xel* newxelrow; ! DOUBL rowsleft; /* The number of rows of output that need to be formed from the current input row (the one in xelrow[]), less the number that have already been formed (either in the rs/gs/bs accumulators or output to the file). This can be fractional because of the way we define rows as having height. */ ! DOUBL fracrowtofill; /* The fraction of the current output row (the one in vertScaledRow[]) that hasn't yet been filled in from an input row. */ *************** *** 593,598 **** --- 595,601 ---- fracrowtofill = 0.0; } } + rowsleft = (float)rowsleft; makeRow(vertScaledRow, rs, gs, bs, cols, newmaxval, format); zeroAccum(cols, format, rs, gs, bs); fracrowtofill = 1.0; *************** *** 633,639 **** xelval const maxval, int const format, int const newcols, int const newrows, xelval const newmaxval, int const newformat, ! float const xscale, float const yscale) { /*---------------------------------------------------------------------------- Scale the image on input file 'ifP' (which is described by 'cols', 'rows', 'format', and 'maxval') by xscale horizontally and --- 636,642 ---- xelval const maxval, int const format, int const newcols, int const newrows, xelval const newmaxval, int const newformat, ! DOUBL const xscale, DOUBL const yscale) { /*---------------------------------------------------------------------------- Scale the image on input file 'ifP' (which is described by 'cols', 'rows', 'format', and 'maxval') by xscale horizontally and *************** *** 688,694 **** FILE* ifP; int rows, cols, format, newformat, newrows, newcols; xelval maxval, newmaxval; ! float xscale, yscale; pnm_init( &argc, argv ); --- 691,697 ---- FILE* ifP; int rows, cols, format, newformat, newrows, newcols; xelval maxval, newmaxval; ! DOUBL xscale, yscale; pnm_init( &argc, argv ); *************** *** 714,721 **** we will run out of input while (a fractional pixel of) output is unfilled -- which is easier for our algorithm to handle. */ ! xscale = (float) newcols / cols; ! yscale = (float) newrows / rows; if (cmdline.verbose) { pm_message("Scaling by %f horizontally to %d columns.", --- 717,724 ---- we will run out of input while (a fractional pixel of) output is unfilled -- which is easier for our algorithm to handle. */ ! xscale = (DOUBL) newcols / cols; ! yscale = (DOUBL) newrows / rows; if (cmdline.verbose) { pm_message("Scaling by %f horizontally to %d columns.",