tahoma2d/toonz/sources/stdfx/multitonefx.cpp

101 lines
2.9 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "stdfx.h"
#include "tfxparam.h"
#include "tspectrumparam.h"
2021-09-02 20:36:37 +12:00
#include "globalcontrollablefx.h"
2016-03-19 06:57:51 +13:00
2021-09-02 20:36:37 +12:00
class MultiToneFx final : public GlobalControllableFx {
2016-06-15 18:43:10 +12:00
FX_PLUGIN_DECLARATION(MultiToneFx)
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRasterFxPort m_input;
TSpectrumParamP m_colors;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
MultiToneFx() {
2018-09-06 05:07:46 +12:00
std::vector<TSpectrum::ColorKey> colors = {
TSpectrum::ColorKey(0, TPixel32::White),
TSpectrum::ColorKey(0.5, TPixel32::Yellow),
TSpectrum::ColorKey(1, TPixel32::Red)};
m_colors = TSpectrumParamP(colors);
2016-06-15 18:43:10 +12:00
bool ret = m_colors->isKeyframe(0);
bindParam(this, "colors", m_colors);
ret = getParams()->getParam(0)->isKeyframe(0);
addInputPort("Source", m_input);
}
~MultiToneFx(){};
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())
return m_input->doGetBBox(frame, bBox, info);
else {
bBox = TRectD();
return false;
}
}
2016-06-19 20:06:29 +12:00
void doCompute(TTile &tile, double frame, const TRenderSettings &) 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, typename PIXELGRAY, typename CHANNEL_TYPE>
2016-06-15 18:43:10 +12:00
void doMultiTone(const TRasterPT<PIXEL> &ras,
const TSpectrumT<PIXEL> &spectrum) {
double aux = (double)PIXEL::maxChannelValue;
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) {
CHANNEL_TYPE reference;
double s;
reference = PIXELGRAY::from(*pix).value;
s = reference / aux;
if (pix->m == aux) {
*pix = spectrum.getPremultipliedValue(s);
} else {
PIXEL tmp = spectrum.getPremultipliedValue(s);
s = pix->m / aux;
tmp.r = (CHANNEL_TYPE)(tmp.r * s);
tmp.g = (CHANNEL_TYPE)(tmp.g * s);
tmp.b = (CHANNEL_TYPE)(tmp.b * s);
tmp.m = (CHANNEL_TYPE)(tmp.m * s);
*pix = tmp;
}
}
pix++;
}
}
ras->unlock();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void MultiToneFx::doCompute(TTile &tile, double frame,
const TRenderSettings &ri) {
if (!m_input.isConnected()) return;
m_input->compute(tile, frame, ri);
if (TRaster32P raster32 = tile.getRaster())
doMultiTone<TPixel32, TPixelGR8, UCHAR>(raster32,
m_colors->getValue(frame));
else if (TRaster64P raster64 = tile.getRaster())
doMultiTone<TPixel64, TPixelGR16, USHORT>(raster64,
m_colors->getValue64(frame));
else
throw TException("MultiToneFx: unsupported Pixel Type");
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
FX_PLUGIN_IDENTIFIER(MultiToneFx, "multiToneFx")