2
* program pgmtoepm - convert any number of Portable GrayMap to
3
* Extented Pixmap Format epm
5
* (C) by Oliver Vogel (e-mail: vogel@ikp.uni-koeln.de)
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public Licence as by published
10
* by the Free Software Foundation; either version 2; or (at your option)
13
* This program is distributed in the hope that it will entertaining,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILTY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16
* Public License for more details.
18
* $Id: pgmtoepm.c,v 1.1 1999/04/04 11:48:24 xblast Exp $
19
* $Log: pgmtoepm.c,v $
20
* Revision 1.1 1999/04/04 11:48:24 xblast
39
static char magic[256];
40
int width, height, maxval;
41
int d_width, d_height, d_maxval;
47
/* check command line args */
49
fprintf(stderr, "usage: %s pgmfile [...]\n", argv[0]);
53
for (i=1; i<argc; i++) {
54
/* open first pgm file */
55
if (NULL == (fp = fopen(argv[i],"r") ) ) {
56
fprintf(stderr, "%s: failed to open file \"%s\"\n", argv[0], argv[i]);
60
fscanf(fp, "%s %d %d %d%c", magic, &width, &height, &maxval, &dummy);
61
/* compare magic word */
62
if (0 != strcmp("P5",magic)) {
63
fprintf(stderr, "%s: wrong magic word in file \"%s\"\n", argv[0], argv[i]);
67
/* set default values */
71
n_data = d_width * d_height;
72
/* alloc data buffer */
73
if (NULL == (buf = malloc(n_data*sizeof(char) ) ) ) {
74
fprintf(stderr, "%s: failed to alloc data buffer\n", argv[0]);
79
printf("%d %d %d %d\n", d_width, d_height, d_maxval, argc-1);
81
/* compare with default values */
82
if ( (d_height != height) || (d_width != width) || (d_maxval != maxval) ) {
83
fprintf(stderr, "%s: wrong image dimensions for file \"%s\"\n",
89
if (n_data != fread(buf, sizeof(char), n_data, fp) ) {
90
fprintf(stderr, "%s: premature end of file \"%s\"\n", argv[0], argv[1]);
93
fwrite (buf, sizeof(char), n_data, stdout);