27 releases

✓ Uses Rust 2018 edition

0.5.12 Mar 8, 2020
0.5.9 Feb 12, 2020
0.5.7 Dec 30, 2019
0.5.6 Jul 28, 2019
0.5.2 Mar 22, 2018

#5 in Data formats

Download history 6/week @ 2019-12-17 29/week @ 2019-12-24 152/week @ 2019-12-31 74/week @ 2020-01-07 63/week @ 2020-01-14 10/week @ 2020-01-21 12/week @ 2020-01-28 230/week @ 2020-02-04 237/week @ 2020-02-11 397/week @ 2020-02-18 107/week @ 2020-02-25 279/week @ 2020-03-03 174/week @ 2020-03-10 197/week @ 2020-03-17 198/week @ 2020-03-24 148/week @ 2020-03-31

751 downloads per month
Used in 7 crates (5 directly)

GPL-3.0 license

61KB
496 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

~4.5MB
~96K SLoC