From 5c00245e50d3c3f035b9b3783193a43b507bc7f5 Mon Sep 17 00:00:00 2001 From: Mike Wey Date: Tue, 27 Aug 2013 23:16:32 +0200 Subject: Add HDRI support. --- dmagick/c/quantum.d | 63 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 12 deletions(-) (limited to 'dmagick/c/quantum.d') diff --git a/dmagick/c/quantum.d b/dmagick/c/quantum.d index a7b14b3..f86d59c 100644 --- a/dmagick/c/quantum.d +++ b/dmagick/c/quantum.d @@ -70,23 +70,62 @@ extern(C) alias ClampToQuantum RoundToQuantum; static pure nothrow Quantum ClampToQuantum(const MagickRealType value) { - if (value <= 0.0) - return(cast(Quantum) 0); - if (value >= cast(MagickRealType) QuantumRange) - return(cast(Quantum) QuantumRange); - return(cast(Quantum) (value+0.5)); + version(MagickCore_HDRI) + { + return value; + } + else + { + if (value <= 0.0) + return(cast(Quantum) 0); + if (value >= cast(MagickRealType) QuantumRange) + return(cast(Quantum) QuantumRange); + return(cast(Quantum) (value+0.5)); + } } static pure nothrow ubyte ScaleQuantumToChar(const Quantum quantum) { - static if ( MagickQuantumDepth == 8 ) - return quantum; - else static if ( MagickQuantumDepth == 16 ) - return cast(ubyte) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8); - else static if ( MagickQuantumDepth == 32 ) - return cast(ubyte) (quantum+8421504UL/16843009UL ); + version(MagickCore_HDRI) + { + if ( quantum <= 0 ) + return 0; + static if ( MagickQuantumDepth == 8 ) + { + if ( quantum >= 255 ) + return 255; + return cast(ubyte)(quantum+0.5); + } + else static if ( MagickQuantumDepth == 16 ) + { + if ( quantum/257 >= 255) + return 255; + return cast(ubyte)(quantum/257+0.5); + } + else static if ( MagickQuantumDepth == 32 ) + { + if ( quantum/16843009 >= 255) + return 255; + return cast(ubyte)(quantum/16843009+0.5); + } + else + { + if ( quantum/72340172838076673 >= 255) + return 255; + return cast(ubyte)(quantum/72340172838076673+0.5); + } + } else - return cast(ubyte) (quantum/72340172838076673.0+0.5); + { + static if ( MagickQuantumDepth == 8 ) + return quantum; + else static if ( MagickQuantumDepth == 16 ) + return cast(ubyte) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8); + else static if ( MagickQuantumDepth == 32 ) + return cast(ubyte) (quantum+8421504UL/16843009UL ); + else + return cast(ubyte) (quantum/72340172838076673.0+0.5); + } } static pure nothrow Quantum ScaleCharToQuantum(ubyte value) -- cgit v1.2.3