sekrit-twc/zimg

Scaling, colorspace conversion, and dithering library

What it solves

Developers often need to resize images, convert between color spaces (like YCbCr and RGB), or change pixel bit depth. z.lib handles these basic operations with a simple API so you can convert between supported formats without deep knowledge of the internals. It avoids being a full color management system and is not meant for drastic contrast or gamut changes.

How it works

The library is split into three modules: colorspace, depth, and resize.

  • Colorspace supports SMPTE-C, Rec.709, and Rec.2020, including the non-traditional BT.2020 constant luminance YCbCr. It minimizes intermediate representation steps for common conversions.
  • Depth converts between BYTE, WORD, HALF, and FLOAT pixel formats, with both limited (16-235) and full-range (0-255) integer handling. It offers multiple dithering methods when going to integer formats.
  • Resize provides linear resamplers, including Bicubic and Lanczos, with support for up to 100x up/downsampling and various chroma siting conventions and interlaced content. Allocation, buffering, and I/O are separated from processing, and the library is designed from the ground up for thread safety.

Who it's for

This is for C++ developers building image or video pipelines on Windows or POSIX systems who need reliable, fast conversions between common formats. It's especially useful when performance matters, as benchmarks on Intel CPUs show it outpaces swscale for resizing and colorspace conversion. It is not intended for tasks like color grading or heavy gamut reduction.

Highlights

  • Simple API requiring minimal knowledge of the underlying formats
  • Correctness, flexibility, and thread-safety as explicit design priorities
  • Colorspace conversion between SMPTE-C, Rec.709, and Rec.2020, including BT.2020 constant luminance
  • Depth conversion for integer, half-float, and float formats with dithering
  • High-quality resize filters (Bicubic, Lanczos) and up to 100x ratios
  • Benchmarked faster than swscale on Intel hardware for common resizing and colorspace tasks
  • Separation of allocation, buffering, and I/O for easy adaptation

Related

  • Project
  • Project
  • Project
  • Project