mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Fix transparency issues after deserialization
This commit is contained in:
parent
dd58af30b9
commit
1624792f61
@ -129,6 +129,17 @@
|
|||||||
return pskl.utils.FrameUtils.createFromImage(resizedImage);
|
return pskl.utils.FrameUtils.createFromImage(resizedImage);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
removeTransparency : function (frame) {
|
||||||
|
frame.forEachPixel(function (color, x, y) {
|
||||||
|
var alpha = color >> 24 >>> 0 & 0xff;
|
||||||
|
if (alpha && alpha !== 255) {
|
||||||
|
var rounded = Math.round(alpha / 255) * 255;
|
||||||
|
var roundedColor = color - (alpha << 24 >>> 0) + (rounded << 24 >>> 0);
|
||||||
|
frame.setPixel(x, y, roundedColor);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
createFromCanvas : function (canvas, x, y, w, h, preserveOpacity) {
|
createFromCanvas : function (canvas, x, y, w, h, preserveOpacity) {
|
||||||
var imgData = canvas.getContext('2d').getImageData(x, y, w, h).data;
|
var imgData = canvas.getContext('2d').getImageData(x, y, w, h).data;
|
||||||
return pskl.utils.FrameUtils.createFromImageData_(imgData, w, h, preserveOpacity);
|
return pskl.utils.FrameUtils.createFromImageData_(imgData, w, h, preserveOpacity);
|
||||||
@ -158,6 +169,10 @@
|
|||||||
createFromImageData_ : function (imageData, width, height, preserveOpacity) {
|
createFromImageData_ : function (imageData, width, height, preserveOpacity) {
|
||||||
var frame = new pskl.model.Frame(width, height);
|
var frame = new pskl.model.Frame(width, height);
|
||||||
frame.pixels = new Uint32Array(imageData.buffer);
|
frame.pixels = new Uint32Array(imageData.buffer);
|
||||||
|
if (!preserveOpacity) {
|
||||||
|
pskl.utils.FrameUtils.removeTransparency(frame);
|
||||||
|
}
|
||||||
|
|
||||||
return frame;
|
return frame;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -127,7 +127,9 @@
|
|||||||
var image = new Image();
|
var image = new Image();
|
||||||
image.onload = function() {
|
image.onload = function() {
|
||||||
var frames = pskl.utils.LayerUtils.createFramesFromSpritesheet(this, layer.frameCount);
|
var frames = pskl.utils.LayerUtils.createFramesFromSpritesheet(this, layer.frameCount);
|
||||||
frames.forEach(layer.model.addFrame.bind(layer.model));
|
frames.forEach(function (frame) {
|
||||||
|
layer.model.addFrame(frame);
|
||||||
|
});
|
||||||
|
|
||||||
loadedLayers++;
|
loadedLayers++;
|
||||||
if (loadedLayers == layerCount) {
|
if (loadedLayers == layerCount) {
|
||||||
|
Loading…
Reference in New Issue
Block a user