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