diff --git a/rtengine/iccstore.cc b/rtengine/iccstore.cc index 67e98ae89..5b44dc7cf 100644 --- a/rtengine/iccstore.cc +++ b/rtengine/iccstore.cc @@ -25,6 +25,7 @@ #include #include #include +#include namespace rtengine { @@ -50,8 +51,14 @@ std::vector ICCStore::getOutputProfiles () { Glib::Mutex::Lock lock(mutex_); std::vector res; - for (std::map::iterator i=fileProfiles.begin(); i!=fileProfiles.end(); i++) - res.push_back (i->first); + for (std::map::iterator i=fileProfiles.begin(); i!=fileProfiles.end(); i++){ + std::string name(i->first); + std::string::size_type i = name.find_last_of('/'); + if( i == std::string::npos ) + i = name.find_last_of('\\'); + if( i == std::string::npos ) + res.push_back ( name ); // list only profiles inside selected profiles directory + } return res; } @@ -206,6 +213,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 5e249a750..1f0751c99 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 bafcb2103..e8bf98697 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -156,7 +156,11 @@ void ImProcFunctions::firstAnalysis (Imagefloat* original, const ProcParams* par if (monitorTransform) cmsDeleteTransform (monitorTransform); monitorTransform = NULL; - cmsHPROFILE monitor = iccStore->getProfile ("file:"+settings->monitorProfile); + + Glib::ustring monitorProfile=settings->monitorProfile; + if (settings->autoMonitorProfile) monitorProfile=iccStore->defaultMonitorProfile; + + cmsHPROFILE monitor = iccStore->getProfile ("file:"+monitorProfile); if (monitor) { cmsHPROFILE iprof = iccStore->getXYZProfile (); lcmsMutex->lock (); 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 ();