{"id":50299052,"url":"https://github.com/yogthos/libwce","last_synced_at":"2026-05-28T11:01:30.009Z","repository":{"id":359699024,"uuid":"1247144706","full_name":"yogthos/libwce","owner":"yogthos","description":"A minimal, zero-dependency C99 library for bit-plane count entropy coding","archived":false,"fork":false,"pushed_at":"2026-05-23T03:21:32.000Z","size":227,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-23T03:24:03.673Z","etag":null,"topics":["bit-plane-coding","codec","compression","entropy-coding","haar-wavelet","haar-wavelet-tranforms","image-compression","wavelet","wavelet-transform"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yogthos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-23T00:32:40.000Z","updated_at":"2026-05-23T03:21:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/yogthos/libwce","commit_stats":null,"previous_names":["yogthos/libwce"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/yogthos/libwce","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yogthos%2Flibwce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yogthos%2Flibwce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yogthos%2Flibwce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yogthos%2Flibwce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yogthos","download_url":"https://codeload.github.com/yogthos/libwce/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yogthos%2Flibwce/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33605379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-28T02:00:06.440Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bit-plane-coding","codec","compression","entropy-coding","haar-wavelet","haar-wavelet-tranforms","image-compression","wavelet","wavelet-transform"],"created_at":"2026-05-28T11:01:27.230Z","updated_at":"2026-05-28T11:01:30.003Z","avatar_url":"https://github.com/yogthos.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libwce — Wavelet Coefficient Entropy Codec\n\nA minimal, zero-dependency Rust library for low-latency entropy coding of\nwavelet coefficient bands. Patent-clean alternative to JPEG XS-style\nBPC entropy layers.\n\n```rust\nuse wce::*;\n\nlet mut coeffs = vec![0i32; 2048];  // your wavelet sub-band\nlet scale = estimate_laplacian_scale(\u0026coeffs);\n\nlet mut buf = vec![0u8; 8192];\nlet out_len = encode(\u0026coeffs, /*lossy_bits=*/3, \u0026mut buf).unwrap();\n// … transmit `\u0026buf[..out_len]` and `scale` …\n\nlet mut decoded = vec![0i32; 2048];\nlet lossy_bits = decode(\u0026buf[..out_len], \u0026mut decoded).unwrap();\ndequantize_optimal(\u0026mut decoded, lossy_bits, scale);\n```\n\n## What it does\n\n`encode` turns an `\u0026[i32]` of wavelet coefficients into a self-contained\nbitstream. `decode` inverts it, returning truncated grid values.\n`dequantize_optimal` applies Laplacian Lloyd-Max reconstruction for\nminimum coefficient-domain MSE.\n\nThe encoder picks between 4 mode combinations on each band:\n\n|  | sparse_flag=off | sparse_flag=on (1 bit/8-group block) |\n|---|---|---|\n| RUNNING predictor (DPCM + zigzag) | smooth bpc sequences | smooth + sparse-block shortcut |\n| ZERO predictor (`bpc − lossy`, unsigned) | sparse bands with occasional spikes | very sparse bands |\n\n…across 7 Rice-k parameter values, via a single-pass histogram-based\ncost picker. The chosen mode is encoded in the 12-byte header.\n\n## Patent posture\n\nThe codec is designed to avoid the JPEG XS patent pool (Vectis /\nintoPIX / Fraunhofer IIS) and all ANS-family entropy coders (notably\nMicrosoft US 11,234,023 B2). See [`PATENTS.md`](PATENTS.md) for the\nfull rationale.\n\n## Performance\n\nEnd-to-end on the demo Cthulhu PGM through a 1-level Haar DWT at four\nquality presets:\n\n| Preset | bytes_out | ratio | PSNR |\n|---|---|---|---|\n| near-lossless | 146 KB | 1.52× | 49.06 dB |\n| balanced      |  92 KB | 2.40× | 37.54 dB |\n| aggressive    |  49 KB | 4.48× | 28.79 dB |\n| very lossy    |  21 KB | 10.11× | 21.62 dB |\n\nSingle-thread throughput on a 24-cell synthetic Laplacian corpus\n(scales 2..128 × band sizes 2K and 32K × lossy_bits 0/2/4/6):\nencode 350–3700 MB/s, decode 380–5600 MB/s.\n\n## API overview\n\n| Category | Functions |\n|---|---|\n| **Top-level codec** | `encode`, `decode`, `encode_with_options` |\n| **Quantization** | `quantize` |\n| **Reconstruction** | `dequantize_optimal`, `estimate_laplacian_scale` |\n| **Bit I/O** | `BitReader`, `BitWriter` — `read_bits`, `write_bits`, `flush`, `byte_align`, etc. |\n| **Rice / zigzag** | `write_rice`, `read_rice`, `zigzag_encode`, `zigzag_decode` |\n| **BPC primitives** | `compute_bpcs`, `pick_rice_k_for_bpcs`, `encode_bpcs_dpcm`, `decode_bpcs_dpcm` |\n| **Coeff pack** | `pack_coeffs`, `unpack_coeffs` |\n\nMost callers want only `encode` / `decode` / `dequantize_optimal`. The\nother entry points are exposed for testing and integration into custom\ncodecs.\n\nGrid-truncated values (skip reconstruction): just don't call\n`dequantize_optimal` — the decoder leaves coefficients on the\nquantization grid.\n\n## Building\n\n```sh\ncargo test                    # run the unit-test suite (81 tests)\ncargo build --examples        # build the demo + bench binaries\ncargo run --example mode_shootout\ncargo run --release --example image_compress -- examples/Cthulhu.pgm examples/Cthulhu\ncargo run --release --example bench        # benchmark harness, CSV to stdout\n```\n\n## Demos\n\nUnder `examples/`:\n\n- **`image_compress`** — reads `demo/Cthulhu.pgm`, runs a 1-level Haar\n  DWT, encodes each sub-band, decodes back with optimal reconstruction,\n  writes reconstructed PGMs and `.wce` container files at four quality\n  presets. Prints PSNR and ratio.\n- **`mode_shootout`** — enumerates the 4 (predictor × sparse-flag) mode\n  combos via `encode_with_options`, then shows the auto-pick outcome\n  alongside. Demonstrates mode selection.\n- **`stream_surgery`** — corruption-resilience demo. Bit-flips, byte\n  scrambles, prefix truncation, and crafted bad-header attacks against\n  `decode`. Every call must return.\n- **`bench`** — sweeps encode/decode over synthetic Laplacian corpora\n  across lossy_bits values, measures throughput in MB/s, emits CSV.\n\n## Design notes\n\n- **Zero dependencies.** Only the Rust standard library. No external\n  crates.\n- **No heap allocation in the hot path.** The library allocates a small\n  BPC buffer on first use; all encode/decode buffers are caller-owned.\n  BitReader/BitWriter borrow slices — no ownership transfer.\n- **Non-owning bit readers/writers.** Hold `\u0026[u8]` / `\u0026mut [u8]` slices\n  into caller-provided buffers. Truncated reads zero-pad.\n  `RICE_MAX_QUOTIENT` caps adversarial unary runs.\n- **Self-contained per-band bitstream.** 12-byte header + payload, with\n  magic `\"WCE\\0\"`, format version, lossy_bits, rice_k + mode bits, and\n  initial-prev seed. Each band is independently decodable.\n- **Thread-safe.** All functions operate only on caller-supplied state.\n  No global mutation. `Send` + `Sync` compatible.\n\n## License\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyogthos%2Flibwce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyogthos%2Flibwce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyogthos%2Flibwce/lists"}