Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TCACHEDLEVEL_INCLUDED
Toshihiro Shimizu 890ddd
#define TCACHEDLEVEL_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
   PER ORA SI PUO' USARE LA CACHE SOLO CON WINDOWS
Toshihiro Shimizu 890ddd
 */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
#include <windows.h></windows.h>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
#include "traster.h"
Toshihiro Shimizu 890ddd
#include "tthread.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TRASTERIMAGE_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
//=============================================================================
Toshihiro Shimizu 890ddd
// forward declaration
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TRawDataCodec;
Toshihiro Shimizu 890ddd
class TRasterCodec;
Toshihiro Shimizu 890ddd
class TCachePersist;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
class TCache {
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  TCache();
Toshihiro Shimizu 890ddd
  virtual ~TCache();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  bool isCached(int frame) const  = 0;
Toshihiro Shimizu 890ddd
  bool isCached(int starFrame, int endFrame) const  = 0; // estremi compresi
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  virtual void putRaster(int frame, const TRasterP &ras) = 0;
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
  virtual void getRaster(int frame, TRaster32P  &ras) const
Toshihiro Shimizu 890ddd
    { getRaster(frame, TRasterP(ras)); }
Toshihiro Shimizu 890ddd
  virtual void getRaster(int frame, TRaster64P  &ras) const
Toshihiro Shimizu 890ddd
    { getRaster(frame, TRasterP(ras)); }
Toshihiro Shimizu 890ddd
  virtual void getRaster(int frame, TRasterYUV422P &ras) const
Toshihiro Shimizu 890ddd
    { getRaster(frame, TRasterP(ras)); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  void invalidateAll() = 0;
Toshihiro Shimizu 890ddd
  void invalidate(int starFrame, int endFrame) = 0; // estremi compresi
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
  virtual void getRaster(int frame, TRasterP &ras) const = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TRamCache final : public TCache {
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
  TRamCache();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TDiskCache final : public TCache {
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
  TDiskCache();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TDiskCache::putRaster(int frame, const TRsterP &ras)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TDiskCache::getRaster(
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TRAMUncompressedCache final : public TRamCache {
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TRAMLzoCache final : public TRamCache {
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TDiskUncompressedCache final : public TDiskCache {
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TDiskYUV422Cache final : public TDiskCache {
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
  TDiskYUV422Cache();
Toshihiro Shimizu 890ddd
  ~TDiskYUV422Cache();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  void putRaster(int frame, const TRasterP &ras);
Toshihiro Shimizu 890ddd
  void getRaster(int frame, TRasterYUV422P &ras) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRAMUncompressedCache::getRaster(int frame, TRasterP &ras)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
TRaster32P ras32(ras.getSize());
Toshihiro Shimizu 890ddd
getRaster(frame, ras32);
Toshihiro Shimizu 890ddd
convert(ras, ras32);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRAMUncompressedCache::getRaster(int frame, TRaster32P  &ras) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
//....
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TRasterCache {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TRasterCache(TCachePersist *cp);
Shinya Kitaoka 120a6e
  virtual ~TRasterCache();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setMode(const TDimension &size, int bpp);
Shinya Kitaoka 120a6e
  void getMode(TDimension &size, int &bpp) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRasterP getRaster(int frame) const;
Shinya Kitaoka 120a6e
  bool getBuffer(int frame, UCHAR *&buffer, int &wrap, int &bpp,
Shinya Kitaoka 120a6e
                 TDimension &rasDim) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool getRaster(int frame, TRaster32P &ras) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void putRaster(int frame, const TRasterP &ras);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  UCHAR *getRawData(int frame, TINT32 &size, int &lx, int &ly) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isFrameCached(int frame) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void invalidate();
Shinya Kitaoka 120a6e
  void invalidate(int startFrame, int endFrame);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void enablePrefetch(bool newState);
Shinya Kitaoka 120a6e
  bool isPrefetchEnabled() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUINT64 getUsedSpace();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  //  virtual TRasterP doGetRaster(int frame) = 0;
Shinya Kitaoka 120a6e
  //  virtual void doPutRaster(int frame, const TRasterP &ras) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  class Data;
Shinya Kitaoka 120a6e
  Data *m_data;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TCachePersist {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TCachePersist(TRasterCodec *codec) : m_codec(codec) {}
Shinya Kitaoka 120a6e
  virtual ~TCachePersist() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual void setFrameSize(int lx, int ly, int bpp) = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual TRasterP doGetRaster(int frame) = 0;
Shinya Kitaoka 120a6e
  virtual bool doGetRaster(int frame, TRaster32P &ras) const = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual bool doPutRaster(int frame, const TRasterP &ras) = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual void onInvalidate() = 0;
Shinya Kitaoka 120a6e
  virtual void onInvalidate(int startFrame, int endFrame) = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual UCHAR *getRawData(int frame, TINT32 &size, int &lx, int &ly) = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual TUINT64 getUsedSpace() = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // private:
Shinya Kitaoka 120a6e
  TRasterCodec *m_codec;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TRamCachePersist final : public TCachePersist {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TRamCachePersist(TRasterCodec *codec);
Shinya Kitaoka 120a6e
  ~TRamCachePersist();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void setFrameSize(int lx, int ly, int bpp) override {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void onInvalidate() override;
Shinya Kitaoka 473e70
  void onInvalidate(int startFrame, int endFrame) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  UCHAR *getRawData(int frame, TINT32 &size, int &lx, int &ly) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TUINT64 getUsedSpace() override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 473e70
  TRasterP doGetRaster(int frame) override;
Shinya Kitaoka 473e70
  bool doGetRaster(int frame, TRaster32P &ras) const override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  bool doPutRaster(int frame, const TRasterP &ras) override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  class Imp;
Shinya Kitaoka 120a6e
  Imp *m_imp;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TDiskCachePersist final : public TCachePersist {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TDiskCachePersist(TRasterCodec *codec, const TFilePath &fullpath);
Shinya Kitaoka 120a6e
  ~TDiskCachePersist();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void setFrameSize(int lx, int ly, int bpp) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void onInvalidate() override;
Shinya Kitaoka 473e70
  void onInvalidate(int startFrame, int endFrame) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  UCHAR *getRawData(int frame, TINT32 &size, int &lx, int &ly) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TUINT64 getUsedSpace() override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 473e70
  TRasterP doGetRaster(int frame) override;
Shinya Kitaoka 473e70
  bool doGetRaster(int frame, TRaster32P &ras) const override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  bool doPutRaster(int frame, const TRasterP &ras) override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  class Imp;
Shinya Kitaoka 120a6e
  Imp *m_imp;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
// TDiskCachePersist2 usa il Direct File I/O (acceso al disco non bufferizzato)
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TDiskCachePersist2 final : public TCachePersist {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TDiskCachePersist2(TRasterCodec *codec, const TFilePath &fullpath);
Shinya Kitaoka 120a6e
  ~TDiskCachePersist2();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void setFrameSize(int lx, int ly, int bpp) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void onInvalidate() override;
Shinya Kitaoka 473e70
  void onInvalidate(int startFrame, int endFrame) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  UCHAR *getRawData(int frame, TINT32 &size, int &lx, int &ly) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TUINT64 getUsedSpace() override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 473e70
  TRasterP doGetRaster(int frame) override;
Shinya Kitaoka 473e70
  bool doGetRaster(int frame, TRaster32P &ras) const override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  bool doPutRaster(int frame, const TRasterP &ras) override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  class Imp;
Shinya Kitaoka 120a6e
  Imp *m_imp;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TCompressedLevel {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TCompressedLevel(const TFilePath &fullpath);
Shinya Kitaoka 120a6e
  ~TCompressedLevel();
Shinya Kitaoka 120a6e
  void setSize(TDimension d);
Shinya Kitaoka 120a6e
  void putImage(int frame, const TRaster32P &ras);
Shinya Kitaoka 120a6e
  TRaster32P getImage(int frame);
Shinya Kitaoka 120a6e
  void invalidate(int frame);
Shinya Kitaoka 120a6e
  void invalidateAll();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  TCompressedLevel();  // not implemented
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFilePath m_fullpath;
Shinya Kitaoka 120a6e
  TRawDataCodec *m_codec;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int m_viewFrameMin, m_viewFrameMax;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
  HANDLE m_hFile, m_hMap;
Shinya Kitaoka 120a6e
  LPVOID m_fileMapAddress;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int m_xSize, m_ySize;
Shinya Kitaoka 120a6e
  int m_frameSize;
Shinya Kitaoka 120a6e
  SYSTEM_INFO m_systemInfo;
Shinya Kitaoka 120a6e
  __int64 m_mapOffset;
Shinya Kitaoka 120a6e
  static DWORD m_maxViewSize;
Shinya Kitaoka 120a6e
  static DWORD m_maxFileSize;
Shinya Kitaoka 120a6e
  static DWORD m_reallocFileSize;
Shinya Kitaoka 120a6e
  //-------
Shinya Kitaoka 120a6e
  HANDLE initFile(const TFilePath &fname);
Shinya Kitaoka 120a6e
  HANDLE mapFile(HANDLE hFile, ULONGLONG size);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static TThread::Mutex m_mutex;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setCurrentView(int frame, bool force = false);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif