about summary refs log tree commit diff
path: root/converter/pgm/pgmtopgm.c
blob: 250bb4dc69f5a4e6dc7aea96f4fb3d52e385eb1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*----------------------------------------------------------------------------
                               pgmtopgm
------------------------------------------------------------------------------
  Part of the Netpbm package.

  Copy PGM image from Standard Input to Standard Output


  By Bryan Henderson, San Jose CA 2002.09.07

  Contributed to the public domain by its author 2002.09.07
-----------------------------------------------------------------------------*/

#include "pgm.h"

int
main(int argc, char *argv[]) {
    int format;
    int rows, cols;
    gray maxval;
    int row;
    gray * grayrow;
    
    pgm_init(&argc, argv);
    
    if (argc-1 != 0)
        pm_error("Program takes no arguments.  Input is from Standard Input");

    pgm_readpgminit(stdin, &cols, &rows, &maxval, &format);

    pgm_writepgminit(stdout, cols, rows, maxval, 0);

    grayrow = pgm_allocrow(cols);

    for (row = 0; row < rows; ++row) {
        pgm_readpgmrow(stdin, grayrow, cols, maxval, format);
        pgm_writepgmrow(stdout, grayrow, cols, maxval, 0);
    }
    pgm_freerow(grayrow);

    pm_close(stdin);

    return 0;
}