Leptonica 1.68
C Image Processing Library

translate_reg.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  * translate_reg.c
00018  *
00019  *    Regression test for in-place translation
00020  */
00021 
00022 #include "allheaders.h"
00023 
00024 #define   BINARY_IMAGE        "test1.png"
00025 #define   GRAYSCALE_IMAGE     "test8.jpg"
00026 #define   FOUR_BPP_IMAGE      "weasel4.8g.png"
00027 #define   COLORMAP_IMAGE      "dreyfus8.png"
00028 #define   RGB_IMAGE           "marge.jpg"
00029 
00030 void TranslateAndSave1(PIXA *pixa, l_int32 depth, PIX *pix,
00031                        l_int32 xshift, l_int32 yshift);
00032 
00033 void TranslateAndSave2(PIXA *pixa, PIX *pix, l_int32 xshift, l_int32 yshift);
00034 
00035 
00036 main(int    argc,
00037      char **argv)
00038 {
00039 BOX          *box;
00040 PIX          *pix, *pixs, *pixd;
00041 PIX          *pix1, *pix2, *pix3, *pix4, *pix5, *pix6, *pix7;
00042 PIXA         *pixa;
00043 L_REGPARAMS  *rp;
00044 
00045     if (regTestSetup(argc, argv, &rp))
00046         return 1;
00047 
00048         /* Set up images */
00049     pix1 = pixRead("weasel2.4c.png");
00050     pix2 = pixScaleBySampling(pix1, 3.0, 3.0);
00051     box = boxCreate(0, 0, 209, 214);
00052     pixs = pixClipRectangle(pix2, box, NULL);
00053     pixDestroy(&pix1);
00054     pixDestroy(&pix2);
00055     boxDestroy(&box);
00056     pix1 = pixRemoveColormap(pixs, REMOVE_CMAP_TO_GRAYSCALE);
00057     pix2 = pixRemoveColormap(pixs, REMOVE_CMAP_TO_FULL_COLOR);
00058     pix3 = pixConvertTo1(pixs, 128);
00059     pix4 = pixRotateAM(pix1, 0.25, L_BRING_IN_BLACK);
00060     pix5 = pixRotateAM(pix1, -0.25, L_BRING_IN_WHITE);
00061     pix6 = pixRotateAM(pix2, -0.15, L_BRING_IN_BLACK);
00062     pix7 = pixRotateAM(pix2, +0.15, L_BRING_IN_WHITE);
00063 
00064     pixa = pixaCreate(0);
00065     TranslateAndSave1(pixa, 32, pixs, 30, 30);
00066     TranslateAndSave1(pixa, 32, pix1, 35, 20);
00067     TranslateAndSave1(pixa, 32, pix2, 20, 35);
00068     TranslateAndSave1(pixa, 32, pix3, 20, 35);
00069     pixd = pixaDisplayOnColor(pixa, 0, 0, 0x44aaaa00);
00070     regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 0 */
00071     pixDisplayWithTitle(pixd, 0, 0, "trans0", rp->display);
00072     pixDestroy(&pixd);
00073     pixaDestroy(&pixa);
00074 
00075     pixa = pixaCreate(0);
00076     TranslateAndSave1(pixa, 8, pix1, 35, 20);
00077     TranslateAndSave1(pixa, 8, pix4, 35, 20);
00078     pixd = pixaDisplayOnColor(pixa, 0, 0, 0x44);
00079     regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 1 */
00080     pixDisplayWithTitle(pixd, 250, 0, "trans1", rp->display);
00081     pixDestroy(&pixd);
00082     pixaDestroy(&pixa);
00083 
00084     pixa = pixaCreate(0);
00085     TranslateAndSave2(pixa, pixs, 30, 30);
00086     TranslateAndSave2(pixa, pix1, 30, 30);
00087     TranslateAndSave2(pixa, pix2, 35, 20);
00088     TranslateAndSave2(pixa, pix3, 20, 35);
00089     TranslateAndSave2(pixa, pix4, 25, 25);
00090     TranslateAndSave2(pixa, pix5, 25, 25);
00091     TranslateAndSave2(pixa, pix6, 25, 25);
00092     TranslateAndSave2(pixa, pix7, 25, 25);
00093     pixd = pixaDisplayTiledInRows(pixa, 32, 1200, 1.0, 0, 30, 3);
00094     regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 2 */
00095     pixDisplayWithTitle(pixd, 500, 0, "trans2", rp->display);
00096     pixDestroy(&pixd);
00097     pixaDestroy(&pixa);
00098   
00099     regTestCleanup(rp);
00100     pixDestroy(&pixs);
00101     pixDestroy(&pix1);
00102     pixDestroy(&pix2);
00103     pixDestroy(&pix3);
00104     pixDestroy(&pix4);
00105     pixDestroy(&pix5);
00106     pixDestroy(&pix6);
00107     pixDestroy(&pix7);
00108     return 0;
00109 }
00110 
00111 
00112 void
00113 TranslateAndSave1(PIXA    *pixa,
00114                   l_int32  depth,
00115                   PIX     *pix,
00116                   l_int32  xshift,
00117                   l_int32  yshift)
00118 {
00119 PIX  *pix1, *pix2, *pix3, *pix4;
00120 
00121     pix1 = pixTranslate(NULL, pix, xshift, yshift, L_BRING_IN_WHITE);
00122     pix2 = pixTranslate(NULL, pix, xshift, yshift, L_BRING_IN_BLACK);
00123     pix3 = pixTranslate(NULL, pix, -xshift, -yshift, L_BRING_IN_WHITE);
00124     pix4 = pixTranslate(NULL, pix, -xshift, -yshift, L_BRING_IN_BLACK);
00125     pixSaveTiled(pix1, pixa, 1, 1, 25, depth);
00126     pixSaveTiled(pix2, pixa, 1, 0, 25, depth);
00127     pixSaveTiled(pix3, pixa, 1, 0, 25, depth);
00128     pixSaveTiled(pix4, pixa, 1, 0, 25, depth);
00129     pixDestroy(&pix1);
00130     pixDestroy(&pix2);
00131     pixDestroy(&pix3);
00132     pixDestroy(&pix4);
00133     return;
00134 }
00135 
00136 void
00137 TranslateAndSave2(PIXA    *pixa,
00138                   PIX     *pix,
00139                   l_int32  xshift,
00140                   l_int32  yshift)
00141 {
00142 PIX  *pix1, *pix2, *pix3, *pix4;
00143 
00144     pix1 = pixTranslate(NULL, pix, xshift, yshift, L_BRING_IN_WHITE);
00145     pix2 = pixTranslate(NULL, pix, xshift, yshift, L_BRING_IN_BLACK);
00146     pix3 = pixTranslate(NULL, pix, -xshift, -yshift, L_BRING_IN_WHITE);
00147     pix4 = pixTranslate(NULL, pix, -xshift, -yshift, L_BRING_IN_BLACK);
00148     pixaAddPix(pixa, pix1, L_INSERT);
00149     pixaAddPix(pixa, pix2, L_INSERT);
00150     pixaAddPix(pixa, pix3, L_INSERT);
00151     pixaAddPix(pixa, pix4, L_INSERT);
00152     return;
00153 }
00154 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines