File: gocr_image.h

package info (click to toggle)
libgocr 0.7.2-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,888 kB
  • ctags: 3,506
  • sloc: sh: 8,723; ansic: 7,872; makefile: 242
file content (227 lines) | stat: -rw-r--r-- 7,282 bytes parent folder | download | duplicates (6)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
GOCR Copyright (C) 2000  Joerg Schulenburg Joerg.Schulenburg@physik.uni-magdeburg.de 
GOCR API Copyright (C) 2001 Bruno Barberi Gnecco <brunobg@sourceforge.net>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
 

#ifndef _GOCR_IMAGE_H 
#define _GOCR_IMAGE_H 

#ifndef _GOCR_MODULE_H
# error "Do not call gocr_gui.h directly; call gocr_module.h instead."
#endif.

#ifdef __cplusplus
extern "C" {
#endif

/*! \file gocr_image.h
  \brief This is the image header
  \author Bruno Barberi Gnecco <brunobg@sourceforge.net>
*/

/** @name Image
  */
/*@{*/
/**
  \brief Black pixel value.
  \sa gocr_Pixel.
*/
#define GOCR_BLACK			0
/**
  \brief White pixel value.
  \sa gocr_Pixel.
*/
#define GOCR_WHITE			1


/**
  \brief Image type values.
*/
enum gocr_imagetype {
	GOCR_NONE, 			/**< No type. */
	GOCR_BW, 			/**< Black and white. */
	GOCR_GRAY, 			/**< Grayscale. */
	GOCR_COLOR,			/**< Color. */
	GOCR_OTHER 			/**< Other (user-defined). */
};
/**
  \brief Typedef encapsulation.
*/
typedef enum gocr_imagetype gocr_ImageType;

/**
 \brief This is the pixel structure.
 
 Long description.

*/
struct gocr_pixelbw {
	unsigned char	value : 1;	/**< pixel value. */
	unsigned char	mark1 : 1;	/**< user defined marker 1. */
	unsigned char	mark2 : 1;	/**< user defined marker 2. */
	unsigned char	mark3 : 1;	/**< user defined marker 3. */
	unsigned char	isblock : 1;	/**< is part of a block? */
	unsigned char	ischar : 1;	/**< is part of a character? */
	unsigned char	private1 : 1;	/**< reserved, used internally (find.c). */
	unsigned char	private2 : 1;	/**< reserved, used internally */
};
/**
  \brief Typedef encapsulation.
*/
typedef struct gocr_pixelbw gocr_PixelBW;

struct gocr_pixelgray {
	unsigned char	pad : 1;	/**< pad bit. */
	unsigned char	mark1 : 1;	/**< user defined marker 1. */
	unsigned char	mark2 : 1;	/**< user defined marker 2. */
	unsigned char	mark3 : 1;	/**< user defined marker 3. */
	unsigned char	isblock : 1;	/**< is part of a block? */
	unsigned char	ischar : 1;	/**< is part of a character? */
	unsigned char	private1 : 1;	/**< reserved, used internally (find.c). */
	unsigned char	private2 : 1;	/**< reserved, used internally */
	
	unsigned char 	value;
};
typedef struct gocr_pixelgray gocr_PixelGray;

struct gocr_pixelcolor {
	unsigned char	pad : 1;	/**< pad bit. */
	unsigned char	mark1 : 1;	/**< user defined marker 1. */
	unsigned char	mark2 : 1;	/**< user defined marker 2. */
	unsigned char	mark3 : 1;	/**< user defined marker 3. */
	unsigned char	isblock : 1;	/**< is part of a block? */
	unsigned char	ischar : 1;	/**< is part of a character? */
	unsigned char	private1 : 1;	/**< reserved, used internally (find.c). */
	unsigned char	private2 : 1;	/**< reserved, used internally */

	unsigned char 	value[3];
};
typedef struct gocr_pixelcolor gocr_PixelColor;


/**
 \brief This is the pixel wrapper data structure.
 
 It should work with any pixel data structure.

*/
struct gocr_pixel {
	unsigned char	pad : 1;	/**< pad bit. */
	unsigned char	mark1 : 1;	/**< user defined marker 1. */
	unsigned char	mark2 : 1;	/**< user defined marker 2. */
	unsigned char	mark3 : 1;	/**< user defined marker 3. */
	unsigned char	isblock : 1;	/**< is part of a block? */
	unsigned char	ischar : 1;	/**< is part of a character? */
	unsigned char	private1 : 1;	/**< reserved, used internally (find.c). */
	unsigned char	private2 : 1;	/**< reserved, used internally */

	char		value[0];
};
typedef struct gocr_pixel gocr_Pixel;

/**
 \brief This is the image structure.
 
 Long description.

*/
struct gocr_image {
	char		*filename;	/**< file name; may be NULL. */
	int		width, height;	/**< size. */
	gocr_ImageType	type;		/**< image type. */

	union {
		gocr_Pixel	**pix;	/**< opaque type */
		gocr_PixelBW	**bw;	/**< bw pixel */
		gocr_PixelGray	**gray; /**< gray pixel */
		gocr_PixelColor	**color;/**< color pixel */
	} data;

/* you are unlikely to change these below. Future: hide them */
	unsigned char	*mask;
	int		threshold;	/**< image threshold, for gray->bw conversion. */
	int		sons;		/**< number of shared images */
	struct gocr_image *parent;	/**< if shared, the parent */
};

/**
  \brief Typedef encapsulation.
*/
typedef struct gocr_image gocr_Image;

/* image.c */
extern void gocr_imageFree ( gocr_Image *image );
extern int gocr_imageWrite ( gocr_Image *image, char *filename );
extern int gocr_mainImageWriteWithData ( char *filename );

/* pixel.c */
extern inline int gocr_pixelGetMark1 ( gocr_Image *image, int x, int y );
extern inline int gocr_pixelSetMark1 ( gocr_Image *image, int x, int y, char value );
extern inline int gocr_pixelGetMark2 ( gocr_Image *image, int x, int y );
extern inline int gocr_pixelSetMark2 ( gocr_Image *image, int x, int y, char value );
extern inline int gocr_pixelGetMark3 ( gocr_Image *image, int x, int y );
extern inline int gocr_pixelSetMark3 ( gocr_Image *image, int x, int y, char value );

#define gocr_isblock(image, x, y) \
 ((gocr_Pixel *)((image)->data.pix[y]+(x)*_gocr_imagePixelSize(image)))->isblock
#define gocr_ischar(image, x, y) \
 ((gocr_Pixel *)((image)->data.pix[y]+(x)*_gocr_imagePixelSize(image)))->ischar


extern void gocr_imagePixelSetBW ( gocr_Image *image, int x, int y, 
		unsigned char data );
extern unsigned char gocr_imagePixelGetBW ( gocr_Image *image, int x, int y );
extern void gocr_imagePixelSetGray ( gocr_Image *image, int x, int y,
		unsigned char data );
extern unsigned char gocr_imagePixelGetGray ( gocr_Image *image, int x, int y );
extern void gocr_imagePixelSetColor ( gocr_Image *image, int x, int y,
		unsigned char data[3] );
extern unsigned char *gocr_imagePixelGetColor ( gocr_Image *image, int x, int y );

/*@}*/

#ifdef _GOCR_INTERNAL_H /*ok, this #ifdef sucks, but is a quick hack */

extern int 	_gocr_imageLoad		( const char *filename, void *data );
extern size_t	_gocr_imagePixelSize	( gocr_Image *image );
extern int 	_gocr_thresholdGrayToBW ( gocr_Image *image );

#define _gocr_private1(image, x, y) \
 ((gocr_Pixel *)((image)->data.pix[y]+(x)*_gocr_imagePixelSize(image)))->private1
#define _gocr_private2(image, x, y) \
 ((gocr_Pixel *)((image)->data.pix[y]+(x)*_gocr_imagePixelSize(image)))->private2
#define _gocr_maskGet(img, x, y) \
	!!(img->mask[(((y)*(img)->width+(x))>>3)]&(((y)*img->width+(x))%8))
#define _gocr_maskSet(img, x, y, v) \
	img->mask[(((y)*(img)->width+(x))>>3)] &= ((v)&(1<<((y)*img->width+(x))%8))
#endif

/**
  \brief A pointer to the current image.
  This variable holds the image being processed right now, and can be freely
  accessed by the programmer.
  \sa gocr_imageLoad, gocr_imageClose, gocr_Image.
*/
extern gocr_Image	*currentimage;

#ifdef __cplusplus
}
#endif

#endif