From b5465ca066916717537e44ba4f2662ee77d077fd Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Wed, 24 Sep 2014 21:50:16 +0200 Subject: [PATCH] fixed palette import bug --- src/js/utils/WorkerUtils.js | 17 +++++++++++++++++ src/js/worker/ImageProcessor.js | 11 ++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/js/utils/WorkerUtils.js diff --git a/src/js/utils/WorkerUtils.js b/src/js/utils/WorkerUtils.js new file mode 100644 index 00000000..0cd421a5 --- /dev/null +++ b/src/js/utils/WorkerUtils.js @@ -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]); + } + }; +})(); \ No newline at end of file diff --git a/src/js/worker/ImageProcessor.js b/src/js/worker/ImageProcessor.js index 53deb72d..82b17695 100644 --- a/src/js/worker/ImageProcessor.js +++ b/src/js/worker/ImageProcessor.js @@ -23,9 +23,14 @@ }); } }; + + var rgbToHex = function (r, g, b) { + return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); + }; - var rgbToHex = function(r, g, b) { - return '#' + ((r << 16) | (g << 8) | b).toString(16); + 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); };