Переглянути джерело

enhance renders by using binary transparency

this is a temporary fix for #32.
it doesn't solve the problem, but it makes the renders much less worse.

in combination with #134 this will hopefully lead to fixing the problem entirely
jomo 9 роки тому
батько
коміт
6d12ed685b
1 змінених файлів з 18 додано та 3 видалено
  1. 18 3
      lib/renders.js

+ 18 - 3
lib/renders.js

@@ -24,6 +24,18 @@ function scale_image(imageData, context, d_x, d_y, scale) {
   }
 }
 
+// makes images less worse by using binary transparency
+function enhance(context) {
+  var imagedata = context.getImageData(0, 0, context.canvas.width, context.canvas.height);
+  var data = imagedata.data;
+  // data is [r,g,b,a, r,g,b,a, *]
+  for (var i = 3; i < data.length; i += 4) {
+    // round to 0 or 255
+    data[i] = Math.round(data[i] / 255) * 255;
+  }
+  context.putImageData(imagedata, 0, 0);
+}
+
 // draws the helmet on to the +skin_canvas+
 // using the skin from the +model_ctx+ at the +scale+
 exp.draw_helmet = function(skin_canvas, model_ctx, scale) {
@@ -155,7 +167,7 @@ exp.draw_model = function(rid, img, scale, helm, body, callback) {
 
   image.onload = function() {
     var width = 64 * scale;
-    var original_height = (image.height === 32 ? 32 : 64);
+    var original_height = image.height === 32 ? 32 : 64;
     var height = original_height * scale;
     var model_canvas = new Canvas(20 * scale, (body ? 44.8 : 17.6) * scale);
     var skin_canvas = new Canvas(width, height);
@@ -173,7 +185,10 @@ exp.draw_model = function(rid, img, scale, helm, body, callback) {
       exp.draw_helmet(skin_canvas, model_ctx, scale);
     }
 
-    model_canvas.toBuffer(function(err, buf){
+    // FIXME: This is a temporary fix for #32
+    enhance(model_ctx);
+
+    model_canvas.toBuffer(function(err, buf) {
       if (err) {
         logging.error(rid, "error creating buffer:", err);
       }
@@ -187,7 +202,7 @@ exp.draw_model = function(rid, img, scale, helm, body, callback) {
 // helper method to open a render from +renderpath+
 // callback: error, image buffer
 exp.open_render = function(rid, renderpath, callback) {
-  fs.readFile(renderpath, function (err, buf) {
+  fs.readFile(renderpath, function(err, buf) {
     if (err) {
       logging.error(rid, "error while opening skin file:", err);
     }