2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
#include "stdfx.h"
|
|
|
|
#include "tfxparam.h"
|
|
|
|
#include "tpixelutils.h"
|
|
|
|
|
|
|
|
#include "tparamset.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 RGBMCutFx final : public GlobalControllableFx {
|
2016-06-15 18:43:10 +12:00
|
|
|
FX_PLUGIN_DECLARATION(RGBMCutFx)
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRasterFxPort m_input;
|
|
|
|
TRangeParamP m_r_range;
|
|
|
|
TRangeParamP m_g_range;
|
|
|
|
TRangeParamP m_b_range;
|
|
|
|
TRangeParamP m_m_range;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
RGBMCutFx()
|
|
|
|
: m_r_range(DoublePair(0., 255.))
|
|
|
|
, m_g_range(DoublePair(0., 255.))
|
|
|
|
, m_b_range(DoublePair(0., 255.))
|
|
|
|
, m_m_range(DoublePair(0., 255.)) {
|
|
|
|
bindParam(this, "r_range", m_r_range);
|
|
|
|
bindParam(this, "g_range", m_g_range);
|
|
|
|
bindParam(this, "b_range", m_b_range);
|
|
|
|
bindParam(this, "m_range", m_m_range);
|
|
|
|
m_r_range->getMin()->setValueRange(0., 255.);
|
|
|
|
m_g_range->getMin()->setValueRange(0., 255.);
|
|
|
|
m_b_range->getMin()->setValueRange(0., 255.);
|
|
|
|
m_m_range->getMin()->setValueRange(0., 255.);
|
|
|
|
m_r_range->getMax()->setValueRange(0., 255.);
|
|
|
|
m_g_range->getMax()->setValueRange(0., 255.);
|
|
|
|
m_b_range->getMax()->setValueRange(0., 255.);
|
|
|
|
m_m_range->getMax()->setValueRange(0., 255.);
|
|
|
|
|
|
|
|
addInputPort("Source", m_input);
|
|
|
|
}
|
|
|
|
|
|
|
|
~RGBMCutFx(){};
|
|
|
|
|
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
|
|
|
return m_input.getFx() && m_input->doGetBBox(frame, bBox, info);
|
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace {
|
|
|
|
void update_param(double ¶m, TRaster32P ras) { return; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void update_param(double ¶m, TRaster64P ras) {
|
|
|
|
param = param * 257;
|
|
|
|
return;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
template <typename PIXEL, typename CHANNEL_TYPE>
|
2016-06-15 18:43:10 +12:00
|
|
|
void doRGBMCut(TRasterPT<PIXEL> ras, double hi_m, double hi_r, double hi_g,
|
|
|
|
double hi_b, double lo_m, double lo_r, double lo_g,
|
|
|
|
double lo_b) {
|
|
|
|
update_param(hi_m, ras);
|
|
|
|
update_param(hi_r, ras);
|
|
|
|
update_param(hi_g, ras);
|
|
|
|
update_param(hi_b, ras);
|
|
|
|
update_param(lo_m, ras);
|
|
|
|
update_param(lo_r, ras);
|
|
|
|
update_param(lo_g, ras);
|
|
|
|
update_param(lo_b, ras);
|
|
|
|
|
|
|
|
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 != 0) {
|
|
|
|
*pix = depremultiply(*pix);
|
|
|
|
if (lo_m == 0)
|
|
|
|
pix->m = tcrop((int)pix->m, (int)lo_m, (int)hi_m);
|
|
|
|
else
|
|
|
|
pix->m = (pix->m) ? tcrop((int)pix->m, (int)lo_m, (int)hi_m) : 0;
|
|
|
|
|
|
|
|
pix->r = tcrop((int)pix->r, (int)lo_r, (int)hi_r);
|
|
|
|
pix->g = tcrop((int)pix->g, (int)lo_g, (int)hi_g);
|
|
|
|
pix->b = tcrop((int)pix->b, (int)lo_b, (int)hi_b);
|
|
|
|
*pix = premultiply(*pix);
|
|
|
|
}
|
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 RGBMCutFx::doCompute(TTile &tile, double frame,
|
|
|
|
const TRenderSettings &ri) {
|
|
|
|
if (!m_input.isConnected()) return;
|
|
|
|
|
|
|
|
m_input->compute(tile, frame, ri);
|
|
|
|
|
|
|
|
double hi_m = m_m_range->getMax()->getValue(frame);
|
|
|
|
double hi_r = m_r_range->getMax()->getValue(frame);
|
|
|
|
double hi_g = m_g_range->getMax()->getValue(frame);
|
|
|
|
double hi_b = m_b_range->getMax()->getValue(frame);
|
|
|
|
double lo_m = m_m_range->getMin()->getValue(frame);
|
|
|
|
double lo_r = m_r_range->getMin()->getValue(frame);
|
|
|
|
double lo_g = m_g_range->getMin()->getValue(frame);
|
|
|
|
double lo_b = m_b_range->getMin()->getValue(frame);
|
|
|
|
|
|
|
|
TRaster32P raster32 = tile.getRaster();
|
|
|
|
|
|
|
|
if (raster32)
|
|
|
|
doRGBMCut<TPixel32, UCHAR>(raster32, hi_m, hi_r, hi_g, hi_b, lo_m, lo_r,
|
|
|
|
lo_g, lo_b);
|
|
|
|
else {
|
|
|
|
TRaster64P raster64 = tile.getRaster();
|
|
|
|
if (raster64)
|
|
|
|
doRGBMCut<TPixel64, USHORT>(raster64, hi_m, hi_r, hi_g, hi_b, lo_m, lo_r,
|
|
|
|
lo_g, lo_b);
|
|
|
|
else
|
2020-10-07 05:26:13 +13:00
|
|
|
throw TException("RGBACutFx: unsupported Pixel Type");
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
FX_PLUGIN_IDENTIFIER(RGBMCutFx, "rgbmCutFx")
|