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; }
int main(int argc, char * argv[] ) { struct cmdlineInfo cmdline; FILE * ifP; int format; struct pam colormapPam; struct pam outpam; tuple ** colormapRaster; tupletable2 colormap; pnm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFilespec); computeColorMapFromInput(ifP, cmdline.allcolors, cmdline.newcolors, cmdline.methodForLargest, cmdline.methodForRep, &format, &colormapPam, &colormap); pm_close(ifP); colormapToImage(format, &colormapPam, colormap, cmdline.sort, cmdline.square, &outpam, &colormapRaster); if (cmdline.verbose) pm_message("Generating %u x %u image", outpam.width, outpam.height); outpam.file = stdout; pnm_writepam(&outpam, colormapRaster); pnm_freetupletable2(&colormapPam, colormap); pnm_freepamarray(colormapRaster, &outpam); pm_close(stdout); return 0; }
static void wipeoutTb(FILE * const ifP, FILE * const ofP) { /* top-bottom we have to read the full image */ struct pam inpam, outpam; tuple ** tuples; tuples = pnm_readpam(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); outpam = inpam; outpam.file = ofP; wipeImgByRow(inpam, tuples); pnm_writepam(&outpam, tuples); pnm_freepamarray(tuples, &inpam); }
static void doHilbert(FILE * const ifP, unsigned int const clumpSize) { /*---------------------------------------------------------------------------- Use hilbert space filling curve dithering -----------------------------------------------------------------------------*/ /* * This is taken from the article "Digital Halftoning with * Space Filling Curves" by Luiz Velho, proceedings of * SIGRAPH '91, page 81. * * This is not a terribly efficient or quick version of * this algorithm, but it seems to work. - Graeme Gill. * [email protected] * */ struct pam graypam; struct pam bitpam; tuple ** grays; tuple ** bits; int end; int *x,*y; int sum; grays = pnm_readpam(ifP, &graypam, PAM_STRUCT_SIZE(tuple_type)); bitpam = makeOutputPam(graypam.width, graypam.height); bits = pnm_allocpamarray(&bitpam); MALLOCARRAY(x, clumpSize); MALLOCARRAY(y, clumpSize); if (x == NULL || y == NULL) pm_error("out of memory"); initHilbert(graypam.width, graypam.height); sum = 0; end = clumpSize; while (end == clumpSize) { unsigned int i; /* compute the next cluster co-ordinates along hilbert path */ for (i = 0; i < end; i++) { if (hilbert(&x[i],&y[i])==0) end = i; /* we reached the end */ } /* sum levels */ for (i = 0; i < end; i++) sum += grays[y[i]][x[i]][0]; /* dither half and half along path */ for (i = 0; i < end; i++) { unsigned int const row = y[i]; unsigned int const col = x[i]; if (sum >= graypam.maxval) { bits[row][col][0] = 1; sum -= graypam.maxval; } else bits[row][col][0] = 0; } } pnm_writepam(&bitpam, bits); pnm_freepamarray(bits, &bitpam); pnm_freepamarray(grays, &graypam); }
int main(int argc, char **argv) { struct cmdlineInfo cmdline; FILE * ifP; tuplen ** tuplenarray; struct pam inpam; struct pam mappam; tuple ** map; int row; float * sharpness; pnm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFilespec); tuplenarray = pnm_readpamn(ifP, &inpam, sizeof(inpam)); mappam = inpam; mappam.file = stdout; mappam.maxval = 255; MALLOCARRAY_NOFAIL(sharpness, inpam.depth); map = pnm_allocpamarray(&mappam); makeBlackRown(&inpam, tuplenarray[0]); for (row = 1; row < inpam.height-1; ++row) { int col; makeBlackTuplen(&inpam, tuplenarray[row][0]); for (col = 1; col < inpam.width-1; ++col) { int dy; unsigned int plane; for (plane = 0; plane < inpam.depth; ++plane) sharpness[plane] = 0.0; for (dy = -1; dy <= 1; ++dy) { int dx; for (dx = -1; dx <= 1; ++dx) { if (dx != 0 || dy != 0) { unsigned int plane; for (plane = 0; plane < inpam.depth; ++plane) { samplen const sampleval = tuplenarray[row][col][plane]; samplen const sampleval2 = tuplenarray[row+dy][col+dx][plane]; sharpness[plane] += fabs(sampleval - sampleval2); } } } } makeSharpnessPixel(&mappam, sharpness, map[row][col]); } makeBlackTuplen(&inpam, tuplenarray[row][inpam.width-1]); } makeBlackRown(&inpam, tuplenarray[inpam.height-1]); free(sharpness); pnm_writepam(&mappam, map); pnm_freepamarray(map, &mappam); pnm_freepamarrayn(tuplenarray, &inpam); return 0; }