GitXplorerGitXplorer
a

spng-rs

public
15 stars
1 forks
2 issues

Commits

List of commits on branch master.
Verified
d3f69ff2c5e5a0abcd3bb5f7b32d7eae7e8c99a2

Merge pull request #16 from ComunidadAylas/feat/decoder-crc-action

aaloucks committed 2 months ago
Verified
51b46a8f9168afb5de3e4ad53ad9c78d8025128b

Support setting chunk CRC error action in the high-level `Decoder` API

AAlexTMjugador committed 2 months ago
Verified
9e833a63198b9a3c469a6b04576ebe62c49524ba

Fix typo

AAlexTMjugador committed 2 months ago
Unverified
a8cc5b6237d6f9d9678c7467af8857643c79ffc0

Add missing newline before read_fn

aaloucks committed 5 months ago
Unverified
52957299df2536d2a9e0348f76d671b8f6d0fb97

Make chunk wrappers repr(transparent) and add to allow access to text chunk data when it's compressed

aaloucks committed 5 months ago
Unverified
661ed9c88b04664d6433596a68896f9fab97a849

Version 0.2.0-alpha.3

aaloucks committed 5 months ago

README

The README file for this repository.

spng-rs

crates.io docs.rs tests

Rust bindings to libspng.

Version

spng-rs libspng
0.2.0-alpha.3 0.7.4
0.2.0-alpha.2 0.7.0-rc2
0.2.0-alpha.1 0.7.0-rc2
0.1.0 0.6.3

Performance

This test image is decoded ~ 3-5x faster than with the png crate.

png_decode              time:   [1.7354 ms 1.7372 ms 1.7392 ms]
spng_decode             time:   [569.27 µs 570.86 µs 572.45 µs]
spng_decode             time:   [311.84 µs 312.45 µs 313.13 µs] (--features=zlib-ng)

Examples

A one-liner for simple use cases:

let file = File::open("image.png")?;
let (out_info, data) = spng::decode(file, spng::Format::Rgba8)?;

assert_eq!(300, out_info.width);
assert_eq!(300, out_info.height);
assert_eq!(8, out_info.bit_depth);
assert_eq!(4, out_info.color_type.samples());
assert_eq!(out_info.buffer_size, output_buffer_size);

The Decoder interface is modeled after the png crate:

let file = File::open("image.png")?;
let decoder = spng::Decoder::new(file)
    .with_output_format(spng::Format::Rgba8);
let (out_info, mut reader) = decoder.read_info()?;
let out_buffer_size = reader.output_buffer_size();
let mut data = vec![0; out_buffer_size];
reader.next_frame(&mut data)?;

assert_eq!(300, out_info.width);
assert_eq!(300, out_info.height);
assert_eq!(8, out_info.bit_depth);
assert_eq!(4, out_info.color_type.samples());
assert_eq!(out_info.buffer_size, out_buffer_size);

The RawContext interface is a safe and minimal wrapper over the full libspng C API.

let file = File::open("image.png")?;
let out_format = spng::Format::Rgba8;
let mut ctx = spng::raw::RawContext::new()?;
ctx.set_png_stream(file)?;
let ihdr = ctx.get_ihdr()?;
let out_buffer_size = ctx.decoded_image_size(out_format)?;
let mut data = vec![0; out_buffer_size];
ctx.decode_image(&mut data, out_format, spng::DecodeFlags::empty())?;

assert_eq!(300, ihdr.width);
assert_eq!(300, ihdr.height);
assert_eq!(8, ihdr.bit_depth);
assert_eq!(4, spng::ColorType::try_from(ihdr.color_type)?.samples());