From 0c271792f234b6aa28af0b18c5e015d2a76d8232 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 31 Jul 2019 10:28:35 +0900 Subject: [PATCH] Added opacity to import --- desktop/sources/scripts/library.js | 6 ++---- desktop/sources/scripts/surface.js | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index ad2c70f..e26530a 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -1,8 +1,8 @@ function Library (ronin) { - this.import = async (path, shape) => { // Imports a graphic file with format. + this.import = async (path, shape, alpha = 1) => { // Imports a graphic file with format. const img = new Image() img.src = path - return ronin.surface.draw(img, shape) + return ronin.surface.draw(img, shape, alpha) } this.export = (path, format = 'image/png', quality = 1.0) => { // Exports a graphic file with format. @@ -217,9 +217,7 @@ function Library (ronin) { const img = ronin.surface.context.getImageData(rect.x, rect.y, rect.w, rect.h) for (let i = 0, loop = img.data.length; i < loop; i += 4) { const pixel = [img.data[i], img.data[i + 1], img.data[i + 2], img.data[i + 3]] - const processed = await fn(pixel, q) - console.log(processed) img.data[i] = this.clamp(parseInt(processed[0]), 0, 255) img.data[i + 1] = this.clamp(parseInt(processed[1]), 0, 255) img.data[i + 2] = this.clamp(parseInt(processed[2]), 0, 255) diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js index 9e5e11c..9fe2363 100644 --- a/desktop/sources/scripts/surface.js +++ b/desktop/sources/scripts/surface.js @@ -154,9 +154,10 @@ function Surface (ronin) { }) } - this.draw = function (img, shape = this.getFrame()) { + this.draw = function (img, shape = this.getFrame(), alpha = 1) { return new Promise(resolve => { img.onload = () => { + this.context.globalAlpha = alpha if (isLine(shape)) { this.context.drawImage(img, shape.a.x, shape.a.y, shape.b.x - shape.a.x, shape.b.y - shape.a.y) } else if (isRect(shape)) { @@ -170,6 +171,7 @@ function Surface (ronin) { } else { this.context.drawImage(img, shape.x, shape.y, img.width, img.height) } + this.context.globalAlpha = 1 resolve() } })