HuginBase::ImageCache Class Reference

This is a cache for all the images we use. More...

#include <ImageCache.h>

List of all members.

Public Types

typedef std::shared_ptr< vigra::BRGBImage > ImageCacheRGB8Ptr
 use reference counted pointers
typedef std::shared_ptr< vigra::UInt16RGBImage > ImageCacheRGB16Ptr
typedef std::shared_ptr< vigra::FRGBImage > ImageCacheRGBFloatPtr
typedef std::shared_ptr< vigra::BImage > ImageCache8Ptr
typedef std::shared_ptr< vigra::ImageImportInfo::ICCProfile > ImageCacheICCProfile
typedef std::shared_ptr< EntryEntryPtr
 a shared pointer to the entry
typedef std::shared_ptr< RequestRequestPtr
 Reference counted request for an image to load.

Public Member Functions

virtual ~ImageCache ()
 dtor.
EntryPtr getImage (const std::string &filename)
 get a image.
EntryPtr getImageIfAvailable (const std::string &filename)
 Get an image if already loaded.
EntryPtr getSmallImage (const std::string &filename)
 get an small image.
EntryPtr getSmallImageIfAvailable (const std::string &filename)
 Get a small image if already loaded.
RequestPtr requestAsyncImage (const std::string &filename)
 Request an image be loaded.
RequestPtr requestAsyncSmallImage (const std::string &filename)
 Request a small image be loaded.
void removeImage (const std::string &filename)
 remove a specific image (and dependant images) from the cache
void flush ()
 release all images in the cache.
void softFlush ()
 a soft version of flush.
void SetUpperLimit (long newUpperLimit)
 sets the upper limit, which is used by softFlush()
void postEvent (RequestPtr request, EntryPtr entry)
 Pass on a loaded event for any images loaded asynchronously.
void setProgressDisplay (AppBase::ProgressDisplay *disp)
void clearProgressDisplay (AppBase::ProgressDisplay *disp)

Static Public Member Functions

static ImageCachegetInstance ()
 get the global ImageCache object

Public Attributes

void(* asyncLoadCompleteSignal )(RequestPtr, EntryPtr)
 Signal for when a asynchronous load completes.

Private Member Functions

 ImageCache ()
void spawnAsyncThread ()
 Start a background thread to load an image.

Static Private Member Functions

template<class SrcPixelType, class DestIterator, class DestAccessor>
static void importAndConvertImage (const vigra::ImageImportInfo &info, vigra::pair< DestIterator, DestAccessor > dest, const std::string &type)
template<class SrcPixelType, class DestIterator, class DestAccessor, class MaskIterator, class MaskAccessor>
static void importAndConvertAlphaImage (const vigra::ImageImportInfo &info, vigra::pair< DestIterator, DestAccessor > dest, vigra::pair< MaskIterator, MaskAccessor > mask, const std::string &type)
static void loadSafely (RequestPtr request, EntryPtr large=EntryPtr())
 Load a requested image in a way that will work in parallel.
static EntryPtr loadImageSafely (const std::string &filename)
 Load a full size image, in a way that will work in parallel.
static EntryPtr loadSmallImageSafely (EntryPtr entry)
 Load a small image, in a way that will work in parallel.

Private Attributes

long upperBound
std::map< std::string, EntryPtrimages
AppBase::ProgressDisplaym_progress
int m_accessCounter
std::map< std::string, RequestPtrm_requests
std::map< std::string, RequestPtrm_smallRequests
std::map< std::string, vigra::BImage * > pyrImages

Static Private Attributes

static ImageCacheinstance = NULL

Classes

struct  Entry
 information about an image inside the cache More...
struct  PyramidKey
 get a pyramid image. More...
class  Request
 Request for an image to load Connect to the ready signal so when the image loads you can respond. More...


Detailed Description

This is a cache for all the images we use.

is a singleton for easy access from everywhere. The cache is used as an image source, that needs to know how to reproduce the requested images, in case that they have been deleted.

Definition at line 52 of file ImageCache.h.


Member Typedef Documentation

typedef std::shared_ptr<Entry> HuginBase::ImageCache::EntryPtr

a shared pointer to the entry

Definition at line 112 of file ImageCache.h.

typedef std::shared_ptr<vigra::BImage> HuginBase::ImageCache::ImageCache8Ptr

Definition at line 60 of file ImageCache.h.

typedef std::shared_ptr<vigra::ImageImportInfo::ICCProfile> HuginBase::ImageCache::ImageCacheICCProfile

Definition at line 61 of file ImageCache.h.

typedef std::shared_ptr<vigra::UInt16RGBImage> HuginBase::ImageCache::ImageCacheRGB16Ptr

Definition at line 58 of file ImageCache.h.

typedef std::shared_ptr<vigra::BRGBImage> HuginBase::ImageCache::ImageCacheRGB8Ptr

use reference counted pointers

Definition at line 57 of file ImageCache.h.

typedef std::shared_ptr<vigra::FRGBImage> HuginBase::ImageCache::ImageCacheRGBFloatPtr

Definition at line 59 of file ImageCache.h.

typedef std::shared_ptr<Request> HuginBase::ImageCache::RequestPtr

Reference counted request for an image to load.

Hold on to this when you want an image to load. If you no longer want the image, just delete it. Deleting it before the image loads lets other images load next.

Connect to the ready signal to respond to the image loading. To keep the image loaded, keep the EntryPtr given to the signal handler.

It is reference counted, so you can freely copy and delete it.

Definition at line 151 of file ImageCache.h.


Constructor & Destructor Documentation

HuginBase::ImageCache::ImageCache (  )  [inline, private]

Definition at line 155 of file ImageCache.h.

Referenced by getInstance().

virtual HuginBase::ImageCache::~ImageCache (  )  [inline, virtual]

dtor.

Definition at line 163 of file ImageCache.h.


Member Function Documentation

void HuginBase::ImageCache::clearProgressDisplay ( AppBase::ProgressDisplay disp  )  [inline]

Definition at line 315 of file ImageCache.h.

void HuginBase::ImageCache::flush (  ) 

release all images in the cache.

useful on project load, or maybe before stitching really big pictures

Definition at line 161 of file ImageCache.cpp.

References images, and pyrImages.

ImageCache::EntryPtr HuginBase::ImageCache::getImage ( const std::string filename  ) 

get a image.

it will be loaded if its not already in the cache

Hold the EntryPtr as long as the image data is needed!

If it isn't vital that the real image is obtained immediately, use getImageIfAvailable instead. This means you can keep the UI responsive while the real image is fetched from a disk or network and decoded.

Definition at line 418 of file ImageCache.cpp.

References images, loadImageSafely(), m_accessCounter, m_progress, and hugin_utils::stripPath().

Referenced by getSmallImage(), and postEvent().

ImageCache::EntryPtr HuginBase::ImageCache::getImageIfAvailable ( const std::string filename  ) 

Get an image if already loaded.

If not already in the cache, the pointer returned is 0.

Hold a non-zero EntryPtr as long as the image data is needed.

If you really need the image immediately, use getImage() instead.

Definition at line 624 of file ImageCache.cpp.

References images, and m_accessCounter.

Referenced by postEvent(), and spawnAsyncThread().

ImageCache & HuginBase::ImageCache::getInstance (  )  [static]

get the global ImageCache object

Definition at line 293 of file ImageCache.cpp.

References ImageCache(), and instance.

Referenced by PreviewColorPickerTool::CalcCorrectionForImage(), PanoOperation::CelesteOperation::GetInternalCommand(), PanoOperation::RemoveImageOperation::GetInternalCommand(), HuginBase::SmallRemappedImageCache::getRemapped(), and loadSafely().

ImageCache::EntryPtr HuginBase::ImageCache::getSmallImage ( const std::string filename  ) 

get an small image.

This image is 512x512 pixel maximum and can be used for icons and different previews. It is directly derived from the original.

If it isn't vital that the real image is obtained immediately, use getSmallImageIfAvailable instead. This means you can keep the UI responsive while the real image is fetched, decoded, and scaled.

Definition at line 638 of file ImageCache.cpp.

References DEBUG_DEBUG, DEBUG_INFO, getImage(), images, loadSmallImageSafely(), m_accessCounter, m_progress, softFlush(), and hugin_utils::stripPath().

Referenced by HuginBase::SmallRemappedImageCache::getRemapped(), and postEvent().

ImageCache::EntryPtr HuginBase::ImageCache::getSmallImageIfAvailable ( const std::string filename  ) 

Get a small image if already loaded.

The EntryPtr returned is 0 if the image isn't loaded yet.

This image is 512x512 pixels maximum and can be used for icons and different previews. It is directly derived from the original.

If you really need the image immediately, use getSmallImage() instead.

Definition at line 729 of file ImageCache.cpp.

References images, m_accessCounter, and softFlush().

Referenced by postEvent().

template<class SrcPixelType, class DestIterator, class DestAccessor, class MaskIterator, class MaskAccessor>
void HuginBase::ImageCache::importAndConvertAlphaImage ( const vigra::ImageImportInfo &  info,
vigra::pair< DestIterator, DestAccessor >  dest,
vigra::pair< MaskIterator, MaskAccessor >  mask,
const std::string type 
) [static, private]

Definition at line 400 of file ImageCache.cpp.

References vigra::importImageAlpha(), celeste::max(), and vigra_ext::transformImage().

template<class SrcPixelType, class DestIterator, class DestAccessor>
void HuginBase::ImageCache::importAndConvertImage ( const vigra::ImageImportInfo &  info,
vigra::pair< DestIterator, DestAccessor >  dest,
const std::string type 
) [static, private]

Definition at line 380 of file ImageCache.cpp.

References celeste::max(), and vigra_ext::transformImage().

ImageCache::EntryPtr HuginBase::ImageCache::loadImageSafely ( const std::string filename  )  [static, private]

Load a full size image, in a way that will work in parallel.

If the image cannot be loaded, the pointer returned is 0.

Definition at line 450 of file ImageCache.cpp.

References vigra::omp::copyImage(), DEBUG_DEBUG, DEBUG_ERROR, DEBUG_FATAL, vigra_ext::destImage(), vigra::importImageAlpha(), celeste::info(), and vigra_ext::srcImageRange().

Referenced by getImage(), and loadSafely().

void HuginBase::ImageCache::loadSafely ( RequestPtr  request,
EntryPtr  large = EntryPtr() 
) [static, private]

Load a requested image in a way that will work in parallel.

When done, it sends an event with the newly created EntryPtr and request.

Parameters:
RequestPtr request for the image to load.
large EntryPtr for the large image when a small image is to be generated from it. Use a 0 pointer (the default) to generate a full size image.

Definition at line 892 of file ImageCache.cpp.

References asyncLoadCompleteSignal, DEBUG_ERROR, getInstance(), loadImageSafely(), and loadSmallImageSafely().

Referenced by spawnAsyncThread().

ImageCache::EntryPtr HuginBase::ImageCache::loadSmallImageSafely ( EntryPtr  entry  )  [static, private]

Load a small image, in a way that will work in parallel.

If the image cannot be loaded, the pointer returned is 0.

Parameters:
entry Large image to scale down.

Definition at line 667 of file ImageCache.cpp.

References vigra_ext::EMoR::h, and vigra_ext::reduceNTimes().

Referenced by getSmallImage(), and loadSafely().

void HuginBase::ImageCache::postEvent ( RequestPtr  request,
EntryPtr  entry 
)

Pass on a loaded event for any images loaded asynchronously.

Call from the main GUI thread when an ImageLoadedEvent occurs. The ImageLoadedEvent originates from async_load_thread.

Parameters:
request The RequestPtr from the ImageLoadedEvent.
entry the EntryPtr from the ImageLoadedEvent.

Definition at line 783 of file ImageCache.cpp.

References getImage(), getImageIfAvailable(), getSmallImage(), getSmallImageIfAvailable(), images, m_accessCounter, m_requests, m_smallRequests, and spawnAsyncThread().

void HuginBase::ImageCache::removeImage ( const std::string filename  ) 

remove a specific image (and dependant images) from the cache

Definition at line 126 of file ImageCache.cpp.

References images, pyrImages, and HuginBase::ImageCache::PyramidKey::toString().

ImageCache::RequestPtr HuginBase::ImageCache::requestAsyncImage ( const std::string filename  ) 

Request an image be loaded.

This function returns quickly even when the image is not cached.

Returns:
Object to keep while you want the image. Connect to its ready signal to be notified when the image is ready.

Definition at line 745 of file ImageCache.cpp.

References m_requests, m_smallRequests, and spawnAsyncThread().

ImageCache::RequestPtr HuginBase::ImageCache::requestAsyncSmallImage ( const std::string filename  ) 

Request a small image be loaded.

This function returns quickly even when the image is not cached.

Returns:
Object to keep while you want the image. Connect to its ready signal to be notified when it is ready.

Definition at line 764 of file ImageCache.cpp.

References m_requests, m_smallRequests, and spawnAsyncThread().

void HuginBase::ImageCache::setProgressDisplay ( AppBase::ProgressDisplay disp  )  [inline]

Definition at line 311 of file ImageCache.h.

void HuginBase::ImageCache::SetUpperLimit ( long  newUpperLimit  )  [inline]

sets the upper limit, which is used by softFlush()

Definition at line 256 of file ImageCache.h.

void HuginBase::ImageCache::softFlush (  ) 

a soft version of flush.

Releases some images if they go over a certain threshold

Definition at line 174 of file ImageCache.cpp.

References cout, DEBUG_ASSERT, DEBUG_DEBUG, images, pyrImages, and upperBound.

Referenced by HuginBase::SmallRemappedImageCache::getRemapped(), getSmallImage(), and getSmallImageIfAvailable().

void HuginBase::ImageCache::spawnAsyncThread (  )  [private]

Start a background thread to load an image.

Definition at line 855 of file ImageCache.cpp.

References DEBUG_DEBUG, getImageIfAvailable(), loadSafely(), m_requests, and m_smallRequests.

Referenced by postEvent(), requestAsyncImage(), and requestAsyncSmallImage().


Member Data Documentation

void(* HuginBase::ImageCache::asyncLoadCompleteSignal)(RequestPtr, EntryPtr)

Signal for when a asynchronous load completes.

If you use the requestAsync functions, ensure there is something connected to this signal. The signal is raised in another thread, so the handler must be thread safe.

The signal handler must pass the request and entry to postEvent from the main thread when it is safe. For example, it you can wrap the request and entry in some wxEvent and the main thread can handle it later.

Referenced by loadSafely().

std::map<std::string, EntryPtr> HuginBase::ImageCache::images [private]

Definition at line 320 of file ImageCache.h.

Referenced by flush(), getImage(), getImageIfAvailable(), getSmallImage(), getSmallImageIfAvailable(), postEvent(), removeImage(), and softFlush().

ImageCache * HuginBase::ImageCache::instance = NULL [static, private]

Definition at line 173 of file ImageCache.h.

Referenced by getInstance().

int HuginBase::ImageCache::m_accessCounter [private]

Definition at line 325 of file ImageCache.h.

Referenced by getImage(), getImageIfAvailable(), getSmallImage(), getSmallImageIfAvailable(), and postEvent().

AppBase::ProgressDisplay* HuginBase::ImageCache::m_progress [private]

Definition at line 323 of file ImageCache.h.

Referenced by getImage(), and getSmallImage().

std::map<std::string, RequestPtr> HuginBase::ImageCache::m_requests [private]

Definition at line 328 of file ImageCache.h.

Referenced by postEvent(), requestAsyncImage(), requestAsyncSmallImage(), and spawnAsyncThread().

std::map<std::string, RequestPtr> HuginBase::ImageCache::m_smallRequests [private]

Definition at line 331 of file ImageCache.h.

Referenced by postEvent(), requestAsyncImage(), requestAsyncSmallImage(), and spawnAsyncThread().

std::map<std::string, vigra::BImage *> HuginBase::ImageCache::pyrImages [private]

Definition at line 389 of file ImageCache.h.

Referenced by flush(), removeImage(), and softFlush().

long HuginBase::ImageCache::upperBound [private]

Definition at line 280 of file ImageCache.h.

Referenced by softFlush().


The documentation for this class was generated from the following files:
Generated on 29 May 2016 for Hugintrunk by  doxygen 1.4.7