mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Improve frame colors worker perfomance by caching
This commit is contained in:
parent
712262b82a
commit
f829d589d5
@ -34,13 +34,24 @@
|
||||
}
|
||||
};
|
||||
|
||||
var intHexCache = {};
|
||||
var intToHex = function(int) {
|
||||
if (intHexCache[int]) {
|
||||
return intHexCache[int];
|
||||
}
|
||||
|
||||
var hex = rgbToHex(int & 0xff, int >> 8 & 0xff, int >> 16 & 0xff);
|
||||
intHexCache[int] = hex;
|
||||
return hex;
|
||||
};
|
||||
|
||||
var getFrameColors = function (frame) {
|
||||
var frameColors = {};
|
||||
var transparentColorInt = 0; // TODO: Fix magic number
|
||||
for (var i = 0; i < frame.length; i++) {
|
||||
var color = frame[i];
|
||||
if (color !== transparentColorInt) {
|
||||
var hexColor = rgbToHex(color & 0xff, color >> 16 & 0xff, color >> 8 & 0xff);
|
||||
var hexColor = intToHex(color);
|
||||
frameColors[hexColor] = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user