Leptonica 1.68
C Image Processing Library

printsplitimage.c

Go to the documentation of this file.
00001 /*====================================================================*
00002  -  Copyright (C) 2001 Leptonica.  All rights reserved.
00003  -  This software is distributed in the hope that it will be
00004  -  useful, but with NO WARRANTY OF ANY KIND.
00005  -  No author or distributor accepts responsibility to anyone for the
00006  -  consequences of using this software, or for whether it serves any
00007  -  particular purpose or works at all, unless he or she says so in
00008  -  writing.  Everyone is granted permission to copy, modify and
00009  -  redistribute this source code, for commercial or non-commercial
00010  -  purposes, with the following restrictions: (1) the origin of this
00011  -  source code must not be misrepresented; (2) modified versions must
00012  -  be plainly marked as such; and (3) this notice may not be removed
00013  -  or altered from any source or modified source distribution.
00014  *====================================================================*/
00015 
00016 /*
00017  * printsplitimage.c
00018  *
00019  *   Syntax:  printsplitimage filein nx ny [printer]
00020  *
00021  *        nx = number of horizontal tiles
00022  *        ny = number of vertical tiles
00023  *
00024  *   If printer is not specified, the only action is that the
00025  *   image is split into a set of tiles, and these are written
00026  *   out as a set of uncompressed (i.e., very large) level 1
00027  *   PostScript files.  The images in the PostScript files are
00028  *   scaled to each fill an 8.5 x 11 inch page, up to the
00029  *   FILLING_FACTOR fraction in each direction.
00030  *
00031  *   If printer is specified, these are printed on separate pages.
00032  *   We do this (separate, uncompressed PostScript pages) because
00033  *   this is the lowest common denominator: many PostScript printers
00034  *   will not print multi-page PostScript of images, or images that
00035  *   are level 2 compressed.  Hard to believe, but true.
00036  */
00037 
00038 #include "allheaders.h"
00039 
00040     /* fill factor on 8.5 x 11 inch output page */
00041 static const l_float32   FILL_FACTOR = 0.95;
00042 
00043 
00044 main(int    argc,
00045      char **argv)
00046 {
00047 char        *filein, *name, *printer;
00048 char         buffer[512];
00049 l_int32      nx, ny, i, w, h, ws, hs, n, ignore;
00050 l_float32    scale;
00051 FILE        *fp;
00052 PIX         *pixs, *pixt, *pixr;
00053 PIXA        *pixa;
00054 SARRAY      *sa;
00055 static char  mainName[] = "printsplitimage";
00056 
00057     if (argc != 4 && argc != 5)
00058         exit(ERROR_INT(" Syntax:  printsplitimage filein nx ny [printer]",
00059                        mainName, 1));
00060 
00061     filein = argv[1];
00062     nx = atoi(argv[2]);
00063     ny = atoi(argv[3]);
00064     if (argc == 5)
00065         printer = argv[4];
00066 
00067     ignore = system("rm -f /tmp/junk_print_image_*.ps");
00068 
00069     if ((pixs = pixRead(filein)) == NULL)
00070         exit(ERROR_INT("pixs not made", mainName, 1));
00071     ws = pixGetWidth(pixs);
00072     hs = pixGetHeight(pixs);
00073     if (ny * ws > nx * hs) {
00074         pixr = pixRotate90(pixs, 1);
00075         pixa = pixaSplitPix(pixr, ny, nx, 0, 0);
00076     }
00077     else {
00078         pixr = pixClone(pixs);
00079         pixa = pixaSplitPix(pixr, nx, ny, 0, 0);
00080     }
00081 
00082     n = pixaGetCount(pixa);
00083     sa = sarrayCreate(n);
00084     for (i = 0; i < n; i++) {
00085         pixt = pixaGetPix(pixa, i, L_CLONE);
00086         w = pixGetWidth(pixt);
00087         h = pixGetHeight(pixt);
00088         scale = L_MIN(FILL_FACTOR * 2550 / w, FILL_FACTOR * 3300 / h);
00089         sprintf(buffer, "/tmp/junk_print_image_%d.ps", i);
00090         fp = lept_fopen(buffer, "wb+");
00091         sarrayAddString(sa, buffer, 1);
00092         pixWriteStreamPS(fp, pixt, NULL, 300, scale);
00093         lept_fclose(fp);
00094         pixDestroy(&pixt);
00095     }
00096 
00097     if (argc == 5) {
00098         for (i = 0; i < n; i++) {
00099             name = sarrayGetString(sa, i, 0);
00100             sprintf(buffer, "lpr -P%s %s &", printer, name);
00101             ignore = system(buffer);
00102         }
00103     }
00104 
00105     sarrayDestroy(&sa);
00106     pixaDestroy(&pixa);
00107     pixDestroy(&pixr);
00108     pixDestroy(&pixs);
00109     return 0;
00110 }
00111 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines