Leptonica 1.68
C Image Processing Library

maketile.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  * maketile.c
00018  *
00019  *    Generates a single image tiling of all images of a specific depth
00020  *    in a directory.  The tiled images are scaled by a specified
00021  *    isotropic scale factor.  One can also specify the approximate width
00022  *    of the output image file, and the background color that is between
00023  *    the tiled images.
00024  *
00025  *    Input:  dirin:  directory that has image files
00026  *            depth (use 32 for RGB)
00027  *            scale factor
00028  *            width (approx. width of output tiled image)
00029  *            background (0 for white, 1 for black)
00030  *            fileout:  output tiled image file
00031  *    
00032  *    Note: this program is Unix only; it will not compile under cygwin.
00033  */
00034 
00035 #include <string.h>
00036 #include "allheaders.h"
00037 
00038 main(int    argc,
00039      char **argv)
00040 {
00041 char        *dirin, *fileout, *fname, *fullname;
00042 l_int32      depth, width, background, i, index, nfiles, n;
00043 l_float32    scale;
00044 SARRAY      *safiles;
00045 PIX         *pix, *pixt, *pixd;
00046 PIXA        *pixa;
00047 static char  mainName[] = "maketile";
00048 
00049     if (argc != 7)
00050         exit(ERROR_INT(
00051             "Syntax:  maketile dirin depth scale width background fileout",
00052             mainName, 1));
00053 
00054     dirin = argv[1];
00055     depth = atoi(argv[2]);
00056     scale = atof(argv[3]);
00057     width = atoi(argv[4]);
00058     background = atoi(argv[5]);
00059     fileout = argv[6];
00060 
00061         /* capture the filenames in the input directory; ignore directories */
00062     if ((safiles = getFilenamesInDirectory(dirin)) == NULL)
00063         exit(ERROR_INT("safiles not made", mainName, 1));
00064 
00065         /* capture images with the requisite depth */
00066     nfiles = sarrayGetCount(safiles);
00067     pixa = pixaCreate(nfiles);
00068     for (i = 0, index = 0; i < nfiles; i++) {
00069         fname = sarrayGetString(safiles, i, 0);
00070         fullname = genPathname(dirin, fname);
00071         pix = pixRead(fullname);
00072         lept_free(fullname);
00073         if (!pix)
00074             continue;
00075         if (pixGetDepth(pix) != depth) {
00076             pixDestroy(&pix);
00077             continue;
00078         }
00079         if (pixGetHeight(pix) > 5000) {
00080             fprintf(stderr, "%s too tall\n", fname);
00081             continue;
00082         }
00083         pixt = pixScale(pix, scale, scale);
00084         pixaAddPix(pixa, pixt, L_INSERT);
00085         pixDestroy(&pix);
00086 /*        fprintf(stderr, "%d..", i); */
00087     }
00088     fprintf(stderr, "\n");
00089 
00090         /* tile them */
00091     pixd = pixaDisplayTiled(pixa, width, background, 15);
00092 
00093     if (depth < 8)
00094       pixWrite(fileout, pixd, IFF_PNG);
00095     else
00096       pixWrite(fileout, pixd, IFF_JFIF_JPEG);
00097 
00098     pixaDestroy(&pixa);
00099     pixDestroy(&pixd);
00100     sarrayDestroy(&safiles);
00101     return 0;
00102 }
00103 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines