Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
#include "toonz/cleanupcolorstyles.h"
Toshihiro Shimizu 890ddd
#include "toonz/targetcolors.h"
Toshihiro Shimizu 890ddd
#include "tgl.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "cleanuppalette.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPalette *createStandardCleanupPalette() {
Shinya Kitaoka 120a6e
  TPalette *palette    = new TPalette();
Shinya Kitaoka 120a6e
  TPalette::Page *page = palette->getPage(0);
Shinya Kitaoka 120a6e
  page->removeStyle(1);  // tolgo il black che c'e' gia' nella palette di
Shinya Kitaoka 120a6e
                         // default
Shinya Kitaoka 120a6e
  TBlackCleanupStyle *black = new TBlackCleanupStyle();
Shinya Kitaoka 120a6e
  palette->setStyle(1, black);
Shinya Kitaoka 120a6e
  page->addStyle(1);
Shinya Kitaoka 120a6e
  // page->addStyle(palette->addStyle(new TColorCleanupStyle(TPixel32::Red)));
Shinya Kitaoka 120a6e
  // page->addStyle(palette->addStyle(new TColorCleanupStyle(TPixel32::Blue)));
Shinya Kitaoka 120a6e
  black->setName(L"color_1");
Shinya Kitaoka 120a6e
  palette->addRef();
Shinya Kitaoka 120a6e
  palette->setIsCleanupPalette(true);
Shinya Kitaoka 120a6e
  return palette;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPalette *createToonzPalette(TPalette *cleanupPalette) {
Shinya Kitaoka 120a6e
  assert(cleanupPalette);
Shinya Kitaoka 120a6e
  assert(cleanupPalette->isCleanupPalette());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPalette *palette = new TPalette();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int i = 0; i < cleanupPalette->getPage(0)->getStyleCount(); i++) {
Shinya Kitaoka 120a6e
    int styleId = cleanupPalette->getPage(0)->getStyleId(i);
Shinya Kitaoka 120a6e
    TCleanupStyle *cs =
Shinya Kitaoka 120a6e
        dynamic_cast<tcleanupstyle *="">(cleanupPalette->getStyle(styleId));</tcleanupstyle>
Shinya Kitaoka 120a6e
    if (!cs) continue;
Shinya Kitaoka 120a6e
    TPixel32 color = cs->getMainColor();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    while (palette->getStyleCount() < styleId) palette->addStyle(TPixel32::Red);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (styleId == palette->getStyleCount())
Shinya Kitaoka 120a6e
      palette->addStyle(color);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      palette->setStyle(styleId, color);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (styleId > 1)  // 0 e 1 sono gia' nella pagina
Shinya Kitaoka 120a6e
      palette->getPage(0)->addStyle(styleId);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    assert(0 <= styleId && styleId < palette->getStyleCount());
Shinya Kitaoka 120a6e
    if (cs->getFlags()) palette->getStyle(styleId)->setFlags(cs->getFlags());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return palette;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPalette *createToonzPalette(TPalette *cleanupPalette, int colorParamIndex) {
Shinya Kitaoka 120a6e
  assert(cleanupPalette);
Shinya Kitaoka 120a6e
  assert(cleanupPalette->isCleanupPalette());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPalette *palette = new TPalette();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int i = 0; i < cleanupPalette->getPage(0)->getStyleCount(); i++) {
Shinya Kitaoka 120a6e
    int styleId = cleanupPalette->getPage(0)->getStyleId(i);
Shinya Kitaoka 120a6e
    TCleanupStyle *cs =
Shinya Kitaoka 120a6e
        dynamic_cast<tcleanupstyle *="">(cleanupPalette->getStyle(styleId));</tcleanupstyle>
Shinya Kitaoka 120a6e
    if (!cs) continue;
Shinya Kitaoka 120a6e
    TPixel32 color = cs->getColorParamValue(colorParamIndex);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    while (palette->getStyleCount() < styleId) palette->addStyle(TPixel32::Red);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (styleId == palette->getStyleCount())
Shinya Kitaoka 120a6e
      palette->addStyle(color);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      palette->setStyle(styleId, color);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (styleId > 1)  // 0 e 1 sono gia' nella pagina
Shinya Kitaoka 120a6e
      palette->getPage(0)->addStyle(styleId);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    assert(0 <= styleId && styleId < palette->getStyleCount());
Shinya Kitaoka 120a6e
    if (cs->getFlags()) palette->getStyle(styleId)->setFlags(cs->getFlags());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return palette;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//====================================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TargetColors::update(TPalette *palette, bool noAntialias) {
Shinya Kitaoka 120a6e
  m_colors.clear();
Shinya Kitaoka 120a6e
luzpaz 27707d
  TargetColor transparent(TPixel32(255, 255, 255, 0) /*TPixel32::Transparent*/,
Shinya Kitaoka 120a6e
                         0,  // BackgroundStyle,
Shinya Kitaoka 120a6e
                         0, 0, 0, 0);
Shinya Kitaoka 120a6e
luzpaz 27707d
  m_colors.push_back(transparent);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int i = 0; i < palette->getPage(0)->getStyleCount(); i++) {
Shinya Kitaoka 120a6e
    int styleId     = palette->getPage(0)->getStyleId(i);
Shinya Kitaoka 120a6e
    TColorStyle *cs = palette->getStyle(styleId);
Shinya Kitaoka 120a6e
    if (!cs) continue;
Shinya Kitaoka 120a6e
    if (TBlackCleanupStyle *blackStyle =
Shinya Kitaoka 120a6e
            dynamic_cast<tblackcleanupstyle *="">(cs)) {</tblackcleanupstyle>
Shinya Kitaoka 120a6e
      TargetColor tc(
Shinya Kitaoka 120a6e
          blackStyle->getMainColor(), styleId, (int)blackStyle->getBrightness(),
Shinya Kitaoka 120a6e
          noAntialias ? 100 : (int)blackStyle->getContrast(),
Shinya Kitaoka 120a6e
          blackStyle->getColorThreshold(), blackStyle->getWhiteThreshold());
Shinya Kitaoka 120a6e
      m_colors.push_back(tc);
Shinya Kitaoka 120a6e
    } else if (TColorCleanupStyle *colorStyle =
Shinya Kitaoka 120a6e
                   dynamic_cast<tcolorcleanupstyle *="">(cs)) {</tcolorcleanupstyle>
Shinya Kitaoka 120a6e
      TargetColor tc(colorStyle->getMainColor(), styleId,
Shinya Kitaoka 120a6e
                     (int)colorStyle->getBrightness(),
Shinya Kitaoka 120a6e
                     noAntialias ? 100 : (int)colorStyle->getContrast(),
Shinya Kitaoka 120a6e
                     colorStyle->getHRange(), colorStyle->getLineWidth());
Shinya Kitaoka 120a6e
      m_colors.push_back(tc);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void convertToCleanupPalette(TPalette *palette) {
Shinya Kitaoka 120a6e
  if (palette->isCleanupPalette()) return;
Shinya Kitaoka 120a6e
  for (int i = 1; i < palette->getStyleCount(); i++) {
Shinya Kitaoka 120a6e
    TColorStyle *cs  = palette->getStyle(i);
Shinya Kitaoka 120a6e
    TPixel32 color   = cs->getMainColor();
Shinya Kitaoka 120a6e
    TColorStyle *ccs = 0;
Shinya Kitaoka 120a6e
    if (i == 1)
Shinya Kitaoka 120a6e
      ccs = new TBlackCleanupStyle();
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      ccs = new TColorCleanupStyle(color);
Shinya Kitaoka 120a6e
    palette->setStyle(i, ccs);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  palette->setIsCleanupPalette(true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void convertToLevelPalette(TPalette *palette) {
Shinya Kitaoka 120a6e
  if (!palette->isCleanupPalette()) return;
Shinya Kitaoka 120a6e
  for (int i = 1; i < palette->getStyleCount(); i++) {
Shinya Kitaoka 120a6e
    TPixel32 color = palette->getStyle(i)->getMainColor();
Shinya Kitaoka 120a6e
    palette->setStyle(i, color);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  palette->setIsCleanupPalette(false);
Toshihiro Shimizu 890ddd
}