118.3. libjpeg-turbo-3.2.0
A fork of the original IJG libjpeg which uses SIMD to accelerate baseline JPEG compression and decompression
| Version | 3.2.0, release 2 |
| Shelf | image-libs — Raster image formats, codecs, metadata, processing, barcodes, and terminal image output |
| Phase | 41_system (System), 92 of 1047 in build order |
| Licence | IJG AND BSD-3-Clause AND Zlib |
| Homepage | https://libjpeg-turbo.org/ |
| Build time | 4.3 SBU |
| Installed size | 5.1 MiB in 42 files |
| Recipe | ports/core/image-libs/libjpeg-turbo/kpkgbuild |
About
libjpeg-turbo is the JPEG codec: libjpeg, the IJG API that nearly every program reading or writing a JPEG links, accelerated with SIMD kernels, and libturbojpeg, its own simpler API. It also installs cjpeg, djpeg, jpegtran, rdjpgcom, wrjpgcom and tjbench. It is one of the most depended-on libraries in the tree: libtiff, libwebp, libjxl, libheif, libavif, gdk-pixbuf, the toolkits and the browsers all link it.
Sources
libjpeg-turbo-3.2.0.tar.gz(2.4 MiB)
sha2566f30092cef9fb839779646608f4ee14ae3cbac989c47fa05e841b0841f09878e
upstream: https://github.com/libjpeg-turbo/libjpeg-turbo/releases/download/3.2.0/libjpeg-turbo-3.2.0.tar.gz
archive copy: sources-3/image-libs--libjpeg-turbo-3.2.0.tar.gz
Dependencies
Depends on: cmake, ninja, nasm, zlib, libspng.
Required by (111): abiword, ardour, blender, calibre, celestia, chafa, chromium, darktable, digikam, djvulibre, endless-sky, farbfeld, firefox-esr, fltk, fontforge, freerdp, gdal, gdk-pixbuf, gegl, ghostscript, gimp, glmark2, gmsh, gnuastro, gphoto2, graphicsmagick, graphviz, gst-plugins-base, gst-plugins-good, gthumb, gtk4, gutenprint, gwenview, handbrake, hplip, imagemagick, imv, inkscape, ioquake3, jasper, kdos-plasma-look, kodi, krita, lcms2, leptonica, libavif, libcupsfilters, libgd, libgeotiff, libgphoto2, libheif, libjxl, libraw, libreoffice, librewolf, libsixel, libtiff, libvips, libvncserver, libwebp, libyuv, luanti, minidlna, motif, mpv, mupdf, netpbm, netsurf, neverball, opencv, openimageio, openjdk, orcaslicer, pdf4qt, pdfium, podofo, poppler, prusaslicer, python3-pillow, qemu, qmapshack, qpdf, qt5-qtbase, qt6-qtbase, qt6-qtwebengine, qv4l2, R, rawtherapee, remmina, sane-airscan, sane-backends, scummvm, sdl2-image, sdl3-image, spice, spice-gtk, supertuxkart, swayimg, testdisk, thunderbird, timg, v4l-utils, vlc, vtk, warzone2100, webkitgtk, webkitgtk6, wlvncc, wxwidgets, xonotic, zbar.
Patches
build.sh applies these; kpkg applies nothing by itself.
config-spng-dependency.patch— makes the installedlibjpeg-turboConfig.cmakecreate thePkgConfig::spngtarget, throughfind_dependency(PkgConfig)andpkg_check_modules, when the library was built withWITH_SYSTEM_SPNG. The exported TurboJPEG targets namePkgConfig::spngin their link interface and upstream’s file never defines it, so a CMake consumer that links them stops with the target not found.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install libjpeg-turbo'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/image-libs/libjpeg-turbo.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/image-libs/libjpeg-turbo
echo '6f30092cef9fb839779646608f4ee14ae3cbac989c47fa05e841b0841f09878e libjpeg-turbo-3.2.0.tar.gz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/libjpeg-turbo
SRC=$SRC_ROOT/libjpeg-turbo-3.2.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf libjpeg-turbo-3.2.0.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
patch -p1 -i "$PORT_SRC/config-spng-dependency.patch"
cmake -S . -B build -G Ninja \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_INSTALL_LIBDIR=/usr/lib \
-DCMAKE_INSTALL_LIBEXECDIR=/usr/lib \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS_RELEASE="$CFLAGS -DNDEBUG" \
-DWITH_SYSTEM_SPNG=ON \
-DWITH_SYSTEM_ZLIB=ON \
-DWITH_TESTS=OFF \
-DWITH_JPEG8=ON \
-DWITH_SIMD=ON \
-DREQUIRE_SIMD=ON \
-DCMAKE_SKIP_INSTALL_RPATH=ON \
-Wno-dev
cmake --build build
DESTDIR=$PKG cmake --install build
The switches, and why each is set:
-DWITH_JPEG8=ON— Emulate the libjpeg v8 API and ABI. The library is installed aslibjpeg.so.8, and is not binary-compatible with the libjpeg v6b ABI (libjpeg.so.62) that is upstream’s default. Every program in the tree is linked against the v8 name, so changing this switch changes the soname and needs every dependent rebuilt.-DWITH_SIMD=ON— Build the SIMD extensions, whichnasmassembles for x86-64. This is upstream’s default, named in the recipe.-DREQUIRE_SIMD=ON— Stop the configure if the SIMD extensions cannot be built. Without it a missing or unusable assembler is only a warning, and the library ships with the plain C code paths alone;nasmis independsfor this reason.-DWITH_SYSTEM_SPNG=ON— Read and write PNG incjpeg,djpeg,tj3LoadImage()andtj3SaveImage()through the libspng port, instead of the copy of libspng in the source tree.-DWITH_SYSTEM_ZLIB=ON— Link the system zlib. The option exists only when the bundled libspng is used; with-DWITH_SYSTEM_SPNG=ONupstream already uses the system zlib, so this switch only states it.-DCMAKE_C_FLAGS_RELEASE="$CFLAGS -DNDEBUG"— Replace CMake’s Release flags,-O3 -DNDEBUG, with the tree’sCFLAGSand-DNDEBUG. CMake puts the Release flags afterCFLAGSon every compile, so its-O3would otherwise override the tree’s-O2.-DCMAKE_SKIP_INSTALL_RPATH=ON— Install the libraries and programs with no run path. Whenever shared libraries are built, upstream setsCMAKE_INSTALL_RPATHto the library directory, which here is/usr/lib, already the default search path, so the entry adds nothing and the package lint warns on it (see What the package lint refuses).-DWITH_TESTS=OFF— Build none of the regression-test programs; this is the project’s own name for the choice-DBUILD_TESTING=OFFmakes elsewhere.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/libjpeg-turbo, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf libjpeg-turbo-3.2.0-2.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/libjpeg-turbo, and runs the triggers its paths call for.
Contents
Installed programs: cjpeg, djpeg, jpegtran, rdjpgcom, tjbench, wrjpgcom.
Installed libraries: libjpeg.a, libjpeg.so, libturbojpeg.a, libturbojpeg.so.
Installed directories: /usr/lib/cmake/libjpeg-turbo, /usr/share/doc/libjpeg-turbo, /usr/share/licenses/libjpeg-turbo.
Short descriptions
cjpeg |
compress an image file to a JPEG file |
djpeg |
decompress a JPEG file to an image file |
jpegtran |
lossless transformation of JPEG files |
rdjpgcom |
display text comments from a JPEG file |
wrjpgcom |
insert text comments into a JPEG file |
libjpeg.pc |
A SIMD-accelerated JPEG codec that provides the libjpeg API |
libturbojpeg.pc |
A SIMD-accelerated JPEG codec that provides the TurboJPEG API |
Notes
The recipe leaves ENABLE_STATIC at its default, so libjpeg.a and libturbojpeg.a are installed beside the shared libraries, with the CMake package files under /usr/lib/cmake/libjpeg-turbo. libtiff finds the library through that CMake package, and falls back to the FindJPEG module in its own cmake/ directory only when the package is missing.