Merge pull request #3810 from Beep6581/autodetect-monitor-profile-linux

Added support for autodetecting the system monitor color profile also on Linux
This commit is contained in:
Alberto Griggio
2017-04-12 14:00:41 +02:00
committed by GitHub
5 changed files with 87 additions and 104 deletions

View File

@@ -71,6 +71,67 @@ int setprogressStrUI ( void *p )
return FALSE;
}
bool find_default_monitor_profile(GdkWindow *rootwin, Glib::ustring &defprof, Glib::ustring &defprofname)
{
#ifdef WIN32
HDC hDC = GetDC(nullptr);
if (hDC != nullptr) {
if (SetICMMode(hDC, ICM_ON)) {
char profileName[MAX_PATH + 1];
DWORD profileLength = MAX_PATH;
if (GetICMProfileA(hDC, &profileLength, profileName)) {
defprof = Glib::ustring(profileName);
defprofname = Glib::path_get_basename(defprof);
size_t pos = defprofname.rfind(".");
if (pos != Glib::ustring::npos) {
defprofname = defprofname.substr(0, pos);
}
defprof = Glib::ustring("file:") + defprof;
return true;
}
// might fail if e.g. the monitor has no profile
}
ReleaseDC(NULL, hDC);
}
#elif !defined(__APPLE__)
// taken from geeqie (image.c) and adapted
// Originally licensed as GPL v2+, with the following copyright:
// * Copyright (C) 2006 John Ellis
// * Copyright (C) 2008 - 2016 The Geeqie Team
//
guchar *prof = nullptr;
gint proflen;
GdkAtom type = GDK_NONE;
gint format = 0;
if (gdk_property_get(rootwin, gdk_atom_intern("_ICC_PROFILE", FALSE), GDK_NONE, 0, 64 * 1024 * 1024, FALSE, &type, &format, &proflen, &prof) && proflen > 0) {
cmsHPROFILE p = cmsOpenProfileFromMem(prof, proflen);
if (p) {
defprofname = "from GDK";
defprof = Glib::build_filename(Options::rtdir, "GDK_ICC_PROFILE.icc");
if (cmsSaveProfileToFile(p, defprof.c_str())) {
cmsCloseProfile(p);
if (prof) {
g_free(prof);
}
defprof = Glib::ustring("file:") + defprof;
return true;
}
}
}
if (prof) {
g_free(prof);
}
#endif
return false;
}
}
class EditorPanel::ColorManagementToolbar
@@ -84,6 +145,7 @@ private:
Gtk::ToggleButton spGamutCheck;
sigc::connection profileConn, intentConn, softproofConn;
bool canSProof;
Glib::ustring defprof;
rtengine::StagedImageProcessor* const& processor;
@@ -95,12 +157,13 @@ private:
setExpandAlignProperties (&profileBox, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_FILL);
profileBox.append (M ("PREFERENCES_PROFILE_NONE"));
#ifdef WIN32
profileBox.append (M ("MONITOR_PROFILE_SYSTEM") + " (" + rtengine::ICCStore::getInstance()->getDefaultMonitorProfileName() + ")");
profileBox.set_active (options.rtSettings.autoMonitorProfile ? 1 : 0);
#else
profileBox.set_active (0);
#endif
Glib::ustring defprofname;
if (find_default_monitor_profile(profileBox.get_root_window()->gobj(), defprof, defprofname)) {
profileBox.append (M ("MONITOR_PROFILE_SYSTEM") + " (" + defprofname + ")");
profileBox.set_active (options.rtSettings.autoMonitorProfile ? 1 : 0);
} else {
profileBox.set_active (0);
}
const std::vector<Glib::ustring> profiles = rtengine::ICCStore::getInstance()->getProfiles (rtengine::ICCStore::ProfileType::MONITOR);
for (const auto profile: profiles) {
profileBox.append (profile);
@@ -174,21 +237,17 @@ private:
Glib::ustring profile;
#if !defined(__APPLE__) // monitor profile not supported on apple
#ifdef WIN32
if (profileBox.get_active_row_number () == 1) {
profile = rtengine::ICCStore::getInstance()->getDefaultMonitorProfileName ();
if (!defprof.empty() && profileBox.get_active_row_number () == 1) {
profile = defprof;
if (profile.empty ()) {
profile = options.rtSettings.monitorProfile;
}
if (profile.empty ()) {
profile = "sRGB IEC61966-2.1";
}
} else if (profileBox.get_active_row_number () > 1) {
} else if (profileBox.get_active_row_number () > 0) {
profile = profileBox.get_active_text ();
}
#else
profile = profileBox.get_active_row_number () > 0 ? profileBox.get_active_text () : Glib::ustring ();
#endif
#else
profile = "RT_sRGB";
#endif
@@ -342,15 +401,11 @@ public:
#if !defined(__APPLE__) // monitor profile not supported on apple
ConnectionBlocker profileBlocker (profileConn);
#ifdef WIN32
if (options.rtSettings.autoMonitorProfile) {
if (!defprof.empty() && options.rtSettings.autoMonitorProfile) {
setActiveTextOrIndex (profileBox, options.rtSettings.monitorProfile, 1);
} else {
setActiveTextOrIndex (profileBox, options.rtSettings.monitorProfile, 0);
}
#else
setActiveTextOrIndex (profileBox, options.rtSettings.monitorProfile, 0);
#endif
#endif
switch (options.rtSettings.monitorIntent) {

View File

@@ -756,11 +756,11 @@ Gtk::Widget* Preferences::getColorManagementPanel ()
setExpandAlignProperties(monBPC, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
monBPC->set_active (true);
#if defined(WIN32) // Auto-detection not implemented for Linux, see issue 851
//#if defined(WIN32) // Auto-detection not implemented for Linux, see issue 851
cbAutoMonProfile = Gtk::manage (new Gtk::CheckButton (M("PREFERENCES_AUTOMONPROFILE")));
setExpandAlignProperties(cbAutoMonProfile, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
autoMonProfileConn = cbAutoMonProfile->signal_toggled().connect (sigc::mem_fun(*this, &Preferences::autoMonProfileToggled));
#endif
//#endif
int row = 0;
gmonitor->attach (*mplabel, 0, row, 1, 1);
@@ -772,18 +772,18 @@ Gtk::Widget* Preferences::getColorManagementPanel ()
gmonitor->attach (*monProfile, 1, row, 1, 1);
#endif
++row;
#if defined(WIN32)
//#if defined(WIN32)
gmonitor->attach (*cbAutoMonProfile, 1, row, 1, 1);
++row;
#endif
//#endif
gmonitor->attach (*milabel, 0, row, 1, 1);
gmonitor->attach (*monIntent, 1, row, 1, 1);
++row;
gmonitor->attach (*monBPC, 0, row, 2, 1);
#if defined(WIN32)
//#if defined(WIN32)
autoMonProfileToggled();
#endif
//#endif
fmonitor->add(*gmonitor);
@@ -830,9 +830,9 @@ Gtk::Widget* Preferences::getColorManagementPanel ()
++row;
gprinter->attach (*prtBPC, 0, row, 2, 1);
#if defined(WIN32)
//#if defined(WIN32)
autoMonProfileToggled();
#endif
//#endif
fprinter->add(*gprinter);
@@ -1676,9 +1676,9 @@ void Preferences::storePreferences ()
break;
}
moptions.rtSettings.monitorBPC = monBPC->get_active ();
#if defined(WIN32)
//#if defined(WIN32)
moptions.rtSettings.autoMonitorProfile = cbAutoMonProfile->get_active ();
#endif
//#endif
#endif
moptions.rtSettings.iccDirectory = iccDir->get_filename ();
@@ -1824,9 +1824,9 @@ void Preferences::fillPreferences ()
break;
}
monBPC->set_active (moptions.rtSettings.monitorBPC);
#if defined(WIN32)
//#if defined(WIN32)
cbAutoMonProfile->set_active(moptions.rtSettings.autoMonitorProfile);
#endif
//#endif
#endif
if (Glib::file_test (moptions.rtSettings.iccDirectory, Glib::FILE_TEST_IS_DIR)) {
@@ -2032,12 +2032,12 @@ void Preferences::savePressed () {
}
*/
#if defined(WIN32)
//#if defined(WIN32)
void Preferences::autoMonProfileToggled ()
{
monProfile->set_sensitive(!cbAutoMonProfile->get_active());
}
#endif
//#endif
/*
void Preferences::autocielabToggled () {
// cbAutocielab->set_sensitive(cbAutocielab->get_active());