Leptonica 1.68
C Image Processing Library

rotate2_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  *   rotate2_reg.c
00018  *
00019  *    Regression test for rotation by shear, sampling and area mapping.
00020  *    Displays results from all the various types of rotations.
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_float32  ANGLE1 = 3.14159265 / 30.;
00035 static const l_float32  ANGLE2 = 3.14159265 / 7.;
00036 
00037 void RotateTest(PIX *pixs, l_int32 reduction, L_REGPARAMS *rp);
00038 
00039 
00040 main(int    argc,
00041      char **argv)
00042 {
00043 PIX          *pixs, *pixd;
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     RotateTest(pixs, 1, rp);
00052     pixDestroy(&pixs);
00053 
00054     fprintf(stderr, "Test 2 bpp cmapped image with filled cmap:\n");
00055     pixs = pixRead(TWO_BPP_IMAGE);
00056     RotateTest(pixs, 1, rp);
00057     pixDestroy(&pixs);
00058 
00059     fprintf(stderr, "Test 4 bpp cmapped image with unfilled cmap:\n");
00060     pixs = pixRead(FOUR_BPP_IMAGE1);
00061     RotateTest(pixs, 1, rp);
00062     pixDestroy(&pixs);
00063 
00064     fprintf(stderr, "Test 4 bpp cmapped image with filled cmap:\n");
00065     pixs = pixRead(FOUR_BPP_IMAGE2);
00066     RotateTest(pixs, 1, rp);
00067     pixDestroy(&pixs);
00068 
00069     fprintf(stderr, "Test 8 bpp grayscale image:\n");
00070     pixs = pixRead(EIGHT_BPP_IMAGE);
00071     RotateTest(pixs, 1, rp);
00072     pixDestroy(&pixs);
00073 
00074     fprintf(stderr, "Test 8 bpp grayscale cmap image:\n");
00075     pixs = pixRead(EIGHT_BPP_CMAP_IMAGE1);
00076     RotateTest(pixs, 1, rp);
00077     pixDestroy(&pixs);
00078 
00079     fprintf(stderr, "Test 8 bpp color cmap image:\n");
00080     pixs = pixRead(EIGHT_BPP_CMAP_IMAGE2);
00081     pixd = pixOctreeColorQuant(pixs, 200, 0);
00082     RotateTest(pixd, 2, rp);
00083     pixDestroy(&pixs);
00084     pixDestroy(&pixd);
00085 
00086     fprintf(stderr, "Test rgb image:\n");
00087     pixs = pixRead(RGB_IMAGE);
00088     RotateTest(pixs, 4, rp);
00089     pixDestroy(&pixs);
00090 
00091     regTestCleanup(rp);
00092     return 0;
00093 }
00094 
00095 
00096 void
00097 RotateTest(PIX          *pixs,
00098            l_int32       reduction,
00099            L_REGPARAMS  *rp)
00100 {
00101 l_int32   w, h, d, outformat;
00102 PIX      *pixt1, *pixt2, *pixt3, *pixd;
00103 PIXA     *pixa;
00104 
00105     pixGetDimensions(pixs, &w, &h, &d);
00106     outformat = (d == 8 || d == 32) ? IFF_JFIF_JPEG : IFF_PNG;
00107 
00108     pixa = pixaCreate(0);
00109     pixt1 = pixRotate(pixs, ANGLE1, L_ROTATE_SHEAR, L_BRING_IN_WHITE, w, h);
00110     pixSaveTiled(pixt1, pixa, reduction, 1, 20, 32);
00111     pixt2 = pixRotate(pixs, ANGLE1, L_ROTATE_SHEAR, L_BRING_IN_BLACK, w, h);
00112     pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00113     pixDestroy(&pixt1);
00114     pixDestroy(&pixt2);
00115     pixt1 = pixRotate(pixs, ANGLE1, L_ROTATE_SHEAR, L_BRING_IN_WHITE, 0, 0);
00116     pixSaveTiled(pixt1, pixa, reduction, 1, 20, 0);
00117     pixt2 = pixRotate(pixs, ANGLE1, L_ROTATE_SHEAR, L_BRING_IN_BLACK, 0, 0);
00118     pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00119     pixDestroy(&pixt1);
00120     pixDestroy(&pixt2);
00121     pixt1 = pixRotate(pixs, ANGLE2, L_ROTATE_SHEAR, L_BRING_IN_WHITE, w, h);
00122     pixSaveTiled(pixt1, pixa, reduction, 1, 20, 0);
00123     pixt2 = pixRotate(pixs, ANGLE2, L_ROTATE_SHEAR, L_BRING_IN_BLACK, w, h);
00124     pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00125     pixDestroy(&pixt1);
00126     pixDestroy(&pixt2);
00127     pixt1 = pixRotate(pixs, ANGLE2, L_ROTATE_SHEAR, L_BRING_IN_WHITE, 0, 0);
00128     pixSaveTiled(pixt1, pixa, reduction, 1, 20, 0);
00129     pixt2 = pixRotate(pixs, ANGLE2, L_ROTATE_SHEAR, L_BRING_IN_BLACK, 0, 0);
00130     pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00131     pixDestroy(&pixt1);
00132     pixDestroy(&pixt2);
00133     pixd = pixaDisplay(pixa, 0, 0);
00134     regTestWritePixAndCheck(rp, pixd, outformat);
00135     pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00136     pixDestroy(&pixd);
00137     pixaDestroy(&pixa);
00138 
00139     pixa = pixaCreate(0);
00140     pixt1 = pixRotate(pixs, ANGLE2, L_ROTATE_SAMPLING, L_BRING_IN_WHITE, w, h);
00141     pixSaveTiled(pixt1, pixa, reduction, 1, 20, 32);
00142     pixt2 = pixRotate(pixs, ANGLE2, L_ROTATE_SAMPLING, L_BRING_IN_BLACK, w, h);
00143     pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00144     pixDestroy(&pixt1);
00145     pixDestroy(&pixt2);
00146     pixt1 = pixRotate(pixs, ANGLE2, L_ROTATE_SAMPLING, L_BRING_IN_WHITE, 0, 0);
00147     pixSaveTiled(pixt1, pixa, reduction, 1, 20, 0);
00148     pixt2 = pixRotate(pixs, ANGLE2, L_ROTATE_SAMPLING, L_BRING_IN_BLACK, 0, 0);
00149     pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0);
00150     pixDestroy(&pixt1);
00151     pixDestroy(&pixt2);
00152 
00153     if (pixGetDepth(pixs) == 1)
00154         pixt1 = pixScaleToGray2(pixs);
00155     else
00156         pixt1 = pixClone(pixs);
00157     pixt2 = pixRotate(pixt1, ANGLE2, L_ROTATE_AREA_MAP, L_BRING_IN_WHITE, w, h);
00158     pixSaveTiled(pixt2, pixa, reduction, 1, 20, 0);
00159     pixt3 = pixRotate(pixt1, ANGLE2, L_ROTATE_AREA_MAP, L_BRING_IN_BLACK, w, h);
00160     pixSaveTiled(pixt3, pixa, reduction, 0, 20, 0);
00161     pixDestroy(&pixt2);
00162     pixDestroy(&pixt3);
00163     pixt2 = pixRotate(pixt1, ANGLE2, L_ROTATE_AREA_MAP, L_BRING_IN_WHITE, 0, 0);
00164     pixSaveTiled(pixt2, pixa, reduction, 1, 20, 0);
00165     pixt3 = pixRotate(pixt1, ANGLE2, L_ROTATE_AREA_MAP, L_BRING_IN_BLACK, 0, 0);
00166     pixSaveTiled(pixt3, pixa, reduction, 0, 20, 0);
00167     pixDestroy(&pixt2);
00168     pixDestroy(&pixt3);
00169     pixDestroy(&pixt1);
00170     pixd = pixaDisplay(pixa, 0, 0);
00171     regTestWritePixAndCheck(rp, pixd, outformat);
00172     pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00173     pixDestroy(&pixd);
00174     pixaDestroy(&pixa);
00175 
00176     return;
00177 }
00178 
00179 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines