title: How can I get back an array of objects from Worker?
body: <p>I have a simple <code>Pixel</code> pseudoclass that has <code>.H()</code>, <code>.S()</code> and <code>.L()</code> methods. I use these in image analysis - like this watermark detection:</p>
  
  <p><img src="https://i.stack.imgur.com/JFe1S.png" alt="saturation diferential"></p>
  
  <p>To get the objects out of ImageData, I just loop through the ImageData and create multi-dimensional array:</p>
  
  <pre><code>  //Get image data
    var id = ctx.getImageData(0, 0, canvas1.width, canvas1.height);
    //The Uint8 array
    var pixels = id.data;
    //Dimensions
    var length = pixels.length;
    var width = id.width;
    var height = id.height;
    //Create empty array for 2D data
    var pixels2D = [];
    //Loop vertically
    for (var y = 0; y &lt; height; y++) {
      //Create 2nd level array
      pixels2D.push([]);            
      //Cache the vertical offset
      var ofy = y * width;
      //Loop horizontally
      for (var x = 0; x &lt; width; x++) {
        //Calculate X offset
        var off = (ofy + x) * 4;
        //Create new object
        pixels2D[y].push(new Pixel([pixels[off], pixels[off + 1], pixels[off + 2], pixels[off + 3]]));
      }
    }
  </code></pre>
  
  <p>For large images, this takes a while. Recetly, I found out about <a href="https://developer.mozilla.org/en/docs/Web/Guide/Performance/Using_web_workers" rel="nofollow noreferrer"><code>Workers</code></a>. It seems like the best way to perform asynchronous CPU-demanding tasks, so that my browser doesn't freeze.  </p>
  
  <p>It's possible to <a href="https://developer.mozilla.org/en/docs/Web/Guide/Performance/Using_web_workers#Passing_data_by_transferring_ownership_(transferable_objects)" rel="nofollow noreferrer">pass <code>UInt8Array</code> to worker</a> - but how can I then retrieve the <em>pseudo-Class instance</em> array? <em>Pseudo-Class instances</em> in javascript can't be serialised...</p>