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 * falsecolor_reg.c
29 *
30 * Test false color generation from 8 and 16 bpp gray
31 */
32
33 #include "allheaders.h"
34
35 static const l_float32 gamma[] = {1.0, 2.0, 3.0};
36
main(int argc,char ** argv)37 int main(int argc,
38 char **argv)
39 {
40 l_int32 i, j, val8, val16;
41 NUMA *na;
42 PIX *pix1, *pix8, *pix16, *pix8f, *pix16f;
43 PIXA *pixa;
44 L_REGPARAMS *rp;
45
46 if (regTestSetup(argc, argv, &rp))
47 return 1;
48
49 pix8 = pixCreate(768, 100, 8);
50 pix16 = pixCreate(768, 100, 16);
51 for (i = 0; i < 100; i++) {
52 for (j = 0; j < 768; j++) {
53 val16 = 0xffff * j / 768;
54 pixSetPixel(pix16, j, i, val16);
55 val8 = 0xff * j / 768;
56 pixSetPixel(pix8, j, i, val8);
57 }
58 }
59 regTestWritePixAndCheck(rp, pix8, IFF_PNG); /* 0 */
60 regTestWritePixAndCheck(rp, pix16, IFF_PNG); /* 1 */
61
62 pixa = pixaCreate(8);
63 pixaAddPix(pixa, pix8, L_INSERT);
64 for (i = 0; i < 3; i++) {
65 pix8f = pixConvertGrayToFalseColor(pix8, gamma[i]);
66 regTestWritePixAndCheck(rp, pix8f, IFF_PNG); /* 2 - 4 */
67 pixaAddPix(pixa, pix8f, L_INSERT);
68 }
69 pixaAddPix(pixa, pix16, L_INSERT);
70 for (i = 0; i < 3; i++) {
71 pix16f = pixConvertGrayToFalseColor(pix16, gamma[i]);
72 regTestWritePixAndCheck(rp, pix16f, IFF_PNG); /* 5 - 7 */
73 pixaAddPix(pixa, pix16f, L_INSERT);
74 }
75
76 if (rp->display) {
77 /* Use na to display them in column major order with 4 rows */
78 na = numaCreate(8);
79 for (i = 0; i < 8; i++)
80 numaAddNumber(na, i / 4);
81 pix1 = pixaDisplayTiledByIndex(pixa, na, 768, 20, 2, 6, 0xff000000);
82 pixDisplay(pix1, 100, 100);
83 numaDestroy(&na);
84 pixDestroy(&pix1);
85 }
86 pixaDestroy(&pixa);
87 return regTestCleanup(rp);
88 }
89
90