From d131ed5959a916a0180bdb561ef508f51e19d8a7 Mon Sep 17 00:00:00 2001 From: Mike Wey Date: Sun, 16 Oct 2011 19:40:07 +0200 Subject: Allow converting one color type to an other. --- dmagick/Color.d | 12 ++++++++++++ dmagick/ImageView.d | 16 ++++++++-------- examples/draw.d | 1 - 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/dmagick/Color.d b/dmagick/Color.d index 7223d81..2ddaa64 100644 --- a/dmagick/Color.d +++ b/dmagick/Color.d @@ -129,6 +129,18 @@ class Color assert(color.toString() == "#0000000000000000FFFFFFFF"); } + /** + * Support casting between different colors. + * You can also use std.conv.to + */ + T opCast(T : Color)() + { + T color = new T(); + color.packet = packet; + + return color; + } + /** * The value for red in the range [0 .. QuantumRange] */ diff --git a/dmagick/ImageView.d b/dmagick/ImageView.d index 4e967be..f23f23a 100644 --- a/dmagick/ImageView.d +++ b/dmagick/ImageView.d @@ -316,14 +316,6 @@ struct Pixels return new Color(pixels.ptr + pixel); } - /** - * Sync the pixels back to the image. The destructor does this for you. - */ - void sync() - { - SyncAuthenticPixelCacheNexus(image.imageRef, &nexus, DMagickExceptionInfo()); - } - ///ditto void opIndexAssign(Color color, size_t index) { @@ -357,6 +349,14 @@ struct Pixels this[i] = color; } + /** + * Sync the pixels back to the image. The destructor does this for you. + */ + void sync() + { + SyncAuthenticPixelCacheNexus(image.imageRef, &nexus, DMagickExceptionInfo()); + } + /** * Support using foreach on a row. */ diff --git a/examples/draw.d b/examples/draw.d index d3635c5..358e942 100644 --- a/examples/draw.d +++ b/examples/draw.d @@ -32,7 +32,6 @@ void main() //Define the Gradients to use; Gradient cylinderEmptyColor = Gradient(new Color("white"), new Color("gray"), imageHeight/2); - Gradient cylinderinsideColor = Gradient(new Color("white"), new Color("darkgray"), imageHeight/2); Gradient cylinderFullColor = Gradient(new Color("green2"), new Color("darkgreen"), imageHeight/2); Gradient cylinderOutColor = Gradient(new Color("lime"), new Color("green4"), imageHeight/2); -- cgit v1.2.3