static void convertRaster(FILE * const ifP, unsigned int const cols, unsigned int const rows, pixval const maxval, int const format, pixel * const inputRow, gray * const outputRow, FILE * const ofP) { unsigned int row; for (row = 0; row < rows; ++row) { ppm_readppmrow( ifP, inputRow, cols, maxval, format ); if (maxval <= 255) { /* Use fast approximation to 0.299 r + 0.587 g + 0.114 b */ unsigned int col; for (col = 0; col < cols; ++col) outputRow[col] = (gray) ppm_fastlumin(inputRow[col]); } else { /* Can't use fast approximation, so fall back on floats. */ unsigned int col; for (col = 0; col < cols; ++col) outputRow[col] = ppm_luminosity(inputRow[col]); } pgm_writepgmrow(ofP, outputRow, cols, maxval, 0); } }
static void computeGrayscaleRow(const pixel * const inputRow, gray * const outputRow, pixval const maxval, unsigned int const cols) { if (maxval <= 255) { unsigned int col; /* Use fast approximation to 0.299 r + 0.587 g + 0.114 b. */ for (col = 0; col < cols; ++col) outputRow[col] = ppm_fastlumin(inputRow[col]); } else { unsigned int col; /* Can't use fast approximation, so fall back on floats. */ for (col = 0; col < cols; ++col) outputRow[col] = PPM_LUMIN(inputRow[col]) + 0.5; } }