|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "stdfx.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tfxparam.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "ttzpimagefx.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "texturefxP.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TextureFx : public TStandardRasterFx
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
FX_PLUGIN_DECLARATION(TextureFx)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterFxPort m_input;
|
|
Toshihiro Shimizu |
890ddd |
TRasterFxPort m_texture;
|
|
Toshihiro Shimizu |
890ddd |
TStringParamP m_string;
|
|
Toshihiro Shimizu |
890ddd |
TIntEnumParamP m_keep;
|
|
Toshihiro Shimizu |
890ddd |
//TIntEnumParamP m_type;
|
|
Toshihiro Shimizu |
890ddd |
TIntEnumParamP m_mode;
|
|
Toshihiro Shimizu |
890ddd |
TDoubleParamP m_value;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TextureFx()
|
|
Toshihiro Shimizu |
890ddd |
: m_string(L"1,2,3"), m_keep(new TIntEnumParam(0, "Delete"))
|
|
Toshihiro Shimizu |
890ddd |
//, m_type(new TIntEnumParam(0, "Lines & Areas"))
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
m_mode(new TIntEnumParam(SUBSTITUTE, "Texture")), m_value(100)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
addInputPort("Source", m_input);
|
|
Toshihiro Shimizu |
890ddd |
addInputPort("Texture", m_texture);
|
|
Toshihiro Shimizu |
890ddd |
bindParam(this, "indexes", m_string);
|
|
Toshihiro Shimizu |
890ddd |
bindParam(this, "keep", m_keep);
|
|
Toshihiro Shimizu |
890ddd |
bindParam(this, "mode", m_mode);
|
|
Toshihiro Shimizu |
890ddd |
//bindParam(this,"type", m_type);
|
|
Toshihiro Shimizu |
890ddd |
bindParam(this, "value", m_value);
|
|
Toshihiro Shimizu |
890ddd |
m_value->setValueRange(0, 100);
|
|
Toshihiro Shimizu |
890ddd |
m_keep->addItem(1, "Keep");
|
|
Toshihiro Shimizu |
890ddd |
//m_type->addItem(1, "Lines");
|
|
Toshihiro Shimizu |
890ddd |
//m_type->addItem(2, "Areas");
|
|
Toshihiro Shimizu |
890ddd |
m_mode->addItem(PATTERNTYPE, "Pattern");
|
|
Toshihiro Shimizu |
890ddd |
m_mode->addItem(ADD, "Add");
|
|
Toshihiro Shimizu |
890ddd |
m_mode->addItem(SUBTRACT, "Subtract");
|
|
Toshihiro Shimizu |
890ddd |
m_mode->addItem(MULTIPLY, "Multiply");
|
|
Toshihiro Shimizu |
890ddd |
m_mode->addItem(LIGHTEN, "Lighten");
|
|
Toshihiro Shimizu |
890ddd |
m_mode->addItem(DARKEN, "Darken");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~TextureFx(){};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_input.isConnected()) {
|
|
Toshihiro Shimizu |
890ddd |
bool ret = m_input->doGetBBox(frame, bBox, info);
|
|
Toshihiro Shimizu |
890ddd |
return ret;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
bBox = TRectD();
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void doCompute(TTile &tile, double frame, const TRenderSettings &ri);
|
|
Toshihiro Shimizu |
890ddd |
void doDryCompute(TRectD &rect, double frame, const TRenderSettings &info);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool allowUserCacheOnPort(int port) { return port != 0; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int getMemoryRequirement(const TRectD &rect, double frame, const TRenderSettings &info);
|
|
Toshihiro Shimizu |
890ddd |
bool canHandle(const TRenderSettings &info, double frame) { return true; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TextureFx::doDryCompute(TRectD &rect, double frame, const TRenderSettings &info)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_input.isConnected())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<std::string> items;</std::string>
|
|
Shinya Kitaoka |
9eb50d |
std::string indexes = ::to_string(m_string->getValue());
|
|
Toshihiro Shimizu |
890ddd |
parseIndexes(indexes, items);
|
|
Toshihiro Shimizu |
890ddd |
TRenderSettings ri2(info);
|
|
Toshihiro Shimizu |
890ddd |
PaletteFilterFxRenderData *PaletteFilterData = new PaletteFilterFxRenderData;
|
|
Toshihiro Shimizu |
890ddd |
insertIndexes(items, PaletteFilterData);
|
|
Toshihiro Shimizu |
890ddd |
PaletteFilterData->m_keep = (bool)(m_keep->getValue() == 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ri2.m_data.push_back(PaletteFilterData);
|
|
Toshihiro Shimizu |
890ddd |
ri2.m_userCachable = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//First child compute: part of output that IS NOT texturized
|
|
Toshihiro Shimizu |
890ddd |
m_input->dryCompute(rect, frame, ri2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!m_texture.isConnected())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isSwatch = ri2.m_isSwatch;
|
|
Toshihiro Shimizu |
890ddd |
if (isSwatch)
|
|
Toshihiro Shimizu |
890ddd |
ri2.m_isSwatch = false;
|
|
Toshihiro Shimizu |
890ddd |
PaletteFilterData->m_keep = !(m_keep->getValue());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Second child compute: part of output that IS to be texturized
|
|
Toshihiro Shimizu |
890ddd |
m_input->dryCompute(rect, frame, ri2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Third child compute: texture
|
|
Toshihiro Shimizu |
890ddd |
m_texture->dryCompute(rect, frame, info);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TextureFx::doCompute(TTile &tile, double frame, const TRenderSettings &ri)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_input.isConnected())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TTile invertMaskTile;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//carico il vettore items con gli indici dei colori
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<std::string> items;</std::string>
|
|
Shinya Kitaoka |
9eb50d |
std::string indexes = ::to_string(m_string->getValue());
|
|
Toshihiro Shimizu |
890ddd |
parseIndexes(indexes, items);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//genero il tile il cui raster contiene l'immagine in input a cui sono stati tolti i pixel
|
|
Toshihiro Shimizu |
890ddd |
//colorati con gli indici contenuti nel vettore items
|
|
Toshihiro Shimizu |
890ddd |
TRenderSettings ri2(ri);
|
|
Toshihiro Shimizu |
890ddd |
PaletteFilterFxRenderData *PaletteFilterData = new PaletteFilterFxRenderData;
|
|
Toshihiro Shimizu |
890ddd |
PaletteFilterData->m_keep = !!(m_keep->getValue());
|
|
Toshihiro Shimizu |
890ddd |
insertIndexes(items, PaletteFilterData);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ri2.m_data.push_back(PaletteFilterData);
|
|
Toshihiro Shimizu |
890ddd |
ri2.m_userCachable = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_input->allocateAndCompute(invertMaskTile, tile.m_pos, tile.getRaster()->getSize(),
|
|
Toshihiro Shimizu |
890ddd |
tile.getRaster(), frame, ri2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!m_texture.isConnected()) {
|
|
Toshihiro Shimizu |
890ddd |
tile.getRaster()->copy(invertMaskTile.getRaster());
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//genero il tile il cui raster contiene l'immagine in input a cui sono stati tolti i pixel
|
|
Toshihiro Shimizu |
890ddd |
//colorati con indici diversi da quelli contenuti nel vettore items
|
|
Toshihiro Shimizu |
890ddd |
bool isSwatch = ri2.m_isSwatch;
|
|
Toshihiro Shimizu |
890ddd |
if (isSwatch)
|
|
Toshihiro Shimizu |
890ddd |
ri2.m_isSwatch = false;
|
|
Toshihiro Shimizu |
890ddd |
PaletteFilterData->m_keep = !(m_keep->getValue());
|
|
Toshihiro Shimizu |
890ddd |
m_input->compute(tile, frame, ri2);
|
|
Toshihiro Shimizu |
890ddd |
if (isSwatch)
|
|
Toshihiro Shimizu |
890ddd |
ri2.m_isSwatch = true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//controllo se ho ottenuto quaclosa su cui si possa lavorare.
|
|
Toshihiro Shimizu |
890ddd |
TRect box;
|
|
Toshihiro Shimizu |
890ddd |
TRop::computeBBox(tile.getRaster(), box);
|
|
Toshihiro Shimizu |
890ddd |
if (box.isEmpty()) {
|
|
Toshihiro Shimizu |
890ddd |
m_input->compute(tile, frame, ri); //Could the invertMask be copied??
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Then, generate the texture tile
|
|
Toshihiro Shimizu |
890ddd |
TTile textureTile;
|
|
Toshihiro Shimizu |
890ddd |
TDimension size = tile.getRaster()->getSize();
|
|
Toshihiro Shimizu |
890ddd |
TPointD pos = tile.m_pos;
|
|
Toshihiro Shimizu |
890ddd |
m_texture->allocateAndCompute(textureTile, pos, size, tile.getRaster(), frame, ri);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//And copy the part corresponding to mask tile
|
|
Toshihiro Shimizu |
890ddd |
/*TDimension dim = tile.getRaster()->getSize();
|
|
Toshihiro Shimizu |
890ddd |
TRasterP appRas = tile.getRaster()->create(dim.lx,dim.ly);
|
|
Toshihiro Shimizu |
890ddd |
appRas->clear();
|
|
Toshihiro Shimizu |
890ddd |
appRas->copy(textureTile.getRaster(),convert(textureTile.m_pos-tile.m_pos));
|
|
Toshihiro Shimizu |
890ddd |
textureTile.setRaster(appRas);*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double v = m_value->getValue(frame);
|
|
Toshihiro Shimizu |
890ddd |
if (ri.m_bpp == 32) {
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P witheCard;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
myOver32(tile.getRaster(), invertMaskTile.getRaster(), &makeOpaque<tpixel32>, v);</tpixel32>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
switch (m_mode->getValue()) {
|
|
Toshihiro Shimizu |
890ddd |
case SUBSTITUTE:
|
|
Toshihiro Shimizu |
890ddd |
myOver32(tile.getRaster(), textureTile.getRaster(), &substitute<tpixel32>, v);</tpixel32>
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
case PATTERNTYPE:
|
|
Shinya Kitaoka |
d4642c |
witheCard = TRaster32P(textureTile.getRaster()->getSize());
|
|
Toshihiro Shimizu |
890ddd |
witheCard->fill(TPixel32::White);
|
|
Toshihiro Shimizu |
890ddd |
TRop::over(textureTile.getRaster(), witheCard, textureTile.getRaster());
|
|
Toshihiro Shimizu |
890ddd |
myOver32(tile.getRaster(), textureTile.getRaster(), &pattern32, v);
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
case ADD:
|
|
Shinya Kitaoka |
d4642c |
myOver32(tile.getRaster(), textureTile.getRaster(), &textureAdd<tpixel32>, v / 100.0);</tpixel32>
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
case SUBTRACT:
|
|
Shinya Kitaoka |
d4642c |
myOver32(tile.getRaster(), textureTile.getRaster(), &textureSub<tpixel32>, v / 100.0);</tpixel32>
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
case MULTIPLY:
|
|
Shinya Kitaoka |
d4642c |
myOver32(tile.getRaster(), textureTile.getRaster(), &textureMult<tpixel32>, v);</tpixel32>
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
case DARKEN:
|
|
Shinya Kitaoka |
d4642c |
myOver32(tile.getRaster(), textureTile.getRaster(), &textureDarken<tpixel32>, v);</tpixel32>
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
case LIGHTEN : myOver32(tile.getRaster(), textureTile.getRaster(), &textureLighten<tpixel32>, v);</tpixel32>
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
default:
|
|
Toshihiro Shimizu |
890ddd |
assert(0);
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
TRaster64P witheCard;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
myOver64(tile.getRaster(), invertMaskTile.getRaster(), &makeOpaque<tpixel64>, v);</tpixel64>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
switch (m_mode->getValue()) {
|
|
Toshihiro Shimizu |
890ddd |
case SUBSTITUTE:
|
|
Toshihiro Shimizu |
890ddd |
myOver64(tile.getRaster(), textureTile.getRaster(), &substitute<tpixel64>, v);</tpixel64>
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
case PATTERNTYPE:
|
|
Shinya Kitaoka |
d4642c |
witheCard = TRaster64P(textureTile.getRaster()->getSize());
|
|
Toshihiro Shimizu |
890ddd |
witheCard->fill(TPixel64::White);
|
|
Toshihiro Shimizu |
890ddd |
TRop::over(textureTile.getRaster(), witheCard, textureTile.getRaster());
|
|
Toshihiro Shimizu |
890ddd |
myOver64(tile.getRaster(), textureTile.getRaster(), &pattern64, v);
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
case ADD:
|
|
Shinya Kitaoka |
d4642c |
myOver64(tile.getRaster(), textureTile.getRaster(), &textureAdd<tpixel64>, v / 100.0);</tpixel64>
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
case SUBTRACT:
|
|
Shinya Kitaoka |
d4642c |
myOver64(tile.getRaster(), textureTile.getRaster(), &textureSub<tpixel64>, v / 100.0);</tpixel64>
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
case MULTIPLY:
|
|
Shinya Kitaoka |
d4642c |
myOver64(tile.getRaster(), textureTile.getRaster(), &textureMult<tpixel64>, v);</tpixel64>
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
case DARKEN:
|
|
Shinya Kitaoka |
d4642c |
myOver64(tile.getRaster(), textureTile.getRaster(), &textureDarken<tpixel64>, v);</tpixel64>
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
case LIGHTEN:
|
|
Shinya Kitaoka |
d4642c |
myOver64(tile.getRaster(), textureTile.getRaster(), &textureLighten<tpixel64>, v);</tpixel64>
|
|
Shinya Kitaoka |
d4642c |
break;
|
|
Shinya Kitaoka |
d4642c |
default:
|
|
Toshihiro Shimizu |
890ddd |
assert(0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRop::over(tile.getRaster(), invertMaskTile.getRaster());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int TextureFx::getMemoryRequirement(const TRectD &rect, double frame, const TRenderSettings &info)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TRasterFx::memorySize(rect, info.m_bpp);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FX_PLUGIN_IDENTIFIER(TextureFx, "textureFx");
|