Expand description
§Blittle
blittle is a fast little blitter.
blittle blits surfaces onto each other.
A surface is a pixel buffer with some additional data such as its pixel type and dimensions.
use blittle::*;
// The size of the source image.
let size = Size::new(512, 512);
// Create a new surface.
// This surface has three channels (r, g, b) and 1 byte per channel.
let mut src = Rgb8Surface::new(size);
// Fill the surface.
src.fill([255, 0, 255]);
// Create a destination surface.
let mut dst = Rgb8Surface::new_filled(Size::new(1920, 1080), [100, 100, 50]);
// Set the position of src relative to dst.
src.set_position(PositionI::new(-50, 100), &dst).unwrap();
// Blit src onto dst.
src.blit(&mut dst).unwrap();The above example is very fast because there is no mask or blending involved.
§Blitting with a mask
A mask is a color. Pixels from the source surface that have the mask color don’t get copied onto the destination surface.
You can apply a mask color to a surface by using a MaskedSurface.
MaskedSurface.blit is usually slower than Surface.blit but it can be sped up by calling MaskedSurface.lock().
§Blending
You can blend the pixels of two surfaces together using a BlendableSurface.
BlendableSurface.blend is usually slower than Surface.blit but it can be sped up by calling BlendableSurface.lock().
§Converting surfaces
The PixelConverter trait can be used to convert one surface into another type of surface:
use blittle::{PixelConverter, Rgb8Surface, Rgba8Surface, Size};
let rgb = Rgb8Surface::new(Size::new(512, 512));
let rgba = Rgba8Surface::from(&rgb);§Feature Flags
bytesallows access to the underlying buffer of aSurfaceas bytespngadds thePngtrait, which can be used to read and write .png files. See:blittle::pngserdeallows some structs such asRectUandRectIto be serializablesoftbufferadds a new type of surface that can be created as a reference to asoftbuffer::Buffer. See:blittle::sbstd(default) allows std.
§no_std
If blittle is no_std, you’ll lose some functionality:
- No
Surfacetype aliases such asRgba8Surface - No implementations for converting one type of surface to another
- Can’t add the
pngorsoftbufferfeatures MaskedSurfaceandBlendableSurfacecan’t lock/unlock
§Benchmarks
Run cargo bench --all-features and find out.
Re-exports§
pub use softbuffer;softbuffer
Modules§
Structs§
- Blendable
Surface - A surface that allows you to blend pixels rather than copying them onto each other.
- Masked
Surface - A surface with a mask color. Pixels of the mask color will not blit to the destination.
- PositionI
- An
(x, y)pixel position. - PositionU
- An
(x, y)pixel position. - RectI
- A rectangle in which the
positioncan have negative values. - RectU
- A rectangle defined by a position and size.
- Size
- Rectangular bounds defined by a width and height.
- Surface
- A Surface is a pixel buffer, a size, and some underlying data describing how to blit it to a given destination Surface.
Enums§
Traits§
- Pixel
Converter - Convert from one surface’s pixel type to another surface’s pixel type.
Type Aliases§
- Blendable
Surface Vec std - A blendable surface backed by a vec.
- L8Surface
std - Grayscale.
- L32Surface
std - 32-bit grayscale.
- La8Surface
std - Grayscale + alpha.
- La32
Surface std - 32-bit grayscale + alpha.
- Rgb8
Surface std - Red, green, blue.
- Rgba8
Surface std - Red, green, blue, alpha.
- Rgba32
Surface std - 32-bit red, green, blue, alpha.