Re: reading and writing pgm files [message #3988] |
Tue, 11 April 1995 00:00 |
johnl
Messages: 1 Registered: April 1995
|
Junior Member |
|
|
I tried to mail a reply but your posting software didn't
include your mail address.
Greening C M (greec) wrote:
: Does anyone have, or know where to get hold of, code to read and
: write .pgm format image files?.
It is very simple, you really don't need much code.
I assume that you want to read/write PGM files from your
application program. Here are some bits of code I used to
create/write PGM files in one of my programs. The image
is a lineSize*1014 array of 8 bit values. I used the manual
pages from the PBM software to get the file format
specification.
/* open PGM output file */
sprintf(ofName, "SNDR%.4d.PGM", serial);
if ((pgmFile = fopen(ofName, "wb")) == NULL) {
fprintf(stderr, "%s: can't open %s\n", pName, ofName);
exit(1);
}
fprintf(pgmFile, "P5 %d %d %d\n", lineSize, 1014, 255);
/* note: repeated 1014 times to output experiment video */
/* write PGM data */
for (j = 0; j < lineSize; ++j)
putc(255 - lineBuf[j], pgmFile);
/* close PGM file */
fclose(pgmFile);
|
|
|
|