Remove loop and use the pixels directly

This commit is contained in:
Dávid Szabó 2016-08-26 01:37:17 +02:00 committed by Julian Descottes
parent a097d0b897
commit f0f79754f1

View File

@ -156,33 +156,9 @@
},
createFromImageData_ : function (imageData, width, height, preserveOpacity) {
// Draw the zoomed-up pixels to a different canvas context
var grid = [];
for (var x = 0 ; x < width ; x++) {
grid[x] = [];
for (var y = 0 ; y < height ; y++) {
// Find the starting index in the one-dimensional image data
var i = (y * width + x) * 4;
var r = imageData[i ];
var g = imageData[i + 1];
var b = imageData[i + 2];
var a = imageData[i + 3];
if (preserveOpacity) {
if (a === 0) {
grid[x][y] = Constants.TRANSPARENT_COLOR;
} else {
grid[x][y] = 'rgba(' + [r, g, b, a / 255].join(',') + ')';
}
} else {
if (a < 125) {
grid[x][y] = Constants.TRANSPARENT_COLOR;
} else {
grid[x][y] = pskl.utils.rgbToHex(r, g, b);
}
}
}
}
return pskl.model.Frame.fromPixelGrid(grid);
var frame = new pskl.model.Frame(width, height);
frame.pixels = new Uint32Array(imageData.buffer);
return frame;
},
/**