Hugin trunk 0.1
Loading...
Searching...
No Matches
ImageCache.h
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
24#ifndef _HUGINAPP_IMAGECACHE_H
25#define _HUGINAPP_IMAGECACHE_H
26
27#include <hugin_shared.h>
28#include "hugin_config.h"
29#include <map>
30#include <vector>
31#include <memory>
32#include <functional>
33#include <vigra/stdimage.hxx>
34#include <vigra/imageinfo.hxx>
35#include <hugin_utils/utils.h>
37
38#define HUGIN_IMGCACHE_MAPPING_INTEGER 0l
39#define HUGIN_IMGCACHE_MAPPING_FLOAT 1l
40
41
42namespace HuginBase {
43
53{
54
55 public:
57 typedef std::shared_ptr<vigra::BRGBImage> ImageCacheRGB8Ptr;
58 typedef std::shared_ptr<vigra::UInt16RGBImage> ImageCacheRGB16Ptr;
59 typedef std::shared_ptr<vigra::FRGBImage> ImageCacheRGBFloatPtr;
60 typedef std::shared_ptr<vigra::BImage> ImageCache8Ptr;
61 typedef std::shared_ptr<vigra::ImageImportInfo::ICCProfile> ImageCacheICCProfile;
62
64 struct IMPEX Entry
65 {
71
72 std::string origType;
74
75 public:
79 image16(ImageCacheRGB16Ptr(new vigra::UInt16RGBImage)),
83 lastAccess(0)
84 {
85 DEBUG_TRACE("Constructing an empty ImageCache::Entry");
86 };
87
94 const std::string & typ)
95 : image8(img), image16(img16), imageFloat(imgFloat), mask(imgMask),
96 iccProfile(ICCProfile), origType(typ), lastAccess(0)
97 {
98 DEBUG_TRACE("Constructing ImageCache::Entry");
99 };
100
103 {
104 DEBUG_TRACE("Deleting ImageCacheEntry");
105 };
106
108 ImageCacheRGB8Ptr get8BitImage(int desiredMapping = -1);
109 };
110
112 typedef std::shared_ptr<Entry> EntryPtr;
113
118 {
119 public:
120 Request(std::string filename, bool request_small)
121 :m_filename(filename), m_isSmall(request_small)
122 {};
131 std::vector <std::function<void(EntryPtr, std::string, bool)>> ready;
132 bool getIsSmall() const
133 {return m_isSmall;};
134 const std::string & getFilename() const
135 {return m_filename;};
136 protected:
137 std::string m_filename;
139 };
140
151 typedef std::shared_ptr<Request> RequestPtr;
152
153 private:
154 // ctor. private, nobody execpt us can create an instance.
156 : asyncLoadCompleteSignal(0), upperBound(100*1024*1024ull),
157 m_progress(NULL), m_accessCounter(0)
158 {};
159
160 public:
163 virtual ~ImageCache()
164 {
165 images.clear();
166 instance = NULL;
167 }
168
170 static ImageCache & getInstance();
171
172 private:
174
175
176 public:
188 EntryPtr getImage(const std::string & filename);
189
197 EntryPtr getImageIfAvailable(const std::string & filename);
198
208 EntryPtr getSmallImage(const std::string & filename);
209
219 EntryPtr getSmallImageIfAvailable(const std::string & filename);
220
227 RequestPtr requestAsyncImage(const std::string & filename);
228
235 RequestPtr requestAsyncSmallImage(const std::string & filename);
236
240 void removeImage(const std::string & filename);
241
247 void flush();
248
253 void softFlush();
256 void SetUpperLimit(const unsigned long long newUpperLimit) { upperBound=newUpperLimit; };
257
268 void (*asyncLoadCompleteSignal)(RequestPtr, EntryPtr);
269
277 void postEvent(RequestPtr request, EntryPtr entry);
278
284 void removeRequest(RequestPtr request);
285
286 private:
287 unsigned long long upperBound;
288
289 template <class SrcPixelType,
290 class DestIterator, class DestAccessor>
291 static void importAndConvertImage(const vigra::ImageImportInfo& info,
292 vigra::pair<DestIterator, DestAccessor> dest,
293 const std::string& type);
294 template <class SrcPixelType,
295 class DestIterator, class DestAccessor,
296 class MaskIterator, class MaskAccessor>
297 static void importAndConvertAlphaImage(const vigra::ImageImportInfo & info,
298 vigra::pair<DestIterator, DestAccessor> dest,
299 vigra::pair<MaskIterator, MaskAccessor> mask,
300 const std::string & type);
301
302
303 public:
307
311
312
313 private:
314 std::map<std::string, EntryPtr> images;
315
316 // our progress display
318
320
321 // Requests for full size images that need loading
322 std::map<std::string, RequestPtr> m_requests;
323
324 // Requests for small images that need generating.
325 std::map<std::string, RequestPtr> m_smallRequests;
326
328 void spawnAsyncThread();
329
338 static void loadSafely(RequestPtr request, EntryPtr large = EntryPtr());
339
343 static EntryPtr loadImageSafely(const std::string & filename);
344
349 static EntryPtr loadSmallImageSafely(EntryPtr entry);
350
351 public:
365 // const vigra::BImage & getPyramidImage(const std::string& filename,
366 // int level);
367
368 private:
369 // key for your pyramid map.
371 {
372 std::string filename;
373 int level;
374
375 public:
376 PyramidKey(const std::string& str, int lv)
377 : filename(str), level(lv)
378 {};
379
380 std::string toString();
381 };
382
383 std::map<std::string, vigra::BImage *> pyrImages;
384};
385
386
387} //namespace
388#endif // _IMAGECACHE_H
Request for an image to load Connect to the ready signal so when the image loads you can respond.
Definition ImageCache.h:118
Request(std::string filename, bool request_small)
Definition ImageCache.h:120
std::vector< std::function< void(EntryPtr, std::string, bool)> > ready
Signal that fires when the image is loaded.
Definition ImageCache.h:131
const std::string & getFilename() const
Definition ImageCache.h:134
This is a cache for all the images we use.
Definition ImageCache.h:53
std::shared_ptr< vigra::FRGBImage > ImageCacheRGBFloatPtr
Definition ImageCache.h:59
AppBase::ProgressDisplay * m_progress
Definition ImageCache.h:317
std::shared_ptr< vigra::BRGBImage > ImageCacheRGB8Ptr
use reference counted pointers
Definition ImageCache.h:57
std::shared_ptr< vigra::BImage > ImageCache8Ptr
Definition ImageCache.h:60
std::map< std::string, RequestPtr > m_smallRequests
Definition ImageCache.h:325
static ImageCache * instance
Definition ImageCache.h:173
void setProgressDisplay(AppBase::ProgressDisplay *disp)
Definition ImageCache.h:305
std::map< std::string, RequestPtr > m_requests
Definition ImageCache.h:322
unsigned long long upperBound
Definition ImageCache.h:287
std::shared_ptr< vigra::UInt16RGBImage > ImageCacheRGB16Ptr
Definition ImageCache.h:58
std::map< std::string, vigra::BImage * > pyrImages
Definition ImageCache.h:383
void clearProgressDisplay(AppBase::ProgressDisplay *disp)
Definition ImageCache.h:309
std::shared_ptr< Request > RequestPtr
Reference counted request for an image to load.
Definition ImageCache.h:151
std::shared_ptr< vigra::ImageImportInfo::ICCProfile > ImageCacheICCProfile
Definition ImageCache.h:61
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
std::map< std::string, EntryPtr > images
Definition ImageCache.h:314
virtual ~ImageCache()
dtor.
Definition ImageCache.h:163
#define IMPEX
#define DEBUG_TRACE(msg)
Definition utils.h:67
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
Definition wxcms.cpp:39
Implementation of fast vector type with support of linear algebra operations Copyright (C) 2009 Lukáš...
information about an image inside the cache
Definition ImageCache.h:65
ImageCacheRGB16Ptr image16
Definition ImageCache.h:67
ImageCacheRGB8Ptr image8
Definition ImageCache.h:66
ImageCacheRGBFloatPtr imageFloat
Definition ImageCache.h:68
ImageCacheICCProfile iccProfile
Definition ImageCache.h:70
Entry(ImageCacheRGB8Ptr &img, ImageCacheRGB16Ptr &img16, ImageCacheRGBFloatPtr &imgFloat, ImageCache8Ptr &imgMask, ImageCacheICCProfile &ICCProfile, const std::string &typ)
Definition ImageCache.h:89
PyramidKey(const std::string &str, int lv)
Definition ImageCache.h:376
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