about summary refs log tree commit diff
path: root/converter/ppm/ppmtoppm.c
blob: 3a48eacc9337fdf125b094f53d744ce0369d1525 (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
45
46
47
/*----------------------------------------------------------------------------
                               ppmtoppm
------------------------------------------------------------------------------
  Part of the Netpbm package.

  Copy PPM 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 "ppm.h"

int
main(int argc, char *argv[]) {
    int format;
    int rows, cols;
    pixval maxval;
    int row;
    pixel* pixelrow;

    ppm_init(&argc, argv);

    if (argc-1 != 0)
        pm_error("Program takes no arguments.  Input is from Standard Input");

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

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

    pixelrow = ppm_allocrow(cols);

    for (row = 0; row < rows; row++) {
        ppm_readppmrow(stdin, pixelrow, cols, maxval, format);
        ppm_writeppmrow(stdout, pixelrow, cols, maxval, 0);
    }
    ppm_freerow(pixelrow);

    pm_close(stdin);

    exit(0);
}