From 0a67e308bf9702546dfa62d44e15b21b04e20621 Mon Sep 17 00:00:00 2001 From: Oliver Duis Date: Tue, 19 Jul 2011 19:01:18 +0200 Subject: [PATCH] Fixed cropping not working in file browser mode see issue 609 --- rtengine/rtthumbnail.cc | 22 +++++----------------- rtengine/rtthumbnail.h | 2 +- rtgui/thumbnail.cc | 32 +++++++++++++++++++++++++++++--- rtgui/thumbnail.h | 3 ++- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index 7b0206166..f05b1a23c 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -790,23 +790,11 @@ int Thumbnail::getImageWidth (const procparams::ProcParams& params, int rheight) return rwidth; } -void Thumbnail::getFinalSize (const rtengine::procparams::ProcParams& params, int& fullw, int& fullh) { - - // WARNING: When downscaled, the ratio have loosed a lot of precision, so we can't get back the exact initial dimensions - double fw = thumbImg->width*scale; - double fh = thumbImg->height*scale; - - if (params.coarse.rotate==90 || params.coarse.rotate==270) { - fh = thumbImg->width*scale; - fw = thumbImg->height*scale; - } - if (!params.resize.enabled) { - fullw = fw; - fullh = fh; - } - else { - fullw = (int)((double)fw+0.5); - fullh = (int)((double)fh+0.5); +void Thumbnail::getDimensions (int& w, int& h, double& scaleFac) { + if (thumbImg) { + w=thumbImg->width; h=thumbImg->height; scaleFac=scale; + } else { + w=0; h=0; scale=1; } } diff --git a/rtengine/rtthumbnail.h b/rtengine/rtthumbnail.h index 6e9e49d0d..aa59f685e 100644 --- a/rtengine/rtthumbnail.h +++ b/rtengine/rtthumbnail.h @@ -73,7 +73,7 @@ namespace rtengine { IImage8* processImage (const procparams::ProcParams& pparams, int rheight, TypeInterpolation interp, double& scale); IImage8* quickProcessImage (const procparams::ProcParams& pparams, int rheight, TypeInterpolation interp, double& scale); int getImageWidth (const procparams::ProcParams& pparams, int rheight); - void getFinalSize (const rtengine::procparams::ProcParams& pparams, int& w, int& h); + void getDimensions (int& w, int& h, double& scaleFac); static Thumbnail* loadQuickFromRaw (const Glib::ustring& fname, rtengine::RawMetaDataLocation& rml, int &w, int &h, int fixwh, bool rotate); static Thumbnail* loadFromRaw (const Glib::ustring& fname, RawMetaDataLocation& rml, int &w, int &h, int fixwh, bool rotate); diff --git a/rtgui/thumbnail.cc b/rtgui/thumbnail.cc index 4500c0a83..2f427bf3b 100644 --- a/rtgui/thumbnail.cc +++ b/rtgui/thumbnail.cc @@ -36,7 +36,7 @@ using namespace rtengine::procparams; 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), - initial_(false) { + initial_(false), lastW(0), lastH(0), lastScale(0) { cfs.load (getCacheFileName ("data")+".txt"); loadProcParams (); @@ -392,6 +392,31 @@ void Thumbnail::getThumbnailSize (int &w, int &h) { if (w==0) w = tw * h / th; } +void Thumbnail::getFinalSize (const rtengine::procparams::ProcParams& pparams, int& w, int& h) { + // TODO: Check for Linux + #ifdef WIN32 + Glib::Mutex::Lock lock(mutex); + #endif + + // WARNING: When downscaled, the ratio have loosed a lot of precision, so we can't get back the exact initial dimensions + double fw = lastW*lastScale; + double fh = lastH*lastScale; + + if (pparams.coarse.rotate==90 || pparams.coarse.rotate==270) { + fh = lastW*lastScale; + fw = lastH*lastScale; + } + if (!pparams.resize.enabled) { + w = fw; + h = fh; + } + else { + w = (int)(fw+0.5); + h = (int)(fh+0.5); + } +} + + rtengine::IImage8* Thumbnail::processThumbImage (const rtengine::procparams::ProcParams& pparams, int h, double& scale) { Glib::Mutex::Lock lock(mutex); @@ -418,7 +443,8 @@ rtengine::IImage8* Thumbnail::processThumbImage (const rtengine::procparams::Pro image = tpp->processImage (pparams, h, rtengine::TI_Bilinear, scale); } - //_saveThumbnail(); + tpp->getDimensions(lastW,lastH,lastScale); + delete tpp; tpp = 0; return image; @@ -440,8 +466,8 @@ rtengine::IImage8* Thumbnail::upgradeThumbImage (const rtengine::procparams::Pro } rtengine::IImage8* image = tpp->processImage (pparams, h, rtengine::TI_Bilinear, scale); + tpp->getDimensions(lastW,lastH,lastScale); - //_saveThumbnail(); delete tpp; tpp = 0; return image; diff --git a/rtgui/thumbnail.h b/rtgui/thumbnail.h index 6a6c28a5e..a8fb75bb1 100644 --- a/rtgui/thumbnail.h +++ b/rtgui/thumbnail.h @@ -54,6 +54,7 @@ class Thumbnail { unsigned char* lastImg; int lastW; int lastH; + double lastScale; // exif & date/time strings Glib::ustring exifString; @@ -102,7 +103,7 @@ class Thumbnail { 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 getFinalSize (const rtengine::procparams::ProcParams& pparams, int& w, int& h) { if (tpp) tpp->getFinalSize (pparams, w, h); } + void getFinalSize (const rtengine::procparams::ProcParams& pparams, int& w, int& h); const Glib::ustring& getExifString (); const Glib::ustring& getDateTimeString ();