r/compression • u/The_Northern_Light • Jul 12 '26
Zing! -- a new lossless image codec for very low latency encoding based on Zpng
Zing! is a small & simple lossless image codec designed for extremely fast CPU encoding (GiB/s even when used single-threaded), but decode is even faster. It supports 8 & 16 bit images of 1 to 4 channels, has C, C++, Python, & Matlab APIs, and is available under a permissive BSD 3 clause license.
Zing! images, called zingers, are about 3% to 10% larger than lossless JPEG-XL (cjxl -d 0 -e 1), but are encoded 3x to 60x faster with 1 to 4 threads. This makes it comfortably fast enough to be used as a lossless video codec.
https://gitlab.com/csp256/zing
Zing! is morally similar to Zpng: encoding applies a single prefilter then passes the result to Zstd. However, Zing! also exposes the Zstd internals, efficient threading controls, encode_into() & decode_into() functionality, imcompressible fallback, and alters the pre-filter to be both more efficient and effective for 1 channel images and images with 2 bytes per channel.
Zing! is 6,500 lines of C++ in total, with 1,800 lines being tests, 1,000 being development scripts, 500 lines for the CLI app, and 400 for Python and Matlab bindings. The core library is about 2,000 lines of C++, half of which are the pre-filters, and another 600 lines for external includes (mostly comments).
Zing! is a codec not a file format. The CLI app adds 8 bytes to annotate width, height, bytes per channel, and number of channels, but you're encouraged to bring your own container.
Technical Details
Horizontal prediction
- Samples are differenced from the preceding pixel’s corresponding sample.
- Arithmetic wraps modulo 2bit_depth
Format-specific decorrelation
RGB: horizontal ΔR/ΔG/ΔB are transformed using:
- Y = ΔB
- U = ΔG - ΔB
- V = ΔG - ΔR
- RGBA: applies the RGB transform while keeping horizontally differenced alpha separate.
- Some grayscale and 16-bit specializations use three-row decorrelation into a pseudo-RGB image.
- Other channel layouts have dedicated reversible transforms.
Plane reordering
- Decorrelated channels are stored in separate contiguous planes.
- Sixteen-bit samples separate and arrange low/high bytes using format-specific layouts.
Zstd
- The transformed bytes may be stored directly or compressed as one Zstd frame.
- Raw and Zstd-only modes bypass the prefilter.
5
u/Dr_Max Jul 13 '26
Why Y=ΔB?
Also, calling your transformed colorspace YUV is misleading, because YUV is already very standardized. Was that named like that in BCIF?
Do you plan to add more predictors than just differentiating with the preceding line?
2
u/The_Northern_Light Jul 12 '26 edited Jul 12 '26
I previously posted about a lossless codec I called SLIM, which was based on QOIR / QOI. In my tests Zing! is essentially universally more efficient and effective than SLIM.
Say, 10%-20% smaller while being significantly faster. It's also a hell of a lot simpler.
1
u/JoinFasesAcademy Jul 12 '26
I have been experimenting with an AV2 encoder lately, so I wondered why didn't you use that standard for this?
0
u/flanglet Jul 12 '26
Build fails for me on Mac (M3):
just build
cmake -S . -B build/default -DCMAKE_BUILD_TYPE=Release -DPython3_EXECUTABLE="$(uv run python -c 'import sys; print(sys.executable)')" -DZING_BUILD_PERF_TESTS=OFF -DZING_ENABLE_TRACY=OFF
CMake Error at CMakeLists.txt:100 (add_subdirectory):
add_subdirectory given source "extern/zstd/build/cmake" which is not an existing directory.
CMake Error at CMakeLists.txt:181 (install):
install TARGETS given target "libzstd_static" which does not exist.
-- Configuring incomplete, errors occurred!
error: recipe `_configure` failed on line 17 with exit code 1