Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PNG Encoding: encoded image is even larger than its pixel size? #177

Open
hillin opened this issue Mar 26, 2024 · 1 comment
Open

PNG Encoding: encoded image is even larger than its pixel size? #177

hillin opened this issue Mar 26, 2024 · 1 comment

Comments

@hillin
Copy link
Contributor

hillin commented Mar 26, 2024

use zune_core::options::DecoderOptions;
use zune_image::{codecs::ImageFormat, image::Image};

const JPEG_IMAGE_DATA: &[u8] = include_bytes!("../resources/lenna.jpg");

fn main() {
    let image = Image::read(JPEG_IMAGE_DATA, DecoderOptions::default()).unwrap();
    println!("Pixel bytes: {}", image.flatten_to_u8().iter().flatten().count());

    let data = image.write_to_vec(ImageFormat::PNG).unwrap();
    println!("PNG bytes: {}", data.len());
}

Where lenna.jpg is a 512*512 picture of the famous Lenna.

Output:

Pixel bytes: 786432
PNG bytes: 788224
@etemesi254
Copy link
Owner

Hi, the png encoder is still in the works, but currently i'd recommend image-rs png encoder, when writing the png decoder and encoder, it wasn't as performant as it currently was, but there have been really great advancements in making it fast. e.g image-rs/image-png#478 and the massive thread at image-rs/image-png#416 (Chromium want to integrate it as the decoder so it has seen some really good optimizations). Zune currently supports easy integration of other crates, e.g see https://github.com/SalOne22/rimage/blob/main/src/codecs/oxipng/encoder/mod.rs that uses oxipng for the png encoder instead of the normal one in zune-png, the same can be done for others

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants