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 {
|
2016-03-19 06:57:51 +13:00
|
|
|
template <typename T, typename PIXEL>
|
2016-06-15 18:43:10 +12:00
|
|
|
void prepare_lut(double max, int edge, std::vector<T> &lut) {
|
|
|
|
double aux = (double)PIXEL::maxChannelValue;
|
|
|
|
int i = 0;
|
|
|
|
for (i = 0; i <= edge; i++) {
|
|
|
|
lut[i] = (int)((max / edge) * i);
|
|
|
|
}
|
|
|
|
for (i = edge + 1; i < PIXEL::maxChannelValue + 1; i++) {
|
|
|
|
lut[i] = (int)((max / (edge - aux)) * (i - aux));
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===================================================================
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class SolarizeFx final : public TStandardRasterFx {
|
2016-06-15 18:43:10 +12:00
|
|
|
FX_PLUGIN_DECLARATION(SolarizeFx)
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRasterFxPort m_input;
|
|
|
|
TDoubleParamP m_maximum;
|
|
|
|
TDoubleParamP m_edge;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
SolarizeFx() : m_maximum(1.0), m_edge(128.0) {
|
|
|
|
bindParam(this, "maximum", m_maximum);
|
|
|
|
bindParam(this, "peak_edge", m_edge);
|
|
|
|
addInputPort("Source", m_input);
|
|
|
|
// m_value->setValueRange(0, std::numeric_limits<double>::max());
|
|
|
|
m_maximum->setValueRange(0.0, 10.0);
|
|
|
|
m_edge->setValueRange(0.0, 255.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
~SolarizeFx(){};
|
|
|
|
|
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
|
|
|
};
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace {
|
2016-03-19 06:57:51 +13:00
|
|
|
template <typename T>
|
2016-06-15 18:43:10 +12:00
|
|
|
void update_param(T ¶m, TRaster32P ras) {
|
|
|
|
return;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2016-06-15 18:43:10 +12:00
|
|
|
void update_param(T ¶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 doSolarize(TRasterPT<PIXEL> ras, double max, int edge) {
|
|
|
|
std::vector<CHANNEL_TYPE> solarize_lut(PIXEL::maxChannelValue + 1);
|
|
|
|
|
|
|
|
update_param(max, ras);
|
|
|
|
update_param(edge, ras);
|
|
|
|
|
|
|
|
prepare_lut<CHANNEL_TYPE, PIXEL>(max, edge, solarize_lut);
|
|
|
|
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->r = (CHANNEL_TYPE)(solarize_lut[(int)(pix->r)]);
|
|
|
|
pix->g = (CHANNEL_TYPE)(solarize_lut[(int)(pix->g)]);
|
|
|
|
pix->b = (CHANNEL_TYPE)(solarize_lut[(int)(pix->b)]);
|
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 SolarizeFx::doCompute(TTile &tile, double frame,
|
|
|
|
const TRenderSettings &ri) {
|
|
|
|
if (!m_input.isConnected()) return;
|
|
|
|
|
|
|
|
m_input->compute(tile, frame, ri);
|
|
|
|
|
|
|
|
double min, max, step;
|
|
|
|
m_maximum->getValueRange(min, max, step);
|
|
|
|
double maxValue = 128 * tcrop(m_maximum->getValue(frame), min, max);
|
|
|
|
m_edge->getValueRange(min, max, step);
|
|
|
|
int edge = (int)tcrop(m_edge->getValue(frame), min, max);
|
|
|
|
|
|
|
|
TRaster32P raster32 = tile.getRaster();
|
|
|
|
if (raster32)
|
|
|
|
doSolarize<TPixel32, UCHAR>(raster32, maxValue, edge);
|
|
|
|
else {
|
|
|
|
TRaster64P raster64 = tile.getRaster();
|
|
|
|
if (raster64)
|
|
|
|
doSolarize<TPixel64, USHORT>(raster64, maxValue, edge);
|
|
|
|
else
|
|
|
|
throw TException("SolarizeFx: unsupported Pixel Type");
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
FX_PLUGIN_IDENTIFIER(SolarizeFx, "solarizeFx");
|