diff options
| author | Mike Wey | 2013-08-27 23:16:32 +0200 |
|---|---|---|
| committer | Mike Wey | 2013-08-27 23:16:32 +0200 |
| commit | 5c00245e50d3c3f035b9b3783193a43b507bc7f5 (patch) | |
| tree | e4b6f2f2c02ad6cb177d32332c1134c64626f03f | |
| parent | 651b1a2c0486cbba412b287c3c67a5b78c47c954 (diff) | |
Add HDRI support.
| -rw-r--r-- | GNUmakefile | 5 | ||||
| -rw-r--r-- | dmagick/Color.d | 13 | ||||
| -rw-r--r-- | dmagick/c/magickType.d | 24 | ||||
| -rw-r--r-- | dmagick/c/quantum.d | 63 |
4 files changed, 83 insertions, 22 deletions
diff --git a/GNUmakefile b/GNUmakefile index 23812e6..c1625e8 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -46,6 +46,7 @@ RANLIB=ranlib QUANTUMDEPTH = $(word 5,$(shell convert --version)) MAGICKVERSION = $(firstword $(subst -, ,$(subst .,,$(word 3,$(shell convert --version))))) +HDRISUPPORT = $(findstring HDRI,$(shell convert --version | grep HDRI)) WRAPEDVERSION = $(subst 0x,,$(subst ;,,$(lastword $(shell grep "enum\ MagickLibVersion\ " dmagick/c/magickVersion.d)))) ifneq ("$(QUANTUMDEPTH)","Q16") @@ -56,6 +57,10 @@ ifneq ("$(MAGICKVERSION)","$(WRAPEDVERSION)") VERSIONS+= -version=MagickCore_$(MAGICKVERSION) endif +ifeq ("$(HDRISUPPORT)","HDRI") + VERSIONS+= -version=MagickCore_HDRI +endif + ifdef VERSIONS DCFLAGS+=$(VERSIONS) endif diff --git a/dmagick/Color.d b/dmagick/Color.d index 0813dc2..11841c5 100644 --- a/dmagick/Color.d +++ b/dmagick/Color.d @@ -7,6 +7,7 @@ module dmagick.Color; import std.conv; +import std.math; import std.string; import dmagick.Exception; @@ -112,13 +113,15 @@ class Color string frm = "%02X"; else static if ( MagickQuantumDepth == 16 ) string frm = "%04X"; - else + else static if ( MagickQuantumDepth == 32 ) string frm = "%08X"; + else + string frm = "%016X"; if ( packet.opacity == OpaqueOpacity ) - return format("#"~frm~frm~frm, packet.red, packet.green, packet.blue); + return format("#"~frm~frm~frm, rndtol(packet.red), rndtol(packet.green), rndtol(packet.blue)); else - return format("#"~frm~frm~frm~frm, packet.red, packet.green, packet.blue, packet.opacity); + return format("#"~frm~frm~frm~frm, rndtol(packet.red), rndtol(packet.green), rndtol(packet.blue), rndtol(QuantumRange-packet.opacity)); } unittest @@ -129,8 +132,10 @@ class Color assert(color.toString() == "#0000FF"); else static if ( MagickQuantumDepth == 16 ) assert(color.toString() == "#00000000FFFF"); - else + else static if ( MagickQuantumDepth == 16 ) assert(color.toString() == "#0000000000000000FFFFFFFF"); + else + assert(color.toString() == "#00000000000000000000000000000000FFFFFFFFFFFFFFFF"); } /* diff --git a/dmagick/c/magickType.d b/dmagick/c/magickType.d index 6f3a17b..1c0d332 100644 --- a/dmagick/c/magickType.d +++ b/dmagick/c/magickType.d @@ -10,7 +10,11 @@ extern (C) * Quantum is an alias for the smallest integer that can hold * a pixel channel. */ - alias ubyte Quantum; + version(MagickCore_HDRI) + alias float Quantum; + else + alias ubyte Quantum; + alias ptrdiff_t SignedQuantum; static if ( MagickLibVersion >= 0x680 ) @@ -22,7 +26,7 @@ extern (C) * The largest value that fits in a Quantum, This is the same * as Quantum.max except when the Quantum dept is 64 bits. */ - enum QuantumRange = Quantum.max; + enum QuantumRange = ubyte.max; enum MAGICKCORE_QUANTUM_DEPTH = 8; enum MaxColormapSize = 256; @@ -38,7 +42,11 @@ extern (C) * Quantum is an alias for the smallest integer that can hold * a pixel channel. */ - alias uint Quantum; + version(MagickCore_HDRI) + alias float Quantum; + else + alias uint Quantum; + alias double SignedQuantum; alias double MagickRealType; @@ -46,7 +54,7 @@ extern (C) * The largest value that fits in a Quantum, This is the same * as Quantum.max except when the Quantum dept is 64 bits. */ - enum QuantumRange = Quantum.max; + enum QuantumRange = uint.max; enum MAGICKCORE_QUANTUM_DEPTH = 32; enum MaxColormapSize = 65536; @@ -88,7 +96,11 @@ extern (C) * Quantum is an alias for the smallest integer that can hold * a pixel channel. */ - alias ushort Quantum; + version(MagickCore_HDRI) + alias float Quantum; + else + alias ushort Quantum; + alias ptrdiff_t SignedQuantum; static if ( MagickLibVersion >= 0x680 ) @@ -100,7 +112,7 @@ extern (C) * The largest value that fits in a Quantum, This is the same * as Quantum.max except when the Quantum dept is 64 bits. */ - enum QuantumRange = Quantum.max; + enum QuantumRange = ushort.max; enum MAGICKCORE_QUANTUM_DEPTH = 16; enum MaxColormapSize = 65536; 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) |
