blit

A Rust library for blitting 2D sprites

Build Status Cargo License: GPL-3.0 Downloads

Documentation

Usage

Add this to your Cargo.toml:

toml [dependencies] blit = "0.3"

And this to your crate root:

rust extern crate blit;

Run the example

On Linux you need the xorg-dev package as required by minifb. sudo apt install xorg-dev

cargo run --example smiley

This should produce the following window:

Example

Examples

```rust use blit::*;

const WIDTH: usize = 180; const HEIGHT: usize = 180; const MASK_COLOR: u32 = 0xFFFF00FF;

let mut buffer: Vec = vec![0xFFFFFFFF; WIDTH * HEIGHT];

let img = image::open("examples/smiley.png").unwrap(); let imgrgb = img.asrgb8().unwrap();

// Blit directly to the buffer let pos = (0, 0); imgrgb.blitwithmaskcolor(&mut buffer, (WIDTH, HEIGHT), pos, MASK_COLOR);

// Blit by creating a special blitting buffer first, this has some initial // overhead but is a lot faster after multiple calls let blitbuffer = imgrgb.asblitbuffer(MASK_COLOR);

let pos = (10, 10); blitbuffer.blit(&mut buffer, (WIDTH, HEIGHT), pos); let pos = (20, 20); blitbuffer.blit(&mut buffer, (WIDTH, HEIGHT), pos); ```