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)
Shinya Kitaoka 120a6e
    : m_path(path), m_fid(fid), m_subsampling(0), m_64bitCompatible(false) {}
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) {
Shinya Kitaoka 120a6e
  return (imFlags & ImageManager::toBeModified)
Shinya Kitaoka 120a6e
             ? 1
Shinya Kitaoka 120a6e
             : (data->m_subs > 0)
Shinya Kitaoka 120a6e
                   ? data->m_subs
Shinya Kitaoka 120a6e
                   : (m_subsampling > 0)
Shinya Kitaoka 120a6e
                         ? m_subsampling
Shinya Kitaoka 120a6e
                         : 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
Shinya Kitaoka 120a6e
    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
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // Load the image
Shinya Kitaoka 120a6e
    TImageP img;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (data->m_icon && m_path.getType() == "tlv")
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);
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;
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
Shinya Kitaoka 120a6e
  if (m_64bitCompatible || !(imFlags & ImageManager::is64bitEnabled)) {
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  }
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;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*--
Shinya Kitaoka 120a6e
 * ImageBuilder仮想関数の実装。アイコン、画像をLoad時に全てキャッシュに格納する
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) {
Shinya Kitaoka 120a6e
  if (m_path.getType() != "tlv") return;
Shinya Kitaoka 120a6e
  if (fids.empty() || iconIds.empty()) return;
Shinya Kitaoka 120a6e
  /*- fidとアイコンidの数は同じはず -*/
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
Shinya Kitaoka 120a6e
      /*- 画像データも一緒にキャッシュする場合 -*/
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
Shinya Kitaoka 120a6e
      /*- アイコンのロード -*/
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
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
      TGlContext oldContext = tglGetCurrentContext();
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 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 120a6e
          assert(glGetError() == 0);
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
          assert(glGetError() == 0);
Shinya Kitaoka 120a6e
          tglDraw(rd, vi.getPointer());
Shinya Kitaoka 120a6e
          assert(glGetError() == 0);
Shinya Kitaoka 70f81d
Shinya Kitaoka 120a6e
          assert(glGetError() == 0);
Shinya Kitaoka 120a6e
          glFlush();
Shinya Kitaoka 120a6e
          assert(glGetError() == 0);
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
        tglMakeCurrent(oldContext);
Shinya Kitaoka 7bc906
Shinya Kitaoka 120a6e
        TRasterImageP ri = TRasterImageP(ras);
Shinya Kitaoka 120a6e
        ri->setOffset(off + ras->getCenter());
Shinya Kitaoka 70f81d
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
}