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, 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; }
static void doPage(FILE * const ifP, struct cmdlineInfo const cmdline) { bit * bitrow; int rows, cols, format, row; unsigned int blankRows; bool rowIsBlank; pbm_readpbminit(ifP, &cols, &rows, &format); bitrow = pbm_allocrow(cols); allocateBuffers(cols); putinit(cmdline); blankRows = 0; prevRowBufferIndex = 0; memset(prevRowBuffer, 0, rowBufferSize); for (row = 0; row < rows; ++row) { pbm_readpbmrow(ifP, bitrow, cols, format); convertRow(bitrow, cols, cmdline.pack, cmdline.delta, &rowIsBlank); if (rowIsBlank) ++blankRows; else { printBlankRows(blankRows); blankRows = 0; printRow(); } } printBlankRows(blankRows); blankRows = 0; putrest(!cmdline.noreset); freeBuffers(); pbm_freerow(bitrow); }
int main( int argc, char* argv[]) { FILE* ifp; bit* bitrow; int rows, cols, format, row, col; pbm_init( &argc, argv ); if ( argc > 2 ) pm_usage( "[pbmfile]" ); if ( argc == 2 ) ifp = pm_openr( argv[1] ); else ifp = stdin; pbm_readpbminit( ifp, &cols, &rows, &format ); if( rows>INT16MAX || cols>INT16MAX ) pm_error ("Input image is too large."); bitrow = pbm_allocrow( cols ); putinit (rows, cols); for ( row = 0; row < rows; ++row ) { #ifdef DEBUG fprintf (stderr, "row %d\n", row); #endif pbm_readpbmrow( ifp, bitrow, cols, format ); for ( col = 0; col < cols; ++col ) putbit( bitrow[col] ); putrow( ); } flushrow (); pm_close( ifp ); exit( 0 ); }
static void convertPage(FILE * const ifP, int const turnflag, int const turnokflag, bool const psfilter, bool const rle, bool const flate, bool const ascii85, bool const setpage, bool const showpage, bool const center, float const scale, int const dpiX, int const dpiY, int const pagewid, int const pagehgt, int const imagewidth, int const imageheight, bool const equalpixels, char const name[], bool const dict, bool const vmreclaim, bool const levelIsGiven, bool const levelGiven) { struct pam inpam; tuple* tuplerow; unsigned int padright; /* Number of bits we must add to the right end of each Postscript output line in order to have an integral number of bytes of output. E.g. at 2 bits per sample with 10 columns, this would be 4. */ int row; unsigned int ps_maxval; /* The maxval of the Postscript program */ float scols, srows; float llx, lly; bool turned; bool color; unsigned int postscriptLevel; struct bmepsoe * bmepsoeP; pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); if (!STRSEQ(inpam.tuple_type, PAM_PBM_TUPLETYPE) && !STRSEQ(inpam.tuple_type, PAM_PGM_TUPLETYPE) && !STRSEQ(inpam.tuple_type, PAM_PPM_TUPLETYPE)) pm_error("Unrecognized tuple type %s. This program accepts only " "PBM, PGM, PPM, and equivalent PAM input images", inpam.tuple_type); color = STRSEQ(inpam.tuple_type, PAM_PPM_TUPLETYPE); selectPostscriptLevel(levelIsGiven, levelGiven, color, dict, flate, ascii85, &postscriptLevel); if (color) pm_message("generating color Postscript program."); computeDepth(inpam.maxval, &bitspersample, &ps_maxval); { unsigned int const realBitsPerLine = inpam.width * bitspersample; unsigned int const paddedBitsPerLine = ((realBitsPerLine + 7) / 8) * 8; padright = (paddedBitsPerLine - realBitsPerLine) / bitspersample; } /* In positioning/scaling the image, we treat the input image as if it has a density of 72 pixels per inch. */ computeImagePosition(dpiX, dpiY, inpam.width, inpam.height, turnflag, turnokflag, center, pagewid, pagehgt, scale, imagewidth, imageheight, equalpixels, &scols, &srows, &llx, &lly, &turned); putinit(postscriptLevel, name, inpam.width, inpam.height, scols, srows, llx, lly, padright, bitspersample, pagewid, pagehgt, color, turned, rle, flate, ascii85, setpage, psfilter, dict); createBmepsOutputEncoder(&bmepsoeP, stdout, rle, flate, ascii85); initNativeOutputEncoder(rle, bitspersample); tuplerow = pnm_allocpamrow(&inpam); for (row = 0; row < inpam.height; ++row) { pnm_readpamrow(&inpam, tuplerow); if (psfilter) convertRowPsFilter(&inpam, tuplerow, bmepsoeP); else convertRowNative(&inpam, tuplerow, ps_maxval, rle, padright); } pnm_freepamrow(tuplerow); if (psfilter) flushBmepsOutput(bmepsoeP); else flushNativeOutput(rle); destroyBmepsOutputEncoder(bmepsoeP); putEnd(showpage, psfilter, ascii85, dict, vmreclaim); }