1 /*====================================================================*
2  -  Copyright (C) 2001 Leptonica.  All rights reserved.
3  -
4  -  Redistribution and use in source and binary forms, with or without
5  -  modification, are permitted provided that the following conditions
6  -  are met:
7  -  1. Redistributions of source code must retain the above copyright
8  -     notice, this list of conditions and the following disclaimer.
9  -  2. Redistributions in binary form must reproduce the above
10  -     copyright notice, this list of conditions and the following
11  -     disclaimer in the documentation and/or other materials
12  -     provided with the distribution.
13  -
14  -  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  -  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  -  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  -  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ANY
18  -  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  -  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  -  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  -  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  -  OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  -  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  -  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *====================================================================*/
26 
27 #ifndef  LEPTONICA_PIX_H
28 #define  LEPTONICA_PIX_H
29 
30 /*!
31  * \file pix.h
32  *
33  * <pre>
34  *   Valid image types in leptonica:
35  *       Pix: 1 bpp, with and without colormap
36  *       Pix: 2 bpp, with and without colormap
37  *       Pix: 4 bpp, with and without colormap
38  *       Pix: 8 bpp, with and without colormap
39  *       Pix: 16 bpp (1 spp)
40  *       Pix: 32 bpp (rgb, 3 spp)
41  *       Pix: 32 bpp (rgba, 4 spp)
42  *       FPix: 32 bpp float
43  *       DPix: 64 bpp double
44  *       Notes:
45  *          (1) The only valid Pix image type with alpha is rgba.
46  *              In particular, the alpha component is not used in
47  *              cmapped images.
48  *          (2) PixComp can hold any Pix with IFF_PNG encoding.
49  *
50  *   Contents:
51  *
52  *   (1) This file defines most of the image-related structs used in leptonica:
53  *         struct Pix
54  *         struct PixColormap
55  *         struct RGBA_Quad
56  *         struct Pixa
57  *         struct Pixaa
58  *         struct Box
59  *         struct Boxa
60  *         struct Boxaa
61  *         struct Pta
62  *         struct Ptaa
63  *         struct Pixacc
64  *         struct PixTiling
65  *         struct FPix
66  *         struct FPixa
67  *         struct DPix
68  *         struct PixComp
69  *         struct PixaComp
70  *
71  *   (2) This file has definitions for:
72  *         Colors for RGB
73  *         Colors for drawing boxes
74  *         Perceptual color weights
75  *         Colormap conversion flags
76  *         Rasterop bit flags
77  *         Structure access flags (for insert, copy, clone, copy-clone)
78  *         Sorting flags (by type and direction)
79  *         Blending flags
80  *         Graphics pixel setting flags
81  *         Size filtering flags
82  *         Color component selection flags
83  *         16-bit conversion flags
84  *         Rotation and shear flags
85  *         Affine transform order flags
86  *         Grayscale filling flags
87  *         Flags for setting to white or black
88  *         Flags for getting white or black pixel value
89  *         Flags for 8 and 16 bit pixel sums
90  *         Dithering flags
91  *         Distance flags
92  *         Statistical measures
93  *         Set selection flags
94  *         Text orientation flags
95  *         Edge orientation flags
96  *         Line orientation flags
97  *         Scan direction flags
98  *         Box size adjustment flags
99  *         Flags for selecting box boundaries from two choices
100  *         Handling overlapping bounding boxes in boxa
101  *         Flags for replacing invalid boxes
102  *         Horizontal warp
103  *         Pixel selection for resampling
104  *         Thinning flags
105  *         Runlength flags
106  *         Edge filter flags
107  *         Subpixel color component ordering in LCD display
108  *         HSV histogram flags
109  *         Region flags (inclusion, exclusion)
110  *         Flags for adding text to a pix
111  *         Flags for plotting on a pix
112  *         Flags for selecting display program
113  *         Flags in the 'special' pix field for non-default operations
114  *         Handling negative values in conversion to unsigned int
115  *         Relative to zero flags
116  *         Flags for adding or removing traling slash from string
117  *
118  *   (3) This file has typedefs for the pix allocator and deallocator functions
119  *         alloc_fn()
120  *         dealloc_fn().
121  * </pre>
122  */
123 
124 
125 /*-------------------------------------------------------------------------*
126  *                              Basic Pix                                  *
127  *-------------------------------------------------------------------------*/
128     /* The 'special' field is by default 0, but it can hold integers
129      * that direct non-default actions, e.g., in png and jpeg I/O. */
130 
131 /*! Basic Pix */
132 struct Pix
133 {
134     l_uint32             w;         /*!< width in pixels                   */
135     l_uint32             h;         /*!< height in pixels                  */
136     l_uint32             d;         /*!< depth in bits (bpp)               */
137     l_uint32             spp;       /*!< number of samples per pixel       */
138     l_uint32             wpl;       /*!< 32-bit words/line                 */
139     l_uint32             refcount;  /*!< reference count (1 if no clones)  */
140     l_int32              xres;      /*!< image res (ppi) in x direction    */
141                                     /*!< (use 0 if unknown)                */
142     l_int32              yres;      /*!< image res (ppi) in y direction    */
143                                     /*!< (use 0 if unknown)                */
144     l_int32              informat;  /*!< input file format, IFF_*          */
145     l_int32              special;   /*!< special instructions for I/O, etc */
146     char                *text;      /*!< text string associated with pix   */
147     struct PixColormap  *colormap;  /*!< colormap (may be null)            */
148     l_uint32            *data;      /*!< the image data                    */
149 };
150 typedef struct Pix PIX;
151 
152 /*! Colormap of a Pix */
153 struct PixColormap
154 {
155     void            *array;   /*!< colormap table (array of RGBA_QUAD)     */
156     l_int32          depth;   /*!< of pix (1, 2, 4 or 8 bpp)               */
157     l_int32          nalloc;  /*!< number of color entries allocated       */
158     l_int32          n;       /*!< number of color entries used            */
159 };
160 typedef struct PixColormap  PIXCMAP;
161 
162 
163     /*! Colormap table entry (after the BMP version).
164      * Note that the BMP format stores the colormap table exactly
165      * as it appears here, with color samples being stored sequentially,
166      * in the order (b,g,r,a). */
167 struct RGBA_Quad
168 {
169     l_uint8     blue;         /*!< blue value */
170     l_uint8     green;        /*!< green value */
171     l_uint8     red;          /*!< red value */
172     l_uint8     alpha;        /*!< alpha value */
173 };
174 typedef struct RGBA_Quad  RGBA_QUAD;
175 
176 
177 
178 /*-------------------------------------------------------------------------*
179  *                             Colors for 32 bpp                           *
180  *-------------------------------------------------------------------------*/
181 /* <pre>
182  *  Notes:
183  *      (1) These are the byte indices for colors in 32 bpp images.
184  *          They are used through the GET/SET_DATA_BYTE accessors.
185  *          The 4th byte, typically known as the "alpha channel" and used
186  *          for blending, is used to a small extent in leptonica.
187  *      (2) Do not change these values!  If you redefine them, functions
188  *          that have the shifts hardcoded for efficiency and conciseness
189  *          (instead of using the constants below) will break.  These
190  *          functions are labelled with "***"  next to their names at
191  *          the top of the files in which they are defined.
192  *      (3) The shifts to extract the red, green, blue and alpha components
193  *          from a 32 bit pixel are defined here.
194  * </pre>
195  */
196 
197 /*! Colors for 32 bpp */
198 enum {
199     COLOR_RED = 0,        /*!< red color index in RGBA_QUAD    */
200     COLOR_GREEN = 1,      /*!< green color index in RGBA_QUAD  */
201     COLOR_BLUE = 2,       /*!< blue color index in RGBA_QUAD   */
202     L_ALPHA_CHANNEL = 3   /*!< alpha value index in RGBA_QUAD  */
203 };
204 
205 static const l_int32  L_RED_SHIFT =
206        8 * (sizeof(l_uint32) - 1 - COLOR_RED);           /* 24 */
207 static const l_int32  L_GREEN_SHIFT =
208        8 * (sizeof(l_uint32) - 1 - COLOR_GREEN);         /* 16 */
209 static const l_int32  L_BLUE_SHIFT =
210        8 * (sizeof(l_uint32) - 1 - COLOR_BLUE);          /*  8 */
211 static const l_int32  L_ALPHA_SHIFT =
212        8 * (sizeof(l_uint32) - 1 - L_ALPHA_CHANNEL);     /*  0 */
213 
214 
215 /*-------------------------------------------------------------------------*
216  *                       Colors for drawing boxes                          *
217  *-------------------------------------------------------------------------*/
218 /*! Colors for drawing boxes */
219 enum {
220     L_DRAW_RED = 0,         /*!< draw in red                   */
221     L_DRAW_GREEN = 1,       /*!< draw in green                 */
222     L_DRAW_BLUE = 2,        /*!< draw in blue                  */
223     L_DRAW_SPECIFIED = 3,   /*!< draw specified color          */
224     L_DRAW_RGB = 4,         /*!< draw as sequence of r,g,b     */
225     L_DRAW_RANDOM = 5       /*!< draw randomly chosen colors   */
226 };
227 
228 
229 /*-------------------------------------------------------------------------*
230  *                       Perceptual color weights                          *
231  *-------------------------------------------------------------------------*/
232 /* <pre>
233  *  Notes:
234  *      (1) These perceptual weighting factors are ad-hoc, but they do
235  *          add up to 1.  Unlike, for example, the weighting factors for
236  *          converting RGB to luminance, or more specifically to Y in the
237  *          YUV colorspace.  Those numbers come from the
238  *          International Telecommunications Union, via ITU-R.
239  * </pre>
240  */
241 static const l_float32  L_RED_WEIGHT =   0.3;  /*!< Percept. weight for red   */
242 static const l_float32  L_GREEN_WEIGHT = 0.5;  /*!< Percept. weight for green */
243 static const l_float32  L_BLUE_WEIGHT =  0.2;  /*!< Percept. weight for blue  */
244 
245 
246 /*-------------------------------------------------------------------------*
247  *                        Flags for colormap conversion                    *
248  *-------------------------------------------------------------------------*/
249 /*! Flags for colormap conversion */
250 enum {
251     REMOVE_CMAP_TO_BINARY = 0,     /*!< remove colormap for conv to 1 bpp  */
252     REMOVE_CMAP_TO_GRAYSCALE = 1,  /*!< remove colormap for conv to 8 bpp  */
253     REMOVE_CMAP_TO_FULL_COLOR = 2, /*!< remove colormap for conv to 32 bpp */
254     REMOVE_CMAP_WITH_ALPHA = 3,    /*!< remove colormap and alpha          */
255     REMOVE_CMAP_BASED_ON_SRC = 4   /*!< remove depending on src format     */
256 };
257 
258 
259 /*------------------------------------------------------------------------*
260  *!
261  * <pre>
262  * The following operation bit flags have been modified from
263  * Sun's pixrect.h.
264  *
265  * The 'op' in 'rasterop' is represented by an integer
266  * composed with Boolean functions using the set of five integers
267  * given below.  The integers, and the op codes resulting from
268  * boolean expressions on them, need only be in the range from 0 to 15.
269  * The function is applied on a per-pixel basis.
270  *
271  * Examples: the op code representing ORing the src and dest
272  * is computed using the bit OR, as PIX_SRC | PIX_DST;  the op
273  * code representing XORing src and dest is found from
274  * PIX_SRC ^ PIX_DST;  the op code representing ANDing src and dest
275  * is found from PIX_SRC & PIX_DST.  Note that
276  * PIX_NOT(PIX_CLR) = PIX_SET, and v.v., as they must be.
277  *
278  * We use the following set of definitions:
279  *
280  *      #define   PIX_SRC      0xc
281  *      #define   PIX_DST      0xa
282  *      #define   PIX_NOT(op)  (op) ^ 0xf
283  *      #define   PIX_CLR      0x0
284  *      #define   PIX_SET      0xf
285  *
286  * These definitions differ from Sun's, in that Sun left-shifted
287  * each value by 1 pixel, and used the least significant bit as a
288  * flag for the "pseudo-operation" of clipping.  We don't need
289  * this bit, because it is both efficient and safe ALWAYS to clip
290  * the rectangles to the src and dest images, which is what we do.
291  * See the notes in rop.h on the general choice of these bit flags.
292  *
293  * [If for some reason you need compatibility with Sun's xview package,
294  * you can adopt the original Sun definitions to avoid redefinition conflicts:
295  *
296  *      #define   PIX_SRC      (0xc << 1)
297  *      #define   PIX_DST      (0xa << 1)
298  *      #define   PIX_NOT(op)  ((op) ^ 0x1e)
299  *      #define   PIX_CLR      (0x0 << 1)
300  *      #define   PIX_SET      (0xf << 1)
301  * ]
302  *
303  * We have, for reference, the following 16 unique op flags:
304  *
305  *      PIX_CLR                           0000             0x0
306  *      PIX_SET                           1111             0xf
307  *      PIX_SRC                           1100             0xc
308  *      PIX_DST                           1010             0xa
309  *      PIX_NOT(PIX_SRC)                  0011             0x3
310  *      PIX_NOT(PIX_DST)                  0101             0x5
311  *      PIX_SRC | PIX_DST                 1110             0xe
312  *      PIX_SRC & PIX_DST                 1000             0x8
313  *      PIX_SRC ^ PIX_DST                 0110             0x6
314  *      PIX_NOT(PIX_SRC) | PIX_DST        1011             0xb
315  *      PIX_NOT(PIX_SRC) & PIX_DST        0010             0x2
316  *      PIX_SRC | PIX_NOT(PIX_DST)        1101             0xd
317  *      PIX_SRC & PIX_NOT(PIX_DST)        0100             0x4
318  *      PIX_NOT(PIX_SRC | PIX_DST)        0001             0x1
319  *      PIX_NOT(PIX_SRC & PIX_DST)        0111             0x7
320  *      PIX_NOT(PIX_SRC ^ PIX_DST)        1001             0x9
321  *
322  * </pre>
323  *-------------------------------------------------------------------------*/
324 
325 #define   PIX_SRC      (0xc)                      /*!< use source pixels      */
326 #define   PIX_DST      (0xa)                      /*!< use destination pixels */
327 #define   PIX_NOT(op)  ((op) ^ 0x0f)              /*!< invert operation %op   */
328 #define   PIX_CLR      (0x0)                      /*!< clear pixels           */
329 #define   PIX_SET      (0xf)                      /*!< set pixels             */
330 
331 #define   PIX_PAINT    (PIX_SRC | PIX_DST)        /*!< paint = src | dst      */
332 #define   PIX_MASK     (PIX_SRC & PIX_DST)        /*!< mask = src & dst       */
333 #define   PIX_SUBTRACT (PIX_DST & PIX_NOT(PIX_SRC)) /*!< subtract =           */
334                                                     /*!<    src & !dst        */
335 #define   PIX_XOR      (PIX_SRC ^ PIX_DST)        /*!< xor = src ^ dst        */
336 
337 
338 /*-------------------------------------------------------------------------*
339  * <pre>
340  *   Important Notes:
341  *
342  *       (1) The image data is stored in a single contiguous
343  *           array of l_uint32, into which the pixels are packed.
344  *           By "packed" we mean that there are no unused bits
345  *           between pixels, except for end-of-line padding to
346  *           satisfy item (2) below.
347  *
348  *       (2) Every image raster line begins on a 32-bit word
349  *           boundary within this array.
350  *
351  *       (3) Pix image data is stored in 32-bit units, with the
352  *           pixels ordered from left to right in the image being
353  *           stored in order from the MSB to LSB within the word,
354  *           for both big-endian and little-endian machines.
355  *           This is the natural ordering for big-endian machines,
356  *           as successive bytes are stored and fetched progressively
357  *           to the right.  However, for little-endians, when storing
358  *           we re-order the bytes from this byte stream order, and
359  *           reshuffle again for byte access on 32-bit entities.
360  *           So if the bytes come in sequence from left to right, we
361  *           store them on little-endians in byte order:
362  *                3 2 1 0 7 6 5 4 ...
363  *           This MSB to LSB ordering allows left and right shift
364  *           operations on 32 bit words to move the pixels properly.
365  *
366  *       (4) We use 32 bit pixels for both RGB and RGBA color images.
367  *           The A (alpha) byte is ignored in most leptonica functions
368  *           operating on color images.  Within each 4 byte pixel, the
369  *           colors are ordered from MSB to LSB, as follows:
370  *
371  *                |  MSB  |  2nd MSB  |  3rd MSB  |  LSB  |
372  *                   red      green       blue      alpha
373  *                    0         1           2         3   (big-endian)
374  *                    3         2           1         0   (little-endian)
375  *
376  *           Because we use MSB to LSB ordering within the 32-bit word,
377  *           the individual 8-bit samples can be accessed with
378  *           GET_DATA_BYTE and SET_DATA_BYTE macros, using the
379  *           (implicitly big-ending) ordering
380  *                 red:    byte 0  (MSB)
381  *                 green:  byte 1  (2nd MSB)
382  *                 blue:   byte 2  (3rd MSB)
383  *                 alpha:  byte 3  (LSB)
384  *
385  *           The specific color assignment is made in this file,
386  *           through the definitions of COLOR_RED, etc.  Then the R, G
387  *           B and A sample values can be retrieved using
388  *                 redval = GET_DATA_BYTE(&pixel, COLOR_RED);
389  *                 greenval = GET_DATA_BYTE(&pixel, COLOR_GREEN);
390  *                 blueval = GET_DATA_BYTE(&pixel, COLOR_BLUE);
391  *                 alphaval = GET_DATA_BYTE(&pixel, L_ALPHA_CHANNEL);
392  *           and they can be set with
393  *                 SET_DATA_BYTE(&pixel, COLOR_RED, redval);
394  *                 SET_DATA_BYTE(&pixel, COLOR_GREEN, greenval);
395  *                 SET_DATA_BYTE(&pixel, COLOR_BLUE, blueval);
396  *                 SET_DATA_BYTE(&pixel, L_ALPHA_CHANNEL, alphaval);
397  *
398  *           For extra speed we extract these components directly
399  *           by shifting and masking, explicitly using the values in
400  *           L_RED_SHIFT, etc.:
401  *                 (pixel32 >> L_RED_SHIFT) & 0xff;         (red)
402  *                 (pixel32 >> L_GREEN_SHIFT) & 0xff;       (green)
403  *                 (pixel32 >> L_BLUE_SHIFT) & 0xff;        (blue)
404  *                 (pixel32 >> L_ALPHA_SHIFT) & 0xff;       (alpha)
405  *           All these operations work properly on both big- and little-endians.
406  *
407  *           For a few situations, these color shift values are hard-coded.
408  *           Changing the RGB color component ordering through the assignments
409  *           in this file will cause functions marked with "***" to fail.
410  *
411  *       (5) A reference count is held within each pix, giving the
412  *           number of ptrs to the pix.  When a pixClone() call
413  *           is made, the ref count is increased by 1, and
414  *           when a pixDestroy() call is made, the reference count
415  *           of the pix is decremented.  The pix is only destroyed
416  *           when the reference count goes to zero.
417  *
418  *       (6) The version numbers (below) are used in the serialization
419  *           of these data structures.  They are placed in the files,
420  *           and rarely (if ever) change.  Provision is currently made for
421  *           backward compatibility in reading from boxaa version 2.
422  *
423  *       (7) The serialization dependencies are as follows:
424  *               pixaa  :  pixa  :  boxa
425  *               boxaa  :  boxa
426  *           So, for example, pixaa and boxaa can be changed without
427  *           forcing a change in pixa or boxa.  However, if pixa is
428  *           changed, it forces a change in pixaa, and if boxa is
429  *           changed, if forces a change in the other three.
430  *           We define four version numbers:
431  *               PIXAA_VERSION_NUMBER
432  *               PIXA_VERSION_NUMBER
433  *               BOXAA_VERSION_NUMBER
434  *               BOXA_VERSION_NUMBER
435  * </pre>
436  *-------------------------------------------------------------------------*/
437 
438 
439 
440 /*-------------------------------------------------------------------------*
441  *                              Array of pix                               *
442  *-------------------------------------------------------------------------*/
443 
444     /*  Serialization for primary data structures */
445 #define  PIXAA_VERSION_NUMBER      2  /*!< Version for Pixaa serialization */
446 #define  PIXA_VERSION_NUMBER       2  /*!< Version for Pixa serialization  */
447 #define  BOXA_VERSION_NUMBER       2  /*!< Version for Boxa serialization  */
448 #define  BOXAA_VERSION_NUMBER      3  /*!< Version for Boxaa serialization */
449 
450 /*! Array of pix */
451 struct Pixa
452 {
453     l_int32             n;          /*!< number of Pix in ptr array        */
454     l_int32             nalloc;     /*!< number of Pix ptrs allocated      */
455     l_uint32            refcount;   /*!< reference count (1 if no clones)  */
456     struct Pix        **pix;        /*!< the array of ptrs to pix          */
457     struct Boxa        *boxa;       /*!< array of boxes                    */
458 };
459 typedef struct Pixa PIXA;
460 
461 /*! Array of arrays of pix */
462 struct Pixaa
463 {
464     l_int32             n;          /*!< number of Pixa in ptr array       */
465     l_int32             nalloc;     /*!< number of Pixa ptrs allocated     */
466     struct Pixa       **pixa;       /*!< array of ptrs to pixa             */
467     struct Boxa        *boxa;       /*!< array of boxes                    */
468 };
469 typedef struct Pixaa PIXAA;
470 
471 
472 /*-------------------------------------------------------------------------*
473  *                    Basic rectangle and rectangle arrays                 *
474  *-------------------------------------------------------------------------*/
475 
476 /*! Basic rectangle */
477 struct Box
478 {
479     l_int32            x;           /*!< left coordinate                   */
480     l_int32            y;           /*!< top coordinate                    */
481     l_int32            w;           /*!< box width                         */
482     l_int32            h;           /*!< box height                        */
483     l_uint32           refcount;    /*!< reference count (1 if no clones)  */
484 
485 };
486 typedef struct Box    BOX;
487 
488 /*! Array of Box */
489 struct Boxa
490 {
491     l_int32            n;           /*!< number of box in ptr array        */
492     l_int32            nalloc;      /*!< number of box ptrs allocated      */
493     l_uint32           refcount;    /*!< reference count (1 if no clones)  */
494     struct Box       **box;         /*!< box ptr array                     */
495 };
496 typedef struct Boxa  BOXA;
497 
498 /*! Array of Boxa */
499 struct Boxaa
500 {
501     l_int32            n;           /*!< number of boxa in ptr array       */
502     l_int32            nalloc;      /*!< number of boxa ptrs allocated     */
503     struct Boxa      **boxa;        /*!< boxa ptr array                    */
504 };
505 typedef struct Boxaa  BOXAA;
506 
507 
508 /*-------------------------------------------------------------------------*
509  *                               Array of points                           *
510  *-------------------------------------------------------------------------*/
511 #define  PTA_VERSION_NUMBER      1  /*!< Version for Pta serialization     */
512 
513 /*! Array of points */
514 struct Pta
515 {
516     l_int32            n;           /*!< actual number of pts              */
517     l_int32            nalloc;      /*!< size of allocated arrays          */
518     l_uint32           refcount;    /*!< reference count (1 if no clones)  */
519     l_float32         *x, *y;       /*!< arrays of floats                  */
520 };
521 typedef struct Pta PTA;
522 
523 
524 /*-------------------------------------------------------------------------*
525  *                              Array of Pta                               *
526  *-------------------------------------------------------------------------*/
527 
528 /*! Array of Pta */
529 struct Ptaa
530 {
531     l_int32              n;         /*!< number of pta in ptr array        */
532     l_int32              nalloc;    /*!< number of pta ptrs allocated      */
533     struct Pta         **pta;       /*!< pta ptr array                     */
534 };
535 typedef struct Ptaa PTAA;
536 
537 
538 /*-------------------------------------------------------------------------*
539  *                       Pix accumulator container                         *
540  *-------------------------------------------------------------------------*/
541 
542 /*! Pix accumulator container */
543 struct Pixacc
544 {
545     l_int32             w;          /*!< array width                       */
546     l_int32             h;          /*!< array height                      */
547     l_int32             offset;     /*!< used to allow negative            */
548                                     /*!< intermediate results              */
549     struct Pix         *pix;        /*!< the 32 bit accumulator pix        */
550 };
551 typedef struct Pixacc PIXACC;
552 
553 
554 /*-------------------------------------------------------------------------*
555  *                              Pix tiling                                 *
556  *-------------------------------------------------------------------------*/
557 
558 /*! Pix tiling */
559 struct PixTiling
560 {
561     struct Pix          *pix;       /*!< input pix (a clone)               */
562     l_int32              nx;        /*!< number of tiles horizontally      */
563     l_int32              ny;        /*!< number of tiles vertically        */
564     l_int32              w;         /*!< tile width                        */
565     l_int32              h;         /*!< tile height                       */
566     l_int32              xoverlap;  /*!< overlap on left and right         */
567     l_int32              yoverlap;  /*!< overlap on top and bottom         */
568     l_int32              strip;     /*!< strip for paint; default is TRUE  */
569 };
570 typedef struct PixTiling PIXTILING;
571 
572 
573 /*-------------------------------------------------------------------------*
574  *                       FPix: pix with float array                        *
575  *-------------------------------------------------------------------------*/
576 #define  FPIX_VERSION_NUMBER      2 /*!< Version for FPix serialization    */
577 
578 /*! Pix with float array */
579 struct FPix
580 {
581     l_int32              w;         /*!< width in pixels                   */
582     l_int32              h;         /*!< height in pixels                  */
583     l_int32              wpl;       /*!< 32-bit words/line                 */
584     l_uint32             refcount;  /*!< reference count (1 if no clones)  */
585     l_int32              xres;      /*!< image res (ppi) in x direction    */
586                                     /*!< (use 0 if unknown)                */
587     l_int32              yres;      /*!< image res (ppi) in y direction    */
588                                     /*!< (use 0 if unknown)                */
589     l_float32           *data;      /*!< the float image data              */
590 };
591 typedef struct FPix FPIX;
592 
593 /*! Array of FPix */
594 struct FPixa
595 {
596     l_int32             n;          /*!< number of fpix in ptr array       */
597     l_int32             nalloc;     /*!< number of fpix ptrs allocated     */
598     l_uint32            refcount;   /*!< reference count (1 if no clones)  */
599     struct FPix       **fpix;       /*!< the array of ptrs to fpix         */
600 };
601 typedef struct FPixa FPIXA;
602 
603 
604 /*-------------------------------------------------------------------------*
605  *                       DPix: pix with double array                       *
606  *-------------------------------------------------------------------------*/
607 #define  DPIX_VERSION_NUMBER      2 /*!< Version for DPix serialization    */
608 
609 /*! Pix with double array */
610 struct DPix
611 {
612     l_int32              w;         /*!< width in pixels                   */
613     l_int32              h;         /*!< height in pixels                  */
614     l_int32              wpl;       /*!< 32-bit words/line                 */
615     l_uint32             refcount;  /*!< reference count (1 if no clones)  */
616     l_int32              xres;      /*!< image res (ppi) in x direction    */
617                                     /*!< (use 0 if unknown)                */
618     l_int32              yres;      /*!< image res (ppi) in y direction    */
619                                     /*!< (use 0 if unknown)                */
620     l_float64           *data;      /*!< the double image data             */
621 };
622 typedef struct DPix DPIX;
623 
624 
625 /*-------------------------------------------------------------------------*
626  *                        PixComp: compressed pix                          *
627  *-------------------------------------------------------------------------*/
628 
629 /*! Compressed Pix */
630 struct PixComp
631 {
632     l_int32              w;         /*!< width in pixels                   */
633     l_int32              h;         /*!< height in pixels                  */
634     l_int32              d;         /*!< depth in bits                     */
635     l_int32              xres;      /*!< image res (ppi) in x direction    */
636                                     /*!<   (use 0 if unknown)              */
637     l_int32              yres;      /*!< image res (ppi) in y direction    */
638                                     /*!<   (use 0 if unknown)              */
639     l_int32              comptype;  /*!< compressed format (IFF_TIFF_G4,   */
640                                     /*!<   IFF_PNG, IFF_JFIF_JPEG)         */
641     char                *text;      /*!< text string associated with pix   */
642     l_int32              cmapflag;  /*!< flag (1 for cmap, 0 otherwise)    */
643     l_uint8             *data;      /*!< the compressed image data         */
644     size_t               size;      /*!< size of the data array            */
645 };
646 typedef struct PixComp PIXC;
647 
648 
649 /*-------------------------------------------------------------------------*
650  *                     PixaComp: array of compressed pix                   *
651  *-------------------------------------------------------------------------*/
652 #define  PIXACOMP_VERSION_NUMBER 2  /*!< Version for PixaComp serialization */
653 
654 /*! Array of compressed pix */
655 struct PixaComp
656 {
657     l_int32              n;         /*!< number of PixComp in ptr array    */
658     l_int32              nalloc;    /*!< number of PixComp ptrs allocated  */
659     l_int32              offset;    /*!< indexing offset into ptr array    */
660     struct PixComp     **pixc;      /*!< the array of ptrs to PixComp      */
661     struct Boxa         *boxa;      /*!< array of boxes                    */
662 };
663 typedef struct PixaComp PIXAC;
664 
665 
666 /*-------------------------------------------------------------------------*
667  *                         Access and storage flags                        *
668  *-------------------------------------------------------------------------*/
669 /*
670  * <pre>
671  *  For Pix, Box, Pta and Numa, there are 3 standard methods for handling
672  *  the retrieval or insertion of a struct:
673  *     (1) direct insertion (Don't do this if there is another handle
674  *                           somewhere to this same struct!)
675  *     (2) copy (Always safe, sets up a refcount of 1 on the new object.
676  *               Can be undesirable if very large, such as an image or
677  *               an array of images.)
678  *     (3) clone (Makes another handle to the same struct, and bumps the
679  *                refcount up by 1.  Safe to do unless you're changing
680  *                data through one of the handles but don't want those
681  *                changes to be seen by the other handle.)
682  *
683  *  For Pixa and Boxa, which are structs that hold an array of clonable
684  *  structs, there is an additional method:
685  *     (4) copy-clone (Makes a new higher-level struct with a refcount
686  *                     of 1, but clones all the structs in the array.)
687  *
688  *  Unlike the other structs, when retrieving a string from an Sarray,
689  *  you are allowed to get a handle without a copy or clone (i.e., that
690  *  you don't own!).  You must not free or insert such a string!
691  *  Specifically, for an Sarray, the copyflag for retrieval is either:
692  *         L_COPY or L_NOCOPY
693  *  and for insertion, the copyflag is either:
694  *         L_COPY or one of {L_INSERT , L_NOCOPY} (the latter are equivalent
695  *                                                 for insertion))
696  * </pre>
697  */
698 
699 /*! Access and storage flags */
700 enum {
701     L_NOCOPY = 0,     /*!< do not copy the object; do not delete the ptr  */
702     L_COPY = 1,       /*!< make/use a copy of the object                  */
703     L_CLONE = 2,      /*!< make/use clone (ref count) of the object       */
704     L_COPY_CLONE = 3  /*!< make a new object and fill each object in the  */
705                       /*!< array(s) with clones                           */
706 };
707 static const l_int32  L_INSERT = 0;  /*!< stuff it in; no copy or clone   */
708 
709 
710 /*----------------------------------------------------------------------------*
711  *                              Sort flags                                    *
712  *----------------------------------------------------------------------------*/
713 
714 /*! Sort mode flags */
715 enum {
716     L_SHELL_SORT = 1,            /*!< use shell sort                        */
717     L_BIN_SORT = 2               /*!< use bin sort                          */
718 };
719 
720 /*! Sort order flags */
721 enum {
722     L_SORT_INCREASING = 1,       /*!< sort in increasing order              */
723     L_SORT_DECREASING = 2        /*!< sort in decreasing order              */
724 };
725 
726 /*! Sort type flags */
727 enum {
728     L_SORT_BY_X = 1,             /*!< sort box or c.c. by left edge location  */
729     L_SORT_BY_Y = 2,             /*!< sort box or c.c. by top edge location   */
730     L_SORT_BY_RIGHT = 3,         /*!< sort box or c.c. by right edge location */
731     L_SORT_BY_BOT = 4,           /*!< sort box or c.c. by bot edge location   */
732     L_SORT_BY_WIDTH = 5,         /*!< sort box or c.c. by width               */
733     L_SORT_BY_HEIGHT = 6,        /*!< sort box or c.c. by height              */
734     L_SORT_BY_MIN_DIMENSION = 7, /*!< sort box or c.c. by min dimension       */
735     L_SORT_BY_MAX_DIMENSION = 8, /*!< sort box or c.c. by max dimension       */
736     L_SORT_BY_PERIMETER = 9,     /*!< sort box or c.c. by perimeter           */
737     L_SORT_BY_AREA = 10,         /*!< sort box or c.c. by area                */
738     L_SORT_BY_ASPECT_RATIO = 11  /*!< sort box or c.c. by width/height ratio  */
739 };
740 
741 
742 /*---------------------------------------------------------------------------*
743  *                             Blend flags                                   *
744  *---------------------------------------------------------------------------*/
745 
746 /*! Blend flags */
747 enum {
748     L_BLEND_WITH_INVERSE = 1,     /*!< add some of src inverse to itself     */
749     L_BLEND_TO_WHITE = 2,         /*!< shift src colors towards white        */
750     L_BLEND_TO_BLACK = 3,         /*!< shift src colors towards black        */
751     L_BLEND_GRAY = 4,             /*!< blend src directly with blender       */
752     L_BLEND_GRAY_WITH_INVERSE = 5 /*!< add amount of src inverse to itself,  */
753                                   /*!< based on blender pix value            */
754 };
755 
756 enum {
757     L_PAINT_LIGHT = 1,            /*!< colorize non-black pixels             */
758     L_PAINT_DARK = 2              /*!< colorize non-white pixels             */
759 };
760 
761 
762 /*-------------------------------------------------------------------------*
763  *                        Graphics pixel setting                           *
764  *-------------------------------------------------------------------------*/
765 
766 /*! Graphics pixel setting */
767 enum {
768     L_SET_PIXELS = 1,           /*!< set all bits in each pixel to 1       */
769     L_CLEAR_PIXELS = 2,         /*!< set all bits in each pixel to 0       */
770     L_FLIP_PIXELS = 3           /*!< flip all bits in each pixel           */
771 };
772 
773 
774 /*-------------------------------------------------------------------------*
775  *                     Size and location filter flags                      *
776  *-------------------------------------------------------------------------*/
777 
778 /*! Location filter flags */
779 enum {
780     L_SELECT_WIDTH = 1,         /*!< width must satisfy constraint         */
781     L_SELECT_HEIGHT = 2,        /*!< height must satisfy constraint        */
782     L_SELECT_XVAL = 3,          /*!< x value satisfy constraint            */
783     L_SELECT_YVAL = 4,          /*!< y value must satisfy constraint       */
784     L_SELECT_IF_EITHER = 5,     /*!< either width or height (or xval       */
785                                 /*!< or yval) can satisfy                  */
786     L_SELECT_IF_BOTH = 6        /*!< both width and height (or xval        */
787                                 /*!< and yval must satisfy                 */
788 };
789 
790 /*! Size filter flags */
791 enum {
792     L_SELECT_IF_LT = 1,         /*!< save if value is less than threshold  */
793     L_SELECT_IF_GT = 2,         /*!< save if value is more than threshold  */
794     L_SELECT_IF_LTE = 3,        /*!< save if value is <= to the threshold  */
795     L_SELECT_IF_GTE = 4         /*!< save if value is >= to the threshold  */
796 };
797 
798 
799 /*-------------------------------------------------------------------------*
800  *                     Color component selection flags                     *
801  *-------------------------------------------------------------------------*/
802 
803 /*! Color component selection flags */
804 enum {
805     L_SELECT_RED = 1,           /*!< use red component                     */
806     L_SELECT_GREEN = 2,         /*!< use green component                   */
807     L_SELECT_BLUE = 3,          /*!< use blue component                    */
808     L_SELECT_MIN = 4,           /*!< use min color component               */
809     L_SELECT_MAX = 5,           /*!< use max color component               */
810     L_SELECT_AVERAGE = 6        /*!< use average of color components       */
811 };
812 
813 
814 /*-------------------------------------------------------------------------*
815  *                         16-bit conversion flags                         *
816  *-------------------------------------------------------------------------*/
817 
818 /*! 16-bit conversion flags */
819 enum {
820     L_LS_BYTE = 1,              /*!< use LSB                               */
821     L_MS_BYTE = 2,              /*!< use MSB                               */
822     L_CLIP_TO_FF = 3,           /*!< use max(val, 255)                     */
823     L_LS_TWO_BYTES = 4,         /*!< use two LSB                           */
824     L_MS_TWO_BYTES = 5,         /*!< use two MSB                           */
825     L_CLIP_TO_FFFF = 6          /*!< use max(val, 65535)                   */
826 };
827 
828 
829 /*-------------------------------------------------------------------------*
830  *                        Rotate and shear flags                           *
831  *-------------------------------------------------------------------------*/
832 
833 /*! Rotate flags */
834 enum {
835     L_ROTATE_AREA_MAP = 1,     /*!< use area map rotation, if possible     */
836     L_ROTATE_SHEAR = 2,        /*!< use shear rotation                     */
837     L_ROTATE_SAMPLING = 3      /*!< use sampling                           */
838 };
839 
840 /*! Background flags */
841 enum {
842     L_BRING_IN_WHITE = 1,      /*!< bring in white pixels from the outside */
843     L_BRING_IN_BLACK = 2       /*!< bring in black pixels from the outside */
844 };
845 
846 /*! Shear flags */
847 enum {
848     L_SHEAR_ABOUT_CORNER = 1,  /*!< shear image about UL corner            */
849     L_SHEAR_ABOUT_CENTER = 2   /*!< shear image about center               */
850 };
851 
852 
853 /*-------------------------------------------------------------------------*
854  *                     Affine transform order flags                        *
855  *-------------------------------------------------------------------------*/
856 
857 /*! Affine transform order flags */
858 enum {
859     L_TR_SC_RO = 1,            /*!< translate, scale, rotate               */
860     L_SC_RO_TR = 2,            /*!< scale, rotate, translate               */
861     L_RO_TR_SC = 3,            /*!< rotate, translate, scale               */
862     L_TR_RO_SC = 4,            /*!< translate, rotate, scale               */
863     L_RO_SC_TR = 5,            /*!< rotate, scale, translate               */
864     L_SC_TR_RO = 6             /*!< scale, translate, rotate               */
865 };
866 
867 
868 /*-------------------------------------------------------------------------*
869  *                       Grayscale filling flags                           *
870  *-------------------------------------------------------------------------*/
871 
872 /*! Grayscale filling flags */
873 enum {
874     L_FILL_WHITE = 1,         /*!< fill white pixels (e.g, in fg map)      */
875     L_FILL_BLACK = 2          /*!< fill black pixels (e.g., in bg map)     */
876 };
877 
878 
879 /*-------------------------------------------------------------------------*
880  *                   Flags for setting to white or black                   *
881  *-------------------------------------------------------------------------*/
882 
883 /*! Flags for setting to white or black */
884 enum {
885     L_SET_WHITE = 1,         /*!< set pixels to white                      */
886     L_SET_BLACK = 2          /*!< set pixels to black                      */
887 };
888 
889 
890 /*-------------------------------------------------------------------------*
891  *                  Flags for getting white or black value                 *
892  *-------------------------------------------------------------------------*/
893 
894 /*! Flags for getting white or black value */
895 enum {
896     L_GET_WHITE_VAL = 1,     /*!< get white pixel value                    */
897     L_GET_BLACK_VAL = 2      /*!< get black pixel value                    */
898 };
899 
900 
901 /*-------------------------------------------------------------------------*
902  *                  Flags for 8 bit and 16 bit pixel sums                  *
903  *-------------------------------------------------------------------------*/
904 
905 /*! Flags for 8 bit and 16 bit pixel sums */
906 enum {
907     L_WHITE_IS_MAX = 1, /*!< white pixels are 0xff or 0xffff; black are 0  */
908     L_BLACK_IS_MAX = 2  /*!< black pixels are 0xff or 0xffff; white are 0  */
909 };
910 
911 
912 /*-------------------------------------------------------------------------*
913  *                           Dither parameters                             *
914  *         If within this grayscale distance from black or white,          *
915  *         do not propagate excess or deficit to neighboring pixels.       *
916  *-------------------------------------------------------------------------*/
917 
918 /*! Dither parameters */
919 enum {
920     DEFAULT_CLIP_LOWER_1 = 10, /*!< dist to black with no prop; 1 bpp      */
921     DEFAULT_CLIP_UPPER_1 = 10, /*!< dist to black with no prop; 1 bpp      */
922     DEFAULT_CLIP_LOWER_2 = 5,  /*!< dist to black with no prop; 2 bpp      */
923     DEFAULT_CLIP_UPPER_2 = 5   /*!< dist to black with no prop; 2 bpp      */
924 };
925 
926 
927 /*-------------------------------------------------------------------------*
928  *                             Distance flags                              *
929  *-------------------------------------------------------------------------*/
930 
931 /*! Distance flags */
932 enum {
933     L_MANHATTAN_DISTANCE = 1,  /*!< L1 distance (e.g., in color space)     */
934     L_EUCLIDEAN_DISTANCE = 2   /*!< L2 distance                            */
935 };
936 
937 
938 /*-------------------------------------------------------------------------*
939  *                         Statistical measures                            *
940  *-------------------------------------------------------------------------*/
941 
942 /*! Statistical measures */
943 enum {
944     L_MEAN_ABSVAL = 1,         /*!< average of abs values                  */
945     L_MEDIAN_VAL = 2,          /*!< median value of set                    */
946     L_MODE_VAL = 3,            /*!< mode value of set                      */
947     L_MODE_COUNT = 4,          /*!< mode count of set                      */
948     L_ROOT_MEAN_SQUARE = 5,    /*!< rms of values                          */
949     L_STANDARD_DEVIATION = 6,  /*!< standard deviation from mean           */
950     L_VARIANCE = 7             /*!< variance of values                     */
951 };
952 
953 
954 /*-------------------------------------------------------------------------*
955  *                          Set selection flags                            *
956  *-------------------------------------------------------------------------*/
957 
958 /*! Set selection flags */
959 enum {
960     L_CHOOSE_CONSECUTIVE = 1,  /*!< select 'n' consecutive                 */
961     L_CHOOSE_SKIP_BY = 2       /*!< select at intervals of 'n'             */
962 };
963 
964 
965 /*-------------------------------------------------------------------------*
966  *                         Text orientation flags                          *
967  *-------------------------------------------------------------------------*/
968 
969 /*! Text orientation flags */
970 enum {
971     L_TEXT_ORIENT_UNKNOWN = 0, /*!< low confidence on text orientation     */
972     L_TEXT_ORIENT_UP = 1,      /*!< portrait, text rightside-up            */
973     L_TEXT_ORIENT_LEFT = 2,    /*!< landscape, text up to left             */
974     L_TEXT_ORIENT_DOWN = 3,    /*!< portrait, text upside-down             */
975     L_TEXT_ORIENT_RIGHT = 4    /*!< landscape, text up to right            */
976 };
977 
978 
979 /*-------------------------------------------------------------------------*
980  *                         Edge orientation flags                          *
981  *-------------------------------------------------------------------------*/
982 
983 /*! Edge orientation flags */
984 enum {
985     L_HORIZONTAL_EDGES = 0,   /*!< filters for horizontal edges            */
986     L_VERTICAL_EDGES = 1,     /*!< filters for vertical edges              */
987     L_ALL_EDGES = 2           /*!< filters for all edges                   */
988 };
989 
990 
991 /*-------------------------------------------------------------------------*
992  *                         Line orientation flags                          *
993  *-------------------------------------------------------------------------*/
994 
995 /*! Line orientation flags */
996 enum {
997     L_HORIZONTAL_LINE = 0,   /*!< horizontal line                          */
998     L_POS_SLOPE_LINE = 1,    /*!< 45 degree line with positive slope       */
999     L_VERTICAL_LINE = 2,     /*!< vertical line                            */
1000     L_NEG_SLOPE_LINE = 3,    /*!< 45 degree line with negative slope       */
1001     L_OBLIQUE_LINE = 4       /*!< neither horizontal nor vertical */
1002 };
1003 
1004 
1005 /*-------------------------------------------------------------------------*
1006  *                           Scan direction flags                          *
1007  *-------------------------------------------------------------------------*/
1008 
1009 /*! Scan direction flags */
1010 enum {
1011     L_FROM_LEFT = 0,         /*!< scan from left                           */
1012     L_FROM_RIGHT = 1,        /*!< scan from right                          */
1013     L_FROM_TOP = 2,          /*!< scan from top                            */
1014     L_FROM_BOT = 3,          /*!< scan from bottom                         */
1015     L_SCAN_NEGATIVE = 4,     /*!< scan in negative direction               */
1016     L_SCAN_POSITIVE = 5,     /*!< scan in positive direction               */
1017     L_SCAN_BOTH = 6,         /*!< scan in both directions                  */
1018     L_SCAN_HORIZONTAL = 7,   /*!< horizontal scan (direction unimportant)  */
1019     L_SCAN_VERTICAL = 8      /*!< vertical scan (direction unimportant)    */
1020 };
1021 
1022 
1023 /*-------------------------------------------------------------------------*
1024  *                Box size adjustment and location flags                   *
1025  *-------------------------------------------------------------------------*/
1026 
1027 /*! Box size adjustment and location flags */
1028 enum {
1029     L_ADJUST_SKIP = 0,           /*!< do not adjust                        */
1030     L_ADJUST_LEFT = 1,           /*!< adjust left edge                     */
1031     L_ADJUST_RIGHT = 2,          /*!< adjust right edge                    */
1032     L_ADJUST_LEFT_AND_RIGHT = 3, /*!< adjust both left and right edges     */
1033     L_ADJUST_TOP = 4,            /*!< adjust top edge                      */
1034     L_ADJUST_BOT = 5,            /*!< adjust bottom edge                   */
1035     L_ADJUST_TOP_AND_BOT = 6,    /*!< adjust both top and bottom edges     */
1036     L_ADJUST_CHOOSE_MIN = 7,     /*!< choose the min median value          */
1037     L_ADJUST_CHOOSE_MAX = 8,     /*!< choose the max median value          */
1038     L_SET_LEFT = 9,              /*!< set left side to a given value       */
1039     L_SET_RIGHT = 10,            /*!< set right side to a given value      */
1040     L_SET_TOP = 11,              /*!< set top side to a given value        */
1041     L_SET_BOT = 12,              /*!< set bottom side to a given value     */
1042     L_GET_LEFT = 13,             /*!< get left side location               */
1043     L_GET_RIGHT = 14,            /*!< get right side location              */
1044     L_GET_TOP = 15,              /*!< get top side location                */
1045     L_GET_BOT = 16               /*!< get bottom side location             */
1046 };
1047 
1048 
1049 /*-------------------------------------------------------------------------*
1050  *          Flags for selecting box boundaries from two choices            *
1051  *-------------------------------------------------------------------------*/
1052 
1053 /*! Flags for selecting box boundaries from two choices */
1054 enum {
1055     L_USE_MINSIZE = 1,           /*!< use boundaries giving min size       */
1056     L_USE_MAXSIZE = 2,           /*!< use boundaries giving max size       */
1057     L_SUB_ON_BIG_DIFF = 3,       /*!< substitute boundary if big abs diff  */
1058     L_USE_CAPPED_MIN = 4,        /*!< substitute boundary with capped min  */
1059     L_USE_CAPPED_MAX = 5         /*!< substitute boundary with capped max  */
1060 };
1061 
1062 /*-------------------------------------------------------------------------*
1063  *              Handling overlapping bounding boxes in boxa                *
1064  *-------------------------------------------------------------------------*/
1065 
1066 /*! Handling overlapping bounding boxes in Boxa */
1067 enum {
1068     L_COMBINE = 1,         /*!< resize to bounding region; remove smaller  */
1069     L_REMOVE_SMALL = 2     /*!< only remove smaller                        */
1070 };
1071 
1072 /*-------------------------------------------------------------------------*
1073  *                    Flags for replacing invalid boxes                    *
1074  *-------------------------------------------------------------------------*/
1075 
1076 /*! Flags for replacing invalid boxes */
1077 enum {
1078     L_USE_ALL_BOXES = 1,         /*!< consider all boxes in the sequence   */
1079     L_USE_SAME_PARITY_BOXES = 2  /*!< consider boxes with the same parity  */
1080 };
1081 
1082 /*-------------------------------------------------------------------------*
1083  *                            Horizontal warp                              *
1084  *-------------------------------------------------------------------------*/
1085 
1086 /*! Horizonal warp direction */
1087 enum {
1088     L_WARP_TO_LEFT = 1,    /*!< increasing stretch or contraction to left  */
1089     L_WARP_TO_RIGHT = 2    /*!< increasing stretch or contraction to right */
1090 };
1091 
1092 /*! Horizonal warp stretch mode */
1093 enum {
1094     L_LINEAR_WARP = 1,     /*!< stretch or contraction grows linearly      */
1095     L_QUADRATIC_WARP = 2   /*!< stretch or contraction grows quadratically */
1096 };
1097 
1098 
1099 /*-------------------------------------------------------------------------*
1100  *                      Pixel selection for resampling                     *
1101  *-------------------------------------------------------------------------*/
1102 
1103 /*! Pixel selection for resampling */
1104 enum {
1105     L_INTERPOLATED = 1,    /*!< linear interpolation from src pixels       */
1106     L_SAMPLED = 2          /*!< nearest src pixel sampling only            */
1107 };
1108 
1109 
1110 /*-------------------------------------------------------------------------*
1111  *                             Thinning flags                              *
1112  *-------------------------------------------------------------------------*/
1113 
1114 /*! Thinning flags */
1115 enum {
1116     L_THIN_FG = 1,             /*!< thin foreground of 1 bpp image         */
1117     L_THIN_BG = 2              /*!< thin background of 1 bpp image         */
1118 };
1119 
1120 
1121 /*-------------------------------------------------------------------------*
1122  *                            Runlength flags                              *
1123  *-------------------------------------------------------------------------*/
1124 
1125 /*! Runlength flags */
1126 enum {
1127     L_HORIZONTAL_RUNS = 0,   /*!< determine runlengths of horizontal runs  */
1128     L_VERTICAL_RUNS = 1      /*!< determine runlengths of vertical runs    */
1129 };
1130 
1131 
1132 /*-------------------------------------------------------------------------*
1133  *                          Edge filter flags                              *
1134  *-------------------------------------------------------------------------*/
1135 
1136 /*! Edge filter flags */
1137 enum {
1138     L_SOBEL_EDGE = 1,        /*!< Sobel edge filter                        */
1139     L_TWO_SIDED_EDGE = 2     /*!< Two-sided edge filter                    */
1140 };
1141 
1142 
1143 /*-------------------------------------------------------------------------*
1144  *             Subpixel color component ordering in LCD display            *
1145  *-------------------------------------------------------------------------*/
1146 
1147 /*! Subpixel color component ordering in LC display */
1148 enum {
1149     L_SUBPIXEL_ORDER_RGB = 1,   /*!< sensor order left-to-right RGB        */
1150     L_SUBPIXEL_ORDER_BGR = 2,   /*!< sensor order left-to-right BGR        */
1151     L_SUBPIXEL_ORDER_VRGB = 3,  /*!< sensor order top-to-bottom RGB        */
1152     L_SUBPIXEL_ORDER_VBGR = 4   /*!< sensor order top-to-bottom BGR        */
1153 };
1154 
1155 
1156 /*-------------------------------------------------------------------------*
1157  *                          HSV histogram flags                            *
1158  *-------------------------------------------------------------------------*/
1159 
1160 /*! HSV histogram flags */
1161 enum {
1162     L_HS_HISTO = 1,            /*!< Use hue-saturation histogram           */
1163     L_HV_HISTO = 2,            /*!< Use hue-value histogram                */
1164     L_SV_HISTO = 3             /*!< Use saturation-value histogram         */
1165 };
1166 
1167 
1168 /*-------------------------------------------------------------------------*
1169  *                    Region flags (inclusion, exclusion)                  *
1170  *-------------------------------------------------------------------------*/
1171 
1172 /*! Region flags (inclusion, exclusion) */
1173 enum {
1174     L_INCLUDE_REGION = 1,      /*!< Use hue-saturation histogram           */
1175     L_EXCLUDE_REGION = 2       /*!< Use hue-value histogram                */
1176 };
1177 
1178 
1179 /*-------------------------------------------------------------------------*
1180  *                    Flags for adding text to a pix                       *
1181  *-------------------------------------------------------------------------*/
1182 
1183 /*! Flags for adding text to a Pix */
1184 enum {
1185     L_ADD_ABOVE = 1,           /*!< Add text above the image               */
1186     L_ADD_BELOW = 2,           /*!< Add text below the image               */
1187     L_ADD_LEFT = 3,            /*!< Add text to the left of the image      */
1188     L_ADD_RIGHT = 4,           /*!< Add text to the right of the image     */
1189     L_ADD_AT_TOP = 5,          /*!< Add text over the top of the image     */
1190     L_ADD_AT_BOT = 6,          /*!< Add text over the bottom of the image  */
1191     L_ADD_AT_LEFT = 7,         /*!< Add text over left side of the image   */
1192     L_ADD_AT_RIGHT = 8         /*!< Add text over right side of the image  */
1193 };
1194 
1195 
1196 /*-------------------------------------------------------------------------*
1197  *                       Flags for plotting on a pix                       *
1198  *-------------------------------------------------------------------------*/
1199 
1200 /*! Flags for plotting on a Pix */
1201 enum {
1202     L_PLOT_AT_TOP = 1,         /*!< Plot horizontally at top               */
1203     L_PLOT_AT_MID_HORIZ = 2,   /*!< Plot horizontally at middle            */
1204     L_PLOT_AT_BOT = 3,         /*!< Plot horizontally at bottom            */
1205     L_PLOT_AT_LEFT = 4,        /*!< Plot vertically at left                */
1206     L_PLOT_AT_MID_VERT = 5,    /*!< Plot vertically at middle              */
1207     L_PLOT_AT_RIGHT = 6        /*!< Plot vertically at right               */
1208 };
1209 
1210 
1211 /*-------------------------------------------------------------------------*
1212  *                   Flags for selecting display program                   *
1213  *-------------------------------------------------------------------------*/
1214 
1215 /*! Flags for selecting display program */
1216 enum {
1217     L_DISPLAY_WITH_XZGV = 1,  /*!< Use xzgv with pixDisplay()              */
1218     L_DISPLAY_WITH_XLI = 2,   /*!< Use xli with pixDisplay()               */
1219     L_DISPLAY_WITH_XV = 3,    /*!< Use xv with pixDisplay()                */
1220     L_DISPLAY_WITH_IV = 4,    /*!< Use irfvanview (win) with pixDisplay()  */
1221     L_DISPLAY_WITH_OPEN = 5   /*!< Use open (apple) with pixDisplay()      */
1222 };
1223 
1224 /*-------------------------------------------------------------------------*
1225  *    Flag(s) used in the 'special' pix field for non-default operations   *
1226  *      - 0 is default for chroma sampling in jpeg                         *
1227  *      - 10-19 are used for zlib compression in png write                 *
1228  *      - 4 and 8 are used for specifying connectivity in labelling        *
1229  *-------------------------------------------------------------------------*/
1230 
1231 /*! Flags used in Pix::special */
1232 enum {
1233     L_NO_CHROMA_SAMPLING_JPEG = 1   /*!< Write full resolution chroma      */
1234 };
1235 
1236 
1237 /*-------------------------------------------------------------------------*
1238  *          Handling negative values in conversion to unsigned int         *
1239  *-------------------------------------------------------------------------*/
1240 
1241 /*! Handling negative values in conversion to unsigned int */
1242 enum {
1243     L_CLIP_TO_ZERO = 1,      /*!< Clip negative values to 0                */
1244     L_TAKE_ABSVAL = 2        /*!< Convert to positive using L_ABS()        */
1245 };
1246 
1247 
1248 /*-------------------------------------------------------------------------*
1249  *                        Relative to zero flags                           *
1250  *-------------------------------------------------------------------------*/
1251 
1252 /*! Relative to zero flags */
1253 enum {
1254     L_LESS_THAN_ZERO = 1,    /*!< Choose values less than zero             */
1255     L_EQUAL_TO_ZERO = 2,     /*!< Choose values equal to zero              */
1256     L_GREATER_THAN_ZERO = 3  /*!< Choose values greater than zero          */
1257 };
1258 
1259 
1260 /*-------------------------------------------------------------------------*
1261  *         Flags for adding or removing traling slash from string          *
1262  *-------------------------------------------------------------------------*/
1263 
1264 /*! Flags for adding or removing traling slash from string */
1265 enum {
1266     L_ADD_TRAIL_SLASH = 1,     /*!< Add trailing slash to string           */
1267     L_REMOVE_TRAIL_SLASH = 2   /*!< Remove trailing slash from string      */
1268 };
1269 
1270 
1271 /*-------------------------------------------------------------------------*
1272  *               Pix allocator and deallocator function types              *
1273  *-------------------------------------------------------------------------*/
1274 /*! Allocator function type */
1275 typedef void *(*alloc_fn)(size_t);
1276 
1277 /*! Deallocator function type */
1278 typedef void (*dealloc_fn)(void *);
1279 
1280 
1281 #endif  /* LEPTONICA_PIX_H */
1282