118.10. libimagequant-4.4.1
Palette quantisation that turns a 32-bit image into a small 8-bit PNG or GIF
| Version | 4.4.1, release 1 |
| Shelf | image-libs — Raster image formats, codecs, metadata, processing, barcodes, and terminal image output |
| Phase | 41_system (System), 615 of 1047 in build order |
| Licence | GPL-3.0-or-later |
| Homepage | https://pngquant.org/lib/ |
| Build time | 0.2 SBU |
| Installed size | 794.3 KiB in 6 files |
| Recipe | ports/core/image-libs/libimagequant/kpkgbuild |
About
libimagequant is the palette quantiser behind pngquant: it reduces a 24- or 32-bit image to at most 256 colours with alpha, for a small 8-bit PNG or GIF. It is written in Rust, and its C library, libimagequant.so with libimagequant.h and imagequant.pc, is what pngquant, libgd, libvips, Pillow and Tux Paint link.
Sources
libimagequant-4.4.1.tar.gz(86.8 KiB)
sha2562464a3e922b5a220b633d674062b82f0670114f8f3dd30d1935a621c95965f1b
upstream: https://github.com/ImageOptim/libimagequant/archive/refs/tags/4.4.1.tar.gz
archive copy: sources-3/image-libs--libimagequant-4.4.1.tar.gzlibimagequant-vendor-4.4.1.tar.xz(1.2 MiB)
sha256367c231c9583eacd02744be76ca17283026135381229a3a2197fc58e97945c06
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-3/image-libs--libimagequant-vendor-4.4.1.tar.xz
Dependencies
Required by (5): libgd, libvips, pngquant, python3-pillow, tuxpaint.
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 libimagequant'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/image-libs/libimagequant.
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/libimagequant
echo '2464a3e922b5a220b633d674062b82f0670114f8f3dd30d1935a621c95965f1b libimagequant-4.4.1.tar.gz' | sha256sum -c -
echo '367c231c9583eacd02744be76ca17283026135381229a3a2197fc58e97945c06 libimagequant-vendor-4.4.1.tar.xz' | 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/libimagequant
SRC=$SRC_ROOT/libimagequant-4.4.1
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf libimagequant-4.4.1.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:
tar xf $PORT_SRC/${name}-vendor-${version}.tar.xz
export CARGO_HOME="$SRC_ROOT/.cargo"
export RUSTFLAGS="-C target-feature=-crt-static"
export CARGO_NET_OFFLINE=true
cargo cinstall --release --frozen --offline \
--manifest-path imagequant-sys/Cargo.toml \
--no-default-features --features threads \
--library-type cdylib \
--prefix /usr --libdir /usr/lib --destdir $PKG
The switches, and why each is set:
cargo cinstall— Build and install the crate as a C library with cargo-c, which writes the shared library, the header and thepkg-configfile in the layout a C consumer expects.--prefix,--libdirand--destdirplace them as a configure script’s equivalents would.--manifest-path imagequant-sys/Cargo.toml— Build theimagequant-sysworkspace member, which holds the C API; the top of the tree is the Rust crate alone.--no-default-features— With--features threads, build with the multithreaded quantiser (rayon) and nothing else.threadsis what the default features amount to; naming it keeps the feature set in the recipe.--library-type cdylib— Build only the shared library; the crate also declares a static one.-C target-feature=-crt-static— Link against musl dynamically. Rust’s musl target links the C library statically by default, and acdylibcannot be built that way.
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/libimagequant, 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 libimagequant-4.4.1-1.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/libimagequant, and runs the triggers its paths call for.
Contents
Installed libraries: libimagequant.so.
Installed directories: /usr/share/licenses/libimagequant.
Short descriptions
imagequant.pc |
Convert 24/32-bit images to 8-bit palette with alpha channel. |
Notes
The Rust crates come from the vendor bundle, libimagequant-vendor-<version>.tar.xz, which ports/fetch writes with cargo vendor and pins with its own sha256 = line (see Vendoring). build.sh unpacks it at the top of the tree and runs cargo from there: cargo finds the bundle’s configuration by walking up from the current directory, so it must stand where the bundle was unpacked and reach the C crate through --manifest-path, or every crate resolves as missing (see Where the bundle goes).
The C library carries its own version, [package.metadata.capi.library] in imagequant-sys/Cargo.toml, and its soname comes from that, not from the release number: cargo-c names a 0.x library by its major and minor numbers (libimagequant.so.0.<minor>), so a change of that minor number needs every consumer rebuilt.