Hugin trunk 0.1
Loading...
Searching...
No Matches
wxImageCache.cpp
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
2
27#include "wxImageCache.h"
28#include "vigra_ext/utils.h"
30#include "base_wx/platform.h"
31#include "wxcms.h"
32
34{
35 if (e->imageFloat->size().area() > 0)
36 {
37 // for float images we need to apply the mapping as selected by the user
38 // in the preferences
39 const int mapping = wxConfigBase::Get()->Read("/ImageCache/Mapping", HUGIN_IMGCACHE_MAPPING_FLOAT);
40 // find average and variance
41 vigra::RGBToGrayAccessor<vigra::RGBValue<float> > ga;
42 vigra::FindAverageAndVariance<float> mean; // init functor
43 vigra::inspectImage(srcImageRange(*(e->imageFloat), ga), mean);
44 // create temporary image with remapped tone scale
45 vigra::BRGBImage mappedImg(e->imageFloat->size());
46 // scale image to (mean - 3 * std deviation) - (mean + 3 * std deviation),
47 vigra_ext::applyMapping(srcImageRange(*(e->imageFloat)), destImage(mappedImg), std::max(mean.average() - 3 * sqrt(mean.variance()), 1e-6f), mean.average() + 3 * sqrt(mean.variance()), mapping);
48 // convert to wxImage
49 wxImage mappedwxImg(mappedImg.width(), mappedImg.height(), (unsigned char *)mappedImg.data(), true);
50 return mappedwxImg.Copy();
51 }
52 else
53 {
54 ImageCacheRGB8Ptr img = e->get8BitImage();
55 if (img)
56 {
57 return wxImage(img->width(), img->height(), (unsigned char *)img->data(), true);
58 }
59 else
60 {
61 // invalid wxImage
62 return wxImage();
63 };
64 };
65}
66
68{
71
72 double iRatio = img.GetWidth() / (double)img.GetHeight();
73 wxSize sz;
74 // estimate image size
75 sz = control->GetContainingSizer()->GetSize();
76 double sRatio = (double)sz.GetWidth() / sz.GetHeight();
77 if (iRatio > sRatio)
78 {
79 // image is wider than screen, display landscape
80 sz.SetHeight((int)(sz.GetWidth() / iRatio));
81 }
82 else
83 {
84 // portrait
85 sz.SetWidth((int)(sz.GetHeight() * iRatio));
86 }
87 // Make sure the size is positive:
88 // on a small window, m_smallImgCtrl can have 0 width.
89 sz.IncTo(wxSize(1, 1));
91 if (std::max(img.GetWidth(), img.GetHeight()) > (ULONG_MAX >> 16))
92 {
93 // wxIMAGE_QUALITY_NORMAL resizes the image with ResampleNearest
94 // this algorithm works only if image dimensions are smaller then
95 // ULONG_MAX >> 16 (actual size of unsigned long differ from system
96 // to system)
98 };
99 wxImage scaled = img.Scale(sz.GetWidth(), sz.GetHeight(), resizeQuality);
100 // now apply color profile
101 if (!cacheEntry->iccProfile->empty() || hasMonitorProfile)
102 {
103 vigra::ImageImportInfo::ICCProfile iccProfile;
104 // ignore icc profile for float images, because we have already color remapped image
105 if (cacheEntry->imageFloat->width() == 0)
106 {
107 iccProfile = *(cacheEntry->iccProfile);
108 }
110 };
112 // set the DPI scale factor in wxBitmap, otherwise wxStaticBitmap scales the wxBitmap also
113 scaledBitmap.SetScaleFactor(control->GetDPIScaleFactor());
114 control->SetBitmap(scaledBitmap);
115 control->GetParent()->Layout();
116 control->Refresh();
117}
118
121
125
127{
128 return new ImageReadyEvent(request, entry);
129}
130
132{
135 // Connect to ImageCache: we need to tell it when it is safe to handle UI events.
136 ImageCache::getInstance().asyncLoadCompleteSignal = &ImageCacheApp::imageLoadedAsync;
137 return true;
138}
139
141{
142 if (event.entry.get())
143 {
144 ImageCache::getInstance().postEvent(event.request, event.entry);
145 }
146 else
147 {
148 // loading failed, first remove request from image cache list
149 ImageCache::getInstance().removeRequest(event.request);
150 // now notify main frame to remove the failed image from project
151 wxCommandEvent e(EVT_LOADING_FAILED);
152 e.SetString(wxString(event.request->getFilename().c_str(), HUGIN_CONV_FILENAME));
153 wxTheApp->GetTopWindow()->GetEventHandler()->AddPendingEvent(e);
154 };
155}
156
158{
159 ImageReadyEvent event(request, entry);
160 // AddPendingEvent adds the event to the event queue and returns without
161 // processing it. This is necessary since we are probably not in the
162 // UI thread, but the event handler must be run in the UI thread since it
163 // could update image views.
164 wxTheApp->GetTopWindow()->GetEventHandler()->AddPendingEvent(event);
165}
166
168{
169#if defined __WXMSW__
170 unsigned long long mem = HUGIN_IMGCACHE_UPPERBOUND;
171 unsigned long mem_low = wxConfigBase::Get()->Read("/ImageCache/UpperBound", HUGIN_IMGCACHE_UPPERBOUND);
172 unsigned long mem_high = wxConfigBase::Get()->Read("/ImageCache/UpperBoundHigh", 0l);
173 if (mem_high > 0)
174 {
175 mem = ((unsigned long long) mem_high << 32) + mem_low;
176 }
177 else
178 {
179 mem = mem_low;
180 }
182#else
183 ImageCache::getInstance().SetUpperLimit(wxConfigBase::Get()->Read("/ImageCache/UpperBound", HUGIN_IMGCACHE_UPPERBOUND));
184#endif
185}
static ImageCache & getInstance()
get the global ImageCache object
std::shared_ptr< Request > RequestPtr
Reference counted request for an image to load.
Definition ImageCache.h:151
std::shared_ptr< Entry > EntryPtr
a shared pointer to the entry
Definition ImageCache.h:112
void SetUpperLimit(const unsigned long long newUpperLimit)
sets the upper limit, which is used by softFlush()
Definition ImageCache.h:256
bool OnInit() wxOVERRIDE
void relayImageLoaded(ImageReadyEvent &event)
Relay image loaded event when the UI thread is ready to process it.
static void imageLoadedAsync(HuginBase::ImageCache::RequestPtr request, HuginBase::ImageCache::EntryPtr entry)
Queue up an image loaded event when an image has just loaded.
Event for when a requested image finished loading.
virtual wxEvent * Clone() const
HuginBase::ImageCache::EntryPtr entry
HuginBase::ImageCache::RequestPtr request
ImageReadyEvent(HuginBase::ImageCache::RequestPtr request, HuginBase::ImageCache::EntryPtr entry)
#define HUGIN_IMGCACHE_UPPERBOUND
#define HUGIN_IMGCACHE_MAPPING_FLOAT
implementation of huginApp Class
#define HUGIN_CONV_FILENAME
Definition platform.h:40
void CorrectImage(wxImage &image, const vigra::ImageImportInfo::ICCProfile &iccProfile, const cmsHPROFILE &monitorProfile)
apply color correction to given image using input iccProfile and monitor profile
Definition wxcms.cpp:218
void applyMapping(vigra::triple< SrcIterator, SrcIterator, SrcAccessor > img, vigra::pair< DestIterator, DestAccessor > dest, T min, T max, int mapping)
Definition utils.h:685
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41
functions to manage ROI's
wxImage imageCacheEntry2wxImage(ImageCache::EntryPtr e)
void UpdateImageCacheSize()
update the image cache size from the settings in wxConfig
wxDEFINE_EVENT(EVT_IMAGE_READY, ImageReadyEvent)
void GeneratePreviewSelectedFile(wxStaticBitmap *control, ImageCache::EntryPtr cacheEntry, const bool hasMonitorProfile, const cmsHPROFILE &monitorProfile)
load given image from image cache and display in wxStaticBitmap control
HuginBase::ImageCache::ImageCacheRGB8Ptr ImageCacheRGB8Ptr
WXIMPEX void UpdateImageCacheSize()
update the image cache size from the settings in wxConfig