title: Transpose a 2D array
body: <p>How do you efficiently transpose a matrix?  Are there libraries for this, or what algorithm would you use?</p>
  
  <p>E.g.:</p>
  
  <pre><code>short src[W*H] = {
    {1,2,3},
    {4,5,6}
  };
  short dest[W*H];
  
  
  rotate_90_clockwise(dest,src,W,H); //&lt;-- magic in here, no need for in-place
  
  //dest is now:
  
  {
    {4, 1},
    {5, 2},
    {6, 3}
  };
  </code></pre>
  
  <p>(In my specific case its src array is raw image data, and the destination is a framebuffer, and I'm embedded on ARM on a toolchain that doesn't support assembly)</p>