summaryrefslogtreecommitdiff
path: root/dmagick/ColorGray.d
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/ColorGray.d
parente48e1f4f081a2c84addc604136c4383bb92de8c6 (diff)
Add ColorGray for grayscale colors.
Diffstat (limited to 'dmagick/ColorGray.d')
-rw-r--r--dmagick/ColorGray.d60
1 files changed, 60 insertions, 0 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);
+ }
+}