Debian Codegraph @

converter/pgm/pgmtopgm.c

raw
1 /*----------------------------------------------------------------------------
2 pgmtopgm
3 ------------------------------------------------------------------------------
4 Part of the Netpbm package.
5
6 Copy PGM image from Standard Input to Standard Output
7
8
9 By Bryan Henderson, San Jose CA 2002.09.07
10
11 Contributed to the public domain by its author 2002.09.07
12 -----------------------------------------------------------------------------*/
13
14 #include "pgm.h"
15
16 int
17 main(int argc, char *argv[]) {
18 int format;
19 int rows, cols;
20 gray maxval;
21 int row;
22 gray * grayrow;
23
24 pgm_init(&argc, argv);
25
26 if (argc-1 != 0)
27 pm_error("Program takes no arguments. Input is from Standard Input");
28
29 pgm_readpgminit(stdin, &cols, &rows, &maxval, &format);
30
31 pgm_writepgminit(stdout, cols, rows, maxval, 0);
32
33 grayrow = pgm_allocrow(cols);
34
35 for (row = 0; row < rows; ++row) {
36 pgm_readpgmrow(stdin, grayrow, cols, maxval, format);
37 pgm_writepgmrow(stdout, grayrow, cols, maxval, 0);
38 }
39 pgm_freerow(grayrow);
40
41 pm_close(stdin);
42
43 return 0;
44 }
45
46
47