title: How to display a JPEG on ANativeWindow?
body: <p>I am trying to show a JPEG to a ANativeWindow with the Android NDK.
  I am getting the <code>ANativeWindow*</code> by doing:</p>
  
  <pre><code>_window = ANativeWindow_fromSurface(env, surface)
  </code></pre>
  
  <p>I am loading the jpeg, with libjpeg-turbo, by doing:</p>
  
  <pre><code>if (tjDecompressHeader2(tj, jpeg, jpegSize, &amp;width, &amp;height, &amp;subsamp) == 0) {
      int format = TJPF_ARGB;
      int pitch  = _windowWidth * tjPixelSize[format];
  
      _bufferSize = pitch * _windowHeight;
      _buffer = realloc(_buffer, _bufferSize);
      tjDecompress2(tj, jpeg, jpegSize, _buffer, _windowWidth, pitch, _windowHeight, format, 0);
  }
  </code></pre>
  
  <p>My Question is, how to show the decoded jpeg on the surface ? I am currently doing this:</p>
  
  <pre><code>ANativeWindow_Buffer surface_buffer;
  if (ANativeWindow_lock(_window, &amp;surface_buffer, NULL) == 0) {
      memcpy(surface_buffer.bits, _buffer,  _bufferSize);
      ANativeWindow_unlockAndPost(_window);
  }
  </code></pre>
  
  <p>But the result (see below) is not what I was expecting. What should I do before sending the buffer to the surface ?</p>
  
  <p><img src="https://i.stack.imgur.com/jLzw4.png" alt="snapshot"></p>
  
  <p>Thanks </p>