• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* sane - Scanner Access Now Easy.
2 
3    Copyright (C) 2009 m. allan noah
4 
5    This file is part of the SANE package.
6 
7    SANE is free software; you can redistribute it and/or modify it
8    under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11 
12    SANE is distributed in the hope that it will be useful, but WITHOUT
13    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15    License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with sane; see the file COPYING.
19    If not, see <https://www.gnu.org/licenses/>.
20 
21    As a special exception, the authors of SANE give permission for
22    additional uses of the libraries contained in this release of SANE.
23 
24    The exception is that, if you link a SANE library with other files
25    to produce an executable, this does not by itself cause the
26    resulting executable to be covered by the GNU General Public
27    License.  Your use of that executable is in no way restricted on
28    account of linking the SANE library code into it.
29 
30    This exception does not, however, invalidate any other reasons why
31    the executable file might be covered by the GNU General Public
32    License.
33 
34    If you submit changes to SANE to the maintainers to be included in
35    a subsequent release, you agree by submitting the changes that
36    those changes may be distributed with this exception intact.
37 
38    If you write modifications of your own for SANE, it is your choice
39    whether to permit this exception to apply to your modifications.
40    If you do not wish that, delete this exception notice.
41 */
42 
43 /** @file sanei_magic.h
44  * This file provides an interface to simple image post-processing functions
45  *
46  * Currently, three operations are provided:
47  * - Deskew (correct rotated scans, by detecting media edges)
48  * - Autocrop (reduce image size to minimum rectangle containing media)
49  * - Despeckle (replace dots of significantly different color with background)
50  * - Blank detection (check if density is over a threshold)
51  * - Rotate (detect and correct 90 degree increment rotations)
52  *
53  * Note that these functions are simplistic, and are expected to change.
54  * Patches and suggestions are welcome.
55  */
56 
57 #ifndef SANEI_MAGIC_H
58 #define SANEI_MAGIC_H
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 /** Initialize sanei_magic.
65  *
66  * Call this before any other sanei_magic function.
67  */
68 extern void sanei_magic_init( void );
69 
70 /** Update the image buffer, replacing dots with surrounding background color
71  *
72  * @param params describes image
73  * @param buffer contains image data
74  * @param diam maximum dot diameter to remove
75  *
76  * @return
77  * - SANE_STATUS_GOOD - success
78  * - SANE_STATUS_INVAL - invalid image parameters
79  */
80 extern SANE_Status
81 sanei_magic_despeck (SANE_Parameters * params, SANE_Byte * buffer,
82   SANE_Int diam);
83 
84 /** Find the skew of the media inside the image, via edge detection.
85  *
86  * @param params describes image
87  * @param buffer contains image data
88  * @param dpiX horizontal resolution
89  * @param dpiY vertical resolution
90  * @param[out] centerX horizontal coordinate of center of rotation
91  * @param[out] centerY vertical coordinate of center of rotation
92  * @param[out] finSlope slope of rotation
93  *
94  * @return
95  * - SANE_STATUS_GOOD - success
96  * - SANE_STATUS_NO_MEM - not enough memory
97  * - SANE_STATUS_INVAL - invalid image parameters
98  * - SANE_STATUS_UNSUPPORTED - slope angle too shallow to detect
99  */
100 extern SANE_Status
101 sanei_magic_findSkew(SANE_Parameters * params, SANE_Byte * buffer,
102   int dpiX, int dpiY, int * centerX, int * centerY, double * finSlope);
103 
104 /** Correct the skew of the media inside the image, via simple rotation
105  *
106  * @param params describes image
107  * @param buffer contains image data
108  * @param centerX horizontal coordinate of center of rotation
109  * @param centerY vertical coordinate of center of rotation
110  * @param slope slope of rotation
111  * @param bg_color the replacement color for edges exposed by rotation
112  *
113  * @return
114  * - SANE_STATUS_GOOD - success
115  * - SANE_STATUS_NO_MEM - not enough memory
116  * - SANE_STATUS_INVAL - invalid image parameters
117  */
118 extern SANE_Status
119 sanei_magic_rotate (SANE_Parameters * params, SANE_Byte * buffer,
120   int centerX, int centerY, double slope, int bg_color);
121 
122 /** Find the edges of the media inside the image, parallel to image edges
123  *
124  * @param params describes image
125  * @param buffer contains image data
126  * @param dpiX horizontal resolution
127  * @param dpiY vertical resolution
128  * @param[out] top vertical offset to upper edge of media
129  * @param[out] bot vertical offset to lower edge of media
130  * @param[out] left horizontal offset to left edge of media
131  * @param[out] right horizontal offset to right edge of media
132  *
133  * @return
134  * - SANE_STATUS_GOOD - success
135  * - SANE_STATUS_NO_MEM - not enough memory
136  * - SANE_STATUS_UNSUPPORTED - edges could not be detected
137  */
138 extern SANE_Status
139 sanei_magic_findEdges(SANE_Parameters * params, SANE_Byte * buffer,
140   int dpiX, int dpiY, int * top, int * bot, int * left, int * right);
141 
142 /** Crop the image, parallel to image edges
143  *
144  * @param params describes image
145  * @param buffer contains image data
146  * @param top vertical offset to upper edge of crop
147  * @param bot vertical offset to lower edge of crop
148  * @param left horizontal offset to left edge of crop
149  * @param right horizontal offset to right edge of crop
150  *
151  * @return
152  * - SANE_STATUS_GOOD - success
153  * - SANE_STATUS_NO_MEM - not enough memory
154  * - SANE_STATUS_INVAL - invalid image parameters
155  */
156 extern SANE_Status
157 sanei_magic_crop(SANE_Parameters * params, SANE_Byte * buffer,
158   int top, int bot, int left, int right);
159 
160 /** Determine if image is blank
161  *
162  * @param params describes image
163  * @param buffer contains image data
164  * @param thresh maximum % density for blankness (0-100)
165  *
166  * @return
167  * - SANE_STATUS_GOOD - page is not blank
168  * - SANE_STATUS_NO_DOCS - page is blank
169  * - SANE_STATUS_NO_MEM - not enough memory
170  * - SANE_STATUS_INVAL - invalid image parameters
171  */
172 extern SANE_Status
173 sanei_magic_isBlank(SANE_Parameters * params, SANE_Byte * buffer,
174   double thresh);
175 
176 /** Determine if image is blank, enhanced version
177  *
178  * @param params describes image
179  * @param buffer contains image data
180  * @param dpiX horizontal resolution
181  * @param dpiY vertical resolution
182  * @param thresh maximum % density for blankness (0-100)
183  *
184  * @return
185  * - SANE_STATUS_GOOD - page is not blank
186  * - SANE_STATUS_NO_DOCS - page is blank
187  * - SANE_STATUS_NO_MEM - not enough memory
188  * - SANE_STATUS_INVAL - invalid image parameters
189  */
190 extern SANE_Status
191 sanei_magic_isBlank2(SANE_Parameters * params, SANE_Byte * buffer,
192   int dpiX, int dpiY, double thresh);
193 
194 /** Determine coarse image rotation (90 degree increments)
195  *
196  * @param params describes image
197  * @param buffer contains image data
198  * @param dpiX horizontal resolution
199  * @param dpiY vertical resolution
200  * @param[out] angle amount of rotation recommended
201  *
202  * @return
203  * - SANE_STATUS_GOOD - success
204  * - SANE_STATUS_NO_MEM - not enough memory
205  * - SANE_STATUS_INVAL - invalid image parameters
206  */
207 extern SANE_Status
208 sanei_magic_findTurn(SANE_Parameters * params, SANE_Byte * buffer,
209   int dpiX, int dpiY, int * angle);
210 
211 /** Coarse image rotation (90 degree increments)
212  *
213  * @param params describes image
214  * @param buffer contains image data
215  * @param angle amount of rotation requested (multiple of 90)
216  *
217  * @return
218  * - SANE_STATUS_GOOD - success
219  * - SANE_STATUS_NO_MEM - not enough memory
220  * - SANE_STATUS_INVAL - invalid image or angle parameters
221  */
222 extern SANE_Status
223 sanei_magic_turn(SANE_Parameters * params, SANE_Byte * buffer,
224   int angle);
225 
226 #ifdef __cplusplus
227 } // extern "C"
228 #endif
229 
230 #endif /* SANEI_MAGIC_H */
231