summaryrefslogtreecommitdiff
path: root/dmagick/c/quantum.d
diff options
context:
space:
mode:
authorMike Wey2011-02-28 23:48:18 +0100
committerMike Wey2011-02-28 23:48:18 +0100
commit29427aa46819561111c1ce31014680f32c0dcab3 (patch)
tree20dfcc3beee6697c5dad9e2a22498005a0a82ae1 /dmagick/c/quantum.d
parent846bd1de37e9dfbbcf33f21d86e755ac833c4e5d (diff)
Add versions for different Quantum depths
Diffstat (limited to 'dmagick/c/quantum.d')
-rw-r--r--dmagick/c/quantum.d13
1 files changed, 10 insertions, 3 deletions
diff --git a/dmagick/c/quantum.d b/dmagick/c/quantum.d
index 4186c11..2a48c0a 100644
--- a/dmagick/c/quantum.d
+++ b/dmagick/c/quantum.d
@@ -68,14 +68,21 @@ extern(C)
{
if (value <= 0.0)
return(cast(Quantum) 0);
- if (value >= cast(MagickRealType) 65535UL)
- return(cast(Quantum) 65535UL);
+ if (value >= cast(MagickRealType) QuantumRange)
+ return(cast(Quantum) QuantumRange);
return(cast(Quantum) (value+0.5));
}
static pure nothrow ubyte ScaleQuantumToChar(const Quantum quantum)
{
- return(cast(ubyte) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
+ 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)