1 /***************************************************************************
2     imgSeek ::  This file is the haar 2d transform implemented in C/C++ to speed things up
3                              -------------------
4     begin                : Fri Jan 17 2003
5     email                : nieder|at|mail.ru
6     Time-stamp:            <03/05/09 21:29:35 rnc>
7 
8     Copyright (C) 2003 Ricardo Niederberger Cabral
9     This program is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13 
14     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18 
19     You should have received a copy of the GNU General Public License
20     along with this program; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 */
23 #ifndef HAAR_H
24 #define HAAR_H
25 
26 /* STL Includes */
27 #include <queue>
28 
29 /* Number of pixels on one side of image; required to be a power of 2. */
30 #define	NUM_PIXELS		128
31 /* Totals pixels in a square image. */
32 #define NUM_PIXELS_SQUARED	(NUM_PIXELS * NUM_PIXELS)
33 /* Number of Haar coeffients we retain as signature for an image. */
34 #define NUM_COEFS		40
35 
36 #define UNIT_IS_DOUBLE
37 
38 #undef ABS
39 #ifdef UNIT_IS_DOUBLE
40 #define ABS(x)	fabs(x)
41 typedef double	Unit;
42 #else
43 #define UNIT_IS_INT
44 #define ABS(x)	abs(x)
45 typedef int	Unit;
46 #endif
47 
48 #define FP_BITS 16 /// max fp bits [apparently 16 is faster]
49 
50 typedef int Idx;
51 
52 /* signature structure */
53 typedef struct valStruct_ {
54   Unit d;			/* [f]abs(a[i]) */
55   int i;			/* index i of a[i] */
56   bool operator< (const valStruct_ &right) const {
57     return d > right.d;
58   }
59 } valStruct;
60 
61 typedef std::priority_queue < valStruct > valqueue;
62 
63 #define max(a, b)  (((a) > (b)) ? (a) : (b))
64 #define min(a, b)  (((a) > (b)) ? (b) : (a))
65 
66 void initImgBin();
67 
68 void transform(Unit *a, Unit *b, Unit *c);
69 
70 void transformChar(unsigned char *c1, unsigned char *c2, unsigned char *c3,
71                    Unit *a, Unit *b, Unit *c);
72 
73 int calcHaar(Unit *cdata1, Unit *cdata2, Unit *cdata3,
74              Idx *sig1, Idx *sig2, Idx *sig3, double *avgl);
75 
76 double *new_darray(int size) ;
77 
78 int *new_iarray(int size);
79 
80 #endif
81