Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef T_TILE_INCLUDED
Toshihiro Shimizu 890ddd
#define T_TILE_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "traster.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Toshihiro Shimizu 890ddd
#include "timagecache.h"
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TRASTER_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
Shinya Kitaoka 120a6e
class DVAPI TTile {
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  std::string m_rasterId;
Shinya Kitaoka 120a6e
  TRect m_subRect;
Shinya Kitaoka 120a6e
  TTile(const TTile &);
Shinya Kitaoka 120a6e
  TTile &operator=(const TTile &);
Shinya Kitaoka 120a6e
  void addInCache(const TRasterP &raster);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TPointD m_pos;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TTile() : m_rasterId(""), m_pos(), m_subRect() {}
Shinya Kitaoka 120a6e
  TTile(const TRasterP &raster);
Shinya Kitaoka 120a6e
  TTile(const TRasterP &raster, TPointD pos);
Shinya Kitaoka 120a6e
  ~TTile();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setRaster(const TRasterP &raster);
Shinya Kitaoka 120a6e
  inline const TRasterP getRaster() const {
Shinya Kitaoka 120a6e
    TImageP img        = TImageCache::instance()->get(m_rasterId, true);
Shinya Kitaoka 120a6e
    TRasterImageP rimg = (TRasterImageP)img;
Shinya Kitaoka 120a6e
    if (rimg) {
Shinya Kitaoka 120a6e
      if (m_subRect == rimg->getRaster()->getBounds())
Shinya Kitaoka 120a6e
        return rimg->getRaster();
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        return rimg->getRaster()->extract(m_subRect.x0, m_subRect.y0,
Shinya Kitaoka 120a6e
                                          m_subRect.x1, m_subRect.y1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TToonzImageP timg = (TToonzImageP)img;
Shinya Kitaoka 120a6e
    if (timg) {
Shinya Kitaoka 120a6e
      if (m_subRect == timg->getRaster()->getBounds())
Shinya Kitaoka 120a6e
        return timg->getRaster();
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        return timg->getRaster()->extract(m_subRect.x0, m_subRect.y0,
Shinya Kitaoka 120a6e
                                          m_subRect.x1, m_subRect.y1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    return TRasterP();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif