File: rotateorth_reg.c

package info (click to toggle)
leptonlib 1.57-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 9,724 kB
  • ctags: 3,900
  • sloc: ansic: 89,715; sh: 3,516; makefile: 718
file content (132 lines) | stat: -rw-r--r-- 3,828 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*====================================================================*
 -  Copyright (C) 2001 Leptonica.  All rights reserved.
 -  This software is distributed in the hope that it will be
 -  useful, but with NO WARRANTY OF ANY KIND.
 -  No author or distributor accepts responsibility to anyone for the
 -  consequences of using this software, or for whether it serves any
 -  particular purpose or works at all, unless he or she says so in
 -  writing.  Everyone is granted permission to copy, modify and
 -  redistribute this source code, for commercial or non-commercial
 -  purposes, with the following restrictions: (1) the origin of this
 -  source code must not be misrepresented; (2) modified versions must
 -  be plainly marked as such; and (3) this notice may not be removed
 -  or altered from any source or modified source distribution.
 *====================================================================*/

/*
 * rotateorth_reg.c
 *
 *    Regression test for all rotateorth functions
 */

#include <stdio.h>
#include <stdlib.h>
#include "allheaders.h"

#define   BINARY_IMAGE        "test1.png"
#define   GRAYSCALE_IMAGE     "test8.jpg"
#define   FOUR_BPP_IMAGE      "weasel4.8g.png"
#define   COLORMAP_IMAGE      "dreyfus8.png"
#define   RGB_IMAGE           "marge.jpg"

void rotateOrthTest(char *fname);


main(int    argc,
     char **argv)
{
static char  mainName[] = "rotateorth_reg";

    if (argc != 1)
	exit(ERROR_INT(" Syntax:  rotateorth_reg", mainName, 1));

    fprintf(stderr, "Test binary image:\n");
    rotateOrthTest(BINARY_IMAGE);
    fprintf(stderr, "Test 4 bpp colormapped image:\n");
    rotateOrthTest(FOUR_BPP_IMAGE);
    fprintf(stderr, "Test grayscale image:\n");
    rotateOrthTest(GRAYSCALE_IMAGE);
    fprintf(stderr, "Test colormap image:\n");
    rotateOrthTest(COLORMAP_IMAGE);
    fprintf(stderr, "Test rgb image:\n");
    rotateOrthTest(RGB_IMAGE);
    return 0;
}


void
rotateOrthTest(char *fname)
{
l_int32   zero, count;
PIX      *pixs, *pixt, *pixd;

    PROCNAME("rotateOrthTest");

    if ((pixs = pixRead(fname)) == NULL)
	return ERROR_VOID("pixs not read", procName);

	/* Test 4 successive 90 degree rotations */
    pixt = pixRotate90(pixs, 1);
    pixd = pixRotate90(pixt, 1);
    pixDestroy(&pixt);
    pixt = pixRotate90(pixd, 1);
    pixDestroy(&pixd);
    pixd = pixRotate90(pixt, 1);
    pixDestroy(&pixt);
    pixXor(pixd, pixd, pixs);
    pixZero(pixd, &zero);
    if (zero)
	fprintf(stderr, "OK.  Four 90-degree rotations gives I\n");
    else {
	pixCountPixels(pixd, &count, NULL);
	fprintf(stderr, "Failure for four 90-degree rotations; count = %d\n",
		count);
    }
    pixDestroy(&pixd);

	/* Test 2 successive 180 degree rotations */
    pixt = pixRotate180(NULL, pixs);
    pixRotate180(pixt, pixt);
    pixXor(pixt, pixt, pixs);
    pixZero(pixt, &zero);
    if (zero)
	fprintf(stderr, "OK.  Two 180-degree rotations gives I\n");
    else {
	pixCountPixels(pixt, &count, NULL);
	fprintf(stderr, "Failure for two 180-degree rotations; count = %d\n",
		count);
    }
    pixDestroy(&pixt);

	/* Test 2 successive LR flips */
    pixt = pixFlipLR(NULL, pixs);
    pixFlipLR(pixt, pixt);
    pixXor(pixt, pixt, pixs);
    pixZero(pixt, &zero);
    if (zero)
	fprintf(stderr, "OK.  Two LR flips gives I\n");
    else {
	pixCountPixels(pixt, &count, NULL);
	fprintf(stderr, "Failure for two LR flips; count = %d\n",
		count);
    }
    pixDestroy(&pixt);

	/* Test 2 successive TB flips */
    pixt = pixFlipTB(NULL, pixs);
    pixFlipTB(pixt, pixt);
    pixXor(pixt, pixt, pixs);
    pixZero(pixt, &zero);
    if (zero)
	fprintf(stderr, "OK.  Two TB flips gives I\n");
    else {
	pixCountPixels(pixt, &count, NULL);
	fprintf(stderr, "Failure for two TB flips; count = %d\n",
		count);
    }
    pixDestroy(&pixt);

    pixDestroy(&pixs);
    return;
}