bc_crunch

January 30, 2026 · View on GitHub

C Standard Build Status

bc_crunch is a tiny, dependency-free C99 library for lossless compression of GPU-compressed texture blocks BC1, BC4, BC3, and BC5.

  • ~1000 LOC total (single-file encoder/decoder, no build system tricks)
  • No malloc, no external libs
  • Deterministic, bit-exact reconstruction, fully tested with bytes-for-bytes comparison
  • Focused on production textures: albedo, masks, normals, heightmaps, etc.
  • GPU-ready output: decompressed blocks are written in standard BC1/BC4/BC3/BC5 format, ready to be uploaded directly to GPU memory (or directly written in shared memory)
  • No extra memory for decompression: only the encoder needs a temporary buffer; decoding writes straight to the output buffer.
  • Achieves a higher average compression ratio than zlib’s maximum-compression setting

This is not another general-purpose compressor. bc_crunch is specialized for already-compressed GPU formats — it exploits the internal structure of BC1/BC4 blocks, spatial patterns, endpoint deltas, bitfield indices to achieve significant size reductions with very low CPU cost.

Check out the technical documentation for more.


Benchmarks

Compression ratio naturally depends on the input content. Repetitive patterns, smooth gradients, and large uniform regions compress very well, while randomness or high-frequency noise significantly reduces efficiency (e.g., dirt textures are typically very noisy).

If you're looking for a better decrunch speed (144MB/s) for a small ratio cost (still 1.52:1) have a look at the huffman branch

BC1 benchmarks

bc_crunch average compression ratio: 1.593820
zlib (best compression) ratio: 1.436144

CategorySamplesAverage bc_crunch RatioAverage zlib Ratio
kodim241.54341.2958
Wood201.70681.3712
Metal201.70121.5511
Brick201.68451.4616
Elements201.55401.3340
Stone201.44691.3061
Tile201.44221.2766
Plaster201.39341.3231
Dirt201.35351.2797
pk02_floor132.11211.9542
SW_Tree72.10642.4498
blaztree61.88562.0893
pk02_trim51.82291.8290
pkf_concrete41.41971.3413
rock41.40031.1317

BC1 textures samples

BC4 benchmarks

bc_crunch average compression ratio: 1.345416
zlib (best compression) ratio: 1.104125

CategorySamplesAverage bc_crunch RatioAverage zlib Ratio
grey_roof_tiles21.46231.1907
patterned_cobblestone21.25251.0674
red_brick21.32481.0842
rough_wood21.30591.0742

BC4 textures samples

BC5 benchmarks

Average compression ratio : 1.200537

TextureWidthHeightBC5 Size (bytes)Crunched Size (bytes)Compression Ratio
grey_roof_tiles_02_nor_dx_1k.png102410241,048,576831,2331.288
patterned_cobblestone_nor_dx_1k.png102410241,048,576915,3871.157
red_brick_nor_dx_1k.png102410241,048,576877,9931.207
rough_wood_nor_dx_1k.png102410241,048,576914,3561.148

BC5 textures samples

Performance

Using a precomputed decoder table, decrunching is now significantly faster—up to ~1.5× speedup. Some parts of the cruncher have been optimized using NEON/SSE3 instructions.

Current performance on an M1 Pro MacBook Pro:

Crunch 100× 1024×1024 texture: 2.26 s → 22.11 MB/s
Decrunch 100× 1024×1024 texture: 1.38 s → 36.02 MB/s

Using the macro BC_CRUNCH_USE_VECTOR_QUANTIZATION slows down the compression ~ 11.5 MB/s

benchmark.c


Technical details

BC1

  • Zigzag block traversal
  • Endpoint deltas using left/up predictors
  • Top-table of the 256 most frequent index bitfields (prepass histogram)
  • Nearest-match selection via popcount distance
  • Delta-encoded index patches (no raw fallback)
  • Inter-Channel differential coding

BC4

  • Cyclic wrapped endpoint deltas (mod 256) using left/up predictors
  • 256-entry sliding dictionary
  • Move-to-front heuristic when hit
  • Nearest-match selection via popcount distance
  • Block zigzag traversal with xor-delta encoding for index fallback

Composite Formats

  • BC3 is just (BC1 + BC4) — no extra logic
  • BC5 is a dual independent BC4 channels

How to build tests

  • open a terminal in the folder
  • mkdir build
  • cd build
  • cmake -DCMAKE_BUILD_TYPE=Release ..
  • cmake --build .
  • ./test
  • ./benchmark

More tests will be added soon.

FAQ

How can I compress a texture with all mipmaps?

Right now you need to call bc_crunch separately for each mip level. I may add a helper later, but I want to keep the encoder simple and stateless, without any mip-level awareness or cross-mip data.

Is there a plan to improve performance or compression ratio?

Short answer: no. This library was intended as a lightweight testbed for a few ideas, not a state-of-the-art compressor. That said, if you want to experiment with improvements, here are some directions:

  • Replace the adaptive range encoder with a static one. This requires gathering statistics in a first pass or defining a generic static model.
  • Switch to a cheaper entropy coder (FSE, rANS, Huffman).
  • Decompress multiple stream in parallel (multiple texture ou mipmaps).
  • For better compression ratio, collecting more data in a first pass could allow a stronger model. Also, BC4 currently has no histogram / first-pass analysis, so there is clear room for improvement there.