tahoma2d/toonz/sources/stdfx/unmultiplyfx.cpp

71 lines
1.9 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "texception.h"
//#include "tfxparam.h"
#include "stdfx.h"
2016-06-15 18:43:10 +12:00
namespace {
TPixel32 unmultiply(const TPixel32 &pix) {
if (!pix.m) return pix;
double depremult = 255.0 / pix.m;
return TPixel32((UCHAR)(pix.r * depremult), (UCHAR)(pix.g * depremult),
(UCHAR)(pix.b * depremult), pix.m);
2016-03-19 06:57:51 +13:00
}
}
//===================================================================
2016-06-15 18:43:10 +12:00
class UnmultiplyFx : public TStandardRasterFx {
FX_PLUGIN_DECLARATION(UnmultiplyFx)
TRasterFxPort m_input;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
UnmultiplyFx() { addInputPort("Source", m_input); }
~UnmultiplyFx(){};
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
};
//------------------------------------------------------------------------------
void UnmultiplyFx::doCompute(TTile &tile, double frame,
2016-06-15 18:43:10 +12:00
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
TRaster32P raster32 = tile.getRaster();
assert(raster32); // per ora gestisco solo i Raster32
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int j;
raster32->lock();
for (j = 0; j < raster32->getLy(); j++) {
TPixel32 *pix = raster32->pixels(j);
TPixel32 *endPix = pix + raster32->getLx();
while (pix < endPix) {
if (pix->m) {
double depremult = 255.0 / pix->m;
pix->r = (UCHAR)(pix->r * depremult);
pix->g = (UCHAR)(pix->g * depremult);
pix->b = (UCHAR)(pix->b * depremult);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//*pix=unmultiply(*pix);
pix++;
}
}
raster32->unlock();
2016-03-19 06:57:51 +13:00
}
FX_PLUGIN_IDENTIFIER(UnmultiplyFx, "unmultiplyFx");