jay3332 / ril

Rust Imaging Library: A high-level imaging crate for Rust.
https://crates.io/crates/ril
MIT License
80 stars 10 forks source link

Indexed (colormap) PNGs not supported #3

Closed rotmoded closed 1 year ago

rotmoded commented 1 year ago
use ril::prelude::*;

fn main() -> ril::Result<()> {
    let mut image: Image<Dynamic> = Image::open("/home/cel/projects/cowmic/cowmic/src/cow.png")?;
    image.invert();
    image.save_inferred("inverted.png")?;
    Ok(())
}

When attempting to open an indexed PNG, the error Unsupported color type. Try using the Dynamic pixel type instead. is thrown.

there is no PixelData::Palette in from_pixel_data:

src/pixel.rs:839

fn from_pixel_data(data: PixelData) -> Result<Self> {
    #[allow(clippy::match_wildcard_for_single_variants)]
    Ok(match data {
        PixelData::Bit(value) => Self::BitPixel(BitPixel(value)),
        PixelData::L(l) => Self::L(L(l)),
        // TODO: LA pixel type
        PixelData::LA(l, _a) => Self::L(L(l)),
        PixelData::Rgb(r, g, b) => Self::Rgb(Rgb { r, g, b }),
        PixelData::Rgba(r, g, b, a) => Self::Rgba(Rgba { r, g, b, a }),
        _ => return Err(UnsupportedColorType),
    })
}
jay3332 commented 1 year ago

Paletted/indexed images are in the works, currently I have an unpushed commit which does implement paletted images, but not the implementation of decoding them. Since people might need this now I might start working on it again soon

rotmoded commented 1 year ago

awesome, superb crate btw! otherwise works perfectly and saved us a lot of time :)