Don't prefetch camera icc profiles, Issue 2818

This commit is contained in:
Ingo 2015-06-24 21:18:33 +02:00
parent 4ab63d8e65
commit 0bfc5a0e98
2 changed files with 47 additions and 22 deletions

View File

@ -264,11 +264,34 @@ cmsHPROFILE ICCStore::getStdProfile (Glib::ustring name) {
MyMutex::MyLock lock(mutex_); MyMutex::MyLock lock(mutex_);
std::map<Glib::ustring, cmsHPROFILE>::iterator r = fileStdProfiles.find (name.uppercase()); std::map<Glib::ustring, cmsHPROFILE>::iterator r = fileStdProfiles.find (name.uppercase());
if (r==fileStdProfiles.end()) return NULL; if (r==fileStdProfiles.end()) {
// profile is not yet in store
return r->second; std::map<Glib::ustring, Glib::ustring>::iterator f = fileStdProfilesFileNames.find (name.uppercase());
if(f!=fileStdProfilesFileNames.end()) {
// but there exists one => load it
ProfileContent pc (f->second);
if (pc.data) {
cmsHPROFILE profile = pc.toProfile ();
if (profile) {
fileStdProfiles[name.uppercase()] = profile;
}
// profile is not valid or it is now stored => remove entry from fileStdProfilesFileNames
fileStdProfilesFileNames.erase(f);
return profile;
} else {
// profile not valid => remove entry from fileStdProfilesFileNames
fileStdProfilesFileNames.erase(f);
return NULL;
}
} else {
// profile does not exist
return NULL;
}
} else {
// return profile from store
return r->second;
}
} }
ProfileContent ICCStore::getContent (Glib::ustring name) { ProfileContent ICCStore::getContent (Glib::ustring name) {
@ -287,17 +310,17 @@ void ICCStore::init (Glib::ustring usrICCDir, Glib::ustring rtICCDir) {
fileProfiles.clear(); fileProfiles.clear();
fileProfileContents.clear(); fileProfileContents.clear();
// RawTherapee's profiles take precedence if a user's profile of the same name exists // RawTherapee's profiles take precedence if a user's profile of the same name exists
loadICCs(Glib::build_filename(rtICCDir, "output"), false, fileProfiles, fileProfileContents, true); loadICCs(Glib::build_filename(rtICCDir, "output"), false, fileProfiles, &fileProfileContents, true, true);
loadICCs(usrICCDir, false, fileProfiles, fileProfileContents, true); loadICCs(usrICCDir, false, fileProfiles, &fileProfileContents, true, true);
// Input profiles // Input profiles
// Load these to different areas, since the short name (e.g. "NIKON D700" may overlap between system/user and RT dir) // Load these to different areas, since the short name (e.g. "NIKON D700" may overlap between system/user and RT dir)
fileStdProfiles.clear(); fileStdProfiles.clear();
fileStdProfileContents.clear(); fileStdProfilesFileNames.clear();
loadICCs(Glib::build_filename(rtICCDir, "input"), true, fileStdProfiles, fileStdProfileContents); loadICCs(Glib::build_filename(rtICCDir, "input"), true, fileStdProfiles, NULL);
} }
void ICCStore::loadICCs(Glib::ustring rootDirName, bool nameUpper, std::map<Glib::ustring, cmsHPROFILE>& resultProfiles, std::map<Glib::ustring, ProfileContent> &resultProfileContents, bool onlyRgb) { void ICCStore::loadICCs(Glib::ustring rootDirName, bool nameUpper, std::map<Glib::ustring, cmsHPROFILE>& resultProfiles, std::map<Glib::ustring, ProfileContent> *resultProfileContents, bool prefetch, bool onlyRgb) {
if (rootDirName!="") { if (rootDirName!="") {
std::deque<Glib::ustring> qDirs; std::deque<Glib::ustring> qDirs;
@ -325,12 +348,17 @@ void ICCStore::loadICCs(Glib::ustring rootDirName, bool nameUpper, std::map<Glib
size_t lastdot = sname.find_last_of ('.'); size_t lastdot = sname.find_last_of ('.');
if (lastdot!=Glib::ustring::npos && lastdot<=sname.size()-4 && (!sname.casefold().compare (lastdot, 4, ".icm") || !sname.casefold().compare (lastdot, 4, ".icc"))) { if (lastdot!=Glib::ustring::npos && lastdot<=sname.size()-4 && (!sname.casefold().compare (lastdot, 4, ".icm") || !sname.casefold().compare (lastdot, 4, ".icc"))) {
Glib::ustring name = nameUpper ? sname.substr(0,lastdot).uppercase() : sname.substr(0,lastdot); Glib::ustring name = nameUpper ? sname.substr(0,lastdot).uppercase() : sname.substr(0,lastdot);
ProfileContent pc (fname); if(!prefetch) {
if (pc.data) { fileStdProfilesFileNames[name] = fname;
cmsHPROFILE profile = pc.toProfile (); } else {
if (profile && (!onlyRgb || cmsGetColorSpace(profile) == cmsSigRgbData)) { ProfileContent pc (fname);
resultProfiles[name] = profile; if (pc.data) {
resultProfileContents[name] = pc; cmsHPROFILE profile = pc.toProfile ();
if (profile && (!onlyRgb || cmsGetColorSpace(profile) == cmsSigRgbData)) {
resultProfiles[name] = profile;
if(resultProfileContents)
(*resultProfileContents)[name] = pc;
}
} }
} }
} }
@ -370,9 +398,8 @@ void ICCStore::findDefaultMonitorProfile() {
if (options.rtSettings.verbose) printf("Default monitor profile is: %s\n", defaultMonitorProfile.c_str()); if (options.rtSettings.verbose) printf("Default monitor profile is: %s\n", defaultMonitorProfile.c_str());
} }
ProfileContent::ProfileContent (Glib::ustring fileName) { ProfileContent::ProfileContent (Glib::ustring fileName) : data(NULL), length(0) {
data = NULL;
FILE* f = safe_g_fopen (fileName, "rb"); FILE* f = safe_g_fopen (fileName, "rb");
if (!f) if (!f)
return; return;
@ -396,10 +423,8 @@ ProfileContent::ProfileContent (const ProfileContent& other) {
data = NULL; data = NULL;
} }
ProfileContent::ProfileContent (cmsHPROFILE hProfile) { ProfileContent::ProfileContent (cmsHPROFILE hProfile) : data(NULL), length(0) {
data = NULL;
length = 0;
if (hProfile != NULL) { if (hProfile != NULL) {
cmsUInt32Number bytesNeeded = 0; cmsUInt32Number bytesNeeded = 0;
cmsSaveProfileToMem(hProfile, 0, &bytesNeeded); cmsSaveProfileToMem(hProfile, 0, &bytesNeeded);

View File

@ -56,8 +56,8 @@ class ICCStore {
std::map<Glib::ustring, ProfileContent> fileProfileContents; std::map<Glib::ustring, ProfileContent> fileProfileContents;
// these contain standard profiles from RT. keys are all in uppercase // these contain standard profiles from RT. keys are all in uppercase
std::map<Glib::ustring, Glib::ustring> fileStdProfilesFileNames;
std::map<Glib::ustring, cmsHPROFILE> fileStdProfiles; std::map<Glib::ustring, cmsHPROFILE> fileStdProfiles;
std::map<Glib::ustring, ProfileContent> fileStdProfileContents;
cmsHPROFILE xyz; cmsHPROFILE xyz;
cmsHPROFILE srgb; cmsHPROFILE srgb;
@ -65,7 +65,7 @@ class ICCStore {
MyMutex mutex_; MyMutex mutex_;
ICCStore (); ICCStore ();
void loadICCs(Glib::ustring rootDirName, bool nameUpper, std::map<Glib::ustring, cmsHPROFILE>& resultProfiles, std::map<Glib::ustring, ProfileContent> &resultProfileContents, bool onlyRgb = false); void loadICCs(Glib::ustring rootDirName, bool nameUpper, std::map<Glib::ustring, cmsHPROFILE>& resultProfiles, std::map<Glib::ustring, ProfileContent> *resultProfileContents, bool prefetch = false, bool onlyRgb = false);
public: public: