Reputation: 2085
When I try to load certain textures into my opengl app I get an unsupported color space errors for seemingly compressed .png files.
If I right click and examine the textures that fail, they have the following property.
color profile: sRGB IEC61966-2.1
The .png appears to get this property when it's compressed. I would really like to have this feature because it reduces the texture size by ~50%.
Here is my texture loading code:
-(GLubyte *) generatePixelDataFromImage: (UIImage *) pic{
GLubyte *pixelData = (GLubyte *) calloc(width * height *4, sizeof(GLubyte));
CGColorSpaceRef imageCS = CGImageGetColorSpace(pic.CGImage);
CGBitmapInfo bitmapInfo = (CGBitmapInfo) kCGImageAlphaPremultipliedLast;
CGContextRef gc = CGBitmapContextCreate(pixelData, width, height, 8, width*4, imageCS, bitmapInfo);
CGContextDrawImage(gc, CGRectMake(0, 0, width, height), pic.CGImage);
CGContextRelease(gc);
return pixelData;
}
Here is the error:
Error: CGBitmapContextCreate: unsupported color space. Feb 14 13:11:59 Garretts-iPhone myApp[712] : CGContextDrawImage: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Is there anyway to convert the texture programmatically whilst still having the benefit of reduced storage space?
Upvotes: 0
Views: 966
Reputation: 385590
From the Quartz 2D Programming Guide:
Important: iOS does not support device-independent or generic color spaces. iOS applications must use device color spaces instead.
Have you tried just using CGColorSpaceCreateDeviceRGB
as the color space? Does it look ok?
Upvotes: 5