title: How to quickly unpack U32 Image Array into an RBG U8 Array in LABVIEW
body: <p>I have a flattened (1D) U32 encoded image array which has r, b, and b 8-bit channel values encoded into the first 24 bits of each U32. I would like to expand this array into and array of U8s that each store a separate r, g, or b value (0-255). The issue is that I need this to happen really fast (hundreds of times per second on an old computer) and the method I created is slow.</p>
  
  <p>I am a novice at labview, so I am not exactly sure what a faster way to do this is.</p>
  
  <p>I have successfully accomplished this by creating a U8 array, iterating through each index of the U32 Image array and assigning the corresponding 3 rgb values to the appropriate index in the U8 array using a shift-register. I attempted to use the In Place Element Structure (which would presumably not require copying data in between loops like shift), but I did not know how to make it work inside the loop and when I tried to return the last array from the loop, only the last element was modified.</p>
  
  <p>Here is the first, working method I described above:</p>
  
  <p><img src="https://www.dropbox.com/s/p7iubl5cxn4f6sl/u32_unpack_image_vi.JPG?dl=1" alt="dropbox VI image link (update i have reputation now)"></p>
  
  <p>In c/c++, it would be pretty simple (something like this):</p>
  
  <pre class="lang-cpp prettyprint-override"><code>
  uint8_t* convert_img(uint32_t img[640*480]){
    uint8_t *img_u8 = new uint8_t[640*480*3];
    for (int i=0; i&lt;640*480; ++i){
      img_u8[i*3] = img[i] &amp; 0xff; // r
      img_u8[i*3 + 1] = (img[i] &gt;&gt; 8) &amp; 0xff; // g
      img_u8[i*3 + 2] = (img[i] &gt;&gt; 16) &amp; 0xff; // b
    }
    return img_u8;
  }
  
  </code></pre>
  
  <p>The working labview example above only runs at 20 Hz! I think this is super slow for such a simple operation. Does anyone with more experience have a suggestion of how I can make this happen quickly with labview code?</p>