Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRasterImage::TRasterImage()
Shinya Kitaoka 120a6e
    : m_mainRaster()
Shinya Kitaoka 120a6e
    , m_patchRaster()
Shinya Kitaoka 120a6e
    , m_iconRaster()
Shinya Kitaoka 120a6e
    , m_dpix(0)
Shinya Kitaoka 120a6e
    , m_dpiy(0)
Shinya Kitaoka 120a6e
    , m_name("")
Shinya Kitaoka 120a6e
    , m_savebox()
Shinya Kitaoka 120a6e
    //, m_hPos(0.0)
Shinya Kitaoka 120a6e
    , m_isOpaque(false)
Shinya Kitaoka 120a6e
    , m_isScanBW(false)
Shinya Kitaoka 120a6e
    , m_offset(0, 0)
Shinya Kitaoka 120a6e
    , m_subsampling(1) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRasterImage::TRasterImage(const TRasterP &ras)
Shinya Kitaoka 120a6e
    : m_mainRaster(ras)
Shinya Kitaoka 120a6e
    , m_patchRaster()
Shinya Kitaoka 120a6e
    , m_iconRaster()
Shinya Kitaoka 120a6e
    , m_dpix(0)
Shinya Kitaoka 120a6e
    , m_dpiy(0)
Shinya Kitaoka 120a6e
    , m_name("")
Shinya Kitaoka 120a6e
    , m_savebox(0, 0, ras->getLx() - 1, ras->getLy() - 1)
Shinya Kitaoka 120a6e
    //, m_hPos(0.0)
Shinya Kitaoka 120a6e
    , m_isOpaque(false)
Shinya Kitaoka 120a6e
    , m_isScanBW(false)
Shinya Kitaoka 120a6e
    , m_offset(0, 0)
Shinya Kitaoka 120a6e
    , m_subsampling(1) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TRasterImage::setRaster(const TRasterP &raster) {
Shinya Kitaoka 120a6e
  m_mainRaster = raster;
Shinya Kitaoka 120a6e
  m_savebox    = TRect(0, 0, raster->getLx() - 1, raster->getLy() - 1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRasterImage::TRasterImage(const TRasterImage &src)
Shinya Kitaoka 120a6e
    : m_mainRaster(src.m_mainRaster)
Shinya Kitaoka 120a6e
    , m_patchRaster(src.m_patchRaster)
Shinya Kitaoka 120a6e
    , m_iconRaster(src.m_iconRaster)
Shinya Kitaoka 120a6e
    , m_dpix(src.m_dpix)
Shinya Kitaoka 120a6e
    , m_dpiy(src.m_dpiy)
Shinya Kitaoka 120a6e
    , m_name(src.m_name)
Shinya Kitaoka 120a6e
    , m_savebox(src.m_savebox)
Shinya Kitaoka 120a6e
    //, m_hPos(src.m_hPos)
Shinya Kitaoka 120a6e
    , m_isOpaque(src.m_isOpaque)
Shinya Kitaoka 120a6e
    , m_isScanBW(src.m_isScanBW)
Shinya Kitaoka 120a6e
    , m_offset(src.m_offset)
Shinya Kitaoka 120a6e
    , m_subsampling(src.m_subsampling) {
Shinya Kitaoka 120a6e
  if (m_mainRaster) m_mainRaster   = m_mainRaster->clone();
Shinya Kitaoka 120a6e
  if (m_patchRaster) m_patchRaster = m_patchRaster->clone();
Shinya Kitaoka 120a6e
  if (m_iconRaster) m_iconRaster   = m_iconRaster->clone();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRasterImage::~TRasterImage() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TImage *TRasterImage::cloneImage() const { return new TRasterImage(*this); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRasterImage::setSubsampling(int s) { m_subsampling = s; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRasterImage::makeIcon(const TRaster32P &dstRas) {
Toshihiro Shimizu 890ddd
#ifndef TNZCORE_LIGHT
Shinya Kitaoka 120a6e
  assert(dstRas && dstRas->getLx() > 0 && dstRas->getLy() > 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterP &srcRas = m_mainRaster;
Shinya Kitaoka 120a6e
  if (!srcRas || srcRas->getLx() <= 0 || srcRas->getLy() <= 0) {
Shinya Kitaoka 120a6e
    dstRas->clear();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double dpix = m_dpix, dpiy = m_dpiy;
Shinya Kitaoka 120a6e
  if (dpix == 0) dpix = 1;
Shinya Kitaoka 120a6e
  if (dpiy == 0) dpiy = 1;
Shinya Kitaoka 120a6e
  double sx   = (double)dstRas->getLx() * dpix / (double)srcRas->getLx();
Shinya Kitaoka 120a6e
  double sy   = (double)dstRas->getLy() * dpiy / (double)srcRas->getLy();
Shinya Kitaoka 120a6e
  double sc   = std::max(sx, sy);
Shinya Kitaoka 120a6e
  TAffine aff = TScale(sc / dpix, sc / dpiy)
Shinya Kitaoka 120a6e
                    .place(srcRas->getCenterD(), dstRas->getCenterD());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRop::resample(dstRas, srcRas, aff);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------