From 142baeb2ed3ac86497239c151ad624b6e825c14f Mon Sep 17 00:00:00 2001 From: Vishesh Yadav Date: Mon, 8 Jun 2015 21:27:38 -0400 Subject: [PATCH] image: Make transparency work FIXES #37 --- whalesong/image/private/js-impl.js | 8 ++++---- whalesong/image/private/kernel.js | 12 +++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/whalesong/image/private/js-impl.js b/whalesong/image/private/js-impl.js index 473243b..f398228 100644 --- a/whalesong/image/private/js-impl.js +++ b/whalesong/image/private/js-impl.js @@ -487,8 +487,8 @@ EXPORTS['overlay/offset'] = var middleY = (img1.getHeight() - img2.getHeight()) / 2; return makeOverlayImage(img1, img2, - jsnums.toFixnum(middleX + deltaX), - jsnums.toFixnum(middleY + deltaY)); + jsnums.toFixnum(middleX) + deltaX, + jsnums.toFixnum(middleY) + deltaY); }); @@ -569,8 +569,8 @@ EXPORTS['underlay/offset'] = var middleY = (img1.getHeight() - img2.getHeight()) / 2; return makeOverlayImage(img2, img1, - -jsnums.toFixnum(middleX + deltaX), - -jsnums.toFixnum(middleY + deltaY)); + -(jsnums.toFixnum(middleX) + deltaX), + -(jsnums.toFixnum(middleY) + deltaY)); }); EXPORTS['underlay/align'] = diff --git a/whalesong/image/private/kernel.js b/whalesong/image/private/kernel.js index 48ca739..513dd48 100644 --- a/whalesong/image/private/kernel.js +++ b/whalesong/image/private/kernel.js @@ -45,14 +45,12 @@ var isColorOrColorString = function(thing) { ////////////////////////////////////////////////////////////////////// -// colorString : hexColor Style -> rgba -// Style can be "solid" (1.0), "outline" (1.0), a number (0-1.0) or null (1.0) -var colorString = function(aColor, aStyle) { - var alpha = isNaN(aStyle)? 1.0 : aStyle/255; +// colorString : hexColor -> rgba +var colorString = function(aColor) { return "rgba(" + colorRed(aColor) + "," + colorGreen(aColor) + ", " + colorBlue(aColor) + ", " + - alpha + ")"; + (colorAlpha(aColor) || 255)/255.0 + ")"; }; @@ -163,7 +161,7 @@ BaseImage.prototype.render = function(ctx, x, y) { ctx.strokeStyle = colorString(this.color); ctx.stroke(); } else { - ctx.fillStyle = colorString(this.color, this.style); + ctx.fillStyle = colorString(this.color); ctx.fill(); } ctx.restore(); @@ -1211,7 +1209,7 @@ EllipseImage.prototype.render = function(ctx, aX, aY) { ctx.stroke(); } else { - ctx.fillStyle = colorString(this.color, this.style); + ctx.fillStyle = colorString(this.color); ctx.fill(); }