static void processMapFile(const char * const mapFileName, struct pam * const outpamCommonP, tupletable * const colormapP, unsigned int * const colormapSizeP, tuple * const firstColorP) { /*---------------------------------------------------------------------------- Read a color map from the file named 'mapFileName'. It's a map that associates each color in that file with a unique whole number. Return the map as *colormapP, with the number of entries in it as *colormapSizeP. Also determine the first color (top left) in the map file and return that as *firstColorP. -----------------------------------------------------------------------------*/ FILE * mapfile; struct pam mappam; tuple ** maptuples; tuple firstColor; mapfile = pm_openr(mapFileName); maptuples = pnm_readpam(mapfile, &mappam, PAM_STRUCT_SIZE(tuple_type)); pm_close(mapfile); computeColorMapFromMap(&mappam, maptuples, colormapP, colormapSizeP); firstColor = pnm_allocpamtuple(&mappam); pnm_assigntuple(&mappam, firstColor, maptuples[0][0]); *firstColorP = firstColor; pnm_freepamarray(maptuples, &mappam); *outpamCommonP = mappam; outpamCommonP->file = stdout; }
static void getOrFakeAndMap(const char * const andPgmFname, int const xorCols, int const xorRows, gray *** const andPGMarrayP, pixval * const andMaxvalP, colorhash_table * const andChtP, const char ** const errorP) { int andRows, andCols; if (!andPgmFname) { /* He's not supplying a bitmap for 'and'. Fake the bitmap. */ *andPGMarrayP = NULL; *andMaxvalP = 1; *andChtP = NULL; *errorP = NULL; } else { FILE * andfile; andfile = pm_openr(andPgmFname); *andPGMarrayP = pgm_readpgm(andfile, &andCols, &andRows, andMaxvalP); pm_close(andfile); if ((andCols != xorCols) || (andRows != xorRows)) { asprintfN(errorP, "And mask and image have different dimensions " "(%d x %d vs %d x %d). Aborting.", andCols, xorCols, andRows, xorRows); } else *errorP = NULL; } }
int main(int argc, char *argv[]) { FILE * const ofP = stdout; struct cmdlineInfo cmdline; FILE* ifP; bool eof; pnm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFilespec); eof = FALSE; while (!eof) { cutOneImage(ifP, cmdline, ofP); pnm_nextimage(ifP, &eof); } pm_close(ifP); pm_close(ofP); return 0; }
int main(int argc, char *argv[]) { FILE* ifP; int eof; /* No more images in input */ unsigned int image_seq; /* Sequence of current image in input file. First = 0 */ pnm_init( &argc, argv ); parse_command_line(argc, argv, &cmdline); ifP = pm_openr(cmdline.input_file); eof = FALSE; for (image_seq = 0; !eof; image_seq++) { const char *output_file_name; /* malloc'ed */ compute_output_name(cmdline.output_file_pattern, cmdline.padname, image_seq, &output_file_name); pm_message("WRITING %s\n", output_file_name); extract_one_image(ifP, output_file_name); strfree(output_file_name); pnm_nextimage(ifP, &eof); } pm_close(ifP); return 0; }
int main(int argc, char * argv[]) { struct cmdlineInfo cmdline; FILE * ifP; unsigned int cols, rows; pixval maxval; xvPalette xvPalette; ppm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFileName); makeXvPalette(&xvPalette); readXvHeader(ifP, &cols, &rows, &maxval); writePpm(ifP, &xvPalette, cols, rows, maxval, stdout); pm_close(ifP); return 0; }
static void readPpmPalette(const char * const paletteFileName, pixel (* const ppmPaletteP)[], unsigned int * const paletteSizeP) { FILE * pfP; pixel ** pixels; int cols, rows; pixval maxval; pfP = pm_openr(paletteFileName); pixels = ppm_readppm(pfP, &cols, &rows, &maxval); pm_close(pfP); *paletteSizeP = rows * cols; if (*paletteSizeP > MAXCOLORS) pm_error("ordered palette image contains %d pixels. Maximum is %d", *paletteSizeP, MAXCOLORS); { int j; int row; j = 0; /* initial value */ for (row = 0; row < rows; ++row) { int col; for (col = 0; col < cols; ++col) (*ppmPaletteP)[j++] = pixels[row][col]; } } ppm_freearray(pixels, rows); }
int main(int argc, const char *argv[]) { struct cmdlineInfo cmdline; FILE * ifP; pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFileName); switch (cmdline.direction) { case DIR_TB: wipeoutTb(ifP, stdout); break; case DIR_LR: wipeoutLr(ifP, stdout); break; } pm_close(ifP); pm_close(stdout); return 0; }
static void readRelevantPixels(const char * const inputFilename, unsigned int const hstepReq, unsigned int const vstepReq, unsigned int * const hstepP, unsigned int * const vstepP, sample *** const pixelsP, struct pam * const pamP, unsigned int * const hsamplesP) { /*---------------------------------------------------------------------------- load the image, saving only the pixels we might actually inspect -----------------------------------------------------------------------------*/ FILE * ifP; unsigned int hstep; unsigned int vstep; ifP = pm_openr(inputFilename); pnm_readpaminit(ifP, pamP, PAM_STRUCT_SIZE(tuple_type)); computeSteps(pamP, hstepReq, vstepReq, &hstep, &vstep); load(pamP, hstep, pixelsP, hsamplesP); *hstepP = hstep; *vstepP = vstep; pm_close(ifP); }
int main(int argc, char **argv) { struct cmdlineInfo cmdline; FILE * ifP; tuplen ** tuplenarray; struct pam inpam; double sharpness; pnm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFilespec); tuplenarray = pnm_readpamn(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); if (inpam.height < 3 || inpam.width < 3) pm_error("sharpness is undefined for an image less than 3 pixels " "in all directions. This image is %d x %d", inpam.width, inpam.height); computeSharpness(&inpam, tuplenarray, &sharpness); printf("Sharpness = %f\n", sharpness); pnm_freepamarrayn(tuplenarray, &inpam); pm_close(ifP); return 0; }
struct sourceManager * dsCreateSource(const char * const fileName) { struct sourceManager * srcP; MALLOCVAR(srcP); if (srcP == NULL) pm_error("Unable to get memory for the Jpeg library source manager."); srcP->ifP = pm_openr(fileName); srcP->jpegSourceMgr.init_source = dsInitSource; srcP->jpegSourceMgr.fill_input_buffer = dsFillInputBuffer; srcP->jpegSourceMgr.skip_input_data = dsSkipInputData; srcP->jpegSourceMgr.resync_to_restart = jpeg_resync_to_restart; srcP->jpegSourceMgr.term_source = dsTermSource; srcP->prematureEof = FALSE; srcP->currentBuffer = srcP->buffer1; srcP->nextBuffer = srcP->buffer2; srcP->jpegSourceMgr.bytes_in_buffer = fread(srcP->currentBuffer, 1, BUFFER_SIZE, srcP->ifP); srcP->jpegSourceMgr.next_input_byte = srcP->currentBuffer; srcP->bytesInNextBuffer = fread(srcP->nextBuffer, 1, BUFFER_SIZE, srcP->ifP); return srcP; }
int main(int argc, char * argv[]) { FILE* ifp; bit** bits; int rows, cols; const char * inputFilename; pbm_init(&argc, argv); if (argc-1 > 0) pm_error("Too many arguments (%d). The only valid argument is an " "input file name.", argc-1); else if (argc-1 == 1) inputFilename = argv[1]; else inputFilename = "-"; ifp = pm_openr(inputFilename); bits = pbm_readpbm(ifp, &cols, &rows); if (rows > 255) pm_error("Image is too high: %d rows. Max height: 255 rows", rows); if (cols > 255) pm_error("Image is too wide: %d cols. Max width: 255 cols", cols); generateMo(stdout, bits, cols, rows); pm_close(ifp); pbm_freearray(bits, rows); exit(0); }
static void openFiles(struct CmdlineInfo const cmdline, unsigned int * const fileCtP, struct pam ** const imgPamP, const char *** const namesP) { unsigned int fileCt; struct pam * imgPam; const char ** names; fileCt = cmdline.nFiles > 0 ? cmdline.nFiles : 1; MALLOCARRAY(imgPam, fileCt); MALLOCARRAY(names, fileCt); if (!imgPam || !names) pm_error("out of memory"); if (cmdline.nFiles > 0) { unsigned int i; for (i = 0; i < cmdline.nFiles; ++i) { imgPam[i].file = pm_openr(cmdline.inFileName[i]); names[i] = strdup(cmdline.inFileName[i]); } } else { imgPam[0].file = stdin; names[0] = strdup("stdin"); } *fileCtP = fileCt; *imgPamP = imgPam; *namesP = names; }
static void readMapFile(const char * const rmapFileName, xelval const maxval, gray * const lumamap) { int rmcols, rmrows; gray rmmaxv; int rmformat; FILE * rmapfP; rmapfP = pm_openr(rmapFileName); pgm_readpgminit(rmapfP, &rmcols, &rmrows, &rmmaxv, &rmformat); if (rmmaxv != maxval) pm_error("maxval in map file (%u) different from input (%u)", rmmaxv, maxval); if (rmrows != 1) pm_error("Map must have 1 row. Yours has %u", rmrows); if (rmcols != maxval + 1) pm_error("Map must have maxval + 1 (%u) columns. Yours has %u", maxval + 1, rmcols); pgm_readpgmrow(rmapfP, lumamap, maxval+1, rmmaxv, rmformat); pm_close(rmapfP); }
int main(int argc, const char ** argv) { struct cmdlineInfo cmdline; FILE * ifP; IPDB * pdbP; int status; pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFileName); pdbP = ipdb_alloc(NULL); if (pdbP == NULL) pm_error("Could not allocate IPDB structure."); status = ipdbRead(pdbP, ifP, cmdline.verbose); if (status != 0) pm_error("Image header read error: %s.", ipdb_err(status)); writeImgPam(pdbP, stdout); writeText(pdbP, cmdline.notefile); ipdb_free(pdbP); pm_close(ifP); return EXIT_SUCCESS; }
static void initPatternPixel(outGenerator * const outGenP, struct cmdlineInfo const cmdline) { struct patternPixelState * stateP; FILE * patternFileP; MALLOCVAR_NOFAIL(stateP); patternFileP = pm_openr(cmdline.patFilespec); stateP->patTuples = pnm_readpam(patternFileP, &stateP->patPam, PAM_STRUCT_SIZE(tuple_type)); pm_close(patternFileP); stateP->xshift = cmdline.xshift; stateP->yshift = cmdline.yshift; stateP->magnifypat = cmdline.magnifypat; outGenP->stateP = stateP; outGenP->getTuple = &patternPixel; outGenP->terminateState = &termPatternPixel; outGenP->pam.format = stateP->patPam.format; outGenP->pam.plainformat = stateP->patPam.plainformat; outGenP->pam.depth = stateP->patPam.depth; outGenP->pam.maxval = stateP->patPam.maxval; strcpy(outGenP->pam.tuple_type, stateP->patPam.tuple_type); if (cmdline.verbose) reportImageParameters("Pattern file", &stateP->patPam); }
static void getLookup(const char * const lookupFileName, tuple *** const lookupP, struct pam * const lookuppamP) { /*---------------------------------------------------------------------------- Get the lookup image (the one that maps integers to tuples, e.g. a color index / color map / palette) from the file named 'lookupFileName'. Return the image as *lookupP and *lookuppamP. -----------------------------------------------------------------------------*/ FILE * lookupfileP; struct pam inputLookuppam; tuple ** inputLookup; lookupfileP = pm_openr(lookupFileName); inputLookup = pnm_readpam(lookupfileP, &inputLookuppam, PAM_STRUCT_SIZE(tuple_type)); pm_close(lookupfileP); if (inputLookuppam.height != 1) pm_error("The lookup table image must be one row. " "Yours is %u rows.", inputLookuppam.height); *lookupP = inputLookup; *lookuppamP = inputLookuppam; }
int main(int argc, const char ** argv) { FILE * ifP; struct CmdlineInfo cmdline; struct SbigHeader hdr; pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFileName); readSbigHeader(ifP, &hdr); pm_message("SBIG '%s' %ux%u %s image, saturation level = %u", (hdr.haveCameraType ? hdr.cameraType : "ST-?"), hdr.cols, hdr.rows, hdr.isCompressed ? "compressed" : "uncompressed", hdr.maxval); if (hdr.maxval > PGM_OVERALLMAXVAL) { pm_error("Saturation level (%u levels) is too large" "This program's limit is %u.", hdr.maxval, PGM_OVERALLMAXVAL); } pgm_writepgminit(stdout, hdr.cols, hdr.rows, hdr.maxval, 0); writeRaster(ifP, hdr, stdout); pm_close(ifP); pm_close(stdout); return 0; }
int main(int argc, const char ** argv) { struct cmdlineInfo cmdline; FILE * ifP; xel ** xels; xel * xelrow; xelval maxval; int rows, cols; int format; unsigned int row; pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFileName); xels = pnm_readpnm(ifP, &cols, &rows, &maxval, &format); pm_close(ifP); xelrow = pnm_allocrow(cmdline.width); pnm_writepnminit(stdout, cmdline.width, cmdline.height, maxval, format, 0); for (row = 0; row < cmdline.height; ++row) { unsigned int col; for (col = 0; col < cmdline.width; ++col) xelrow[col] = xels[row % rows][col % cols]; pnm_writepnmrow(stdout, xelrow, cmdline.width, maxval, format, 0); } pm_close(stdout); return 0; }
int main(int argc, const char * argv[]) { struct cmdlineInfo cmdline; FILE * ifP; struct script * scriptP; int eof; pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); verbose = cmdline.verbose; ifP = pm_openr(cmdline.inputFilename); getScript(cmdline, &scriptP); eof = FALSE; while (!eof) { doOneImage(ifP, scriptP); ppm_nextimage(ifP, &eof); } freeScript(scriptP); pm_close(ifP); /* If the program failed, it previously aborted with nonzero completion code, via various function calls. */ return 0; }
int main(int argc, char *argv[]) { struct cmdlineInfo cmdline; /* Parsed command line */ FILE * ifP; /* Parse the command line. */ pnm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); if (cmdline.verbose) reportParameters(cmdline); srand(cmdline.randomseed); ifP = pm_openr(cmdline.inputFilespec); /* Produce a stereogram. */ produceStereogram(ifP, cmdline); pm_close(ifP); return 0; }
int main(int argc, char *argv[]) { struct cmdlineInfo cmdline; pnm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); if (cmdline.inputFileCount == 0) describeOneFile("stdin", stdin, cmdline.allimages || cmdline.count, cmdline.count, cmdline.comments); else { unsigned int i; for (i = 0; i < cmdline.inputFileCount; ++i) { FILE * ifP; ifP = pm_openr(cmdline.inputFilespec[i]); describeOneFile(cmdline.inputFilespec[i], ifP, cmdline.allimages || cmdline.count, cmdline.count, cmdline.comments); pm_close(ifP); } } return 0; }
int main(int argc, char **argv) { FILE * ifP; struct cmdlineInfo cmdline; struct pam inpam, outpam; int eof; /* No more images in input stream */ pnm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); if (cmdline.simple || cmdline.local) ifP = pm_openr(cmdline.inputFileName); else ifP = pm_openr_seekable(cmdline.inputFileName); /* Threshold each image in the PAM file */ eof = FALSE; while (!eof) { pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); /* Set output image parameters for a bilevel image */ outpam.size = sizeof(outpam); outpam.len = PAM_STRUCT_SIZE(tuple_type); outpam.file = stdout; outpam.format = PAM_FORMAT; outpam.plainformat = 0; outpam.height = inpam.height; outpam.width = inpam.width; outpam.maxval = 1; outpam.bytes_per_sample = 1; if (inpam.depth > 1) { strcpy(outpam.tuple_type, "BLACKANDWHITE_ALPHA"); outpam.depth = 2; } else { strcpy(outpam.tuple_type, "BLACKANDWHITE"); outpam.depth = 1; } pnm_writepaminit(&outpam); /* Do the thresholding */ if (cmdline.simple) thresholdSimple(&inpam, &outpam, cmdline.threshold); else if (cmdline.local || cmdline.dual) thresholdLocal(&inpam, &outpam, cmdline); else thresholdIterative(&inpam, &outpam, cmdline.verbose); pnm_nextimage(ifP, &eof); } pm_close(ifP); return 0; }
int main(int argc, char *argv[]) { FILE * ifP; tuple * tuplerow; /* Row from input image */ unsigned int row; struct cmdlineInfo cmdline; struct pam inpam; struct pam outpam; pnm_init( &argc, argv ); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFilespec); pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); tuplerow = pnm_allocpamrow(&inpam); outpam = inpam; /* Initial value -- most fields should be same */ outpam.file = stdout; if (inpam.height % 2 == 0) outpam.height = inpam.height / 2; else { if (cmdline.rowsToTake == ODD) outpam.height = inpam.height / 2; else outpam.height = inpam.height / 2 + 1; } pnm_writepaminit(&outpam); { unsigned int modulusToTake; /* The row number mod 2 of the rows that are supposed to go into the output. */ switch (cmdline.rowsToTake) { case EVEN: modulusToTake = 0; break; case ODD: modulusToTake = 1; break; default: pm_error("INTERNAL ERROR: invalid rowsToTake"); } /* Read input and write out rows extracted from it */ for (row = 0; row < inpam.height; row++) { pnm_readpamrow(&inpam, tuplerow); if (row % 2 == modulusToTake) pnm_writepamrow(&outpam, tuplerow); } } pnm_freepamrow(tuplerow); pm_close(inpam.file); pm_close(outpam.file); return 0; }
int main(int argc, char **argv) { FILE *ifp; pixel **pixels; int rows, row, cols, col, pal_len, i; pixval maxval; struct cmdlineInfo cmdline; unsigned char rgb[NUM_COLORS][3]; char ansi_code[NUM_COLORS][MAX_ANSI_STR_LEN]; ppm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifp = pm_openr(cmdline.inputFilespec); pixels = ppm_readppm(ifp, &cols, &rows, &maxval); pm_close(ifp); pal_len=generate_palette(rgb, ansi_code); for (row = 0; row < rows; ++row) { for (col = 0; col < cols; col++) { pixval const r=(int)PPM_GETR(pixels[row][col])*255/maxval; pixval const g=(int)PPM_GETG(pixels[row][col])*255/maxval; pixval const b=(int)PPM_GETB(pixels[row][col])*255/maxval; int val, dist; /* The following loop calculates the index that corresponds to the minimum color distance between the given RGB values and the values available in the palette. */ for(i=0, dist=sqr(255)*3, val=0; i<pal_len; i++) { pixval const pr=rgb[i][0]; pixval const pg=rgb[i][1]; pixval const pb=rgb[i][2]; unsigned int j; if( (j=sqr(r-pr)+sqr(b-pb)+sqr(g-pg))<dist ) { dist=j; val=i; } } printf("%s%c", ansi_code[val],0xB1); } printf(ESC"\x30m\n"); } printf(ESC"\x30m"); ppm_freearray(pixels, rows); exit(0); }
int main(int argc, const char ** argv) { struct cmdlineInfo cmdline; FILE * ifP; int cols, rows; xelval maxval; int format; unsigned int histWidth; unsigned int range; unsigned int hmax; xelval startval, endval; pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFilespec); pnm_readpnminit(ifP, &cols, &rows, &maxval, &format); startval = cmdline.lval; endval = MIN(maxval, cmdline.rval) + 1; range = endval - startval; if (cmdline.widthSpec) histWidth = cmdline.width; else histWidth = range; reportScale(histWidth, range, cmdline.verbose); if (cmdline.nmaxSpec) hmax = cols * rows / histWidth * cmdline.nmax; switch (PNM_FORMAT_TYPE(format)) { case PPM_TYPE: ppmHist(ifP, cols, rows, maxval, format, cmdline.dots, cmdline.white, cmdline.black, cmdline.colorWanted, cmdline.verbose, startval, endval, histWidth, cmdline.height, cmdline.nmaxSpec, hmax); break; case PGM_TYPE: pgmHist(ifP, cols, rows, maxval, format, cmdline.dots, cmdline.white, cmdline.black, cmdline.verbose, startval, endval, histWidth, cmdline.height, cmdline.nmaxSpec, hmax); break; case PBM_TYPE: pm_error("Cannot do a histogram of a a PBM file"); break; } pm_close(ifP); return 0; }
int main(int argc, char * argv[]) { FILE* ifp; const char *name; /* malloc'ed */ struct cmdline_info cmdline; pnm_init( &argc, argv ); parseCommandLine(argc, argv, &cmdline); verbose = cmdline.verbose; ifp = pm_openr(cmdline.input_filespec); if (strcmp(cmdline.input_filespec, "-") == 0 ) name = strdup("noname"); else name = basebasename(cmdline.input_filespec); { int eof; /* There are no more images in the input file */ unsigned int image_seq; /* I don't know if this works at all for multi-image PNM input. Before July 2000, it ignored everything after the first image, so this probably is at least as good -- it should be identical for a single-image file, which is the only kind which was legal before July 2000. Maybe there needs to be some per-file header and trailers stuff in the Postscript program, with some per-page header and trailer stuff inside. I don't know Postscript. - Bryan 2000.06.19. */ eof = FALSE; /* There is always at least one image */ for (image_seq = 0; !eof; image_seq++) { convertPage(ifp, cmdline.mustturn, cmdline.canturn, cmdline.psfilter, cmdline.rle, cmdline.flate, cmdline.ascii85, cmdline.setpage, cmdline.showpage, cmdline.center, cmdline.scale, cmdline.dpiX, cmdline.dpiY, cmdline.width, cmdline.height, cmdline.imagewidth, cmdline.imageheight, cmdline.equalpixels, name, cmdline.dict, cmdline.vmreclaim, cmdline.levelSpec, cmdline.level); pnm_nextimage(ifp, &eof); } } strfree(name); pm_close(ifp); return 0; }
int main(int argc, const char * argv[]) { FILE * ifP; gray * grayrow; int rows; int cols; unsigned int depth; int format; unsigned int padright; unsigned int row; gray maxval; const char * inputFile; pm_proginit(&argc, argv); if (argc-1 < 1) inputFile = "-"; else { inputFile = argv[1]; if (argc-1 > 2) pm_error("Too many arguments. The only argument is the optional " "input file name"); } ifP = pm_openr(inputFile); pgm_readpgminit(ifP, &cols, &rows, &maxval, &format); grayrow = pgm_allocrow(cols); depth = pm_maxvaltobits(maxval); /* Compute padding to round cols up to the nearest multiple of 32. */ padright = ((cols + 31) / 32) * 32 - cols; putinit(cols, rows, depth); for (row = 0; row < rows; ++row) { unsigned int col; pgm_readpgmrow(ifP, grayrow, cols, maxval, format); for (col = 0; col < cols; ++col) putval(grayrow[col]); for (col = 0; col < padright; ++col) putval(0); } pm_close(ifP); putrest(); return 0; }
int main(int argc, const char * argv[]) { struct cmdlineInfo cmdline; FILE * ifP; bit ** bits; int rows, cols; unsigned int top, bottom, left, right; /* boundaries of principal part of image -- i.e. excluding white borders */ pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFileName); bits = pbm_readpbm(ifP, &cols, &rows); pm_close(ifP); findPrincipalImage(bits, rows, cols, &top, &bottom, &left, &right); printf("%%!PS-Adobe-2.0 EPSF-1.2\n"); outputBoundingBox(top, bottom, left, right, rows, cmdline.dpiX, cmdline.dpiY); if (!cmdline.bbonly) { int row; printf("%%%%BeginPreview: %d %d 1 %d\n", right - left + 1, bottom - top + 1, bottom - top + 1); for (row = top; row <= bottom; row++) { unsigned int col; unsigned int outChars; printf("%% "); outChars = 2; /* initial value */ for (col = left; col <= right; col += 8) { if (outChars == 72) { printf("\n%% "); outChars = 2; } printf("%02x", eightPixels(bits, row, col, cols)); outChars += 2; } if (outChars > 0) printf("\n"); } printf("%%%%EndImage\n"); printf("%%%%EndPreview\n"); } return 0; }
int main(int argc, const char *argv[]) { FILE * ifP; bit * bitrow; int rows; int cols; int format; unsigned int padright; unsigned int row; const char * inputFile; pm_proginit(&argc, argv); if (argc-1 < 1) inputFile = "-"; else { inputFile = argv[1]; if (argc-1 > 2) pm_error("Too many arguments. The only argument is the optional " "input file name"); } ifP = pm_openr(inputFile); pbm_readpbminit(ifP, &cols, &rows, &format); if (rows > INT16MAX || cols > INT16MAX) pm_error("Input image is too large."); bitrow = pbm_allocrow(cols); /* Compute padding to round cols up to the nearest multiple of 16. */ padright = ((cols + 15) / 16) * 16 - cols; putinit(cols, rows); for (row = 0; row < rows; ++row) { unsigned int col; pbm_readpbmrow(ifP, bitrow, cols, format); for (col = 0; col < cols; ++col) putbit(bitrow[col]); for (col = 0; col < padright; ++col) putbit(0); } if (ifP != stdin) fclose(ifP); putrest(); return 0; }
int main(int argc, char *argv[]) { struct cmdlineInfo cmdline; FILE * ifP; tuple ** tuples; struct pam pam; int ncolors; tupletable chv; tuplehash cht; struct ImageHeader tgaHeader; enum TGAbaseImageType baseImgType; bool withAlpha; const char *outName; pnm_init( &argc, argv ); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFilespec); computeOutName(cmdline, &outName); tuples = pnm_readpam(ifP, &pam, PAM_STRUCT_SIZE(tuple_type)); pm_close(ifP); computeImageType_cht(&pam, cmdline, tuples, &baseImgType, &withAlpha, &chv, &cht, &ncolors); /* Do the Targa header */ computeTgaHeader(&pam, baseImgType, withAlpha, !cmdline.norle, ncolors, 0, outName, &tgaHeader); writeTgaHeader(tgaHeader); if (baseImgType == TGA_MAP_TYPE) { /* Write out the Targa colormap. */ int i; for (i = 0; i < ncolors; ++i) putMapEntry(&pam, chv[i]->tuple, tgaHeader.CoSize); } writeTgaRaster(&pam, tuples, cht, baseImgType, withAlpha, !cmdline.norle, 0); if (cht) pnm_destroytuplehash(cht); if (chv) pnm_freetupletable(&pam, chv); releaseTgaHeader(tgaHeader); strfree(outName); pnm_freepamarray(tuples, &pam); return 0; }