1 /*====================================================================*
2  -  Copyright (C) 2001 Leptonica.  All rights reserved.
3  -
4  -  Redistribution and use in source and binary forms, with or without
5  -  modification, are permitted provided that the following conditions
6  -  are met:
7  -  1. Redistributions of source code must retain the above copyright
8  -     notice, this list of conditions and the following disclaimer.
9  -  2. Redistributions in binary form must reproduce the above
10  -     copyright notice, this list of conditions and the following
11  -     disclaimer in the documentation and/or other materials
12  -     provided with the distribution.
13  -
14  -  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  -  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  -  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  -  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ANY
18  -  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  -  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  -  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  -  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  -  OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  -  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  -  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *====================================================================*/
26 
27 /*
28  * displayboxa.c
29  *
30  *        displayboxa filein width fileout [fontdir]
31  *
32  *   This reads a boxa from file and generates a composite view of the
33  *   boxes, one per "page", tiled in rows.
34  *   The pix that backs each box is chosen to be the minimum size that
35  *   supports every box in the boxa.  Each pix (and the box it backs)
36  *   is scaled so that the pix width is @width in pixels.
37  *   If @fontdir is specified, the number of each box is written below it.
38  *
39  *   The minimum allowed width of the backing pix is 30, and the default
40  *   width is 100.
41  */
42 
43 #include "allheaders.h"
44 
main(int argc,char ** argv)45 int main(int    argc,
46          char **argv)
47 {
48 char        *filein, *fileout;
49 l_int32      w, h, width, sep;
50 l_float32    scalefact;
51 BOXA        *boxa1, *boxa2;
52 PIX         *pixd;
53 static char  mainName[] = "displayboxa";
54 
55     if (argc != 4) {
56         fprintf(stderr, "Syntax error in displayboxa:\n"
57            "   displayboxa filein width fileout\n");
58          return 1;
59     }
60     filein = argv[1];
61     width = atoi(argv[2]);
62     fileout = argv[3];
63     if (width < 30) {
64         L_ERROR("width too small; setting to 100\n", mainName);
65         width = 100;
66     }
67     setLeptDebugOK(1);
68 
69     if ((boxa1 = boxaRead(filein)) == NULL)
70         return ERROR_INT("boxa not made", mainName, 1);
71     boxaGetExtent(boxa1, &w, &h, NULL);
72     scalefact = (l_float32)width / (l_float32)w;
73     boxa2 = boxaTransform(boxa1, 0, 0, scalefact, scalefact);
74     sep = L_MIN(width / 5, 20);
75     pixd = boxaDisplayTiled(boxa2, NULL, 1500, 2, 1.0, 0, sep, 2);
76     pixWrite(fileout, pixd, IFF_PNG);
77     pixDisplay(pixd, 100, 100);
78 
79     boxaDestroy(&boxa1);
80     boxaDestroy(&boxa2);
81     pixDestroy(&pixd);
82     return 0;
83 }
84 
85