nlfiedler / magick-rust

Rust bindings for ImageMagick
https://crates.io/crates/magick_rust
Apache License 2.0
259 stars 68 forks source link

Creating a wrapper for PHP's getImageChannelRange #128

Open jordanknapp00 opened 3 months ago

jordanknapp00 commented 3 months ago

I'm working on translating an old PHP script that uses Imagick to Rust. The script uses the function getImageChannelRange at one point. I've searched through the docs and can't seem to find an equivalent function in this library, not even one that exists in bindings but doesn't have a wrapper yet.

I've noticed that there is a MagickGetImageRange function in bindings that does not currently have a wrapper. However, it doesn't take a channel as a parameter. Based on looking at existing code, it seems like I could create a wrapper like so:

pub fn get_image_range(&self) -> Result<(f64, f64)> {
    let mut minima: f64 = -1.0;
    let mut maxima: f64 = -1.0;

    match unsafe {
        bindings::MagickGetImageRange(self.wand, &mut minima, &mut maxima)
    } {
        MagickTrue => Ok((minima, maxima)),
        _ => Err(MagickError(self.get_exception()?.0))
    }
}

But then I don't think this does the same thing as getImageChannelRange, since it doesn't take a channel as a parameter. If anyone out there is familiar with PHP's Imagick library, I'd be curious of there's a way to add that function to this crate or if there's another way to replicate its functionality.