diff --git a/src/util/BlendMode.js b/src/util/BlendMode.js index f9372e28..7d462103 100644 --- a/src/util/BlendMode.js +++ b/src/util/BlendMode.js @@ -44,164 +44,126 @@ var BlendMode = { // TODO: Clean up codespacing of original code, or keep it as is, so // we can easily encorporate changes? process: function(blendMode, sourceContext, destContext, opacity, offset) { - var sourceCanvas = sourceContext.canvas; - var dstD = destContext.getImageData( - offset.x, offset.y, - sourceCanvas.width, sourceCanvas.height - ); + var sourceCanvas = sourceContext.canvas, + dstD = destContext.getImageData(offset.x, offset.y, + sourceCanvas.width, sourceCanvas.height), + srcD = sourceContext.getImageData(0, 0, + sourceCanvas.width, sourceCanvas.height), + src = srcD.data, + dst = dstD.data, + sA, dA, len = dst.length, + sRA, sGA, sBA, dRA, dGA, dBA, dA2, + demultiply, + min = Math.min; - var srcD = sourceContext.getImageData( - 0, 0, - sourceCanvas.width, sourceCanvas.height - ); + for (var i = 0; i < len; i += 4) { + sA = src[i + 3] / 255 * opacity; + dA = dst[i + 3] / 255; + dA2 = sA + dA - sA * dA; + dst[i + 3] = dA2 * 255; - var src = srcD.data; - var dst = dstD.data; - var sA, dA, len=dst.length; - var sRA, sGA, sBA, dRA, dGA, dBA, dA2; - var demultiply; - - for (var px=0;pxdRA ? dRA : sRA) * demultiply; - dst[px+1] = (sGA>dGA ? dGA : sGA) * demultiply; - dst[px+2] = (sBA>dBA ? dBA : sBA) * demultiply; + case 'darken': + case 'darker': + dst[i] = (sRA > dRA ? dRA : sRA) * demultiply; + dst[i + 1] = (sGA > dGA ? dGA : sGA) * demultiply; + dst[i + 2] = (sBA > dBA ? dBA : sBA) * demultiply; break; - - case 'lighten': - case 'lighter': - dst[px ] = (sRA