Expand description
BIC: an experimental lossless and near-lossless image codec for images with large solid areas, such as screenshots, user interfaces, diagrams, charts, icons and pixel art. On those it produces smaller files than optimized PNG. On photographs it offers little or no advantage: a JPEG source is stored unchanged, and lossless photographs gain little.
BIC files are optimized for size first and decoding speed second. Each
image is coded with a palette or with a subtract-green transform, then
row prediction, run-length blocks and Zstandard. The encoder tries every
combination and keeps the smallest. When a source file (PNG, JPEG, WebP or
HEIF) is smaller than that, it is stored unchanged. The wire format is
specified in FORMAT.md in the repository.
§Encoding pixels
use bic::{decode_rgba, encode_rgba, EncodeOptions};
// A 2×2 RGBA image.
let rgba = [255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255, 255, 255, 255];
let file = encode_rgba(2, 2, &rgba, EncodeOptions::default())?;
let (width, height, pixels) = decode_rgba(&file)?;
assert_eq!((width, height, pixels.as_slice()), (2, 2, &rgba[..]));§Encoding a file
encode_file reads a PNG, JPEG, WebP or HEIF file (and BMP, GIF, TIFF or
QOI with the cli feature), applies its orientation, keeps its ICC
profile, and stores the original unchanged when that is smaller:
let original = std::fs::read("photo.jpg")?;
let file = bic::encode_file(&original, bic::EncodeOptions::default())?;
std::fs::write("photo.bic", file)?;§Untrusted input
Decoding checks the declared size against DecodeLimits before
allocating. Use decode_rgba_with_limits or decode_with_metadata
with tighter limits for files from untrusted sources.
§Features
cli(default): thebicandbic-viewprograms and their dependencies. Library users can disable it withdefault-features = false.
Structs§
- Decode
Limits - Resource caps applied before the decoder allocates anything.
- Decoded
- A decoded image.
- Encode
Options - Encoder settings. The defaults give the smallest lossless file.
- Metadata
- Metadata stored alongside the pixels.
- Source
- A decoded source image.
Enums§
- Embeddable
Format - Formats a BIC file may store unchanged.
- Storage
- How a BIC file stores its image.
Functions§
- decode_
rgba - Decodes a BIC file to
(width, height, rgba)with the default limits. - decode_
rgba_ with_ limits - Decodes a BIC file to
(width, height, rgba), refusing files that exceedlimitsbefore allocating. - decode_
with_ metadata - Decodes pixels and metadata.
- embeddable_
format - Identifies an embeddable format from the file’s signature.
- encode_
file - Encodes an image file (any format
read_sourcereads). SeeEncodeOptions::keep_original. - encode_
rgba - Encodes 8-bit RGBA pixels (row-major,
width × height × 4bytes). - encode_
rgba_ with_ metadata - Like
encode_rgba, also storingmetadata(such as an ICC profile). - encode_
source - Encodes a source already read from
originalwithread_source. - read_
source - Decodes an image file. Sizes are checked against
limitsbefore the pixels are decoded. - storage
- How
filestores its image, from the header alone.