Automatic monitor profile detection using operation system; see issue #577

This commit is contained in:
Oliver Duis
2011-03-12 18:22:50 +01:00
parent 71a4fea38d
commit aded66851e
9 changed files with 52 additions and 2 deletions

View File

@@ -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

View File

@@ -214,6 +214,32 @@ std::vector<std::string> 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;

View File

@@ -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);

View File

@@ -25,6 +25,7 @@
#include <bilateral2.h>
#include <minmax.h>
#include <mytime.h>
#include <glib.h>
#include <glibmm.h>
#include <iccstore.h>
#include <impulse_denoise.h>
@@ -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);

View File

@@ -36,6 +36,8 @@ int init (const Settings* s) {
settings = s;
iccStore->parseDir (s->iccDirectory);
iccStore->findDefaultMonitorProfile();
CurveFactory::init ();
ImProcFunctions::initCache ();
Thumbnail::initGamma ();

View File

@@ -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

View File

@@ -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<int> bab = baBehav;

View File

@@ -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);

View File

@@ -76,6 +76,7 @@ class Preferences : public Gtk::Dialog {
Gtk::FileChooserButton* iccDir;
Gtk::FileChooserButton* monProfile;
Gtk::CheckButton* cbAutoMonProfile;
Gtk::CheckButton* blinkClipped;
Gtk::SpinButton* hlThresh;