source: project/release/4/leptonica/trunk/leptonica.scm @ 20741

Last change on this file since 20741 was 20741, checked in by petercrlane, 11 years ago

further functions

File size: 8.6 KB
Line 
1;;; Leptonica library wrapped for Chicken Scheme.
2;;; Copyright (c) Peter Lane, 2010.
3
4;;; This program is free software: you can redistribute it and/or modify
5;;; it under the terms of the GNU General Public License as published by
6;;; the Free Software Foundation, either version 3 of the License, or
7;;; (at your option) any later version.
8
9;;; This program is distributed in the hope that it will be useful,
10;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12;;; GNU General Public License for more details.
13
14;;; You should have received a copy of the GNU General Public License
15;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17;;; -------------------------------------------------------------------------------
18
19(module
20  leptonica
21  (export 
22    L-BRING-IN-WHITE L-BRING-IN-BLACK
23    L-ROTATE-AREA-MAP L-ROTATE-SHEAR L-ROTATE-SAMPLING
24    IFF-UNKNOWN IFF-BMP IFF-JFIF-JPEG IFF-PNG IFF-TIFF IFF-TIFF-PACKBITS
25    IFF-TIFF-RLE IFF-TIFF-G3 IFF-TIFF-G4 IFF-TIFF-LZW IFF-TIFF-ZIP
26    IFF-PNM IFF-PS IFF-GIF IFF-JP2 IFF-DEFAULT IFF-SPIX
27    L-LINEAR-SCALE L-LOG-SCALE
28    L-CHOOSE-MIN L-CHOOSE-MAX L-CHOOSE-MAX-MIN-DIFF
29    pix-create pix-copy pix-destroy
30    pix-get-width pix-set-width pix-get-height pix-set-height
31    pix-get-depth pix-set-depth pix-set-dimensions
32    pix-get-x-res pix-set-x-res pix-get-y-res pix-set-y-res
33    pix-set-resolution pix-scale-resolution pix-get-input-format pix-set-input-format
34    pix-abs-difference
35    pix-add-gray
36    pix-close-gray
37    pix-combine-masked
38    pix-dilate-gray
39    pix-dither-to-binary
40    pix-dither-to-binary-spec
41    pix-erode-gray
42    pix-find-skew
43    pix-invert
44    pix-max-dynamic-range
45    pix-min-or-max
46    pix-mult-constant-gray
47    pix-open-gray
48    pix-read
49    pix-rotate
50    pix-rotate-am-gray
51    pix-scale
52    pix-subtract-gray
53    pix-threshold-to-binary
54    pix-threshold-to-value
55    pix-var-threshold-to-binary
56    pix-write
57    )
58  (import chicken extras foreign scheme)
59
60  #>
61  #include <liblept/allheaders.h>
62  <#
63
64  ;; define constants
65  (define L-BRING-IN-WHITE 1)
66  (define L-BRING-IN-BLACK 2)
67
68  (define L-ROTATE-AREA-MAP 1)
69  (define L-ROTATE-SHEAR 2)
70  (define L-ROTATE-SAMPLING 3)
71
72  ;; -- from imageio.h
73
74  ;; define constants
75  (define IFF-UNKNOWN 0)
76  (define IFF-BMP 1)
77  (define IFF-JFIF-JPEG 2)
78  (define IFF-PNG 3)
79  (define IFF-TIFF 4)
80  (define IFF-TIFF-PACKBITS 5)
81  (define IFF-TIFF-RLE 6)
82  (define IFF-TIFF-G3 7)
83  (define IFF-TIFF-G4 8)
84  (define IFF-TIFF-LZW 9)
85  (define IFF-TIFF-ZIP 10)
86  (define IFF-PNM 11)
87  (define IFF-PS 12)
88  (define IFF-GIF 13)
89  (define IFF-JP2 14)
90  (define IFF-DEFAULT 15)
91  (define IFF-SPIX 16)
92
93  (define L-LINEAR-SCALE 1)
94  (define L-LOG-SCALE 2)
95
96  (define L-CHOOSE-MIN 1)
97  (define L-CHOOSE-MAX 2)
98  (define L-CHOOSE-MAX-MIN-DIFF 3)
99
100  ;; -- from graymorph.c (complete)
101
102  (define pix-close-gray
103    (foreign-lambda c-pointer "pixCloseGray" c-pointer integer integer))
104
105  (define pix-dilate-gray
106    (foreign-lambda c-pointer "pixDilateGray" c-pointer integer integer))
107
108  (define pix-erode-gray
109    (foreign-lambda c-pointer "pixErodeGray" c-pointer integer integer))
110
111  (define pix-open-gray
112    (foreign-lambda c-pointer "pixOpenGray" c-pointer integer integer))
113
114  ;; -- from grayquant.c
115
116  ;; ---- threshold from 8 bpp to 1 bpp
117
118  ;; Uses Floyd-Steinberg error diffusion dithering algorithm to convert
119  ;; given pix to a new pix.  Returns #f on error
120  (define pix-dither-to-binary
121    (foreign-lambda c-pointer "pixDitherToBinary" c-pointer))
122
123  ;; as above, but takes parameters for the lowerclip (distance from 0) and
124  ;; upperclip (distance from 255), to adjust the values below and above which
125  ;; the routine does not propagate excess.
126  (define pix-dither-to-binary-spec
127    (foreign-lambda c-pointer "pixDitherToBinarySpec" c-pointer integer integer))
128
129  ;; Simple (pixelwise) binarisation with fixed threshold
130  ;; converts an image pix with 4 or 8 bpp to an image pix with 1 bpp,
131  ;; thresholding on given level
132  (define pix-threshold-to-binary
133    (foreign-lambda c-pointer "pixThresholdToBinary" c-pointer integer))
134
135  ;; uses second argument as a source of variable thresholds for first argument.
136  (define pix-var-threshold-to-binary
137    (foreign-lambda c-pointer "pixVarThresholdToBinary" c-pointer c-pointer))
138
139  ;; -- from pixarith.c
140
141  (define pix-abs-difference
142    (foreign-lambda c-pointer "pixAbsDifference" c-pointer c-pointer))
143
144  (define pix-add-gray
145    (foreign-lambda c-pointer "pixAddGray" c-pointer c-pointer c-pointer))
146
147  (define pix-add-constant-gray
148    (foreign-lambda integer "pixAddConstantGray" c-pointer integer))
149
150  (define pix-max-dynamic-range
151    (foreign-lambda c-pointer "pixMaxDynamicRange" c-pointer integer))
152
153  (define pix-min-or-max
154    (foreign-lambda c-pointer "pixMinOrMax" c-pointer c-pointer c-pointer integer))
155
156  (define pix-mult-constant-gray
157    (foreign-lambda integer "pixMultConstantGray" c-pointer float))
158
159  (define pix-subtract-gray
160    (foreign-lambda c-pointer "pixSubtractGray" c-pointer c-pointer c-pointer))
161
162  (define pix-threshold-to-value
163    (foreign-lambda c-pointer "pixThresholdToValue" c-pointer c-pointer integer integer))
164
165  ;; -- from pix1.c
166
167  (define pix-create
168    (foreign-lambda c-pointer "pixCreate" integer integer integer))
169
170  (define pix-clone
171    (foreign-lambda c-pointer "pixClone" c-pointer))
172
173  (define pix-copy
174    (foreign-lambda c-pointer "pixCopy" c-pointer c-pointer))
175
176  (define pix-destroy
177    (foreign-lambda void "pixDestroy" c-pointer))
178
179  (define pix-get-width
180    (foreign-lambda integer "pixGetWidth" c-pointer))
181
182  (define pix-set-width
183    (foreign-lambda integer "pixSetWidth" c-pointer integer))
184
185  (define pix-get-height
186    (foreign-lambda integer "pixGetHeight" c-pointer))
187
188  (define pix-set-height
189    (foreign-lambda integer "pixSetHeight" c-pointer integer))
190
191  (define pix-get-depth
192    (foreign-lambda integer "pixGetDepth" c-pointer))
193
194  (define pix-set-depth
195    (foreign-lambda integer "pixSetDepth" c-pointer integer))
196
197  (define pix-set-dimensions
198    (foreign-lambda integer "pixSetDimensions" c-pointer integer integer integer))
199
200  (define pix-get-x-res
201    (foreign-lambda integer "pixGetXRes" c-pointer))
202
203  (define pix-set-x-res
204    (foreign-lambda integer "pixSetXRes" c-pointer integer))
205
206  (define pix-get-y-res
207    (foreign-lambda integer "pixGetYRes" c-pointer))
208
209  (define pix-set-y-res
210    (foreign-lambda integer "pixSetYRes" c-pointer integer))
211
212  (define pix-set-resolution
213    (foreign-lambda integer "pixSetResolution" c-pointer integer integer))
214
215  (define pix-scale-resolution
216    (foreign-lambda integer "pixScaleResolution" c-pointer float float))
217
218  (define pix-get-input-format
219    (foreign-lambda integer "pixGetInputFormat" c-pointer))
220
221  (define pix-set-input-format
222    (foreign-lambda integer "pixSetInputFormat" c-pointer integer))
223
224  ;; -- from pix3.c
225
226  (define pix-combine-masked
227    (foreign-lambda integer "pixCombineMasked" c-pointer c-pointer c-pointer))
228
229  (define pix-invert
230    (foreign-lambda c-pointer "pixInvert" c-pointer c-pointer))
231
232  ;; -- from readfile.c
233
234  ;; Reads an image reference from given filename
235  (define pix-read
236    (foreign-lambda c-pointer "pixRead" c-string))
237
238  ;; -- from rotate.c
239
240  ;; input:
241  ;;   * c-pointer: to image
242  ;;   * float:     angle (radians, clockwise is positive)
243  ;;   * integer:   type (L-ROTATE-*)
244  ;;   * integer:   incolour (L-BRING-IN-*)
245  ;;   * width:     original width, use 0 to avoid embedding
246  ;;   * height:    original height, use 0 to avoid embedding
247  ;; output:
248  ;;   * c-pointer to new image, or #f on error
249  (define pix-rotate
250    (foreign-lambda c-pointer "pixRotate" c-pointer float integer integer integer integer))
251
252  (define pix-rotate-am-gray
253    (foreign-lambda c-pointer "pixRotateAMGray" c-pointer float integer))
254
255  ;; -- from scale.c
256
257  ;; input:
258  ;;   * c-pointer: to image
259  ;;   * float:     scale_x
260  ;;   * float:     scale_y
261  ;; output:
262  ;;   * c-pointer to new image, or #f on error
263  (define pix-scale
264    (foreign-lambda c-pointer "pixScale" c-pointer float float))
265
266  ;; -- from skew.c
267
268  (define call-find-skew
269    (foreign-lambda integer "pixFindSkew" c-pointer (c-pointer float) (c-pointer float)))
270
271  (define (pix-find-skew pix)
272    (let-location ((angle float)
273                   (confidence float))
274                  (let ((value (call-find-skew pix (location angle) (location confidence))))
275                    (values (/ (* 3.141927 angle) 180) confidence))))
276
277  ;; -- from writefile.c
278
279  ;; Writes image reference by c-pointer to filename c-string, using type of integer
280  (define pix-write
281    (foreign-lambda void "pixWrite" c-string c-pointer integer))
282
283  ) ; end of module
284
Note: See TracBrowser for help on using the repository browser.