I am using Assimp and when using FBX with embedded textures, Assimp provides the embedded texture data in the following struct aiTexture's pcData slot. The documentation for pcData says:
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
I understand that pcData will have the png header, chunks etc and libPNG can give me back the actual image data with other specs (width, height etc).
What is the native iOS/macOS API to do this instead of using libPNG?
For example: CGImageCreateWithPNGDataProvider source property describes it as a data provider supplying PNG encoded data. I tried with some code like this but that doesn't work:
CGDataProviderRef dataProvider = NULL;
dataProvider = CGDataProviderCreateWithData(NULL,
(const void*)texture->pcData,
texture->mWidth,
rgbReleaseRampData);
if(dataProvider) {
NSLog(@" ********* Created image data provider ");
}
// fails at this line
CGImageRef imageRef = CGImageCreateWithPNGDataProvider(dataProvider,
NULL,false, kCGRenderingIntentDefault);
Well, at least for iOS/macOS; it seems to be a problem with the
assimplibrary.The following, if not the perfect fix, works:
adding a
uint_8to hold raw image data intexture.h:Then reinterpret the
pcDatainFBXConverter.cppas such:fixes the above problem. Without reinterpreting the
pcData, in iOS/macOS one gets the invalid memory address for the memory buffer.With the above fix, generating an image object requires only the following:
The GH Issue.