3 unstable releases
0.2.1 | Nov 15, 2024 |
---|---|
0.2.0 | Nov 14, 2024 |
0.1.0 | Nov 14, 2024 |
#57 in Multimedia
319 downloads per month
29KB
296 lines
nannou_webp_animation
A Rust library for decoding and rendering animated WebP images using the nannou creative coding framework.
Overview
nannou_webp_animation
allows you to load, decode, and display animated WebP images within your nannou applications. It handles frame decoding, animation playback, and integrates seamlessly with nannou's rendering capabilities.
Features
- Decode animated WebP files and extract frames.
- Handle frame positioning, blending, and disposal methods for accurate rendering.
- Control animation playback (play, pause, loop).
- Easily integrate with nannou's
App
andDraw
APIs.
Installation
Prerequisites
- Rust programming language.
- libwebp and libwebpdemux libraries installed on your system.
- pkg-config utility for discovering library paths and compilation flags.
Installing Dependencies
macOS
Install libwebp
and pkg-config
using Homebrew:
brew install webp pkg-config
Ubuntu/Debian
Install the required packages:
sudo apt-get update
sudo apt-get install libwebp-dev pkg-config
Fedora
Install the dependencies:
sudo dnf install libwebp-devel pkgconf-pkg-config
Arch Linux
Install the necessary packages:
sudo pacman -S libwebp pkgconf
Adding to Your Project
Add the following to your Cargo.toml
:
[dependencies]
nannou = "0.19.0" # Or the latest version
libc = "0.2.162"
Clone this repository and include it as a local dependency if needed.
Usage
Loading and Displaying an Animated WebP
Here's a basic example of how to use nannou_webp_animation
in your application:
use nannou::prelude::*;
use nannou_webp_animation::WebpAnimation;
struct Model {
animation: WebpAnimation,
}
fn model(app: &App) -> Model {
// Create a new window
app.new_window().view(view).build().unwrap();
// Load the WEBP animation
let assets = app.assets_path().expect("Failed to find assets directory");
// Place 'animation.webp' in the 'assets' directory
let webp_path = assets.join("animation.webp");
// Initialize the animation
let animation =
WebpAnimation::from_file(&webp_path, app).expect("Failed to load WEBP animation");
Model { animation }
}
fn update(_app: &App, model: &mut Model, _update: Update) {
// Update the animation
model.animation.update();
}
fn view(app: &App, model: &Model, frame: Frame) {
// Clear the frame
frame.clear(BLACK);
let win = app.window_rect();
// Define the rectangle where the animation will be drawn
let r = Rect::from_w_h(
model.animation.width() as f32,
model.animation.height() as f32,
)
.top_left_of(win);
let draw = app.draw();
draw.texture(model.animation.texture())
.xy(r.xy())
.wh(r.wh());
draw.to_frame(app, &frame).unwrap();
}
fn main() {
nannou::app(model).update(update).run();
}
Place your animated WebP file named animation.webp
inside an assets
directory at the root of your project.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Dependencies
~21–56MB
~1M SLoC