Hugintrunk
0.1
|
This is a cache for all the images we use. More...
#include <ImageCache.h>
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... | |
Public Types | |
typedef std::shared_ptr < vigra::BRGBImage > | ImageCacheRGB8Ptr |
use reference counted pointers More... | |
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< Entry > | EntryPtr |
a shared pointer to the entry More... | |
typedef std::shared_ptr< Request > | RequestPtr |
Reference counted request for an image to load. More... | |
Public Member Functions | |
virtual | ~ImageCache () |
dtor. More... | |
EntryPtr | getImage (const std::string &filename) |
get a image. More... | |
EntryPtr | getImageIfAvailable (const std::string &filename) |
Get an image if already loaded. More... | |
EntryPtr | getSmallImage (const std::string &filename) |
get an small image. More... | |
EntryPtr | getSmallImageIfAvailable (const std::string &filename) |
Get a small image if already loaded. More... | |
RequestPtr | requestAsyncImage (const std::string &filename) |
Request an image be loaded. More... | |
RequestPtr | requestAsyncSmallImage (const std::string &filename) |
Request a small image be loaded. More... | |
void | removeImage (const std::string &filename) |
remove a specific image (and dependant images) from the cache More... | |
void | flush () |
release all images in the cache. More... | |
void | softFlush () |
a soft version of flush. More... | |
void | SetUpperLimit (const unsigned long long newUpperLimit) |
sets the upper limit, which is used by softFlush() More... | |
void | postEvent (RequestPtr request, EntryPtr entry) |
Pass on a loaded event for any images loaded asynchronously. More... | |
void | removeRequest (RequestPtr request) |
Removes the given RequestPtr from queue, Call from main GUI thread when an image could not loaded. More... | |
void | setProgressDisplay (AppBase::ProgressDisplay *disp) |
void | clearProgressDisplay (AppBase::ProgressDisplay *disp) |
Static Public Member Functions | |
static ImageCache & | getInstance () |
get the global ImageCache object More... | |
Public Attributes | |
void(* | asyncLoadCompleteSignal )(RequestPtr, EntryPtr) |
Signal for when a asynchronous load completes. More... | |
Private Member Functions | |
ImageCache () | |
void | spawnAsyncThread () |
Start a background thread to load an image. More... | |
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. More... | |
static EntryPtr | loadImageSafely (const std::string &filename) |
Load a full size image, in a way that will work in parallel. More... | |
static EntryPtr | loadSmallImageSafely (EntryPtr entry) |
Load a small image, in a way that will work in parallel. More... | |
Private Attributes | |
unsigned long long | upperBound |
std::map< std::string, EntryPtr > | images |
AppBase::ProgressDisplay * | m_progress |
int | m_accessCounter |
std::map< std::string, RequestPtr > | m_requests |
std::map< std::string, RequestPtr > | m_smallRequests |
std::map< std::string, vigra::BImage * > | pyrImages |
Static Private Attributes | |
static ImageCache * | instance = NULL |
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.
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.
|
inlineprivate |
Definition at line 155 of file ImageCache.h.
Referenced by getInstance().
|
inlinevirtual |
dtor.
Definition at line 163 of file ImageCache.h.
|
inline |
Definition at line 322 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 160 of file ImageCache.cpp.
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 419 of file ImageCache.cpp.
References images, loadImageSafely(), m_accessCounter, m_progress, AppBase::ProgressDisplay::setMessage(), hugin_utils::stripPath(), and AppBase::ProgressDisplay::taskFinished().
Referenced by PreviewColorPickerTool::CalcCorrectionForImage(), PanoOperation::CelesteOperation::GetInternalCommand(), 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 625 of file ImageCache.cpp.
References images, and m_accessCounter.
Referenced by postEvent(), and spawnAsyncThread().
|
static |
get the global ImageCache object
Definition at line 294 of file ImageCache.cpp.
References ImageCache(), and instance.
Referenced by PreviewColorPickerTool::CalcCorrectionForImage(), PanoOperation::RemoveImageOperation::GetInternalCommand(), PanoOperation::CelesteOperation::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 639 of file ImageCache.cpp.
References DEBUG_DEBUG, DEBUG_INFO, getImage(), images, loadSmallImageSafely(), m_accessCounter, m_progress, AppBase::ProgressDisplay::setMessage(), softFlush(), hugin_utils::stripPath(), and AppBase::ProgressDisplay::taskFinished().
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 730 of file ImageCache.cpp.
References images, m_accessCounter, and softFlush().
Referenced by postEvent().
|
staticprivate |
Definition at line 401 of file ImageCache.cpp.
References vigra::importImageAlpha(), celeste::max(), and vigra_ext::transformImage().
|
staticprivate |
Definition at line 381 of file ImageCache.cpp.
References celeste::max(), and vigra_ext::transformImage().
|
staticprivate |
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 451 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().
|
staticprivate |
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.
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 955 of file ImageCache.cpp.
References asyncLoadCompleteSignal, DEBUG_ERROR, getInstance(), loadImageSafely(), and loadSmallImageSafely().
Referenced by spawnAsyncThread().
|
staticprivate |
Load a small image, in a way that will work in parallel.
If the image cannot be loaded, the pointer returned is 0.
entry | Large image to scale down. |
Definition at line 668 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.
request | The RequestPtr from the ImageLoadedEvent. |
entry | the EntryPtr from the ImageLoadedEvent. |
Definition at line 784 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 125 of file ImageCache.cpp.
References images, pyrImages, and HuginBase::ImageCache::PyramidKey::toString().
Referenced by PanoOperation::RemoveImageOperation::GetInternalCommand().
void HuginBase::ImageCache::removeRequest | ( | RequestPtr | request | ) |
Removes the given RequestPtr from queue, Call from main GUI thread when an image could not loaded.
request | The RequestPtr from the ImageLoadedEvent. |
Definition at line 856 of file ImageCache.cpp.
References m_requests, m_smallRequests, and spawnAsyncThread().
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.
Definition at line 746 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.
Definition at line 765 of file ImageCache.cpp.
References m_requests, m_smallRequests, and spawnAsyncThread().
|
inline |
Definition at line 318 of file ImageCache.h.
|
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 173 of file ImageCache.cpp.
References DEBUG_ASSERT, DEBUG_DEBUG, images, pyrImages, and upperBound.
Referenced by HuginBase::SmallRemappedImageCache::getRemapped(), getSmallImage(), and getSmallImageIfAvailable().
|
private |
Start a background thread to load an image.
Definition at line 918 of file ImageCache.cpp.
References DEBUG_DEBUG, getImageIfAvailable(), loadSafely(), m_requests, and m_smallRequests.
Referenced by postEvent(), removeRequest(), requestAsyncImage(), and requestAsyncSmallImage().
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.
Definition at line 268 of file ImageCache.h.
Referenced by loadSafely().
|
private |
Definition at line 327 of file ImageCache.h.
Referenced by flush(), getImage(), getImageIfAvailable(), getSmallImage(), getSmallImageIfAvailable(), postEvent(), removeImage(), and softFlush().
|
staticprivate |
Definition at line 173 of file ImageCache.h.
Referenced by getInstance().
|
private |
Definition at line 332 of file ImageCache.h.
Referenced by getImage(), getImageIfAvailable(), getSmallImage(), getSmallImageIfAvailable(), and postEvent().
|
private |
Definition at line 330 of file ImageCache.h.
Referenced by getImage(), and getSmallImage().
|
private |
Definition at line 335 of file ImageCache.h.
Referenced by postEvent(), removeRequest(), requestAsyncImage(), requestAsyncSmallImage(), and spawnAsyncThread().
|
private |
Definition at line 338 of file ImageCache.h.
Referenced by postEvent(), removeRequest(), requestAsyncImage(), requestAsyncSmallImage(), and spawnAsyncThread().
|
private |
Definition at line 396 of file ImageCache.h.
Referenced by flush(), removeImage(), and softFlush().
|
private |
Definition at line 287 of file ImageCache.h.
Referenced by softFlush().