Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "timageinfo.h"
Toshihiro Shimizu 890ddd
#include "timage_io.h"
Toshihiro Shimizu 890ddd
#include "tlevel_io.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
#include "trastercm.h"
Toshihiro Shimizu 890ddd
#include "tvectorrenderdata.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tgl.h"
Toshihiro Shimizu 890ddd
#include "tvectorgl.h"
Toshihiro Shimizu 890ddd
#include "tofflinegl.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "timagecache.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/fill.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Shinya Kitaoka 70f81d
#include <qimage></qimage>
Shinya Kitaoka 70f81d
#include <qthread></qthread>
Shinya Kitaoka 70f81d
#include <qopenglcontext></qopenglcontext>
Shinya Kitaoka 70f81d
#include <qoffscreensurface></qoffscreensurface>
Shinya Kitaoka 70f81d
#include <qopenglframebufferobject></qopenglframebufferobject>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "imagebuilders.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//***************************************************************************************
Toshihiro Shimizu 890ddd
//    Global stuff
Toshihiro Shimizu 890ddd
//***************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
extern TOfflineGL *currentOfflineGL;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//***************************************************************************************
Toshihiro Shimizu 890ddd
//    ImageLoader  implementation
Toshihiro Shimizu 890ddd
//***************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ImageLoader::ImageLoader(const TFilePath &path, const TFrameId &fid)
shun-iwasawa 481b59
    : m_path(path)
shun-iwasawa 481b59
    , m_fid(fid)
shun-iwasawa 481b59
    , m_subsampling(0)
shun-iwasawa 481b59
    , m_64bitCompatible(false)
shun-iwasawa 481b59
    , m_colorSpaceGamma(LevelOptions::DefaultColorSpaceGamma) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool ImageLoader::getInfo(TImageInfo &info, int imFlags, void *extData) {
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    TLevelReaderP lr(m_path);
Shinya Kitaoka 120a6e
    TImageReaderP fr = lr->getFrameReader(m_fid);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // NOTE: Currently not changing imageInfo's bpp stuff...
Shinya Kitaoka 120a6e
    //       Ignoring subsampling too...
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    return ImageBuilder::setImageInfo(info, fr.getPointer());
Shinya Kitaoka 120a6e
  } catch (TException &e) {
Shinya Kitaoka 120a6e
    QString msg = QString::fromStdWString(e.getMessage());
Shinya Kitaoka 120a6e
    if (msg == QString("Old 4.1 Palette")) throw;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline int ImageLoader::buildSubsampling(int imFlags, BuildExtData *data) {
shun-iwasawa 481b59
  return (imFlags & ImageManager::toBeModified) ? 1
shun-iwasawa 481b59
         : (data->m_subs > 0)                   ? data->m_subs
shun-iwasawa 481b59
         : (m_subsampling > 0)                  ? m_subsampling
shun-iwasawa 481b59
                               : data->m_sl->getProperties()->getSubsampling();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TImageP ImageLoader::build(int imFlags, void *extData) {
Shinya Kitaoka 120a6e
  assert(extData);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Extract external data
Shinya Kitaoka 120a6e
  BuildExtData *data = static_cast<buildextdata *="">(extData);</buildextdata>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int subsampling = buildSubsampling(imFlags, data);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    // Initialize level reader
Shinya Kitaoka 120a6e
    TLevelReaderP lr(m_path);
Shinya Kitaoka 120a6e
    if (!lr) return TImageP();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // Load info in cases where it's required first
Shinya Kitaoka 120a6e
    lr->doReadPalette(false);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if ((m_path.getType() == "pli") || (m_path.getType() == "svg") ||
Shinya Kitaoka 120a6e
        (m_path.getType() == "psd"))
Shinya Kitaoka 120a6e
      lr->loadInfo();
Toshihiro Shimizu 890ddd
shun-iwasawa 18198a
    bool isTlvIcon = data->m_icon && m_path.getType() == "tlv";
shun-iwasawa 18198a
shun-iwasawa 18198a
    // for TLV icons, palettes will be applied in IconGenerator later
shun-iwasawa 18198a
    if (!isTlvIcon) lr->doReadPalette(true);  // Allow palette loading
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    TImageReaderP ir = lr->getFrameReader(m_fid);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    bool enable64bit = (imFlags & ImageManager::is64bitEnabled);
Shinya Kitaoka 120a6e
    ir->enable16BitRead(enable64bit);  // Set 64-bit loading if required
shun-iwasawa 481b59
    bool enableFloat = (imFlags & ImageManager::isFloatEnabled);
shun-iwasawa 481b59
    ir->enableFloatRead(enableFloat);  // Set float loading if required
shun-iwasawa 481b59
shun-iwasawa 481b59
    double colorSpaceGamma = LevelOptions::DefaultColorSpaceGamma;
shun-iwasawa 481b59
    if (m_path.getType() == "exr") {
shun-iwasawa 481b59
      // gamma value to be used for converting linear-based image file to
shun-iwasawa 481b59
      // nonlinear raster. Curretly only used in EXR image levels.
shun-iwasawa 481b59
      colorSpaceGamma = data->m_sl->getProperties()->colorSpaceGamma();
shun-iwasawa 481b59
      ir->setColorSpaceGamma(colorSpaceGamma);
shun-iwasawa 481b59
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // Load the image
Shinya Kitaoka 120a6e
    TImageP img;
Toshihiro Shimizu 890ddd
shun-iwasawa 18198a
    if (isTlvIcon)
Shinya Kitaoka 120a6e
      img = ir->loadIcon();  // TODO: Why just in the tlv case??
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      ir->setShrink(subsampling);
Shinya Kitaoka 120a6e
      img = ir->load();
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    ir->enable16BitRead(false);
shun-iwasawa 481b59
    ir->enableFloatRead(false);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (!img) return img;  // There was an error loading the image.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    TPalette *palette = data->m_sl->getPalette();
Shinya Kitaoka 120a6e
    if (palette) img->setPalette(palette);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (subsampling > 1) {
Shinya Kitaoka 120a6e
      // Store the subsampling info in the image
Shinya Kitaoka 120a6e
      if (TRasterImageP ri = img)
Shinya Kitaoka 120a6e
        ri->setSubsampling(subsampling);
Shinya Kitaoka 120a6e
      else if (TToonzImageP ti = img)
Shinya Kitaoka 120a6e
        ti->setSubsampling(subsampling);
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // In case the image will be cached, store its subsampling and 64 bit
Shinya Kitaoka 120a6e
    // compatibility
Shinya Kitaoka 120a6e
    if (!(imFlags & ImageManager::dontPutInCache)) {
Shinya Kitaoka 120a6e
      m_subsampling = subsampling;
Shinya Kitaoka 120a6e
      m_64bitCompatible =
Shinya Kitaoka 120a6e
          data->m_sl->is16BitChannelLevel() ? enable64bit : true;
shun-iwasawa 481b59
      m_floatCompatible =
shun-iwasawa 481b59
          data->m_sl->isFloatChannelLevel() ? enableFloat : true;
shun-iwasawa 481b59
      if (m_path.getType() == "exr") m_colorSpaceGamma = colorSpaceGamma;
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    return img;
Shinya Kitaoka 120a6e
  } catch (...) {
Shinya Kitaoka 120a6e
    return TImageP();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool ImageLoader::isImageCompatible(int imFlags, void *extData) {
Shinya Kitaoka 120a6e
  assert(extData);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  BuildExtData *data        = static_cast<buildextdata *="">(extData);</buildextdata>
Shinya Kitaoka 120a6e
  const TXshSimpleLevel *sl = data->m_sl;
tomosu e5f7d8
Shinya Kitaoka 120a6e
  // NOTE: Vector and Mesh dont care about sub sampling rate and bit depth
Shinya Kitaoka 120a6e
  // compatibility.
Shinya Kitaoka 120a6e
  //       They are property of Raster.
Shinya Kitaoka 120a6e
  if (sl->getType() == PLI_XSHLEVEL || sl->getType() == MESH_XSHLEVEL)
Shinya Kitaoka 120a6e
    return true;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int subsampling = buildSubsampling(imFlags, data);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_subsampling <= 0 || subsampling != m_subsampling) return false;
Toshihiro Shimizu 890ddd
shun-iwasawa 481b59
  if (m_path.getType() == "exr" &&
shun-iwasawa 481b59
      !areAlmostEqual(m_colorSpaceGamma,
shun-iwasawa 481b59
                      sl->getProperties()->colorSpaceGamma()))
Shinya Kitaoka 120a6e
    return false;
shun-iwasawa 481b59
shun-iwasawa 481b59
  if (!m_floatCompatible && (imFlags & ImageManager::isFloatEnabled))
shun-iwasawa 481b59
    return false;
shun-iwasawa 481b59
  else if (!m_64bitCompatible && (imFlags & ImageManager::is64bitEnabled))
shun-iwasawa 481b59
    return false;
shun-iwasawa 481b59
  else
shun-iwasawa 481b59
    return true;
shun-iwasawa 481b59
shun-iwasawa 481b59
  // if (m_64bitCompatible || !(imFlags & ImageManager::is64bitEnabled)) {
shun-iwasawa 481b59
  //   return true;
shun-iwasawa 481b59
  // } else {
shun-iwasawa 481b59
  //   return false;
shun-iwasawa 481b59
  // }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ImageLoader::invalidate() {
Shinya Kitaoka 120a6e
  ImageBuilder::invalidate();
Shinya Kitaoka 120a6e
  m_subsampling     = 0;
Shinya Kitaoka 120a6e
  m_64bitCompatible = false;
shun-iwasawa 481b59
  m_colorSpaceGamma = LevelOptions::DefaultColorSpaceGamma;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*--
shun-iwasawa 443318
 * Implement ImageBuilder virtual functions. All icons and images are stored in
shun-iwasawa 443318
 * the cache on Loading.
Shinya Kitaoka 120a6e
 * --*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ImageLoader::buildAllIconsAndPutInCache(TXshSimpleLevel *level,
Shinya Kitaoka 120a6e
                                             std::vector<tframeid> fids,</tframeid>
Shinya Kitaoka 120a6e
                                             std::vector<std::string> iconIds,</std::string>
Shinya Kitaoka 120a6e
                                             bool cacheImagesAsWell) {
shun-iwasawa 48d289
  // if (m_path.getType() != "tlv") return;
shun-iwasawa 48d289
  if (level->getType() != TZP_XSHLEVEL && level->getType() != OVL_XSHLEVEL)
shun-iwasawa 48d289
    return;
shun-iwasawa 48d289
Shinya Kitaoka 120a6e
  if (fids.empty() || iconIds.empty()) return;
shun-iwasawa 443318
  /*- The number of fid and icon id should be the same -*/
Shinya Kitaoka 120a6e
  if ((int)fids.size() != (int)iconIds.size()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    TLevelReaderP lr(m_path);
Shinya Kitaoka 120a6e
    if (!lr) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (int i = 0; i < (int)fids.size(); i++) {
Shinya Kitaoka 120a6e
      lr->doReadPalette(false);
Shinya Kitaoka 120a6e
      TImageReaderP ir = lr->getFrameReader(fids[i]);
Shinya Kitaoka 120a6e
      lr->doReadPalette(true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      TImageInfo info;
Shinya Kitaoka 120a6e
      TPalette *palette     = level->getPalette();
Shinya Kitaoka 120a6e
      std::string fullImgId = level->getImageId(fids[i]);
Shinya Kitaoka 120a6e
shun-iwasawa 443318
      /*- When image data is also cached together -*/
Shinya Kitaoka 120a6e
      if (cacheImagesAsWell) {
Shinya Kitaoka 120a6e
        ir->enable16BitRead(m_64bitCompatible);
Shinya Kitaoka 120a6e
        ir->setShrink(1);
Shinya Kitaoka 120a6e
        TImageP fullImg = ir->load();
Shinya Kitaoka 120a6e
        if (fullImg) {
Shinya Kitaoka 120a6e
          if (palette) fullImg->setPalette(palette);
Shinya Kitaoka 120a6e
          TImageCache::instance()->add(fullImgId, fullImg, true);
Shinya Kitaoka 120a6e
          setImageInfo(info, fullImg.getPointer());
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
shun-iwasawa 443318
      /*- load icons -*/
Shinya Kitaoka 120a6e
      TImageP img = ir->loadIcon();
Shinya Kitaoka 120a6e
      ir->enable16BitRead(false);
Shinya Kitaoka 120a6e
      if (img) {
Shinya Kitaoka 120a6e
        if (palette) img->setPalette(palette);
Shinya Kitaoka 120a6e
        TImageCache::instance()->add(iconIds[i], img, true);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } catch (...) {
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
manongjohn 88ffb4
void ImageLoader::setFid(const TFrameId &fid) { m_fid = fid; }
manongjohn 88ffb4
Toshihiro Shimizu 890ddd
//***************************************************************************************
Toshihiro Shimizu 890ddd
//    ImageRasterizer  implementation
Toshihiro Shimizu 890ddd
//***************************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool ImageRasterizer::getInfo(TImageInfo &info, int imFlags, void *extData) {
Shinya Kitaoka 120a6e
  assert(false);  // None should get these... in case, TODO
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TImageP ImageRasterizer::build(int imFlags, void *extData) {
Shinya Kitaoka 120a6e
  assert(!(imFlags &
Shinya Kitaoka 120a6e
           ~(ImageManager::dontPutInCache | ImageManager::forceRebuild)));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TDimension d(10, 10);
Shinya Kitaoka 120a6e
  TPoint off(0, 0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Fetch image
Shinya Kitaoka 120a6e
  assert(extData);
Shinya Kitaoka 120a6e
  ImageLoader::BuildExtData *data = (ImageLoader::BuildExtData *)extData;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const std::string &srcImgId = data->m_sl->getImageId(data->m_fid);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TImageP img = ImageManager::instance()->getImage(srcImgId, imFlags, extData);
Shinya Kitaoka 120a6e
  if (img) {
Shinya Kitaoka 120a6e
    TVectorImageP vi = img;
Shinya Kitaoka 120a6e
    if (vi) {
Shinya Kitaoka 120a6e
      TRectD bbox = vi->getBBox();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      d   = TDimension(tceil(bbox.getLx()) + 1, tceil(bbox.getLy()) + 1);
Shinya Kitaoka 120a6e
      off = TPoint((int)bbox.x0, (int)bbox.y0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      TPalette *vpalette = vi->getPalette();
Shinya Kitaoka 120a6e
      TVectorRenderData rd(TTranslation(-off.x, -off.y), TRect(TPoint(0, 0), d),
Shinya Kitaoka 120a6e
                           vpalette, 0, true, true);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      // this is too slow.
Shinya Kitaoka 120a6e
      {
Shinya Kitaoka 120a6e
        QSurfaceFormat format;
Shinya Kitaoka 120a6e
        format.setProfile(QSurfaceFormat::CompatibilityProfile);
Shinya Kitaoka 70f81d
Shinya Kitaoka 0f12b3
        std::unique_ptr<qoffscreensurface> surface(new QOffscreenSurface());</qoffscreensurface>
Shinya Kitaoka 0f12b3
        surface->setFormat(format);
Shinya Kitaoka 0f12b3
        surface->create();
Shinya Kitaoka 0f12b3
Shinya Kitaoka 120a6e
        TRaster32P ras(d);
Shinya Kitaoka 70f81d
Shinya Kitaoka 120a6e
        glPushAttrib(GL_ALL_ATTRIB_BITS);
Shinya Kitaoka 120a6e
        glMatrixMode(GL_MODELVIEW), glPushMatrix();
Shinya Kitaoka 120a6e
        glMatrixMode(GL_PROJECTION), glPushMatrix();
Shinya Kitaoka 120a6e
        {
Shinya Kitaoka 120a6e
          std::unique_ptr<qopenglframebufferobject> fb(</qopenglframebufferobject>
Shinya Kitaoka 120a6e
              new QOpenGLFramebufferObject(d.lx, d.ly));
Shinya Kitaoka 70f81d
Shinya Kitaoka 120a6e
          fb->bind();
Shinya Kitaoka 70f81d
Shinya Kitaoka 120a6e
          glViewport(0, 0, d.lx, d.ly);
Shinya Kitaoka 120a6e
          glClearColor(0, 0, 0, 0);
Shinya Kitaoka 120a6e
          glClear(GL_COLOR_BUFFER_BIT);
Shinya Kitaoka 70f81d
Shinya Kitaoka 120a6e
          glMatrixMode(GL_PROJECTION);
Shinya Kitaoka 120a6e
          glLoadIdentity();
Shinya Kitaoka 120a6e
          gluOrtho2D(0, d.lx, 0, d.ly);
Shinya Kitaoka 70f81d
Shinya Kitaoka 120a6e
          glMatrixMode(GL_MODELVIEW);
Shinya Kitaoka 120a6e
          glLoadIdentity();
Shinya Kitaoka 120a6e
          glTranslatef(0.375, 0.375, 0.0);
Shinya Kitaoka 70f81d
Shinya Kitaoka 120a6e
          tglDraw(rd, vi.getPointer());
Shinya Kitaoka 70f81d
Shinya Kitaoka 120a6e
          glFlush();
Shinya Kitaoka 70f81d
Shinya Kitaoka 120a6e
          QImage img =
Shinya Kitaoka 120a6e
              fb->toImage().scaled(QSize(d.lx, d.ly), Qt::IgnoreAspectRatio,
Shinya Kitaoka 120a6e
                                   Qt::SmoothTransformation);
Shinya Kitaoka 70f81d
Shinya Kitaoka 120a6e
          int wrap      = ras->getLx() * sizeof(TPixel32);
Shinya Kitaoka 120a6e
          uchar *srcPix = img.bits();
Shinya Kitaoka 120a6e
          uchar *dstPix = ras->getRawData() + wrap * (d.ly - 1);
Shinya Kitaoka 120a6e
          for (int y = 0; y < d.ly; y++) {
Shinya Kitaoka 120a6e
            memcpy(dstPix, srcPix, wrap);
Shinya Kitaoka 120a6e
            dstPix -= wrap;
Shinya Kitaoka 120a6e
            srcPix += wrap;
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
          fb->release();
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        glMatrixMode(GL_MODELVIEW), glPopMatrix();
Shinya Kitaoka 120a6e
        glMatrixMode(GL_PROJECTION), glPopMatrix();
Shinya Kitaoka 70f81d
Shinya Kitaoka 120a6e
        glPopAttrib();
Shinya Kitaoka 70f81d
Shinya Kitaoka 120a6e
        TRasterImageP ri = TRasterImageP(ras);
Shinya Kitaoka 120a6e
        ri->setOffset(off + ras->getCenter());
Shinya Kitaoka 70f81d
shun_iwasawa 7e52a2
        assert(glGetError() == 0);
shun_iwasawa 7e52a2
Shinya Kitaoka 120a6e
        return ri;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Error case: return a dummy image (is it really required?)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRaster32P ras(d);
Shinya Kitaoka 120a6e
  ras->fill(TPixel32(127, 0, 127, 127));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return TRasterImageP(ras);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//***************************************************************************************
Toshihiro Shimizu 890ddd
//    ImageFiller  implementation
Toshihiro Shimizu 890ddd
//***************************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool ImageFiller::getInfo(TImageInfo &info, int imFlags, void *extData) {
Shinya Kitaoka 120a6e
  assert(false);  // None should get these... in case, TODO
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TImageP ImageFiller::build(int imFlags, void *extData) {
Shinya Kitaoka 120a6e
  assert(imFlags == ImageManager::none);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Fetch image
Shinya Kitaoka 120a6e
  assert(extData);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ImageLoader::BuildExtData *data = (ImageLoader::BuildExtData *)extData;
Shinya Kitaoka 120a6e
  assert(data->m_subs == 0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const std::string &srcImgId = data->m_sl->getImageId(data->m_fid);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TImageP img = ImageManager::instance()->getImage(srcImgId, imFlags, extData);
Shinya Kitaoka 120a6e
  if (img) {
Shinya Kitaoka 120a6e
    TRasterImageP ri = img;
Shinya Kitaoka 120a6e
    if (ri) {
Shinya Kitaoka 120a6e
      TRaster32P ras = ri->getRaster();
Shinya Kitaoka 120a6e
      if (ras) {
Shinya Kitaoka 120a6e
        TRaster32P newRas = ras->clone();
Shinya Kitaoka 120a6e
        FullColorAreaFiller filler(newRas);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        TPaletteP palette = new TPalette();
Shinya Kitaoka 120a6e
        int styleId       = palette->getPage(0)->addStyle(TPixel32::White);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        FillParameters params;
Shinya Kitaoka 120a6e
        params.m_palette      = palette.getPointer();
Shinya Kitaoka 120a6e
        params.m_styleId      = styleId;
Shinya Kitaoka 120a6e
        params.m_minFillDepth = 0;
Shinya Kitaoka 120a6e
        params.m_maxFillDepth = 15;
Shinya Kitaoka 120a6e
        filler.rectFill(newRas->getBounds(), params, false);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        TRasterImageP ri = TRasterImageP(newRas);
Shinya Kitaoka 120a6e
        return ri;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Error case: return a dummy image (is it really required?)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRaster32P ras(10, 10);
Shinya Kitaoka 120a6e
  ras->fill(TPixel32(127, 0, 127, 127));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return TRasterImageP(ras);
Toshihiro Shimizu 890ddd
}