static void adaptRowFormat(struct pam * const inpamP, struct pam * const outpamP, tuple * const tuplerow) { /*---------------------------------------------------------------------------- Convert the row in 'tuplerow', which is in a format described by *inpamP, to the format described by *outpamP. 'tuplerow' must have enough allocated depth to do this. -----------------------------------------------------------------------------*/ assert(outpamP->visual); assert(inpamP->visual); pnm_scaletuplerow(inpamP, tuplerow, tuplerow, outpamP->maxval); if (outpamP->color_depth == 3) { if (outpamP->have_opacity) pnm_makerowrgba(inpamP, tuplerow); else pnm_makerowrgb(inpamP, tuplerow); } else { if (outpamP->have_opacity) pnm_addopacityrow(inpamP, tuplerow); } }
static void ditherImage(struct pam * const inpamP, const scaler * const scalerP, unsigned int const dithPower, struct colorResolution const colorRes, struct pam * const outpamP, tuple *** const outTuplesP) { unsigned int const dithDim = 1 << dithPower; unsigned int const ditherMatrixArea = SQR(dithDim); unsigned int const modMask = (dithDim - 1); /* And this into N to compute N % dithDim cheaply, since we know (though the compiler doesn't) that dithDim is a power of 2 */ unsigned int ** const ditherMatrix = dithMatrix(dithPower); tuple * inrow; tuple ** outTuples; unsigned int row; struct pam ditherPam; /* Describes the tuples that ditherRow() sees */ assert(dithPower < sizeof(unsigned int) * 8); assert(UINT_MAX / dithDim >= dithDim); validateNoDitherOverflow(ditherMatrixArea, inpamP, colorRes); inrow = pnm_allocpamrow(inpamP); outTuples = pnm_allocpamarray(outpamP); /* We will modify the input to promote it to depth 3 */ ditherPam = *inpamP; ditherPam.depth = 3; for (row = 0; row < inpamP->height; ++row) { pnm_readpamrow(inpamP, inrow); pnm_makerowrgb(inpamP, inrow); ditherRow(&ditherPam, inrow, scalerP, ditherMatrix, ditherMatrixArea, colorRes, row, modMask, outpamP, outTuples[row]); } free(ditherMatrix); pnm_freepamrow(inrow); *outTuplesP = outTuples; }
static void adaptRowToOutputFormat(struct pam * const inpamP, tuple * const tuplerow, struct pam * const outpamP) { /*---------------------------------------------------------------------------- Convert the row in 'tuplerow', which is in a format described by *inpamP, to the format described by *outpamP. 'tuplerow' must have enough allocated depth to do this. -----------------------------------------------------------------------------*/ pnm_scaletuplerow(inpamP, tuplerow, tuplerow, outpamP->maxval); if (strncmp(outpamP->tuple_type, "RGB", 3) == 0) pnm_makerowrgb(inpamP, tuplerow); }