GNOME Bugzilla – Bug 488170
use system monitor profile on OSX
Last modified: 2007-10-30 15:16:26 UTC
The lcms display filter which is responsible for color-correction of the image window in GIMP 2.4 currently has code to retrieve the system monitor profile on the X11 and Windows platforms. We should also add code to do this on Mac OSX. I will attach a patch that I cooked up after looking at Oyranos (http://www.oyranos.org/) and consulting the ColorSync documentation offered by Apple (http://developer.apple.com/documentation/GraphicsImaging/Reference/ColorSync_Manager/). Since I don't have access to an OSX system, I cannot even attempt to compile this code. Someone should test it, fix it if necessary and try if it does the right thing.
Created attachment 97463 [details] [review] attempt to implement retrieval of the system monitor profile on OSX
I would like to get this in for 2.4. If we can't test it before 2.4.0, then we should consider adding it for 2.4.1. If it turns out to be more difficult we can still bump it to 2.6.
Hi, I tested the patch and it currently does not compile because the correct headers are not included : #if defined GDK_WINDOWING_QUARTZ #include <Carbon/Carbon.h> #include <ApplicationServices/ApplicationServices.h> #include <CoreServices/CoreServices.h> #endif I will attach a patch that makes it compile correctly and run without error. However i am currently unable to test whether it works because i have no yet got around to learning how gimp deals with cms on a stable platform and as such i do not know how to test such feature.
Created attachment 97683 [details] [review] Added correct includes to patch so it compiles
Thanks for fixing the patch. I wonder if it is safe to include ApplicationServices.h and CoreServices.h or if we need to check for their presence. The GDK Quartz backend seems to include ApplicationServices.h, so that should be fine. Will CoreServices.h be available on all Mac OS X systems?
All includes i added are present on all Mac OS X systems (and, further than that, cannot be removed without breaking the system) what somewhat suprised me is that i did not have to set the header search paths, but i suppose it works because GTD-quartz does set them. (I checked quickly in the color management section of the preferences but did not see anything different - should have something appeared? Or perhaps i need to reset the preference files before it takes effect?)
If you have a system monitor profile, you should see it shown in the Color Management display filter. Make sure you have "Color Managed Display" enabled in the Preferences, then open an image and go to View->Display Filters. You should see the Color Management display filter there and if you select it, the dialog should display the names of the profiles it uses.
To explain this further, the idea here is that you don't configure a monitor profile in GIMP, only enable the "Use system monitor profile" check-box. The display filter should then use the system-wide configured profile.
Ok i see let's try. In the preferences, "Color Managed Display" and "Use system monitor profile" are both checked. I then go to "View->Display Filters". "Color management" is in "active filters" section and checked. When i click on it, all the profiles in the info read "none". It does not seem to work at all, since when i select my monitor's profile manually i see a visual change, but when using the automatic profile detection i do not. Further investigation showed that cdisplay_lcms_get_screen returns 'monitor' as '0', because 'GTK_WIDGET_DRAWABLE (managed)' returns false. This may need to be discussed with the gtk-mac developers as i myself do not know GTK (unless you have directives or a patch i can try). Fortunately, mac users can probably find their profile in directory /Library/ColorSync/Profiles/Displays/ (i have not searched for documentation saying it is supposed to be there, i just found mine there.)
I would also like to mention i only tested the code with the GTK-quartz backend and not with the X11.app version, that may act differently since this port is more stable.
0 is the correct value for a single-monitor configuration. GTK_WIDGET_DRAWABLE (managed) should have be TRUE though. The question is whether the monitor number is the correct value to pass to CMGetProfileByAVID(). If it is, and CMGetProfileByAVID() doesn't receive a profile handle, then it looks as if your system doesn't have a system-wide monitor profile set.
I have a monitor profile set in the system preferences (it's set by default) unless ColorSync expects soemthing else i can't think about. It may be needed to deal this issue with a more knowledgeable mac programmer - but there's still one thing i can confirm, is that 'CMGetProfileByAVID' returns '0' wich means 'no error'. (On a side note, for some reason when i tried it again today 'GTK_IS_WIDGET (managed)' did not return false anymore... i'm a bit puzzled as to why the same code may run differently today than yesterday but i guess these issues can be sorted out when the mac port of GTK becomes stable if they are still there.)
For the interest that anyone that may want to look into this, i suggest looking at: http://developer.apple.com/documentation/mac/ACIReference/ACIReference-162.html from my experiments, it would seem like the 'lcms_cdisplay_lcms_flatten_profile' function will not be called once, but several times and must act a bit like a stream. The first time the function is called, only 128 bytes are given, and it seems like write is called 3 times before the data is completely sent in. I will try to make it work.
Created attachment 98129 [details] [review] Patch to get CMS auto-detect profile on OS X (works on my computer) Ok i got it working! Patch attached. (It's probably not on par with your coding standards, however. also i'm not very used to working in C so i may have done something wrong. but at least the base is there to build upon)
Very nice, thank you. This will need some changes to conform to our coding standards but I hope that Mitch can do this and commit the patch in time for 2.4.1.
Created attachment 98148 [details] [review] Same as previous one but with a memory leak fixed Hi, i re-read the code i had written and found a memory leak in it - fixed.
Created attachment 98157 [details] [review] cleaned up patch This is a cleaned up version of your patch. I am afraid though that it needs further work. The use of static variables to track the state of the flatten process is unacceptable. I will have a look at this again later.
Created attachment 98172 [details] [review] cleaned up patch that avoids the use of global variables Please test if this patch compiles and works for you.
Created attachment 98175 [details] [review] Patch that compiles
It seems to load the profile from the system correctly. At least i can see the name of my configured profile in the filter config UI and the display clearly changes when i enable/disable the filter. Please commit that latest patch.
Fixed in SVN: 2007-10-30 Michael Natterer <mitch@gimp.org> * modules/cdisplay_lcms.c: applied patch from Sven Neumann and Marianne Gagnon which adds support for getting the system monitor profile on OS/X. Fixes bug #488170.