Leptonica 1.68
C Image Processing Library

rotateorthtest1.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  * rotateorthtest1.c
00018  *
00019  *    Tests and timings for 90 and 180 degree rotations
00020  *        rotateorthtest1 filein fileout [direction]
00021  *    where
00022  *        direction = 1 for cw; -1 for ccw
00023  */
00024 
00025 #include "allheaders.h"
00026 
00027 #define  NTIMES   10
00028 
00029 
00030 main(int    argc,
00031      char **argv)
00032 {
00033 l_int32      i, w, h, dir;
00034 PIX         *pixs, *pixd, *pixt;
00035 l_float32    pops;
00036 char        *filein, *fileout;
00037 static char  mainName[] = "rotateorthtest1";
00038 
00039     if (argc != 3 && argc != 4)
00040         exit(ERROR_INT(" Syntax:  rotateorthtest1 filein fileout [direction]",
00041                mainName, 1));
00042 
00043     filein = argv[1];
00044     fileout = argv[2];
00045     if (argc == 4)
00046         dir = atoi(argv[3]);
00047     else
00048         dir = 1;
00049 
00050     if ((pixs = pixRead(filein)) == NULL)
00051         exit(ERROR_INT("pix not made", mainName, 1));
00052 
00053         /* Do a single operation */
00054 #if 1
00055     pixd = pixRotate90(pixs, dir);
00056 #elif 0
00057     pixd = pixRotate180(NULL, pixs);
00058 #elif 0
00059     pixd = pixRotateLR(NULL, pixs);
00060 #elif 0
00061     pixd = pixRotateTB(NULL, pixs);
00062 #endif
00063 
00064         /* Time rotate 90, allocating & destroying each time */
00065 #if 0
00066     startTimer();
00067     w = pixGetWidth(pixs);
00068     h = pixGetHeight(pixs);
00069     for (i = 0; i < NTIMES; i++) {
00070         pixd = pixRotate90(pixs, dir);
00071         pixDestroy(&pixd);
00072     }
00073     pops = (l_float32)(w * h * NTIMES) / stopTimer();
00074     fprintf(stderr, "MPops for 90 rotation: %7.3f\n", pops / 1000000.);
00075     pixd = pixRotate90(pixs, dir);
00076 #endif
00077 
00078         /* Time rotate 180, with no alloc/destroy */
00079 #if 0
00080     startTimer();
00081     w = pixGetWidth(pixs);
00082     h = pixGetHeight(pixs);
00083     pixd = pixCreateTemplate(pixs);
00084     for (i = 0; i < NTIMES; i++)
00085         pixRotate180(pixd, pixs);
00086     pops = (l_float32)(w * h * NTIMES) / stopTimer();
00087     fprintf(stderr, "MPops for 180 rotation: %7.3f\n", pops / 1000000.);
00088 #endif
00089 
00090 
00091         /* Test rotate 180 not in-place */
00092 #if 0
00093     pixt = pixRotate180(NULL, pixs);
00094     pixd = pixRotate180(NULL, pixt);
00095     pixEqual(pixs, pixd, &eq);
00096     if (eq) fprintf(stderr, "2 rots gives I\n");
00097     else fprintf(stderr, "2 rots fail to give I\n");
00098     pixDestroy(&pixt);
00099 #endif
00100 
00101        /* Test rotate 180 in-place */
00102 #if 0
00103     pixd = pixCopy(NULL, pixs);
00104     pixRotate180(pixd, pixd);
00105     pixRotate180(pixd, pixd);
00106     pixEqual(pixs, pixd, &eq);
00107     if (eq) fprintf(stderr, "2 rots gives I\n");
00108     else fprintf(stderr, "2 rots fail to give I\n");
00109 #endif
00110 
00111         /* Mix rotate 180 with LR/TB */
00112 #if 0
00113     pixd = pixRotate180(NULL, pixs);
00114     pixRotateLR(pixd, pixd);
00115     pixRotateTB(pixd, pixd);
00116     pixEqual(pixs, pixd, &eq);
00117     if (eq) fprintf(stderr, "180 rot OK\n");
00118     else fprintf(stderr, "180 rot error\n");
00119 #endif
00120 
00121     if (pixGetDepth(pixd) < 8)
00122         pixWrite(fileout, pixd, IFF_PNG);
00123     else
00124         pixWrite(fileout, pixd, IFF_JFIF_JPEG);
00125 
00126     pixDestroy(&pixs);
00127     pixDestroy(&pixd);
00128     exit(0);
00129 }
00130 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines