/*! * pixWriteStream() * * Input: stream * pix * format * Return: 0 if OK; 1 on error. */ l_int32 pixWriteStream(FILE *fp, PIX *pix, l_int32 format) { PROCNAME("pixWriteStream"); if (!fp) return ERROR_INT("stream not defined", procName, 1); if (!pix) return ERROR_INT("pix not defined", procName, 1); if (format == IFF_DEFAULT) format = pixChooseOutputFormat(pix); switch(format) { case IFF_BMP: pixWriteStreamBmp(fp, pix); break; case IFF_JFIF_JPEG: /* default quality; baseline sequential */ return pixWriteStreamJpeg(fp, pix, 75, 0); break; case IFF_PNG: /* no gamma value stored */ return pixWriteStreamPng(fp, pix, 0.0); break; case IFF_TIFF: /* uncompressed */ case IFF_TIFF_PACKBITS: /* compressed, binary only */ case IFF_TIFF_RLE: /* compressed, binary only */ case IFF_TIFF_G3: /* compressed, binary only */ case IFF_TIFF_G4: /* compressed, binary only */ case IFF_TIFF_LZW: /* compressed, all depths */ case IFF_TIFF_ZIP: /* compressed, all depths */ return pixWriteStreamTiff(fp, pix, format); break; case IFF_PNM: return pixWriteStreamPnm(fp, pix); break; case IFF_GIF: return pixWriteStreamGif(fp, pix); break; case IFF_PS: return pixWriteStreamPS(fp, pix, NULL, 0, DEFAULT_SCALING); break; case IFF_JP2: return ERROR_INT("jp2 format not supported", procName, 1); break; case IFF_WEBP: return pixWriteStreamWebP(fp, pix, 80, 0); break; case IFF_LPDF: return pixWriteStreamPdf(fp, pix, 0, NULL); break; case IFF_SPIX: return pixWriteStreamSpix(fp, pix); break; default: return ERROR_INT("unknown format", procName, 1); break; } return 0; }
main(int argc, char **argv) { l_int32 w, h, success, display; l_float32 factor, scale; BOX *box; FILE *fp, *fp1; PIX *pixs, *pixt; if (regTestSetup(argc, argv, &fp, &display, &success, NULL)) return 1; factor = 0.95; /* Uncompressed PS with scaling but centered on the page */ pixs = pixRead("feyn-fract.tif"); pixGetDimensions(pixs, &w, &h, NULL); scale = L_MIN(factor * 2550 / w, factor * 3300 / h); fp1 = fopen("/tmp/psio0.ps", "wb+"); pixWriteStreamPS(fp1, pixs, NULL, 300, scale); fclose(fp1); regTestCheckFile(fp, argv, "/tmp/psio0.ps", 0, &success); pixDestroy(&pixs); /* Uncompressed PS with scaling, with LL corner at (1500, 1500) mils */ pixs = pixRead("weasel4.11c.png"); pixGetDimensions(pixs, &w, &h, NULL); scale = L_MIN(factor * 2550 / w, factor * 3300 / h); box = boxCreate(1500, 1500, (l_int32)(1000 * scale * w / 300), (l_int32)(1000 * scale * h / 300)); fp1 = fopen("/tmp/psio1.ps", "wb+"); pixWriteStreamPS(fp1, pixs, box, 300, 1.0); fclose(fp1); regTestCheckFile(fp, argv, "/tmp/psio1.ps", 1, &success); boxDestroy(&box); pixDestroy(&pixs); /* DCT compressed PS with LL corner at (300, 1000) pixels */ pixs = pixRead("marge.jpg"); pixt = pixConvertTo32(pixs); pixWrite("/tmp/psio2.jpg", pixt, IFF_JFIF_JPEG); convertJpegToPS("/tmp/psio2.jpg", "/tmp/psio3.ps", "w", 300, 1000, 0, 4.0, 1, 1); regTestCheckFile(fp, argv, "/tmp/psio2.jpg", 2, &success); regTestCheckFile(fp, argv, "/tmp/psio3.ps", 3, &success); pixDestroy(&pixt); pixDestroy(&pixs); /* For each page, apply tiff g4 image first; then jpeg or png over it */ convertTiffG4ToPS("feyn.tif", "/tmp/psio4.ps", "w", 0, 0, 0, 1.0, 1, 1, 0); convertJpegToPS("marge.jpg", "/tmp/psio4.ps", "a", 500, 100, 300, 2.0, 1, 0); convertFlateToPS("weasel4.11c.png", "/tmp/psio4.ps", "a", 300, 400, 300, 6.0, 1, 0); convertJpegToPS("marge.jpg", "/tmp/psio4.ps", "a", 100, 800, 300, 1.5, 1, 1); convertTiffG4ToPS("feyn.tif", "/tmp/psio4.ps", "a", 0, 0, 0, 1.0, 2, 1, 0); convertJpegToPS("marge.jpg", "/tmp/psio4.ps", "a", 1000, 700, 300, 2.0, 2, 0); convertJpegToPS("marge.jpg", "/tmp/psio4.ps", "a", 100, 200, 300, 2.0, 2, 1); convertTiffG4ToPS("feyn.tif", "/tmp/psio4.ps", "a", 0, 0, 0, 1.0, 3, 1, 0); convertJpegToPS("marge.jpg", "/tmp/psio4.ps", "a", 200, 200, 300, 2.0, 3, 0); convertJpegToPS("marge.jpg", "/tmp/psio4.ps", "a", 200, 900, 300, 2.0, 3, 1); regTestCheckFile(fp, argv, "/tmp/psio4.ps", 4, &success); /* Now apply jpeg first; then paint through a g4 mask. * For gv, the first image with a b.b. determines the * window size for the canvas, so we put down the largest * image first. If we had rendered a small image first, * gv and evince will not show the entire page. However, after * conversion to pdf, everything works fine, regardless of the * order in which images are placed into the PS. That is * because the pdf interpreter is robust to bad hints, ignoring * the page hints and computing the bounding box from the * set of images rendered on the page. */ pixs = pixRead("wyom.jpg"); pixt = pixScaleToSize(pixs, 2528, 3300); pixWrite("/tmp/psio5.jpg", pixt, IFF_JFIF_JPEG); pixDestroy(&pixs); pixDestroy(&pixt); convertJpegToPS("/tmp/psio5.jpg", "/tmp/psio5.ps", "w", 0, 0, 0, 1.0, 1, 0); convertFlateToPS("weasel8.240c.png", "/tmp/psio5.ps", "a", 100, 100, 300, 5.0, 1, 0); convertFlateToPS("weasel8.149g.png", "/tmp/psio5.ps", "a", 200, 300, 300, 5.0, 1, 0); convertFlateToPS("weasel4.11c.png", "/tmp/psio5.ps", "a", 300, 500, 300, 5.0, 1, 0); convertTiffG4ToPS("feyn.tif", "/tmp/psio5.ps", "a", 0, 0, 0, 1.0, 1, 1, 1); convertJpegToPS("marge.jpg", "/tmp/psio5.ps", "a", 500, 100, 300, 2.0, 2, 0); convertFlateToPS("weasel4.11c.png", "/tmp/psio5.ps", "a", 300, 400, 300, 6.0, 2, 0); convertJpegToPS("marge.jpg", "/tmp/psio5.ps", "a", 100, 800, 300, 1.5, 2, 0); convertTiffG4ToPS("feyn.tif", "/tmp/psio5.ps", "a", 0, 0, 0, 1.0, 2, 1, 1); convertJpegToPS("marge.jpg", "/tmp/psio5.ps", "a", 500, 100, 300, 2.0, 3, 0); convertJpegToPS("marge.jpg", "/tmp/psio5.ps", "a", 100, 800, 300, 2.0, 3, 0); convertTiffG4ToPS("feyn.tif", "/tmp/psio5.ps", "a", 0, 0, 0, 1.0, 3, 1, 1); convertJpegToPS("marge.jpg", "/tmp/psio5.ps", "a", 1000, 700, 300, 2.0, 4, 0); convertJpegToPS("marge.jpg", "/tmp/psio5.ps", "a", 100, 200, 300, 2.0, 4, 0); convertTiffG4ToPS("feyn.tif", "/tmp/psio5.ps", "a", 0, 0, 0, 1.0, 4, 1, 1); convertJpegToPS("marge.jpg", "/tmp/psio5.ps", "a", 200, 200, 300, 2.0, 5, 0); convertJpegToPS("marge.jpg", "/tmp/psio5.ps", "a", 200, 900, 300, 2.0, 5, 0); convertTiffG4ToPS("feyn.tif", "/tmp/psio5.ps", "a", 0, 0, 0, 1.0, 5, 1, 1); regTestCheckFile(fp, argv, "/tmp/psio5.ps", 5, &success); /* Generation using segmentation masks */ convertSegmentedPagesToPS(".", "lion-page", ".", "lion-mask", 10, 0, 100, 2.0, 0.8, 190, "/tmp/psio6.ps"); regTestCheckFile(fp, argv, "/tmp/psio6.ps", 6, &success); regTestCleanup(argc, argv, fp, success, NULL); return 0; }
main(int argc, char **argv) { char *filein, *fileout; l_int32 w, h; l_float32 scale; FILE *fp; PIX *pix, *pixs, *pixd; PIXCMAP *cmap; static char mainName[] = "dithertest"; if (argc != 3) exit(ERROR_INT(" Syntax: dithertest filein fileout", mainName, 1)); filein = argv[1]; fileout = argv[2]; if ((pix = pixRead(filein)) == NULL) exit(ERROR_INT("pix not made", mainName, 1)); if (pixGetDepth(pix) != 8) exit(ERROR_INT("pix not 8 bpp", mainName, 1)); pixs = pixGammaTRC(NULL, pix, GAMMA, 0, 255); startTimer(); pixd = pixDitherToBinary(pixs); fprintf(stderr, " time for binarized dither = %7.3f sec\n", stopTimer()); pixDisplayWrite(pixd, 1); pixDestroy(&pixd); /* Dither to 2 bpp, with colormap */ startTimer(); pixd = pixDitherTo2bpp(pixs, 1); fprintf(stderr, " time for dither = %7.3f sec\n", stopTimer()); pixDisplayWrite(pixd, 1); cmap = pixGetColormap(pixd); pixcmapWriteStream(stderr, cmap); pixDestroy(&pixd); /* Dither to 2 bpp, without colormap */ startTimer(); pixd = pixDitherTo2bpp(pixs, 0); fprintf(stderr, " time for dither = %7.3f sec\n", stopTimer()); pixDisplayWrite(pixd, 1); pixDestroy(&pixd); /* Dither to 2 bpp, without colormap; output in PostScript */ pixd = pixDitherTo2bpp(pixs, 0); w = pixGetWidth(pixs); h = pixGetHeight(pixs); scale = L_MIN(FACTOR * 2550 / w, FACTOR * 3300 / h); fp = lept_fopen(fileout, "wb+"); pixWriteStreamPS(fp, pixd, NULL, 300, scale); lept_fclose(fp); pixDestroy(&pixd); /* Dither 2x upscale to 1 bpp */ startTimer(); pixd = pixScaleGray2xLIDither(pixs); fprintf(stderr, " time for scale/dither = %7.3f sec\n", stopTimer()); pixDisplayWrite(pixd, 1); pixDestroy(&pixd); /* Dither 4x upscale to 1 bpp */ startTimer(); pixd = pixScaleGray4xLIDither(pixs); fprintf(stderr, " time for scale/dither = %7.3f sec\n", stopTimer()); pixDisplayWrite(pixd, 1); pixDestroy(&pixd); pixDisplayMultiple("/tmp/junk_write_display*"); pixDestroy(&pix); pixDestroy(&pixs); return 0; }
int main(int argc, char **argv) { l_int32 i, w, h; l_float32 factor, scale; BOX *box; FILE *fp1; PIX *pixs, *pixt; PIXA *pixa; SARRAY *sa; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; factor = 0.95; /* Uncompressed PS with scaling but centered on the page */ pixs = pixRead("feyn-fract.tif"); pixGetDimensions(pixs, &w, &h, NULL); scale = L_MIN(factor * 2550 / w, factor * 3300 / h); fp1 = lept_fopen("/tmp/regout/psio0.ps", "wb+"); pixWriteStreamPS(fp1, pixs, NULL, 300, scale); lept_fclose(fp1); regTestCheckFile(rp, "/tmp/regout/psio0.ps"); /* 0 */ pixDestroy(&pixs); /* Uncompressed PS with scaling, with LL corner at (1500, 1500) mils */ pixs = pixRead("weasel4.11c.png"); pixGetDimensions(pixs, &w, &h, NULL); scale = L_MIN(factor * 2550 / w, factor * 3300 / h); box = boxCreate(1500, 1500, (l_int32)(1000 * scale * w / 300), (l_int32)(1000 * scale * h / 300)); fp1 = lept_fopen("/tmp/regout/psio1.ps", "wb+"); pixWriteStreamPS(fp1, pixs, box, 300, 1.0); lept_fclose(fp1); regTestCheckFile(rp, "/tmp/regout/psio1.ps"); /* 1 */ boxDestroy(&box); pixDestroy(&pixs); /* DCT compressed PS with LL corner at (300, 1000) pixels */ pixs = pixRead("marge.jpg"); pixt = pixConvertTo32(pixs); pixWrite("/tmp/regout/psio2.jpg", pixt, IFF_JFIF_JPEG); convertJpegToPS("/tmp/regout/psio2.jpg", "/tmp/regout/psio3.ps", "w", 300, 1000, 0, 4.0, 1, 1); regTestCheckFile(rp, "/tmp/regout/psio2.jpg"); /* 2 */ regTestCheckFile(rp, "/tmp/regout/psio3.ps"); /* 3 */ pixDestroy(&pixt); pixDestroy(&pixs); /* For each page, apply tiff g4 image first; then jpeg or png over it */ convertG4ToPS("feyn.tif", "/tmp/regout/psio4.ps", "w", 0, 0, 0, 1.0, 1, 1, 0); convertJpegToPS("marge.jpg", "/tmp/regout/psio4.ps", "a", 500, 100, 300, 2.0, 1, 0); convertFlateToPS("weasel4.11c.png", "/tmp/regout/psio4.ps", "a", 300, 400, 300, 6.0, 1, 0); convertJpegToPS("marge.jpg", "/tmp/regout/psio4.ps", "a", 100, 800, 300, 1.5, 1, 1); convertG4ToPS("feyn.tif", "/tmp/regout/psio4.ps", "a", 0, 0, 0, 1.0, 2, 1, 0); convertJpegToPS("marge.jpg", "/tmp/regout/psio4.ps", "a", 1000, 700, 300, 2.0, 2, 0); convertJpegToPS("marge.jpg", "/tmp/regout/psio4.ps", "a", 100, 200, 300, 2.0, 2, 1); convertG4ToPS("feyn.tif", "/tmp/regout/psio4.ps", "a", 0, 0, 0, 1.0, 3, 1, 0); convertJpegToPS("marge.jpg", "/tmp/regout/psio4.ps", "a", 200, 200, 300, 2.0, 3, 0); convertJpegToPS("marge.jpg", "/tmp/regout/psio4.ps", "a", 200, 900, 300, 2.0, 3, 1); regTestCheckFile(rp, "/tmp/regout/psio4.ps"); /* 4 */ /* Now apply jpeg first; then paint through a g4 mask. * For gv, the first image with a b.b. determines the * window size for the canvas, so we put down the largest * image first. If we had rendered a small image first, * gv and evince will not show the entire page. However, after * conversion to pdf, everything works fine, regardless of the * order in which images are placed into the PS. That is * because the pdf interpreter is robust to bad hints, ignoring * the page hints and computing the bounding box from the * set of images rendered on the page. * * Concatenate several pages, with colormapped png, color * jpeg and tiffg4 images (with the g4 image acting as a mask * that we're painting black through. If the text layer * is painted first, the following images occlude it; otherwise, * the images remain in the background of the text. */ pixs = pixRead("wyom.jpg"); pixt = pixScaleToSize(pixs, 2528, 3300); pixWrite("/tmp/regout/psio5.jpg", pixt, IFF_JFIF_JPEG); pixDestroy(&pixs); pixDestroy(&pixt); convertJpegToPS("/tmp/regout/psio5.jpg", "/tmp/regout/psio5.ps", "w", 0, 0, 300, 1.0, 1, 0); convertFlateToPS("weasel8.240c.png", "/tmp/regout/psio5.ps", "a", 100, 100, 300, 5.0, 1, 0); convertFlateToPS("weasel8.149g.png", "/tmp/regout/psio5.ps", "a", 200, 300, 300, 5.0, 1, 0); convertFlateToPS("weasel4.11c.png", "/tmp/regout/psio5.ps", "a", 300, 500, 300, 5.0, 1, 0); convertG4ToPS("feyn.tif", "/tmp/regout/psio5.ps", "a", 0, 0, 0, 1.0, 1, 1, 1); convertJpegToPS("marge.jpg", "/tmp/regout/psio5.ps", "a", 500, 100, 300, 2.0, 2, 0); convertFlateToPS("weasel4.11c.png", "/tmp/regout/psio5.ps", "a", 300, 400, 300, 6.0, 2, 0); convertJpegToPS("marge.jpg", "/tmp/regout/psio5.ps", "a", 100, 800, 300, 1.5, 2, 0); convertG4ToPS("feyn.tif", "/tmp/regout/psio5.ps", "a", 0, 0, 0, 1.0, 2, 1, 1); convertJpegToPS("marge.jpg", "/tmp/regout/psio5.ps", "a", 500, 100, 300, 2.0, 3, 0); convertJpegToPS("marge.jpg", "/tmp/regout/psio5.ps", "a", 100, 800, 300, 2.0, 3, 0); convertG4ToPS("feyn.tif", "/tmp/regout/psio5.ps", "a", 0, 0, 0, 1.0, 3, 1, 1); convertJpegToPS("marge.jpg", "/tmp/regout/psio5.ps", "a", 700, 700, 300, 2.0, 4, 0); convertFlateToPS("weasel8.149g.png", "/tmp/regout/psio5.ps", "a", 400, 400, 300, 5.0, 4, 0); convertG4ToPS("feyn.tif", "/tmp/regout/psio5.ps", "a", 0, 0, 0, 1.0, 4, 1, 0); convertFlateToPS("weasel8.240c.png", "/tmp/regout/psio5.ps", "a", 100, 220, 300, 5.0, 4, 0); convertJpegToPS("marge.jpg", "/tmp/regout/psio5.ps", "a", 100, 200, 300, 2.0, 4, 1); convertJpegToPS("marge.jpg", "/tmp/regout/psio5.ps", "a", 200, 200, 300, 1.5, 5, 0); convertFlateToPS("weasel8.240c.png", "/tmp/regout/psio5.ps", "a", 140, 80, 300, 7.0, 5, 0); convertG4ToPS("feyn.tif", "/tmp/regout/psio5.ps", "a", 0, 0, 0, 1.0, 5, 1, 0); convertFlateToPS("weasel8.149g.png", "/tmp/regout/psio5.ps", "a", 280, 310, 300, 5.0, 4, 0); convertJpegToPS("marge.jpg", "/tmp/regout/psio5.ps", "a", 200, 900, 300, 2.0, 5, 1); regTestCheckFile(rp, "/tmp/regout/psio5.ps"); /* 5 */ /* Generation using segmentation masks */ convertSegmentedPagesToPS(".", "lion-page", 10, ".", "lion-mask", 10, 0, 100, 2.0, 0.8, 190, "/tmp/regout/psio6.ps"); regTestCheckFile(rp, "/tmp/regout/psio6.ps"); /* 6 */ /* PS generation for embeddding */ convertJpegToPSEmbed("tetons.jpg", "/tmp/regout/psio7.ps"); regTestCheckFile(rp, "/tmp/regout/psio7.ps"); /* 7 */ convertG4ToPSEmbed("feyn-fract.tif", "/tmp/regout/psio8.ps"); regTestCheckFile(rp, "/tmp/regout/psio8.ps"); /* 8 */ convertFlateToPSEmbed("weasel8.240c.png", "/tmp/regout/psio9.ps"); regTestCheckFile(rp, "/tmp/regout/psio9.ps"); /* 9 */ /* Writing compressed from a pixa */ sa = sarrayCreate(0); for (i = 0; i < 11; i++) sarrayAddString(sa, WeaselNames[i], L_COPY); pixa = pixaReadFilesSA(sa); pixaWriteCompressedToPS(pixa, "/tmp/regout/psio10.ps", 0, 3); regTestCheckFile(rp, "/tmp/regout/psio10.ps"); /* 10 */ pixaDestroy(&pixa); sarrayDestroy(&sa); return regTestCleanup(rp); }
int main(int argc, char **argv) { char *filein, *fname, *argp, *argn; char buffer[512]; l_int32 i, w, h, ignore; l_float32 scale; FILE *fp; PIX *pixs, *pixt; static char mainName[] = "printimage"; if (argc < 2 || argc > 4) return ERROR_INT( " Syntax: printimage filein [-P<printer>] [-#<number>]", mainName, 1); /* parse args */ filein = argv[1]; argp = argn = NULL; if (argc > 2) { for (i = 2; i < argc; i++) { if (argv[i][1] == 'P') argp = argv[i]; else if (argv[i][1] == '#') argn = argv[i]; } } lept_rm(NULL, "print_image.ps"); if ((pixs = pixRead(filein)) == NULL) return ERROR_INT("pixs not made", mainName, 1); pixGetDimensions(pixs, &w, &h, NULL); if (w > h) { pixt = pixRotate90(pixs, 1); pixGetDimensions(pixt, &w, &h, NULL); } else { pixt = pixClone(pixs); } scale = L_MIN(FILL_FACTOR * 2550 / w, FILL_FACTOR * 3300 / h); fname = genPathname("/tmp", "print_image.ps"); fp = lept_fopen(fname, "wb+"); pixWriteStreamPS(fp, pixt, NULL, 300, scale); lept_fclose(fp); /* print it out */ if (argp && !argn) { sprintf(buffer, "lpr %s %s &", argp, fname); ignore = system(buffer); } else if (!argp && argn) { sprintf(buffer, "lpr %s %s &", argn, fname); ignore = system(buffer); } else if (argp && argn) { sprintf(buffer, "lpr %s %s %s &", argp, argn, fname); ignore = system(buffer); } lept_free(fname); pixDestroy(&pixs); pixDestroy(&pixt); return 0; }
int main(int argc, char **argv) { char *filein, *fname, *printer; char buf[512]; l_int32 nx, ny, i, w, h, ws, hs, n, ignore; l_float32 scale; FILE *fp; PIX *pixs, *pixt, *pixr; PIXA *pixa; SARRAY *sa; static char mainName[] = "printsplitimage"; if (argc != 4 && argc != 5) return ERROR_INT(" Syntax: printsplitimage filein nx ny [printer]", mainName, 1); filein = argv[1]; nx = atoi(argv[2]); ny = atoi(argv[3]); if (argc == 5) printer = argv[4]; lept_rmdir("split"); lept_mkdir("split"); if ((pixs = pixRead(filein)) == NULL) return ERROR_INT("pixs not made", mainName, 1); pixGetDimensions(pixs, &ws, &hs, NULL); if (ny * ws > nx * hs) { pixr = pixRotate90(pixs, 1); pixa = pixaSplitPix(pixr, ny, nx, 0, 0); } else { pixr = pixClone(pixs); pixa = pixaSplitPix(pixr, nx, ny, 0, 0); } pixDestroy(&pixr); n = pixaGetCount(pixa); sa = sarrayCreate(n); for (i = 0; i < n; i++) { pixt = pixaGetPix(pixa, i, L_CLONE); pixGetDimensions(pixt, &w, &h, NULL); scale = L_MIN(FILL_FACTOR * 2550 / w, FILL_FACTOR * 3300 / h); sprintf(buf, "image%d.ps", i); fname = genPathname("/tmp/split", buf); fprintf(stderr, "fname: %s\n", fname); sarrayAddString(sa, fname, L_INSERT); fp = lept_fopen(fname, "wb+"); pixWriteStreamPS(fp, pixt, NULL, 300, scale); lept_fclose(fp); pixDestroy(&pixt); } if (argc == 5) { for (i = 0; i < n; i++) { fname = sarrayGetString(sa, i, L_NOCOPY); sprintf(buf, "lpr -P%s %s &", printer, fname); ignore = system(buf); } } sarrayDestroy(&sa); pixaDestroy(&pixa); pixDestroy(&pixs); return 0; }