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