diff --git a/Cargo.toml b/Cargo.toml index 23acf7b..e29e0d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,8 @@ libc = "0.2.70" [build-dependencies] bindgen = "0.53.2" pkg-config = "0.3.17" + +[features] + +# Workaround for bindgen bug when ImageMagick is compiled with disable-hdri +disable-hdri = [] diff --git a/src/wand/magick.rs b/src/wand/magick.rs index 3c59488..153f4f3 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -265,6 +265,26 @@ impl MagickWand { } } + // Define two 'quantum_range' functions because the bindings::QuantumRange symbol + // is not available if hdri is disabled in the compiled ImageMagick libs + #[cfg(not(feature="disable-hdri"))] + fn quantum_range(&self) -> Result { + return Ok(bindings::QuantumRange); + } + + // with disable-hdri enabled we define our own quantum_range + // values lifted directly from magick-type.h + #[cfg(feature="disable-hdri")] + fn quantum_range(&self) -> Result { + match bindings::MAGICKCORE_QUANTUM_DEPTH { + 8 => Ok(255.0f64), + 16 => Ok(65535.0f64), + 32 => Ok(4294967295.0f64), + 64 => Ok(18446744073709551615.0f64), + _ => Err("Quantum depth must be one of 8, 16, 32 or 64") + } + } + // Level an image. Black and white points are multiplied with QuantumRange to // decrease dependencies on the end user. pub fn level_image( @@ -273,12 +293,14 @@ impl MagickWand { gamma: f64, white_point: f64, ) -> Result<(), &'static str> { + let quantum_range = self.quantum_range()?; + let result = unsafe { bindings::MagickLevelImage( self.wand, - black_point * bindings::QuantumRange, + black_point * quantum_range, gamma, - white_point * bindings::QuantumRange, + white_point * quantum_range, ) }; match result { @@ -287,6 +309,7 @@ impl MagickWand { } } + /// Extend the image as defined by the geometry, gravity, and wand background color. Set the /// (x,y) offset of the geometry to move the original wand relative to the extended wand. pub fn extend_image( @@ -586,7 +609,7 @@ impl MagickWand { /// Returns the image resolution as a pair (horizontal resolution, vertical resolution) pub fn sepia_tone_image(&self, threshold: f64) -> Result<(), &'static str> { unsafe { - if bindings::MagickSepiaToneImage(self.wand, threshold * bindings::QuantumRange) + if bindings::MagickSepiaToneImage(self.wand, threshold * self.quantum_range()?) == bindings::MagickBooleanType_MagickTrue { Ok(())