-
Notifications
You must be signed in to change notification settings - Fork 806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force all loaded textures to 32bpp in GLKit #2165
Force all loaded textures to 32bpp in GLKit #2165
Conversation
…/creation via converting the images to the correct format
Frameworks/GLKit/GLKTexture.mm
Outdated
+ (GLKTextureInfo*)textureWithContentsOfFile:(NSString*)fname options:(NSDictionary*)opts error:(NSError**)err { | ||
CGDataProviderRef provider = CGDataProviderCreateWithFilename([fname UTF8String]); | ||
CGImageRef img = _CGImageCreateFromDataProvider(provider); | ||
static inline CGImageRef __Create32bppPRGBAImageFromFile(NSString* fname) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_CGImageCreateFromFileWithFormat(name, format) and export it from CG? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need like we are bloating CG. we already have an internal method, and we keep on building on top of it for every case. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but i'll go ahead and make that change #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CG has 600+ apis :). What belongs there has to belong there... #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if you do make this API, please perhaps call it _CGImageCreateFromFileWithWICFormat
-- specifically, we need to differentiate it from the CGBitmapInfo/CGAlphaInfo APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it'll have to take a CFStringRef.
Frameworks/GLKit/GLKTexture.mm
Outdated
+ (GLKTextureInfo*)textureWithCGImage:(CGImageRef)image options:(NSDictionary*)opts error:(NSError**)err { | ||
woc::StrongCF<CGImageRef> img = { woc::MakeStrongCF(_CGImageCreateCopyWithPixelFormat(image, GUID_WICPixelFormat32bppPRGBA)) }; | ||
|
||
if (!img) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no macro here?
Frameworks/GLKit/GLKTexture.mm
Outdated
+ (GLKTextureInfo*)textureWithContentsOfFile:(NSString*)fname options:(NSDictionary*)opts error:(NSError**)err { | ||
CGDataProviderRef provider = CGDataProviderCreateWithFilename([fname UTF8String]); | ||
CGImageRef img = _CGImageCreateFromDataProvider(provider); | ||
static inline CGImageRef __Create32bppPRGBAImageFromFile(NSString* fname) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if you do make this API, please perhaps call it _CGImageCreateFromFileWithWICFormat
-- specifically, we need to differentiate it from the CGBitmapInfo/CGAlphaInfo APIs.
Frameworks/GLKit/GLKTexture.mm
Outdated
+ (GLKTextureInfo*)textureWithContentsOfFile:(NSString*)fname options:(NSDictionary*)opts error:(NSError**)err { | ||
CGDataProviderRef provider = CGDataProviderCreateWithFilename([fname UTF8String]); | ||
CGImageRef img = _CGImageCreateFromDataProvider(provider); | ||
static inline CGImageRef __Create32bppPRGBAImageFromFile(NSString* fname) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it'll have to take a CFStringRef.
Frameworks/GLKit/GLKTexture.mm
Outdated
return nil; | ||
} | ||
|
||
CGDataProviderRelease(provider); | ||
provider = CGImageGetDataProvider(img); | ||
CGDataProviderRef provider = CGImageGetDataProvider(img); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are fixing this code, you might as well make it use _CGDataProviderGetBytes
.
Also nit: When you merge this, please fix the name to be |
I have renamed this pull request. Please add "Fixes #2150." |
I think taking in char * would be fine, given that's what CGDataProviderCreateWithFilename takes not. |
@msft-Jeyaram please do not do that. We have strong, expressive string types for a reason. NSString is bridged directly to CFStringRef; unless you want to deal with UTF8<->UTF16 issues like #1875 and #1891 I would implore you to use CFString. |
fixes #2150 |
Frameworks/CoreGraphics/CGImage.mm
Outdated
|
||
RETURN_NULL_IF(!fname); | ||
|
||
woc::StrongCF<CGDataProviderRef> provider{ woc::MakeStrongCF(CGDataProviderCreateWithFilename(fname)) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: these can be "auto provider = "
NSData* data = (id)CGDataProviderCopyData(provider); | ||
[data autorelease]; | ||
auto bytesIn = (unsigned char*)[data bytes]; | ||
unsigned char* bytesIn = static_cast<unsigned char*>(const_cast<void*>(_CGDataProviderGetData(CGImageGetDataProvider(img)))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: a c-style cast from const void* -> char* should suffice
Frameworks/CoreGraphics/CGImage.mm
Outdated
CGImageRef _CGImageCreateFromFileWithWICFormat(CFStringRef filename, WICPixelFormatGUID format) { | ||
RETURN_NULL_IF(!filename); | ||
|
||
std::vector<char> buffer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second look, we'd be better off here creating a CFURL from the filename and using CGDataProviderCreateWithURL, because that's what CGDataProviderCreateWithFilename goes through, and we get the added bonus of not creating an extra CFStringRef as well as cutting down on the length of this function quite a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here was me thinking it was the other way around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😃
GLKit's implementation of GLKTexture only handled an image format of 32bpp properly (other formats e.g 8bpp indexed,etc) was not handled properly (the code was never exercised).
The root cause of this was that the earlier Cairo implementation treated every image as a 32bpp. Thus when we created an image with it's proper pixel format, GLKTexture code didn't know how to handle it and thus the errors were produced.
fixes #2150
The fix converts the images to 32bpp, since GLKTexture does not support any other format properly.
Eventually, GLKTexure needs to be re-written properly.
Current Stage: