nannou_webp_animation

Crates.ionannou_webp_animation
lib.rsnannou_webp_animation
version
sourcesrc
created_at2024-11-14 19:32:13.117458
updated_at2024-11-15 15:16:31.361602
descriptionA Rust library for decoding and rendering animated WebP images using the nannou creative coding framework.
homepagehttps://github.com/haradama/nannou_webp_animation
repositoryhttps://github.com/haradama/nannou_webp_animation
max_upload_size
id1448242
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
haradama (haradama)

documentation

https://docs.rs/nannou_webp_animation/

README

nannou_webp_animation

github crates.io docs.rs build status

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 and Draw 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.

Commit count: 14

cargo fmt