diff --git a/rtdata/languages/default b/rtdata/languages/default index c27e3fb3a..07e9ea372 100644 --- a/rtdata/languages/default +++ b/rtdata/languages/default @@ -478,6 +478,7 @@ PARTIALPASTE_WHITEBALANCE;White balance POPUPBUTTON_SELECTOPTIONHINT;RMB to change option PREFERENCES_ADD;ADD PREFERENCES_APPLNEXTSTARTUP;restart required +PREFERENCES_AUTOMONPROFILE;Automatically use operating systems main monitors profile PREFERENCES_BATCH_PROCESSING;Batch Processing PREFERENCES_BEHAVIOR;Behavior PREFERENCES_BLINKCLIPPED;Blink clipped areas diff --git a/rtengine/iccstore.cc b/rtengine/iccstore.cc index c5cb6cff5..87c8901b5 100644 --- a/rtengine/iccstore.cc +++ b/rtengine/iccstore.cc @@ -214,6 +214,32 @@ std::vector ICCStore::parseDir (Glib::ustring pdir) { return result; } +// Determine the first monitor default profile of operating system, if selected +void ICCStore::findDefaultMonitorProfile() { + defaultMonitorProfile=""; + +#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(NULL); + + if (hDC!=NULL) { + if (SetICMMode(hDC, ICM_ON)) { + char profileName[MAX_PATH+1]; DWORD profileLength=MAX_PATH; + if (GetICMProfileA(hDC,&profileLength,profileName)) defaultMonitorProfile=Glib::ustring(profileName); + // might fail if e.g. the monitor has no profile + } + + ReleaseDC(NULL,hDC); + } +#else +// TODO: Add other OS specific code here +printf("Automatic Monitor Profile Detection not supported on your OS\n"); +#endif + + if (options.rtSettings.verbose) printf("Default monitor profile is: %s\n", defaultMonitorProfile.c_str()); +} + ProfileContent::ProfileContent (Glib::ustring fileName) { data = NULL; diff --git a/rtengine/iccstore.h b/rtengine/iccstore.h index 5e67b55a7..2f311b69d 100644 --- a/rtengine/iccstore.h +++ b/rtengine/iccstore.h @@ -63,6 +63,9 @@ class ICCStore { static ICCStore* getInstance(void); + Glib::ustring defaultMonitorProfile; // Main monitors standard profile name, from OS + void findDefaultMonitorProfile(); + int numOfWProfiles (); cmsHPROFILE createFromMatrix (const double matrix[3][3], bool gamma=false, Glib::ustring name=""); cmsHPROFILE workingSpace (Glib::ustring name); diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index 37fe8099c..2f6fc4f88 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -195,7 +196,12 @@ void ImProcFunctions::firstAnalysis (Image16* original, const ProcParams* params if (monitorTransform) cmsDeleteTransform (monitorTransform); monitorTransform = NULL; - cmsHPROFILE monitor = iccStore->getProfile ("file:"+settings->monitorProfile); + + Glib::ustring monitorProfile=settings->monitorProfile; + if (settings->autoMonitorProfile) monitorProfile=iccStore->defaultMonitorProfile; + //if (settings->verbose) printf("Using monitor profile: %s\n", monitorProfile.c_str()); + + cmsHPROFILE monitor = iccStore->getProfile ("file:"+monitorProfile); if (monitor) { cmsHPROFILE iprof = iccStore->getXYZProfile (); cmsHPROFILE oprof = iccStore->getProfile (params->icm.output); diff --git a/rtengine/init.cc b/rtengine/init.cc index 51a411cb0..fce420697 100644 --- a/rtengine/init.cc +++ b/rtengine/init.cc @@ -36,6 +36,8 @@ int init (const Settings* s) { settings = s; iccStore->parseDir (s->iccDirectory); + iccStore->findDefaultMonitorProfile(); + CurveFactory::init (); ImProcFunctions::initCache (); Thumbnail::initGamma (); diff --git a/rtengine/settings.h b/rtengine/settings.h index 0f022664b..bd3c1f32a 100644 --- a/rtengine/settings.h +++ b/rtengine/settings.h @@ -28,6 +28,8 @@ namespace rtengine { Glib::ustring iccDirectory; ///< The directory containing the possible output icc profiles int colorimetricIntent; ///< Colorimetric intent used at color space conversions Glib::ustring monitorProfile; ///< ICC profile of the monitor (full path recommended) + bool autoMonitorProfile; ///< Try to auto-determine the correct monitor color profile + bool verbose; Glib::ustring darkFramesPath; ///< The default directory for dark frames Glib::ustring flatFieldsPath; ///< The default directory for flat fields diff --git a/rtgui/options.cc b/rtgui/options.cc index 80bcad79d..8d53bcb89 100644 --- a/rtgui/options.cc +++ b/rtgui/options.cc @@ -148,6 +148,8 @@ void Options::setDefaults () { #endif rtSettings.colorimetricIntent = 1; rtSettings.monitorProfile = ""; + rtSettings.autoMonitorProfile = false; + rtSettings.verbose = false; } @@ -303,6 +305,8 @@ if (keyFile.has_group ("Crop Settings")) { if (keyFile.has_group ("Color Management")) { if (keyFile.has_key ("Color Management", "ICCDirectory")) rtSettings.iccDirectory = keyFile.get_string ("Color Management", "ICCDirectory"); if (keyFile.has_key ("Color Management", "MonitorProfile")) rtSettings.monitorProfile = keyFile.get_string ("Color Management", "MonitorProfile"); + if (keyFile.has_key ("Color Management", "AutoMonitorProfile")) rtSettings.autoMonitorProfile = keyFile.get_boolean ("Color Management", "AutoMonitorProfile"); + if (keyFile.has_key ("Color Management", "Intent")) rtSettings.colorimetricIntent = keyFile.get_integer("Color Management", "Intent"); } @@ -441,6 +445,7 @@ int Options::saveToFile (Glib::ustring fname) { keyFile.set_string ("Color Management", "ICCDirectory", rtSettings.iccDirectory); keyFile.set_string ("Color Management", "MonitorProfile", rtSettings.monitorProfile); + keyFile.set_boolean ("Color Management", "AutoMonitorProfile", rtSettings.autoMonitorProfile); keyFile.set_integer ("Color Management", "Intent", rtSettings.colorimetricIntent); Glib::ArrayHandle bab = baBehav; diff --git a/rtgui/preferences.cc b/rtgui/preferences.cc index 5532157cb..d8df183d5 100644 --- a/rtgui/preferences.cc +++ b/rtgui/preferences.cc @@ -337,6 +337,8 @@ Gtk::Widget* Preferences::getColorManagementPanel () { monProfile = Gtk::manage (new Gtk::FileChooserButton (M("PREFERENCES_MONITORICC"), Gtk::FILE_CHOOSER_ACTION_OPEN)); Gtk::Label* mplabel = Gtk::manage (new Gtk::Label (M("PREFERENCES_MONITORICC")+":")); + cbAutoMonProfile = Gtk::manage (new Gtk::CheckButton (M("PREFERENCES_AUTOMONPROFILE"))); + Gtk::Table* colt = Gtk::manage (new Gtk::Table (3, 2)); colt->attach (*intlab, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 2, 2); colt->attach (*intent, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 2, 2); @@ -344,7 +346,7 @@ Gtk::Widget* Preferences::getColorManagementPanel () { colt->attach (*iccDir, 1, 2, 1, 2, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 2, 2); colt->attach (*mplabel, 0, 1, 2, 3, Gtk::SHRINK, Gtk::SHRINK, 2, 2); colt->attach (*monProfile, 1, 2, 2, 3, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 2, 2); - + colt->attach (*cbAutoMonProfile, 1, 2, 3, 4, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 2, 2); mvbcm->pack_start (*colt, Gtk::PACK_SHRINK, 4); return mvbcm; @@ -809,6 +811,7 @@ void Preferences::storePreferences () { moptions.rtSettings.monitorProfile = monProfile->get_filename (); + moptions.rtSettings.autoMonitorProfile = cbAutoMonProfile->get_active (); moptions.rtSettings.iccDirectory = iccDir->get_current_folder (); moptions.rtSettings.colorimetricIntent = intent->get_active_row_number (); @@ -883,6 +886,7 @@ void Preferences::fillPreferences () { monProfile->set_filename (moptions.rtSettings.monitorProfile); if (moptions.rtSettings.monitorProfile.empty()) monProfile->set_current_folder (moptions.rtSettings.iccDirectory); + cbAutoMonProfile->set_active(moptions.rtSettings.autoMonitorProfile); if (Glib::file_test (moptions.rtSettings.iccDirectory, Glib::FILE_TEST_IS_DIR)) iccDir->set_current_folder (moptions.rtSettings.iccDirectory); diff --git a/rtgui/preferences.h b/rtgui/preferences.h index 8c19e4b82..33d8bc84f 100644 --- a/rtgui/preferences.h +++ b/rtgui/preferences.h @@ -76,6 +76,7 @@ class Preferences : public Gtk::Dialog { Gtk::FileChooserButton* iccDir; Gtk::FileChooserButton* monProfile; + Gtk::CheckButton* cbAutoMonProfile; Gtk::CheckButton* blinkClipped; Gtk::SpinButton* hlThresh;