Text archives Help
- From: arobison@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [Manta] r1998 - trunk/Image
- Date: Tue, 22 Jan 2008 22:22:40 -0700 (MST)
Author: arobison
Date: Tue Jan 22 22:22:38 2008
New Revision: 1998
Modified:
trunk/Image/CoreGraphicsFile.cc
Log:
The CoreGraphics image loader now loads the system sRGB ICC profile instead
of relying on
the SDK to provide a colorspace for input images. This code should work on
both 10.4 and 10.5.
Modified: trunk/Image/CoreGraphicsFile.cc
==============================================================================
--- trunk/Image/CoreGraphicsFile.cc (original)
+++ trunk/Image/CoreGraphicsFile.cc Tue Jan 22 22:22:38 2008
@@ -61,12 +61,19 @@
bytes_per_row = (w * 4 * sizeof(float));
byte_count = bytes_per_row * h;
-#ifdef APPLE_LEOPARD
- color_space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
-#else
- color_space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
-#endif
+ // Load the sRGB profile from file since 10.4 does not support a direct
sRGB profile
+ // defaults to a generic RGB space if the file does not exist
+ CGColorSpaceRef alternate =
CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
+ CFURLRef icc_profile_path =
+ CFURLCreateWithFileSystemPath( NULL,
+
CFSTR("/System/Library/ColorSync/Profiles/sRGB Profile.icc"),
+ kCFURLPOSIXPathStyle, false);
+ CGDataProviderRef icc_profile =
CGDataProviderCreateWithURL(icc_profile_path);
+ const CGFloat range[] = {0,1,0,1,0,1}; // min/max of the three components
+ color_space = CGColorSpaceCreateICCBased( 3, range, icc_profile,
alternate );
+
if(color_space == NULL) {
+ CGDataProviderRelease(icc_profile);
throw InternalError("Could not create CoreGraphics bitmap context");
}
@@ -80,7 +87,13 @@
kCGBitmapByteOrder32Host);
- CGColorSpaceRelease(color_space);
+ CGDataProviderRelease(icc_profile);
+ if(color_space == alternate) {
+ CGColorSpaceRelease(alternate);
+ } else {
+ CGColorSpaceRelease(color_space);
+ CGColorSpaceRelease(alternate);
+ }
return context;
}
- [Manta] r1998 - trunk/Image, arobison, 01/23/2008
Archive powered by MHonArc 2.6.16.