17 releases (4 breaking)

0.5.2 Mar 22, 2018
0.5.1 Mar 4, 2018
0.4.4 Mar 4, 2018
0.4.3 Feb 17, 2018
0.1.1 Jan 6, 2018

#4 in Data formats

Download history 41/week @ 2018-05-27 96/week @ 2018-06-03 3/week @ 2018-06-10 72/week @ 2018-06-17 35/week @ 2018-06-24 138/week @ 2018-07-01 23/week @ 2018-07-08 14/week @ 2018-07-15 123/week @ 2018-07-22 43/week @ 2018-07-29 360/week @ 2018-08-05 401/week @ 2018-08-12 15/week @ 2018-08-19

177 downloads per month
Used in 4 crates (3 directly)

GPL-3.0 license

50KB
384 lines

blit

A Rust library for blitting 2D sprites

Build Status Cargo License: GPL-3.0 Downloads

Documentation

Usage

Add this to your Cargo.toml:

[dependencies]
blit = "0.5"

And this to your crate root:

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

extern crate image;

use blit::*;

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

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

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

// Blit directly to the buffer
let pos = (0, 0);
img_rgb.blit(&mut buffer, WIDTH, pos, Color::from_u32(MASK_COLOR));

// Blit by creating a special blitting buffer first, this has some initial
// overhead but is a lot faster after multiple calls
let blit_buffer = img_rgb.to_blit_buffer(Color::from_u32(MASK_COLOR));

let pos = (10, 10);
blit_buffer.blit(&mut buffer, WIDTH, pos);
let pos = (20, 20);
blit_buffer.blit(&mut buffer, WIDTH, pos);

// Save the blit buffer to a file
blit_buffer.save("smiley.blit");

Dependencies

~4MB
~81K SLoC