From b549ecf5a8b976e2c6e0c092982af78f437b15a8 Mon Sep 17 00:00:00 2001 From: Hombre Date: Mon, 2 Dec 2013 00:59:28 +0100 Subject: [PATCH] Solving issue 2045: "Batch queue pp3's conflicts with main pp3's" --- rtgui/batchqueue.cc | 21 ++++++++++++++----- rtgui/cachemanager.cc | 10 +++------ rtgui/cachemanager.h | 2 +- rtgui/thumbnail.cc | 47 ++++++++++++++++++++++++++----------------- rtgui/thumbnail.h | 6 +++--- 5 files changed, 52 insertions(+), 34 deletions(-) diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index 6e5fd79da..3e1ed081a 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -74,7 +74,18 @@ BatchQueue::BatchQueue () : processing(NULL), sequence(0), listener(NULL) { BatchQueue::~BatchQueue () { - delete pmenu; + #if PROTECT_VECTORS + MYWRITERLOCK(l, entryRW); + #endif + + // The listener merges parameters with old values, so delete afterwards + for (size_t i=0; igetEntry( source, &pparams ); + ::Thumbnail *thumb = cacheMgr->getEntry( source ); if( thumb ){ rtengine::ProcessingJob* job = rtengine::ProcessingJob::create(source, thumb->getType() == FT_Raw, pparams); int prevh = getMaxThumbnailHeight(); int prevw = prevh; - thumb->getThumbnailSize (prevw, prevh); + thumb->getThumbnailSize (prevw, prevh, &pparams); BatchQueueEntry *entry = new BatchQueueEntry(job, pparams,source, prevw, prevh, thumb); + thumb->decreaseRef(); // Removing the refCount acquired by cacheMgr->getEntry entry->setParent(this); // BatchQueueButtonSet HAVE TO be added before resizing to take them into account @@ -661,7 +673,7 @@ rtengine::ProcessingJob* BatchQueue::imageReady (rtengine::IImage16* img) { MYREADERLOCK_RELEASE(l); #endif std::vector names; - Glib::ustring batchdir = options.rtdir+"/batch/"; + Glib::ustring batchdir = Glib::build_filename(options.rtdir, "batch"); Glib::RefPtr dir = Gio::File::create_for_path (batchdir); safe_build_file_list (dir, names, batchdir); for(std::vector::iterator iter=names.begin(); iter != names.end();iter++ ) @@ -885,7 +897,6 @@ void BatchQueue::redrawNeeded (LWButton* button) { void BatchQueue::error (Glib::ustring msg) { - BatchQueueEntry* current = static_cast(fd[0]); if (processing && processing->processing) { // restore failed thumb BatchQueueButtonSet* bqbs = new BatchQueueButtonSet (processing); diff --git a/rtgui/cachemanager.cc b/rtgui/cachemanager.cc index 5296dd9a8..894b574eb 100644 --- a/rtgui/cachemanager.cc +++ b/rtgui/cachemanager.cc @@ -64,11 +64,7 @@ void CacheManager::init () { safe_g_mkdir_with_parents (Glib::ustring(Glib::build_filename (baseDir, "data")), 511); } -/* - * if pparams is NULL (default), get the ProcParams from the cache; - * if pparams is non NULL, compute the thumbnails with the provided pparams - */ -Thumbnail* CacheManager::getEntry (const Glib::ustring& fname, const rtengine::procparams::ProcParams *pparams) { +Thumbnail* CacheManager::getEntry (const Glib::ustring& fname) { Thumbnail* res = NULL; @@ -98,7 +94,7 @@ Thumbnail* CacheManager::getEntry (const Glib::ustring& fname, const rtengine::p CacheImageData* cfs = new CacheImageData (); int e = cfs->load (cfname); if (!e && cfs->supported==true) - res = new Thumbnail (this, fname, cfs, pparams); + res = new Thumbnail (this, fname, cfs); if (res && !res->isSupported ()) { delete res; res = NULL; @@ -108,7 +104,7 @@ Thumbnail* CacheManager::getEntry (const Glib::ustring& fname, const rtengine::p // if not, create a new one if (!res) { - res = new Thumbnail (this, fname, md5, pparams); + res = new Thumbnail (this, fname, md5); if (!res->isSupported ()) { delete res; res = NULL; diff --git a/rtgui/cachemanager.h b/rtgui/cachemanager.h index 183d304f7..6173e1c80 100644 --- a/rtgui/cachemanager.h +++ b/rtgui/cachemanager.h @@ -47,7 +47,7 @@ class CacheManager { static CacheManager* getInstance(void); void init (); - Thumbnail* getEntry (const Glib::ustring& fname, const rtengine::procparams::ProcParams *pparams=NULL); + Thumbnail* getEntry (const Glib::ustring& fname); void deleteEntry (const Glib::ustring& fname); void renameEntry (const std::string& oldfilename, const std::string& oldmd5, const std::string& newfilename); diff --git a/rtgui/thumbnail.cc b/rtgui/thumbnail.cc index e6940ae76..279928034 100644 --- a/rtgui/thumbnail.cc +++ b/rtgui/thumbnail.cc @@ -33,18 +33,13 @@ using namespace rtengine::procparams; -Thumbnail::Thumbnail (CacheManager* cm, const Glib::ustring& fname, CacheImageData* cf, const rtengine::procparams::ProcParams *pparams) +Thumbnail::Thumbnail (CacheManager* cm, const Glib::ustring& fname, CacheImageData* cf) : fname(fname), cfs(*cf), cachemgr(cm), ref(1), enqueueNumber(0), tpp(NULL), pparamsValid(false), needsReProcessing(true),imageLoading(false), lastImg(NULL), lastW(0), lastH(0), lastScale(0), initial_(false) { - if (pparams) { - this->pparams = *pparams; - pparamsValid = true; - } - else - loadProcParams (); + loadProcParams (); // should be safe to use the unprotected version of loadThumbnail, since we are in the constructor _loadThumbnail (); @@ -66,7 +61,7 @@ Thumbnail::Thumbnail (CacheManager* cm, const Glib::ustring& fname, CacheImageDa tpp = 0; } -Thumbnail::Thumbnail (CacheManager* cm, const Glib::ustring& fname, const std::string& md5, const rtengine::procparams::ProcParams *pparams) +Thumbnail::Thumbnail (CacheManager* cm, const Glib::ustring& fname, const std::string& md5) : fname(fname), cachemgr(cm), ref(1), enqueueNumber(0), tpp(NULL), pparamsValid(false), needsReProcessing(true),imageLoading(false), lastImg(NULL), initial_(true) @@ -74,12 +69,7 @@ Thumbnail::Thumbnail (CacheManager* cm, const Glib::ustring& fname, const std::s cfs.md5 = md5; - if (pparams) { - this->pparams = *pparams; - pparamsValid = true; - } - else - loadProcParams (); + loadProcParams (); _generateThumbnailImage (); cfs.recentlySaved = false; @@ -456,11 +446,32 @@ void Thumbnail::decreaseRef () cachemgr->closeThumbnail (this); } -void Thumbnail::getThumbnailSize (int &w, int &h) { - if (imgRatio > 0.) - w = (int)(imgRatio * (float)h); +void Thumbnail::getThumbnailSize (int &w, int &h, const rtengine::procparams::ProcParams *pparams) { + int tw_ = tw; + int th_ = th; + float imgRatio_ = imgRatio; + + if (pparams) { + int ppCoarse = pparams->coarse.rotate; + if (ppCoarse >= 180) ppCoarse -= 180; + + int thisCoarse = this->pparams.coarse.rotate; + if (thisCoarse >= 180) thisCoarse -= 180; + + if (thisCoarse != ppCoarse) { + // different orientation -> swapping width & height + int tmp = th_; + th_ = tw_; + tw_ = tmp; + if (imgRatio_ >= 0.0001f) + imgRatio_ = 1.f/imgRatio_; + } + } + + if (imgRatio_ > 0.) + w = (int)(imgRatio_ * (float)h); else - w = tw * h / th; + w = tw_ * h / th_; } void Thumbnail::getFinalSize (const rtengine::procparams::ProcParams& pparams, int& w, int& h) { diff --git a/rtgui/thumbnail.h b/rtgui/thumbnail.h index 8225603f5..183f4b195 100644 --- a/rtgui/thumbnail.h +++ b/rtgui/thumbnail.h @@ -77,8 +77,8 @@ class Thumbnail { Glib::ustring getCacheFileName (Glib::ustring subdir); public: - Thumbnail (CacheManager* cm, const Glib::ustring& fname, CacheImageData* cf, const rtengine::procparams::ProcParams *pparams=NULL); - Thumbnail (CacheManager* cm, const Glib::ustring& fname, const std::string& md5, const rtengine::procparams::ProcParams *pparams=NULL); + Thumbnail (CacheManager* cm, const Glib::ustring& fname, CacheImageData* cf); + Thumbnail (CacheManager* cm, const Glib::ustring& fname, const std::string& md5); ~Thumbnail (); bool hasProcParams (); @@ -105,7 +105,7 @@ class Thumbnail { // unsigned char* getThumbnailImage (int &w, int &h, int fixwh=1); // fixwh = 0: fix w and calculate h, =1: fix h and calculate w rtengine::IImage8* processThumbImage (const rtengine::procparams::ProcParams& pparams, int h, double& scale); rtengine::IImage8* upgradeThumbImage (const rtengine::procparams::ProcParams& pparams, int h, double& scale); - void getThumbnailSize (int &w, int &h); + void getThumbnailSize (int &w, int &h, const rtengine::procparams::ProcParams *pparams=NULL); void getFinalSize (const rtengine::procparams::ProcParams& pparams, int& w, int& h); const Glib::ustring& getExifString ();