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  * arithtest.c
29  *
30  *   Test the pixacc functions, using an 8 bpp image and converting
31  *   back and forth between 8 and 16 bpp.
32  */
33 
34 #include "allheaders.h"
35 
main(int argc,char ** argv)36 int main(int    argc,
37          char **argv)
38 {
39 char        *filein;
40 l_int32      w, h;
41 PIX         *pixs, *pix1, *pix2, *pix3, *pix4, *pix5;
42 static char  mainName[] = "arithtest";
43 
44     if (argc != 2)
45         return ERROR_INT(" Syntax:  arithtest filein", mainName, 1);
46     filein = argv[1];
47 
48     setLeptDebugOK(1);
49     lept_mkdir("lept/arith");
50 
51     if ((pixs = pixRead(filein)) == NULL)
52         return ERROR_INT("pix not made", mainName, 1);
53 
54         /* Input a grayscale image and convert it to 16 bpp */
55     pixGetDimensions(pixs, &w, &h, NULL);
56     pix1 = pixInitAccumulate(w, h, 0);
57     pixAccumulate(pix1, pixs, L_ARITH_ADD);
58     pixMultConstAccumulate(pix1, 255., 0);
59     pix2 = pixFinalAccumulate(pix1, 0, 16);
60     l_pngSetReadStrip16To8(0);
61     pixWrite("/tmp/lept/arith/pix1.png", pix2, IFF_PNG);
62 
63         /* Convert it back to 8 bpp, linear mapped */
64     pix3 = pixMaxDynamicRange(pix2, L_LINEAR_SCALE);
65     pixWrite("/tmp/lept/arith/pix2.png", pix3, IFF_PNG);
66 
67         /* Convert it back to 8 bpp using the MSB */
68     pix4 = pixRead("/tmp/pix1.png");
69     pix5 = pixConvert16To8(pix4, 1);
70     pixWrite("/tmp/lept/arith/pix3.png", pix5, IFF_PNG);
71 
72     pixDestroy(&pixs);
73     pixDestroy(&pix1);
74     pixDestroy(&pix2);
75     pixDestroy(&pix3);
76     pixDestroy(&pix4);
77     pixDestroy(&pix5);
78     return 0;
79 }
80