diff options
| author | Mike Wey | 2011-02-07 23:47:33 +0100 |
|---|---|---|
| committer | Mike Wey | 2011-02-07 23:47:33 +0100 |
| commit | b5fc681a9af594c3d872199393ae065d37e4faf7 (patch) | |
| tree | 194b25590c573396f82f48d8b8bae452979abc11 /dmagick | |
| parent | d33595cdf0da82c14e7d12dd74a8cedbd9900cee (diff) | |
Add a Color class
Diffstat (limited to 'dmagick')
| -rw-r--r-- | dmagick/Color.d | 79 | ||||
| -rw-r--r-- | dmagick/Options.d | 177 | ||||
| -rw-r--r-- | dmagick/c/magickType.d | 14 |
3 files changed, 187 insertions, 83 deletions
diff --git a/dmagick/Color.d b/dmagick/Color.d new file mode 100644 index 0000000..f428f95 --- /dev/null +++ b/dmagick/Color.d @@ -0,0 +1,79 @@ +/** + * The image + * + * Copyright: Mike Wey 2011 + * License: To be determined + * Authors: Mike Wey + */ + +module dmagick.Color; + +import std.string; + +import dmagick.Exception; +import dmagick.Utils; + +import dmagick.c.color; +import dmagick.c.exception; +import dmagick.c.pixel; +import dmagick.c.magickType; + +class Color +{ + PixelPacket pixelPacket; + + this() + { + pixelPacket.opacity = TransparentOpacity; + } + + this(Quantum red, Quantum green, Quantum blue) + { + this(red, green, blue, 0); + } + + this(Quantum red, Quantum green, Quantum blue, Quantum opacity) + { + this(); + + pixelPacket.red = red; + pixelPacket.green = green; + pixelPacket.blue = blue; + pixelPacket.opacity = opacity; + } + + this(string color) + { + this(); + + ExceptionInfo* exception = AcquireExceptionInfo(); + const(char)* name = toStringz(color); + + QueryColorDatabase(name, &pixelPacket, exception); + DMagickException.throwException(exception); + + DestroyExceptionInfo(exception); + } + + this(PixelPacket packet) + { + pixelPacket = packet; + } + + bool opEquals(Color color) + { + return pixelPacket == color.pixelPacket; + } + + override string toString() + { + //TODO + + return "none"; + } + + Color clone() + { + return new Color(pixelPacket); + } +} diff --git a/dmagick/Options.d b/dmagick/Options.d index d7aa486..f7c931f 100644 --- a/dmagick/Options.d +++ b/dmagick/Options.d @@ -13,6 +13,7 @@ import std.math; import core.stdc.stdio; import core.stdc.string; +import dmagick.Color; import dmagick.Image; import dmagick.Utils; @@ -83,22 +84,23 @@ class Options return imageInfo.adjoin == 1; } - //** - // * Set the image background color. The default is "white". - // */ - //void backgroundColor(string color) - //{ - // - //} - //ditto - //void backgroundColor(Color color) - //{ - // - //} - //Color backgroundColor() - //{ - // - //} + /** + * Set the image background color. The default is "white". + */ + void backgroundColor(string color) + { + backgroundColor = new Color(color); + } + ///ditto + void backgroundColor(Color color) + { + imageInfo.background_color = color.pixelPacket; + } + ///ditto + Color backgroundColor() + { + return new Color(imageInfo.background_color); + } /** * Set a texture to tile onto the image background. @@ -115,16 +117,24 @@ class Options return to!(string)(imageInfo.texture); } - //void borderColor(Color color) - //{ - // imageInfo.border_color - // drawInfo.border_color - //} - //ditto - //Color borderColor() - //{ - // - //} + /** + * Set the image border color. The default is "#dfdfdf". + */ + void borderColor(string color) + { + borderColor = new Color(color); + } + ///ditto + void borderColor(Color color) + { + imageInfo.border_color = color.pixelPacket; + drawInfo.border_color = color.pixelPacket; + } + ///ditto + Color borderColor() + { + return new Color(imageInfo.border_color); + } /** * Set the image border color. The default is "#dfdfdf". @@ -331,15 +341,23 @@ class Options return imageInfo.magick[0 .. strlen(imageInfo.magick.ptr)].idup; } - //void matteColor(Color color) - //{ - // - //} - //ditto - //Color matteColor() - //{ - // - //} + /** + * Set the image transparent color. The default is "#bdbdbd". + */ + void matteColor(string color) + { + matteColor = new Color(color); + } + ///ditto + void matteColor(Color color) + { + imageInfo.matte_color = color.pixelPacket; + } + ///ditto + Color matteColor() + { + return new Color(imageInfo.matte_color); + } /** * Transform the image to black and white on input. @@ -714,32 +732,42 @@ class Options return drawInfo.text_antialias == 1; } - //** - // * If set, causes the text to be drawn over a box of the specified color. - // */ - //void boxColor(Color color) - //{ - // drawInfo.undercolor - //} - //ditto - //Color boxColor() - //{ - // - //} + /** + * If set, causes the text to be drawn over a box of the specified color. + */ + void boxColor(string color) + { + boxColor = new Color(color); + } + ///ditto + void boxColor(Color color) + { + drawInfo.undercolor = color.pixelPacket; + } + ///ditto + Color boxColor() + { + return new Color(drawInfo.undercolor); + } - //** - // * Color to use when filling drawn objects. - // * The default is "black". - // */ - //void fillColor(Color color) - //{ - // drawInfo.fill - //} - //ditto - //Color fillColor() - //{ - // - //} + /** + * Color to use when filling drawn objects. + * The default is "black". + */ + void fillColor(string color) + { + fillColor = new Color(color); + } + ///ditto + void fillColor(Color color) + { + drawInfo.fill = color.pixelPacket; + } + ///ditto + Color fillColor() + { + return new Color(drawInfo.fill); + } /** * Pattern image to use when filling drawn objects. @@ -784,18 +812,23 @@ class Options return drawInfo.stroke_antialias == 1; } - //** - // * Color to use when drawing object outlines - // */ - //void strokeColor(Color color) - //{ - // drawInfo.stroke - //} - //ditto - //Color strokeColor() - //{ - // - //} + /** + * Color to use when drawing object outlines + */ + void strokeColor(string color) + { + strokeColor = new Color(color); + } + ///ditto + void strokeColor(Color color) + { + drawInfo.stroke = color.pixelPacket; + } + ///ditto + Color strokeColor() + { + return new Color(imageInfo.background_color); + } /** * The initial distance into the dash pattern. The units are pixels. diff --git a/dmagick/c/magickType.d b/dmagick/c/magickType.d index 498fb61..0817bb4 100644 --- a/dmagick/c/magickType.d +++ b/dmagick/c/magickType.d @@ -8,7 +8,10 @@ extern (C) alias long MagickOffsetType; alias ulong MagickSizeType; + alias int MagickBooleanType; + alias MagickSizeType QuantumAny; + alias QuantumRange TransparentOpacity; enum MaxTextExtent = 4096; enum QuantumRange = 65535UL; @@ -44,16 +47,5 @@ extern (C) PseudoClass } - alias int MagickBooleanType; - - //typedef enum - //{ - // MagickFalse = 0, - // MagickTrue = 1 - //} MagickBooleanType; - struct BlobInfo {} - - //alias _Image Image; - //alias _ImageInfo ImageInfo; } |
