tahoma2d/toonz/sources/stdfx/rgbmfadefx.cpp

93 lines
2.9 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "texception.h"
#include "tfxparam.h"
#include "stdfx.h"
#include "tpixelutils.h"
#include "tparamset.h"
//===================================================================
2016-06-15 18:43:10 +12:00
class RGBMFadeFx : public TStandardRasterFx {
FX_PLUGIN_DECLARATION(RGBMFadeFx)
TRasterFxPort m_input;
TPixelParamP m_color;
TDoubleParamP m_intensity;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
RGBMFadeFx() : m_intensity(50.0), m_color(TPixel32::Black) {
bindParam(this, "color", m_color);
bindParam(this, "intensity", m_intensity);
m_intensity->setValueRange(0, 100);
addInputPort("Source", m_input);
m_color->enableMatte(false);
}
~RGBMFadeFx(){};
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
bool doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info) override {
2016-06-15 18:43:10 +12:00
if (m_input.isConnected())
return m_input->doGetBBox(frame, bBox, info);
else {
bBox = TRectD();
return false;
}
}
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void doCompute(TTile &tile, double frame, const TRenderSettings &ri) override;
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 doRGBMFade(TRasterPT<PIXEL> &ras, const PIXEL &col, double intensity) {
int j;
ras->lock();
for (j = 0; j < ras->getLy(); j++) {
PIXEL *pix = ras->pixels(j);
PIXEL *endPix = pix + ras->getLx();
while (pix < endPix) {
pix->m = pix->m;
double factor = pix->m / (double)PIXEL::maxChannelValue;
int val;
val = troundp(pix->r + intensity * (col.r * factor - pix->r));
pix->r = (val > PIXEL::maxChannelValue) ? PIXEL::maxChannelValue : val;
val = troundp(pix->g + intensity * (col.g * factor - pix->g));
pix->g = (val > PIXEL::maxChannelValue) ? PIXEL::maxChannelValue : val;
val = troundp(pix->b + intensity * (col.b * factor - pix->b));
pix->b = (val > PIXEL::maxChannelValue) ? PIXEL::maxChannelValue : val;
/* qui si faceva il fade anche del matte
pix->r=(UCHAR)(pix->r+intensity*(col.r-pix->r));
pix->g=(UCHAR)(pix->g+intensity*(col.g-pix->g));
pix->b=(UCHAR)(pix->b+intensity*(col.b-pix->b));
pix->m=(UCHAR)(pix->m+intensity*(col.m-pix->m));*/
++pix;
}
}
ras->unlock();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------
void RGBMFadeFx::doCompute(TTile &tile, double frame,
2016-06-15 18:43:10 +12:00
const TRenderSettings &ri) {
if (!m_input.isConnected()) return;
m_input->compute(tile, frame, ri);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPixel32 col = m_color->getValue(frame);
double min, max, step;
m_intensity->getValueRange(min, max, step);
double intensity = tcrop(m_intensity->getValue(frame), min, max) / 100;
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)
doRGBMFade<TPixel32>(raster32, col, intensity);
else {
TRaster64P raster64 = tile.getRaster();
if (raster64)
doRGBMFade<TPixel64>(raster64, toPixel64(col), intensity);
else
throw TException("RGBMFadeFx: unsupported Pixel Type");
}
2016-03-19 06:57:51 +13:00
}
FX_PLUGIN_IDENTIFIER(RGBMFadeFx, "rgbmFadeFx");