mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-21 23:41:18 +01:00
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
This commit is contained in:
parent
fe12901f41
commit
6d12ed685b
@ -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,6 +185,9 @@ exp.draw_model = function(rid, img, scale, helm, body, callback) {
|
||||
exp.draw_helmet(skin_canvas, model_ctx, scale);
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user