Leptonica 1.68
C Image Processing Library
|
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 * printimage.c 00018 * 00019 * Syntax: printimage filein [-P<printer> [-#<number>] 00020 * 00021 * If you want the image printed, use the standard lpr flags 00022 * for either (or both) the printer and the number of copies. 00023 * 00024 * If neither a printer nor a number of copies is specified, the 00025 * only action is that a new PostScript file, 00026 * /tmp/junk_print_image.ps 00027 * is generated for the image. 00028 * 00029 * The PS file generated is level 1. This is large, but will work 00030 * on all PS printers. 00031 */ 00032 00033 #include "allheaders.h" 00034 00035 static const l_float32 FILL_FACTOR = 0.95; /* fill factor on 8.5 x 11 page */ 00036 00037 00038 main(int argc, 00039 char **argv) 00040 { 00041 char *filein, *argp, *argn; 00042 char buffer[512]; 00043 l_int32 i, w, h, ignore; 00044 l_float32 scale; 00045 FILE *fp; 00046 PIX *pixs, *pixt; 00047 static char mainName[] = "printimage"; 00048 00049 if (argc < 2 || argc > 4) 00050 return ERROR_INT( 00051 " Syntax: printimage filein [-P<printer>] [-#<number>]", 00052 mainName, 1); 00053 00054 /* parse args */ 00055 filein = argv[1]; 00056 argp = argn = NULL; 00057 if (argc > 2) { 00058 for (i = 2; i < argc; i++) { 00059 if (argv[i][1] == 'P') 00060 argp = argv[i]; 00061 else if (argv[i][1] == '#') 00062 argn = argv[i]; 00063 } 00064 } 00065 00066 lept_rm(NULL, "junk_print_image.ps"); 00067 00068 if ((pixs = pixRead(filein)) == NULL) 00069 return ERROR_INT("pixs not made", mainName, 1); 00070 00071 pixGetDimensions(pixs, &w, &h, NULL); 00072 if (w > h) { 00073 pixt = pixRotate90(pixs, 1); 00074 pixGetDimensions(pixt, &w, &h, NULL); 00075 } 00076 else 00077 pixt = pixClone(pixs); 00078 scale = L_MIN(FILL_FACTOR * 2550 / w, FILL_FACTOR * 3300 / h); 00079 fp = lept_fopen("/tmp/junk_print_image.ps", "wb+"); 00080 pixWriteStreamPS(fp, pixt, NULL, 300, scale); 00081 lept_fclose(fp); 00082 00083 /* print it out */ 00084 if (argp && !argn) { 00085 sprintf(buffer, "lpr %s /tmp/junk_print_image.ps &", argp); 00086 ignore = system(buffer); 00087 } 00088 else if (!argp && argn) { 00089 sprintf(buffer, "lpr %s /tmp/junk_print_image.ps &", argn); 00090 ignore = system(buffer); 00091 } 00092 else if (argp && argn) { 00093 sprintf(buffer, "lpr %s %s /tmp/junk_print_image.ps &", 00094 argp, argn); 00095 ignore = system(buffer); 00096 } 00097 00098 pixDestroy(&pixs); 00099 pixDestroy(&pixt); 00100 return 0; 00101 } 00102