Leptonica 1.68
C Image Processing Library

shear2_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  *   shear2_reg.c
00018  *
00019  *    Regression test for quadratic shear, both sampled and interpolated.
00020  */
00021 
00022 #include "allheaders.h"
00023 
00024 void PixSave(PIX **ppixs, PIXA *pixa, l_int32 newrow,
00025              L_BMF *bmf, const char *textstr);
00026 
00027 
00028 l_int32 main(int    argc,
00029              char **argv)
00030 {
00031 L_BMF        *bmf;
00032 PIX          *pixs1, *pixs2, *pixg, *pixt, *pixd;
00033 PIXA         *pixa;
00034 L_REGPARAMS  *rp;
00035 
00036     if (regTestSetup(argc, argv, &rp))
00037         return 1;
00038 
00039     bmf = bmfCreate("./fonts", 8);
00040     pixs1 = pixCreate(301, 301, 32);
00041     pixs2 = pixCreate(601, 601, 32);
00042     pixSetAll(pixs1);
00043     pixSetAll(pixs2);
00044     pixRenderLineArb(pixs1, 0, 20, 300, 20, 5, 0, 0, 255);
00045     pixRenderLineArb(pixs1, 0, 70, 300, 70, 5, 0, 255, 0);
00046     pixRenderLineArb(pixs1, 0, 120, 300, 120, 5, 0, 255, 255);
00047     pixRenderLineArb(pixs1, 0, 170, 300, 170, 5, 255, 0, 0);
00048     pixRenderLineArb(pixs1, 0, 220, 300, 220, 5, 255, 0, 255);
00049     pixRenderLineArb(pixs1, 0, 270, 300, 270, 5, 255, 255, 0);
00050     pixRenderLineArb(pixs2, 0, 20, 300, 20, 5, 0, 0, 255);
00051     pixRenderLineArb(pixs2, 0, 70, 300, 70, 5, 0, 255, 0);
00052     pixRenderLineArb(pixs2, 0, 120, 300, 120, 5, 0, 255, 255);
00053     pixRenderLineArb(pixs2, 0, 170, 300, 170, 5, 255, 0, 0);
00054     pixRenderLineArb(pixs2, 0, 220, 300, 220, 5, 255, 0, 255);
00055     pixRenderLineArb(pixs2, 0, 270, 300, 270, 5, 255, 255, 0);
00056 
00057         /* Color, small pix */
00058     pixa = pixaCreate(0);
00059     pixt = pixQuadraticVShear(pixs1, L_WARP_TO_LEFT,
00060                                    60, -20, L_SAMPLED, L_BRING_IN_WHITE);
00061     PixSave(&pixt, pixa, 1, bmf, "sampled-left");
00062     pixt = pixQuadraticVShear(pixs1, L_WARP_TO_RIGHT,
00063                                    60, -20, L_SAMPLED, L_BRING_IN_WHITE);
00064     PixSave(&pixt, pixa, 0, bmf, "sampled-right");
00065     pixt = pixQuadraticVShear(pixs1, L_WARP_TO_LEFT,
00066                                    60, -20, L_INTERPOLATED, L_BRING_IN_WHITE);
00067     PixSave(&pixt, pixa, 1, bmf, "interpolated-left");
00068     pixt = pixQuadraticVShear(pixs1, L_WARP_TO_RIGHT,
00069                                    60, -20, L_INTERPOLATED, L_BRING_IN_WHITE);
00070     PixSave(&pixt, pixa, 0, bmf, "interpolated-right");
00071     pixd = pixaDisplay(pixa, 0, 0);
00072     regTestWritePixAndCheck(rp, pixd, IFF_PNG);
00073     pixDisplayWithTitle(pixd, 50, 50, NULL, rp->display);
00074     pixDestroy(&pixd);
00075     pixaDestroy(&pixa);
00076 
00077         /* Grayscale, small pix */
00078     pixg = pixConvertTo8(pixs1, 0);
00079     pixa = pixaCreate(0);
00080     pixt = pixQuadraticVShear(pixg, L_WARP_TO_LEFT,
00081                                    60, -20, L_SAMPLED, L_BRING_IN_WHITE);
00082     PixSave(&pixt, pixa, 1, bmf, "sampled-left");
00083     pixt = pixQuadraticVShear(pixg, L_WARP_TO_RIGHT,
00084                                    60, -20, L_SAMPLED, L_BRING_IN_WHITE);
00085     PixSave(&pixt, pixa, 0, bmf, "sampled-right");
00086     pixt = pixQuadraticVShear(pixg, L_WARP_TO_LEFT,
00087                                    60, -20, L_INTERPOLATED, L_BRING_IN_WHITE);
00088     PixSave(&pixt, pixa, 1, bmf, "interpolated-left");
00089     pixt = pixQuadraticVShear(pixg, L_WARP_TO_RIGHT,
00090                                    60, -20, L_INTERPOLATED, L_BRING_IN_WHITE);
00091     PixSave(&pixt, pixa, 0, bmf, "interpolated-right");
00092     pixd = pixaDisplay(pixa, 0, 0);
00093     regTestWritePixAndCheck(rp, pixd, IFF_PNG);
00094     pixDisplayWithTitle(pixd, 250, 50, NULL, rp->display);
00095     pixDestroy(&pixg);
00096     pixDestroy(&pixd);
00097     pixaDestroy(&pixa);
00098 
00099         /* Color, larger pix */
00100     pixa = pixaCreate(0);
00101     pixt = pixQuadraticVShear(pixs2, L_WARP_TO_LEFT,
00102                               120, -40, L_SAMPLED, L_BRING_IN_WHITE);
00103     PixSave(&pixt, pixa, 1, bmf, "sampled-left");
00104     pixt = pixQuadraticVShear(pixs2, L_WARP_TO_RIGHT,
00105                               120, -40, L_SAMPLED, L_BRING_IN_WHITE);
00106     PixSave(&pixt, pixa, 0, bmf, "sampled-right");
00107     pixt = pixQuadraticVShear(pixs2, L_WARP_TO_LEFT,
00108                               120, -40, L_INTERPOLATED, L_BRING_IN_WHITE);
00109     PixSave(&pixt, pixa, 1, bmf, "interpolated-left");
00110     pixt = pixQuadraticVShear(pixs2, L_WARP_TO_RIGHT,
00111                               120, -40, L_INTERPOLATED, L_BRING_IN_WHITE);
00112     PixSave(&pixt, pixa, 0, bmf, "interpolated-right");
00113     pixd = pixaDisplay(pixa, 0, 0);
00114     regTestWritePixAndCheck(rp, pixd, IFF_PNG);
00115     pixDisplayWithTitle(pixd, 550, 50, NULL, rp->display);
00116     pixDestroy(&pixd);
00117     pixaDestroy(&pixa);
00118 
00119         /* Grayscale, larger pix */
00120     pixg = pixConvertTo8(pixs2, 0);
00121     pixa = pixaCreate(0);
00122     pixt = pixQuadraticVShear(pixg, L_WARP_TO_LEFT,
00123                               60, -20, L_SAMPLED, L_BRING_IN_WHITE);
00124     PixSave(&pixt, pixa, 1, bmf, "sampled-left");
00125     pixt = pixQuadraticVShear(pixg, L_WARP_TO_RIGHT,
00126                               60, -20, L_SAMPLED, L_BRING_IN_WHITE);
00127     PixSave(&pixt, pixa, 0, bmf, "sampled-right");
00128     pixt = pixQuadraticVShear(pixg, L_WARP_TO_LEFT,
00129                               60, -20, L_INTERPOLATED, L_BRING_IN_WHITE);
00130     PixSave(&pixt, pixa, 1, bmf, "interpolated-left");
00131     pixt = pixQuadraticVShear(pixg, L_WARP_TO_RIGHT,
00132                               60, -20, L_INTERPOLATED, L_BRING_IN_WHITE);
00133     PixSave(&pixt, pixa, 0, bmf, "interpolated-right");
00134     pixd = pixaDisplay(pixa, 0, 0);
00135     regTestWritePixAndCheck(rp, pixd, IFF_PNG);
00136     pixDisplayWithTitle(pixd, 850, 50, NULL, rp->display);
00137     pixDestroy(&pixg);
00138     pixDestroy(&pixd);
00139     pixaDestroy(&pixa);
00140 
00141     pixDestroy(&pixs1);
00142     pixDestroy(&pixs2);
00143     bmfDestroy(&bmf);
00144     regTestCleanup(rp);
00145     return 0;
00146 }
00147 
00148 
00149 void 
00150 PixSave(PIX        **ppixs,
00151         PIXA        *pixa,
00152         l_int32      newrow,
00153         L_BMF       *bmf,
00154         const char  *textstr)
00155 {
00156     PROCNAME("PixSave");
00157     if (!ppixs || !(*ppixs)) {
00158         L_ERROR("pixs not defined", procName);
00159         return;
00160     }
00161 
00162         /* Scaling is done after adding border pixels.  Therefore, to
00163          * avoid rescaling, add twice the border pixels to the target width */
00164     pixSaveTiledWithText(*ppixs, pixa, pixGetWidth(*ppixs) + 6,
00165                          newrow, 20, 3, bmf, textstr, 0xff000000, L_ADD_BELOW);
00166     pixDestroy(ppixs);
00167 }
00168 
00169   
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines