Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/trasterimageutils.h"
Toshihiro Shimizu 890ddd
#include "toonz/ttileset.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "tofflinegl.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
#include "tvectorrenderdata.h"
Toshihiro Shimizu 890ddd
#include "ttzpimagefx.h"
Toshihiro Shimizu 890ddd
#include "tvectorgl.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tregion.h"
Toshihiro Shimizu 890ddd
#include "tcolorstyles.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qcolor></qcolor>
Toshihiro Shimizu 890ddd
#include <qimage></qimage>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
QImage rasterToQImage(const TRasterP &ras, bool premultiplied, bool mirrored) {
Shinya Kitaoka 120a6e
  if (TRaster32P ras32 = ras) {
Shinya Kitaoka 120a6e
    QImage image(ras->getRawData(), ras->getLx(), ras->getLy(),
Shinya Kitaoka 120a6e
                 premultiplied ? QImage::Format_ARGB32_Premultiplied
Shinya Kitaoka 120a6e
                               : QImage::Format_ARGB32);
Shinya Kitaoka 120a6e
    if (mirrored) return image.mirrored();
Shinya Kitaoka 120a6e
    return image;
Shinya Kitaoka 120a6e
  } else if (TRasterGR8P ras8 = ras) {
Shinya Kitaoka 120a6e
    QImage image(ras->getRawData(), ras->getLx(), ras->getLy(), ras->getWrap(),
Shinya Kitaoka 120a6e
                 QImage::Format_Indexed8);
Shinya Kitaoka 120a6e
    static QVector<qrgb> colorTable;</qrgb>
Shinya Kitaoka 120a6e
    if (colorTable.size() == 0) {
Shinya Kitaoka 120a6e
      int i;
Shinya Kitaoka 120a6e
      for (i = 0; i < 256; i++) colorTable.append(QColor(i, i, i).rgb());
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    image.setColorTable(colorTable);
Shinya Kitaoka 120a6e
    if (mirrored) return image.mirrored();
Shinya Kitaoka 120a6e
    return image;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return QImage();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void rasterizeWholeStroke(TOfflineGL *&gl, TStroke *stroke, TPalette *palette,
Shinya Kitaoka 120a6e
                          bool doAnialias) {
Shinya Kitaoka 120a6e
  TRectD bbox = stroke->getBBox();
Shinya Kitaoka 120a6e
  TRect rect  = convert(bbox).enlarge(1);
Shinya Kitaoka 120a6e
  gl          = new TOfflineGL(rect.getSize());
Shinya Kitaoka 120a6e
  gl->makeCurrent();
Shinya Kitaoka 120a6e
  gl->clear(TPixel32(0, 0, 0, 0));
Shinya Kitaoka 120a6e
  glEnable(GL_ALPHA_TEST);
Shinya Kitaoka 120a6e
  glAlphaFunc(GL_GREATER, 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPaletteP plt      = palette->clone();
Shinya Kitaoka 120a6e
  int styleId        = stroke->getStyle();
Shinya Kitaoka 120a6e
  TColorStyleP style = plt->getStyle(styleId);
Shinya Kitaoka 120a6e
  TTranslation affine(-convert(rect.getP00()));
Shinya Kitaoka 120a6e
  TVectorRenderData rd(affine, gl->getBounds(), plt.getPointer(), 0, true,
Shinya Kitaoka 120a6e
                       true);
Shinya Kitaoka 120a6e
  if (doAnialias)
Shinya Kitaoka 120a6e
    tglDraw(rd, stroke);
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    TStrokeProp *prop = stroke->getProp();
Shinya Kitaoka 120a6e
    if (prop) prop->getMutex()->lock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (!style->isStrokeStyle() || style->isEnabled() == false) {
Shinya Kitaoka 120a6e
      if (prop) prop->getMutex()->unlock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      prop = 0;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      if (!prop || style.getPointer() != prop->getColorStyle()) {
Shinya Kitaoka 120a6e
        if (prop) prop->getMutex()->unlock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        stroke->setProp(style->makeStrokeProp(stroke));
Shinya Kitaoka 120a6e
        prop = stroke->getProp();
Shinya Kitaoka 120a6e
        if (prop) prop->getMutex()->lock();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (!prop) return;
Shinya Kitaoka 120a6e
    prop->getMutex()->lock();
Shinya Kitaoka 120a6e
    glPushAttrib(GL_ALL_ATTRIB_BITS);
Shinya Kitaoka 120a6e
    prop->draw(rd);
Shinya Kitaoka 120a6e
    glPopAttrib();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glDisable(GL_ALPHA_TEST);
Shinya Kitaoka 120a6e
  glFinish();
tomosu 8d9526
  gl->doneCurrent();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRect fastAddInkStroke(const TRasterImageP &ri, TStroke *stroke, TRectD clip,
Shinya Kitaoka 120a6e
                       double opacity, bool doAntialiasing) {
Shinya Kitaoka 120a6e
  TOfflineGL *gl   = 0;
Shinya Kitaoka 120a6e
  TRectD bbox      = stroke->getBBox();
Shinya Kitaoka 120a6e
  TRect sBBox      = convert(bbox).enlarge(1);
Shinya Kitaoka 120a6e
  TRect rectRender = sBBox * ri->getRaster()->getBounds();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!rectRender.isEmpty()) {
Shinya Kitaoka 120a6e
    if (opacity < 1.0) {
Shinya Kitaoka 120a6e
      int styleId    = stroke->getStyle();
Shinya Kitaoka 120a6e
      TPalette *plt  = ri->getPalette();
Shinya Kitaoka 120a6e
      TPixel32 color = plt->getStyle(styleId)->getMainColor();
Shinya Kitaoka 120a6e
      color.m        = 255 * opacity;
Shinya Kitaoka 120a6e
      TPaletteP newPlt(plt);
Shinya Kitaoka 120a6e
      newPlt->getStyle(styleId)->setMainColor(color);
Shinya Kitaoka 120a6e
      rasterizeWholeStroke(gl, stroke, newPlt.getPointer(), doAntialiasing);
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      rasterizeWholeStroke(gl, stroke, ri->getPalette(), doAntialiasing);
Shinya Kitaoka 120a6e
    TRect tmp        = rectRender - sBBox.getP00();
Shinya Kitaoka 120a6e
    TRaster32P glRas = gl->getRaster()->extract(tmp);
Shinya Kitaoka 120a6e
    TRop::over(ri->getRaster(), glRas, rectRender.getP00());
Shinya Kitaoka 120a6e
    delete gl;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return rectRender;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRect rasterizeRegion(TOfflineGL *&gl, TRect rasBounds, TRegion *region,
Shinya Kitaoka 120a6e
                      TPalette *palette, TRectD clip) {
Shinya Kitaoka 120a6e
  TRectD regionBBox               = region->getBBox();
Shinya Kitaoka 120a6e
  if (!clip.isEmpty()) regionBBox = regionBBox * clip;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRect rect = convert(regionBBox) * rasBounds;
Shinya Kitaoka 120a6e
  if (!rect.isEmpty()) {
Shinya Kitaoka 120a6e
    gl = new TOfflineGL(rect.getSize());
Shinya Kitaoka 120a6e
    gl->makeCurrent();
Shinya Kitaoka 120a6e
    gl->clear(TPixel32::Transparent);
Shinya Kitaoka 120a6e
    glPushAttrib(GL_ALL_ATTRIB_BITS);
Shinya Kitaoka 120a6e
    glEnable(GL_ALPHA_TEST);
Shinya Kitaoka 120a6e
    glAlphaFunc(GL_GREATER, 0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    TTranslation affine(-convert(rect.getP00()));
Shinya Kitaoka 120a6e
    TVectorRenderData rd(affine, gl->getBounds(), palette, 0, true, true);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    tglDraw(rd, region);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    glDisable(GL_ALPHA_TEST);
Shinya Kitaoka 120a6e
    glPopAttrib();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    glFinish();
tomosu 8d9526
    gl->doneCurrent();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return rect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void fastAddPaintRegion(const TRasterImageP &ri, TRegion *region,
Shinya Kitaoka 120a6e
                        int newPaintId, int maxStyleId,
Shinya Kitaoka 120a6e
                        TRectD clip = TRectD()) {
Shinya Kitaoka 120a6e
  TRaster32P ras = ri->getRaster();
Shinya Kitaoka 120a6e
  TOfflineGL *gl;
Shinya Kitaoka 120a6e
  TRect rect =
Shinya Kitaoka 120a6e
      rasterizeRegion(gl, ras->getBounds(), region, ri->getPalette(), clip);
Shinya Kitaoka 120a6e
  if (rect.isEmpty()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRaster32P glRas = gl->getRaster();
Shinya Kitaoka 120a6e
  assert(TPixelCM32::getMaxTone() == 255);
Shinya Kitaoka 120a6e
  TRop::over(ri->getRaster(), glRas, rect.getP00());
Shinya Kitaoka 120a6e
  delete gl;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRegion *subregion;
Shinya Kitaoka 120a6e
  UINT i = 0;
Shinya Kitaoka 120a6e
  for (; i < region->getSubregionCount(); ++i) {
Shinya Kitaoka 120a6e
    subregion = region->getSubregion(i);
Shinya Kitaoka 120a6e
    fastAddPaintRegion(ri, subregion,
Shinya Kitaoka 120a6e
                       std::min(maxStyleId, subregion->getStyle()), maxStyleId);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==========================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRect TRasterImageUtils::addStroke(const TRasterImageP &ri, TStroke *stroke,
Shinya Kitaoka 120a6e
                                   TRectD clip, double opacity,
Shinya Kitaoka 120a6e
                                   bool doAntialiasing) {
Shinya Kitaoka 120a6e
  TStroke *s      = new TStroke(*stroke);
Shinya Kitaoka 120a6e
  TPoint riCenter = ri->getRaster()->getCenter();
Shinya Kitaoka 120a6e
  s->transform(TTranslation(riCenter.x, riCenter.y));
Shinya Kitaoka 120a6e
  TRect rect = fastAddInkStroke(ri, s, clip, opacity, doAntialiasing);
Shinya Kitaoka 120a6e
  rect -= riCenter;
Shinya Kitaoka 120a6e
  delete s;
Shinya Kitaoka 120a6e
  return rect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==========================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRect TRasterImageUtils::convertWorldToRaster(const TRectD &area,
Shinya Kitaoka 120a6e
                                              const TRasterImageP ri) {
Shinya Kitaoka 120a6e
  if (area.isEmpty()) return TRect();
Shinya Kitaoka 120a6e
  if (!ri || !ri->getRaster())
Shinya Kitaoka 120a6e
    return TRect(tfloor(area.x0), tfloor(area.y0), tfloor(area.x1) - 1,
Shinya Kitaoka 120a6e
                 tfloor(area.y1) - 1);
Shinya Kitaoka 120a6e
  TRasterP ras = ri->getRaster();
Shinya Kitaoka 120a6e
  TRectD rect(area + ras->getCenterD());
Shinya Kitaoka 120a6e
  return TRect(tfloor(rect.x0), tfloor(rect.y0), tceil(rect.x1) - 1,
Shinya Kitaoka 120a6e
               tceil(rect.y1) - 1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==========================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRectD TRasterImageUtils::convertRasterToWorld(const TRect &area,
Shinya Kitaoka 120a6e
                                               const TRasterImageP ri) {
Shinya Kitaoka 120a6e
  if (area.isEmpty()) return TRectD();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRectD rect(area.x0, area.y0, area.x1 + 1, area.y1 + 1);
Shinya Kitaoka 120a6e
  if (ri && ri->getRaster()) rect = rect - ri->getRaster()->getCenterD();
Shinya Kitaoka 120a6e
  return rect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==========================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// DA RIFARE
Toshihiro Shimizu 890ddd
// e' lenta da far schifo
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! Converts a TVectorImage into a TRasterImage. The input vector image
Shinya Kitaoka 120a6e
//! is transformed through the passed affine \b aff, and put into a
Shinya Kitaoka 120a6e
//! TRasterImage strictly covering the bounding box of the transformed
Shinya Kitaoka 120a6e
//! vector image. The output image has its lower-left position in the
Shinya Kitaoka 120a6e
//! world reference specified by the \b pos parameter, which is granted to
Shinya Kitaoka 120a6e
//! be an integer displacement of the passed value. Additional parameters
Shinya Kitaoka 120a6e
//! include an integer \b enlarge by which the output image is enlarged with
Shinya Kitaoka 120a6e
//! respect to the transformed image's bbox, and the bool \b transformThickness
Shinya Kitaoka 120a6e
//! to specify whether the transformation should involve strokes' thickensses
Shinya Kitaoka 120a6e
//! or not.
Toshihiro Shimizu 890ddd
TRasterImageP TRasterImageUtils::vectorToFullColorImage(
Shinya Kitaoka 120a6e
    const TVectorImageP &vimage, const TAffine &aff, TPalette *palette,
Shinya Kitaoka 120a6e
    const TPointD &outputPos, const TDimension &outputSize,
Shinya Kitaoka 120a6e
    const std::vector<trasterfxrenderdatap> *fxs, bool transformThickness) {</trasterfxrenderdatap>
Shinya Kitaoka 120a6e
  if (!vimage || !palette) return 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Transform the vector image through aff
Shinya Kitaoka 120a6e
  TVectorImageP vi = vimage->clone();
Shinya Kitaoka 120a6e
  vi->transform(aff, transformThickness);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Allocate the output ToonzImage
Shinya Kitaoka 120a6e
  TRaster32P raster(outputSize.lx, outputSize.ly);
Shinya Kitaoka 120a6e
  raster->clear();
Shinya Kitaoka 120a6e
  TRasterImageP ri(raster);
Shinya Kitaoka 120a6e
  ri->setPalette(palette->clone());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Shift outputPos to the origin
Shinya Kitaoka 120a6e
  vi->transform(TTranslation(-outputPos));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int strokeCount = vi->getStrokeCount();
Shinya Kitaoka 120a6e
  std::vector<int> strokeIndex(strokeCount);</int>
Shinya Kitaoka 120a6e
  std::vector<tstroke *=""> strokes(strokeCount);</tstroke>
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < strokeCount; ++i) {
Shinya Kitaoka 120a6e
    strokeIndex[i] = i;
Shinya Kitaoka 120a6e
    strokes[i]     = vi->getStroke(i);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  vi->notifyChangedStrokes(strokeIndex, strokes);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int maxStyleId = palette->getStyleCount() - 1;
Shinya Kitaoka 120a6e
  for (i = 0; i < (int)vi->getRegionCount(); ++i) {
Shinya Kitaoka 120a6e
    TRegion *region = vi->getRegion(i);
Shinya Kitaoka 120a6e
    fastAddPaintRegion(ri, region, std::min(maxStyleId, region->getStyle()),
Shinya Kitaoka 120a6e
                       maxStyleId);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  set<int> colors;</int>
Shinya Kitaoka 120a6e
  if (fxs) {
Shinya Kitaoka 120a6e
    for (i = 0; i < (int)fxs->size(); i++) {
Shinya Kitaoka 120a6e
      SandorFxRenderData *sandorData =
Shinya Kitaoka 120a6e
          dynamic_cast<sandorfxrenderdata *="">((*fxs)[i].getPointer());</sandorfxrenderdata>
Shinya Kitaoka 120a6e
      if (sandorData && sandorData->m_type == BlendTz) {
Shinya Kitaoka 120a6e
        std::string indexes =
Shinya Kitaoka 120a6e
            ::to_string(sandorData->m_blendParams.m_colorIndex);
Shinya Kitaoka 120a6e
        std::vector<std::string> items;</std::string>
Shinya Kitaoka 120a6e
        parseIndexes(indexes, items);
Shinya Kitaoka 120a6e
        PaletteFilterFxRenderData paletteFilterData;
Shinya Kitaoka 120a6e
        insertIndexes(items, &paletteFilterData);
Shinya Kitaoka 120a6e
        colors = paletteFilterData.m_colors;
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = 0; i < strokeCount; ++i) {
Shinya Kitaoka 120a6e
    TStroke *stroke = vi->getStroke(i);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    bool visible       = false;
Shinya Kitaoka 120a6e
    int styleId        = stroke->getStyle();
Shinya Kitaoka 120a6e
    TColorStyleP style = palette->getStyle(styleId);
Shinya Kitaoka 120a6e
    assert(style);
Shinya Kitaoka 120a6e
    int colorCount = style->getColorParamCount();
Shinya Kitaoka 120a6e
    if (colorCount == 0)
Shinya Kitaoka 120a6e
      visible = true;
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      visible = false;
Shinya Kitaoka 120a6e
      for (int j = 0; j < style->getColorParamCount() && !visible; j++) {
Shinya Kitaoka 120a6e
        TPixel32 color            = style->getColorParamValue(j);
Shinya Kitaoka 120a6e
        if (color.m != 0) visible = true;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (visible) fastAddInkStroke(ri, stroke, TRectD(), 1, true);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return ri;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRect TRasterImageUtils::eraseRect(const TRasterImageP &ri,
Shinya Kitaoka 120a6e
                                   const TRectD &area) {
Shinya Kitaoka 120a6e
  TRasterP ras = ri->getRaster();
Shinya Kitaoka 120a6e
  TRect rect   = convertWorldToRaster(area, ri) * ras->getBounds();
Shinya Kitaoka 120a6e
  if (rect.isEmpty()) return rect;
Shinya Kitaoka 120a6e
  ras->lock();
Shinya Kitaoka 120a6e
  TRasterP workRas = ras->extract(rect);
Shinya Kitaoka 120a6e
  if (workRas->getPixelSize() == 4)
Shinya Kitaoka 120a6e
    workRas->clear();
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    TRasterGR8P rasGR8(workRas);
Shinya Kitaoka 120a6e
    if (rasGR8) rasGR8->fill(TPixelGR8::White);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  ras->unlock();
Shinya Kitaoka 120a6e
  return rect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::vector<trect> TRasterImageUtils::paste(const TRasterImageP &ri,</trect>
Shinya Kitaoka 120a6e
                                            const TTileSetFullColor *tileSet) {
Shinya Kitaoka 120a6e
  std::vector<trect> rects;</trect>
Shinya Kitaoka 120a6e
  TRasterP raster = ri->getRaster();
Shinya Kitaoka 120a6e
  for (int i = 0; i < tileSet->getTileCount(); i++) {
Shinya Kitaoka 120a6e
    const TTileSetFullColor::Tile *tile = tileSet->getTile(i);
Shinya Kitaoka 120a6e
    TRasterP ras;
Shinya Kitaoka 120a6e
    tile->getRaster(ras);
Shinya Kitaoka 120a6e
    assert(ras);
Shinya Kitaoka 120a6e
    raster->copy(ras, tile->m_rasterBounds.getP00());
Shinya Kitaoka 120a6e
    rects.push_back(tile->m_rasterBounds);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return rects;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRasterImageUtils::addSceneNumbering(const TRasterImageP &ri,
Shinya Kitaoka 120a6e
                                          int globalIndex,
Shinya Kitaoka 120a6e
                                          const std::wstring &sceneName,
Shinya Kitaoka 120a6e
                                          int sceneIndex) {
Shinya Kitaoka 120a6e
  if (!ri) return;
Shinya Kitaoka 120a6e
  TRasterP raster = ri->getRaster();
Shinya Kitaoka 120a6e
  int lx = raster->getLx(), ly = raster->getLy();
Shinya Kitaoka 120a6e
  QColor greyOverlay(100, 100, 100, 140);
Shinya Kitaoka 120a6e
  QImage image = rasterToQImage(raster, true, false);
Shinya Kitaoka 120a6e
  QPainter p(&image);
Shinya Kitaoka 120a6e
  QFont numberingFont = QFont();
Shinya Kitaoka 120a6e
  numberingFont.setPixelSize(ly * 0.04);
Shinya Kitaoka 120a6e
  numberingFont.setBold(true);
Shinya Kitaoka 120a6e
  p.setFont(numberingFont);
Shinya Kitaoka 120a6e
  QMatrix matrix;
Shinya Kitaoka 120a6e
  p.setMatrix(matrix.translate(0, ly).scale(1, -1), true);
Shinya Kitaoka 120a6e
  QFontMetrics fm = p.fontMetrics();
Shinya Kitaoka 120a6e
  int fontHeight  = fm.height();
Shinya Kitaoka 120a6e
  int offset      = fontHeight * 0.2;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // write the scenename and the scene frame
Shinya Kitaoka 120a6e
  QString sceneFrame = QString::number(sceneIndex);
Shinya Kitaoka 120a6e
  while (sceneFrame.size() < 4) sceneFrame.push_front("0");
Shinya Kitaoka 120a6e
  QString sceneNumberingString =
Shinya Kitaoka 120a6e
      QString::fromStdWString(sceneName) + ": " + sceneFrame;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int sceneNumberingWidth = fm.width(sceneNumberingString);
Shinya Kitaoka 120a6e
  p.setPen(Qt::NoPen);
Shinya Kitaoka 120a6e
  p.setBrush(QColor(255, 255, 255, 255));
Shinya Kitaoka 120a6e
  p.drawRect(offset, ly - offset - fontHeight, sceneNumberingWidth + offset * 2,
Shinya Kitaoka 120a6e
             fontHeight);
Shinya Kitaoka 120a6e
  p.setBrush(greyOverlay);
Shinya Kitaoka 120a6e
  p.drawRect(offset, ly - offset - fontHeight, sceneNumberingWidth + offset * 2,
Shinya Kitaoka 120a6e
             fontHeight);
Shinya Kitaoka 120a6e
  p.setPen(Qt::white);
Shinya Kitaoka 120a6e
  p.drawText(2 * offset, ly - 2 * offset, sceneNumberingString);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // write the global frame
Shinya Kitaoka 120a6e
  QString globalFrame = QString::number(globalIndex);
Shinya Kitaoka 120a6e
  while (globalFrame.size() < 4) globalFrame.push_front("0");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int gloablNumberingWidth = fm.width(globalFrame);
Shinya Kitaoka 120a6e
  p.setPen(Qt::NoPen);
Shinya Kitaoka 120a6e
  p.setBrush(QColor(255, 255, 255, 255));
Shinya Kitaoka 120a6e
  p.drawRect(lx - 3 * offset - gloablNumberingWidth, ly - offset - fontHeight,
Shinya Kitaoka 120a6e
             gloablNumberingWidth + offset * 2, fontHeight);
Shinya Kitaoka 120a6e
  p.setBrush(greyOverlay);
Shinya Kitaoka 120a6e
  p.drawRect(lx - 3 * offset - gloablNumberingWidth, ly - offset - fontHeight,
Shinya Kitaoka 120a6e
             gloablNumberingWidth + offset * 2, fontHeight);
Shinya Kitaoka 120a6e
  p.setPen(Qt::white);
Shinya Kitaoka 120a6e
  p.drawText(lx - 2 * offset - gloablNumberingWidth, ly - 2 * offset,
Shinya Kitaoka 120a6e
             globalFrame);
Shinya Kitaoka 120a6e
  p.end();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRasterImageUtils::addGlobalNumbering(const TRasterImageP &ri,
Shinya Kitaoka 120a6e
                                           const std::wstring &sceneName,
Shinya Kitaoka 120a6e
                                           int globalIndex) {
Shinya Kitaoka 120a6e
  if (!ri) return;
Shinya Kitaoka 120a6e
  TRasterP raster = ri->getRaster();
Shinya Kitaoka 120a6e
  int lx = raster->getLx(), ly = raster->getLy();
Shinya Kitaoka 120a6e
  QColor greyOverlay(100, 100, 100, 140);
Shinya Kitaoka 120a6e
  QImage image = rasterToQImage(raster, true, false);
Shinya Kitaoka 120a6e
  QPainter p(&image);
Shinya Kitaoka 120a6e
  QFont numberingFont = QFont();
Shinya Kitaoka 120a6e
  numberingFont.setPixelSize(ly * 0.04);
Shinya Kitaoka 120a6e
  numberingFont.setBold(true);
Shinya Kitaoka 120a6e
  p.setFont(numberingFont);
Shinya Kitaoka 120a6e
  QMatrix matrix;
Shinya Kitaoka 120a6e
  p.setMatrix(matrix.translate(0, ly).scale(1, -1), true);
Shinya Kitaoka 120a6e
  QFontMetrics fm     = p.fontMetrics();
Shinya Kitaoka 120a6e
  int fontHeight      = fm.height();
Shinya Kitaoka 120a6e
  int offset          = fontHeight * 0.2;
Shinya Kitaoka 120a6e
  QString globalFrame = QString::number(globalIndex);
Shinya Kitaoka 120a6e
  while (globalFrame.size() < 4) globalFrame.push_front("0");
Shinya Kitaoka 120a6e
  QString globalNumberingString =
Shinya Kitaoka 120a6e
      QString::fromStdWString(sceneName) + ": " + globalFrame;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int globalNumberingWidth = fm.width(globalNumberingString);
Shinya Kitaoka 120a6e
  p.setPen(Qt::NoPen);
Shinya Kitaoka 120a6e
  p.setBrush(QColor(255, 255, 255, 255));
Shinya Kitaoka 120a6e
  p.drawRect(offset, ly - offset - fontHeight,
Shinya Kitaoka 120a6e
             globalNumberingWidth + offset * 2, fontHeight);
Shinya Kitaoka 120a6e
  p.setBrush(greyOverlay);
Shinya Kitaoka 120a6e
  p.drawRect(offset, ly - offset - fontHeight,
Shinya Kitaoka 120a6e
             globalNumberingWidth + offset * 2, fontHeight);
Shinya Kitaoka 120a6e
  p.setPen(Qt::white);
Shinya Kitaoka 120a6e
  p.drawText(2 * offset, ly - 2 * offset, globalNumberingString);
Shinya Kitaoka 120a6e
  p.end();
Toshihiro Shimizu 890ddd
}