A Rust library for decoding and rendering animated WebP images using the nannou creative coding framework.
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.
- 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.
- Rust programming language.
- libwebp and libwebpdemux libraries installed on your system.
- pkg-config utility for discovering library paths and compilation flags.
Install libwebp
and pkg-config
using Homebrew.
brew install webp pkg-config
Install the required packages.
sudo apt-get update
sudo apt-get install libwebp-dev pkg-config
Install the dependencies.
sudo dnf install libwebp-devel pkgconf-pkg-config
Install the necessary packages.
sudo pacman -S libwebp pkgconf
Install the required packages using MSYS2.
-
Download and Install MSYS2
Visit the MSYS2 website and follow the installation instructions.
-
Update Package Database and Core Packages
Open the MSYS2 MinGW 64-bit terminal and run.
pacman -Syu
If prompted, close and reopen the terminal, then run the command again.
-
Install Dependencies
pacman -S mingw-w64-x86_64-libwebp mingw-w64-x86_64-pkg-config
Add the following to your Cargo.toml
.
[dependencies]
nannou = "0.19.0" # Or the latest version
nannou_webp_animation = "0.2.0"
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.
This project is licensed under the MIT License. See the LICENSE file for details.