1 /*====================================================================* 2 - Copyright (C) 2001 Leptonica. All rights reserved. 3 - This software is distributed in the hope that it will be 4 - useful, but with NO WARRANTY OF ANY KIND. 5 - No author or distributor accepts responsibility to anyone for the 6 - consequences of using this software, or for whether it serves any 7 - particular purpose or works at all, unless he or she says so in 8 - writing. Everyone is granted permission to copy, modify and 9 - redistribute this source code, for commercial or non-commercial 10 - purposes, with the following restrictions: (1) the origin of this 11 - source code must not be misrepresented; (2) modified versions must 12 - be plainly marked as such; and (3) this notice may not be removed 13 - or altered from any source or modified source distribution. 14 *====================================================================*/ 15 16 #ifndef LEPTONICA_PIX_H 17 #define LEPTONICA_PIX_H 18 19 /* 20 * pix.h 21 * 22 * Contains the following structures: 23 * struct Pix 24 * struct PixColormap 25 * struct RGBA_Quad 26 * struct Pixa 27 * struct Pixaa 28 * struct Box 29 * struct Boxa 30 * struct Boxaa 31 * struct Pta 32 * struct Ptaa 33 * struct Pixacc 34 * struct PixTiling 35 * struct FPix 36 * struct DPix 37 * struct PixComp 38 * struct PixaComp 39 * 40 * Contains definitions for: 41 * Colors for RGB 42 * Perceptual color weights 43 * Colormap conversion flags 44 * Rasterop bit flags 45 * Structure access flags (for insert, copy, clone, copy-clone) 46 * Sorting flags (by type and direction) 47 * Blending flags 48 * Graphics pixel setting flags 49 * Size filtering flags 50 * Rotation and shear flags 51 * Affine transform order flags 52 * Grayscale filling flags 53 * Dithering flags 54 * Distance flags 55 * Statistical measures 56 * Set selection flags 57 * Text orientation flags 58 * Edge orientation flags 59 * Line orientation flags 60 * Scan direction flags 61 * Horizontal warp 62 * Pixel selection for resampling 63 * Thinning flags 64 * Runlength flags 65 * Edge filter flags 66 * Handling negative values in conversion to unsigned int 67 * Subpixel color component ordering in LCD display 68 * Relative to zero flags 69 * HSV histogram flags 70 * Region flags (inclusion, exclusion) 71 * Flags for adding text to a pix 72 * Flags for selecting display program 73 */ 74 75 76 /*-------------------------------------------------------------------------* 77 * Basic Pix * 78 *-------------------------------------------------------------------------*/ 79 struct Pix 80 { 81 l_uint32 w; /* width in pixels */ 82 l_uint32 h; /* height in pixels */ 83 l_uint32 d; /* depth in bits */ 84 l_uint32 wpl; /* 32-bit words/line */ 85 l_uint32 refcount; /* reference count (1 if no clones) */ 86 l_uint32 xres; /* image res (ppi) in x direction */ 87 /* (use 0 if unknown) */ 88 l_uint32 yres; /* image res (ppi) in y direction */ 89 /* (use 0 if unknown) */ 90 l_int32 informat; /* input file format, IFF_* */ 91 char *text; /* text string associated with pix */ 92 struct PixColormap *colormap; /* colormap (may be null) */ 93 l_uint32 *data; /* the image data */ 94 }; 95 typedef struct Pix PIX; 96 97 98 struct PixColormap 99 { 100 void *array; /* colormap table (array of RGBA_QUAD) */ 101 l_int32 depth; /* of pix (1, 2, 4 or 8 bpp) */ 102 l_int32 nalloc; /* number of color entries allocated */ 103 l_int32 n; /* number of color entries used */ 104 }; 105 typedef struct PixColormap PIXCMAP; 106 107 108 /* Colormap table entry (after the BMP version). 109 * Note that the BMP format stores the colormap table exactly 110 * as it appears here, with color samples being stored sequentially, 111 * in the order (b,g,r,a). */ 112 struct RGBA_Quad 113 { 114 l_uint8 blue; 115 l_uint8 green; 116 l_uint8 red; 117 l_uint8 reserved; 118 }; 119 typedef struct RGBA_Quad RGBA_QUAD; 120 121 122 123 /*-------------------------------------------------------------------------* 124 * Colors for 32 bpp * 125 *-------------------------------------------------------------------------*/ 126 /* Notes: 127 * (1) These are the byte indices for colors in 32 bpp images. 128 * They are used through the GET/SET_DATA_BYTE accessors. 129 * The 4th byte, typically known as the "alpha channel" and used 130 * for blending, is not explicitly used in leptonica. 131 * (2) If you redefine these values, functions that have the shifts 132 * hardcoded (instead of using the constants below) will break. 133 * These functions are labelled with "***" next to their names 134 * at the top of the files in which they are defined. 135 * Advice: Do not change these values! 136 * (3) The shifts to extract the red, green and blue components 137 * from a 32 bit pixel are defined in terms of these colors. 138 */ 139 enum { 140 COLOR_RED = 0, 141 COLOR_GREEN = 1, 142 COLOR_BLUE = 2, 143 L_ALPHA_CHANNEL = 3 144 }; 145 146 static const l_int32 L_RED_SHIFT = 147 8 * (sizeof(l_uint32) - 1 - COLOR_RED); /* 24 */ 148 static const l_int32 L_GREEN_SHIFT = 149 8 * (sizeof(l_uint32) - 1 - COLOR_GREEN); /* 16 */ 150 static const l_int32 L_BLUE_SHIFT = 151 8 * (sizeof(l_uint32) - 1 - COLOR_BLUE); /* 8 */ 152 static const l_int32 L_ALPHA_SHIFT = 153 8 * (sizeof(l_uint32) - 1 - L_ALPHA_CHANNEL); /* 0 */ 154 155 156 /*-------------------------------------------------------------------------* 157 * Perceptual color weights * 158 *-------------------------------------------------------------------------*/ 159 /* Notes: 160 * (1) These numbers are ad-hoc, but they do add up to 1. 161 * Unlike, for example, the weighting factor for conversion 162 * of RGB to luminance, or more specifically to Y in the 163 * YUV colorspace. Those numbers come from the 164 * International Telecommunications Union, via ITU-R. 165 */ 166 static const l_float32 L_RED_WEIGHT = 0.3; 167 static const l_float32 L_GREEN_WEIGHT = 0.5; 168 static const l_float32 L_BLUE_WEIGHT = 0.2; 169 170 171 /*-------------------------------------------------------------------------* 172 * Flags for colormap conversion * 173 *-------------------------------------------------------------------------*/ 174 enum { 175 REMOVE_CMAP_TO_BINARY = 0, 176 REMOVE_CMAP_TO_GRAYSCALE = 1, 177 REMOVE_CMAP_TO_FULL_COLOR = 2, 178 REMOVE_CMAP_BASED_ON_SRC = 3 179 }; 180 181 182 /*-------------------------------------------------------------------------* 183 * 184 * The following operation bit flags have been modified from 185 * Sun's pixrect.h. 186 * 187 * The 'op' in 'rasterop' is represented by an integer 188 * composed with Boolean functions using the set of five integers 189 * given below. The integers, and the op codes resulting from 190 * boolean expressions on them, need only be in the range from 0 to 15. 191 * The function is applied on a per-pixel basis. 192 * 193 * Examples: the op code representing ORing the src and dest 194 * is computed using the bit OR, as PIX_SRC | PIX_DST; the op 195 * code representing XORing src and dest is found from 196 * PIX_SRC ^ PIX_DST; the op code representing ANDing src and dest 197 * is found from PIX_SRC & PIX_DST. Note that 198 * PIX_NOT(PIX_CLR) = PIX_SET, and v.v., as they must be. 199 * 200 * We would like to use the following set of definitions: 201 * 202 * #define PIX_SRC 0xc 203 * #define PIX_DST 0xa 204 * #define PIX_NOT(op) ((op) ^ 0xf) 205 * #define PIX_CLR 0x0 206 * #define PIX_SET 0xf 207 * 208 * Now, these definitions differ from Sun's, in that Sun 209 * left-shifted each value by 1 pixel, and used the least 210 * significant bit as a flag for the "pseudo-operation" of 211 * clipping. We don't need this bit, because it is both 212 * efficient and safe ALWAYS to clip the rectangles to the src 213 * and dest images, which is what we do. See the notes in rop.h 214 * on the general choice of these bit flags. 215 * 216 * However, if you include Sun's xview package, you will get their 217 * definitions, and because I like using these flags, we will 218 * adopt the original Sun definitions to avoid redefinition conflicts. 219 * 220 * Then we have, for reference, the following 16 unique op flags: 221 * 222 * PIX_CLR 00000 0x0 223 * PIX_SET 11110 0x1e 224 * PIX_SRC 11000 0x18 225 * PIX_DST 10100 0x14 226 * PIX_NOT(PIX_SRC) 00110 0x06 227 * PIX_NOT(PIX_DST) 01010 0x0a 228 * PIX_SRC | PIX_DST 11100 0x1c 229 * PIX_SRC & PIX_DST 10000 0x10 230 * PIX_SRC ^ PIX_DST 01100 0x0c 231 * PIX_NOT(PIX_SRC) | PIX_DST 10110 0x16 232 * PIX_NOT(PIX_SRC) & PIX_DST 00100 0x04 233 * PIX_SRC | PIX_NOT(PIX_DST) 11010 0x1a 234 * PIX_SRC & PIX_NOT(PIX_DST) 01000 0x08 235 * PIX_NOT(PIX_SRC | PIX_DST) 00010 0x02 236 * PIX_NOT(PIX_SRC & PIX_DST) 01110 0x0e 237 * PIX_NOT(PIX_SRC ^ PIX_DST) 10010 0x12 238 * 239 *-------------------------------------------------------------------------*/ 240 #define PIX_SRC (0xc << 1) 241 #define PIX_DST (0xa << 1) 242 #define PIX_NOT(op) ((op) ^ 0x1e) 243 #define PIX_CLR (0x0 << 1) 244 #define PIX_SET (0xf << 1) 245 246 #define PIX_PAINT (PIX_SRC | PIX_DST) 247 #define PIX_MASK (PIX_SRC & PIX_DST) 248 #define PIX_SUBTRACT (PIX_DST & PIX_NOT(PIX_SRC)) 249 #define PIX_XOR (PIX_SRC ^ PIX_DST) 250 251 252 /*-------------------------------------------------------------------------* 253 * 254 * Important Notes: 255 * 256 * (1) The image data is stored in a single contiguous 257 * array of l_uint32, into which the pixels are packed. 258 * By "packed" we mean that there are no unused bits 259 * between pixels, except for end-of-line padding to 260 * satisfy item (2) below. 261 * 262 * (2) Every image raster line begins on a 32-bit word 263 * boundary within this array. 264 * 265 * (3) Pix image data is stored in 32-bit units, with the 266 * pixels ordered from left to right in the image being 267 * stored in order from the MSB to LSB within the word, 268 * for both big-endian and little-endian machines. 269 * This is the natural ordering for big-endian machines, 270 * as successive bytes are stored and fetched progressively 271 * to the right. However, for little-endians, when storing 272 * we re-order the bytes from this byte stream order, and 273 * reshuffle again for byte access on 32-bit entities. 274 * So if the bytes come in sequence from left to right, we 275 * store them on little-endians in byte order: 276 * 3 2 1 0 7 6 5 4 ... 277 * This MSB to LSB ordering allows left and right shift 278 * operations on 32 bit words to move the pixels properly. 279 * 280 * (4) For 24-bit color images, use 32 bpp data, leaving 281 * the fourth byte unused. Within each 4 byte pixel, the 282 * colors are ordered from MSB to LSB, as follows: 283 * 284 * | MSB | 2nd MSB | 3rd MSB | LSB | 285 * red green blue unused 286 * 0 1 2 3 (big-endian) 287 * 3 2 1 0 (little-endian) 288 * 289 * Because we use MSB to LSB ordering within the 32-bit word, 290 * the individual 8-bit samples can be accessed with 291 * GET_DATA_BYTE and SET_DATA_BYTE macros, using the 292 * (implicitly big-ending) ordering 293 * red: byte 0 (MSB) 294 * green: byte 1 (2nd MSB) 295 * blue: byte 2 (3rd MSB) 296 * 297 * This specific color assignment is made in this file, 298 * through the definitions of COLOR_RED, etc. Then the R, G 299 * and B sample values can be retrieved using 300 * redval = GET_DATA_BYTE(&pixel, COLOR_RED); 301 * greenval = GET_DATA_BYTE(&pixel, COLOR_GREEN); 302 * blueval = GET_DATA_BYTE(&pixel, COLOR_BLUE); 303 * and they can be set with 304 * SET_DATA_BYTE(&pixel, COLOR_RED, redval); 305 * SET_DATA_BYTE(&pixel, COLOR_GREEN, greenval); 306 * SET_DATA_BYTE(&pixel, COLOR_BLUE, blueval); 307 * 308 * For extra speed we extract the R, G and B colors directly 309 * by shifting and masking, explicitly using the values in 310 * L_RED_SHIFT, L_GREEN_SHIFT and L_BLUE_SHIFT: 311 * (pixel32 >> L_RED_SHIFT) & 0xff; (red) 312 * (pixel32 >> L_GREEN_SHIFT) & 0xff; (green) 313 * (pixel32 >> L_BLUE_SHIFT) & 0xff; (blue) 314 * All these operations work properly on both big- and little-endians. 315 * 316 * For a few situations, these color shift values are hard-coded. 317 * Changing the RGB color component ordering through the assignments 318 * in this file will cause functions marked with "***" to fail. 319 * 320 * (5) A reference count is held within each pix, giving the 321 * number of ptrs to the pix. When a pixClone() call 322 * is made, the ref count is increased by 1, and 323 * when a pixDestroy() call is made, the reference count 324 * of the pix is decremented. The pix is only destroyed 325 * when the reference count goes to zero. 326 * 327 * (6) The version numbers (below) are used in the serialization 328 * of these data structures. They are placed in the files, 329 * and rarely (if ever) change. Provision is currently made for 330 * backward compatibility in reading from boxaa version 2. 331 * 332 * (7) The serialization dependencies are as follows: 333 * pixaa : pixa : boxa 334 * boxaa : boxa 335 * So, for example, pixaa and boxaa can be changed without 336 * forcing a change in pixa or boxa. However, if pixa is 337 * changed, it forces a change in pixaa, and if boxa is 338 * changed, if forces a change in the other three. 339 * We define four version numbers: 340 * PIXAA_VERSION_NUMBER 341 * PIXA_VERSION_NUMBER 342 * BOXAA_VERSION_NUMBER 343 * BOXA_VERSION_NUMBER 344 * 345 *-------------------------------------------------------------------------*/ 346 347 348 349 /*-------------------------------------------------------------------------* 350 * Array of pix * 351 *-------------------------------------------------------------------------*/ 352 353 /* Serialization for primary data structures */ 354 #define PIXAA_VERSION_NUMBER 2 355 #define PIXA_VERSION_NUMBER 2 356 #define BOXA_VERSION_NUMBER 2 357 #define BOXAA_VERSION_NUMBER 3 358 359 360 struct Pixa 361 { 362 l_int32 n; /* number of Pix in ptr array */ 363 l_int32 nalloc; /* number of Pix ptrs allocated */ 364 l_uint32 refcount; /* reference count (1 if no clones) */ 365 struct Pix **pix; /* the array of ptrs to pix */ 366 struct Boxa *boxa; /* array of boxes */ 367 }; 368 typedef struct Pixa PIXA; 369 370 371 struct Pixaa 372 { 373 l_int32 n; /* number of Pixa in ptr array */ 374 l_int32 nalloc; /* number of Pixa ptrs allocated */ 375 struct Pixa **pixa; /* array of ptrs to pixa */ 376 struct Boxa *boxa; /* array of boxes */ 377 }; 378 typedef struct Pixaa PIXAA; 379 380 381 /*-------------------------------------------------------------------------* 382 * Basic rectangle and rectangle arrays * 383 *-------------------------------------------------------------------------*/ 384 struct Box 385 { 386 l_int32 x; 387 l_int32 y; 388 l_int32 w; 389 l_int32 h; 390 l_uint32 refcount; /* reference count (1 if no clones) */ 391 392 }; 393 typedef struct Box BOX; 394 395 struct Boxa 396 { 397 l_int32 n; /* number of box in ptr array */ 398 l_int32 nalloc; /* number of box ptrs allocated */ 399 l_uint32 refcount; /* reference count (1 if no clones) */ 400 struct Box **box; /* box ptr array */ 401 }; 402 typedef struct Boxa BOXA; 403 404 struct Boxaa 405 { 406 l_int32 n; /* number of boxa in ptr array */ 407 l_int32 nalloc; /* number of boxa ptrs allocated */ 408 struct Boxa **boxa; /* boxa ptr array */ 409 }; 410 typedef struct Boxaa BOXAA; 411 412 413 /*-------------------------------------------------------------------------* 414 * Array of points * 415 *-------------------------------------------------------------------------*/ 416 #define PTA_VERSION_NUMBER 1 417 418 struct Pta 419 { 420 l_int32 n; /* actual number of pts */ 421 l_int32 nalloc; /* size of allocated arrays */ 422 l_int32 refcount; /* reference count (1 if no clones) */ 423 l_float32 *x, *y; /* arrays of floats */ 424 }; 425 typedef struct Pta PTA; 426 427 428 /*-------------------------------------------------------------------------* 429 * Array of Pta * 430 *-------------------------------------------------------------------------*/ 431 struct Ptaa 432 { 433 l_int32 n; /* number of pta in ptr array */ 434 l_int32 nalloc; /* number of pta ptrs allocated */ 435 struct Pta **pta; /* pta ptr array */ 436 }; 437 typedef struct Ptaa PTAA; 438 439 440 /*-------------------------------------------------------------------------* 441 * Pix accumulator container * 442 *-------------------------------------------------------------------------*/ 443 struct Pixacc 444 { 445 l_int32 w; /* array width */ 446 l_int32 h; /* array height */ 447 l_int32 offset; /* used to allow negative */ 448 /* intermediate results */ 449 struct Pix *pix; /* the 32 bit accumulator pix */ 450 }; 451 typedef struct Pixacc PIXACC; 452 453 454 /*-------------------------------------------------------------------------* 455 * Pix tiling * 456 *-------------------------------------------------------------------------*/ 457 struct PixTiling 458 { 459 struct Pix *pix; /* input pix (a clone) */ 460 l_int32 nx; /* number of tiles horizontally */ 461 l_int32 ny; /* number of tiles vertically */ 462 l_int32 w; /* tile width */ 463 l_int32 h; /* tile height */ 464 l_int32 xoverlap; /* overlap on left and right */ 465 l_int32 yoverlap; /* overlap on top and bottom */ 466 l_int32 strip; /* strip for paint; default is TRUE */ 467 }; 468 typedef struct PixTiling PIXTILING; 469 470 471 /*-------------------------------------------------------------------------* 472 * FPix: pix with float array * 473 *-------------------------------------------------------------------------*/ 474 struct FPix 475 { 476 l_int32 w; /* width in pixels */ 477 l_int32 h; /* height in pixels */ 478 l_int32 wpl; /* 32-bit words/line */ 479 l_int32 refcount; /* reference count (1 if no clones) */ 480 l_int32 xres; /* image res (ppi) in x direction */ 481 /* (use 0 if unknown) */ 482 l_int32 yres; /* image res (ppi) in y direction */ 483 /* (use 0 if unknown) */ 484 l_float32 *data; /* the float image data */ 485 }; 486 typedef struct FPix FPIX; 487 488 489 /*-------------------------------------------------------------------------* 490 * DPix: pix with double array * 491 *-------------------------------------------------------------------------*/ 492 struct DPix 493 { 494 l_int32 w; /* width in pixels */ 495 l_int32 h; /* height in pixels */ 496 l_int32 wpl; /* 32-bit words/line */ 497 l_int32 refcount; /* reference count (1 if no clones) */ 498 l_int32 xres; /* image res (ppi) in x direction */ 499 /* (use 0 if unknown) */ 500 l_int32 yres; /* image res (ppi) in y direction */ 501 /* (use 0 if unknown) */ 502 l_float64 *data; /* the double image data */ 503 }; 504 typedef struct DPix DPIX; 505 506 507 /*-------------------------------------------------------------------------* 508 * PixComp: compressed pix * 509 *-------------------------------------------------------------------------*/ 510 struct PixComp 511 { 512 l_int32 w; /* width in pixels */ 513 l_int32 h; /* height in pixels */ 514 l_int32 d; /* depth in bits */ 515 l_uint32 xres; /* image res (ppi) in x direction */ 516 /* (use 0 if unknown) */ 517 l_uint32 yres; /* image res (ppi) in y direction */ 518 /* (use 0 if unknown) */ 519 l_int32 comptype; /* compressed format (IFF_TIFF_G4, */ 520 /* IFF_PNG, IFF_JFIF_JPEG) */ 521 char *text; /* text string associated with pix */ 522 l_int32 cmapflag; /* flag (1 for cmap, 0 otherwise) */ 523 l_uint8 *data; /* the compressed image data */ 524 l_int32 size; /* size of the data array */ 525 }; 526 typedef struct PixComp PIXC; 527 528 529 /*-------------------------------------------------------------------------* 530 * PixaComp: array of compressed pix * 531 *-------------------------------------------------------------------------*/ 532 #define PIXACOMP_VERSION_NUMBER 1 533 534 struct PixaComp 535 { 536 l_int32 n; /* number of PixComp in ptr array */ 537 l_int32 nalloc; /* number of PixComp ptrs allocated */ 538 struct PixComp **pixc; /* the array of ptrs to PixComp */ 539 struct Boxa *boxa; /* array of boxes */ 540 }; 541 typedef struct PixaComp PIXAC; 542 543 544 /*-------------------------------------------------------------------------* 545 * Access and storage flags * 546 *-------------------------------------------------------------------------*/ 547 /* 548 * For Pix, Box, Pta and Numa, there are 3 standard methods for handling 549 * the retrieval or insertion of a struct: 550 * (1) direct insertion (Don't do this if there is another handle 551 * somewhere to this same struct!) 552 * (2) copy (Always safe, sets up a refcount of 1 on the new object. 553 * Can be undesirable if very large, such as an image or 554 * an array of images.) 555 * (3) clone (Makes another handle to the same struct, and bumps the 556 * refcount up by 1. Safe to do unless you're changing 557 * data through one of the handles but don't want those 558 * changes to be seen by the other handle.) 559 * 560 * For Pixa and Boxa, which are structs that hold an array of clonable 561 * structs, there is an additional method: 562 * (4) copy-clone (Makes a new higher-level struct with a refcount 563 * of 1, but clones all the structs in the array.) 564 * 565 * Unlike the other structs, when retrieving a string from an Sarray, 566 * you are allowed to get a handle without a copy or clone (i.e., that 567 * you don't own!). You must not free or insert such a string! 568 * Specifically, for an Sarray, the copyflag for retrieval is either: 569 * TRUE (or 1 or L_COPY) 570 * or 571 * FALSE (or 0 or L_NOCOPY) 572 * For insertion, the copyflag is either: 573 * TRUE (or 1 or L_COPY) 574 * or 575 * FALSE (or 0 or L_INSERT) 576 * Note that L_COPY is always 1, and L_INSERT and L_NOCOPY are always 0. 577 */ 578 enum { 579 L_INSERT = 0, /* stuff it in; no copy, clone or copy-clone */ 580 L_COPY = 1, /* make/use a copy of the object */ 581 L_CLONE = 2, /* make/use clone (ref count) of the object */ 582 L_COPY_CLONE = 3 /* make a new object and fill with with clones */ 583 /* of each object in the array(s) */ 584 }; 585 static const l_int32 L_NOCOPY = 0; /* copyflag value in sarrayGetString() */ 586 587 588 /*--------------------------------------------------------------------------* 589 * Sort flags * 590 *--------------------------------------------------------------------------*/ 591 enum { 592 L_SORT_INCREASING = 1, /* sort in increasing order */ 593 L_SORT_DECREASING = 2 /* sort in decreasing order */ 594 }; 595 596 enum { 597 L_SORT_BY_X = 3, /* sort box or c.c. by horiz location */ 598 L_SORT_BY_Y = 4, /* sort box or c.c. by vert location */ 599 L_SORT_BY_WIDTH = 5, /* sort box or c.c. by width */ 600 L_SORT_BY_HEIGHT = 6, /* sort box or c.c. by height */ 601 L_SORT_BY_MIN_DIMENSION = 7, /* sort box or c.c. by min dimension */ 602 L_SORT_BY_MAX_DIMENSION = 8, /* sort box or c.c. by max dimension */ 603 L_SORT_BY_PERIMETER = 9, /* sort box or c.c. by perimeter */ 604 L_SORT_BY_AREA = 10, /* sort box or c.c. by area */ 605 L_SORT_BY_ASPECT_RATIO = 11 /* sort box or c.c. by width/height ratio */ 606 }; 607 608 609 /*-------------------------------------------------------------------------* 610 * Blend flags * 611 *-------------------------------------------------------------------------*/ 612 enum { 613 L_BLEND_WITH_INVERSE = 1, /* add some of src inverse to itself */ 614 L_BLEND_TO_WHITE = 2, /* shift src colors towards white */ 615 L_BLEND_TO_BLACK = 3, /* shift src colors towards black */ 616 L_BLEND_GRAY = 4, /* blend src directly with blender */ 617 L_BLEND_GRAY_WITH_INVERSE = 5 /* add amount of src inverse to itself, */ 618 /* based on blender pix value */ 619 }; 620 621 enum { 622 L_PAINT_LIGHT = 1, /* colorize non-black pixels */ 623 L_PAINT_DARK = 2 /* colorize non-white pixels */ 624 }; 625 626 627 /*-------------------------------------------------------------------------* 628 * Graphics pixel setting * 629 *-------------------------------------------------------------------------*/ 630 enum { 631 L_SET_PIXELS = 1, /* set all bits in each pixel to 1 */ 632 L_CLEAR_PIXELS = 2, /* set all bits in each pixel to 0 */ 633 L_FLIP_PIXELS = 3 /* flip all bits in each pixel */ 634 }; 635 636 637 /*-------------------------------------------------------------------------* 638 * Size filter flags * 639 *-------------------------------------------------------------------------*/ 640 enum { 641 L_SELECT_WIDTH = 1, /* width must satisfy constraint */ 642 L_SELECT_HEIGHT = 2, /* height must satisfy constraint */ 643 L_SELECT_IF_EITHER = 3, /* either width or height can satisfy */ 644 L_SELECT_IF_BOTH = 4 /* both width and height must satisfy */ 645 }; 646 647 enum { 648 L_SELECT_IF_LT = 1, /* save if value is less than threshold */ 649 L_SELECT_IF_GT = 2, /* save if value is more than threshold */ 650 L_SELECT_IF_LTE = 3, /* save if value is <= to the threshold */ 651 L_SELECT_IF_GTE = 4 /* save if value is >= to the threshold */ 652 }; 653 654 655 /*-------------------------------------------------------------------------* 656 * Rotate and shear flags * 657 *-------------------------------------------------------------------------*/ 658 enum { 659 L_ROTATE_AREA_MAP = 1, /* use area map rotation, if possible */ 660 L_ROTATE_SHEAR = 2, /* use shear rotation */ 661 L_ROTATE_SAMPLING = 3 /* use sampling */ 662 }; 663 664 enum { 665 L_BRING_IN_WHITE = 1, /* bring in white pixels from the outside */ 666 L_BRING_IN_BLACK = 2 /* bring in black pixels from the outside */ 667 }; 668 669 enum { 670 L_SHEAR_ABOUT_CORNER = 1, /* shear image about UL corner */ 671 L_SHEAR_ABOUT_CENTER = 2 /* shear image about center */ 672 }; 673 674 675 /*-------------------------------------------------------------------------* 676 * Affine transform order flags * 677 *-------------------------------------------------------------------------*/ 678 enum { 679 L_TR_SC_RO = 1, /* translate, scale, rotate */ 680 L_SC_RO_TR = 2, /* scale, rotate, translate */ 681 L_RO_TR_SC = 3, /* rotate, translate, scale */ 682 L_TR_RO_SC = 4, /* translate, rotate, scale */ 683 L_RO_SC_TR = 5, /* rotate, scale, translate */ 684 L_SC_TR_RO = 6 /* scale, translate, rotate */ 685 }; 686 687 688 /*-------------------------------------------------------------------------* 689 * Grayscale fill flags * 690 *-------------------------------------------------------------------------*/ 691 enum { 692 L_FILL_WHITE = 1, /* fill white pixels (e.g, in fg map) */ 693 L_FILL_BLACK = 2 /* fill black pixels (e.g., in bg map) */ 694 }; 695 696 697 /*-------------------------------------------------------------------------* 698 * Dither parameters * 699 * If within this grayscale distance from black or white, * 700 * do not propagate excess or deficit to neighboring pixels. * 701 *-------------------------------------------------------------------------*/ 702 enum { 703 DEFAULT_CLIP_LOWER_1 = 10, /* dist to black with no prop; 1 bpp */ 704 DEFAULT_CLIP_UPPER_1 = 10, /* dist to black with no prop; 1 bpp */ 705 DEFAULT_CLIP_LOWER_2 = 5, /* dist to black with no prop; 2 bpp */ 706 DEFAULT_CLIP_UPPER_2 = 5 /* dist to black with no prop; 2 bpp */ 707 }; 708 709 710 /*-------------------------------------------------------------------------* 711 * Distance flags * 712 *-------------------------------------------------------------------------*/ 713 enum { 714 L_MANHATTAN_DISTANCE = 1, /* L1 distance (e.g., in color space) */ 715 L_EUCLIDEAN_DISTANCE = 2 /* L2 distance */ 716 }; 717 718 719 /*-------------------------------------------------------------------------* 720 * Statistical measures * 721 *-------------------------------------------------------------------------*/ 722 enum { 723 L_MEAN_ABSVAL = 1, /* average of abs values */ 724 L_MEDIAN_VAL = 2, /* median value of set */ 725 L_MODE_VAL = 3, /* mode value of set */ 726 L_MODE_COUNT = 4, /* mode count of set */ 727 L_ROOT_MEAN_SQUARE = 5, /* rms of values */ 728 L_STANDARD_DEVIATION = 6, /* standard deviation from mean */ 729 L_VARIANCE = 7 /* variance of values */ 730 }; 731 732 733 /*-------------------------------------------------------------------------* 734 * Set selection flags * 735 *-------------------------------------------------------------------------*/ 736 enum { 737 L_CHOOSE_CONSECUTIVE = 1, /* select 'n' consecutive */ 738 L_CHOOSE_SKIP_BY = 2 /* select at intervals of 'n' */ 739 }; 740 741 742 /*-------------------------------------------------------------------------* 743 * Text orientation flags * 744 *-------------------------------------------------------------------------*/ 745 enum { 746 L_TEXT_ORIENT_UNKNOWN = 0, /* low confidence on text orientation */ 747 L_TEXT_ORIENT_UP = 1, /* portrait, text rightside-up */ 748 L_TEXT_ORIENT_LEFT = 2, /* landscape, text up to left */ 749 L_TEXT_ORIENT_DOWN = 3, /* portrait, text upside-down */ 750 L_TEXT_ORIENT_RIGHT = 4 /* landscape, text up to right */ 751 }; 752 753 754 /*-------------------------------------------------------------------------* 755 * Edge orientation flags * 756 *-------------------------------------------------------------------------*/ 757 enum { 758 L_HORIZONTAL_EDGES = 0, /* filters for horizontal edges */ 759 L_VERTICAL_EDGES = 1, /* filters for vertical edges */ 760 L_ALL_EDGES = 2 /* filters for all edges */ 761 }; 762 763 764 /*-------------------------------------------------------------------------* 765 * Line orientation flags * 766 *-------------------------------------------------------------------------*/ 767 enum { 768 L_HORIZONTAL_LINE = 0, /* horizontal line */ 769 L_POS_SLOPE_LINE = 1, /* 45 degree line with positive slope */ 770 L_VERTICAL_LINE = 2, /* vertical line */ 771 L_NEG_SLOPE_LINE = 3 /* 45 degree line with negative slope */ 772 }; 773 774 775 /*-------------------------------------------------------------------------* 776 * Scan direction flags * 777 *-------------------------------------------------------------------------*/ 778 enum { 779 L_FROM_LEFT = 0, /* scan from left */ 780 L_FROM_RIGHT = 1, /* scan from right */ 781 L_FROM_TOP = 2, /* scan from top */ 782 L_FROM_BOTTOM = 3 /* scan from bottom */ 783 }; 784 785 786 /*-------------------------------------------------------------------------* 787 * Horizontal warp * 788 *-------------------------------------------------------------------------*/ 789 enum { 790 L_WARP_TO_LEFT = 1, /* increasing stretch or contraction to left */ 791 L_WARP_TO_RIGHT = 2 /* increasing stretch or contraction to right */ 792 }; 793 794 enum { 795 L_LINEAR_WARP = 1, /* stretch or contraction grows linearly */ 796 L_QUADRATIC_WARP = 2 /* stretch or contraction grows quadratically */ 797 }; 798 799 800 /*-------------------------------------------------------------------------* 801 * Pixel selection for resampling * 802 *-------------------------------------------------------------------------*/ 803 enum { 804 L_INTERPOLATED = 1, /* linear interpolation from src pixels */ 805 L_SAMPLED = 2 /* nearest src pixel sampling only */ 806 }; 807 808 809 /*-------------------------------------------------------------------------* 810 * Thinning flags * 811 *-------------------------------------------------------------------------*/ 812 enum { 813 L_THIN_FG = 1, /* thin foreground of 1 bpp image */ 814 L_THIN_BG = 2 /* thin background of 1 bpp image */ 815 }; 816 817 818 /*-------------------------------------------------------------------------* 819 * Runlength flags * 820 *-------------------------------------------------------------------------*/ 821 enum { 822 L_HORIZONTAL_RUNS = 0, /* determine runlengths of horizontal runs */ 823 L_VERTICAL_RUNS = 1 /* determine runlengths of vertical runs */ 824 }; 825 826 827 /*-------------------------------------------------------------------------* 828 * Edge filter flags * 829 *-------------------------------------------------------------------------*/ 830 enum { 831 L_SOBEL_EDGE = 1, /* Sobel edge filter */ 832 L_TWO_SIDED_EDGE = 2 /* Two-sided edge filter */ 833 }; 834 835 836 /*-------------------------------------------------------------------------* 837 * Handling negative values in conversion to unsigned int * 838 *-------------------------------------------------------------------------*/ 839 enum { 840 L_CLIP_TO_ZERO = 1, /* Clip negative values to 0 */ 841 L_TAKE_ABSVAL = 2 /* Convert to positive using L_ABS() */ 842 }; 843 844 845 /*-------------------------------------------------------------------------* 846 * Subpixel color component ordering in LCD display * 847 *-------------------------------------------------------------------------*/ 848 enum { 849 L_SUBPIXEL_ORDER_RGB = 1, /* sensor order left-to-right RGB */ 850 L_SUBPIXEL_ORDER_BGR = 2, /* sensor order left-to-right BGR */ 851 L_SUBPIXEL_ORDER_VRGB = 3, /* sensor order top-to-bottom RGB */ 852 L_SUBPIXEL_ORDER_VBGR = 4 /* sensor order top-to-bottom BGR */ 853 }; 854 855 856 /*-------------------------------------------------------------------------* 857 * Relative to zero flags * 858 *-------------------------------------------------------------------------*/ 859 enum { 860 L_LESS_THAN_ZERO = 1, /* Choose values less than zero */ 861 L_EQUAL_TO_ZERO = 2, /* Choose values equal to zero */ 862 L_GREATER_THAN_ZERO = 3 /* Choose values greater than zero */ 863 }; 864 865 866 /*-------------------------------------------------------------------------* 867 * HSV histogram flags * 868 *-------------------------------------------------------------------------*/ 869 enum { 870 L_HS_HISTO = 1, /* Use hue-saturation histogram */ 871 L_HV_HISTO = 2, /* Use hue-value histogram */ 872 L_SV_HISTO = 3 /* Use saturation-value histogram */ 873 }; 874 875 876 /*-------------------------------------------------------------------------* 877 * Region flags (inclusion, exclusion) * 878 *-------------------------------------------------------------------------*/ 879 enum { 880 L_INCLUDE_REGION = 1, /* Use hue-saturation histogram */ 881 L_EXCLUDE_REGION = 2 /* Use hue-value histogram */ 882 }; 883 884 885 /*-------------------------------------------------------------------------* 886 * Flags for adding text to a pix * 887 *-------------------------------------------------------------------------*/ 888 enum { 889 L_ADD_ABOVE = 1, /* Add text above the image */ 890 L_ADD_AT_TOP = 2, /* Add text over the top of the image */ 891 L_ADD_AT_BOTTOM = 3, /* Add text over the bottom of the image */ 892 L_ADD_BELOW = 4 /* Add text below the image */ 893 }; 894 895 896 /*-------------------------------------------------------------------------* 897 * Flags for selecting display program * 898 *-------------------------------------------------------------------------*/ 899 enum { 900 L_DISPLAY_WITH_XV = 1, /* Use xv with pixDisplay() */ 901 L_DISPLAY_WITH_XLI = 2, /* Use xli with pixDisplay() */ 902 L_DISPLAY_WITH_XZGV = 3, /* Use xzgv with pixDisplay() */ 903 L_DISPLAY_WITH_IV = 4 /* Use irfvanview with pixDisplay() */ 904 }; 905 906 #endif /* LEPTONICA_PIX_H */ 907