Leptonica 1.68
C Image Processing Library

rotate1_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  *   rotate1_reg.c
00018  *
00019  *    Regression test for rotation by shear and area mapping.
00020  *    Displays results when images are rotated sequentially multiple times.
00021  */
00022 
00023 #include "allheaders.h"
00024 
00025 #define   BINARY_IMAGE              "test1.png"
00026 #define   TWO_BPP_IMAGE             "weasel2.4c.png"
00027 #define   FOUR_BPP_IMAGE1           "weasel4.11c.png"
00028 #define   FOUR_BPP_IMAGE2           "weasel4.16g.png"
00029 #define   EIGHT_BPP_IMAGE           "test8.jpg"
00030 #define   EIGHT_BPP_CMAP_IMAGE1     "dreyfus8.png"
00031 #define   EIGHT_BPP_CMAP_IMAGE2     "test24.jpg"
00032 #define   RGB_IMAGE                 "marge.jpg"
00033 
00034 static const l_int32    MODSIZE = 11;  /* set to 11 for display */
00035 
00036 static const l_float32  ANGLE1 = 3.14159265 / 12.;
00037 static const l_float32  ANGLE2 = 3.14159265 / 120.;
00038 static const l_int32    NTIMES = 24;
00039 
00040 static void RotateTest(PIX *pixs, l_int32 reduction, L_REGPARAMS *rp);
00041 
00042 
00043 l_int32 main(int    argc,
00044              char **argv)
00045 {
00046 PIX          *pixs, *pixd;
00047 L_REGPARAMS  *rp;
00048 
00049     if (regTestSetup(argc, argv, &rp))
00050         return 1;
00051 
00052     fprintf(stderr, "Test binary image:\n");
00053     pixs = pixRead(BINARY_IMAGE);
00054     RotateTest(pixs, 1, rp);
00055     pixDestroy(&pixs);
00056 
00057     fprintf(stderr, "Test 2 bpp cmapped image with filled cmap:\n");
00058     pixs = pixRead(TWO_BPP_IMAGE);
00059     RotateTest(pixs, 1, rp);
00060     pixDestroy(&pixs);
00061 
00062     fprintf(stderr, "Test 4 bpp cmapped image with unfilled cmap:\n");
00063     pixs = pixRead(FOUR_BPP_IMAGE1);
00064     RotateTest(pixs, 1, rp);
00065     pixDestroy(&pixs);
00066 
00067     fprintf(stderr, "Test 4 bpp cmapped image with filled cmap:\n");
00068     pixs = pixRead(FOUR_BPP_IMAGE2);
00069     RotateTest(pixs, 1, rp);
00070     pixDestroy(&pixs);
00071 
00072     fprintf(stderr, "Test 8 bpp grayscale image:\n");
00073     pixs = pixRead(EIGHT_BPP_IMAGE);
00074     RotateTest(pixs, 1, rp);
00075     pixDestroy(&pixs);
00076 
00077     fprintf(stderr, "Test 8 bpp grayscale cmap image:\n");
00078     pixs = pixRead(EIGHT_BPP_CMAP_IMAGE1);
00079     RotateTest(pixs, 1, rp);
00080     pixDestroy(&pixs);
00081 
00082     fprintf(stderr, "Test 8 bpp color cmap image:\n");
00083     pixs = pixRead(EIGHT_BPP_CMAP_IMAGE2);
00084     pixd = pixOctreeColorQuant(pixs, 200, 0);
00085     RotateTest(pixs, 4, rp);
00086     pixDestroy(&pixs);
00087     pixDestroy(&pixd);
00088 
00089     fprintf(stderr, "Test rgb image:\n");
00090     pixs = pixRead(RGB_IMAGE);
00091     RotateTest(pixs, 1, rp);
00092     pixDestroy(&pixs);
00093 
00094     regTestCleanup(rp);
00095     return 0;
00096 }
00097 
00098 
00099 static void
00100 RotateTest(PIX          *pixs,
00101            l_int32       reduction,
00102            L_REGPARAMS  *rp)
00103 {
00104 l_int32   w, h, d, i, outformat;
00105 PIX      *pixt, *pixd;
00106 PIXA     *pixa;
00107 PIXCMAP  *cmap;
00108 
00109     pixa = pixaCreate(0);
00110     pixGetDimensions(pixs, &w, &h, &d);
00111     outformat = (d == 8 || d == 32) ? IFF_JFIF_JPEG : IFF_PNG;
00112     cmap = pixGetColormap(pixs);
00113     pixd = pixRotate(pixs, ANGLE1, L_ROTATE_SHEAR, L_BRING_IN_WHITE, w, h);
00114     for (i = 1; i < NTIMES; i++) {
00115         if ((i % MODSIZE) == 0) {
00116             if (i == MODSIZE) {
00117                 pixSaveTiled(pixd, pixa, reduction, 1, 20, 32);
00118                 regTestWritePixAndCheck(rp, pixd, outformat);
00119             } else {
00120                 pixSaveTiled(pixd, pixa, reduction, 0, 20, 32);
00121                 regTestWritePixAndCheck(rp, pixd, outformat);
00122             }
00123         }
00124         pixt = pixRotate(pixd, ANGLE1, L_ROTATE_SHEAR,
00125                          L_BRING_IN_WHITE, w, h);
00126         pixDestroy(&pixd);
00127         pixd = pixt;
00128     }
00129     pixDestroy(&pixd);
00130 
00131     pixd = pixRotate(pixs, ANGLE1, L_ROTATE_SAMPLING, L_BRING_IN_WHITE, w, h);
00132     for (i = 1; i < NTIMES; i++) {
00133         if ((i % MODSIZE) == 0) {
00134             if (i == MODSIZE) {
00135                 pixSaveTiled(pixd, pixa, reduction, 1, 20, 32);
00136                 regTestWritePixAndCheck(rp, pixd, outformat);
00137             } else {
00138                 pixSaveTiled(pixd, pixa, reduction, 0, 20, 32);
00139                 regTestWritePixAndCheck(rp, pixd, outformat);
00140             }
00141         }
00142         pixt = pixRotate(pixd, ANGLE1, L_ROTATE_SAMPLING,
00143                          L_BRING_IN_WHITE, w, h);
00144         pixDestroy(&pixd);
00145         pixd = pixt;
00146     }
00147     pixDestroy(&pixd);
00148 
00149     pixd = pixRotate(pixs, ANGLE1, L_ROTATE_AREA_MAP, L_BRING_IN_WHITE, w, h);
00150     for (i = 1; i < NTIMES; i++) {
00151         if ((i % MODSIZE) == 0) {
00152             if (i == MODSIZE) {
00153                 pixSaveTiled(pixd, pixa, reduction, 1, 20, 32);
00154                 regTestWritePixAndCheck(rp, pixd, outformat);
00155             } else {
00156                 pixSaveTiled(pixd, pixa, reduction, 0, 20, 32);
00157                 regTestWritePixAndCheck(rp, pixd, outformat);
00158             }
00159         }
00160         pixt = pixRotate(pixd, ANGLE1, L_ROTATE_AREA_MAP,
00161                          L_BRING_IN_WHITE, w, h);
00162         pixDestroy(&pixd);
00163         pixd = pixt;
00164     }
00165     pixDestroy(&pixd);
00166 
00167     pixd = pixRotateAMCorner(pixs, ANGLE2, L_BRING_IN_WHITE);
00168     for (i = 1; i < NTIMES; i++) {
00169         if ((i % MODSIZE) == 0) {
00170             if (i == MODSIZE) {
00171                 pixSaveTiled(pixd, pixa, reduction, 1, 20, 32);
00172                 regTestWritePixAndCheck(rp, pixd, outformat);
00173             } else {
00174                 pixSaveTiled(pixd, pixa, reduction, 0, 20, 32);
00175                 regTestWritePixAndCheck(rp, pixd, outformat);
00176             }
00177         }
00178         pixt = pixRotateAMCorner(pixd, ANGLE2, L_BRING_IN_WHITE);
00179         pixDestroy(&pixd);
00180         pixd = pixt;
00181     }
00182     pixDestroy(&pixd);
00183 
00184     if (d == 32) {
00185         pixd = pixRotateAMColorFast(pixs, ANGLE1, 0xb0ffb000);
00186         for (i = 1; i < NTIMES; i++) {
00187             if ((i % MODSIZE) == 0) {
00188                 if (i == MODSIZE) {
00189                     pixSaveTiled(pixd, pixa, reduction, 1, 20, 32);
00190                     regTestWritePixAndCheck(rp, pixd, outformat);
00191                 } else {
00192                     pixSaveTiled(pixd, pixa, reduction, 0, 20, 32);
00193                     regTestWritePixAndCheck(rp, pixd, outformat);
00194                 }
00195             }
00196             pixt = pixRotateAMColorFast(pixd, ANGLE1, 0xb0ffb000);
00197             pixDestroy(&pixd);
00198             pixd = pixt;
00199         }
00200     }
00201     pixDestroy(&pixd);
00202 
00203     pixd = pixaDisplay(pixa, 0, 0);
00204     pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00205     pixDestroy(&pixd);
00206     pixaDestroy(&pixa);
00207     return;
00208 }
00209 
00210 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines