Skip to content
zdenop edited this page Dec 1, 2023 · 8 revisions

Welcome to the leptonica wiki!

Build

Get the source

Download release package

The release version can be downloaded from the Leptonica Github project page. In the "Assets" section you will find source packages compressed with zip or tar&gz. Download the package with the desired compression and decompress it.

Retrieve current code with Git

With Git you can get the current source code (e.g. with not yet released fixes and improvements, but the code might be unstable so you should not use it in a production environment).

git clone --depth=1 https://github.com/DanBloomberg/leptonica

Parameter --depth=1 limits code history to the latest commit, so if you want to work with full code history, skip this parameter.

Dependencies

To build Leptonica you only need C compiler and GNU Autotools or CMake.

Without other external libraries Leptonica only support the following image formats: bmp, pnm, spix. This might be sufficient if you use Leptonica only for image processing and the image is opened by other tools (e.g. Qt).

However, it might be good idea to compile Leptonica with zlib and png support.

You should consider to installing the following other libraries (and their dependencies) as need:

The presence of dependencies is recognised automatically, so you do not need to activate them (but you can deactivate them).

Windows

Requirements:

All tools must be in the path, so maybe you will need to adapt your system PATH by c:\Program Files\Git\usr\bin;c:\Program Files\Git\mingw64\bin;

Let's use for source code directory C:\Projects\source and for installation directory C:\Projects\win64

mkdir C:\Projects\source
mkdir C:\Projects\win64
SET INSTALL_DIR=C:\Projects\win64
SET PATH=%PATH%;%INSTALL_DIR%\bin;
chdir C:\Projects\source

Initialize VS (2019) 64bit environment:

call "c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" x64

Optional: Installing dependencies

This is not a comprehensive guide to creating external libraries - just use it as an example and customise the creation parameters according to your needs.

Note: The following steps use the latest code of the external libraries - you should use the stable version.

Build and Install zlib-ng

git clone --depth 1 https://github.com/zlib-ng/zlib-ng.git
chdir zlib-ng
cmake -Bbuild -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DBUILD_SHARED_LIBS=OFF -DZLIB_COMPAT=ON -DZLIB_ENABLE_TESTS=OFF -DINSTALL_UTILS=OFF
cmake --build build --config Release --target install
chdir ..

Build and Install libpng

curl -sSL https://download.sourceforge.net/libpng/lpng1640.zip -o lpng1640.zip
unzip.exe -qq lpng1640.zip
chdir lpng1640
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DPNG_TESTS=OFF -DPNG_SHARED=OFF
cmake --build build --config Release --target install
chdir ..

Build and Install giflib

git clone --depth 1 https://github.com/xbmc/giflib.git
chdir giflib
cmake -Bbuild -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% 
cmake --build build --config Release --target install
chdir ..

Build and Install libjpeg

curl -sSL  https://www.nasm.us/pub/nasm/releasebuilds/2.16.01/win64/nasm-2.16.01-win64.zip -o nasm-2.16.01-win64.zip
unzip -qq  nasm-2.16.01-win64.zip
copy nasm-2.16.01\*.exe %INSTALL_DIR%\bin\

git clone --depth 1 https://github.com/libjpeg-turbo/libjpeg-turbo.git
chdir libjpeg-turbo
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DWITH_TURBOJPEG=OFF
cmake --build build --config Release --target install
chdir ..

Build and Install webp

git clone --depth 1 https://chromium.googlesource.com/webm/libwebp
chdir libwebp
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DWEBP_BUILD_WEBP_JS=OFF -DWEBP_BUILD_ANIM_UTILS=OFF -DWEBP_BUILD_CWEBP=OFF -DWEBP_BUILD_DWEBP=OFF -DWEBP_BUILD_GIF2WEBP=OFF -DWEBP_BUILD_IMG2WEBP=OFF -DWEBP_BUILD_VWEBP=OFF -DWEBP_BUILD_WEBPMUX=OFF -DWEBP_BUILD_EXTRAS=OFF -DWEBP_BUILD_WEBP_JS=OFF
cmake --build build --config Release --target install
chdir ..

Build and Install tiff and its depencies

Build and Install jbigkit
git clone --depth 1 https://github.com/zdenop/jbigkit.git
chdir jbigkit
cmake -Bbuild -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DBUILD_PROGRAMS=OFF -DBUILD_TOOLS=OFF -DCMAKE_WARN_DEPRECATED=OFF
cmake --build build --config Release --target install
chdir ..
Build and Install zstd
git clone --depth 1 https://github.com/facebook/zstd.git
chdir zstd\build\cmake
cmake -Bbuild -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% 
cmake --build build --config Release --target install
chdir ..\..\..
Build and Install lzma
curl -sSL https://sourceforge.net/projects/lzmautils/files/xz-5.4.5.tar.zst/download -o xz-5.4.5.tar.zst
zstd -d xz-5.4.5.tar.zst
tar xf  xz-5.4.5.tar
chdir xz-5.4.5
cmake -Bbuild -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=ON
cmake --build build --config Release --target install
chdir ..
Build and Install libtiff
git clone --depth 1 https://gitlab.com/libtiff/libtiff.git
chdir libtiff
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -Dtiff-tools=OFF -Dtiff-tests=OFF -Dtiff-contrib=OFF -Dtiff-docs=OFF
cmake --build build --config Release --target install
chdir ..

Build and Install openjpeg

git clone --depth 1 https://github.com/uclouvain/openjpeg.git
chdir openjpeg
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% 
cmake --build build --config Release --target install
chdir ..

Build and Install Leptonica

git clone --depth=1 https://github.com/DanBloomberg/leptonica
chdir leptonica
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DSW_BUILD=OFF -DBUILD_PROG=OFF -DBUILD_SHARED_LIBS=ON -DBUILD_PROG=ON
cmake --build build --config Release --target install
chdir ..

Test Leptonica

C:\Projects\win64\bin\fileinfo c:\Projects\source\leptonica\prog\test-rgb.png
Clone this wiki locally