Leptonica 1.68
C Image Processing Library

rotatetest2.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  *   rotatetest2.c
00018  *
00019  */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include "allheaders.h"
00024 
00025 #define   BINARY_IMAGE        "test1.png"
00026 #define   GRAYSCALE_IMAGE     "test8.jpg"
00027 #define   FOUR_BPP_IMAGE      "weasel4.8g.png"
00028 #define   COLORMAP_IMAGE      "dreyfus8.png"
00029 #define   RGB_IMAGE           "marge.jpg"
00030 
00031 static const l_int32    MODSIZE = 7;  /* set to 7 for display */
00032 
00033 static const l_float32  ANGLE1 = 3.14159265 / 12;
00034 static const l_int32    NTIMES = 24;
00035 
00036 void rotateTest(const char *fname, PIXA *pixa);
00037 
00038 
00039 main(int    argc,
00040      char **argv)
00041 {
00042 PIX         *pixd;
00043 PIXA        *pixa;
00044 static char  mainName[] = "rotatetest2";
00045 
00046     if (argc != 1)
00047         exit(ERROR_INT(" Syntax:  rotatetest2", mainName, 1));
00048 
00049     pixa = pixaCreate(0);
00050 
00051     fprintf(stderr, "Test binary image:\n");
00052     rotateTest((char *)BINARY_IMAGE, pixa);
00053     fprintf(stderr, "Test 4 bpp colormapped image:\n");
00054     rotateTest((char *)FOUR_BPP_IMAGE, pixa);
00055     fprintf(stderr, "Test grayscale image:\n");
00056     rotateTest((char *)GRAYSCALE_IMAGE, pixa);
00057     fprintf(stderr, "Test colormap image:\n");
00058     rotateTest((char *)COLORMAP_IMAGE, pixa);
00059     fprintf(stderr, "Test rgb image:\n");
00060     rotateTest((char *)RGB_IMAGE, pixa);
00061 
00062         /* Display results */
00063     pixd = pixaDisplay(pixa, 0, 0);
00064     pixDisplay(pixd, 100, 100);
00065     pixWrite("/tmp/junkrot2.jpg", pixd, IFF_JFIF_JPEG);
00066     pixDestroy(&pixd);
00067     pixaDestroy(&pixa);
00068 
00069     return 0;
00070 }
00071 
00072 
00073 void
00074 rotateTest(const char *fname,
00075            PIXA       *pixa)
00076 {
00077 l_int32   w, h, d, i;
00078 PIX      *pixs, *pixt, *pixd1, *pixd2;
00079 PIXCMAP  *cmap;
00080 
00081     PROCNAME("rotateTest");
00082 
00083     if ((pixs = pixRead(fname)) == NULL) {
00084         L_ERROR("pixs not read", procName);
00085         return;
00086     }
00087 
00088     pixGetDimensions(pixs, &w, &h, &d);
00089     cmap = pixGetColormap(pixs);
00090     pixd1 = pixRotate(pixs, ANGLE1, L_ROTATE_SHEAR, L_BRING_IN_WHITE, w, h);
00091     for (i = 1; i < NTIMES; i++) {
00092         if (((i + MODSIZE - 1) % MODSIZE) == 0)
00093             pixSaveTiledOutline(pixd1, pixa, 1, (i == 1) ? 1 : 0, 20, 2, 32);
00094         pixt = pixRotate(pixd1, ANGLE1, L_ROTATE_SHEAR,
00095                          L_BRING_IN_WHITE, w, h);
00096         pixDestroy(&pixd1);
00097         pixd1 = pixt;
00098     }
00099 
00100     pixd2 = pixRotate(pixs, ANGLE1, L_ROTATE_AREA_MAP, L_BRING_IN_WHITE, w, h);
00101     for (i = 1; i < NTIMES; i++) {
00102         if (((i + MODSIZE - 1) % MODSIZE) == 0)
00103             pixSaveTiledOutline(pixd2, pixa, 1, (i == 1) ? 1 : 0, 20, 2, 32);
00104         pixt = pixRotate(pixd2, ANGLE1, L_ROTATE_AREA_MAP,
00105                          L_BRING_IN_WHITE, w, h);
00106         pixDestroy(&pixd2);
00107         pixd2 = pixt;
00108     }
00109 
00110     if (d == 1) {
00111         pixWrite("/tmp/junkbin1", pixd1, IFF_PNG);
00112         pixWrite("/tmp/junkbin2", pixd2, IFF_PNG);
00113     } else if (cmap) {
00114         pixWrite("/tmp/junkcmap1", pixd1, IFF_PNG);
00115         pixWrite("/tmp/junkcmap2", pixd2, IFF_PNG);
00116     } else if (d == 8) {
00117         pixWrite("/tmp/junkgray1", pixd1, IFF_JFIF_JPEG);
00118         pixWrite("/tmp/junkgray2", pixd2, IFF_JFIF_JPEG);
00119     } else if (d == 32) {
00120         pixWrite("/tmp/junkrgb1", pixd1, IFF_JFIF_JPEG);
00121         pixWrite("/tmp/junkrgb2", pixd2, IFF_JFIF_JPEG);
00122     }
00123 
00124     pixDestroy(&pixd1);
00125     pixDestroy(&pixd2);
00126     pixDestroy(&pixs);
00127     return;
00128 }
00129 
00130 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines