Antialiasing
authorAlyssa Rosenzweig <bobbybee@users.noreply.github.com>
Tue, 2 Jun 2015 12:49:01 +0000 (08:49 -0400)
committerAlyssa Rosenzweig <bobbybee@users.noreply.github.com>
Tue, 2 Jun 2015 12:49:01 +0000 (08:49 -0400)
DynImage.js
main.js

index bb3605e..5e973f0 100644 (file)
@@ -231,5 +231,62 @@ DynImage.prototype.border = function(width, height, bred, bgreen, bblue, mul) {
        }       
 }
 
+DynImage.prototype.antialias = function(width, height) {
+    var buf = new Buffer(width * height * 4);
+    
+    for(var i = 0; i < width; ++i) {
+        for(var j = 0; j < height; ++j) {
+            var successPixels = 0;
+            var rSum = 0, gSum = 0, bSum = 0, aSum = 0;
+            var that = this;
+
+            function run(x, y) {
+                var color = that.getColor(x, y);
+                rSum += color[0];
+                gSum += color[1];
+                bSum += color[2];
+                aSum += color[3];
+                successPixels++;
+            }
+
+            run(i, j);
+
+            if( (i - 1) >= 0) {
+               run(i - 1, j);
+
+               if( (j - 1) >= 0) {
+                  run(i - 1, j -1);
+               }
+
+               if( (j + 1) < width) {
+                   run(i -1, j + 1);
+               }
+            }
+
+            if( (i + 1) < width) {
+                run(i + 1, j);
+
+                if( (j - 1) >= 0) {
+                    run(i + 1, j - 1);
+                }
+
+                if( (j + 1) < width) {
+                    run(i + 1, j + 1);
+                }
+            }
+
+            if( (j - 1) >= 0) {
+                run(i, j - 1);
+            }
+
+            if( (j + 1) < width) {
+                run(i, j + 1);
+            }
+            
+            this.setColor(i, j, rSum / successPixels, gSum / successPixels, bSum / successPixels, aSum / successPixels);
+        }
+    }        
+}
+
 
 module.exports = DynImage;
diff --git a/main.js b/main.js
index 6b854ba..7d107cf 100644 (file)
--- a/main.js
+++ b/main.js
@@ -40,7 +40,14 @@ function pretty(name, ired, igreen, iblue, ringConstant, stainConstant, stainSiz
        dynimage.recontrast(contrastThreshold, Math.floor(Math.random() * 60));
 
 //     dynimage.border(width, height, bred, bgreen, bblue, borderConstant);
-       
+
+       var png = new Png(buffer, width, height, 'rgba');
+       png.encode(function(image) {
+                               fs.writeFile(name+".blurry.png", image);
+                       });
+
+    dynimage.antialias(width, height);
+
        var png = new Png(buffer, width, height, 'rgba');
        png.encode(function(image) {
                                fs.writeFile(name+".png", image);
This page took 0.026298 seconds and 4 git commands to generate.