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