Added support for autodetecting the system monitor color profile also on Linux
Code borrowed from Geeqie
This commit is contained in:
@@ -304,57 +304,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void findDefaultMonitorProfile()
|
|
||||||
{
|
|
||||||
// Determine the first monitor default profile of operating system, if selected
|
|
||||||
|
|
||||||
defaultMonitorProfile.clear();
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
// Get current main monitor. Could be fine tuned to get the current windows monitor(multi monitor setup),
|
|
||||||
// but problem is that we live in RTEngine with no GUI window to query around
|
|
||||||
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)) {
|
|
||||||
defaultMonitorProfile = Glib::ustring(profileName);
|
|
||||||
defaultMonitorProfile = Glib::path_get_basename(defaultMonitorProfile);
|
|
||||||
size_t pos = defaultMonitorProfile.rfind(".");
|
|
||||||
|
|
||||||
if (pos != Glib::ustring::npos) {
|
|
||||||
defaultMonitorProfile = defaultMonitorProfile.substr(0, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// might fail if e.g. the monitor has no profile
|
|
||||||
}
|
|
||||||
|
|
||||||
ReleaseDC(NULL, hDC);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
// TODO: Add other OS specific code here
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (options.rtSettings.verbose) {
|
|
||||||
printf("Default monitor profile is: %s\n", defaultMonitorProfile.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmsHPROFILE getDefaultMonitorProfile()
|
|
||||||
{
|
|
||||||
return getProfile(defaultMonitorProfile);
|
|
||||||
}
|
|
||||||
|
|
||||||
Glib::ustring getDefaultMonitorProfileName() const
|
|
||||||
{
|
|
||||||
return defaultMonitorProfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmsHPROFILE workingSpace(const Glib::ustring& name) const
|
cmsHPROFILE workingSpace(const Glib::ustring& name) const
|
||||||
{
|
{
|
||||||
const ProfileMap::const_iterator r = wProfiles.find(name);
|
const ProfileMap::const_iterator r = wProfiles.find(name);
|
||||||
@@ -628,21 +577,6 @@ void rtengine::ICCStore::init(const Glib::ustring& usrICCDir, const Glib::ustrin
|
|||||||
implementation->init(usrICCDir, stdICCDir, loadAll);
|
implementation->init(usrICCDir, stdICCDir, loadAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rtengine::ICCStore::findDefaultMonitorProfile()
|
|
||||||
{
|
|
||||||
implementation->findDefaultMonitorProfile();
|
|
||||||
}
|
|
||||||
|
|
||||||
cmsHPROFILE rtengine::ICCStore::getDefaultMonitorProfile() const
|
|
||||||
{
|
|
||||||
return implementation->getDefaultMonitorProfile();
|
|
||||||
}
|
|
||||||
|
|
||||||
Glib::ustring rtengine::ICCStore::getDefaultMonitorProfileName() const
|
|
||||||
{
|
|
||||||
return implementation->getDefaultMonitorProfileName();
|
|
||||||
}
|
|
||||||
|
|
||||||
cmsHPROFILE rtengine::ICCStore::workingSpace(const Glib::ustring& name) const
|
cmsHPROFILE rtengine::ICCStore::workingSpace(const Glib::ustring& name) const
|
||||||
{
|
{
|
||||||
return implementation->workingSpace(name);
|
return implementation->workingSpace(name);
|
||||||
|
@@ -68,11 +68,6 @@ public:
|
|||||||
|
|
||||||
void init(const Glib::ustring& usrICCDir, const Glib::ustring& stdICCDir, bool loadAll);
|
void init(const Glib::ustring& usrICCDir, const Glib::ustring& stdICCDir, bool loadAll);
|
||||||
|
|
||||||
// Main monitors standard profile name, from OS
|
|
||||||
void findDefaultMonitorProfile();
|
|
||||||
cmsHPROFILE getDefaultMonitorProfile() const;
|
|
||||||
Glib::ustring getDefaultMonitorProfileName() const;
|
|
||||||
|
|
||||||
cmsHPROFILE workingSpace(const Glib::ustring& name) const;
|
cmsHPROFILE workingSpace(const Glib::ustring& name) const;
|
||||||
cmsHPROFILE workingSpaceGamma(const Glib::ustring& name) const;
|
cmsHPROFILE workingSpaceGamma(const Glib::ustring& name) const;
|
||||||
TMatrix workingSpaceMatrix(const Glib::ustring& name) const;
|
TMatrix workingSpaceMatrix(const Glib::ustring& name) const;
|
||||||
|
@@ -41,7 +41,6 @@ int init (const Settings* s, Glib::ustring baseDir, Glib::ustring userSettingsDi
|
|||||||
{
|
{
|
||||||
settings = s;
|
settings = s;
|
||||||
ICCStore::getInstance()->init (s->iccDirectory, Glib::build_filename (baseDir, "iccprofiles"), loadAll);
|
ICCStore::getInstance()->init (s->iccDirectory, Glib::build_filename (baseDir, "iccprofiles"), loadAll);
|
||||||
ICCStore::getInstance()->findDefaultMonitorProfile();
|
|
||||||
DCPStore::getInstance()->init (Glib::build_filename (baseDir, "dcpprofiles"), loadAll);
|
DCPStore::getInstance()->init (Glib::build_filename (baseDir, "dcpprofiles"), loadAll);
|
||||||
|
|
||||||
CameraConstantsStore::getInstance ()->init (baseDir, userSettingsDir);
|
CameraConstantsStore::getInstance ()->init (baseDir, userSettingsDir);
|
||||||
|
@@ -71,6 +71,67 @@ int setprogressStrUI ( void *p )
|
|||||||
return FALSE;
|
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;
|
||||||
|
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 = "GDK_ICC_PROFILE";
|
||||||
|
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
|
class EditorPanel::ColorManagementToolbar
|
||||||
@@ -84,6 +145,7 @@ private:
|
|||||||
Gtk::ToggleButton spGamutCheck;
|
Gtk::ToggleButton spGamutCheck;
|
||||||
sigc::connection profileConn, intentConn, softproofConn;
|
sigc::connection profileConn, intentConn, softproofConn;
|
||||||
bool canSProof;
|
bool canSProof;
|
||||||
|
Glib::ustring defprof;
|
||||||
|
|
||||||
rtengine::StagedImageProcessor* const& processor;
|
rtengine::StagedImageProcessor* const& processor;
|
||||||
|
|
||||||
@@ -95,12 +157,13 @@ private:
|
|||||||
setExpandAlignProperties (&profileBox, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_FILL);
|
setExpandAlignProperties (&profileBox, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_FILL);
|
||||||
|
|
||||||
profileBox.append (M ("PREFERENCES_PROFILE_NONE"));
|
profileBox.append (M ("PREFERENCES_PROFILE_NONE"));
|
||||||
#ifdef WIN32
|
Glib::ustring defprofname;
|
||||||
profileBox.append (M ("MONITOR_PROFILE_SYSTEM") + " (" + rtengine::ICCStore::getInstance()->getDefaultMonitorProfileName() + ")");
|
if (find_default_monitor_profile(profileBox.get_root_window()->gobj(), defprof, defprofname)) {
|
||||||
profileBox.set_active (options.rtSettings.autoMonitorProfile ? 1 : 0);
|
profileBox.append (M ("MONITOR_PROFILE_SYSTEM") + " (" + defprofname + ")");
|
||||||
#else
|
profileBox.set_active (options.rtSettings.autoMonitorProfile ? 1 : 0);
|
||||||
profileBox.set_active (0);
|
} else {
|
||||||
#endif
|
profileBox.set_active (0);
|
||||||
|
}
|
||||||
const std::vector<Glib::ustring> profiles = rtengine::ICCStore::getInstance()->getProfiles (rtengine::ICCStore::ProfileType::MONITOR);
|
const std::vector<Glib::ustring> profiles = rtengine::ICCStore::getInstance()->getProfiles (rtengine::ICCStore::ProfileType::MONITOR);
|
||||||
for (const auto profile: profiles) {
|
for (const auto profile: profiles) {
|
||||||
profileBox.append (profile);
|
profileBox.append (profile);
|
||||||
@@ -174,21 +237,17 @@ private:
|
|||||||
Glib::ustring profile;
|
Glib::ustring profile;
|
||||||
|
|
||||||
#if !defined(__APPLE__) // monitor profile not supported on apple
|
#if !defined(__APPLE__) // monitor profile not supported on apple
|
||||||
#ifdef WIN32
|
if (!defprof.empty() && profileBox.get_active_row_number () == 1) {
|
||||||
if (profileBox.get_active_row_number () == 1) {
|
profile = defprof;
|
||||||
profile = rtengine::ICCStore::getInstance()->getDefaultMonitorProfileName ();
|
|
||||||
if (profile.empty ()) {
|
if (profile.empty ()) {
|
||||||
profile = options.rtSettings.monitorProfile;
|
profile = options.rtSettings.monitorProfile;
|
||||||
}
|
}
|
||||||
if (profile.empty ()) {
|
if (profile.empty ()) {
|
||||||
profile = "sRGB IEC61966-2.1";
|
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 ();
|
profile = profileBox.get_active_text ();
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
profile = profileBox.get_active_row_number () > 0 ? profileBox.get_active_text () : Glib::ustring ();
|
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
profile = "RT_sRGB";
|
profile = "RT_sRGB";
|
||||||
#endif
|
#endif
|
||||||
@@ -342,15 +401,11 @@ public:
|
|||||||
#if !defined(__APPLE__) // monitor profile not supported on apple
|
#if !defined(__APPLE__) // monitor profile not supported on apple
|
||||||
ConnectionBlocker profileBlocker (profileConn);
|
ConnectionBlocker profileBlocker (profileConn);
|
||||||
|
|
||||||
#ifdef WIN32
|
if (!defprof.empty() && options.rtSettings.autoMonitorProfile) {
|
||||||
if (options.rtSettings.autoMonitorProfile) {
|
|
||||||
setActiveTextOrIndex (profileBox, options.rtSettings.monitorProfile, 1);
|
setActiveTextOrIndex (profileBox, options.rtSettings.monitorProfile, 1);
|
||||||
} else {
|
} else {
|
||||||
setActiveTextOrIndex (profileBox, options.rtSettings.monitorProfile, 0);
|
setActiveTextOrIndex (profileBox, options.rtSettings.monitorProfile, 0);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
setActiveTextOrIndex (profileBox, options.rtSettings.monitorProfile, 0);
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (options.rtSettings.monitorIntent) {
|
switch (options.rtSettings.monitorIntent) {
|
||||||
|
@@ -756,11 +756,11 @@ Gtk::Widget* Preferences::getColorManagementPanel ()
|
|||||||
setExpandAlignProperties(monBPC, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
|
setExpandAlignProperties(monBPC, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
|
||||||
monBPC->set_active (true);
|
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")));
|
cbAutoMonProfile = Gtk::manage (new Gtk::CheckButton (M("PREFERENCES_AUTOMONPROFILE")));
|
||||||
setExpandAlignProperties(cbAutoMonProfile, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
|
setExpandAlignProperties(cbAutoMonProfile, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
|
||||||
autoMonProfileConn = cbAutoMonProfile->signal_toggled().connect (sigc::mem_fun(*this, &Preferences::autoMonProfileToggled));
|
autoMonProfileConn = cbAutoMonProfile->signal_toggled().connect (sigc::mem_fun(*this, &Preferences::autoMonProfileToggled));
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
gmonitor->attach (*mplabel, 0, row, 1, 1);
|
gmonitor->attach (*mplabel, 0, row, 1, 1);
|
||||||
@@ -772,18 +772,18 @@ Gtk::Widget* Preferences::getColorManagementPanel ()
|
|||||||
gmonitor->attach (*monProfile, 1, row, 1, 1);
|
gmonitor->attach (*monProfile, 1, row, 1, 1);
|
||||||
#endif
|
#endif
|
||||||
++row;
|
++row;
|
||||||
#if defined(WIN32)
|
//#if defined(WIN32)
|
||||||
gmonitor->attach (*cbAutoMonProfile, 1, row, 1, 1);
|
gmonitor->attach (*cbAutoMonProfile, 1, row, 1, 1);
|
||||||
++row;
|
++row;
|
||||||
#endif
|
//#endif
|
||||||
gmonitor->attach (*milabel, 0, row, 1, 1);
|
gmonitor->attach (*milabel, 0, row, 1, 1);
|
||||||
gmonitor->attach (*monIntent, 1, row, 1, 1);
|
gmonitor->attach (*monIntent, 1, row, 1, 1);
|
||||||
++row;
|
++row;
|
||||||
gmonitor->attach (*monBPC, 0, row, 2, 1);
|
gmonitor->attach (*monBPC, 0, row, 2, 1);
|
||||||
|
|
||||||
#if defined(WIN32)
|
//#if defined(WIN32)
|
||||||
autoMonProfileToggled();
|
autoMonProfileToggled();
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
fmonitor->add(*gmonitor);
|
fmonitor->add(*gmonitor);
|
||||||
|
|
||||||
@@ -830,9 +830,9 @@ Gtk::Widget* Preferences::getColorManagementPanel ()
|
|||||||
++row;
|
++row;
|
||||||
gprinter->attach (*prtBPC, 0, row, 2, 1);
|
gprinter->attach (*prtBPC, 0, row, 2, 1);
|
||||||
|
|
||||||
#if defined(WIN32)
|
//#if defined(WIN32)
|
||||||
autoMonProfileToggled();
|
autoMonProfileToggled();
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
fprinter->add(*gprinter);
|
fprinter->add(*gprinter);
|
||||||
|
|
||||||
@@ -1677,9 +1677,9 @@ void Preferences::storePreferences ()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
moptions.rtSettings.monitorBPC = monBPC->get_active ();
|
moptions.rtSettings.monitorBPC = monBPC->get_active ();
|
||||||
#if defined(WIN32)
|
//#if defined(WIN32)
|
||||||
moptions.rtSettings.autoMonitorProfile = cbAutoMonProfile->get_active ();
|
moptions.rtSettings.autoMonitorProfile = cbAutoMonProfile->get_active ();
|
||||||
#endif
|
//#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
moptions.rtSettings.iccDirectory = iccDir->get_filename ();
|
moptions.rtSettings.iccDirectory = iccDir->get_filename ();
|
||||||
@@ -1825,9 +1825,9 @@ void Preferences::fillPreferences ()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
monBPC->set_active (moptions.rtSettings.monitorBPC);
|
monBPC->set_active (moptions.rtSettings.monitorBPC);
|
||||||
#if defined(WIN32)
|
//#if defined(WIN32)
|
||||||
cbAutoMonProfile->set_active(moptions.rtSettings.autoMonitorProfile);
|
cbAutoMonProfile->set_active(moptions.rtSettings.autoMonitorProfile);
|
||||||
#endif
|
//#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (Glib::file_test (moptions.rtSettings.iccDirectory, Glib::FILE_TEST_IS_DIR)) {
|
if (Glib::file_test (moptions.rtSettings.iccDirectory, Glib::FILE_TEST_IS_DIR)) {
|
||||||
@@ -2033,12 +2033,12 @@ void Preferences::savePressed () {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(WIN32)
|
//#if defined(WIN32)
|
||||||
void Preferences::autoMonProfileToggled ()
|
void Preferences::autoMonProfileToggled ()
|
||||||
{
|
{
|
||||||
monProfile->set_sensitive(!cbAutoMonProfile->get_active());
|
monProfile->set_sensitive(!cbAutoMonProfile->get_active());
|
||||||
}
|
}
|
||||||
#endif
|
//#endif
|
||||||
/*
|
/*
|
||||||
void Preferences::autocielabToggled () {
|
void Preferences::autocielabToggled () {
|
||||||
// cbAutocielab->set_sensitive(cbAutocielab->get_active());
|
// cbAutocielab->set_sensitive(cbAutocielab->get_active());
|
||||||
|
Reference in New Issue
Block a user