]> Dogcows Code - chaz/rasterize/blobdiff - color.h
add scene lighting constructs; real stdin support
[chaz/rasterize] / color.h
diff --git a/color.h b/color.h
index 26a6390d2adf70c598652bc33183e5b15a421c23..2c5bf8040cc2ee0ff7cbd9ecf7665902a930fdb0 100644 (file)
--- a/color.h
+++ b/color.h
@@ -80,7 +80,7 @@ void color_print(color_t c)
 
 
 /*
- * Add two colors together.  Color may need to be clamped afterward.
+ * Add two colors together.
  */
 INLINE_MAYBE
 color_t color_add(color_t c1, color_t c2)
@@ -89,7 +89,7 @@ color_t color_add(color_t c1, color_t c2)
 }
 
 /*
- * Add three colors together.  Color may need to be clamped afterward.
+ * Add three colors together.
  */
 INLINE_MAYBE
 color_t color_add2(color_t c1, color_t c2, color_t c3)
@@ -97,6 +97,41 @@ color_t color_add2(color_t c1, color_t c2, color_t c3)
     return color_add(color_add(c1, c2), c3);
 }
 
+/*
+ * Multiply two colors together.
+ */
+INLINE_MAYBE
+color_t color_mult(color_t c1, color_t c2)
+{
+    c1.r *= c2.r;
+    c1.g *= c2.g;
+    c1.b *= c2.b;
+    c1.a *= c2.a;
+    return c1;
+}
+
+/*
+ * Scale a color by some scalar coefficient.
+ */
+INLINE_MAYBE
+color_t color_scale(color_t c, scal_t k)
+{
+    c.r *= k;
+    c.g *= k;
+    c.b *= k;
+    c.a *= k;
+    return c;
+}
+
+/*
+ * Scale a color by another color and some scalar coefficient.
+ */
+INLINE_MAYBE
+color_t color_scale2(color_t c1, color_t c2, scal_t k)
+{
+    return color_scale(color_mult(c1, c2), k);
+}
+
 /*
  * Clamp a color's channels to the normal range of 0.0 to 1.0.
  */
This page took 0.019816 seconds and 4 git commands to generate.