Contrast adjustment
authorAlyssa Rosenzweig <bobbybee@users.noreply.github.com>
Tue, 19 May 2015 18:59:56 +0000 (14:59 -0400)
committerAlyssa Rosenzweig <bobbybee@users.noreply.github.com>
Tue, 19 May 2015 18:59:56 +0000 (14:59 -0400)
DynImage.js
main.js

index 1b0fdb6..8e2f2ca 100644 (file)
@@ -154,4 +154,26 @@ DynImage.prototype.punchPoint = function(x, y, force) {
        this.setColor(x, y, color[0], color[1], color[2], color[3]);
 }
 
+// contrast changer
+// any pixel below a threshold becomes darker,
+// and any pixel above the threshold becomes lighter
+
+DynImage.prototype.recontrast = function(threshold, amount) {
+       for(var i = 0; i < this.width; ++i) {
+               for(var j = 0; j < this.height; ++j) {
+                       var pix = this.getColor(i, j);
+                       
+                       // TODO: use HSL for proper value testing
+
+                       var avg = (pix[0] + pix[1] + pix[2]) / 3;
+                       if(avg > threshold) {
+                               this.setColor(i, j, pix[0] + amount, pix[1] + amount, pix[2] + amount);
+                       } else {
+                               this.setColor(i, j, pix[0] - amount, pix[1] - amount, pix[2] - amount);
+                       }
+               }
+       }
+}
+
+
 module.exports = DynImage;
diff --git a/main.js b/main.js
index 4eac93a..f7b6435 100644 (file)
--- a/main.js
+++ b/main.js
@@ -33,7 +33,9 @@ function pretty(name, ired, igreen, iblue, ringConstant, stainConstant, stainSiz
 
        dynimage.punchImage(width / 2, height / 2, width * stainSize, height * stainSize, Math.floor(stainConstant), width / 3);
 
-       dynimage.pointRing(width / 2, height / 2, width, ringConstant)
+       dynimage.pointRing(width / 2, height / 2, width, ringConstant);
+
+       dynimage.recontrast(127, 70);
 
        var png = new Png(buffer, width, height, 'rgba');
        png.encode(function(image) {
This page took 0.024665 seconds and 4 git commands to generate.