blittle

Crates.ioblittle
lib.rsblittle
version0.4.3
created_at2025-10-15 18:24:45.49001+00
updated_at2026-01-15 14:37:45.07239+00
descriptionA fast little blitter
homepage
repositoryhttps://github.com/subalterngames/blittle
max_upload_size
id1884773
size61,353
Esther Alter (subalterngames)

documentation

README

Blittle

blittle is a fast little blitter.

use blittle::*;

/// Red, green, blue. One byte per channel.
let pixel_type = PixelType::Rgb8;

// The dimensions and byte data of the source image.
let src_w = 32;
let src_h = 17;
// A raw image bitmap.re
let src = vec![0u8; src_w * src_h * pixel_type.stride()];
let src_size = Size { w: src_w, h: src_h };

// The dimensions and byte data of the destination image.
let dst_w = 64;
let dst_h = 64;
// Another raw image bitmap.
let mut dst = vec![0u8; dst_w * dst_h * pixel_type.stride()];
// The top-left position of where `src` will appear on `dst`.
let dst_position = PositionI { x: 2, y: 12 };
let dst_size = Size { w: dst_w, h: dst_h };
let rect = ClippedRect::new(dst_position, dst_size, src_size).unwrap();

// Blit `src` onto `dst`.
blit(&src, &mut dst, &rect, &pixel_type);

No mask? No mask!

Most blit functions assume that you might want to apply a mask. A mask is typically a certain color. Pixels in the source image that have the mask color aren't blitted to the destination image.

blittle is fast because it doesn't apply a mask. Since blittle doesn't have to check each pixel's color, it can copy per-row, rather than per-pixel.

Clipping

By default, blittle won't check whether your source image exceeds the bounds of the destination image. This will cause your program to crash with a very opaque memory error.

To trim the source image's blittable region, call [clip].

Feature Flags

The overlay feature

Add the overlay feature to include functions for overlaying a source image onto a destination with alpha (transparency) value(s).

The overlaying functions are always slower than blittle::blit. blittle::blit copies lines of bytes, while overlaying involves per-pixel calculations.

The rayon feature

Add the rayon feature to enable multithreaded blitting:

blit_multi_threaded breaks the source and destination images into multiple chunks and then blits each chunk in parallel. The function signature is the same as that of [blit] except that there's an additional num_threads argument.

The serde feature

Add the serde feature to make PositionI, PositionU, and Size serializable.

Benchmarks

Run cargo bench --all-features and find out.

Commit count: 79

cargo fmt