HTML and CSS Reference
In-Depth Information
var imageData = JSON.parse(,
worker = null;
pendingWorkers = getNumberOfWorkers(imageData.width
¬ / workingWidth);
// reset any old results
results = {};
for (var i = 0; i < pendingWorkers; i++) {
worker = new Worker('photofilter.js');
imageData: imageData,
x: i * workingWidth,
width: workingWidth
worker.onmessage = storeResult;
function storeResult(event) {
var result = JSON.parse(;
if (pendingWorkers <= 0) {
When the message is received from the sub-worker, the main
worker above decreases the number of outstanding sub-workers.
Once all the sub-workers have returned their slice of the image
data, the flnal result is returned to the parent document.
The sub-worker, photofilter.js worker, would contain the following
code to handle processing just a small region of the image data:
onmessage = function (event) {
var data = JSON.parse(;
// perform some amaing feat of image processing
var imageData = amaingImageProcess(data.imageData,
¬ data.x, data.width);
Search WWH ::

Custom Search