|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "texception.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "stdfx.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelutils.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class BacklitFx : public TStandardRasterFx
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
FX_PLUGIN_DECLARATION(BacklitFx)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterFxPort m_input;
|
|
Toshihiro Shimizu |
890ddd |
//TDoubleParamP m_value;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
BacklitFx()
|
|
Toshihiro Shimizu |
890ddd |
// , m_value (args, "Blur")
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//m_value->setDefaultValue(100);
|
|
Toshihiro Shimizu |
890ddd |
addInputPort("Source", m_input);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~BacklitFx(){};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool doGetBBox(double frame, TRectD &bBox);
|
|
Toshihiro Shimizu |
890ddd |
void doCompute(TTile &tile, double frame, const TRenderSettings &ri);
|
|
Toshihiro Shimizu |
890ddd |
int getMemoryRequirement(const TRectD &rect, double frame, const TRenderSettings &info);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect getInvalidRect(const TRect &max);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool BacklitFx::doGetBBox(double frame, TRectD &bBox)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_input.isConnected()) {
|
|
Toshihiro Shimizu |
890ddd |
bool ret = m_input->doGetBBox(frame, bBox);
|
|
Toshihiro Shimizu |
890ddd |
// devo scurire bgColor
|
|
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 |
//===================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
void computeBacklit(TRasterPT<t> dst,</t>
|
|
Toshihiro Shimizu |
890ddd |
TRasterPT<t> src,</t>
|
|
Toshihiro Shimizu |
890ddd |
const TPoint &srcPos,
|
|
Toshihiro Shimizu |
890ddd |
// cordinate di src[0,0] rispetto a dst;
|
|
Toshihiro Shimizu |
890ddd |
// in genere srcPos.x,.y <= 0
|
|
Toshihiro Shimizu |
890ddd |
const TPoint ¢er
|
|
Toshihiro Shimizu |
890ddd |
// coordinate della sorgente di luce rispetto a dst;
|
|
Toshihiro Shimizu |
890ddd |
)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//TRect srcRect = src->getBounds() + srcPos;
|
|
Toshihiro Shimizu |
890ddd |
//assert(srcRect.contains(dst->getBounds()));
|
|
Toshihiro Shimizu |
890ddd |
//assert(srcRect.contains(center));
|
|
Toshihiro Shimizu |
890ddd |
UINT max = T::maxChannelValue;
|
|
Toshihiro Shimizu |
890ddd |
dst->lock();
|
|
Toshihiro Shimizu |
890ddd |
for (int x = 0; x < dst->getLx(); x++)
|
|
Toshihiro Shimizu |
890ddd |
for (int y = 0; y < dst->getLy(); y++) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int dx = x - center.x;
|
|
Toshihiro Shimizu |
890ddd |
int dy = y - center.y;
|
|
Toshihiro Shimizu |
890ddd |
int dist = (int)sqrt((float)(dx * dx + dy * dy));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int d = tmin(100, dist) + 1;
|
|
Toshihiro Shimizu |
890ddd |
double value = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i <= d; i++) {
|
|
Toshihiro Shimizu |
890ddd |
int xx = center.x + (x - center.x) * i / d - srcPos.x;
|
|
Toshihiro Shimizu |
890ddd |
int yy = center.y + (y - center.y) * i / d - srcPos.y;
|
|
Toshihiro Shimizu |
890ddd |
assert(src->getBounds().contains(TPoint(xx, yy)));
|
|
Toshihiro Shimizu |
890ddd |
value += (max - src->pixels(yy)[xx].m) * 2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
value = value / dist;
|
|
Toshihiro Shimizu |
890ddd |
// double value = sin(dist)<0?0:255;
|
|
Toshihiro Shimizu |
890ddd |
int v = tcrop((int)value, 0, (int)max);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int srcX = -srcPos.x + x;
|
|
Toshihiro Shimizu |
890ddd |
int srcY = -srcPos.y + y;
|
|
Toshihiro Shimizu |
890ddd |
T srcPix(0, 0, 0, 0);
|
|
Toshihiro Shimizu |
890ddd |
if (src->getBounds().contains(TPoint(srcX, srcY)))
|
|
Toshihiro Shimizu |
890ddd |
srcPix = src->pixels(srcY)[srcX];
|
|
Toshihiro Shimizu |
890ddd |
srcPix.r = srcPix.r * (max - v) / max;
|
|
Toshihiro Shimizu |
890ddd |
srcPix.g = srcPix.g * (max - v) / max;
|
|
Toshihiro Shimizu |
890ddd |
srcPix.b = srcPix.b * (max - v) / max;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
dst->pixels(y)[x] = overPix(srcPix, T(v, v, v, v / 2));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
dst->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BacklitFx::doCompute(TTile &tile, double frame, const TRenderSettings &ri)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_input.isConnected()) {
|
|
Toshihiro Shimizu |
890ddd |
tile.getRaster()->clear();
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
TTile srcTile;
|
|
Toshihiro Shimizu |
890ddd |
srcTile.m_pos = tile.m_pos;
|
|
Toshihiro Shimizu |
890ddd |
TPoint srcPos(0, 0);
|
|
Toshihiro Shimizu |
890ddd |
TDimension srcSize = tile.getRaster()->getSize();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPoint center(-(int)tile.m_pos.x, -(int)tile.m_pos.y);
|
|
Toshihiro Shimizu |
890ddd |
center += TPoint(10, 10);
|
|
Toshihiro Shimizu |
890ddd |
if (center.x < 0) {
|
|
Toshihiro Shimizu |
890ddd |
srcSize.lx += -center.x;
|
|
Toshihiro Shimizu |
890ddd |
srcPos.x += center.x;
|
|
Toshihiro Shimizu |
890ddd |
srcTile.m_pos.x += center.x;
|
|
Toshihiro Shimizu |
890ddd |
} else if (center.x >= srcSize.lx) {
|
|
Toshihiro Shimizu |
890ddd |
srcSize.lx += center.x - srcSize.lx + 1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (center.y < 0) {
|
|
Toshihiro Shimizu |
890ddd |
srcSize.ly += -center.y;
|
|
Toshihiro Shimizu |
890ddd |
srcPos.y += center.y;
|
|
Toshihiro Shimizu |
890ddd |
srcTile.m_pos.y += center.y;
|
|
Toshihiro Shimizu |
890ddd |
} else if (center.y >= srcSize.ly) {
|
|
Toshihiro Shimizu |
890ddd |
srcSize.ly += center.y - srcSize.ly + 1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if ((TRaster32P)tile.getRaster()) {
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P src = TRaster32P(srcSize);
|
|
Toshihiro Shimizu |
890ddd |
src->clear();
|
|
Toshihiro Shimizu |
890ddd |
srcTile.getRaster() = src;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_input->compute(srcTile, frame, ri);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P dst = tile.getRaster();
|
|
Toshihiro Shimizu |
890ddd |
assert(dst);
|
|
Toshihiro Shimizu |
890ddd |
computeBacklit<tpixel32>(dst, src, srcPos, center);</tpixel32>
|
|
Toshihiro Shimizu |
890ddd |
} else if ((TRaster64P)tile.getRaster()) {
|
|
Toshihiro Shimizu |
890ddd |
TRaster64P src = TRaster64P(srcSize);
|
|
Toshihiro Shimizu |
890ddd |
src->clear();
|
|
Toshihiro Shimizu |
890ddd |
srcTile.getRaster() = src;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_input->compute(srcTile, frame, ri);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster64P dst = tile.getRaster();
|
|
Toshihiro Shimizu |
890ddd |
assert(dst);
|
|
Toshihiro Shimizu |
890ddd |
computeBacklit<tpixel64>(dst, src, srcPos, center);</tpixel64>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//dst->copy(src,srcPos);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int BacklitFx::getMemoryRequirement(const TRectD &rect, double frame, const TRenderSettings &info)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TRasterFx::memorySize(rect, frame, info);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect BacklitFx::getInvalidRect(const TRect &max)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_input.isConnected())
|
|
Toshihiro Shimizu |
890ddd |
return TRect();
|
|
Toshihiro Shimizu |
890ddd |
TRect rect = m_input->getInvalidRect(max);
|
|
Toshihiro Shimizu |
890ddd |
TRect ris = max;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (rect.x0 >= 0)
|
|
Toshihiro Shimizu |
890ddd |
ris.x0 = tmin(rect.x0, max.x1);
|
|
Toshihiro Shimizu |
890ddd |
else if (rect.x1 <= 0)
|
|
Toshihiro Shimizu |
890ddd |
ris.x1 = tmax(rect.x1, max.x0);
|
|
Toshihiro Shimizu |
890ddd |
if (rect.y0 >= 0)
|
|
Toshihiro Shimizu |
890ddd |
ris.y0 = tmin(rect.y0, max.y1);
|
|
Toshihiro Shimizu |
890ddd |
else if (rect.y1 <= 0)
|
|
Toshihiro Shimizu |
890ddd |
ris.y1 = tmax(rect.y1, max.y0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return ris;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//FX_PLUGIN_IDENTIFIER(BacklitFx , "backlitFx")
|