silvia-odwyer / photon

⚡ Rust/WebAssembly image processing library
https://silvia-odwyer.github.io/photon
Apache License 2.0
2.67k stars 151 forks source link

Pixel Byte vs Bytes #149

Open HarrisDePerceptron opened 1 year ago

HarrisDePerceptron commented 1 year ago

why are these not equal

assert_eq!(img.get_raw_pixels().len(),  img.get_bytes().len())

@igrep @rsk700 @Horki @Clivern @samuelvanderwaal

nathanbabcock commented 1 year ago

@HarrisDePerceptron

    /// Convert the PhotonImage to raw bytes. Returns JPEG.
    pub fn get_bytes(&self) -> Vec<u8> {
        let mut img = helpers::dyn_image_from_raw(self);
        img = ImageRgba8(img.to_rgba8());
        let mut buffer = vec![];
        img.write_to(&mut buffer, image::ImageOutputFormat::Png)
            .unwrap();
        buffer
    }

As the doc comment says, get_bytes is meant to be an encoded image, which is different. Although it seems it returns a PNG, not JPEG.