| 1 |
/* pgmbentley.c - read a portable graymap and smear it according to brightness |
| 2 |
** |
| 3 |
** Copyright (C) 1990 by Wilson Bent ([email protected]) |
| 4 |
** |
| 5 |
** Permission to use, copy, modify, and distribute this software and its |
| 6 |
** documentation for any purpose and without fee is hereby granted, provided |
| 7 |
** that the above copyright notice appear in all copies and that both that |
| 8 |
** copyright notice and this permission notice appear in supporting |
| 9 |
** documentation. This software is provided "as is" without express or |
| 10 |
** implied warranty. |
| 11 |
*/ |
| 12 |
|
| 13 |
#include <stdio.h> |
| 14 |
|
| 15 |
#include "pm_c_util.h" |
| 16 |
#include "pgm.h" |
| 17 |
|
| 18 |
|
| 19 |
static unsigned int const N = 4; |
| 20 |
|
| 21 |
|
| 22 |
int |
| 23 |
main(int argc, const char * argv[]) { |
| 24 |
|
| 25 |
FILE * ifP; |
| 26 |
int rows, cols; |
| 27 |
gray maxval; |
| 28 |
gray ** gin; |
| 29 |
gray ** gout; |
| 30 |
unsigned int row; |
| 31 |
const char * inputFileName; |
| 32 |
|
| 33 |
pm_proginit(&argc, argv); |
| 34 |
|
| 35 |
if (argc-1 < 1) |
| 36 |
inputFileName = "-"; |
| 37 |
else { |
| 38 |
inputFileName = argv[1]; |
| 39 |
|
| 40 |
if (argc-1 > 1) |
| 41 |
pm_error("There are no options and only one argument. " |
| 42 |
"You specified %u", argc-1); |
| 43 |
} |
| 44 |
ifP = pm_openr(inputFileName); |
| 45 |
|
| 46 |
gin = pgm_readpgm(ifP, &cols, &rows, &maxval); |
| 47 |
|
| 48 |
pm_close(ifP); |
| 49 |
|
| 50 |
gout = pgm_allocarray(cols, rows); |
| 51 |
|
| 52 |
for (row = 0; row < rows; ++row) { |
| 53 |
unsigned int col; |
| 54 |
for (col = 0; col < cols; ++col) |
| 55 |
gout[row][col] = 0; |
| 56 |
} |
| 57 |
|
| 58 |
for (row = 0; row < rows; ++row) { |
| 59 |
unsigned int col; |
| 60 |
|
| 61 |
for (col = 0; col < cols; ++col) { |
| 62 |
unsigned int const brow = MIN(rows-1, row + gin[row][col] / N); |
| 63 |
|
| 64 |
gout[brow][col] = gin[row][col]; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
pgm_writepgm(stdout, gout, cols, rows, maxval, 0); |
| 69 |
|
| 70 |
pm_close(stdout); |
| 71 |
pgm_freearray(gout, rows); |
| 72 |
|
| 73 |
return 0; |
| 74 |
} |