README.html 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. <html>
  2. <body BGCOLOR=FFFFE4>
  3. <!-- JS Window Closer -----
  4. <form>
  5. <center>
  6. <input type="button" onclick="window.close();" value="Close this window">
  7. </center>
  8. </form>
  9. ----- JS Window Closer -->
  10. <!-- Creative Commons License -->
  11. <a rel="license" href="http://creativecommons.org/licenses/by/2.5/"><img alt="Creative Commons License" border="0" src="http://creativecommons.org/images/public/somerights20.gif" /></a>
  12. This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/2.5/">Creative Commons Attribution 2.5 License</a>.
  13. <!-- /Creative Commons License -->
  14. <!--
  15. <rdf:RDF xmlns="http://web.resource.org/cc/"
  16. xmlns:dc="http://purl.org/dc/elements/1.1/"
  17. xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  18. <Work rdf:about="">
  19. <dc:title>leptonica</dc:title>
  20. <dc:date>2001</dc:date>
  21. <dc:description>An open source C library for efficient image processing and image analysis operations</dc:description>
  22. <dc:creator><Agent>
  23. <dc:title>Dan S. Bloomberg</dc:title>
  24. </Agent></dc:creator>
  25. <dc:rights><Agent>
  26. <dc:title>Dan S. Bloomberg</dc:title>
  27. </Agent></dc:rights>
  28. <dc:type rdf:resource="http://purl.org/dc/dcmitype/Text" />
  29. <dc:source rdf:resource="www.leptonica.com"/>
  30. <license rdf:resource="http://creativecommons.org/licenses/by/2.5/" />
  31. </Work>
  32. <License rdf:about="http://creativecommons.org/licenses/by/2.5/">
  33. <permits rdf:resource="http://web.resource.org/cc/Reproduction" />
  34. <permits rdf:resource="http://web.resource.org/cc/Distribution" />
  35. <requires rdf:resource="http://web.resource.org/cc/Notice" />
  36. <requires rdf:resource="http://web.resource.org/cc/Attribution" />
  37. <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
  38. </License>
  39. </rdf:RDF>
  40. -->
  41. <pre>
  42. /*====================================================================*
  43. - Copyright (C) 2001 Leptonica. All rights reserved.
  44. -
  45. - Redistribution and use in source and binary forms, with or without
  46. - modification, are permitted provided that the following conditions
  47. - are met:
  48. - 1. Redistributions of source code must retain the above copyright
  49. - notice, this list of conditions and the following disclaimer.
  50. - 2. Redistributions in binary form must reproduce the above
  51. - copyright notice, this list of conditions and the following
  52. - disclaimer in the documentation and/or other materials
  53. - provided with the distribution.
  54. -
  55. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  56. - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  57. - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  58. - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
  59. - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  60. - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  61. - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  62. - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  63. - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  64. - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  65. - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  66. *====================================================================*/
  67. README (version 1.85.0)
  68. File update: Oct 16 2024
  69. ---------------------------
  70. gunzip leptonica-1.85.0.tar.gz
  71. tar -xvf leptonica-1.85.0.tar
  72. </pre>
  73. <!--Navigation Panel-->
  74. <hr>
  75. <P>
  76. <A HREF="#BUILDING">Building leptonica</A><br>
  77. <A HREF="#DEPENDENCIES">I/O libraries leptonica is dependent on</A><br>
  78. <A HREF="#DOXYGEN">Generating documentation using doxygen</A><br>
  79. <A HREF="#DEVELOP">Developing with leptonica</A><br>
  80. <A HREF="#CONTENTS">What's in leptonica?</A><br>
  81. <P>
  82. <hr>
  83. <!--End of Navigation Panel-->
  84. <h2> <A NAME="BUILDING">
  85. Building leptonica
  86. </h2>
  87. <pre>
  88. 1. Top view
  89. This tar includes:
  90. (1) src: library source and function prototypes for building liblept
  91. (2) prog: source for regression test, usage example programs, and
  92. sample images
  93. for building on these platforms:
  94. - Linux on x86 (i386) and AMD 64 (x64)
  95. - OSX (both powerPC and x86).
  96. - Cygwin, msys and mingw on x86
  97. There is an additional zip file for building with MS Visual Studio.
  98. Libraries, executables and prototypes are easily made, as described below.
  99. When you extract from the archive, all files are put in a
  100. subdirectory 'leptonica-1.85.0'. In that directory you will
  101. find a src directory containing the source files for the library,
  102. and a prog directory containing source files for various
  103. testing and example programs.
  104. 2. Building on Linux/Unix/MacOS
  105. The software can be downloaded from either a release tar file or
  106. from the current head of the source. For the latter, go to a directory
  107. and clone the tree into it (note the '.' at the end):
  108. cd [some directory]
  109. git clone https://github.com/DanBloomberg/leptonica.git .
  110. There are three ways to build the library:
  111. (1) By customization: Use the existing static makefile,
  112. src/makefile.static and customize the build by setting flags
  113. in src/environ.h. See details below.
  114. Note: if you are going to develop with leptonica, the static
  115. makefiles are useful.
  116. (2) Using autoconf (supported by James Le Cuirot).
  117. Run ./configure in this directory to
  118. build Makefiles here and in src. Autoconf handles the
  119. following automatically:
  120. * architecture endianness
  121. * enabling Leptonica I/O image read/write functions that
  122. depend on external libraries (if the libraries exist)
  123. * enabling functions for redirecting formatted image stream
  124. I/O to memory (on Linux only)
  125. After running ./configure: make; make install. There's also
  126. a 'make check' for testing.
  127. (3) Using cmake (supported by Egor Pugin).
  128. The build must always be in a different directory from the root
  129. of the source (here). It is common to build in a subdirectory
  130. of the root. From the root directory, do this:
  131. mkdir build
  132. cd build
  133. Then to make only the library:
  134. cmake ..
  135. make
  136. To make both the library and the programs:
  137. cmake .. -DBUILD_PROG=1
  138. make
  139. To clean out the current build, just remove everything in
  140. the build subdirectory.
  141. In more detail for these three methods:
  142. (1) Customization using the static makefiles:
  143. * FIRST THING: Run make-for-local. This simply renames
  144. src/makefile.static --> src/makefile
  145. prog/makefile.static --> prog/makefile
  146. [Note: the autoconf build will not work if you have any files
  147. named "makefile" in src or prog. If you've already run
  148. make-for-local and renamed the static makefiles, and you then
  149. want to build with autoconf, run make-for-auto to rename them
  150. back to makefile.static.]
  151. * You can customize for:
  152. (a) Including Leptonica image I/O functions that depend on external
  153. libraries, such as libpng. Use environment variables in
  154. src/environ.h, such as HAVE_LIBPNG.
  155. (b) Disabling the GNU functions for redirecting formatted stream I/O
  156. to memory. By default, HAVE_FMEMOPEN is enabled in src/environ.h.
  157. (c) Using special memory allocators (see src/environ.h).
  158. (d) Changing compile and runtime defaults for messages to stderr.
  159. The default in src/environ.h is to output info, warning and
  160. error messages.
  161. (e) Specifying the location of the object code. By default it
  162. goes into a tree whose root is also the parent of the src
  163. and prog directories. This can be changed using the
  164. ROOT_DIR variable in makefile.
  165. * Build the library:
  166. - To make an optimized version of the library (in src):
  167. make
  168. - To make a debug version of the library (in src):
  169. make DEBUG=yes debug
  170. - To make a shared library version (in src):
  171. make SHARED=yes shared
  172. - To make the prototype extraction program (in src):
  173. make (to make the library first)
  174. make xtractprotos
  175. * To use shared libraries, you need to include the location of
  176. the shared libraries in your LD_LIBRARY_PATH. For example,
  177. after you have built programs with 'make SHARED=yes' in the
  178. prog directory, you need to tell the programs where the shared
  179. libraries are:
  180. export LD_LIBRARY_PATH=../lib/shared:$LD_LIBRARY_PATH
  181. * Make the programs in prog/ (after you have make liblept):
  182. - Customize the makefile by setting ALL_LIBS to link the
  183. external image I/O libraries. By default, ALL_LIBS assumes that
  184. libtiff, libjpeg and libpng are available.
  185. - To make an optimized version of all programs (in prog):
  186. make
  187. - To make a debug version of all programs (in prog):
  188. make DEBUG=yes
  189. - To make a shared library version of all programs (in prog):
  190. make SHARED=yes
  191. - To run the programs, be sure to set
  192. export LD_LIBRARY_PATH=../lib/shared:$LD_LIBRARY_PATH
  193. (2) Building using autoconf (Thanks to James Le Cuirot)
  194. * If you downloaded from a release tar, it will be "configure ready".
  195. * If you cloned from the git master tree, you need to make the
  196. configure executable. To do this, run
  197. autogen.sh.
  198. Use the standard incantation, in the root directory (the
  199. directory with configure):
  200. ./configure [build the Makefile]
  201. make [builds the library and shared library versions of
  202. all the progs]
  203. make install [as root; this puts liblept.a into /usr/local/lib/
  204. and 13 of the progs into /usr/local/bin/ ]
  205. make [-j2] check [runs the alltests_reg set of regression tests.
  206. This works even if you build in a different
  207. place from the distribution. The -j parameter
  208. should not exceed half the number of cores.
  209. NOTE: If the test fails, it's likely due to a race
  210. condition. Rerun with 'make check']
  211. Configure supports installing in a local directory (e.g., one that
  212. doesn't require root access). For example, to install in $HOME/local,
  213. ./configure --prefix=$HOME/local/
  214. make install
  215. For different ways to build and link leptonica with tesseract, see
  216. https://github.com/tesseract-ocr/tesseract/wiki/Compiling
  217. In brief, using autotools to build tesseract and then install it
  218. in $HOME/local (after installing leptonica there), do the
  219. following from your tesseract root source directory:
  220. ./autogen.sh
  221. LIBLEPT_HEADERSDIR=$HOME/local/include ./configure \
  222. --prefix=$HOME/local/ --with-extra-libraries=$HOME/local/lib
  223. make install
  224. Configure also supports building in a separate directory from the
  225. source. Run "/(path-to)/leptonica-1.85.0/configure" and then "make"
  226. from the desired build directory.
  227. Configure has a number of useful options; run "configure --help" for
  228. details. If you're not planning to modify the library, adding the
  229. "--disable-dependency-tracking" option will speed up the build. By
  230. default, both static and shared versions of the library are built. Add
  231. the "--disable-shared" or "--disable-static" option if one or the other
  232. isn't needed. To skip building the programs, use "--disable-programs".
  233. By default, the library is built with debugging symbols. If you do not
  234. want these, use "CFLAGS=-O2 ./configure" to eliminate symbols for
  235. subsequent compilations, or "make CFLAGS=-O2" to override the default
  236. for compilation only. Another option is to use the 'install-strip'
  237. target (i.e., "make install-strip") to remove the debugging symbols
  238. when the library is installed.
  239. Finally, if you find that the installed programs are unable to link
  240. at runtime to the installed library, which is in /usr/local/lib,
  241. try to run configure in this way:
  242. LDFLAGS="-Wl,-rpath -Wl,/usr/local/lib" ./configure
  243. which causes the compiler to pass those options through to the linker.
  244. For the Debian distribution, out of all the programs in the prog
  245. directory, we only build a small subset of general purpose
  246. utility programs. This subset is the same set of programs that
  247. 'make install' puts into /usr/local/bin. It has no dependency on
  248. the image files that are bundled in the prog directory for testing.
  249. (3) Using cmake
  250. The usual method is to build in a directory that is a subdirectory
  251. of the root. First do this from the root directory:
  252. mkdir build
  253. cd build
  254. The default build (shared libraries, no debug, only the library)
  255. is made with
  256. cmake ..
  257. For other options, you can use these flags on the cmake line:
  258. * To make a static library:
  259. cmake .. -DBUILD_SHARED_LIBS=OFF
  260. make
  261. * To make a dynamic library (default) and STATIC (or builtin) dependencies:
  262. cmake .. -DSW_BUILD_SHARED_LIBS=0
  263. make
  264. * To build with debug:
  265. cmake .. -DCMAKE_BUILD_TYPE=Debug
  266. make
  267. * To make both the library and the programs:
  268. cmake .. -DBUILD_PROG=1
  269. make
  270. The programs are put in build/bin/
  271. To run these (e.g., for testing), move them to the prog
  272. directory and run them from there:
  273. cd bin
  274. mv * ../../prog/
  275. cd ../../prog
  276. alltests_reg generate
  277. alltests_reg compare
  278. To build the library directly from the root directory instead of
  279. the build subdirectory:
  280. mkdir build
  281. cmake -H . -Bbuild (-H means the source directory,
  282. -B means the directory for the build
  283. make
  284. 3. Building on Windows
  285. (a) Building with Visual Studio
  286. 1. Download the latest SW
  287. (Software Network https://software-network.org/)
  288. client from https://software-network.org/client/
  289. 2. Unpack it, add to PATH.
  290. 3. Run once to perform cmake integration:
  291. sw setup
  292. 4. Run:
  293. git clone https://github.com/danbloomberg/leptonica
  294. cd leptonica
  295. mkdir build
  296. cd build
  297. cmake ..
  298. 5. Build a solution (leptonica.sin) in your Visual Studio version.
  299. (b) Building for mingw32 with <a href="http://www.mingw.org/">MSYS</a>
  300. (Thanks to David Bryan)
  301. MSYS is a Unix-compatible build environment for the Windows-native
  302. mingw32 compiler. Selecting the "mingw-developer-toolkit",
  303. "mingw32-base", and "msys-base" packages during installation will allow
  304. building the library with autoconf as in (2) above. It will also allow
  305. building with the static makefile as in (1) above if this option is used
  306. in the make command line:
  307. CC='gcc -std=c99 -U__STRICT_ANSI__'
  308. Only the static library may be built this way; the autoconf method must
  309. be used if a shared (DLL) library is desired.
  310. External image libraries (see below) must be downloaded separately,
  311. built, and installed before building the library. Pre-built libraries
  312. are available from the <a
  313. href="http://sourceforge.net/projects/ezwinports/">ezwinports</a> project.
  314. (c) Building for <a href="http://www.cygwin.com/">Cygwin</a>
  315. (Thanks to David Bryan)
  316. Cygwin is a Unix-compatible build and runtime environment. Adding the
  317. "binutils", "gcc-core", and "make" packages from the "Devel" category and
  318. the "diffutils" package from the "Utils" category to the packages
  319. installed by default will allow building the library with autoconf as in
  320. (2) above. Pre-built external image libraries are available in the
  321. "Graphics" and "Libs" categories and may be selected for installation.
  322. If the libraries are not installed into the /lib, /usr/lib, or
  323. /usr/local/lib directories, you must run make with the
  324. "LDFLAGS=-L/(path-to-image)/lib" option. Building may also be performed
  325. with the static makefile as in (1) above if this option is used in the
  326. make command:
  327. CC='gcc -std=c99 -U__STRICT_ANSI__'
  328. Only the static library may be built this way; the autoconf method must
  329. be used if a shared (DLL) library is desired.
  330. 4. Building and running oss-fuzz programs
  331. The oss-fuzz programs are in prog/fuzzing/. They are run by oss-fuzz
  332. on a continual basis with random inputs. clang-10, which is required
  333. to build these programs, can be installed using the command
  334. sudo apt-get install clang-10
  335. Stefan Weil has provided this method for building the fuzzing programs.
  336. From your github root:
  337. ./autogen.sh (to make configure)
  338. mkdir -p bin/fuzzer
  339. cd bin/fuzzer
  340. Run configure to generate the Makefiles:
  341. address sanitizer issue:
  342. ../../configure CC=clang-10 CXX=clang++-10 CFLAGS="-g -O2 \
  343. -D_GLIBCXX_DEBUG -fsanitize=fuzzer-no-link,address,undefined" \
  344. CXXFLAGS="-g -O2 -D_GLIBCXX_DEBUG \
  345. -fsanitize=fuzzer-no-link,address,undefined"
  346. memory sanitizer issue:
  347. ../../configure CC=clang-10 CXX=clang++-10 CFLAGS="-g -O2 \
  348. -D_GLIBCXX_DEBUG -fsanitize=fuzzer-no-link,memory,undefined" \
  349. CXXFLAGS="-g -O2 -D_GLIBCXX_DEBUG \
  350. -fsanitize=fuzzer-no-link,memory,undefined"
  351. Build:
  352. address sanitizer issue:
  353. make fuzzers CXX=clang++-10 CXXFLAGS="-g -O2 -D_GLIBCXX_DEBUG \
  354. -fsanitize=fuzzer,address,undefined"
  355. memory sanitizer issue:
  356. make fuzzers CXX=clang++-10 CXXFLAGS="-g -O2 -D_GLIBCXX_DEBUG \
  357. -fsanitize=fuzzer,memory,undefined"
  358. When an oss-fuzz issue has been created, download the Reproducer
  359. Testcase file (e.g, name it "/tmp/payload"). To run one of the
  360. fuzzing executables in bin/fuzzer, e.g., pix4_fuzzer:
  361. cd ../../prog/fuzzing
  362. ../../bin/fuzzer/pix4_fuzzer /tmp/payload
  363. 5. The 270+ programs in the prog directory are an integral part of this
  364. package. They can be divided into four groups:
  365. (1) Programs that are useful applications for running on the
  366. command line. They can be installed from autoconf builds
  367. using 'make install'. Examples of these are the PostScript
  368. and pdf conversion programs: converttopdf, converttops,
  369. convertfilestopdf, convertfilestops, convertsegfilestopdf,
  370. convertsegfilestops, imagetops, printimage and printsplitimage.
  371. (2) Programs that are used as regression tests in alltests_reg.
  372. These are named *_reg, and 100 of them are invoked together
  373. (alltests_reg). The regression test framework has been
  374. standardized, and regresstion tests are relatively easy
  375. to write. See regutils.h for details.
  376. (3) Other regression tests, some of which have not (yet) been
  377. put into the framework. They are also named *_reg.
  378. (4) Programs that were used to test library functions or auto-generate
  379. library code. These are useful for testing the behavior of small
  380. sets of functions and for providing example code.
  381. 6. Sanitizers can be used on all the regression tests in alltests_reg.c.
  382. First run autogen.sh to generate the configure script
  383. autogen.sh
  384. Then run configure to generate the Makefile with the address sanitizer
  385. ./configure '--disable-shared' '--enable-debug' 'CFLAGS=-D_GLIBCXX_DEBUG -DDEBUG=1 -Wall -pedantic -g -O0 -fsanitize=address,undefined -fstack-protector-strong -ftrapv'
  386. Make and run all the regression tests
  387. make check
  388. </pre>
  389. <h2> <A NAME="DEPENDENCIES">
  390. I/O libraries leptonica is dependent on
  391. </h2>
  392. <pre>
  393. Leptonica is configured to handle image I/O using these external
  394. libraries: libjpeg, libtiff, libpng, libz, libwebp, libgif, libopenjp2
  395. These libraries are easy to obtain. For example, using the
  396. Debian package manager:
  397. sudo apt-get install <package>
  398. where <package> = {libpng-dev, libjpeg62-turbo-dev, libtiff5-dev,
  399. libwebp-dev, libopenjp2-7-dev, libgif-dev}.
  400. Leptonica also allows image I/O with bmp and pnm formats, for which
  401. we provide the serializers (encoders and decoders). It also
  402. gives output drivers for wrapping images in PostScript and PDF, which
  403. in turn use tiffg4, jpeg and flate (i.e., zlib) encoding. PDF will
  404. also wrap jpeg2000 images.
  405. There is a programmatic interface to gnuplot. To use it, you
  406. need only the gnuplot executable (suggest version 3.7.2 or later);
  407. the gnuplot library is not required.
  408. If you build with automake, libraries on your system will be
  409. automatically found and used.
  410. The rest of this section is for building with the static makefiles.
  411. The entries in environ.h specify which of these libraries to use.
  412. The default is to link to these four libraries:
  413. libjpeg.a (standard jfif jpeg library, version 6b or 7, 8 or 9))
  414. libtiff.a (standard Leffler tiff library, version 3.7.4 or later;
  415. libpng.a (standard png library, suggest version 1.4.0 or later)
  416. libz.a (standard gzip library, suggest version 1.2.3)
  417. current non-beta version is 3.8.2)
  418. These libraries (and their shared versions) should be in /usr/lib.
  419. (If they're not, you can change the LDFLAGS variable in the makefile.)
  420. Additionally, for compilation, the following header files are
  421. assumed to be in /usr/include:
  422. jpeg: jconfig.h
  423. png: png.h, pngconf.h
  424. tiff: tiff.h, tiffio.h
  425. If for some reason you do not want to link to specific libraries,
  426. even if you have them, stub files are included for the ten
  427. different output formats:
  428. bmp, jpeg, png, pnm, ps, pdf, tiff, gif, webp and jp2.
  429. For example, if you don't want to include the tiff library,
  430. in environ.h set:
  431. #define HAVE_LIBTIFF 0
  432. and the stubs will be linked in.
  433. To read and write webp files:
  434. (1) Download libwebp from sourceforge
  435. (2) #define HAVE_LIBWEBP 1 (in environ.h)
  436. (3) In prog/makefile, edit ALL_LIBS to include -lwebp
  437. (4) The library will be installed into /usr/local/lib.
  438. You may need to add that directory to LDFLAGS; or, equivalently,
  439. add that path to the LD_LIBRARY_PATH environment variable.
  440. To read and write jpeg2000 files:
  441. (1) Download libopenjp2, version 2.3, from their distribution.
  442. (2) #define HAVE_LIBJP2K 1 (in environ.h)
  443. (2a) If you have version 2.X, X != 3, edit LIBJP2K_HEADER (in environ.h)
  444. (3) In prog/makefile, edit ALL_LIBS to include -lopenjp2
  445. (4) The library will be installed into /usr/local/lib.
  446. To read and write gif files:
  447. (1) Download version giflib-5.1.X+ from souceforge
  448. (2) #define HAVE_LIBGIF 1 (in environ.h)
  449. (3) In prog/makefile, edit ALL_LIBS to include -lgif
  450. (4) The library will be installed into /usr/local/lib.
  451. </pre>
  452. <h2> <A NAME="DOXYGEN">
  453. Generating documentation using doxygen
  454. </h2>
  455. <pre>
  456. The source code is set up to allow generation of documentation using doxygen.
  457. To do this:
  458. (1) Download the Debian doxygen package:
  459. sudo apt-get install doxygen
  460. (2) In the root client directory containing Doxyfile:
  461. doxygen Doxyfile
  462. The documentation will be generated in a 'doc' subdirectory, accessible
  463. from this file (relative to the root)
  464. ./doc/html/index.html
  465. </pre>
  466. <h2> <A NAME="DEVELOP">
  467. Developing with leptonica
  468. </h2>
  469. <pre>
  470. You are encouraged to use the static makefiles if you are developing
  471. applications using leptonica. The following instructions assume
  472. that you are using the static makefiles and customizing environ.h.
  473. 1. Automatic generation of prototypes
  474. The prototypes are automatically generated by the program xtractprotos.
  475. They can either be put in-line into allheaders.h, or they can be
  476. written to a file leptprotos.h, which is #included in allheaders.h.
  477. Note: (1) We supply the former version of allheaders.h.
  478. (2) all .c files simply include allheaders.h.
  479. First, make xtractprotos:
  480. make xtractprotos
  481. Then to generate the prototypes and make allheaders.h, do one of
  482. these two things:
  483. make allheaders [puts everything into allheaders.h]
  484. make allprotos [generates a file leptprotos.h containing the
  485. function prototypes, and includes it in allheaders.h]
  486. Things to note about xtractprotos, assuming that you are developing
  487. in Leptonica and need to regenerate the prototypes in allheaders.h:
  488. (1) xtractprotos is part of Leptonica. You can 'make' it in either
  489. src or prog (see the makefile).
  490. (2) You can output the prototypes for any C file to stdout by running:
  491. xtractprotos <cfile> or
  492. xtractprotos -prestring=[string] <cfile>
  493. (3) The source for xtractprotos has been packaged up into a tar
  494. containing just the Leptonica files necessary for building it
  495. in Linux. The tar file is available at:
  496. www.leptonica.com/source/xtractlib-1.5.tar.gz
  497. 2. Global parameter to enable development and testing
  498. For security reasons, with the exception of the regression utility
  499. (regutils.c), leptonica as shipped (starting with 1.77) does not allow:
  500. * 'system(3)' fork/exec
  501. * writes to temp files with compiled-in names
  502. System calls are used either to run gnuplot or display an image on
  503. the screen.
  504. This is enforced with a global parameter, LeptDebugOK, initialized to 0.
  505. It can be overridden either at compile time by changing the initialization
  506. (in writefile.c), or at runtime, using setLeptDebugOK().
  507. The programs in the prog directory, which mostly test functions in
  508. the library, are not subject to this restriction.
  509. 3. GNU runtime functions for stream redirection to memory
  510. There are two non-standard gnu functions, fmemopen() and open_memstream(),
  511. that only work on Linux and conveniently allow memory I/O with a file
  512. stream interface. This is convenient for compressing and decompressing
  513. image data to memory rather than to file. Stubs are provided
  514. for all these I/O functions. Default is to enable them; OSX developers
  515. must disable by setting #define HAVE_FMEMOPEN 0 (in environ.h).
  516. If these functions are not enabled, raster to compressed data in
  517. memory is accomplished safely but through a temporary file.
  518. See 9 for more details on image I/O formats.
  519. If you're building with the autoconf programs, these two functions are
  520. automatically enabled if available.
  521. 4. Runtime functions not available on all platforms
  522. Some functions are not available on all systems. One example of such a
  523. function is fstatat(). If possible, such functions will be replaced by
  524. wrappers, stubs or behavioral equivalent functions. By default, such
  525. functions are disabled; enable them by setting #define HAVE_FUNC 1 (in
  526. environ.h).
  527. If you're building with the autoconf or cmake programs, these functions are
  528. automatically enabled if available.
  529. 5. Typedefs
  530. A deficiency of C is that no standard has been universally
  531. adopted for typedefs of the built-in types. As a result,
  532. typedef conflicts are common, and cause no end of havoc when
  533. you try to link different libraries. If you're lucky, you
  534. can find an order in which the libraries can be linked
  535. to avoid these conflicts, but the state of affairs is aggravating.
  536. The most common typedefs use lower case variables: uint8, int8, ...
  537. The png library avoids typedef conflicts by altruistically
  538. appending "png_" to the type names. Following that approach,
  539. Leptonica appends "l_" to the type name. This should avoid
  540. just about all conflicts. In the highly unlikely event that it doesn't,
  541. here's a simple way to change the type declarations throughout
  542. the Leptonica code:
  543. (1) customize a file "converttypes.sed" with the following lines:
  544. /l_uint8/s//YOUR_UINT8_NAME/g
  545. /l_int8/s//YOUR_INT8_NAME/g
  546. /l_uint16/s//YOUR_UINT16_NAME/g
  547. /l_int16/s//YOUR_INT16_NAME/g
  548. /l_uint32/s//YOUR_UINT32_NAME/g
  549. /l_int32/s//YOUR_INT32_NAME/g
  550. /l_float32/s//YOUR_FLOAT32_NAME/g
  551. /l_float64/s//YOUR_FLOAT64_NAME/g
  552. (2) in the src and prog directories:
  553. - if you have a version of sed that does in-place conversion:
  554. sed -i -f converttypes.sed *
  555. - else, do something like (in csh)
  556. foreach file (*)
  557. sed -f converttypes.sed $file > tempdir/$file
  558. end
  559. If you are using Leptonica with a large code base that typedefs the
  560. built-in types differently from Leptonica, just edit the typedefs
  561. in environ.h. This should have no side-effects with other libraries,
  562. and no issues should arise with the location in which liblept is
  563. included.
  564. For compatibility with 64 bit hardware and compilers, where
  565. necessary we use the typedefs in stdint.h to specify the pointer
  566. size (either 4 or 8 byte).
  567. 6. Compile and runtime control over stderr output (see environ.h and utils1.c)
  568. Leptonica provides both compile-time and run-time control over
  569. messages and debug output (thanks to Dave Bryan). Both compile-time
  570. and run-time severity thresholds can be set. The runtime threshold
  571. can also be set by an environmental variable. Messages are
  572. vararg-formatted and of 3 types: error, warning, informational.
  573. These are all macros, and can be further suppressed when
  574. NO_CONSOLE_IO is defined on the compile line. For production code
  575. where no output is to go to stderr, compile with -DNO_CONSOLE_IO.
  576. Runtime redirection of stderr output is also possible, using a
  577. callback mechanism. The callback function is registered using
  578. leptSetStderrHandler(). See utils1.c for details.
  579. 7. In-memory raster format (Pix)
  580. Unlike many other open source packages, Leptonica uses packed
  581. data for images with all bit/pixel (bpp) depths, allowing us
  582. to process pixels in parallel. For example, rasterops works
  583. on all depths with 32-bit parallel operations throughout.
  584. Leptonica is also explicitly configured to work on both little-endian
  585. and big-endian hardware. RGB image pixels are always stored
  586. in 32-bit words, and a few special functions are provided for
  587. scaling and rotation of RGB images that have been optimized by
  588. making explicit assumptions about the location of the R, G and B
  589. components in the 32-bit pixel. In such cases, the restriction
  590. is documented in the function header. The in-memory data structure
  591. used throughout Leptonica to hold the packed data is a Pix,
  592. which is defined and documented in pix.h. The alpha component
  593. in RGB images is significantly better supported, starting in 1.70.
  594. Additionally, a FPix is provided for handling 2D arrays of floats,
  595. and a DPix is provided for 2D arrays of doubles. Converters
  596. between these and the Pix are given.
  597. 8. Conversion between Pix and other in-memory raster formats
  598. . If you use Leptonica with other imaging libraries, you will need
  599. functions to convert between the Pix and other image data
  600. structures. To make a Pix from other image data structures, you
  601. will need to understand pixel packing, pixel padding, component
  602. ordering and byte ordering on raster lines. See the file pix.h
  603. for the specification of image data in the pix.
  604. 9. Custom memory management
  605. Leptonica allows you to use custom memory management (allocator,
  606. deallocator). For Pix, which tend to be large, the alloc/dealloc
  607. functions can be set programmatically. For all other structs and arrays,
  608. the allocators are specified in environ.h. Default functions
  609. are malloc and free. We have also provided a sample custom
  610. allocator/deallocator for Pix, in pixalloc.c.
  611. </pre>
  612. <h2> <A NAME="CONTENTS">
  613. What's in leptonica?
  614. </h2>
  615. <pre>
  616. 1. Rasterops
  617. This is a source for a clean, fast implementation of rasterops.
  618. You can find details starting at the Leptonica home page,
  619. and also by looking directly at the source code.
  620. Some of the low-level code is in roplow.c, and an interface is
  621. given in rop.c to the simple Pix image data structure.
  622. 2. Binary morphology
  623. This is a source for efficient implementations of binary morphology
  624. Details are found starting at the Leptonica home page, and by reading
  625. the source code.
  626. Binary morphology is implemented two ways:
  627. (a) Successive full image rasterops for arbitrary
  628. structuring elements (Sels)
  629. (b) Destination word accumulation (dwa) for specific Sels.
  630. This code is automatically generated. See, for example,
  631. the code in fmorphgen.1.c and fmorphgenlow.1.c.
  632. These files were generated by running the program
  633. prog/fmorphautogen.c. Results can be checked by comparing dwa
  634. and full image rasterops; e.g., prog/fmorphauto_reg.c.
  635. Method (b) is considerably faster than (a), which is the
  636. reason we've gone to the effort of supporting the use
  637. of this method for all Sels. We also support two different
  638. boundary conditions for erosion.
  639. Similarly, dwa code for the general hit-miss transform can
  640. be auto-generated from an array of hit-miss Sels.
  641. When prog/fhmtautogen.c is compiled and run, it generates
  642. the dwa C code in fhmtgen.1.c and fhmtgenlow.1.c. These
  643. files can then be compiled into the libraries or into other programs.
  644. Results can be checked by comparing dwa and rasterop results;
  645. e.g., prog/fhmtauto_reg.c
  646. Several functions with simple parsers are provided to execute a
  647. sequence of morphological operations (plus binary rank reduction
  648. and replicative expansion). See morphseq.c.
  649. The structuring element is represented by a simple Sel data structure
  650. defined in morph.h. We provide (at least) seven ways to generate
  651. Sels in sel1.c, and several simple methods to generate hit-miss
  652. Sels for pattern finding in selgen.c.
  653. In use, the most common morphological Sels are separable bricks,
  654. of dimension n x m (where either n or m, but not both, is commonly 1).
  655. Accordingly, we provide separable morphological operations on brick
  656. Sels, using for binary both rasterops and dwa. Parsers are provided
  657. for a sequence of separable binary (rasterop and dwa) and grayscale
  658. brick morphological operations, in morphseq.c. The main
  659. advantage in using the parsers is that you don't have to create
  660. and destroy Sels, or do any of the intermediate image bookkeeping.
  661. We also give composable separable brick functions for binary images,
  662. for both rasterop and dwa. These decompose each of the linear
  663. operations into a sequence of two operations at different scales,
  664. reducing the operation count to a sum of decomposition factors,
  665. rather than the (un-decomposed) product of factors.
  666. As always, parsers are provided for a sequence of such operations.
  667. 3. Grayscale morphology and rank order filters
  668. We give an efficient implementation of grayscale morphology for brick
  669. Sels. See the Leptonica home page and the source code.
  670. Brick Sels are separable into linear horizontal and vertical elements.
  671. We use the van Herk/Gil-Werman algorithm, that performs the calculations
  672. in a time that is independent of the size of the Sels. Implementations
  673. of tophat and hdome are also given.
  674. We also provide grayscale rank order filters for brick filters.
  675. The rank order filter is a generalization of grayscale morphology,
  676. that selects the rank-valued pixel (rather than the min or max).
  677. A color rank order filter applies the grayscale rank operation
  678. independently to each of the (r,g,b) components.
  679. 4. Image scaling
  680. Leptonica provides many simple and relatively efficient
  681. implementations of image scaling. Some of them are listed here;
  682. for the full set see the web page and the source code.
  683. Grayscale and color images are scaled using:
  684. - sampling
  685. - lowpass filtering followed by sampling,
  686. - area mapping
  687. - linear interpolation
  688. Scaling operations with antialiased sampling, area mapping,
  689. and linear interpolation are limited to 2, 4 and 8 bpp gray,
  690. 24 bpp full RGB color, and 2, 4 and 8 bpp colormapped
  691. (bpp == bits/pixel). Scaling operations with simple sampling
  692. can be done at 1, 2, 4, 8, 16 and 32 bpp. Linear interpolation
  693. is slower but gives better results, especially for upsampling.
  694. For moderate downsampling, best results are obtained with area
  695. mapping scaling. With very high downsampling, either area mapping
  696. or antialias sampling (lowpass filter followed by sampling) give
  697. good results. Fast area map with power-of-2 reduction are also
  698. provided. Optional sharpening after resampling is provided to
  699. improve appearance by reducing the visual effect of averaging
  700. across sharp boundaries.
  701. For fast analysis of grayscale and color images, it is useful to
  702. have integer subsampling combined with pixel depth reduction.
  703. RGB color images can thus be converted to low-resolution
  704. grayscale and binary images.
  705. For binary scaling, the dest pixel can be selected from the
  706. closest corresponding source pixel. For the special case of
  707. power-of-2 binary reduction, low-pass rank-order filtering can be
  708. done in advance. Isotropic integer expansion is done by pixel replication.
  709. We also provide 2x, 3x, 4x, 6x, 8x, and 16x scale-to-gray reduction
  710. on binary images, to produce high quality reduced grayscale images.
  711. These are integrated into a scale-to-gray function with arbitrary
  712. reduction.
  713. Conversely, we have special 2x and 4x scale-to-binary expansion
  714. on grayscale images, using linear interpolation on grayscale
  715. raster line buffers followed by either thresholding or dithering.
  716. There are also image depth converters that don't have scaling,
  717. such as unpacking operations from 1 bpp to grayscale, and
  718. thresholding and dithering operations from grayscale to 1, 2 and 4 bpp.
  719. 5. Image shear and rotation (and affine, projective, ...)
  720. Image shear is implemented with both rasterops and linear interpolation.
  721. The rasterop implementation is faster and has no constraints on image
  722. depth. We provide horizontal and vertical shearing about an
  723. arbitrary point (really, a line), both in-place and from source to dest.
  724. The interpolated shear is used on 8 bpp and 32 bpp images, and
  725. gives a smoother result. Shear is used for the fastest implementations
  726. of rotation.
  727. There are three different types of general image rotators:
  728. a. Grayscale rotation using area mapping
  729. - pixRotateAM() for 8 bit gray and 24 bit color, about center
  730. - pixRotateAMCorner() for 8 bit gray, about image UL corner
  731. - pixRotateAMColorFast() for faster 24 bit color, about center
  732. b. Rotation of an image of arbitrary bit depth, using
  733. either 2 or 3 shears. These rotations can be done
  734. about an arbitrary point, and they can be either
  735. from source to dest or in-place; e.g.
  736. - pixRotateShear()
  737. - pixRotateShearIP()
  738. c. Rotation by sampling. This can be used on images of arbitrary
  739. depth, and done about an arbitrary point. Colormaps are retained.
  740. The area mapping rotations are slower and more accurate, because each
  741. new pixel is composed using an average of four neighboring pixels
  742. in the original image; this is sometimes also also called "antialiasing".
  743. Very fast color area mapping rotation is provided.
  744. The shear rotations are much faster, and work on images of arbitrary
  745. pixel depth, but they just move pixels around without doing any averaging.
  746. The pixRotateShearIP() operates on the image in-place.
  747. We also provide orthogonal rotators (90, 180, 270 degree; left-right
  748. flip and top-bottom flip) for arbitrary image depth.
  749. And we provide implementations of affine, projective and bilinear
  750. transforms, with both sampling (for speed) and interpolation
  751. (for antialiasing).
  752. 6. Sequential algorithms
  753. We provide a number of fast sequential algorithms, including
  754. binary and grayscale seedfill, and the distance function for
  755. a binary image. The most efficient binary seedfill is
  756. pixSeedfill(), which uses Luc Vincent's algorithm to iterate
  757. raster- and antiraster-ordered propagation, and can be used
  758. for either 4- or 8-connected fills. Similar raster/antiraster
  759. sequential algorithms are used to generate a distance map from
  760. a binary image, and for grayscale seedfill. We also use Heckbert's
  761. stack-based filling algorithm for identifying 4- and 8-connected
  762. components in a binary image. A fast implementation of the
  763. watershed transform, using a priority queue, is included.
  764. 7. Image enhancement
  765. Some simple image enhancement routines for grayscale and color
  766. images have been provided. These include intensity mapping with
  767. gamma correction and contrast enhancement, histogram equalization,
  768. edge sharpening, smoothing, and various color-shifting operations.
  769. 8. Convolution and cousins
  770. A number of standard image processing operations are also
  771. included, such as block convolution, binary block rank filtering,
  772. grayscale and rgb rank order filtering, and edge and local
  773. minimum/maximum extraction. Generic convolution is included,
  774. for both separable and non-separable kernels, using float arrays
  775. in the Pix. Two implementations are included for grayscale and
  776. color bilateral filtering: a straightforward (slow) one, and a
  777. fast, approximate, separable one.
  778. 9. Image I/O
  779. Some facilities have been provided for image input and output.
  780. This is of course required to build executables that handle images,
  781. and many examples of such programs, most of which are for
  782. testing, can be built in the prog directory. Functions have been
  783. provided to allow reading and writing of files in JPEG, PNG,
  784. TIFF, BMP, PNM ,GIF, WEBP and JP2 formats. These formats were chosen
  785. for the following reasons:
  786. - JFIF JPEG is the standard method for lossy compression
  787. of grayscale and color images. It is supported natively
  788. in all browsers, and uses a good open source compression
  789. library. Decompression is supported by the rasterizers
  790. in PS and PDF, for level 2 and above. It has a progressive
  791. mode that compresses about 10% better than standard, but
  792. is considerably slower to decompress. See jpegio.c.
  793. - PNG is the standard method for lossless compression
  794. of binary, grayscale and color images. It is supported
  795. natively in all browsers, and uses a good open source
  796. compression library (zlib). It is superior in almost every
  797. respect to GIF (which, until recently, contained proprietary
  798. LZW compression). See pngio.c.
  799. - TIFF is a common interchange format, which supports different
  800. depths, colormaps, etc., and also has a relatively good and
  801. widely used binary compression format (CCITT Group 4).
  802. Decompression of G4 is supported by rasterizers in PS and PDF,
  803. level 2 and above. G4 compresses better than PNG for most
  804. text and line art images, but it does quite poorly for halftones.
  805. It has good and stable support by Leffler's open source library,
  806. which is clean and small. Tiff also supports multipage
  807. images through a directory structure. Note: because jpeg is
  808. a supported tiff compression mode, leptonica requires linking
  809. both libtiff and libjpeg to read and write tiff. See tiffio.c
  810. - BMP has (until recently) had no compression. It is a simple
  811. format with colormaps that requires no external libraries.
  812. It is commonly used because it is a Microsoft standard,
  813. but has little besides simplicity to recommend it. See bmpio.c.
  814. - PNM is a very simple, old format that still has surprisingly
  815. wide use in the image processing community. It does not
  816. support compression or colormaps, but it does support binary,
  817. grayscale and rgb images. Like BMP, the implementation
  818. is simple and requires no external libraries. See pnmio.c.
  819. - WEBP is a new wavelet encoding method derived from libvpx,
  820. a video compression library. It is rapidly growing in acceptance,
  821. and is supported natively in several browsers. Leptonica provides
  822. an interface through webp into the underlying codec. You need
  823. to download libwebp. See webpio.c.
  824. - JP2 (jpeg2000) is a wavelet encoding method, that has clear
  825. advantages over jpeg in compression and quality (especially when
  826. the image has sharp edges, such as scanned documents), but is
  827. only slowly growing in acceptance. For it to be widely supported,
  828. it will require support on a major browser (as with webp).
  829. Leptonica provides an interface through openjpeg into the underlying
  830. codec. You need to download libopenjp2, version 2.X. See jp2kio.c.
  831. - GIF is still widely used in the world. With the expiration
  832. of the LZW patent, it is practical to add support for GIF files.
  833. The open source gif library is relatively incomplete and
  834. unsupported (because of the Sperry-Rand-Burroughs-Univac
  835. patent history). Leptonica supports versions 5.1+. See gifio.c.
  836. Here's a summary of compression support and limitations:
  837. - All formats except JPEG, WEBP and JP2K support 1 bpp binary.
  838. - All formats support 8 bpp grayscale (GIF must have a colormap).
  839. - All formats except GIF support rgb color.
  840. - All formats except PNM, JPEG, WEBP and JP2K support 8 bpp colormap.
  841. - PNG and PNM support 2 and 4 bpp images.
  842. - PNG supports 2 and 4 bpp colormap, and 16 bpp without colormap.
  843. - PNG, JPEG, TIFF, WEBP, JP2K and GIF support image compression;
  844. PNM and BMP do not.
  845. - WEBP supports rgb color and rgba.
  846. - JP2 supports 8 bpp grayscale, rgb color and rgba.
  847. Use prog/ioformats_reg for a regression test on all formats, including
  848. thorough testing on TIFF.
  849. For more thorough testing on other formats, use:
  850. - prog/pngio_reg for PNG.
  851. - prog/gifio_reg for GIF
  852. - prog/webpio_reg for WEBP
  853. - prog/jp2kio_reg for JP2
  854. We provide generators for PS output, from all types of input images.
  855. The output can be either uncompressed or compressed with level 2
  856. (ccittg4 or dct) or level 3 (flate) encoding. You have flexibility
  857. for scaling and placing of images, and for printing at different
  858. resolutions. You can also compose mixed raster (text, image) PS.
  859. See psio1.c for examples of how to output PS for different applications.
  860. As examples of usage, see:
  861. * prog/converttops.c for a general image --> PS conversion
  862. for printing. You can specify the PS compression level (1, 2, or 3).
  863. * prog/imagetops.c for a special image --> PS conversion
  864. for printing at maximum size on 8.5 x 11 paper. You can
  865. specify the PS compression level (1, 2, or 3).
  866. * prog/convertfilestops.c to generate a multipage level 3 compressed
  867. PS file that can then be converted to pdf with ps2pdf.
  868. * prog/convertsegfilestops.c to generate a multipage, mixed raster,
  869. level 2 compressed PS file.
  870. We provide generators for PDF output, again from all types of input
  871. images, and with ccittg4, dct, flate and jpx (jpeg2000) compression.
  872. You can do the following for PDF:
  873. * Put any number of images onto a page, with specified input
  874. resolution, location and compression.
  875. * Write a mixed raster PDF, given an input image and a segmentation
  876. mask. Non-image regions are written in G4 (fax) encoding.
  877. * Concatenate single-page PDF wrapped images into a single PDF file.
  878. * Build a PDF file of all images in a directory or array of file names.
  879. As examples of usage, see:
  880. * prog/converttopdf.c: fast pdf generation with one image/page.
  881. For speed, this avoids transcoding whenever possible.
  882. * prog/convertfilestopdf.c: more flexibility in the output. You
  883. can set the resolution, scaling, encoding type and jpeg quality.
  884. * prog/convertsegfilestopdf.c: generates a multipage, mixed raster pdf,
  885. with separate controls for compressing text and non-text regions.
  886. Note: any or all of these I/O library calls can be stubbed out at
  887. compile time, using the environment variables in environ.h.
  888. For all formatted reads and writes, we support read from memory
  889. and write to memory. The gnu C runtime library (glibc) supports
  890. two I/O functions, open_memstream() and fmemopen(), which read
  891. and write directly to memory as if writing to a file stream.
  892. * On all platforms, leptonica supports direct read/write with memory
  893. for TIFF, PNG, BMP, GIF and WEBP formats.
  894. * On linux, leptonica uses the special gnu libraries to enable
  895. direct read/write with memory for JPEG, PNM and JP2.
  896. * On platforms without the gnu libraries, such as OSX, Windows
  897. and Solaris, read/write with memory for JPEG, PNM and JP2 goes
  898. through temp files.
  899. To enable/disable memory I/O for image read/write, see environ.h.
  900. We also provide fast serialization and deserialization between a pix
  901. in memory and a file (spixio.c). This works on all types of pix images.
  902. 10. Colormap removal and color quantization
  903. Leptonica provides functions that remove colormaps, for conversion
  904. to either 8 bpp gray or 24 bpp RGB. It also provides the inverse
  905. function to colormap removal; namely, color quantization
  906. from 24 bpp full color to 8 bpp colormap with some number
  907. of colormap colors. Several versions are provided, some that
  908. use a fast octree vector quantizer and others that use
  909. a variation of the median cut quantizer. For high-level interfaces,
  910. see for example: pixConvertRGBToColormap(), pixOctreeColorQuant(),
  911. pixOctreeQuantByPopulation(), pixFixedOctcubeQuant256(),
  912. and pixMedianCutQuant().
  913. 11. Programmatic image display
  914. For debugging, pixDisplay() and pixDisplayWithTitle() in writefile.c
  915. can be called to display an image using one of several display
  916. programs (xzgv, xli, xv, l_view). If necessary to fit on the screen,
  917. the image is reduced in size, with 1 bpp images being converted
  918. to grayscale for readability. Another common debug method is to
  919. accumulate intermediate images in a pixa, and then either view these
  920. as a mosaic (using functions in pixafunc2.c), or gather them into
  921. a compressed PDF or PostScript file for viewing with evince. Common
  922. image display programs are: xzgv, xli, xv, display, gthumb, gqview,
  923. evince, gv and acroread.
  924. 12. Document image analysis
  925. Many functions have been included specifically to help with
  926. document image analysis. These include skew and text orientation
  927. detection; page segmentation; baseline finding for text;
  928. unsupervised classification of connected components, characters
  929. and words; dewarping camera images; adaptive binarization; and
  930. a simple book-adaptive classifier for various character sets,
  931. segmentation for newspaper articles, etc.
  932. 13. Data structures
  933. Several simple data structures are provided for safe and efficient handling
  934. of arrays of numbers, strings, pointers, and bytes. The generic
  935. pointer array is implemented in four ways: as a stack, a queue,
  936. a heap (used to implement a priority queue), and an array with
  937. insertion and deletion, from which the stack operations form a subset.
  938. Byte arrays are implemented both as a wrapper around the actual
  939. array and as a queue. The string arrays are particularly useful
  940. for both parsing and composing text. Generic lists with
  941. doubly-linked cons cells are also provided. Other data structures
  942. are provided for handling ordered sets and maps, as well as hash sets
  943. and hash maps.
  944. 14. Examples of programs that are easily built using the library:
  945. - for plotting x-y data, we give a programmatic interface
  946. to the gnuplot program, with output to X11, png, ps or eps.
  947. We also allow serialization of the plot data, in a form
  948. such that the data can be read, the commands generated,
  949. and (finally) the plot constructed by running gnuplot.
  950. - a simple jbig2-type classifier, using various distance
  951. metrics between image components (correlation, rank
  952. hausdorff); see prog/jbcorrelation.c, prog/jbrankhaus.c.
  953. - a simple color segmenter, giving a smoothed image
  954. with a small number of the most significant colors.
  955. - a program for converting all images in a directory
  956. to a PostScript file, and a program for printing an image
  957. in any (supported) format to a PostScript printer.
  958. - various programs for generating pdf files from compressed
  959. images, including very fast ones that don't scale and
  960. avoid transcoding if possible.
  961. - converters between binary images and SVG format.
  962. - an adaptive recognition utility for training and identifying
  963. text characters in a multipage document such as a book.
  964. - a bitmap font facility that allows painting text onto
  965. images. We currently support one font in several sizes.
  966. The font images and postscript programs for generating
  967. them are stored in prog/fonts/, and also as compiled strings
  968. in bmfdata.h.
  969. - a binary maze game lets you generate mazes and find shortest
  970. paths between two arbitrary points, if such a path exists.
  971. You can also compute the "shortest" (i.e., least cost) path
  972. between points on a grayscale image.
  973. - a 1D barcode reader. This is still in an early stage of development,
  974. with little testing, and it only decodes 6 formats.
  975. - a utility that will dewarp images of text that were captured
  976. with a camera at close range.
  977. - a sudoku solver and generator, including a good test for uniqueness
  978. - see (13, above) for other document image applications.
  979. 15. JBig2 encoder
  980. Leptonica supports an open source jbig2 encoder (yes, there is one!),
  981. which can be downloaded from:
  982. http://www.imperialviolet.org/jbig2.html.
  983. To build the encoder, use the most recent version. This bundles
  984. Leptonica 1.63. Once you've built the encoder, use it to compress
  985. a set of input image files: (e.g.)
  986. ./jbig2 -v -s <imagefile1 ...> > <jbig2_file>
  987. You can also generate a pdf wrapping for the output jbig2. To do that,
  988. call jbig2 with the -p arg, which generates a symbol file (output.sym)
  989. plus a set of location files for each input image (output.0000, ...):
  990. ./jbig2 -v -s -p <imagefile1 ...>
  991. and then generate the pdf:
  992. python pdf.py output > <pdf_file>
  993. See the usage documentation for the jbig2 compressor at:
  994. http://www.imperialviolet.org/binary/jbig2enc.html
  995. You can uncompress the jbig2 files using jbig2dec, which can be
  996. downloaded and built from:
  997. http://jbig2dec.sourceforge.net/
  998. 16. Versions
  999. New versions of the Leptonica library are released several times
  1000. a year, and version numbers are provided for each release in the
  1001. following files:
  1002. src/makefile.static
  1003. CMakeLists.txt
  1004. configure.ac
  1005. allheaders_top.txt (and propagated to allheaders.h)
  1006. All even versions from 1.42 to 1.60 were originally archived at
  1007. http://code.google.com/p/leptonica, as well as all versions after 1.60.
  1008. These have now been transferred by Egor Pugin to github:
  1009. github.com/danbloomberg/leptonica
  1010. where all releases (1.42 - 1.85.0) are available; e.g.,
  1011. https://github.com/DanBloomberg/leptonica/releases/tag/1.85.0
  1012. The more recent releases, from 1.80, are also available at
  1013. leptonica.org/download.html
  1014. Note that if you are downloading from github, the releases are more
  1015. likely to be stable than the master. Also, if you download from
  1016. the master and use autotools (e.g., Makefile.am), you must first run
  1017. autogen.sh to generate the configure program and the Makefiles.
  1018. The number of downloads of leptonica increased by nearly an order
  1019. of magnitude with 1.69, due to bundling with tesseract and
  1020. incorporation in ubuntu 12-04. Jeff Breidenbach has built all
  1021. the Debian releases, which require release version numbers.
  1022. The Debian binary release versions to date are:
  1023. 1.69 : 3.0.0
  1024. 1.70 : 4.0.0
  1025. 1.71 : 4.2.0
  1026. 1.72 : 4.3.0
  1027. 1.73 : 5.0.0
  1028. 1.74 : 5.1.0
  1029. 1.75 : 5.2.0
  1030. 1.76 : 5.3.0
  1031. 1.77 : 5.3.0
  1032. 1.78 : 5.3.0
  1033. 1.79 : 5.4.0
  1034. 1.80 : 5.4.0
  1035. 1.81 : 5.4.0
  1036. 1.82 : 5.4.0
  1037. 1.83 : 6.0.0
  1038. 1.84 : 6.0.0
  1039. 1.85 : 6.0.0 (in progress)
  1040. A brief version chronology is maintained in version-notes.html.
  1041. Starting with gcc 4.3.3, error warnings (-Werror) are given for
  1042. minor infractions like not checking return values of built-in C
  1043. functions. I have attempted to eliminate these warnings.
  1044. In any event, you will see warnings with the -Wall flag.
  1045. </pre>
  1046. <!-- JS Window Closer -----
  1047. <form>
  1048. <center>
  1049. <input type="button" onclick="window.close();" value="Close this window">
  1050. </center>
  1051. </form>
  1052. ----- JS Window Closer -->
  1053. </body>
  1054. </html>