fixed palette import bug

This commit is contained in:
juliandescottes 2014-09-24 21:50:16 +02:00
parent 258d13371d
commit b5465ca066
2 changed files with 25 additions and 3 deletions

View File

@ -0,0 +1,17 @@
(function () {
var ns = $.namespace('pskl.utils');
var workers = {};
ns.WorkerUtils = {
createWorker : function (worker, workerId) {
if (!workers[workerId]) {
var typedArray = [(worker+"").replace(/function \(\)\s?\{/,"").replace(/\}[^}]*$/, "")];
var blob = new Blob(typedArray, {type: "application/javascript"}); // pass a useful mime type here
workers[workerId] = window.URL.createObjectURL(blob);
}
return new Worker(workers[workerId]);
}
};
})();

View File

@ -25,7 +25,12 @@
};
var rgbToHex = function (r, g, b) {
return '#' + ((r << 16) | (g << 8) | b).toString(16);
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
};
var componentToHex = function (c) {
var hex = c.toString(16);
return hex.length == 1 ? "0" + hex : hex;
};
var imageDataToGrid = function (imageData, width, height, transparent) {
@ -96,7 +101,7 @@
this.onError = onError;
// var worker = pskl.utils.WorkerUtils.addPartialWorker(imageProcessorWorker, 'step-counter');
this.worker = pskl.utils.WorkerUtils.createWorker(worker, 'image-colors-processor');
this.worker = pskl.utils.WorkerUtils.createWorker(imageProcessorWorker, 'image-colors-processor');
this.worker.onmessage = this.onWorkerMessage.bind(this);
};