From e1651a2f892ffca9a9314011fcf2d5a9a2b152cc Mon Sep 17 00:00:00 2001 From: yushijinhun Date: Thu, 5 Jul 2018 23:08:05 +0800 Subject: [PATCH] Fix #15 --- src/utils.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/utils.js b/src/utils.js index b24dc81..927a65a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -47,10 +47,27 @@ function computeSkinScale(width) { return width / 64.0; } +function fixOpaqueSkin(context, width) { + // Some ancient skins don't have transparent pixels (nor have helm). + // We have to make the helm area transparent, otherwise it will be rendered as black. + if (!hasTransparency(context, 0, 0, width, width / 2)) { + let scale = computeSkinScale(width); + let clearArea = (x, y, w, h) => context.clearRect(x * scale, y * scale, w * scale, h * scale); + clearArea(40, 0, 8, 8); // Helm Top + clearArea(48, 0, 8, 8); // Helm Bottom + clearArea(32, 8, 8, 8); // Helm Right + clearArea(40, 8, 8, 8); // Helm Front + clearArea(48, 8, 8, 8); // Helm Left + clearArea(56, 8, 8, 8); // Helm Back + } +} + function convertSkinTo1_8(context, width) { let scale = computeSkinScale(width); let copySkin = (sX, sY, w, h, dX, dY, flipHorizontal) => copyImage(context, sX * scale, sY * scale, w * scale, h * scale, dX * scale, dY * scale, flipHorizontal); + fixOpaqueSkin(context, width); + copySkin(4, 16, 4, 4, 20, 48, true); // Top Leg copySkin(8, 16, 4, 4, 24, 48, true); // Bottom Leg copySkin(0, 20, 4, 12, 24, 52, true); // Outer Leg