Martin van Zijl 708c58
// Glew include
Martin van Zijl 708c58
#include <gl glew.h=""></gl>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/imagepainter.h"
Toshihiro Shimizu 890ddd
#include "toonz/glrasterpainter.h"
Toshihiro Shimizu 890ddd
#include "trastercm.h"
Toshihiro Shimizu 890ddd
#include "tropcm.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
#include "tgl.h"
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tvectorrenderdata.h"
Toshihiro Shimizu 890ddd
#include "tvectorgl.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "timagecache.h"
Toshihiro Shimizu 890ddd
#include "toonz/sceneproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage2.h"
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
#include "toonz/fill.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace ImagePainter;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TEnv::IntVar FlipBookWhiteBgToggle("FlipBookWhiteBgToggle", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar FlipBookBlackBgToggle("FlipBookBlackBgToggle", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar FlipBookCheckBgToggle("FlipBookCheckBgToggle", 0);
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 481b59
TRasterP keepChannels(const TRasterP &rin, TPalette *palette, UCHAR channel) {
shun-iwasawa 481b59
  TRasterP rout;
shun-iwasawa 481b59
  if ((TRasterFP)rin) {
shun-iwasawa 481b59
    rout = rin->clone();
shun-iwasawa 481b59
shun-iwasawa 481b59
    TPixelF *pix = (TPixelF *)rout->getRawData();
shun-iwasawa 481b59
shun-iwasawa 481b59
    assert(channel & TRop::MChan);
shun-iwasawa 481b59
    int i;
shun-iwasawa 481b59
    for (i = 0; i < rout->getLx() * rout->getLy(); i++, pix++) {
shun-iwasawa 481b59
      if (!(channel & TRop::RChan)) pix->r = 0.f;
shun-iwasawa 481b59
      if (!(channel & TRop::GChan)) pix->g = 0.f;
shun-iwasawa 481b59
      if (!(channel & TRop::BChan)) pix->b = 0.f;
shun-iwasawa 481b59
    }
shun-iwasawa 481b59
  } else {
shun-iwasawa 481b59
    rout = TRaster32P(rin->getSize());
Shinya Kitaoka 120a6e
shun-iwasawa 481b59
    if ((TRasterCM32P)rin)
shun-iwasawa 481b59
      TRop::convert(rout, (TRasterCM32P)rin, TPaletteP(palette));
shun-iwasawa 481b59
    else
shun-iwasawa 481b59
      TRop::copy(rout, rin);
Shinya Kitaoka 120a6e
shun-iwasawa 481b59
    TPixel32 *pix = (TPixel32 *)rout->getRawData();
Shinya Kitaoka 120a6e
shun-iwasawa 481b59
    assert(channel & TRop::MChan);
shun-iwasawa 481b59
    int i;
Shinya Kitaoka 120a6e
shun-iwasawa 481b59
    for (i = 0; i < rout->getLx() * rout->getLy(); i++, pix++) {
shun-iwasawa 481b59
      if (!(channel & TRop::RChan)) pix->r = 0;
shun-iwasawa 481b59
      if (!(channel & TRop::GChan)) pix->g = 0;
shun-iwasawa 481b59
      if (!(channel & TRop::BChan)) pix->b = 0;
shun-iwasawa 481b59
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return rout;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline void quickput(const TRasterP &rout, const TRasterP &rin,
Shinya Kitaoka 120a6e
                     const TPaletteP &palette, const TAffine &aff,
Shinya Kitaoka 120a6e
                     bool useChecks) {
Shinya Kitaoka 120a6e
  if (TRasterCM32P srcCM32 = rin) {
Shinya Kitaoka 120a6e
    if (useChecks) {
Shinya Kitaoka 120a6e
      bool inksOnly       = false;
Shinya Kitaoka 120a6e
      TPixel32 colorscale = TPixel32(0, 0, 0, 255);
Shinya Kitaoka 120a6e
      int tc              = ToonzCheck::instance()->getChecks();
Shinya Kitaoka 120a6e
      int index           = ToonzCheck::instance()->getColorIndex();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (tc & ToonzCheck::eGap) {
Shinya Kitaoka 120a6e
        srcCM32 = srcCM32->clone();
Shinya Kitaoka 120a6e
        AreaFiller(srcCM32).rectFill(srcCM32->getBounds(), 1, true, true,
Shinya Kitaoka 120a6e
                                     false);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (tc == 0 || tc == ToonzCheck::eBlackBg)
Shinya Kitaoka 120a6e
        TRop::quickPut(rout, srcCM32, palette, aff, colorscale, inksOnly);
Shinya Kitaoka 120a6e
      else {
Shinya Kitaoka 120a6e
        TRop::CmappedQuickputSettings settings;
Shinya Kitaoka 120a6e
        settings.m_globalColorScale = colorscale;
Shinya Kitaoka 120a6e
        settings.m_inksOnly         = inksOnly;
Shinya Kitaoka 120a6e
        settings.m_transparencyCheck =
Shinya Kitaoka 120a6e
            tc & (ToonzCheck::eTransparency | ToonzCheck::eGap);
Shinya Kitaoka 120a6e
        settings.m_blackBgCheck = tc & ToonzCheck::eBlackBg;
Shinya Kitaoka 120a6e
        settings.m_inkIndex =
Shinya Kitaoka 120a6e
            tc & ToonzCheck::eInk ? index : (tc & ToonzCheck::eInk1 ? 1 : -1);
Shinya Kitaoka 120a6e
        settings.m_paintIndex = tc & ToonzCheck::ePaint ? index : -1;
Shinya Kitaoka 120a6e
        Preferences::instance()->getTranspCheckData(
Shinya Kitaoka 120a6e
            settings.m_transpCheckBg, settings.m_transpCheckInk,
Shinya Kitaoka 120a6e
            settings.m_transpCheckPaint);
Shinya Kitaoka 120a6e
        TRop::quickPut(rout, srcCM32, palette, aff, settings);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      srcCM32 = TRasterCM32P();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      TRop::quickPut(rout, rin, palette, aff);
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    TRop::quickPut(rout, rin, aff);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPixel32 *getBuffer(const TRect &rect) {
Shinya Kitaoka 120a6e
  static std::vector<char> buffer;</char>
Shinya Kitaoka 120a6e
  int size = rect.getLx() * rect.getLy() * 4;
Shinya Kitaoka 120a6e
  if (size > (int)buffer.size()) buffer.resize(size);
Shinya Kitaoka 120a6e
  return (TPixel32 *)&buffer[0];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRaster32P getCheckBoard(const TRect &rect, const TAffine &aff,
Shinya Kitaoka 120a6e
                         TSceneProperties *sprop) {
Shinya Kitaoka 120a6e
  double scale = sqrt(fabs(aff.det()));
Shinya Kitaoka 120a6e
  TPixel32 col1, col2;
Shinya Kitaoka 120a6e
  Preferences::instance()->getChessboardColors(col1, col2);
Shinya Kitaoka 120a6e
  TRaster32P ras(rect.getLx(), rect.getLy(), rect.getLx(), getBuffer(rect));
Shinya Kitaoka 120a6e
  TRop::checkBoard(ras, col1, col2, TDimensionD(50 * scale, 50 * scale),
Shinya Kitaoka 120a6e
                   TPointD(-aff.a13, -aff.a23));
Shinya Kitaoka 120a6e
  return ras;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void drawCompareLines(const TDimension &dim, double compareX, double compareY) {
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
  glLoadIdentity();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glColor3d(0.0, 0.0, 0.0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glBegin(GL_LINES);
Shinya Kitaoka 120a6e
  glVertex2d(dim.lx * compareX - 1, 0);
Shinya Kitaoka 120a6e
  glVertex2d(dim.lx * compareX - 1, dim.ly - 1);
Shinya Kitaoka 120a6e
  glVertex2d(dim.lx * compareX + 1, 0);
Shinya Kitaoka 120a6e
  glVertex2d(dim.lx * compareX + 1, dim.ly - 1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glVertex2d(0, dim.ly * compareY - 1);
Shinya Kitaoka 120a6e
  glVertex2d(dim.lx - 1, dim.ly * compareY - 1);
Shinya Kitaoka 120a6e
  glVertex2d(0, dim.ly * compareY + 1);
Shinya Kitaoka 120a6e
  glVertex2d(dim.lx - 1, dim.ly * compareY + 1);
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  glColor3d(1.0, 0.0, 0.0);
Shinya Kitaoka 120a6e
  glBegin(GL_LINES);
Shinya Kitaoka 120a6e
  glVertex2d(dim.lx * compareX, 0);
Shinya Kitaoka 120a6e
  glVertex2d(dim.lx * compareX, dim.ly - 1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glVertex2d(0, dim.ly * compareY);
Shinya Kitaoka 120a6e
  glVertex2d(dim.lx - 1, dim.ly * compareY);
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  glPopMatrix();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class Painter {
Shinya Kitaoka 120a6e
  TDimension m_dim;
Shinya Kitaoka 120a6e
  TDimension m_imageSize;
Shinya Kitaoka 120a6e
  TAffine m_aff;
Shinya Kitaoka 120a6e
  TAffine m_finalAff;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPalette *m_palette;
Shinya Kitaoka 120a6e
  TRectD m_bbox;
Shinya Kitaoka 120a6e
  TRasterP m_raster;
Shinya Kitaoka 120a6e
  bool m_useTexture;
Shinya Kitaoka 120a6e
  bool m_drawExternalBG;
Shinya Kitaoka 120a6e
  VisualSettings m_vSettings;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Painter(const TDimension &dim, const TDimension &imageSize,
Shinya Kitaoka 120a6e
          const TAffine &viewAff, TPalette *palette,
Shinya Kitaoka 120a6e
          const VisualSettings &visualSettings);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void flushRasterImages(const TRect &loadbox, double compareX, double compareY,
Shinya Kitaoka 120a6e
                         bool swapCompared);
Shinya Kitaoka 120a6e
  void doFlushRasterImages(const TRasterP &rin, int bg,
Shinya Kitaoka 120a6e
                           const TPointD &offs = TPointD());
Shinya Kitaoka 120a6e
  void onVectorImage(TVectorImage *vi);
Shinya Kitaoka 120a6e
  void onRasterImage(TRasterImage *ri);
Shinya Kitaoka 120a6e
  void onToonzImage(TToonzImage *ti);
Shinya Kitaoka 120a6e
  void drawBlank();
shun-iwasawa 481b59
  TRasterP buildCheckboard(int bg, const TDimension &dim,
shun-iwasawa 481b59
                           TRasterP templateRas = TRaster32P());
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Painter::Painter(const TDimension &dim, const TDimension &imageSize,
Shinya Kitaoka 120a6e
                 const TAffine &viewAff, TPalette *palette,
Shinya Kitaoka 120a6e
                 const VisualSettings &visualSettings)
Shinya Kitaoka 120a6e
    : m_dim(dim)
Shinya Kitaoka 120a6e
    , m_imageSize(imageSize)
Shinya Kitaoka 120a6e
    , m_aff(viewAff)
Shinya Kitaoka 120a6e
    , m_palette(palette)
Shinya Kitaoka 120a6e
    , m_bbox()
Shinya Kitaoka 120a6e
    , m_raster()
Shinya Kitaoka 120a6e
    , m_vSettings(visualSettings)
Toshihiro Shimizu 890ddd
//, m_channel(visualSettings.m_colorMask)
Toshihiro Shimizu 890ddd
//, m_greytones(visualSettings.m_greytones)
Toshihiro Shimizu 890ddd
//, m_sceneProperties(visualSettings.m_sceneProperties)
Toshihiro Shimizu 890ddd
//, m_useTexture(visualSettings.m_useTexture)
Toshihiro Shimizu 890ddd
//, m_drawExternalBG(visualSettings.m_drawExternalBG)
Shinya Kitaoka 120a6e
{}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Painter::flushRasterImages(const TRect &loadbox, double compareX,
Shinya Kitaoka 120a6e
                                double compareY, bool swapCompare) {
Shinya Kitaoka 120a6e
  if (!m_raster) return;
Shinya Kitaoka 120a6e
  glDisable(GL_DEPTH_TEST);
Shinya Kitaoka 120a6e
  glDisable(GL_DITHER);
Shinya Kitaoka 120a6e
  glDisable(GL_LOGIC_OP);
Shinya Kitaoka 120a6e
  glDisable(GL_STENCIL_TEST);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef GL_EXT_convolution
shun-iwasawa 215a5b
  if (GLEW_EXT_convolution) {
Martin van Zijl 708c58
    glDisable(GL_CONVOLUTION_1D_EXT);
Martin van Zijl 708c58
    glDisable(GL_CONVOLUTION_2D_EXT);
Martin van Zijl 708c58
    glDisable(GL_SEPARABLE_2D_EXT);
Martin van Zijl 708c58
  }
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef GL_EXT_histogram
shun-iwasawa 215a5b
  if (GLEW_EXT_histogram) {
Martin van Zijl 708c58
    glDisable(GL_HISTOGRAM_EXT);
Martin van Zijl 708c58
    glDisable(GL_MINMAX_EXT);
Martin van Zijl 708c58
  }
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef GL_EXT_texture3D
shun-iwasawa 215a5b
  if (GL_EXT_texture3D) {
Martin van Zijl 708c58
    glDisable(GL_TEXTURE_3D_EXT);
Martin van Zijl 708c58
  }
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  UCHAR m = m_vSettings.m_colorMask;
Shinya Kitaoka 120a6e
  bool showBg =
Shinya Kitaoka 120a6e
      (m == 0 || (m & TRop::MChan && !m_vSettings.m_greytones &&
Shinya Kitaoka 120a6e
                  (m & TRop::RChan || m & TRop::GChan || m & TRop::BChan)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int bg = showBg ? m_vSettings.m_bg : 0x40000;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_vSettings.m_drawExternalBG) {
Shinya Kitaoka 120a6e
    if (m_vSettings.m_colorMask != 0) {
Shinya Kitaoka 120a6e
      glClearColor(0, 0, 0, 1.0);
Shinya Kitaoka 120a6e
      glClear(GL_COLOR_BUFFER_BIT);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      TPixel bgColor = Preferences::instance()->getPreviewBgColor();
Shinya Kitaoka 120a6e
      glClearColor(bgColor.r / 255.0f, bgColor.g / 255.0f, bgColor.b / 255.0f,
Shinya Kitaoka 120a6e
                   1.0);
Shinya Kitaoka 120a6e
      glClear(GL_COLOR_BUFFER_BIT);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  UCHAR chan = m_vSettings.m_colorMask;
Shinya Kitaoka 120a6e
  if (chan != 0 && !(chan & TRop::MChan) &&
Shinya Kitaoka 120a6e
      !(chan != TRop::MChan && chan & TRop::MChan) && !m_vSettings.m_greytones)
Shinya Kitaoka 120a6e
    glColorMask((chan & TRop::RChan) ? GL_TRUE : GL_FALSE,
Shinya Kitaoka 120a6e
                (chan & TRop::GChan) ? GL_TRUE : GL_FALSE,
Shinya Kitaoka 120a6e
                (chan & TRop::BChan) ? GL_TRUE : GL_FALSE, GL_TRUE);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (compareX != DefaultCompareValue || compareY != DefaultCompareValue) {
Shinya Kitaoka 120a6e
    glEnable(GL_SCISSOR_TEST);
Shinya Kitaoka 120a6e
    // draw right/down part of the screen...
Shinya Kitaoka 120a6e
    if (swapCompare)
Shinya Kitaoka 120a6e
      glScissor(0, 0,
Shinya Kitaoka 120a6e
                m_dim.lx * (compareX == DefaultCompareValue ? 1 : compareX),
Shinya Kitaoka 120a6e
                m_dim.ly * (compareY == DefaultCompareValue ? 1 : compareY));
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      glScissor(m_dim.lx * (compareX == DefaultCompareValue ? 0 : compareX),
Shinya Kitaoka 120a6e
                m_dim.ly * (compareY == DefaultCompareValue ? 0 : compareY),
Shinya Kitaoka 120a6e
                m_dim.lx, m_dim.ly);
Shinya Kitaoka 120a6e
    doFlushRasterImages(m_raster, bg, convert(loadbox.getP00()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TImageP refimg =
Shinya Kitaoka 120a6e
        TImageCache::instance()->get(QString("TnzCompareImg"), false);
Shinya Kitaoka 120a6e
    if ((TToonzImageP)refimg || (TRasterImageP)refimg) {
Shinya Kitaoka 120a6e
      // draw left/up part of the screen...
Shinya Kitaoka 120a6e
      TRasterP raux, rref;
shun-iwasawa 9da5bf
      if ((TToonzImageP)refimg) {
shun-iwasawa 9da5bf
        rref      = ((TToonzImageP)refimg)->getCMapped();
shun-iwasawa 9da5bf
        m_palette = refimg->getPalette();
shun-iwasawa 9da5bf
      } else
Shinya Kitaoka 120a6e
        rref = ((TRasterImageP)refimg)->getRaster();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      TRect rect = loadbox;
Shinya Kitaoka 120a6e
      raux       = loadbox != TRect() ? rref->extract(rect) : rref;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      TPointD cmpOffs = TPointD(
Shinya Kitaoka 120a6e
          0.5 * (((m_imageSize.lx == 0) ? m_raster->getLx() : m_imageSize.lx) -
Shinya Kitaoka 120a6e
                 rref->getLx()),
Shinya Kitaoka 120a6e
          0.5 * (((m_imageSize.ly == 0) ? m_raster->getLy() : m_imageSize.ly) -
Shinya Kitaoka 120a6e
                 rref->getLy()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (swapCompare)
Shinya Kitaoka 120a6e
        glScissor(m_dim.lx * (compareX == DefaultCompareValue ? 0 : compareX),
Shinya Kitaoka 120a6e
                  m_dim.ly * (compareY == DefaultCompareValue ? 0 : compareY),
Shinya Kitaoka 120a6e
                  m_dim.lx, m_dim.ly);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        glScissor(0, 0,
Shinya Kitaoka 120a6e
                  m_dim.lx * (compareX == DefaultCompareValue ? 1 : compareX),
Shinya Kitaoka 120a6e
                  m_dim.ly * (compareY == DefaultCompareValue ? 1 : compareY));
Shinya Kitaoka 120a6e
      doFlushRasterImages(raux, bg, cmpOffs + convert(loadbox.getP00()));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    glDisable(GL_SCISSOR_TEST);
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    doFlushRasterImages(m_raster, bg, convert(loadbox.getP00()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_raster  = TRasterP();
Shinya Kitaoka 120a6e
  m_palette = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 481b59
TRasterP Painter::buildCheckboard(int bg, const TDimension &dim,
shun-iwasawa 481b59
                                  TRasterP templateRas) {
shun-iwasawa 481b59
  TRaster32P ras32(templateRas);
shun-iwasawa 481b59
  TRaster64P ras64(templateRas);
shun-iwasawa 481b59
  TRasterFP rasF(templateRas);
shun-iwasawa 481b59
  templateRas = 0;
shun-iwasawa 481b59
  TRasterP checkBoard;
shun-iwasawa 481b59
  if (ras32)
shun-iwasawa 481b59
    checkBoard = TRaster32P(100, 100);
shun-iwasawa 481b59
  else if (ras64)
shun-iwasawa 481b59
    checkBoard = TRaster64P(100, 100);
shun-iwasawa 481b59
  else if (rasF)
shun-iwasawa 481b59
    checkBoard = TRasterFP(100, 100);
shun-iwasawa 481b59
shun-iwasawa 481b59
  TPixel col1, col2;
shun-iwasawa 481b59
  Preferences::instance()->getChessboardColors(col1, col2);
shun-iwasawa 481b59
  TPointD p = TPointD(0, 0);
shun-iwasawa 481b59
  if (m_vSettings.m_useTexture)
shun-iwasawa 481b59
    p = TPointD(m_bbox.x0 > 0 ? 0 : -m_bbox.x0, m_bbox.y0 > 0 ? 0 : -m_bbox.y0);
Shinya Kitaoka 120a6e
shun-iwasawa 481b59
  assert(checkBoard.getPointer());
shun-iwasawa 481b59
  TRop::checkBoard(checkBoard, col1, col2, TDimensionD(50, 50), p);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(checkBoard.getPointer());
Shinya Kitaoka 120a6e
  int lx = (m_imageSize.lx == 0 ? dim.lx : m_imageSize.lx);
Shinya Kitaoka 120a6e
  int ly = (m_imageSize.ly == 0 ? dim.ly : m_imageSize.ly);
Shinya Kitaoka 120a6e
  int x, y;
Shinya Kitaoka 120a6e
shun-iwasawa 481b59
  TRasterP checkBoardRas;
shun-iwasawa 481b59
shun-iwasawa 481b59
  if (ras32)
shun-iwasawa 481b59
    checkBoardRas = TRaster32P(lx, ly);
shun-iwasawa 481b59
  else if (ras64)
shun-iwasawa 481b59
    checkBoardRas = TRaster64P(lx, ly);
shun-iwasawa 481b59
  else if (rasF)
shun-iwasawa 481b59
    checkBoardRas = TRasterFP(lx, ly);
shun-iwasawa 481b59
Shinya Kitaoka 120a6e
  for (y = 0; y < ly; y += 100) {
Shinya Kitaoka 120a6e
    for (x = 0; x < lx; x += 100) {
Shinya Kitaoka 120a6e
      // TAffine checkTrans = TTranslation(x,y);
Shinya Kitaoka 120a6e
      // if(m_vSettings.m_useTexture)
Shinya Kitaoka 120a6e
      //  quickput(textureBackGround, checkBoard, m_palette, checkTrans);
Shinya Kitaoka 120a6e
      // else
Shinya Kitaoka 120a6e
      quickput(checkBoardRas, checkBoard, m_palette, TTranslation(x, y), false);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return checkBoardRas;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Painter::doFlushRasterImages(const TRasterP &rin, int bg,
Shinya Kitaoka 120a6e
                                  const TPointD &offs) {
Shinya Kitaoka 120a6e
  if (!rin) return;
Shinya Kitaoka 120a6e
  TRectD viewRect(0.0, 0.0, m_dim.lx - 1, m_dim.ly - 1);
Shinya Kitaoka 120a6e
  TRectD bbox;
Shinya Kitaoka 120a6e
  if (m_vSettings.m_useTexture)
Shinya Kitaoka 120a6e
    bbox = m_bbox;
Shinya Kitaoka 120a6e
  else {
shun-iwasawa fe0983
    // double delta = sqrt(fabs(m_finalAff.det()));
shun-iwasawa fe0983
    // bbox = m_bbox.enlarge(delta) * viewRect;
shun-iwasawa fe0983
    bbox = m_bbox * viewRect;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  UCHAR chan = m_vSettings.m_colorMask;
Shinya Kitaoka 120a6e
  TRect rect(tfloor(bbox.x0), tfloor(bbox.y0), tceil(bbox.x1), tceil(bbox.y1));
Shinya Kitaoka 120a6e
  if (rect.isEmpty()) return;
Shinya Kitaoka 120a6e
shun-iwasawa 215a5b
  TRasterP ras;
shun-iwasawa 215a5b
  // TRaster32P ras;
Shinya Kitaoka 120a6e
  TRasterP _rin = rin;
Shinya Kitaoka 120a6e
  TAffine aff;
shun-iwasawa 481b59
  GLenum bpcType = TGL_TYPE;
shun-iwasawa 481b59
  // is16bpc = false;
Shinya Kitaoka 120a6e
  if (m_vSettings.m_useTexture) {
Shinya Kitaoka 120a6e
    ras = _rin;
Shinya Kitaoka 120a6e
    aff = m_aff;
Shinya Kitaoka 120a6e
    // ras->clear();
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    int lx = rect.getLx(), ly = rect.getLy();
shun-iwasawa fe0983
    // when the "30bit display" preference option is enabled,
shun-iwasawa fe0983
    // image previewed in 16bpc is not dithered & converted to 8bpc,
shun-iwasawa fe0983
    // but is kept the channel depth as 16bpc.
shun-iwasawa fe0983
    if (_rin->getPixelSize() == 8) {
shun-iwasawa fe0983
      ras     = TRaster64P(lx, ly);
shun-iwasawa 481b59
      bpcType = TGL_TYPE16;
shun-iwasawa 481b59
    } else if (_rin->getPixelSize() == 16) {
shun-iwasawa 481b59
      ras     = TRasterFP(lx, ly);
shun-iwasawa 481b59
      bpcType = TGL_TYPE32F;
shun-iwasawa fe0983
    } else
shun-iwasawa fe0983
      ras = TRaster32P(lx, ly);
Shinya Kitaoka 120a6e
shun-iwasawa fe0983
    /*
Shinya Kitaoka 120a6e
    // Following lines are used to solve a problem that occurs with some
Shinya Kitaoka 120a6e
    // graphics cards!
MCCCS a0ce32
    // It seems that the glReadPixels() function is very slow if the lx length
Shinya Kitaoka 120a6e
    // isn't a multiple of 8!
Shinya Kitaoka 120a6e
    TDimension backgroundDim(lx, ly);
Shinya Kitaoka 120a6e
    backgroundDim.lx = (lx & 0x7) == 0 ? lx : lx + 8 - (lx & 0x7);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    static std::vector<char> buffer;</char>
Shinya Kitaoka 120a6e
    int size = backgroundDim.lx * backgroundDim.ly * 4;
Shinya Kitaoka 120a6e
    if (size > (int)buffer.size()) buffer.resize(size);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TRaster32P backgroundRas(backgroundDim.lx, backgroundDim.ly,
Shinya Kitaoka 120a6e
                             backgroundDim.lx, (TPixel32 *)&buffer[0]);
Shinya Kitaoka 120a6e
    glReadPixels(rect.x0, rect.y0, backgroundDim.lx, backgroundDim.ly, TGL_FMT,
Shinya Kitaoka 120a6e
                 TGL_TYPE, backgroundRas->getRawData());
Shinya Kitaoka 120a6e
    TRect r = rect - rect.getP00();
Shinya Kitaoka 120a6e
    ras     = backgroundRas->extract(r);
shun-iwasawa fe0983
    */
Shinya Kitaoka 120a6e
    aff = TTranslation(-rect.x0, -rect.y0) * m_finalAff;
Shinya Kitaoka 120a6e
    aff *= TTranslation(TPointD(0.5, 0.5));  // very quick and very dirty fix:
Shinya Kitaoka 120a6e
                                             // in camerastand the images seems
Shinya Kitaoka 120a6e
                                             // shifted of an half pixel...it's
Shinya Kitaoka 120a6e
                                             // a quickput approximation?
shun-iwasawa fe0983
    if (bg == 0x100000)
shun-iwasawa 481b59
      quickput(ras, buildCheckboard(bg, _rin->getSize(), ras), m_palette, aff,
shun-iwasawa fe0983
               false);
shun-iwasawa fe0983
    else {
shun-iwasawa 481b59
      if (bpcType == TGL_TYPE16)
shun-iwasawa fe0983
        ((TRaster64P)ras)
shun-iwasawa fe0983
            ->fill(bg == 0x40000 ? TPixel64::Black : TPixel64::White);
shun-iwasawa 481b59
      else if (bpcType == TGL_TYPE32F)
shun-iwasawa 481b59
        ((TRasterFP)ras)->fill(bg == 0x40000 ? TPixelF::Black : TPixelF::White);
shun-iwasawa fe0983
      else
shun-iwasawa fe0983
        ((TRaster32P)ras)->fill(bg == 0x40000 ? TPixel::Black : TPixel::White);
shun-iwasawa fe0983
    }
shun-iwasawa 215a5b
  }
shun-iwasawa 215a5b
Shinya Kitaoka 120a6e
  ras->lock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool showChannelsOnMatte =
Shinya Kitaoka 120a6e
      (chan != TRop::MChan && chan != 0 && !m_vSettings.m_greytones);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_vSettings.m_useTexture) {
Shinya Kitaoka 120a6e
    TRaster32P checkBoardRas = buildCheckboard(bg, _rin->getSize());
Shinya Kitaoka 120a6e
    GLRasterPainter::drawRaster(aff, checkBoardRas->getRawData(),
Shinya Kitaoka 120a6e
                                checkBoardRas->getWrap(), 4,
Shinya Kitaoka 120a6e
                                checkBoardRas->getSize(), true);
shun-iwasawa de71c0
    if (showChannelsOnMatte)
shun-iwasawa de71c0
      ras = keepChannels(_rin, m_palette, chan);
shun-iwasawa de71c0
    else if (chan == TRop::MChan || m_vSettings.m_greytones) {
shun-iwasawa de71c0
      TRasterP app = ras->create(ras->getLx(), ras->getLy());
shun-iwasawa de71c0
      try {
shun-iwasawa de71c0
        TRop::setChannel(ras, app, chan, m_vSettings.m_greytones);
shun-iwasawa de71c0
        ras = app;
shun-iwasawa de71c0
      } catch (...) {
shun-iwasawa de71c0
      }
shun-iwasawa de71c0
    }
Shinya Kitaoka 120a6e
    GLRasterPainter::drawRaster(aff, ras->getRawData(), ras->getWrap(), 4,
Shinya Kitaoka 120a6e
                                ras->getSize(), true);
Shinya Kitaoka 120a6e
    ras->unlock();
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    if (showChannelsOnMatte)
Shinya Kitaoka 120a6e
      quickput(ras, keepChannels(_rin, m_palette, chan), m_palette,
Shinya Kitaoka 120a6e
               m_vSettings.m_useTexture ? TAffine() : aff * TTranslation(offs),
Shinya Kitaoka 120a6e
               m_vSettings.m_useChecks);
shun-iwasawa de71c0
    else if (chan != 0) {
shun-iwasawa de71c0
      TRasterP app = ras->create(_rin->getLx(), _rin->getLy());
shun-iwasawa de71c0
      quickput(app, _rin, m_palette, TAffine(), m_vSettings.m_useChecks);
shun-iwasawa de71c0
      try {
shun-iwasawa de71c0
        TRop::setChannel(app, app, chan, m_vSettings.m_greytones);
shun-iwasawa de71c0
      } catch (...) {
shun-iwasawa de71c0
      }
shun-iwasawa de71c0
      quickput(ras, app, m_palette, aff * TTranslation(offs),
shun-iwasawa de71c0
               m_vSettings.m_useChecks);
shun-iwasawa de71c0
    } else {
Shinya Kitaoka 120a6e
      quickput(ras, _rin, m_palette, aff * TTranslation(offs),
Shinya Kitaoka 120a6e
               m_vSettings.m_useChecks);
shun-iwasawa de71c0
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    glDisable(GL_BLEND);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    glPushMatrix();
Shinya Kitaoka 120a6e
    glLoadIdentity();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    glRasterPos2d(rect.x0, rect.y0);
Shinya Kitaoka 120a6e
    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
Shinya Kitaoka 120a6e
shun-iwasawa 481b59
    glDrawPixels(ras->getWrap(), ras->getLy(), TGL_FMT, bpcType,
shun-iwasawa 215a5b
                 (GLvoid *)ras->getRawData());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    CHECK_ERRORS_BY_GL
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    ras->unlock();
Shinya Kitaoka 120a6e
    glPopMatrix();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Painter::onVectorImage(TVectorImage *vi) {
Shinya Kitaoka 120a6e
  TRect clipRect = m_dim;
Shinya Kitaoka 120a6e
  clipRect -= TPoint(m_dim.lx * 0.5, m_dim.ly * 0.5);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool thereIsColorFilter =
Shinya Kitaoka 120a6e
      (m_vSettings.m_colorMask != 0 && m_vSettings.m_colorMask != TRop::MChan);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_vSettings.m_bg == 0x100000 && !thereIsColorFilter) {
Shinya Kitaoka 120a6e
    TRaster32P check =
Shinya Kitaoka 120a6e
        getCheckBoard(clipRect, m_aff, m_vSettings.m_sceneProperties);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    glDisable(GL_BLEND);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    glPushMatrix();
Shinya Kitaoka 120a6e
    glLoadIdentity();
Shinya Kitaoka 120a6e
    glRasterPos2d(0, 0);
Shinya Kitaoka 120a6e
    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    glDrawPixels(check->getLx(), check->getLy(), TGL_FMT, TGL_TYPE,
Shinya Kitaoka 120a6e
                 check->getRawData());
Shinya Kitaoka 120a6e
    glPopMatrix();
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    if (m_vSettings.m_bg == 0x40000 || thereIsColorFilter)
Shinya Kitaoka 120a6e
      glClearColor(0.0, 0.0, 0.0, 1.0);
Shinya Kitaoka 120a6e
    else if (m_vSettings.m_bg == 0x80000)
Shinya Kitaoka 120a6e
      glClearColor(1.0, 1.0, 1.0, 1.0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    glClear(GL_COLOR_BUFFER_BIT);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TVectorRenderData rd(m_aff, clipRect, vi->getPalette(), 0,
Shinya Kitaoka 120a6e
                       true  // alfa enabled
shun-iwasawa 215a5b
  );
Shinya Kitaoka 120a6e
  if (m_vSettings.m_useChecks) {
Shinya Kitaoka 120a6e
    ToonzCheck *tc         = ToonzCheck::instance();
Shinya Kitaoka 120a6e
    int checks             = tc->getChecks();  // &ToonzCheck::eBlackBg
Shinya Kitaoka 120a6e
    rd.m_inkCheckEnabled   = checks & ToonzCheck::eInk;
Shinya Kitaoka 120a6e
    rd.m_paintCheckEnabled = checks & ToonzCheck::ePaint;
Shinya Kitaoka 120a6e
    rd.m_colorCheckIndex   = tc->getColorIndex();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  tglDraw(rd, vi);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Painter::onRasterImage(TRasterImage *ri) {
Shinya Kitaoka 120a6e
  TDimension imageSize =
Shinya Kitaoka 120a6e
      (m_imageSize.lx == 0 ? ri->getRaster()->getSize() : m_imageSize);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_finalAff =
Shinya Kitaoka 120a6e
      m_vSettings.m_useTexture
Shinya Kitaoka 120a6e
          ? m_aff
Shinya Kitaoka 120a6e
          : TTranslation(m_dim.lx * 0.5, m_dim.ly * 0.5) * m_aff *
Shinya Kitaoka 120a6e
                TTranslation(-TPointD(0.5 * imageSize.lx, 0.5 * imageSize.ly));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRectD bbox = TRectD(0, 0, imageSize.lx - 1, imageSize.ly - 1);
Shinya Kitaoka 120a6e
  m_bbox      = m_vSettings.m_useTexture ? bbox : m_finalAff * bbox;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!m_bbox.overlaps(TRectD(0, 0, m_dim.lx - 1, m_dim.ly - 1))) return;
Shinya Kitaoka 120a6e
  m_raster = ri->getRaster();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Painter::onToonzImage(TToonzImage *ti) {
Shinya Kitaoka 120a6e
  TDimension imageSize =
Shinya Kitaoka 120a6e
      (m_imageSize.lx == 0 ? ti->getRaster()->getSize() : m_imageSize);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_finalAff =
Shinya Kitaoka 120a6e
      m_vSettings.m_useTexture
Shinya Kitaoka 120a6e
          ? m_aff
Shinya Kitaoka 120a6e
          : TTranslation(m_dim.lx * 0.5, m_dim.ly * 0.5) * m_aff *
Shinya Kitaoka 120a6e
                TTranslation(-TPointD(0.5 * imageSize.lx, 0.5 * imageSize.ly));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRectD bbox = TRectD(0, 0, imageSize.lx - 1, imageSize.ly - 1);
Shinya Kitaoka 120a6e
  m_bbox      = m_vSettings.m_useTexture ? bbox : m_finalAff * bbox;
Shinya Kitaoka 120a6e
  if (!m_bbox.overlaps(TRectD(0, 0, m_dim.lx - 1, m_dim.ly - 1))) return;
Shinya Kitaoka 120a6e
  m_raster = ti->getRaster();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Painter::drawBlank() {
Shinya Kitaoka 120a6e
  TPixel bgColor = Preferences::instance()->getPreviewBgColor();
Shinya Kitaoka 120a6e
  glClearColor(bgColor.r / 255.0f, bgColor.g / 255.0f, bgColor.b / 255.0f, 1.0);
Shinya Kitaoka 120a6e
  glClear(GL_COLOR_BUFFER_BIT);
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
  glLoadIdentity();
Shinya Kitaoka 120a6e
  tglColor(m_vSettings.m_blankColor);
Shinya Kitaoka 120a6e
  tglFillRect(m_bbox);
Shinya Kitaoka 120a6e
  glPopMatrix();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ImagePainter::VisualSettings::VisualSettings()
Shinya Kitaoka 120a6e
    : m_colorMask(0)
Shinya Kitaoka 120a6e
    , m_greytones(false)
Shinya Kitaoka 120a6e
    , m_doCompare(false)
Shinya Kitaoka 120a6e
    , m_defineLoadbox(false)
Shinya Kitaoka 120a6e
    , m_useLoadbox(false)
Shinya Kitaoka 120a6e
    , m_blankColor(TPixel::Transparent)
Shinya Kitaoka 120a6e
    , m_useTexture(false)
Shinya Kitaoka 120a6e
    , m_drawExternalBG(false)
Shinya Kitaoka 120a6e
    , m_showBBox(false)
Shinya Kitaoka 120a6e
    , m_sceneProperties(0)
Shinya Kitaoka 120a6e
    , m_recomputeIfNeeded(true)
Shinya Kitaoka 120a6e
    , m_drawBlankFrame(false)
shun-iwasawa 481b59
    , m_useChecks(false)
shun-iwasawa 481b59
    , m_gainStep(0) {
Shinya Kitaoka 120a6e
  if (FlipBookBlackBgToggle) m_bg = 0x40000;
Shinya Kitaoka 120a6e
  if (FlipBookWhiteBgToggle) m_bg = 0x80000;
Shinya Kitaoka 120a6e
  if (FlipBookCheckBgToggle) m_bg = 0x100000;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool ImagePainter::VisualSettings::needRepaint(const VisualSettings &vs) const {
Shinya Kitaoka 120a6e
  return !(m_colorMask == vs.m_colorMask && m_greytones == vs.m_greytones &&
Shinya Kitaoka 120a6e
           m_bg == vs.m_bg && m_doCompare == vs.m_doCompare &&
Shinya Kitaoka 120a6e
           m_defineLoadbox == vs.m_defineLoadbox &&
Shinya Kitaoka 120a6e
           m_useLoadbox == vs.m_useLoadbox && m_useTexture == vs.m_useTexture &&
shun-iwasawa 481b59
           m_drawExternalBG == vs.m_drawExternalBG &&
shun-iwasawa 481b59
           m_gainStep == vs.m_gainStep);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ImagePainter::CompareSettings::CompareSettings()
Shinya Kitaoka 120a6e
    : m_compareX(0.5)
Shinya Kitaoka 120a6e
    , m_compareY(DefaultCompareValue)
Shinya Kitaoka 120a6e
    , m_dragCompareX(false)
Shinya Kitaoka 120a6e
    , m_dragCompareY(false)
Shinya Kitaoka 120a6e
    , m_swapCompared(false) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ImagePainter::paintImage(const TImageP &image, const TDimension &imageSize,
Shinya Kitaoka 120a6e
                              const TDimension &viewerSize, const TAffine &aff,
Shinya Kitaoka 120a6e
                              const VisualSettings &visualSettings,
Shinya Kitaoka 120a6e
                              const CompareSettings &compareSettings,
Shinya Kitaoka 120a6e
                              const TRect &loadbox) {
Shinya Kitaoka 120a6e
  glDisable(GL_DEPTH_TEST);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (visualSettings.m_drawExternalBG) {
Shinya Kitaoka 120a6e
    glClearColor(0.0, 0.0, 0.0, 0.0);
Shinya Kitaoka 120a6e
    glClear(GL_COLOR_BUFFER_BIT);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  GLenum error = glGetError();
Shinya Kitaoka 120a6e
  // assert(error==GL_NO_ERROR);
Shinya Kitaoka 120a6e
  if (error != GL_NO_ERROR) {
Shinya Kitaoka 120a6e
    printf("ImagePainter::paintImage() gl_error:%d\n", error);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!image) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterImageP rimg = (TRasterImageP)image;
Shinya Kitaoka 120a6e
  TVectorImageP vimg = (TVectorImageP)image;
Shinya Kitaoka 120a6e
  TToonzImageP timg  = (TToonzImageP)image;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRect clipRect(viewerSize);
Shinya Kitaoka 120a6e
  clipRect -= TPoint(viewerSize.lx * 0.5, viewerSize.ly * 0.5);
Shinya Kitaoka 120a6e
  Painter painter(viewerSize, imageSize, aff, image->getPalette(),
Shinya Kitaoka 120a6e
                  visualSettings);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (rimg)
Shinya Kitaoka 120a6e
    painter.onRasterImage(rimg.getPointer());
Shinya Kitaoka 120a6e
  else if (vimg)
Shinya Kitaoka 120a6e
    painter.onVectorImage(vimg.getPointer());
Shinya Kitaoka 120a6e
  else if (timg)
Shinya Kitaoka 120a6e
    painter.onToonzImage(timg.getPointer());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (visualSettings.m_blankColor != TPixel::Transparent) {
Shinya Kitaoka 120a6e
    painter.drawBlank();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // if I have a color filter applied using a glmask, , drawing of images must
Shinya Kitaoka 120a6e
  // be done on black bg!
Shinya Kitaoka 120a6e
  if (!vimg)
Shinya Kitaoka 120a6e
    painter.flushRasterImages(
shun-iwasawa 215a5b
        loadbox,
shun-iwasawa 215a5b
        visualSettings.m_doCompare ? compareSettings.m_compareX
shun-iwasawa 215a5b
                                   : DefaultCompareValue,
Shinya Kitaoka 120a6e
        visualSettings.m_doCompare ? compareSettings.m_compareY
Shinya Kitaoka 120a6e
                                   : DefaultCompareValue,
Shinya Kitaoka 120a6e
        compareSettings.m_swapCompared);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (visualSettings.m_doCompare)
Shinya Kitaoka 120a6e
    drawCompareLines(viewerSize, compareSettings.m_compareX,
Shinya Kitaoka 120a6e
                     compareSettings.m_compareY);
Toshihiro Shimizu 890ddd
}