static void determineOutputType(const struct pam * const underlayPamP, const struct pam * const overlayPamP, struct pam * const composedPamP) { BaseTupletype const baseTupletype = commonTupletype(underlayPamP->tuple_type, overlayPamP->tuple_type); composedPamP->height = underlayPamP->height; composedPamP->width = underlayPamP->width; composedPamP->format = commonFormat(underlayPamP->format, overlayPamP->format); composedPamP->plainformat = FALSE; composedPamP->maxval = pm_lcm(underlayPamP->maxval, overlayPamP->maxval, 1, PNM_OVERALLMAXVAL); composedPamP->visual = true; composedPamP->color_depth = (baseTupletype == TT_RGB ? 3 : 1); composedPamP->have_opacity = underlayPamP->have_opacity; composedPamP->opacity_plane = (baseTupletype == TT_RGB ? 3 : 1); composedPamP->depth = (baseTupletype == TT_RGB ? 3 : 1) + (underlayPamP->have_opacity ? 1 : 0); determineOutputTupleType(baseTupletype, underlayPamP->have_opacity, composedPamP->tuple_type, sizeof(composedPamP->tuple_type)); }
static void determineOutputType(struct pam * const composedPamP, struct pam * const underlayPamP, struct pam * const overlayPamP) { composedPamP->height = underlayPamP->height; composedPamP->width = underlayPamP->width; composedPamP->format = commonFormat(underlayPamP->format, overlayPamP->format); composedPamP->plainformat = FALSE; commonTupletype(underlayPamP->tuple_type, overlayPamP->tuple_type, composedPamP->tuple_type, sizeof(composedPamP->tuple_type)); composedPamP->maxval = pm_lcm(underlayPamP->maxval, overlayPamP->maxval, 1, PNM_OVERALLMAXVAL); if (strcmp(composedPamP->tuple_type, "RGB") == 0) composedPamP->depth = 3; else if (strcmp(composedPamP->tuple_type, "GRAYSCALE") == 0) composedPamP->depth = 1; else if (strcmp(composedPamP->tuple_type, "BLACKANDWHITE") == 0) composedPamP->depth = 1; else /* Results are undefined for this case, so we just do something safe */ composedPamP->depth = MIN(underlayPamP->depth, overlayPamP->depth); }
int main(int argc, const char ** argv) { struct cmdlineInfo cmdline; FILE * ifP; tuple ** outTuples; /* Output image */ scaler * scalerP; struct pam inpam; struct pam outpam; pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFileName); pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(allocation_depth)); pnm_setminallocationdepth(&inpam, 3); outpam.size = sizeof(outpam); outpam.len = PAM_STRUCT_SIZE(tuple_type); outpam.file = stdout; outpam.width = inpam.width; outpam.height = inpam.height; outpam.depth = 3; outpam.maxval = pm_lcm(cmdline.colorRes.c[RED]-1, cmdline.colorRes.c[GRN]-1, cmdline.colorRes.c[BLU]-1, PPM_MAXMAXVAL); outpam.bytes_per_sample = inpam.bytes_per_sample; STRSCPY(outpam.tuple_type, "RGB"); outpam.format = RPPM_FORMAT; outpam.plainformat = false; scaler_create(outpam.maxval, cmdline.colorRes, &scalerP); ditherImage(&inpam, scalerP, cmdline.dim, cmdline.colorRes, &outpam, &outTuples); pnm_writepam(&outpam, outTuples); scaler_destroy(scalerP); pnm_freepamarray(outTuples, &outpam); pm_close(ifP); return 0; }