|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "texception.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tfxparam.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "stdfx.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixel="" t,="" typename=""></typename>
|
|
Shinya Kitaoka |
3bfa54 |
void prepare_lut(double max, int edge, std::vector<t> &lut)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double aux = (double)PIXEL::maxChannelValue;
|
|
Toshihiro Shimizu |
890ddd |
int i = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i <= edge; i++) {
|
|
Toshihiro Shimizu |
890ddd |
lut[i] = (int)((max / edge) * i);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
for (i = edge + 1; i < PIXEL::maxChannelValue + 1; i++) {
|
|
Toshihiro Shimizu |
890ddd |
lut[i] = (int)((max / (edge - aux)) * (i - aux));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class SolarizeFx : public TStandardRasterFx
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
FX_PLUGIN_DECLARATION(SolarizeFx)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterFxPort m_input;
|
|
Toshihiro Shimizu |
890ddd |
TDoubleParamP m_maximum;
|
|
Toshihiro Shimizu |
890ddd |
TDoubleParamP m_edge;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
SolarizeFx()
|
|
Toshihiro Shimizu |
890ddd |
: m_maximum(1.0), m_edge(128.0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bindParam(this, "maximum", m_maximum);
|
|
Toshihiro Shimizu |
890ddd |
bindParam(this, "peak_edge", m_edge);
|
|
Toshihiro Shimizu |
890ddd |
addInputPort("Source", m_input);
|
|
Toshihiro Shimizu |
890ddd |
//m_value->setValueRange(0, std::numeric_limits<double>::max());</double>
|
|
Toshihiro Shimizu |
890ddd |
m_maximum->setValueRange(0.0, 10.0);
|
|
Toshihiro Shimizu |
890ddd |
m_edge->setValueRange(0.0, 255.0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~SolarizeFx(){};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_input.isConnected()) {
|
|
Toshihiro Shimizu |
890ddd |
bool ret = m_input->doGetBBox(frame, bBox, info);
|
|
Toshihiro Shimizu |
890ddd |
return ret;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
bBox = TRectD();
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void doCompute(TTile &tile, double frame, const TRenderSettings &ri);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool canHandle(const TRenderSettings &info, double frame) { return true; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
template <typename t=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
void update_param(T ¶m, TRaster32P ras)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename t=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
void update_param(T ¶m, TRaster64P ras)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
param = param * 257;
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename channel_type="" pixel,="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
void doSolarize(TRasterPT<pixel> ras, double max, int edge)</pixel>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<channel_type> solarize_lut(PIXEL::maxChannelValue + 1);</channel_type>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
update_param(max, ras);
|
|
Toshihiro Shimizu |
890ddd |
update_param(edge, ras);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
prepare_lut<channel_type, pixel="">(max, edge, solarize_lut);</channel_type,>
|
|
Toshihiro Shimizu |
890ddd |
int j;
|
|
Toshihiro Shimizu |
890ddd |
ras->lock();
|
|
Toshihiro Shimizu |
890ddd |
for (j = 0; j < ras->getLy(); j++) {
|
|
Toshihiro Shimizu |
890ddd |
PIXEL *pix = ras->pixels(j);
|
|
Toshihiro Shimizu |
890ddd |
PIXEL *endPix = pix + ras->getLx();
|
|
Toshihiro Shimizu |
890ddd |
while (pix < endPix) {
|
|
Toshihiro Shimizu |
890ddd |
pix->r = (CHANNEL_TYPE)(solarize_lut[(int)(pix->r)]);
|
|
Toshihiro Shimizu |
890ddd |
pix->g = (CHANNEL_TYPE)(solarize_lut[(int)(pix->g)]);
|
|
Toshihiro Shimizu |
890ddd |
pix->b = (CHANNEL_TYPE)(solarize_lut[(int)(pix->b)]);
|
|
Toshihiro Shimizu |
890ddd |
*pix++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
ras->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void SolarizeFx::doCompute(TTile &tile, double frame, const TRenderSettings &ri)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_input.isConnected())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_input->compute(tile, frame, ri);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double min, max, step;
|
|
Toshihiro Shimizu |
890ddd |
m_maximum->getValueRange(min, max, step);
|
|
Toshihiro Shimizu |
890ddd |
double maxValue = 128 * tcrop(m_maximum->getValue(frame), min, max);
|
|
Toshihiro Shimizu |
890ddd |
m_edge->getValueRange(min, max, step);
|
|
Toshihiro Shimizu |
890ddd |
int edge = (int)tcrop(m_edge->getValue(frame), min, max);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P raster32 = tile.getRaster();
|
|
Toshihiro Shimizu |
890ddd |
if (raster32)
|
|
Toshihiro Shimizu |
890ddd |
doSolarize<tpixel32, uchar="">(raster32, maxValue, edge);</tpixel32,>
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TRaster64P raster64 = tile.getRaster();
|
|
Toshihiro Shimizu |
890ddd |
if (raster64)
|
|
Toshihiro Shimizu |
890ddd |
doSolarize<tpixel64, ushort="">(raster64, maxValue, edge);</tpixel64,>
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
throw TException("SolarizeFx: unsupported Pixel Type");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FX_PLUGIN_IDENTIFIER(SolarizeFx, "solarizeFx");
|