[go: up one dir, main page]

Crate blittle

Crate blittle 

Source
Expand description

§Blittle

blittle is a fast little blitter.

use blittle::{*, stride::RGB};

// 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 * RGB];
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 * RGB];
// 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, RGB);

§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.

Modules§

overlayoverlay
This module contains functions for overlaying a source image onto destination image using alpha (transparency) value(s).
stride
Stride values for various types of pixels.

Structs§

ClippedRect
The original destination position and source size, and the position and size used for blitting.
PositionI
A signed (x, y) pixel position.
PositionU
An unsigned (x, y) pixel position.
Size
Rectangular bounds defined by a width and height.

Functions§

blit
Blit src onto dst.
blit_multi_threadedrayon
Blit using multiple threads by dividing src and dst into chunks and blitting each in parallel.
fill
Fill buffer with color.
get_index
Converts a position, width, and stride to an index in a 1D byte slice.
max_num_threads
Returns the maximum number of threads that Rayon supports in a single thread pool.