Leptonica 1.68
C Image Processing Library

scaleandtile.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  * scaleandtile.c
00018  *
00019  *    Generates a single image tiling of all images in a directory
00020  *    whose filename contains a given substring.  The filenames
00021  *    are filtered and sorted, and read into a pixa, which is
00022  *    then tiled into a pix at a specified depth, and finally
00023  *    written out to file.
00024  *
00025  *    Input:  dirin:  directory that has image files
00026  *            depth (output depth: 1, 8 or 32; use 32 for RGB)
00027  *            width (of each tile; all pix are scaled to the same width)
00028  *            ncols (number of tiles in each row)
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 <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038 #include "allheaders.h"
00039 
00040     /* Change these and recompile if necessary */
00041 static const l_int32  BACKGROUND_COLOR = 0;
00042 static const l_int32  SPACING = 25;  /* between images and on outside */
00043 static const l_int32  BLACK_BORDER = 2;  /* surrounding each image */
00044 
00045 
00046 main(int    argc,
00047      char **argv)
00048 {
00049 char        *dirin, *substr, *fileout;
00050 l_int32      depth, width, ncols;
00051 PIX         *pixd;
00052 PIXA        *pixa;
00053 static char  mainName[] = "scaleandtile";
00054 
00055     if (argc != 7)
00056         return ERROR_INT(
00057             "Syntax:  scaleandtile dirin substr depth width ncols fileout",
00058             mainName, 1);
00059 
00060     dirin = argv[1];
00061     substr = argv[2];
00062     depth = atoi(argv[3]);
00063     width = atoi(argv[4]);
00064     ncols = atoi(argv[5]);
00065     fileout = argv[6];
00066 
00067         /* Read the specified images from file */
00068     if ((pixa = pixaReadFiles(dirin, substr)) == NULL)
00069         return ERROR_INT("safiles not made", mainName, 1);
00070     fprintf(stderr, "Number of pix: %d\n", pixaGetCount(pixa));
00071 
00072         /* Tile them */
00073     pixd = pixaDisplayTiledAndScaled(pixa, depth, width, ncols,
00074                                      BACKGROUND_COLOR, SPACING, BLACK_BORDER);
00075 
00076     if (depth < 8)
00077         pixWrite(fileout, pixd, IFF_PNG);
00078     else
00079         pixWrite(fileout, pixd, IFF_JFIF_JPEG);
00080 
00081     pixaDestroy(&pixa);
00082     pixDestroy(&pixd);
00083     return 0;
00084 }
00085 
00086 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines