29 releases

0.6.1 Feb 26, 2023
0.5.12 Mar 8, 2020
0.5.7 Dec 30, 2019
0.5.6 Jul 28, 2019
0.5.2 Mar 22, 2018

#9 in Data formats

Download history 26/week @ 2022-11-27 39/week @ 2022-12-04 53/week @ 2022-12-11 76/week @ 2022-12-18 34/week @ 2022-12-25 22/week @ 2023-01-01 42/week @ 2023-01-08 18/week @ 2023-01-15 56/week @ 2023-01-22 69/week @ 2023-01-29 104/week @ 2023-02-05 116/week @ 2023-02-12 160/week @ 2023-02-19 79/week @ 2023-02-26 62/week @ 2023-03-05 42/week @ 2023-03-12

385 downloads per month
Used in 8 crates (5 directly)

GPL-3.0 license

60KB
521 lines

blit

A Rust library for blitting 2D sprites

CI Cargo License: GPL-3.0 Downloads

Documentation

Usage

Add this to your Cargo.toml:

[dependencies]
blit = "0.6"

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

~14MB
~182K SLoC