pix.h 60 KB

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