2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
#include "texception.h"
|
|
|
|
#include "tfxparam.h"
|
|
|
|
|
|
|
|
#include "stdfx.h"
|
|
|
|
#include "trandom.h"
|
|
|
|
|
|
|
|
//===================================================================
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class DissolveFx final : public TStandardRasterFx {
|
2016-06-15 18:43:10 +12:00
|
|
|
FX_PLUGIN_DECLARATION(DissolveFx)
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRasterFxPort m_input;
|
|
|
|
TDoubleParamP m_intensity;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
DissolveFx() : m_intensity(30.0) {
|
|
|
|
bindParam(this, "intensity", m_intensity);
|
|
|
|
addInputPort("Source", m_input);
|
|
|
|
m_intensity->setValueRange(0.0, 100.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
~DissolveFx(){};
|
|
|
|
|
2016-06-20 14:23:05 +12:00
|
|
|
bool doGetBBox(double frame, TRectD &bBox,
|
|
|
|
const TRenderSettings &info) override {
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_input.isConnected()) {
|
|
|
|
bool ret = m_input->doGetBBox(frame, bBox, info);
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
bBox = TRectD();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void doCompute(TTile &tile, double frame, const TRenderSettings &ri) override;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
2016-06-20 14:23:05 +12:00
|
|
|
bool canHandle(const TRenderSettings &info, double frame) override {
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename PIXEL>
|
2016-06-15 18:43:10 +12:00
|
|
|
void doDissolve(const TRasterPT<PIXEL> &ras, const double intensity,
|
|
|
|
TRandom &rnd) {
|
|
|
|
int j;
|
|
|
|
ras->lock();
|
|
|
|
for (j = 0; j < ras->getLy(); j++) {
|
|
|
|
PIXEL *pix = ras->pixels(j);
|
|
|
|
PIXEL *endPix = pix + ras->getLx();
|
|
|
|
while (pix < endPix) {
|
|
|
|
if (pix->m) {
|
|
|
|
double data;
|
|
|
|
data = rnd.getFloat();
|
|
|
|
if (data < intensity) {
|
|
|
|
pix->r = pix->g = pix->b = pix->m = 0;
|
|
|
|
}
|
|
|
|
}
|
2020-04-12 17:19:20 +12:00
|
|
|
pix++;
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ras->unlock();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DissolveFx::doCompute(TTile &tile, double frame,
|
|
|
|
const TRenderSettings &ri) {
|
|
|
|
if (!m_input.isConnected()) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_input->compute(tile, frame, ri);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRandom rnd;
|
|
|
|
double intensity = m_intensity->getValue(frame) / 100.0;
|
|
|
|
;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRaster32P raster32 = tile.getRaster();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (raster32)
|
|
|
|
doDissolve<TPixel32>(raster32, intensity, rnd);
|
|
|
|
else {
|
|
|
|
TRaster64P raster64 = tile.getRaster();
|
|
|
|
if (raster64)
|
|
|
|
doDissolve<TPixel64>(raster64, intensity, rnd);
|
|
|
|
else
|
|
|
|
throw TException("Brightness&Contrast: unsupported Pixel Type");
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
FX_PLUGIN_IDENTIFIER(DissolveFx, "dissolveFx");
|