diff options
| -rw-r--r-- | dmagick/Color.d | 6 | ||||
| -rw-r--r-- | dmagick/ColorRGB.d | 24 | ||||
| -rw-r--r-- | dmagick/Geometry.d | 47 | ||||
| -rw-r--r-- | dmagick/Options.d | 37 |
4 files changed, 88 insertions, 26 deletions
diff --git a/dmagick/Color.d b/dmagick/Color.d index 7c50595..c35b796 100644 --- a/dmagick/Color.d +++ b/dmagick/Color.d @@ -222,6 +222,12 @@ class Color return toString(); } + unittest + { + Color color = new Color("red"); + assert( color.name == "red" ); + } + static Quantum scaleDoubleToQuantum(double value) { return cast(Quantum)(value*QuantumRange); diff --git a/dmagick/ColorRGB.d b/dmagick/ColorRGB.d index 777c300..94ff72f 100644 --- a/dmagick/ColorRGB.d +++ b/dmagick/ColorRGB.d @@ -53,55 +53,79 @@ class ColorRGB : Color super(color); } + /** + * The value for red as a byte + */ void redByte(ubyte red) { pixelPacket.red = ScaleCharToQuantum(red); } + ///ditto ubyte redByte() { return ScaleQuantumToChar(pixelPacket.red); } + /** + * The value for green as a byte + */ void greenByte(ubyte green) { pixelPacket.green = ScaleCharToQuantum(green); } + ///ditto ubyte greenByte() { return ScaleQuantumToChar(pixelPacket.green); } + /** + * The value for blue as a byte + */ void blueByte(ubyte blue) { pixelPacket.blue = ScaleCharToQuantum(blue); } + ///ditto ubyte blueByte() { return ScaleQuantumToChar(pixelPacket.blue); } + /** + * The value for red as a double in the range [0.0 .. 1.0] + */ void red(double red) { pixelPacket.red = scaleDoubleToQuantum(red); } + ///ditto double red() { return scaleQuantumToDouble(pixelPacket.red); } + /** + * The value for green as a double in the range [0.0 .. 1.0] + */ void green(double green) { pixelPacket.green = scaleDoubleToQuantum(green); } + ///ditto double green() { return scaleQuantumToDouble(pixelPacket.green); } + /** + * The value for blue as a double in the range [0.0 .. 1.0] + */ void blue(double blue) { pixelPacket.blue = scaleDoubleToQuantum(blue); } + ///ditto double blue() { return scaleQuantumToDouble(pixelPacket.blue); diff --git a/dmagick/Geometry.d b/dmagick/Geometry.d index 0547f49..afda819 100644 --- a/dmagick/Geometry.d +++ b/dmagick/Geometry.d @@ -1,6 +1,4 @@ /** - * A class to specify a geometry argument. - * * Copyright: Mike Wey 2011 * License: To be determined * Authors: Mike Wey @@ -17,18 +15,25 @@ import dmagick.c.geometry; import dmagick.c.magickString; import dmagick.c.magickType; +/** + * Geometry provides a convenient means to specify a geometry argument. + */ struct Geometry { - size_t width; - size_t height; - ssize_t xOffset; - ssize_t yOffset; - bool percent; - bool minimum; - bool keepAspect = true; - bool greater; - bool less; - + size_t width; /// + size_t height; /// + ssize_t xOffset; /// + ssize_t yOffset; /// + bool percent; /// The width and/or height are percentages of the original. + bool minimum; /// The specified width and/or height is the minimum value. + bool keepAspect = true; ///Retain the aspect ratio. + bool greater; /// Resize only if the image is greater than the width and/or height. + bool less; /// Resize only if the image is smaller than the width and/or height. + + /** + * Create a Geometry form a Imagemagick / X11 geometry string. + */ + //TODO: expand the documentation for this constructor. this(string geometry) { MagickStatusType flags; @@ -64,7 +69,10 @@ struct Geometry assert( geo.width == 595 && geo.height == 842); } - this(size_t width, size_t height, ssize_t xOffset, ssize_t yOffset) + /** + * Initialize with width heigt and offsets. + */ + this(size_t width, size_t height, ssize_t xOffset = 0, ssize_t yOffset = 0) { this.width = width; this.height = height; @@ -72,6 +80,9 @@ struct Geometry this.yOffset = yOffset; } + /** + * Convert Geometry into a Imagemagick geometry string. + */ string toString() { string geometry; @@ -82,9 +93,6 @@ struct Geometry if ( height > 0 ) geometry ~= "x" ~ to!(string)(height); - if ( xOffset != 0 && yOffset != 0 ) - geometry ~= format("%+s%+s", xOffset, yOffset); - geometry ~= format("%s%s%s%s%s", percent ? "%" : "", minimum ? "^" : "", @@ -92,13 +100,16 @@ struct Geometry less ? "<" : "", greater ? ">" : ""); + if ( xOffset != 0 && yOffset != 0 ) + geometry ~= format("%+s%+s", xOffset, yOffset); + return geometry; } unittest { - Geometry geo = Geometry("200x150-50+25!"); - assert( geo.toString == "200x150-50+25!"); + Geometry geo = Geometry("200x150!-50+25"); + assert( geo.toString == "200x150!-50+25"); } int opCmp(ref const Geometry geometry) diff --git a/dmagick/Options.d b/dmagick/Options.d index 7e37042..082e455 100644 --- a/dmagick/Options.d +++ b/dmagick/Options.d @@ -14,6 +14,7 @@ import core.stdc.stdio; import core.stdc.string; import dmagick.Color; +import dmagick.Geometry; import dmagick.Image; import dmagick.Utils; @@ -189,9 +190,14 @@ class Options copyString(imageInfo.density, str); } ///ditto - string density() + void density(Geometry geometry) { - return to!(string)(imageInfo.density); + density(geometry.toString()); + } + ///ditto + Geometry density() + { + return Geometry( to!(string)(imageInfo.density) ); } /** @@ -387,9 +393,14 @@ class Options copyString(imageInfo.page, str); } ///ditto - string page() + void page(Geometry geometry) + { + page(geometry.toString()); + } + ///ditto + Geometry page() { - return to!(string)(imageInfo.page); + return Geometry( to!(string)(imageInfo.page) ); } /** @@ -466,9 +477,14 @@ class Options copyString(imageInfo.size, str); } ///ditto - string size() + void size(Geometry geometry) { - return to!(string)(imageInfo.size); + size(geometry.toString()); + } + ///ditto + Geometry size() + { + return Geometry( to!(string)(imageInfo.size) ); } /** @@ -955,9 +971,14 @@ class Options copyString(imageInfo.density, str); } ///ditto - string textDensity() + void textDensity(Geometry geometry) + { + textDensity(geometry.toString); + } + ///ditto + Geometry textDensity() { - return to!(string)(imageInfo.density); + return Geometry( to!(string)(imageInfo.density) ); } /** |
