etemesi254/zune-image

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

Opened this issue · 1 comments

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

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