Giter Club home page Giter Club logo

blit's Introduction

blit

Build Status Crates.io Documentation License: GPL-3.0 Downloads

Draw sprites quickly using a masking color or an alpha treshold.

This crate works with RGBA u32 buffers. The alpha channel can only be read with a singular treshold, converting it to a binary transparent or opaque color. The reason this limitation is in place is that it allows efficient rendering optimizations.

For ergonomic use of this crate without needing to type convert everything most functions accepting numbers are generic with the number types being [num_traits::ToPrimitive], this might seem confusing but any number can be passed to these functions immediately.

When using this crate the most important function to know about is [Blit::blit], which is implemented for [BlitBuffer].

Example

use blit::{Blit, ToBlitBuffer, BlitOptions, geom::Size};

const CANVAS_SIZE: Size = Size { width: 180, height: 180 };
const MASK_COLOR: u32 = 0xFF_00_FF;
// Create a buffer in which we'll draw our image
let mut canvas: Vec<u32> = vec![0xFF_FF_FF_FF; CANVAS_SIZE.pixels()];

// Load the image from disk using the `image` crate
let img = image::open("examples/smiley_rgb.png").unwrap().into_rgb8();

// Blit by creating a special blitting buffer first where the MASK_COLOR will be the color that will be made transparent
let blit_buffer = img.to_blit_buffer_with_mask_color(MASK_COLOR);

// Draw the image 2 times to the buffer
blit_buffer.blit(&mut canvas, CANVAS_SIZE, &BlitOptions::new_position(10, 10));
blit_buffer.blit(&mut canvas, CANVAS_SIZE, &BlitOptions::new_position(20, 20));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.