|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
#undef _STLP_DEBUG
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define _STLP_DEBUG 1
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUGTOONZ
|
|
Toshihiro Shimizu |
890ddd |
#undef _DEBUGTOONZ
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
#define _DEBUGTOONZ _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "timagecache.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trasterimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trastercm.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tropcm.h"
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tcodec.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tfilepath_io.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tconvert.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tsystem.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "traster.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//#include "tstopwatch.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tconvert.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tbigmemorymanager.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tstream.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tenv.h"
|
|
Toshihiro Shimizu |
890ddd |
#include <deque></deque>
|
|
Toshihiro Shimizu |
890ddd |
#include <numeric></numeric>
|
|
Toshihiro Shimizu |
890ddd |
#include <sstream></sstream>
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
#include <crtdbg.h></crtdbg.h>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Qt includes
|
|
Toshihiro Shimizu |
890ddd |
#include <qthreadstorage></qthreadstorage>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#undef DVAPI
|
|
Toshihiro Shimizu |
890ddd |
#undef DVVAR
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TSYSTEM_EXPORTS
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_EXPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_EXPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_IMPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_IMPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class ImageBuilder;
|
|
Toshihiro Shimizu |
890ddd |
class ImageInfo;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//std::ofstream os("C:\\cache.txt");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 HistoryCount = 0;
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TheCodec : public TRasterCodecLz4
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
static TheCodec *instance()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!_instance)
|
|
Toshihiro Shimizu |
890ddd |
_instance = new TheCodec();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return _instance;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void reset()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (_instance)
|
|
Toshihiro Shimizu |
890ddd |
_instance->TRasterCodecLz4::reset();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Toshihiro Shimizu |
890ddd |
static TheCodec *_instance;
|
|
Toshihiro Shimizu |
890ddd |
TheCodec() : TRasterCodecLz4("Lz4_Codec", false) {}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TheCodec *TheCodec::_instance = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class CacheItem : public TSmartObject
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
DECLARE_CLASS_CODE
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
CacheItem()
|
|
Toshihiro Shimizu |
890ddd |
: m_cantCompress(false), m_builder(0), m_imageInfo(0), m_modified(false) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CacheItem(ImageBuilder *builder, ImageInfo *imageInfo)
|
|
Toshihiro Shimizu |
890ddd |
: m_cantCompress(false), m_builder(builder), m_imageInfo(imageInfo), m_historyCount(0), m_modified(false)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual ~CacheItem() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual TUINT32 getSize() const = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// getImage restituisce un'immagine non compressa
|
|
Toshihiro Shimizu |
890ddd |
virtual TImageP getImage() const = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool m_cantCompress;
|
|
Toshihiro Shimizu |
890ddd |
ImageBuilder *m_builder;
|
|
Toshihiro Shimizu |
890ddd |
ImageInfo *m_imageInfo;
|
|
Toshihiro Shimizu |
890ddd |
string m_id;
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 m_historyCount;
|
|
Toshihiro Shimizu |
890ddd |
bool m_modified;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TSmartPointerT<cacheitem>;</cacheitem>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
typedef TSmartPointerT<cacheitem> CacheItemP;</cacheitem>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DEFINE_CLASS_CODE(CacheItem, 101)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class ImageInfo
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TDimension m_size;
|
|
Toshihiro Shimizu |
890ddd |
ImageInfo(const TDimension &size) : m_size(size) {}
|
|
Toshihiro Shimizu |
890ddd |
virtual ~ImageInfo() {}
|
|
Toshihiro Shimizu |
890ddd |
virtual ImageInfo *clone() = 0;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class ImageBuilder
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
virtual ~ImageBuilder() {}
|
|
Toshihiro Shimizu |
890ddd |
virtual ImageBuilder *clone() = 0;
|
|
Toshihiro Shimizu |
890ddd |
virtual TImageP build(ImageInfo *info, const TRasterP &ras) = 0;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class RasterImageInfo : public ImageInfo
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
RasterImageInfo(const TRasterImageP &ri);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void setInfo(const TRasterImageP &ri);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ImageInfo *clone();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double m_dpix, m_dpiy;
|
|
Toshihiro Shimizu |
890ddd |
string m_name;
|
|
Toshihiro Shimizu |
890ddd |
TRect m_savebox;
|
|
Toshihiro Shimizu |
890ddd |
bool m_isOpaque;
|
|
Toshihiro Shimizu |
890ddd |
TPoint m_offset;
|
|
Toshihiro Shimizu |
890ddd |
int m_subs;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
RasterImageInfo::RasterImageInfo(const TRasterImageP &ri)
|
|
Toshihiro Shimizu |
890ddd |
: ImageInfo(ri->getRaster()->getSize())
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
ri->getDpi(m_dpix, m_dpiy);
|
|
Toshihiro Shimizu |
890ddd |
m_name = ri->getName();
|
|
Toshihiro Shimizu |
890ddd |
m_savebox = ri->getSavebox();
|
|
Toshihiro Shimizu |
890ddd |
m_isOpaque = ri->isOpaque();
|
|
Toshihiro Shimizu |
890ddd |
m_offset = ri->getOffset();
|
|
Toshihiro Shimizu |
890ddd |
m_subs = ri->getSubsampling();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void RasterImageInfo::setInfo(const TRasterImageP &ri)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
ri->setDpi(m_dpix, m_dpiy);
|
|
Toshihiro Shimizu |
890ddd |
ri->setName(m_name);
|
|
Toshihiro Shimizu |
890ddd |
ri->setSavebox(m_savebox);
|
|
Toshihiro Shimizu |
890ddd |
ri->setOpaqueFlag(m_isOpaque);
|
|
Toshihiro Shimizu |
890ddd |
ri->setOffset(m_offset);
|
|
Toshihiro Shimizu |
890ddd |
ri->setSubsampling(m_subs);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ImageInfo *RasterImageInfo::clone()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return new RasterImageInfo(*this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tpalette.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "ttoonzimage.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class ToonzImageInfo : public ImageInfo
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
ToonzImageInfo(const TToonzImageP &ti);
|
|
Toshihiro Shimizu |
890ddd |
~ToonzImageInfo()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_palette)
|
|
Toshihiro Shimizu |
890ddd |
m_palette->release();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ImageInfo *clone()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
ToonzImageInfo *ret = new ToonzImageInfo(*this);
|
|
Toshihiro Shimizu |
890ddd |
if (ret->m_palette)
|
|
Toshihiro Shimizu |
890ddd |
ret->m_palette->addRef();
|
|
Toshihiro Shimizu |
890ddd |
return ret;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void setInfo(const TToonzImageP &ti);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double m_dpix, m_dpiy;
|
|
Toshihiro Shimizu |
890ddd |
string m_name;
|
|
Toshihiro Shimizu |
890ddd |
TRect m_savebox;
|
|
Toshihiro Shimizu |
890ddd |
TPoint m_offset;
|
|
Toshihiro Shimizu |
890ddd |
int m_subs;
|
|
Toshihiro Shimizu |
890ddd |
TPalette *m_palette;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ToonzImageInfo::ToonzImageInfo(const TToonzImageP &ti) : ImageInfo(ti->getSize())
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_palette = ti->getPalette();
|
|
Toshihiro Shimizu |
890ddd |
if (m_palette)
|
|
Toshihiro Shimizu |
890ddd |
m_palette->addRef();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ti->getDpi(m_dpix, m_dpiy);
|
|
Toshihiro Shimizu |
890ddd |
m_savebox = ti->getSavebox();
|
|
Toshihiro Shimizu |
890ddd |
m_offset = ti->getOffset();
|
|
Toshihiro Shimizu |
890ddd |
m_subs = ti->getSubsampling();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void ToonzImageInfo::setInfo(const TToonzImageP &ti)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
ti->setPalette(m_palette);
|
|
Toshihiro Shimizu |
890ddd |
ti->setDpi(m_dpix, m_dpiy);
|
|
Toshihiro Shimizu |
890ddd |
ti->setOffset(m_offset);
|
|
Toshihiro Shimizu |
890ddd |
ti->setSubsampling(m_subs);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class RasterImageBuilder : public ImageBuilder
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
ImageBuilder *clone()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return new RasterImageBuilder(*this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP build(ImageInfo *info, const TRasterP &ras);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP RasterImageBuilder::build(ImageInfo *info, const TRasterP &ras)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
RasterImageInfo *riInfo = dynamic_cast<rasterimageinfo *="">(info);</rasterimageinfo>
|
|
Toshihiro Shimizu |
890ddd |
assert(riInfo);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int rcount = ras->getRefCount();
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = new TRasterImage();
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUGTOONZ
|
|
Toshihiro Shimizu |
890ddd |
ras->m_cashed = true;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
ri->setRaster(ras);
|
|
Toshihiro Shimizu |
890ddd |
riInfo->setInfo(ri);
|
|
Toshihiro Shimizu |
890ddd |
assert(ras->getRefCount() > rcount);
|
|
Toshihiro Shimizu |
890ddd |
return ri;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class ToonzImageBuilder : public ImageBuilder
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
ImageBuilder *clone()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return new ToonzImageBuilder(*this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP build(ImageInfo *info, const TRasterP &ras);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP ToonzImageBuilder::build(ImageInfo *info, const TRasterP &ras)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
ToonzImageInfo *tiInfo = dynamic_cast<toonzimageinfo *="">(info);</toonzimageinfo>
|
|
Toshihiro Shimizu |
890ddd |
assert(tiInfo);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32P rasCM32 = ras;
|
|
Toshihiro Shimizu |
890ddd |
assert(rasCM32);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32P imgRasCM32;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(TRect(tiInfo->m_size).contains(tiInfo->m_savebox));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (ras->getSize() != tiInfo->m_size) {
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32P fullRas(tiInfo->m_size);
|
|
Toshihiro Shimizu |
890ddd |
TRect rectToExtract(tiInfo->m_savebox);
|
|
Toshihiro Shimizu |
890ddd |
TPixelCM32 bgColor;
|
|
Toshihiro Shimizu |
890ddd |
fullRas->fillOutside(tiInfo->m_savebox, bgColor);
|
|
Toshihiro Shimizu |
890ddd |
fullRas->extractT(rectToExtract)->copy(ras);
|
|
Toshihiro Shimizu |
890ddd |
assert(rectToExtract == tiInfo->m_savebox);
|
|
Toshihiro Shimizu |
890ddd |
imgRasCM32 = fullRas;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
imgRasCM32 = rasCM32;
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
imgRasCM32->m_cashed = true;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = new TToonzImage(imgRasCM32, tiInfo->m_savebox);
|
|
Toshihiro Shimizu |
890ddd |
tiInfo->setInfo(ti);
|
|
Toshihiro Shimizu |
890ddd |
return ti;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class UncompressedOnMemoryCacheItem : public CacheItem
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnMemoryCacheItem(const TImageP &image) : m_image(image)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = m_image;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (ri)
|
|
Toshihiro Shimizu |
890ddd |
m_imageInfo = new RasterImageInfo(ri);
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = m_image;
|
|
Toshihiro Shimizu |
890ddd |
if (ti)
|
|
Toshihiro Shimizu |
890ddd |
m_imageInfo = new ToonzImageInfo(ti);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
m_imageInfo = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
m_imageInfo = 0;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~UncompressedOnMemoryCacheItem()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_imageInfo)
|
|
Toshihiro Shimizu |
890ddd |
delete m_imageInfo;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 getSize() const;
|
|
Toshihiro Shimizu |
890ddd |
TImageP getImage() const { return m_image; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP m_image;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TSmartPointerT<uncompressedonmemorycacheitem>;</uncompressedonmemorycacheitem>
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TDerivedSmartPointerT<uncompressedonmemorycacheitem, cacheitem="">;</uncompressedonmemorycacheitem,>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
typedef TDerivedSmartPointerT<uncompressedonmemorycacheitem, cacheitem=""> UncompressedOnMemoryCacheItemP;</uncompressedonmemorycacheitem,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 UncompressedOnMemoryCacheItem::getSize() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = m_image;
|
|
Toshihiro Shimizu |
890ddd |
if (ri) {
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
if (ras)
|
|
Toshihiro Shimizu |
890ddd |
return ras->getLy() * ras->getRowSize();
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = m_image;
|
|
Toshihiro Shimizu |
890ddd |
if (ti) {
|
|
Toshihiro Shimizu |
890ddd |
TDimension size = ti->getSize();
|
|
Toshihiro Shimizu |
890ddd |
return size.lx * size.ly * sizeof(TPixelCM32);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class CompressedOnMemoryCacheItem : public CacheItem
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnMemoryCacheItem(const TImageP &img);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnMemoryCacheItem(const TRasterP &compressedRas,
|
|
Toshihiro Shimizu |
890ddd |
ImageBuilder *builder,
|
|
Toshihiro Shimizu |
890ddd |
ImageInfo *info);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~CompressedOnMemoryCacheItem();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 getSize() const;
|
|
Toshihiro Shimizu |
890ddd |
TImageP getImage() const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterP m_compressedRas;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TSmartPointerT<compressedonmemorycacheitem>;</compressedonmemorycacheitem>
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TDerivedSmartPointerT<compressedonmemorycacheitem, cacheitem="">;</compressedonmemorycacheitem,>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
typedef TDerivedSmartPointerT<compressedonmemorycacheitem, cacheitem=""> CompressedOnMemoryCacheItemP;</compressedonmemorycacheitem,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnMemoryCacheItem::CompressedOnMemoryCacheItem(const TImageP &img)
|
|
Toshihiro Shimizu |
890ddd |
: m_compressedRas()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = img;
|
|
Toshihiro Shimizu |
890ddd |
if (ri) {
|
|
Toshihiro Shimizu |
890ddd |
m_imageInfo = new RasterImageInfo(ri);
|
|
Toshihiro Shimizu |
890ddd |
m_builder = new RasterImageBuilder();
|
|
Toshihiro Shimizu |
890ddd |
TINT32 buffSize = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_compressedRas = TheCodec::instance()->compress(ri->getRaster(), 1, buffSize);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = img;
|
|
Toshihiro Shimizu |
890ddd |
if (ti) {
|
|
Toshihiro Shimizu |
890ddd |
m_imageInfo = new ToonzImageInfo(ti);
|
|
Toshihiro Shimizu |
890ddd |
m_builder = new ToonzImageBuilder();
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32P rasCM32 = ti->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
TINT32 buffSize = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_compressedRas = TheCodec::instance()->compress(rasCM32, 1, buffSize);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
assert(false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
assert(false);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnMemoryCacheItem::CompressedOnMemoryCacheItem(const TRasterP &ras,
|
|
Toshihiro Shimizu |
890ddd |
ImageBuilder *builder,
|
|
Toshihiro Shimizu |
890ddd |
ImageInfo *info)
|
|
Toshihiro Shimizu |
890ddd |
: CacheItem(builder, info), m_compressedRas(ras)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnMemoryCacheItem::~CompressedOnMemoryCacheItem()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
delete m_imageInfo;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 CompressedOnMemoryCacheItem::getSize() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_compressedRas)
|
|
Toshihiro Shimizu |
890ddd |
return m_compressedRas->getLx();
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP CompressedOnMemoryCacheItem::getImage() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(m_compressedRas);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// PER IL MOMENTO DISCRIMINO: DA ELIMINARE
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TheCodec::instance()->decompress(m_compressedRas, ras);
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUGTOONZ
|
|
Toshihiro Shimizu |
890ddd |
ras->m_cashed = true;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
ToonzImageBuilder *tibuilder = dynamic_cast<toonzimagebuilder *="">(m_builder);</toonzimagebuilder>
|
|
Toshihiro Shimizu |
890ddd |
if (tibuilder)
|
|
Toshihiro Shimizu |
890ddd |
return tibuilder->build(m_imageInfo, ras);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
return m_builder->build(m_imageInfo, ras);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class CompressedOnDiskCacheItem : public CacheItem
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnDiskCacheItem(const TFilePath &fp,
|
|
Toshihiro Shimizu |
890ddd |
const TRasterP &compressedRas,
|
|
Toshihiro Shimizu |
890ddd |
ImageBuilder *builder,
|
|
Toshihiro Shimizu |
890ddd |
ImageInfo *info);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~CompressedOnDiskCacheItem();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 getSize() const { return 0; }
|
|
Toshihiro Shimizu |
890ddd |
TImageP getImage() const;
|
|
Toshihiro Shimizu |
890ddd |
TFilePath m_fp;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TSmartPointerT<compressedondiskcacheitem>;</compressedondiskcacheitem>
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TDerivedSmartPointerT<compressedondiskcacheitem, cacheitem="">;</compressedondiskcacheitem,>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
typedef TDerivedSmartPointerT<compressedondiskcacheitem, cacheitem=""> CompressedOnDiskCacheItemP;</compressedondiskcacheitem,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnDiskCacheItem::CompressedOnDiskCacheItem(const TFilePath &fp,
|
|
Toshihiro Shimizu |
890ddd |
const TRasterP &compressedRas,
|
|
Toshihiro Shimizu |
890ddd |
ImageBuilder *builder,
|
|
Toshihiro Shimizu |
890ddd |
ImageInfo *info)
|
|
Toshihiro Shimizu |
890ddd |
: CacheItem(builder, info), m_fp(fp)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
compressedRas->lock();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tofstream oss(m_fp);
|
|
Toshihiro Shimizu |
890ddd |
assert(compressedRas->getLy() == 1 && compressedRas->getPixelSize() == 1);
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 size = compressedRas->getLx();
|
|
Toshihiro Shimizu |
890ddd |
oss.write((char *)&size, sizeof(TUINT32));
|
|
Toshihiro Shimizu |
890ddd |
oss.write((char *)compressedRas->getRawData(), size);
|
|
Toshihiro Shimizu |
890ddd |
assert(!oss.fail());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
compressedRas->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnDiskCacheItem::~CompressedOnDiskCacheItem()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
delete m_imageInfo;
|
|
Toshihiro Shimizu |
890ddd |
TSystem::deleteFile(m_fp);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP CompressedOnDiskCacheItem::getImage() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Tifstream is(m_fp);
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 dataSize;
|
|
Toshihiro Shimizu |
890ddd |
is.read((char *)&dataSize, sizeof(TUINT32));
|
|
Toshihiro Shimizu |
890ddd |
TRasterGR8P ras(dataSize, 1);
|
|
Toshihiro Shimizu |
890ddd |
ras->lock();
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *data = ras->getRawData();
|
|
Toshihiro Shimizu |
890ddd |
is.read((char *)data, dataSize);
|
|
Toshihiro Shimizu |
890ddd |
assert(!is.fail());
|
|
Toshihiro Shimizu |
890ddd |
ras->unlock();
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnMemoryCacheItem item(ras, m_builder->clone(), m_imageInfo->clone());
|
|
Toshihiro Shimizu |
890ddd |
return item.getImage();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class UncompressedOnDiskCacheItem : public CacheItem
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int m_pixelsize;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnDiskCacheItem(const TFilePath &fp,
|
|
Toshihiro Shimizu |
890ddd |
const TImageP &img);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~UncompressedOnDiskCacheItem();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 getSize() const { return 0; }
|
|
Toshihiro Shimizu |
890ddd |
TImageP getImage() const;
|
|
Toshihiro Shimizu |
890ddd |
//TRaster32P getRaster32() const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePath m_fp;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TSmartPointerT<uncompressedondiskcacheitem>;</uncompressedondiskcacheitem>
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TDerivedSmartPointerT<uncompressedondiskcacheitem, cacheitem="">;</uncompressedondiskcacheitem,>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
typedef TDerivedSmartPointerT<uncompressedondiskcacheitem, cacheitem=""> UncompressedOnDiskCacheItemP;</uncompressedondiskcacheitem,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnDiskCacheItem::UncompressedOnDiskCacheItem(const TFilePath &fp,
|
|
Toshihiro Shimizu |
890ddd |
const TImageP &image)
|
|
Toshihiro Shimizu |
890ddd |
: CacheItem(0, 0), m_fp(fp)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = image;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras;
|
|
Toshihiro Shimizu |
890ddd |
if (ri) {
|
|
Toshihiro Shimizu |
890ddd |
m_imageInfo = new RasterImageInfo(ri);
|
|
Toshihiro Shimizu |
890ddd |
ras = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = image;
|
|
Toshihiro Shimizu |
890ddd |
if (ti) {
|
|
Toshihiro Shimizu |
890ddd |
m_imageInfo = new ToonzImageInfo(ti);
|
|
Toshihiro Shimizu |
890ddd |
ras = ti->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
assert(false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
assert(false);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_builder = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int dataSize = ras->getLx() * ras->getLy() * ras->getPixelSize();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int lx = ras->getLx();
|
|
Toshihiro Shimizu |
890ddd |
int ly = ras->getLy();
|
|
Toshihiro Shimizu |
890ddd |
int wrap = ras->getWrap();
|
|
Toshihiro Shimizu |
890ddd |
m_pixelsize = ras->getPixelSize();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tofstream oss(m_fp);
|
|
Toshihiro Shimizu |
890ddd |
//oss.write((char*)&dataSize, sizeof(TUINT32));
|
|
Toshihiro Shimizu |
890ddd |
//assert(!oss.fail());
|
|
Toshihiro Shimizu |
890ddd |
ras->lock();
|
|
Toshihiro Shimizu |
890ddd |
if (lx == wrap) {
|
|
Toshihiro Shimizu |
890ddd |
oss.write((char *)ras->getRawData(), dataSize);
|
|
Toshihiro Shimizu |
890ddd |
assert(!oss.fail());
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
char *buf = (char *)ras->getRawData();
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < ly; i++, buf += wrap) {
|
|
Toshihiro Shimizu |
890ddd |
oss.write(buf, lx * m_pixelsize);
|
|
Toshihiro Shimizu |
890ddd |
assert(!oss.fail());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
ras->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnDiskCacheItem::~UncompressedOnDiskCacheItem()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
delete m_imageInfo;
|
|
Toshihiro Shimizu |
890ddd |
TSystem::deleteFile(m_fp);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP UncompressedOnDiskCacheItem::getImage() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Tifstream is(m_fp);
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 dataSize = m_imageInfo->m_size.lx * m_imageInfo->m_size.ly * m_pixelsize;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//is.read((char*)&dataSize, sizeof(TUINT32));
|
|
Toshihiro Shimizu |
890ddd |
//assert(unsigned(m_lx*m_ly*m_pixelsize)==dataSize);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
RasterImageInfo *rii = dynamic_cast<rasterimageinfo *="">(m_imageInfo);</rasterimageinfo>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (rii) {
|
|
Toshihiro Shimizu |
890ddd |
if (m_pixelsize == 4)
|
|
Toshihiro Shimizu |
890ddd |
ras = (TRasterP)(TRaster32P(rii->m_size));
|
|
Toshihiro Shimizu |
890ddd |
else if (m_pixelsize == 8)
|
|
Toshihiro Shimizu |
890ddd |
ras = (TRasterP)(TRaster64P(rii->m_size));
|
|
Toshihiro Shimizu |
890ddd |
else if (m_pixelsize == 1)
|
|
Toshihiro Shimizu |
890ddd |
ras = (TRasterP)(TRasterGR8P(rii->m_size));
|
|
Toshihiro Shimizu |
890ddd |
else if (m_pixelsize == 2)
|
|
Toshihiro Shimizu |
890ddd |
ras = (TRasterP)(TRasterGR16P(rii->m_size));
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
assert(false);
|
|
Toshihiro Shimizu |
890ddd |
ras->lock();
|
|
Toshihiro Shimizu |
890ddd |
char *data = (char *)ras->getRawData();
|
|
Toshihiro Shimizu |
890ddd |
is.read(data, dataSize);
|
|
Toshihiro Shimizu |
890ddd |
ras->unlock();
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUGTOONZ
|
|
Toshihiro Shimizu |
890ddd |
ras->m_cashed = true;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return RasterImageBuilder().build(m_imageInfo, ras);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
ToonzImageInfo *tii = dynamic_cast<toonzimageinfo *="">(m_imageInfo);</toonzimageinfo>
|
|
Toshihiro Shimizu |
890ddd |
if (tii) {
|
|
Toshihiro Shimizu |
890ddd |
ras = (TRasterP)(TRasterCM32P(tii->m_size));
|
|
Toshihiro Shimizu |
890ddd |
ras->lock();
|
|
Toshihiro Shimizu |
890ddd |
char *data = (char *)ras->getRawData();
|
|
Toshihiro Shimizu |
890ddd |
is.read(data, dataSize);
|
|
Toshihiro Shimizu |
890ddd |
ras->unlock();
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
ras->m_cashed = true;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return ToonzImageBuilder().build(m_imageInfo, ras);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
assert(false);
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
assert(false);
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
string TImageCache::getUniqueId(void)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
static TAtomicVar count;
|
|
Toshihiro Shimizu |
890ddd |
std::stringstream ss;
|
|
Toshihiro Shimizu |
890ddd |
ss << ++count;
|
|
Toshihiro Shimizu |
890ddd |
return "IMAGECACHEUNIQUEID" + ss.str();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TImageCache::Imp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
Imp() : m_rootDir()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//ATTENZIONE: e' molto piu' veloce se si usa memoria fisica
|
|
Toshihiro Shimizu |
890ddd |
//invece che virtuale: la virtuale e' tanta, non c'e' quindi bisogno
|
|
Toshihiro Shimizu |
890ddd |
//di comprimere le immagini, che grandi come sono vengono swappate su disco
|
|
Toshihiro Shimizu |
890ddd |
if (TBigMemoryManager::instance()->isActive())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_reservedMemory = (TINT64)(TSystem::getMemorySize(true) * 0.10);
|
|
Toshihiro Shimizu |
890ddd |
if (m_reservedMemory < 64 * 1024)
|
|
Toshihiro Shimizu |
890ddd |
m_reservedMemory = 64 * 1024;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~Imp()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_rootDir != TFilePath())
|
|
Toshihiro Shimizu |
890ddd |
TSystem::rmDirTree(m_rootDir);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool inline notEnoughMemory()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (TBigMemoryManager::instance()->isActive())
|
|
Toshihiro Shimizu |
890ddd |
return TBigMemoryManager::instance()->getAvailableMemoryinKb() < 50 * 1024;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return TSystem::memoryShortage();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void doCompress();
|
|
Toshihiro Shimizu |
890ddd |
void doCompress(string id);
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *compressAndMalloc(TUINT32 requestedSize); // compress in the cache till it can nallocate the requested memory
|
|
Toshihiro Shimizu |
890ddd |
void outputMap(UINT chunkRequested, string filename);
|
|
Toshihiro Shimizu |
890ddd |
void remove(const string &id);
|
|
Toshihiro Shimizu |
890ddd |
void remap(const string &dstId, const string &srcId);
|
|
Toshihiro Shimizu |
890ddd |
TImageP get(const string &id, bool toBeModified);
|
|
Toshihiro Shimizu |
890ddd |
void add(const string &id, const TImageP &img, bool overwrite);
|
|
Toshihiro Shimizu |
890ddd |
TFilePath m_rootDir;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
QThreadStorage<bool *=""> m_isEnabled;</bool>
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
bool m_isEnabled;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
map<string, cacheitemp=""> m_uncompressedItems;</string,>
|
|
Toshihiro Shimizu |
890ddd |
map<tuint32, string=""> m_itemHistory;</tuint32,>
|
|
Toshihiro Shimizu |
890ddd |
map<string, cacheitemp=""> m_compressedItems;</string,>
|
|
Toshihiro Shimizu |
890ddd |
map<void *,="" string=""> m_itemsByImagePointer; //items ordered by ImageP.getPointer()</void>
|
|
Toshihiro Shimizu |
890ddd |
map<string, string=""> m_duplicatedItems; //for duplicated items (when id1!=id2 but image1==image2) in the map: key is dup id, value is main id</string,>
|
|
Toshihiro Shimizu |
890ddd |
//memoria fisica totale della macchina che non puo' essere utilizzata;
|
|
Toshihiro Shimizu |
890ddd |
TINT64 m_reservedMemory;
|
|
Toshihiro Shimizu |
890ddd |
TThread::Mutex m_mutex;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static int m_fileid;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int TImageCache::Imp::m_fileid;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
inline void *getPointer(const TImageP &img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP rimg = img;
|
|
Toshihiro Shimizu |
890ddd |
if (rimg)
|
|
Toshihiro Shimizu |
890ddd |
return rimg->getRaster().getPointer();
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP timg = img;
|
|
Toshihiro Shimizu |
890ddd |
if (timg)
|
|
Toshihiro Shimizu |
890ddd |
return timg->getRaster().getPointer();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return img.getPointer();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Returns true or false whether the image or its eventual raster are
|
|
Toshihiro Shimizu |
890ddd |
// referenced by someone other than Toonz cache.
|
|
Toshihiro Shimizu |
890ddd |
inline TINT32 hasExternalReferences(const TImageP &img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int refCount;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP rimg = img;
|
|
Toshihiro Shimizu |
890ddd |
if (rimg)
|
|
Toshihiro Shimizu |
890ddd |
refCount = rimg->getRaster()->getRefCount();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP timg = img;
|
|
Toshihiro Shimizu |
890ddd |
if (timg)
|
|
Toshihiro Shimizu |
890ddd |
refCount = timg->getRaster()->getRefCount() - 1; //!!! the TToonzImage::getRaster method increments raster refCount!(the TRasterImage::getRaster don't)
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return tmax(refCount, img->getRefCount()) > 1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::Imp::doCompress()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// se la memoria usata per mantenere le immagini decompresse e' superiore
|
|
Toshihiro Shimizu |
890ddd |
// a un dato valore, comprimo alcune immagini non compresse non checked-out
|
|
Toshihiro Shimizu |
890ddd |
// in modo da liberare memoria
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// per il momento scorre tutte le immagini alla ricerca di immagini
|
|
Toshihiro Shimizu |
890ddd |
// non compresse non checked-out
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<tuint32, string="">::iterator itu = m_itemHistory.begin();</tuint32,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (; itu != m_itemHistory.end() && notEnoughMemory();) {
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it = m_uncompressedItems.find(itu->second);</string,>
|
|
Toshihiro Shimizu |
890ddd |
assert(it != m_uncompressedItems.end());
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP item = it->second;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnMemoryCacheItemP uitem = item;
|
|
Toshihiro Shimizu |
890ddd |
if (item->m_cantCompress ||
|
|
Toshihiro Shimizu |
890ddd |
(uitem && (!uitem->m_image || hasExternalReferences(uitem->m_image)))) {
|
|
Toshihiro Shimizu |
890ddd |
++itu;
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
string id = it->first;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
assert(itu->first == it->second->m_historyCount);
|
|
Toshihiro Shimizu |
890ddd |
itu = m_itemHistory.erase(itu);
|
|
Toshihiro Shimizu |
890ddd |
m_itemsByImagePointer.erase(getPointer(item->getImage()));
|
|
Toshihiro Shimizu |
890ddd |
m_uncompressedItems.erase(it);
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
std::map<tuint32, string="">::iterator itu2 = itu;</tuint32,>
|
|
Toshihiro Shimizu |
890ddd |
itu++;
|
|
Toshihiro Shimizu |
890ddd |
m_itemHistory.erase(itu2);
|
|
Toshihiro Shimizu |
890ddd |
m_itemsByImagePointer.erase(item->getImage().getPointer());
|
|
Toshihiro Shimizu |
890ddd |
m_uncompressedItems.erase(it);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_compressedItems.find(id) == m_compressedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
assert(uitem);
|
|
Toshihiro Shimizu |
890ddd |
item->m_cantCompress = true;
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP newItem = new CompressedOnMemoryCacheItem(item->getImage()); //WARNING the codec buffer allocation can CHANGE the cache.
|
|
Toshihiro Shimizu |
890ddd |
item->m_cantCompress = false;
|
|
Toshihiro Shimizu |
890ddd |
if (newItem->getSize() == 0) ///non c'era memoria sufficiente per il buffer compresso....
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(m_rootDir != TFilePath());
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp = m_rootDir + TFilePath(toString(TImageCache::Imp::m_fileid++));
|
|
Toshihiro Shimizu |
890ddd |
newItem = new UncompressedOnDiskCacheItem(fp, item->getImage());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_compressedItems[id] = newItem;
|
|
Toshihiro Shimizu |
890ddd |
item = CacheItemP();
|
|
Toshihiro Shimizu |
890ddd |
uitem = UncompressedOnMemoryCacheItemP();
|
|
Toshihiro Shimizu |
890ddd |
//doCompress();//restart, since interators can have been changed (see comment above)
|
|
Toshihiro Shimizu |
890ddd |
//return;
|
|
Toshihiro Shimizu |
890ddd |
itu = m_itemHistory.begin();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// se il quantitativo di memoria utilizzata e' superiore a un dato valore, sposto
|
|
Toshihiro Shimizu |
890ddd |
// su disco alcune immagini compresse in modo da liberare memoria
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (itu != m_itemHistory.end()) //memory is enough!
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itc = m_compressedItems.begin();</string,>
|
|
Toshihiro Shimizu |
890ddd |
for (; itc != m_compressedItems.end() && notEnoughMemory(); ++itc) {
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP item = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
if (item->m_cantCompress)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnMemoryCacheItemP citem = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
if (citem) {
|
|
Toshihiro Shimizu |
890ddd |
assert(m_rootDir != TFilePath());
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp = m_rootDir + TFilePath(toString(TImageCache::Imp::m_fileid++));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP newItem = new CompressedOnDiskCacheItem(fp, citem->m_compressedRas,
|
|
Toshihiro Shimizu |
890ddd |
citem->m_builder->clone(), citem->m_imageInfo->clone());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
itc->second = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_compressedItems[itc->first] = newItem;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::Imp::doCompress(string id)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// search id in m_uncompressedItems
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it = m_uncompressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (it == m_uncompressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
return; // id not found: return
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// is item suitable for compression ?
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP item = it->second;
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnMemoryCacheItemP uitem = item;
|
|
Toshihiro Shimizu |
890ddd |
if (item->m_cantCompress ||
|
|
Toshihiro Shimizu |
890ddd |
(uitem && (!uitem->m_image || hasExternalReferences(uitem->m_image))))
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// search id in m_itemHistory
|
|
Toshihiro Shimizu |
890ddd |
std::map<tuint32, string="">::iterator itu = m_itemHistory.begin();</tuint32,>
|
|
Toshihiro Shimizu |
890ddd |
while (itu != m_itemHistory.end() && itu->second != id)
|
|
Toshihiro Shimizu |
890ddd |
++itu;
|
|
Toshihiro Shimizu |
890ddd |
if (itu == m_itemHistory.end())
|
|
Toshihiro Shimizu |
890ddd |
return; // id not found: return
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// delete itu from m_itemHistory
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
assert(itu->first == it->second->m_historyCount);
|
|
Toshihiro Shimizu |
890ddd |
itu = m_itemHistory.erase(itu);
|
|
Toshihiro Shimizu |
890ddd |
m_itemsByImagePointer.erase(getPointer(item->getImage()));
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
std::map<tuint32, string="">::iterator itu2 = itu;</tuint32,>
|
|
Toshihiro Shimizu |
890ddd |
itu++;
|
|
Toshihiro Shimizu |
890ddd |
m_itemHistory.erase(itu2);
|
|
Toshihiro Shimizu |
890ddd |
m_itemsByImagePointer.erase(item->getImage().getPointer());
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// delete item from m_uncompressedItems
|
|
Toshihiro Shimizu |
890ddd |
m_uncompressedItems.erase(it);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// check if item has been already compressed. this should never happen
|
|
Toshihiro Shimizu |
890ddd |
if (m_compressedItems.find(id) != m_compressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(uitem);
|
|
Toshihiro Shimizu |
890ddd |
item->m_cantCompress = true; // ??
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP newItem = new CompressedOnMemoryCacheItem(item->getImage()); //WARNING the codec buffer allocation can CHANGE the cache.
|
|
Toshihiro Shimizu |
890ddd |
item->m_cantCompress = false; // ??
|
|
Toshihiro Shimizu |
890ddd |
if (newItem->getSize() == 0) ///non c'era memoria sufficiente per il buffer compresso....
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(m_rootDir != TFilePath());
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp = m_rootDir + TFilePath(toString(TImageCache::Imp::m_fileid++));
|
|
Toshihiro Shimizu |
890ddd |
newItem = new UncompressedOnDiskCacheItem(fp, item->getImage());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_compressedItems[id] = newItem;
|
|
Toshihiro Shimizu |
890ddd |
item = CacheItemP();
|
|
Toshihiro Shimizu |
890ddd |
uitem = UncompressedOnMemoryCacheItemP();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
// se il quantitativo di memoria utilizzata e' superiore a un dato valore, sposto
|
|
Toshihiro Shimizu |
890ddd |
// su disco alcune immagini compresse in modo da liberare memoria
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (itu != m_itemHistory.end()) //memory is enough!
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itc = m_compressedItems.begin();</string,>
|
|
Toshihiro Shimizu |
890ddd |
for ( ; itc != m_compressedItems.end() && notEnoughMemory(); ++itc)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP item = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
if (item->m_cantCompress)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnMemoryCacheItemP citem = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
if (citem)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(m_rootDir!=TFilePath());
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp = m_rootDir + TFilePath(toString(TImageCache::Imp::m_fileid++));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP newItem = new CompressedOnDiskCacheItem(fp, citem->m_compressedRas,
|
|
Toshihiro Shimizu |
890ddd |
citem->m_builder->clone(), citem->m_imageInfo->clone());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
itc->second = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_compressedItems[itc->first] = newItem;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *TImageCache::Imp::compressAndMalloc(TUINT32 size)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *buf = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TheCodec::instance()->reset();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//if (size!=0)
|
|
Toshihiro Shimizu |
890ddd |
// size = size>>10;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//assert(size==0 || TBigMemoryManager::instance()->isActive());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<tuint32, string="">::iterator itu = m_itemHistory.begin();</tuint32,>
|
|
Toshihiro Shimizu |
890ddd |
while ((buf = TBigMemoryManager::instance()->getBuffer(size)) == 0 &&
|
|
Toshihiro Shimizu |
890ddd |
itu != m_itemHistory.end()) //>TBigMemoryManager::instance()->getAvailableMemoryinKb()))
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it = m_uncompressedItems.find(itu->second);</string,>
|
|
Toshihiro Shimizu |
890ddd |
assert(it != m_uncompressedItems.end());
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP item = it->second;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnMemoryCacheItemP uitem = item;
|
|
Toshihiro Shimizu |
890ddd |
if (item->m_cantCompress || (uitem && (!uitem->m_image || hasExternalReferences(uitem->m_image)))) {
|
|
Toshihiro Shimizu |
890ddd |
++itu;
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_compressedItems.find(it->first) == m_compressedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
assert(uitem);
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP newItem;
|
|
Toshihiro Shimizu |
890ddd |
//newItem = new CompressedOnMemoryCacheItem(item->getImage());
|
|
Toshihiro Shimizu |
890ddd |
//if (newItem->getSize()==0)
|
|
Toshihiro Shimizu |
890ddd |
// {
|
|
Toshihiro Shimizu |
890ddd |
assert(m_rootDir != TFilePath());
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp = m_rootDir + TFilePath(toString(TImageCache::Imp::m_fileid++));
|
|
Toshihiro Shimizu |
890ddd |
newItem = new UncompressedOnDiskCacheItem(fp, item->getImage());
|
|
Toshihiro Shimizu |
890ddd |
// }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_compressedItems[it->first] = newItem;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
assert(itu->first == it->second->m_historyCount);
|
|
Toshihiro Shimizu |
890ddd |
itu = m_itemHistory.erase(itu);
|
|
Toshihiro Shimizu |
890ddd |
m_itemsByImagePointer.erase(getPointer(item->getImage()));
|
|
Toshihiro Shimizu |
890ddd |
m_uncompressedItems.erase(it);
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
std::map<tuint32, string="">::iterator itu2 = itu;</tuint32,>
|
|
Toshihiro Shimizu |
890ddd |
itu++;
|
|
Toshihiro Shimizu |
890ddd |
m_itemHistory.erase(itu2);
|
|
Toshihiro Shimizu |
890ddd |
m_itemsByImagePointer.erase(item->getImage().getPointer());
|
|
Toshihiro Shimizu |
890ddd |
m_uncompressedItems.erase(it);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (buf != 0)
|
|
Toshihiro Shimizu |
890ddd |
return buf;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itc = m_compressedItems.begin();</string,>
|
|
Toshihiro Shimizu |
890ddd |
for (; itc != m_compressedItems.end() &&
|
|
Toshihiro Shimizu |
890ddd |
(buf = TBigMemoryManager::instance()->getBuffer(size)) == 0;
|
|
Toshihiro Shimizu |
890ddd |
++itc) {
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP item = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
if (item->m_cantCompress)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnMemoryCacheItemP citem = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
if (citem) {
|
|
Toshihiro Shimizu |
890ddd |
assert(m_rootDir != TFilePath());
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp = m_rootDir + TFilePath(toString(TImageCache::Imp::m_fileid++));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP newItem = new CompressedOnDiskCacheItem(
|
|
Toshihiro Shimizu |
890ddd |
fp, citem->m_compressedRas,
|
|
Toshihiro Shimizu |
890ddd |
citem->m_builder->clone(), citem->m_imageInfo->clone());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
itc->second = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_compressedItems[itc->first] = newItem;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return buf;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int check = 0;
|
|
Toshihiro Shimizu |
890ddd |
const int magic = 123456;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static TImageCache *CacheInstance = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageCache *TImageCache::instance()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (CacheInstance == 0)
|
|
Toshihiro Shimizu |
890ddd |
CacheInstance = new TImageCache();
|
|
Toshihiro Shimizu |
890ddd |
return CacheInstance;
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
if (!ImageCache::m_instance)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
ImageCache::m_instance = new ImageCache;
|
|
Toshihiro Shimizu |
890ddd |
ImageCache::m_destroyer.m_imageCache = ImageCache::m_instance;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return ImageCache::m_instance;
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageCache::TImageCache()
|
|
Toshihiro Shimizu |
890ddd |
: m_imp(new Imp())
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(check == 0);
|
|
Toshihiro Shimizu |
890ddd |
check = magic;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageCache::~TImageCache()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(check == magic);
|
|
Toshihiro Shimizu |
890ddd |
check = -1;
|
|
Toshihiro Shimizu |
890ddd |
delete m_imp;
|
|
Toshihiro Shimizu |
890ddd |
CacheInstance = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::setEnabled(bool isEnabled)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
QThreadStorage<bool *=""> &storage = m_imp->m_isEnabled;</bool>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (storage.hasLocalData() && *(storage.localData()) == isEnabled)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
if (!storage.hasLocalData())
|
|
Toshihiro Shimizu |
890ddd |
storage.setLocalData(new bool(isEnabled));
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
*(storage.localData()) = isEnabled;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_isEnabled = isEnabled;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool TImageCache::isEnabled()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
QThreadStorage<bool *=""> &storage = m_imp->m_isEnabled;</bool>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!storage.hasLocalData())
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
return *(storage.localData());
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
return m_isEnabled;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::setRootDir(const TFilePath &cacheDir)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_imp->m_rootDir != TFilePath())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_rootDir = cacheDir + TFilePath(toString(TSystem::getProcessId()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
TFileStatus fs1(m_imp->m_rootDir);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!fs1.doesExist())
|
|
Toshihiro Shimizu |
890ddd |
TSystem::mkDir(m_imp->m_rootDir);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
TFilePath TImageCache::getRootDir() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_imp->m_rootDir;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *TImageCache::compressAndMalloc(TUINT32 requestedSize)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_imp->compressAndMalloc(requestedSize);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::add(const string &id, const TImageP &img, bool overwrite)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!isEnabled())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
m_imp->add(id, img, overwrite);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::Imp::add(const string &id, const TImageP &img, bool overwrite)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef LEVO
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it1 = m_uncompressedItems.begin();</string,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (; it1 != m_uncompressedItems.end(); ++it1) {
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnMemoryCacheItemP item = (UncompressedOnMemoryCacheItemP)it1->second;
|
|
Toshihiro Shimizu |
890ddd |
//m_memUsage -= item->getSize();
|
|
Toshihiro Shimizu |
890ddd |
assert(item);
|
|
Toshihiro Shimizu |
890ddd |
TImageP refImg = item->getImage();
|
|
Toshihiro Shimizu |
890ddd |
if (refImg.getPointer() == img.getPointer() && it1->first != id)
|
|
Toshihiro Shimizu |
890ddd |
assert(!"opps gia' esiste in cache!");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itUncompr = m_uncompressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itCompr = m_compressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUGTOONZ
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP rimg = (TRasterImageP)img;
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP timg = (TToonzImageP)img;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (itUncompr != m_uncompressedItems.end() ||
|
|
Toshihiro Shimizu |
890ddd |
itCompr != m_compressedItems.end()) //already present in cache with same id...
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (overwrite) {
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUGTOONZ
|
|
Toshihiro Shimizu |
890ddd |
if (rimg)
|
|
Toshihiro Shimizu |
890ddd |
rimg->getRaster()->m_cashed = true;
|
|
Toshihiro Shimizu |
890ddd |
else if (timg)
|
|
Toshihiro Shimizu |
890ddd |
timg->getRaster()->m_cashed = true;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it;</string,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (itUncompr != m_uncompressedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
assert(m_itemHistory.find(itUncompr->second->m_historyCount) != m_itemHistory.end());
|
|
Toshihiro Shimizu |
890ddd |
m_itemHistory.erase(itUncompr->second->m_historyCount);
|
|
Toshihiro Shimizu |
890ddd |
m_itemsByImagePointer.erase(getPointer(itUncompr->second->getImage()));
|
|
Toshihiro Shimizu |
890ddd |
m_uncompressedItems.erase(itUncompr);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (itCompr != m_compressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
m_compressedItems.erase(id);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, string="">::iterator dt = m_duplicatedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if ((dt != m_duplicatedItems.end()) && !overwrite)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<void *,="" string="">::iterator it;</void>
|
|
Toshihiro Shimizu |
890ddd |
if ((it = m_itemsByImagePointer.find(getPointer(img))) != m_itemsByImagePointer.end()) //already present in cache with another id...
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_duplicatedItems[id] = it->second;
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (dt != m_duplicatedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
m_duplicatedItems.erase(dt);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP item;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUGTOONZ
|
|
Toshihiro Shimizu |
890ddd |
if (rimg)
|
|
Toshihiro Shimizu |
890ddd |
rimg->getRaster()->m_cashed = true;
|
|
Toshihiro Shimizu |
890ddd |
else if (timg)
|
|
Toshihiro Shimizu |
890ddd |
timg->getRaster()->m_cashed = true;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
item = new UncompressedOnMemoryCacheItem(img);
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
item->m_cantCompress = false;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
item->m_cantCompress = (TVectorImageP(img) ? true : false);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
item->m_id = id;
|
|
Toshihiro Shimizu |
890ddd |
m_uncompressedItems[id] = item;
|
|
Toshihiro Shimizu |
890ddd |
m_itemsByImagePointer[getPointer(img)] = id;
|
|
Toshihiro Shimizu |
890ddd |
item->m_historyCount = HistoryCount;
|
|
Toshihiro Shimizu |
890ddd |
m_itemHistory[HistoryCount] = id;
|
|
Toshihiro Shimizu |
890ddd |
HistoryCount++;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
doCompress();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUGTOONZ
|
|
Toshihiro Shimizu |
890ddd |
//int itemCount = m_imp->m_uncompressedItems.size()+m_imp->m_compressedItems.size();
|
|
Toshihiro Shimizu |
890ddd |
//m_imp->outputDebug();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::remove(const string &id)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_imp->remove(id);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::Imp::remove(const string &id)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (CacheInstance == 0)
|
|
Toshihiro Shimizu |
890ddd |
return; //the remove can be called when exiting from toonz...after the imagecache was already freed!
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(check == magic);
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, string="">::iterator it1;</string,>
|
|
Toshihiro Shimizu |
890ddd |
if ((it1 = m_duplicatedItems.find(id)) != m_duplicatedItems.end()) //it's a duplicated id...
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_duplicatedItems.erase(it1);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (it1 = m_duplicatedItems.begin(); it1 != m_duplicatedItems.end(); ++it1)
|
|
Toshihiro Shimizu |
890ddd |
if (it1->second == id)
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (it1 != m_duplicatedItems.end()) //it has duplicated, so cannot erase it; I erase the duplicate, and assign its id has the main id
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
string sonId = it1->first;
|
|
Toshihiro Shimizu |
890ddd |
m_duplicatedItems.erase(it1);
|
|
Toshihiro Shimizu |
890ddd |
remap(sonId, id);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it = m_uncompressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itc = m_compressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_uncompressedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
const CacheItemP &item = it->second;
|
|
Toshihiro Shimizu |
890ddd |
assert((UncompressedOnMemoryCacheItemP)item);
|
|
Toshihiro Shimizu |
890ddd |
assert(m_itemHistory.find(it->second->m_historyCount) != m_itemHistory.end());
|
|
Toshihiro Shimizu |
890ddd |
m_itemHistory.erase(it->second->m_historyCount);
|
|
Toshihiro Shimizu |
890ddd |
m_itemsByImagePointer.erase(getPointer(it->second->getImage()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUGTOONZ
|
|
Toshihiro Shimizu |
890ddd |
if ((TRasterImageP)it->second->getImage())
|
|
Toshihiro Shimizu |
890ddd |
((TRasterImageP)it->second->getImage())->getRaster()->m_cashed = false;
|
|
Toshihiro Shimizu |
890ddd |
else if ((TToonzImageP)it->second->getImage())
|
|
Toshihiro Shimizu |
890ddd |
((TToonzImageP)it->second->getImage())->getRaster()->m_cashed = false;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_uncompressedItems.erase(it);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (itc != m_compressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
m_compressedItems.erase(itc);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::remap(const string &dstId, const string &srcId)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_imp->remap(dstId, srcId);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::Imp::remap(const string &dstId, const string &srcId)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it = m_uncompressedItems.find(srcId);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_uncompressedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP citem = it->second;
|
|
Toshihiro Shimizu |
890ddd |
assert(m_itemHistory.find(citem->m_historyCount) != m_itemHistory.end());
|
|
Toshihiro Shimizu |
890ddd |
m_itemHistory.erase(citem->m_historyCount);
|
|
Toshihiro Shimizu |
890ddd |
m_itemsByImagePointer.erase(getPointer(citem->getImage()));
|
|
Toshihiro Shimizu |
890ddd |
m_uncompressedItems.erase(it);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_uncompressedItems[dstId] = citem;
|
|
Toshihiro Shimizu |
890ddd |
m_itemHistory[citem->m_historyCount] = dstId;
|
|
Toshihiro Shimizu |
890ddd |
m_itemsByImagePointer[getPointer(citem->getImage())] = dstId;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
it = m_compressedItems.find(srcId);
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_compressedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP citem = it->second;
|
|
Toshihiro Shimizu |
890ddd |
m_compressedItems.erase(it);
|
|
Toshihiro Shimizu |
890ddd |
m_compressedItems[dstId] = citem;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, string="">::iterator it2 = m_duplicatedItems.find(srcId);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (it2 != m_duplicatedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
string id = it2->second;
|
|
Toshihiro Shimizu |
890ddd |
m_duplicatedItems.erase(it2);
|
|
Toshihiro Shimizu |
890ddd |
m_duplicatedItems[dstId] = id;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
for (it2 = m_duplicatedItems.begin(); it2 != m_duplicatedItems.end(); ++it2)
|
|
Toshihiro Shimizu |
890ddd |
if (it2->second == srcId)
|
|
Toshihiro Shimizu |
890ddd |
it2->second = dstId;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::remapIcons(const string &dstId, const string &srcId)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it;</string,>
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, string=""> table;</string,>
|
|
Toshihiro Shimizu |
890ddd |
string prefix = srcId + ":";
|
|
Toshihiro Shimizu |
890ddd |
int j = (int)prefix.length();
|
|
Toshihiro Shimizu |
890ddd |
for (it = m_imp->m_uncompressedItems.begin(); it != m_imp->m_uncompressedItems.end(); ++it) {
|
|
Toshihiro Shimizu |
890ddd |
string id = it->first;
|
|
Toshihiro Shimizu |
890ddd |
if (id.find(prefix) == 0)
|
|
Toshihiro Shimizu |
890ddd |
table[id] = dstId + ":" + id.substr(j);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
for (std::map<string, string="">::iterator it2 = table.begin();</string,>
|
|
Toshihiro Shimizu |
890ddd |
it2 != table.end(); ++it2) {
|
|
Toshihiro Shimizu |
890ddd |
remap(it2->second, it2->first);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::clear(bool deleteFolder)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_imp->m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_uncompressedItems.clear();
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_itemHistory.clear();
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_compressedItems.clear();
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_duplicatedItems.clear();
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_itemsByImagePointer.clear();
|
|
Toshihiro Shimizu |
890ddd |
if (deleteFolder && m_imp->m_rootDir != TFilePath())
|
|
Toshihiro Shimizu |
890ddd |
TSystem::rmDirTree(m_imp->m_rootDir);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::clearSceneImages()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_imp->m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//note the ';' - which follows ':' in the ascii table
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_uncompressedItems.erase(m_imp->m_uncompressedItems.begin(), m_imp->m_uncompressedItems.lower_bound("$:"));
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_uncompressedItems.erase(m_imp->m_uncompressedItems.lower_bound("$;"), m_imp->m_uncompressedItems.end());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_compressedItems.erase(m_imp->m_compressedItems.begin(), m_imp->m_compressedItems.lower_bound("$:"));
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_compressedItems.erase(m_imp->m_compressedItems.lower_bound("$;"), m_imp->m_compressedItems.end());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_duplicatedItems.erase(m_imp->m_duplicatedItems.begin(), m_imp->m_duplicatedItems.lower_bound("$:"));
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_duplicatedItems.erase(m_imp->m_duplicatedItems.lower_bound("$;"), m_imp->m_duplicatedItems.end());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Clear maps whose id is on the second of map pairs.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<tuint32, std::string="">::iterator it;</tuint32,>
|
|
Toshihiro Shimizu |
890ddd |
for (it = m_imp->m_itemHistory.begin(); it != m_imp->m_itemHistory.end();) {
|
|
Toshihiro Shimizu |
890ddd |
if (it->second.size() >= 2 && it->second[0] == '$' && it->second[1] == ':')
|
|
Toshihiro Shimizu |
890ddd |
++it;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
std::map<tuint32, std::string="">::iterator app = it;</tuint32,>
|
|
Toshihiro Shimizu |
890ddd |
app++;
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_itemHistory.erase(it);
|
|
Toshihiro Shimizu |
890ddd |
it = app;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<void *,="" std::string="">::iterator jt;</void>
|
|
Toshihiro Shimizu |
890ddd |
for (jt = m_imp->m_itemsByImagePointer.begin(); jt != m_imp->m_itemsByImagePointer.end();) {
|
|
Toshihiro Shimizu |
890ddd |
if (jt->second.size() >= 2 && jt->second[0] == '$' && jt->second[1] == ':')
|
|
Toshihiro Shimizu |
890ddd |
++jt;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
std::map<void *,="" std::string="">::iterator app = jt;</void>
|
|
Toshihiro Shimizu |
890ddd |
app++;
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_itemsByImagePointer.erase(jt);
|
|
Toshihiro Shimizu |
890ddd |
jt = app;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool TImageCache::isCached(const string &id) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_imp->m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
return (m_imp->m_uncompressedItems.find(id) != m_imp->m_uncompressedItems.end() ||
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_compressedItems.find(id) != m_imp->m_compressedItems.end() ||
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_duplicatedItems.find(id) != m_imp->m_duplicatedItems.end());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
#ifdef LEVO
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool TImageCache::getSize(const string &id, TDimension &size) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker sl(&m_imp->m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it = m_imp->m_uncompressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_imp->m_uncompressedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnMemoryCacheItemP uncompressed = it->second;
|
|
Toshihiro Shimizu |
890ddd |
assert(uncompressed);
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = uncompressed->getImage();
|
|
Toshihiro Shimizu |
890ddd |
if (ti) {
|
|
Toshihiro Shimizu |
890ddd |
size = ti->getSize();
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = uncompressed->getImage();
|
|
Toshihiro Shimizu |
890ddd |
if (ri && ri->getRaster()) {
|
|
Toshihiro Shimizu |
890ddd |
size = ri->getRaster()->getSize();
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itc = m_imp->m_compressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (itc == m_imp->m_compressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP cacheItem = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (cacheItem->m_imageInfo) {
|
|
Toshihiro Shimizu |
890ddd |
RasterImageInfo *rimageInfo = dynamic_cast<rasterimageinfo *="">(cacheItem->m_imageInfo);</rasterimageinfo>
|
|
Toshihiro Shimizu |
890ddd |
if (rimageInfo) {
|
|
Toshihiro Shimizu |
890ddd |
size = rimageInfo->m_size;
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
ToonzImageInfo *timageInfo = dynamic_cast<toonzimageinfo *="">(cacheItem->m_imageInfo);</toonzimageinfo>
|
|
Toshihiro Shimizu |
890ddd |
if (timageInfo) {
|
|
Toshihiro Shimizu |
890ddd |
size = timageInfo->m_size;
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool TImageCache::getSavebox(const string &id, TRect &savebox) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker sl(&m_imp->m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it = m_imp->m_uncompressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_imp->m_uncompressedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnMemoryCacheItemP uncompressed = it->second;
|
|
Toshihiro Shimizu |
890ddd |
assert(uncompressed);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = uncompressed->getImage();
|
|
Toshihiro Shimizu |
890ddd |
if (ti) {
|
|
Toshihiro Shimizu |
890ddd |
savebox = ti->getSavebox();
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = uncompressed->getImage();
|
|
Toshihiro Shimizu |
890ddd |
if (ri) {
|
|
Toshihiro Shimizu |
890ddd |
savebox = ri->getSavebox();
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itc = m_imp->m_compressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (itc == m_imp->m_compressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP cacheItem = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(cacheItem->m_imageInfo);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
RasterImageInfo *rimageInfo = dynamic_cast<rasterimageinfo *="">(cacheItem->m_imageInfo);</rasterimageinfo>
|
|
Toshihiro Shimizu |
890ddd |
if (rimageInfo) {
|
|
Toshihiro Shimizu |
890ddd |
savebox = rimageInfo->m_savebox;
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
ToonzImageInfo *timageInfo = dynamic_cast<toonzimageinfo *="">(cacheItem->m_imageInfo);</toonzimageinfo>
|
|
Toshihiro Shimizu |
890ddd |
if (timageInfo) {
|
|
Toshihiro Shimizu |
890ddd |
savebox = timageInfo->m_savebox;
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool TImageCache::getDpi(const string &id, double &dpiX, double &dpiY) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker sl(&m_imp->m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it = m_imp->m_uncompressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_imp->m_uncompressedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnMemoryCacheItemP uncompressed = it->second;
|
|
Toshihiro Shimizu |
890ddd |
assert(uncompressed);
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = uncompressed->getImage();
|
|
Toshihiro Shimizu |
890ddd |
if (ti) {
|
|
Toshihiro Shimizu |
890ddd |
ti->getDpi(dpiX, dpiY);
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = uncompressed->getImage();
|
|
Toshihiro Shimizu |
890ddd |
if (ri) {
|
|
Toshihiro Shimizu |
890ddd |
ri->getDpi(dpiX, dpiY);
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itc = m_imp->m_compressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (itc == m_imp->m_compressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP cacheItem = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
assert(cacheItem->m_imageInfo);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
RasterImageInfo *rimageInfo = dynamic_cast<rasterimageinfo *="">(cacheItem->m_imageInfo);</rasterimageinfo>
|
|
Toshihiro Shimizu |
890ddd |
if (rimageInfo) {
|
|
Toshihiro Shimizu |
890ddd |
dpiX = rimageInfo->m_dpix;
|
|
Toshihiro Shimizu |
890ddd |
dpiY = rimageInfo->m_dpiy;
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
ToonzImageInfo *timageInfo = dynamic_cast<toonzimageinfo *="">(cacheItem->m_imageInfo);</toonzimageinfo>
|
|
Toshihiro Shimizu |
890ddd |
if (timageInfo) {
|
|
Toshihiro Shimizu |
890ddd |
dpiX = timageInfo->m_dpix;
|
|
Toshihiro Shimizu |
890ddd |
dpiY = timageInfo->m_dpiy;
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool TImageCache::getSubsampling(const string &id, int &subs) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_imp->m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, string="">::iterator it1;</string,>
|
|
Toshihiro Shimizu |
890ddd |
if ((it1 = m_imp->m_duplicatedItems.find(id)) != m_imp->m_duplicatedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
assert(m_imp->m_duplicatedItems.find(it1->second) == m_imp->m_duplicatedItems.end());
|
|
Toshihiro Shimizu |
890ddd |
return getSubsampling(it1->second, subs);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it = m_imp->m_uncompressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_imp->m_uncompressedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnMemoryCacheItemP uncompressed = it->second;
|
|
Toshihiro Shimizu |
890ddd |
assert(uncompressed);
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
if (TToonzImageP ti = uncompressed->getImage()) {
|
|
Toshihiro Shimizu |
890ddd |
subs = ti->getSubsampling();
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
if (TRasterImageP ri = uncompressed->getImage()) {
|
|
Toshihiro Shimizu |
890ddd |
subs = ri->getSubsampling();
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itc = m_imp->m_compressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (itc == m_imp->m_compressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP cacheItem = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
assert(cacheItem->m_imageInfo);
|
|
Toshihiro Shimizu |
890ddd |
if (RasterImageInfo *rimageInfo = dynamic_cast<rasterimageinfo *="">(cacheItem->m_imageInfo)) {</rasterimageinfo>
|
|
Toshihiro Shimizu |
890ddd |
subs = rimageInfo->m_subs;
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
else if (ToonzImageInfo *timageInfo = dynamic_cast<toonzimageinfo *="">(cacheItem->m_imageInfo)) {</toonzimageinfo>
|
|
Toshihiro Shimizu |
890ddd |
subs = timageInfo->m_subs;
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool TImageCache::hasBeenModified(const string &id, bool reset) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_imp->m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, string="">::iterator it;</string,>
|
|
Toshihiro Shimizu |
890ddd |
if ((it = m_imp->m_duplicatedItems.find(id)) != m_imp->m_duplicatedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
assert(m_imp->m_duplicatedItems.find(it->second) == m_imp->m_duplicatedItems.end());
|
|
Toshihiro Shimizu |
890ddd |
return hasBeenModified(it->second, reset);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP img;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itu = m_imp->m_uncompressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (itu != m_imp->m_uncompressedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
if (reset && itu->second->m_modified) {
|
|
Toshihiro Shimizu |
890ddd |
itu->second->m_modified = false;
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
return itu->second->m_modified;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return true; //not present in cache==modified (for particle purposes...)
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP TImageCache::get(const string &id, bool toBeModified) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_imp->get(id, toBeModified);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP TImageCache::Imp::get(const string &id, bool toBeModified)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, string="">::const_iterator it;</string,>
|
|
Toshihiro Shimizu |
890ddd |
if ((it = m_duplicatedItems.find(id)) != m_duplicatedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
assert(m_duplicatedItems.find(it->second) == m_duplicatedItems.end());
|
|
Toshihiro Shimizu |
890ddd |
return get(it->second, toBeModified);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP img;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itu = m_uncompressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (itu != m_uncompressedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
img = itu->second->getImage();
|
|
Toshihiro Shimizu |
890ddd |
if (itu->second->m_historyCount != HistoryCount - 1) //significa che l'ultimo get non era sulla stessa immagine, quindi serve aggiornare l'history!
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(m_itemHistory.find(itu->second->m_historyCount) != m_itemHistory.end());
|
|
Toshihiro Shimizu |
890ddd |
m_itemHistory.erase(itu->second->m_historyCount);
|
|
Toshihiro Shimizu |
890ddd |
m_itemHistory[HistoryCount] = id;
|
|
Toshihiro Shimizu |
890ddd |
itu->second->m_historyCount = HistoryCount;
|
|
Toshihiro Shimizu |
890ddd |
HistoryCount++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (toBeModified) {
|
|
Toshihiro Shimizu |
890ddd |
itu->second->m_modified = true;
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itc = m_compressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (itc != m_compressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
m_compressedItems.erase(itc);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return img;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itc = m_compressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (itc == m_compressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP cacheItem = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
img = cacheItem->getImage();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP uncompressed;
|
|
Toshihiro Shimizu |
890ddd |
uncompressed = new UncompressedOnMemoryCacheItem(img);
|
|
Toshihiro Shimizu |
890ddd |
m_uncompressedItems[itc->first] = uncompressed;
|
|
Toshihiro Shimizu |
890ddd |
m_itemsByImagePointer[getPointer(img)] = itc->first;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_itemHistory[HistoryCount] = itc->first;
|
|
Toshihiro Shimizu |
890ddd |
uncompressed->m_historyCount = HistoryCount;
|
|
Toshihiro Shimizu |
890ddd |
HistoryCount++;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (CompressedOnMemoryCacheItemP(cacheItem))
|
|
Toshihiro Shimizu |
890ddd |
//l'immagine compressa non la tengo insieme alla
|
|
Toshihiro Shimizu |
890ddd |
//uncompressa se e' troppo grande
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (10 * cacheItem->getSize() > uncompressed->getSize()) {
|
|
Toshihiro Shimizu |
890ddd |
m_compressedItems.erase(itc);
|
|
Toshihiro Shimizu |
890ddd |
itc = m_compressedItems.end();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
assert((CompressedOnDiskCacheItemP)cacheItem || (UncompressedOnDiskCacheItemP)cacheItem); //deve essere compressa!
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (toBeModified && itc != m_compressedItems.end()) {
|
|
Toshihiro Shimizu |
890ddd |
uncompressed->m_modified = true;
|
|
Toshihiro Shimizu |
890ddd |
m_compressedItems.erase(itc);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
uncompressed->m_cantCompress = toBeModified;
|
|
Toshihiro Shimizu |
890ddd |
// se la memoria utilizzata e' superiore al massimo consentito, comprime
|
|
Toshihiro Shimizu |
890ddd |
doCompress();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
uncompressed->m_cantCompress = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//#define DO_MEMCHECK
|
|
Toshihiro Shimizu |
890ddd |
#ifdef DO_MEMCHECK
|
|
Toshihiro Shimizu |
890ddd |
assert(_CrtCheckMemory());
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return img;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class AccumulateMemUsage
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
int operator()(int oldValue, std::pair<string, cacheitemp=""> item)</string,>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return oldValue + item.second->getSize();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UINT TImageCache::getMemUsage() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_imp->m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int ret = std::accumulate(
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_uncompressedItems.begin(),
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_uncompressedItems.end(),
|
|
Toshihiro Shimizu |
890ddd |
0,
|
|
Toshihiro Shimizu |
890ddd |
AccumulateMemUsage());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return ret + std::accumulate(
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_compressedItems.begin(),
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_compressedItems.end(),
|
|
Toshihiro Shimizu |
890ddd |
0,
|
|
Toshihiro Shimizu |
890ddd |
AccumulateMemUsage());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UINT TImageCache::getDiskUsage() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UINT TImageCache::getMemUsage(const string &id) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it = m_imp->m_uncompressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_imp->m_uncompressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
return it->second->getSize();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
it = m_imp->m_compressedItems.find(id);
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_imp->m_compressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
return it->second->getSize();
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//! Returns the uncompressed image size (in KB) of the image associated with
|
|
Toshihiro Shimizu |
890ddd |
//! passd id, or 0 if none was found.
|
|
Toshihiro Shimizu |
890ddd |
UINT TImageCache::getUncompressedMemUsage(const string &id) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it = m_imp->m_uncompressedItems.find(id);</string,>
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_imp->m_uncompressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
return it->second->getSize();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
it = m_imp->m_compressedItems.find(id);
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_imp->m_compressedItems.end())
|
|
Toshihiro Shimizu |
890ddd |
return it->second->getSize();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
int TImageCache::getItemCount() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_imp->m_uncompressedItems.size()+m_imp->m_compressedItems.size();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UINT TImageCache::getDiskUsage(const string &id) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::dump(ostream &os) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
os << "mem: " << getMemUsage() << std::endl;
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator it = m_imp->m_uncompressedItems.begin();</string,>
|
|
Toshihiro Shimizu |
890ddd |
for (; it != m_imp->m_uncompressedItems.end(); ++it) {
|
|
Toshihiro Shimizu |
890ddd |
os << it->first << std::endl;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::outputMap(UINT chunkRequested, string filename)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_imp->outputMap(chunkRequested, filename);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::Imp::outputMap(UINT chunkRequested, string filename)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker sl(&m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
//#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
//static int Count = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::string st = filename /*+toString(Count++)*/ + ".txt";
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp(st);
|
|
Toshihiro Shimizu |
890ddd |
Tofstream os(fp);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int umcount1 = 0;
|
|
Toshihiro Shimizu |
890ddd |
int umcount2 = 0;
|
|
Toshihiro Shimizu |
890ddd |
int umcount3 = 0;
|
|
Toshihiro Shimizu |
890ddd |
int cmcount = 0;
|
|
Toshihiro Shimizu |
890ddd |
int cdcount = 0;
|
|
Toshihiro Shimizu |
890ddd |
int umcount = 0;
|
|
Toshihiro Shimizu |
890ddd |
int udcount = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TUINT64 umsize1 = 0;
|
|
Toshihiro Shimizu |
890ddd |
TUINT64 umsize2 = 0;
|
|
Toshihiro Shimizu |
890ddd |
TUINT64 umsize3 = 0;
|
|
Toshihiro Shimizu |
890ddd |
TUINT64 cmsize = 0;
|
|
Toshihiro Shimizu |
890ddd |
TUINT64 cdsize = 0;
|
|
Toshihiro Shimizu |
890ddd |
TUINT64 umsize = 0;
|
|
Toshihiro Shimizu |
890ddd |
TUINT64 udsize = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itu = m_uncompressedItems.begin();</string,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (; itu != m_uncompressedItems.end(); ++itu) {
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnMemoryCacheItemP uitem = itu->second;
|
|
Toshihiro Shimizu |
890ddd |
if (uitem->m_image && hasExternalReferences(uitem->m_image)) {
|
|
Toshihiro Shimizu |
890ddd |
umcount1++;
|
|
Toshihiro Shimizu |
890ddd |
umsize1 += (TUINT64)(itu->second->getSize() / 1024.0);
|
|
Toshihiro Shimizu |
890ddd |
} else if (uitem->m_cantCompress) {
|
|
Toshihiro Shimizu |
890ddd |
umcount2++;
|
|
Toshihiro Shimizu |
890ddd |
umsize2 += (TUINT64)(itu->second->getSize() / 1024.0);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
umcount3++;
|
|
Toshihiro Shimizu |
890ddd |
umsize3 += (TUINT64)(itu->second->getSize() / 1024.0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, cacheitemp="">::iterator itc = m_compressedItems.begin();</string,>
|
|
Toshihiro Shimizu |
890ddd |
for (; itc != m_compressedItems.end(); ++itc) {
|
|
Toshihiro Shimizu |
890ddd |
CacheItemP boh = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnMemoryCacheItemP cmitem = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
CompressedOnDiskCacheItemP cditem = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
UncompressedOnDiskCacheItemP uditem = itc->second;
|
|
Toshihiro Shimizu |
890ddd |
if (cmitem) {
|
|
Toshihiro Shimizu |
890ddd |
cmcount++;
|
|
Toshihiro Shimizu |
890ddd |
cmsize += cmitem->getSize();
|
|
Toshihiro Shimizu |
890ddd |
} else if (cditem) {
|
|
Toshihiro Shimizu |
890ddd |
cdcount++;
|
|
Toshihiro Shimizu |
890ddd |
cdsize += cditem->getSize();
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
assert(uditem);
|
|
Toshihiro Shimizu |
890ddd |
udcount++;
|
|
Toshihiro Shimizu |
890ddd |
udsize += uditem->getSize();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TUINT64 currPhisMemoryAvail = (TUINT64)(TSystem::getFreeMemorySize(true) / 1024.0);
|
|
Toshihiro Shimizu |
890ddd |
//TUINT64 currVirtualMemoryAvail = TSystem::getFreeMemorySize(false)/1024.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
os << "************************************************************\n";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
os << "***requested memory: " + toString((int)chunkRequested / 1048576.0) + " MB\n";
|
|
Toshihiro Shimizu |
890ddd |
//os<<"*** memory in rasters: " + toString((int)TRaster::getTotalMemoryInKB()/1024.0) + " MB\n";
|
|
Toshihiro Shimizu |
890ddd |
//os<<"***virtualmem " + toString((int)currVirtualMemoryAvail) + " MB\n";
|
|
Toshihiro Shimizu |
890ddd |
os << "***phismem " + toString((int)currPhisMemoryAvail) + " MB; percent of tot:" + toString((int)((currPhisMemoryAvail * 100) / m_reservedMemory)) + "\n";
|
|
Toshihiro Shimizu |
890ddd |
//os<<"***bigmem available" + toString((int)TBigMemoryManager::instance()->getAvailableMemoryinKb());
|
|
Toshihiro Shimizu |
890ddd |
os << "***uncompressed NOT compressable(refcount>1) " + toString(umcount1) + " " + toString(umsize1 / 1024.0) + " MB\n";
|
|
Toshihiro Shimizu |
890ddd |
os << "***uncompressed NOT compressable(cantCompress) " + toString(umcount2) + " " + toString(umsize2 / 1024.0) + " MB\n";
|
|
Toshihiro Shimizu |
890ddd |
os << "***uncompressed compressable " + toString(umcount3) + " " + toString(umsize3 / 1024.0) + " MB\n";
|
|
Toshihiro Shimizu |
890ddd |
os << "***compressed on mem " + toString(cmcount) + " " + toString((int)cmsize / 1048576.0) + " MB\n";
|
|
Toshihiro Shimizu |
890ddd |
os << "***compressed on disk " + toString(cdcount) + " " + toString((int)cdsize / 1048576.0) + " MB\n";
|
|
Toshihiro Shimizu |
890ddd |
os << "***uncompressed on disk " + toString(udcount) + " " + toString((int)udsize / 1048576.0) + " MB\n";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//TBigMemoryManager::instance()->printMap();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::compress(const string &id)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_imp->doCompress(id);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZCORE_LIGHT
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::add(const QString &id, const TImageP &img, bool overwrite)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!isEnabled())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
m_imp->add(id.toStdString(), img, overwrite);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TImageCache::remove(const QString &id)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_imp->remove(id.toStdString());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP TImageCache::get(const QString &id, bool toBeModified) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return get(id.toStdString(), toBeModified);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// TCachedImage implementation
|
|
Toshihiro Shimizu |
890ddd |
//*************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DEFINE_CLASS_CODE(TCachedImage, 103)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TCachedImage::TCachedImage()
|
|
Toshihiro Shimizu |
890ddd |
: TSmartObject(m_classCode), m_ref(TImageCache::instance()->getUniqueId())
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TCachedImage::TCachedImage(const TImageP &img)
|
|
Toshihiro Shimizu |
890ddd |
: TSmartObject(m_classCode), m_ref(TImageCache::instance()->getUniqueId())
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
setImage(img);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TCachedImage::~TCachedImage()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TImageCache::instance()->remove(m_ref);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TCachedImage::setImage(const TImageP &img, bool overwrite)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TImageCache::instance()->add(m_ref, img, overwrite);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP TCachedImage::image(bool toBeModified)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TImageCache::instance()->get(m_ref, toBeModified);
|
|
Toshihiro Shimizu |
890ddd |
}
|