title: How to decode raw png data from Assimp to CGImage?
body: <p>I am using <code>Assimp</code> and when using FBX with embedded textures, Assimp provides the embedded texture data in the following <a href="http://assimp.sourceforge.net/lib_html/structai_texture.html#a97dcffdd5651f20605750820dab897a7" rel="nofollow noreferrer">struct <code>aiTexture</code>'s <code>pcData</code> slot</a>. The documentation for <code>pcData</code> says:</p>
  
  <blockquote>
    <p>Appropriate decoders (such as libjpeg, libpng, D3DX, DevIL) are
    required to load theses textures. aiTexture::mWidth specifies the size
    of the texture data in bytes, aiTexture::pcData is a pointer to the
    raw image data</p>
  </blockquote>
  
  <p>I understand that <code>pcData</code> will have the png header, chunks etc and <code>libPNG</code> can give me back the actual image data with other specs (width, height etc).</p>
  
  <p><strong>What is the native iOS/macOS API to do this instead of using <code>libPNG</code>?</strong>
  For example: <a href="https://developer.apple.com/documentation/coregraphics/1454993-cgimagecreatewithpngdataprovider?language=objc" rel="nofollow noreferrer"><code>CGImageCreateWithPNGDataProvider</code> <code>source</code></a> property describes it as <code>a data provider supplying PNG encoded data</code>. I tried with some code like this but that doesn't work:</p>
  
  <pre><code>                 CGDataProviderRef dataProvider = NULL;
                   dataProvider = CGDataProviderCreateWithData(NULL,
                                                              (const void*)texture-&gt;pcData,
                                                               texture-&gt;mWidth,
                                                               rgbReleaseRampData);
                    if(dataProvider) {
                          NSLog(@" ********* Created image data provider ");
                    }
  
                    // fails at this line            
                    CGImageRef  imageRef =   CGImageCreateWithPNGDataProvider(dataProvider, 
                                               NULL,false, kCGRenderingIntentDefault);
  </code></pre>