All Projects → kornelski → Lodepng Rust

kornelski / Lodepng Rust

Licence: zlib
All-in-one PNG image encoder/decoder in pure Rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Lodepng Rust

Rust Rocksdb
rust wrapper for rocksdb
Stars: ✭ 815 (+944.87%)
Mutual labels:  rust-bindings
Isparta
APNG、WebP converter
Stars: ✭ 942 (+1107.69%)
Mutual labels:  png
H2d2 Shopicons
Essentials E-Commerce icon pack for free.
Stars: ✭ 67 (-14.1%)
Mutual labels:  png
Is Animated
Checks if image is animated 🎞
Stars: ✭ 17 (-78.21%)
Mutual labels:  png
Mapbox Gl Print Export For Port
Print/Export for Mapbox GL
Stars: ✭ 14 (-82.05%)
Mutual labels:  png
Chunky png
Read/write access to PNG images in pure Ruby.
Stars: ✭ 970 (+1143.59%)
Mutual labels:  png
Scrimage
Java, Scala and Kotlin image processing library
Stars: ✭ 792 (+915.38%)
Mutual labels:  png
Gutenberg Parser Rs
An experimental Rust parser for WordPress Gutenberg post format
Stars: ✭ 76 (-2.56%)
Mutual labels:  rust-bindings
Bsnes Mt
bsnes-based SNES emulator featuring pixel-perfect integer scaling, PNG screenshots, built-in hotkeys, translations, bug fixes, and more.
Stars: ✭ 22 (-71.79%)
Mutual labels:  png
Optimise Images
Batch image resizer, optimiser and profiler using ImageMagick convert, OptiPNG, JpegOptim and optional ZopfliPNG, Guetzli and MozJPEG.
Stars: ✭ 64 (-17.95%)
Mutual labels:  png
Stegify
🔍 Go tool for LSB steganography, capable of hiding any file within an image.
Stars: ✭ 927 (+1088.46%)
Mutual labels:  png
Repng
React component to PNG converter
Stars: ✭ 856 (+997.44%)
Mutual labels:  png
Format parser
file metadata parsing, done cheap
Stars: ✭ 46 (-41.03%)
Mutual labels:  png
Stripe Rs
Moved to https://github.com/wyyerd/stripe-rs.
Stars: ✭ 16 (-79.49%)
Mutual labels:  rust-bindings
Gh Card
GitHub Repository Card for Any Web Site
Stars: ✭ 1,154 (+1379.49%)
Mutual labels:  png
Ritual
Use C++ libraries from Rust
Stars: ✭ 792 (+915.38%)
Mutual labels:  rust-bindings
Ruby Gem Downloads Badge
Clean and simple gem downloads count badge, courtesy of http://shields.io/. You can checkout the application directly at the following URL:
Stars: ✭ 29 (-62.82%)
Mutual labels:  png
Rusted Switch
Nintendo Switch Homebrew with Rust 🦀
Stars: ✭ 75 (-3.85%)
Mutual labels:  rust-bindings
Imageviewer
HDR, PFM, DDS, KTX, EXR, PNG, JPG, BMP image viewer and manipulator
Stars: ✭ 71 (-8.97%)
Mutual labels:  png
Tiny Site
图片优化
Stars: ✭ 65 (-16.67%)
Mutual labels:  png

Rust version of LodePNG

This is a pure Rust PNG image decoder and encoder. Allows easy reading and writing of PNG files without any system dependencies.

To use the lodepng crate, add to your Cargo.toml:

[dependencies]
lodepng = "3.4"

See API reference for details. Requires Rust 1.46 or later.

Loading image example

There are more examples in the examples/ dir.

let image = lodepng::decode32_file("in.png")?;

returns image of type lodepng::Bitmap<lodepng::RGBA<u8>> with fields .width, .height, and .buffer (the buffer is a Vec).

The RGB/RGBA pixel types are from the RGB crate, which you can import separately to use the same pixel struct throughout the program, without casting. But if you want to read the image buffer as bunch of raw bytes, ignoring the RGB(A) pixel structure, use:

[dependencies]
rgb = "0.8"
use rgb::*;

let bytes: &[u8] = image.buffer.as_bytes();

Saving image example

lodepng::encode32_file("out.png", &buffer, width, height)

The buffer can be a slice of any type as long as it has 4 bytes per element (e.g. struct RGBA or [u8; 4]).

Advanced

let mut state = lodepng::Decoder::new();
state.remember_unknown_chunks(true);

match state.decode("in.png") {
    Ok(lodepng::Image::RGB(image)) => {}
    Ok(lodepng::Image::RGBA(image)) => {}
    Ok(lodepng::Image::RGBA16(image)) => {}
    Ok(lodepng::Image::Grey(image)) => {}
    Ok(_) => {}
    Err(err) => {}
}

for chunk in state.info_png().unknown_chunks(ChunkPosition::IHDR) {
    println!("{:?} = {:?}", chunk.name(), chunk.data());
}

// Color profile (to be used with e.g. LCMS2)
let icc_data = state.get_icc();

See load_image crate for an example how to use lodepng with color profiles.

Upgrading from 2.x

  • C FFI still exists, but is no longer ABI-compatible with the original C lodepng due to layout changes in structs.
  • Structs use bool where appropriate instead of 0/1 int.
  • Custom zlib callbacks use io::Write instead of malloc-ed buffers (remember to use write_all, not write!)
  • ffi::Error has been renamed to ffi::ErrorCode.
  • Compression level is set via set_level() function instead of individual CompressConfig fields.

Upgrading from 1.x

  • CVec has been replaced with a regular Vec. Delete extra .as_ref() that the compiler may complain about.
  • LCT_* constants have been changed to ColorType::*.
  • Chunk/Chunks renamed to ChunkRef/ChunksIter.
  • auto_convert is a boolean.
  • bitdepth has a getter/setter.
  • There is no C any more!

Origin of the Rust version

This codebase is derived from C LodePNG by Lode Vandevenne. It has been converted to Rust using Citrus C to Rust converter and manual refactorings.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].