Leptonica 1.68
C Image Processing Library

shear_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  *   shear_reg.c
00018  *
00019  *    Regression test for shear, both IP and to new pix.
00020  */
00021 
00022 #include "allheaders.h"
00023 
00024 #define   BINARY_IMAGE              "test1.png"
00025 #define   TWO_BPP_IMAGE             "weasel2.4c.png"
00026 #define   FOUR_BPP_IMAGE1           "weasel4.11c.png"
00027 #define   FOUR_BPP_IMAGE2           "weasel4.16g.png"
00028 #define   EIGHT_BPP_IMAGE           "test8.jpg"
00029 #define   EIGHT_BPP_CMAP_IMAGE1     "dreyfus8.png"
00030 #define   EIGHT_BPP_CMAP_IMAGE2     "test24.jpg"
00031 #define   RGB_IMAGE                 "marge.jpg"
00032 
00033 static PIX *shearTest(PIX *pixs, l_int32 reduction);
00034 
00035 static const l_float32  ANGLE1 = 3.14159265 / 12.;
00036 
00037 
00038 l_int32 main(int    argc,
00039              char **argv)
00040 {
00041 l_int32       index;
00042 PIX          *pixs, *pixc, *pixd;
00043 PIXCMAP      *cmap;
00044 L_REGPARAMS  *rp;
00045 
00046     if (regTestSetup(argc, argv, &rp))
00047         return 1;
00048 
00049     fprintf(stderr, "Test binary image:\n");
00050     pixs = pixRead(BINARY_IMAGE);
00051     pixd = shearTest(pixs, 1);
00052     regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 0 */
00053     pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00054     pixDestroy(&pixs);
00055     pixDestroy(&pixd);
00056 
00057         /* We change the black to dark red so that we can see
00058          * that the IP shear does brings in that color.  It
00059          * can't bring in black because the cmap is filled. */
00060     fprintf(stderr, "Test 2 bpp cmapped image with filled cmap:\n");
00061     pixs = pixRead(TWO_BPP_IMAGE);
00062     cmap = pixGetColormap(pixs);
00063     pixcmapGetIndex(cmap, 40, 44, 40, &index);
00064     pixcmapResetColor(cmap, index, 100, 0, 0);
00065     pixd = shearTest(pixs, 1);
00066     regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 1 */
00067     pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00068     pixDestroy(&pixs);
00069     pixDestroy(&pixd);
00070 
00071     fprintf(stderr, "Test 4 bpp cmapped image with unfilled cmap:\n");
00072     pixs = pixRead(FOUR_BPP_IMAGE1);
00073     pixd = shearTest(pixs, 1);
00074     regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 2 */
00075     pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00076     pixDestroy(&pixs);
00077     pixDestroy(&pixd);
00078 
00079     fprintf(stderr, "Test 4 bpp cmapped image with filled cmap:\n");
00080     pixs = pixRead(FOUR_BPP_IMAGE2);
00081     pixd = shearTest(pixs, 1);
00082     regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 3 */
00083     pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00084     pixDestroy(&pixs);
00085     pixDestroy(&pixd);
00086 
00087     fprintf(stderr, "Test 8 bpp grayscale image:\n");
00088     pixs = pixRead(EIGHT_BPP_IMAGE);
00089     pixd = shearTest(pixs, 2);
00090     regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG);  /* 4 */
00091     pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00092     pixDestroy(&pixs);
00093     pixDestroy(&pixd);
00094 
00095     fprintf(stderr, "Test 8 bpp grayscale cmap image:\n");
00096     pixs = pixRead(EIGHT_BPP_CMAP_IMAGE1);
00097     pixd = shearTest(pixs, 1);
00098     regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 5 */
00099     pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00100     pixDestroy(&pixs);
00101     pixDestroy(&pixd);
00102 
00103     fprintf(stderr, "Test 8 bpp color cmap image:\n");
00104     pixs = pixRead(EIGHT_BPP_CMAP_IMAGE2);
00105     pixd = pixOctreeColorQuant(pixs, 200, 0);
00106     pixc = shearTest(pixd, 3);
00107     regTestWritePixAndCheck(rp, pixc, IFF_JFIF_JPEG);  /* 6 */
00108     pixDisplayWithTitle(pixc, 100, 100, NULL, rp->display);
00109     pixDestroy(&pixs);
00110     pixDestroy(&pixd);
00111     pixDestroy(&pixc);
00112 
00113     fprintf(stderr, "Test rgb image:\n");
00114     pixs = pixRead(RGB_IMAGE);
00115     pixd = shearTest(pixs, 2);
00116     regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG);  /* 7 */
00117     pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00118     pixDestroy(&pixs);
00119     pixDestroy(&pixd);
00120 
00121     regTestCleanup(rp);
00122     return 0;
00123 }
00124 
00125 
00126 static PIX *
00127 shearTest(PIX     *pixs,
00128           l_int32  reduction)
00129 {
00130 l_int32   w, h, d;
00131 PIX      *pixt1, *pixt2, *pixd;
00132 PIXA     *pixa;
00133 
00134     PROCNAME("shearTest");
00135 
00136     pixa = pixaCreate(0);
00137     pixGetDimensions(pixs, &w, &h, &d);
00138 
00139     pixt1 = pixHShear(NULL, pixs, 0, ANGLE1, L_BRING_IN_WHITE);
00140     pixSaveTiled(pixt1, pixa, reduction, 1, 20, 32);
00141     pixt2 = pixHShear(NULL, pixs, h / 2, ANGLE1, L_BRING_IN_WHITE);
00142     pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00143     pixDestroy(&pixt1);
00144     pixDestroy(&pixt2);
00145     pixt1 = pixHShear(NULL, pixs, 0, ANGLE1, L_BRING_IN_BLACK);
00146     pixSaveTiled(pixt1, pixa, reduction, 0, 20, 0);
00147     pixt2 = pixHShear(NULL, pixs, h / 2, ANGLE1, L_BRING_IN_BLACK);
00148     pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00149     pixDestroy(&pixt1);
00150     pixDestroy(&pixt2);
00151 
00152     if (!pixGetColormap(pixs)) {
00153         pixt1 = pixCopy(NULL, pixs);
00154         pixHShearIP(pixt1, 0, ANGLE1, L_BRING_IN_WHITE);
00155         pixSaveTiled(pixt1, pixa, reduction, 1, 20, 0);
00156         pixt2 = pixCopy(NULL, pixs);
00157         pixHShearIP(pixt2, h / 2, ANGLE1, L_BRING_IN_WHITE);
00158         pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00159         pixDestroy(&pixt1);
00160         pixDestroy(&pixt2);
00161         pixt1 = pixCopy(NULL, pixs);
00162         pixHShearIP(pixt1, 0, ANGLE1, L_BRING_IN_BLACK);
00163         pixSaveTiled(pixt1, pixa, reduction, 0, 20, 0);
00164         pixt2 = pixCopy(NULL, pixs);
00165         pixHShearIP(pixt2, h / 2, ANGLE1, L_BRING_IN_BLACK);
00166         pixSaveTiled(pixt2, pixa, reduction, 0, 20, 32);
00167         pixDestroy(&pixt1);
00168         pixDestroy(&pixt2);
00169     }
00170 
00171     if (d == 8 || d == 32 || pixGetColormap(pixs)) {
00172         pixt1 = pixHShearLI(pixs, 0, ANGLE1, L_BRING_IN_WHITE);
00173         pixSaveTiled(pixt1, pixa, reduction, 1, 20, 0);
00174         pixt2 = pixHShearLI(pixs, w / 2, ANGLE1, L_BRING_IN_WHITE);
00175         pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00176         pixDestroy(&pixt1);
00177         pixDestroy(&pixt2);
00178         pixt1 = pixHShearLI(pixs, 0, ANGLE1, L_BRING_IN_BLACK);
00179         pixSaveTiled(pixt1, pixa, reduction, 0, 20, 0);
00180         pixt2 = pixHShearLI(pixs, w / 2, ANGLE1, L_BRING_IN_BLACK);
00181         pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00182         pixDestroy(&pixt1);
00183         pixDestroy(&pixt2);
00184     }
00185 
00186     pixt1 = pixVShear(NULL, pixs, 0, ANGLE1, L_BRING_IN_WHITE);
00187     pixSaveTiled(pixt1, pixa, reduction, 1, 20, 0);
00188     pixt2 = pixVShear(NULL, pixs, w / 2, ANGLE1, L_BRING_IN_WHITE);
00189     pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00190     pixDestroy(&pixt1);
00191     pixDestroy(&pixt2);
00192     pixt1 = pixVShear(NULL, pixs, 0, ANGLE1, L_BRING_IN_BLACK);
00193     pixSaveTiled(pixt1, pixa, reduction, 0, 20, 0);
00194     pixt2 = pixVShear(NULL, pixs, w / 2, ANGLE1, L_BRING_IN_BLACK);
00195     pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00196     pixDestroy(&pixt1);
00197     pixDestroy(&pixt2);
00198 
00199     if (!pixGetColormap(pixs)) {
00200         pixt1 = pixCopy(NULL, pixs);
00201         pixVShearIP(pixt1, 0, ANGLE1, L_BRING_IN_WHITE);
00202         pixSaveTiled(pixt1, pixa, reduction, 1, 20, 0);
00203         pixt2 = pixCopy(NULL, pixs);
00204         pixVShearIP(pixt2, w / 2, ANGLE1, L_BRING_IN_WHITE);
00205         pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00206         pixDestroy(&pixt1);
00207         pixDestroy(&pixt2);
00208         pixt1 = pixCopy(NULL, pixs);
00209         pixVShearIP(pixt1, 0, ANGLE1, L_BRING_IN_BLACK);
00210         pixSaveTiled(pixt1, pixa, reduction, 0, 20, 0);
00211         pixt2 = pixCopy(NULL, pixs);
00212         pixVShearIP(pixt2, w / 2, ANGLE1, L_BRING_IN_BLACK);
00213         pixSaveTiled(pixt2, pixa, reduction, 0, 20, 32);
00214         pixDestroy(&pixt1);
00215         pixDestroy(&pixt2);
00216     }
00217 
00218     if (d == 8 || d == 32 || pixGetColormap(pixs)) {
00219         pixt1 = pixVShearLI(pixs, 0, ANGLE1, L_BRING_IN_WHITE);
00220         pixSaveTiled(pixt1, pixa, reduction, 1, 20, 0);
00221         pixt2 = pixVShearLI(pixs, w / 2, ANGLE1, L_BRING_IN_WHITE);
00222         pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00223         pixDestroy(&pixt1);
00224         pixDestroy(&pixt2);
00225         pixt1 = pixVShearLI(pixs, 0, ANGLE1, L_BRING_IN_BLACK);
00226         pixSaveTiled(pixt1, pixa, reduction, 0, 20, 0);
00227         pixt2 = pixVShearLI(pixs, w / 2, ANGLE1, L_BRING_IN_BLACK);
00228         pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00229         pixDestroy(&pixt1);
00230         pixDestroy(&pixt2);
00231     }
00232 
00233     pixd = pixaDisplay(pixa, 0, 0);
00234     pixaDestroy(&pixa);
00235     return pixd;
00236 }
00237 
00238 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines