summaryrefslogtreecommitdiff
path: root/dmagick
diff options
context:
space:
mode:
authorMike Wey2011-08-15 22:02:15 +0200
committerMike Wey2011-08-15 22:02:15 +0200
commit0b7d66fea114d6bc45586a8c62cd98df4ee7d507 (patch)
tree12cf74764753fdd41950ef13a5aec09360e5e73c /dmagick
parente48e1f4f081a2c84addc604136c4383bb92de8c6 (diff)
Add ColorGray for grayscale colors.
Diffstat (limited to 'dmagick')
-rw-r--r--dmagick/ColorGray.d60
-rw-r--r--dmagick/ColorRGB.d20
2 files changed, 68 insertions, 12 deletions
diff --git a/dmagick/ColorGray.d b/dmagick/ColorGray.d
new file mode 100644
index 0000000..3d78bda
--- /dev/null
+++ b/dmagick/ColorGray.d
@@ -0,0 +1,60 @@
+/**
+ * Copyright: Mike Wey 2011
+ * License: zlib (See accompanying LICENSE file)
+ * Authors: Mike Wey
+ */
+
+module dmagick.ColorGray;
+
+import dmagick.Color;
+
+import dmagick.c.magickType;
+import dmagick.c.quantum;
+
+/**
+ * A Gray scale color.
+ */
+class ColorGray : Color
+{
+ ///
+ this()
+ {
+ super();
+ }
+
+ /**
+ * Create a Color from the specified Bytes.
+ */
+ this(ubyte shade, ubyte opacity = 0)
+ {
+ Quantum gray = ScaleCharToQuantum(shade);
+
+ super(gray, gray, gray, ScaleCharToQuantum(opacity));
+ }
+
+ /**
+ * Create a Color from the specified doubles.
+ * The values should be between 0.0 and 1.0.
+ */
+ this(double shade, double opacity = 0)
+ {
+ Quantum gray = scaleDoubleToQuantum(shade);
+
+ super(gray, gray, gray, scaleDoubleToQuantum(opacity));
+ }
+
+ /**
+ * The value for the shade as a double in the range [0.0 .. 1.0]
+ */
+ void shade(double shade)
+ {
+ pixelPacket.red = ScaleCharToQuantum(shade);
+ pixelPacket.green = ScaleCharToQuantum(shade);
+ pixelPacket.blue = ScaleCharToQuantum(shade);
+ }
+ ///ditto
+ double shade()
+ {
+ return scaleQuantumToDouble(pixelPacket.red);
+ }
+}
diff --git a/dmagick/ColorRGB.d b/dmagick/ColorRGB.d
index 1cbd48d..80c85f9 100644
--- a/dmagick/ColorRGB.d
+++ b/dmagick/ColorRGB.d
@@ -26,12 +26,10 @@ class ColorRGB : Color
*/
this(ubyte red, ubyte green, ubyte blue, ubyte opacity = 0)
{
- super();
-
- pixelPacket.red = ScaleCharToQuantum(red);
- pixelPacket.green = ScaleCharToQuantum(green);
- pixelPacket.blue = ScaleCharToQuantum(blue);
- pixelPacket.opacity = ScaleCharToQuantum(opacity);
+ super(ScaleCharToQuantum(red),
+ ScaleCharToQuantum(green),
+ ScaleCharToQuantum(blue),
+ ScaleCharToQuantum(opacity));
}
/**
@@ -40,12 +38,10 @@ class ColorRGB : Color
*/
this(double red, double green, double blue, double opacity = 0)
{
- super();
-
- pixelPacket.red = scaleDoubleToQuantum(red);
- pixelPacket.green = scaleDoubleToQuantum(green);
- pixelPacket.blue = scaleDoubleToQuantum(blue);
- pixelPacket.opacity = scaleDoubleToQuantum(opacity);
+ super(scaleDoubleToQuantum(red),
+ scaleDoubleToQuantum(green),
+ scaleDoubleToQuantum(blue),
+ scaleDoubleToQuantum(opacity));
}
/**