Skip to main content

Crate wml2

Crate wml2 

Source
Expand description

Multi-format image decoding and encoding for RGBA buffers.

wml2 exposes a callback-based decoding API in draw and built-in buffer-backed helpers via draw::ImageBuffer. The crate can decode still images and animations into RGBA buffers, preserve metadata, and encode BMP, GIF, JPEG, PNG/APNG, TIFF, and WebP output.

§Example

use wml2::draw::*;
use wml2::metadata::DataMap;
use std::error::Error;
use std::env;

pub fn main()-> Result<(),Box<dyn Error>> {
    let args: Vec<String> = env::args().collect();
    if args.len() < 2 {
        println!("usage: metadata <inputfilename>");
        return Ok(())
    }

    let filename = &args[1];
    let mut image = image_from_file(filename.to_string())?;
    let metadata = image.metadata()?;
    if let Some(metadata) = metadata {
        for (key,value) in metadata {
            match value {
                DataMap::None => {
                    println!("{}",key);
                },
                DataMap::Raw(value) => {
                    println!("{}: {}bytes",key,value.len());
                },
                DataMap::Ascii(string) => {
                    println!("{}: {}",key,string);
                },
                DataMap::Exif(value) => {
                    println!("=============== EXIF START ==============");
                    let string = value.to_string();
                    println!("{}", string);
                    println!("================ EXIF END ===============");
                },
                DataMap::ICCProfile(data) => {
                    println!("{}: {}bytes",key,data.len());
                },
                _ => {
                    println!("{}: {:?}",key,value);
                }
            }
        }        
    }
    Ok(())
}

Modules§

bmp
BMP format support.
color
RGB and RGBA color primitives used across decoders and encoders.
decoder
Shared low-level decoder utilities.
draw
Callback-based image I/O primitives and the default RGBA image buffer.
encoder
Shared low-level encoder utilities.
error
Error types returned by decoders, encoders, and helpers.
gif
GIF format support.
ico
ICO decoder implementation.
jpeg
JPEG format support.
mag
MAG format support.
maki
MAKI format support.
metadata
Metadata value types shared by image decoders and encoders.
pcd
Photo CD format support.
pi
PI format support.
pic
PIC format support.
png
PNG and APNG format support.
tiff
TIFF format support, including EXIF-oriented metadata parsing.
util
Format detection helpers and shared image format identifiers.
vsp
VSP format support.
warning
Warning aggregation traits and container types.
webp
WebP support backed by the standalone webp-rust codec crate.

Functions§

get_can_decode
get_can_decode get WML2 crate decoder header check
get_decoder_extentions
get_decoder_extentions get extentions of WML2’s decoders
get_encode_extentions
get_encode_extentions get extentions of WML2’s encoders
get_version
get_version get WML2 crate version