ImageIO.framework has supported OpenEXR for many major releases now. If you are just trying to get RGBA content up on the screen or loaded into one of these other frameworks, the CGImageSourceRef should be your first stop. It works just like for JPEGs, TIFFs, and such. For example, in this case, we draw the image into a CG context:
Code Block #include <ImageIO/ImageIO.h> |
#include <CoreGraphics/CoreGraphics.h> |
|
const char * path_to_file = ...; |
CFStringRef s = CFStringCreateWithCString(NULL, path_to_file, kCFStringEncodingUTF8 ); |
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, s, kCFURLPOSIXPathStyle, false); |
CFRelease(s); |
|
CGImageSourceRef source = CGImageSourceCreateWithURL( url, NULL); |
CFRelease(url); |
|
CGImageRef image = CGImageSourceCreateImageAtIndex(source, 0, NULL); |
CFRelease(source); |
|
CGContextRef context = CGBitmapContextCreate( NULL, |
CGImageGetWidth(image), |
CGImageGetHeight(image), |
16, |
CGImageGetWidth(image) * 8, // 8 = 4 channels * 16bit/chan RGBA |
CGColorSpaceCreateDeviceRGB(), |
kCGBitmapByteOrder16Host | kCGImageAlphaPremultipliedLast | kCGBitmapFloatComponents ); |
|
CGRect where = CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image)); |
CGContextClearRect( context, where); |
CGContextDrawImage( context, where, image); |
CGContextFlush(context); |
|
CGImageRelease(image); |
CGContextRelease(context); |
__________________
New in Big Sur, we've replaced ImageIO's underlying OpenEXR implementation with an Apple developed library, AppleEXR. It is accelerated for Neon (Apple Silicon) and AVX2 (Intel) and uses GCD. It is also available on iOS, iPadOS, watchOS and tvOS. You may find it is quite a bit faster than the ImageIO EXR plugin that was there before. It has a C interface so that it is callable from C/C++/ObjC/Swift as API and supports ARC:
#include <AppleEXR.h> <== /usr/include/AppleEXR.h
link: -lAppleEXR <== /usr/bin/libAppleEXR.dylib
It is exposed to provide more direct access to lower level features in the OpenEXR file format important to some apps. The file format is extremely flexible and not all of its feature set fits entirely under the CoreGraphics / ImageIO feature space.
It is not source level compatible with the Academy Software Foundation's OpenEXR implementation, just file format compatible, so some refactoring of your preexisting OpenEXR code would be needed to use it if you had any. (OpenEXR has a C++ interface which can be challenging to export stably over the long term as a dynamic library.) Relevant documentation is in the C version of the header. AppleEXR.h is annotated in Doxygen style, so you might be able to get something nice with the Doxygen tool, though I will confess that as of the WWDC release, I have not yet made it a priority to make the Doxygen output looking pretty. AppleEXR presumes some basic knowledge of the OpenEXR file format or experience with OpenEXR, so for most developers, I would start with CGImageSourceRef first and then drill down if you can't get what you need out of it.
For more details on OpenEXR itself and the file format features, you may visit the Academy Software foundation website at OpenEXR dot com / documentation.html