diff options
Diffstat (limited to 'converter/other')
-rw-r--r-- | converter/other/pamtopnm.c | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/converter/other/pamtopnm.c b/converter/other/pamtopnm.c index cc1164da..6835b43f 100644 --- a/converter/other/pamtopnm.c +++ b/converter/other/pamtopnm.c @@ -108,6 +108,7 @@ main(int argc, char *argv[]) { struct cmdlineInfo cmdline; FILE* ifP; + bool eof; /* no more images in input stream */ struct pam inpam; /* Input PAM image */ struct pam outpam; /* Output PNM image */ @@ -117,39 +118,45 @@ main(int argc, char *argv[]) { ifP = pm_openr(cmdline.inputFilespec); - pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); + eof = FALSE; + while (!eof) { + pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); - validateTupleType(inpam, cmdline.assume); + validateTupleType(inpam, cmdline.assume); - outpam = inpam; - outpam.file = stdout; - - if (inpam.depth < 3) { - outpam.depth = 1; - if (inpam.maxval == 1) - outpam.format = PBM_FORMAT; - else - outpam.format = PGM_FORMAT; - } else { - outpam.depth = 3; - outpam.format = PPM_FORMAT; - } + outpam = inpam; + outpam.file = stdout; + + if (inpam.depth < 3) { + outpam.depth = 1; + if (inpam.maxval == 1) + outpam.format = PBM_FORMAT; + else + outpam.format = PGM_FORMAT; + } else { + outpam.depth = 3; + outpam.format = PPM_FORMAT; + } - pnm_writepaminit(&outpam); + pnm_writepaminit(&outpam); - { - tuple *tuplerow; - - tuplerow = pnm_allocpamrow(&inpam); - { - int row; + { + tuple *tuplerow; - for (row = 0; row < inpam.height; row++) { - pnm_readpamrow(&inpam, tuplerow); - pnm_writepamrow(&outpam, tuplerow); + tuplerow = pnm_allocpamrow(&inpam); + { + int row; + + for (row = 0; row < inpam.height; row++) { + pnm_readpamrow(&inpam, tuplerow); + pnm_writepamrow(&outpam, tuplerow); + } } + pnm_freepamrow(tuplerow); } - pnm_freepamrow(tuplerow); + + pnm_nextimage(ifP, &eof); } + return 0; } |