title: libpng 1.6.35 : Unable to render image using image format as RGBA or BGRA
body: <p>I am trying to use <code>libpng1.6.35</code> library to decode image data from the given input buffer and return back the decode buffer to the renderer. I want the image with a transparent background.</p>
  
  <p>Below is the image which I am trying to render:</p>
  
  <p><a href="https://i.stack.imgur.com/Bd3Hd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Bd3Hd.png" alt="image which I am trying to render"></a></p>
  
  <pre><code>#include "png.h"
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  extern unsigned char g_image[0x00080000]; 
  
  unsigned char * PngFileToRGBA(unsigned int *width,
  unsigned int *height)
  {
       png_image image;
       memset(&amp;image, 0, (sizeof image));
       image.version = PNG_IMAGE_VERSION;
       png_image_begin_read_from_memory(&amp;image,
       png_const_voidp(g_image), sizeof(g_image));  /*g_image contains the 
                                                      input image buffer to 
                                                      decode*/
      png_bytep buffer1;                           /*buffer1 is output 
                                                    decoded image buffer.*/
      image.format = PNG_FORMAT_BGRA;
      buffer1 = (png_bytep)malloc(PNG_IMAGE_SIZE(image));
      if (buffer1 != NULL &amp;&amp;
      png_image_finish_read(&amp;image, NULL/*background*/, buffer1,
          0/*row_stride*/, NULL/*colormap*/) != 0)
     {
          return buffer1;
  
     }
  }
  </code></pre>
  
  <p>If I use image format as BGR, I get the correct output image using buffer1, but with image format as BGRA, the output image is washed out. Please guide what I am missing here.</p>
  
  <p>Output rendered images with BGR and BGR format:</p>
  
  <p><a href="https://i.stack.imgur.com/wdQoK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wdQoK.png" alt="with image format as BGR"></a></p>
  
  <p>with image format as BGRA:</p>
  
  <p><a href="https://i.stack.imgur.com/ZpnXP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZpnXP.png" alt="with image format as BGRA"></a></p>
  
  <p>It behaves the same even if I use image format as RGB/RGBA.</p>