static void extractOneImage(FILE * const infileP, FILE * const outfileP) { struct pam inpam; struct pam outpam; enum pm_check_code checkRetval; unsigned int row; tuple * tuplerow; pnm_readpaminit(infileP, &inpam, PAM_STRUCT_SIZE(tuple_type)); pnm_checkpam(&inpam, PM_CHECK_BASIC, &checkRetval); outpam = inpam; outpam.file = outfileP; pnm_writepaminit(&outpam); tuplerow = pnm_allocpamrow(&inpam); for (row = 0; row < inpam.height; ++row) { pnm_readpamrow(&inpam, tuplerow); pnm_writepamrow(&outpam, tuplerow); } pnm_freepamrow(tuplerow); }
static void extractOneImage(FILE * const infileP, FILE * const outfileP) { /*---------------------------------------------------------------------------- Copy a complete image from input stream *infileP to output stream *outfileP. But if outfileP == NULL, just read the image and discard it. -----------------------------------------------------------------------------*/ struct pam inpam; struct pam outpam; enum pm_check_code checkRetval; unsigned int row; tuple * tuplerow; pnm_readpaminit(infileP, &inpam, PAM_STRUCT_SIZE(tuple_type)); pnm_checkpam(&inpam, PM_CHECK_BASIC, &checkRetval); outpam = inpam; outpam.file = outfileP; if (outfileP) pnm_writepaminit(&outpam); tuplerow = pnm_allocpamrow(&inpam); for (row = 0; row < inpam.height; ++row) { pnm_readpamrow(&inpam, tuplerow); if (outfileP) pnm_writepamrow(&outpam, tuplerow); } pnm_freepamrow(tuplerow); }
static void doOneImage(const char * const name, unsigned int const imageDoneCount, FILE * const fileP, bool const allimages, bool const justCount, bool const wantComments, bool * const eofP) { struct pam pam; const char * comments; enum pm_check_code checkRetval; pam.comment_p = &comments; pnm_readpaminit(fileP, &pam, PAM_STRUCT_SIZE(comment_p)); if (!justCount) { if (allimages) printf("%s:\tImage %d:\t", name, imageDoneCount); else printf("%s:\t", name); dumpHeader(pam); if (wantComments) dumpComments(comments); } strfree(comments); pnm_checkpam(&pam, PM_CHECK_BASIC, &checkRetval); if (allimages) { tuple * tuplerow; unsigned int row; tuplerow = pnm_allocpamrow(&pam); for (row = 0; row < pam.height; ++row) pnm_readpamrow(&pam, tuplerow); pnm_freepamrow(tuplerow); pnm_nextimage(fileP, eofP); } }