title: Issue with libyuv::ConvertToI420 on Android?
body: <p>I have an onPreviewFrame callback set up. This gets a byte[] with NV21 data in it. I have set the preview size to 176*144. When device is held in landscape mode, byte[] with 176*144 dimensions is perfect but when device is held in portrait mode I still get byte[] with the same dimensions.</p>
  
  <p>I want to rotate the byte[] by 90 degrees and obtain byte[] with dimensions 144*176.</p>
  
  <p>So the question is, how to rotate the data, not just the preview image? Camera.Parameters.setRotation only affects taking the picture, not video. Camera.setDisplayOrientation specifically says it only affects the displaying preview, not the frame bytes:</p>
  
  <pre><code>This does not affect the order of byte array passed in      
  onPreviewFrame(byte[], Camera), JPEG pictures, or recorded videos.
  </code></pre>
  
  <p>After checking out various posts I have found <a href="https://stackoverflow.com/a/24044228/3437573">this</a> one stating to use ConvertToI420 from libyuv.</p>
  
  <p>Now the deal is I have compiled libyuv and able to call libyuv::ConvertToI420 method but the resulting I420 that I get is all messed up in terms of color and showing lines and all..... however the dimensions that I get are now 144*176, can check the image <a href="https://www.dropbox.com/s/o4qs4fwhvau9bfs/captured_nexus5_9.bmp?dl=0" rel="nofollow noreferrer">here</a>.</p>
  
  <p>The code snippet that i've used is as follows.</p>
  
  <pre><code>    //sourceWidth = 176 and sourceHeight = 144  
      unsigned char I420M = new unsigned char[(int)(sourceWidth*sourceHeight*1.5)];
  
      unsigned int YSize = sourceWidth * sourceHeight;
      // yuvPtr is the NV21 data passed from onPreviewCallback (from JAVA layer)
      const uint8* src_frame = const_cast&lt;const uint8*&gt;(yuvPtr);
      size_t src_size = YSize;
  
      uint8* pDstY = I420M;
      uint8* pDstU = I420M + YSize;
      uint8* pDstV = I420M + (YSize/4);
  
      libyuv::RotationMode mode;
      if(landscapeLeft){
          mode = libyuv::kRotate90;
      }else{
          mode = libyuv::kRotate270;
      }
  
  
      uint32 format = libyuv::FOURCC_NV21;
      int retVal = libyuv::ConvertToI420(src_frame, src_size,
                pDstY, sourceHeight,
                pDstU, (sourceHeight/2),
                pDstV, (sourceHeight/2),
                0, 0,
                sourceWidth, sourceHeight,
                sourceWidth, sourceHeight,
                mode,
                format);
  </code></pre>
  
  <p>I don't wish to crop the image, just rotate it by 90 (clockwise/anticlockwise) the attached image is for  kRotate90.</p>
  
  <p>Could anyone please point me where am going wrong, I strongly doubt it has o do something with the parameters am passing to the ConvertToI420 method.</p>
  
  <p>Any help appreciated.</p>