$ show Lymphatus/libcaesium
Libcaesium is a Rust library for lossy/lossless compression and conversion of JPEG, PNG, GIF, WebP, and TIFF images, with a C API for cross-language usage. It provides both file-based and in-memory compression, targeting specific output sizes, and preserving EXIF metadata or orientation. The architecture is modular, with format-specific compressors (jpeg.rs, png.rs, etc.) and shared utilities. The code is well-structured, tested across multiple platforms, and integrates advanced libraries like mozjpeg-sys, oxipng, gifski, and libwebp. It avoids framework boilerplate and demonstrates strong engineering practices, though some parts use unsafe Rust for direct JPEG manipulation.
The LLM identified 4 files worth highlighting for reuse:
Provides a generic function to resize image buffers with Lanczos3 filtering, including automatic dimension computation that maintains aspect ratio when only one of width/height is specified. Handles orientation-aware swapping of width/height for JPEG images. The function is standalone and could be extracted for any image processing project.
Encapsulates EXIF orientation extraction and modification in a reusable manner. Includes `get_orientation`, `build_orientation_exif`, `set_exif_orientation`, and helper functions to preserve rotation metadata across formats. These functions are self-contained (no internal coupling beyond bytes crate) and can be reused in other image libraries.
Defines a clean, type-safe parameter hierarchy (CSParameters with sub-structs for each format) with sensible defaults and validation enums (ChromaSubsampling, TiffCompression, TiffDeflateLevel). This pattern of nested parameter structs is reusable for any library that needs per-format configuration.
Implements cross-format image conversion in memory, handling decoding, orientation, color space conversion (e.g., RGBA to RGB for JPEG), and metadata injection via img-parts. The logic is isolated and could be adapted to support additional formats or different metadata handling.