Added opacity to import
This commit is contained in:
parent
e54eed7ad9
commit
0c271792f2
@ -1,8 +1,8 @@
|
|||||||
function Library (ronin) {
|
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()
|
const img = new Image()
|
||||||
img.src = path
|
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.
|
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)
|
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) {
|
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 pixel = [img.data[i], img.data[i + 1], img.data[i + 2], img.data[i + 3]]
|
||||||
|
|
||||||
const processed = await fn(pixel, q)
|
const processed = await fn(pixel, q)
|
||||||
console.log(processed)
|
|
||||||
img.data[i] = this.clamp(parseInt(processed[0]), 0, 255)
|
img.data[i] = this.clamp(parseInt(processed[0]), 0, 255)
|
||||||
img.data[i + 1] = this.clamp(parseInt(processed[1]), 0, 255)
|
img.data[i + 1] = this.clamp(parseInt(processed[1]), 0, 255)
|
||||||
img.data[i + 2] = this.clamp(parseInt(processed[2]), 0, 255)
|
img.data[i + 2] = this.clamp(parseInt(processed[2]), 0, 255)
|
||||||
|
@ -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 => {
|
return new Promise(resolve => {
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
|
this.context.globalAlpha = alpha
|
||||||
if (isLine(shape)) {
|
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)
|
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)) {
|
} else if (isRect(shape)) {
|
||||||
@ -170,6 +171,7 @@ function Surface (ronin) {
|
|||||||
} else {
|
} else {
|
||||||
this.context.drawImage(img, shape.x, shape.y, img.width, img.height)
|
this.context.drawImage(img, shape.x, shape.y, img.width, img.height)
|
||||||
}
|
}
|
||||||
|
this.context.globalAlpha = 1
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user