|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "stdfx.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tfxparam.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tdoubleparam.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "tnotanimatableparam.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelgr.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trasterfx.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
enum Status {
|
|
Toshihiro Shimizu |
890ddd |
StatusGood = 0,
|
|
Toshihiro Shimizu |
890ddd |
OutOfTime = 1 << 1, //Non utilizzato
|
|
Toshihiro Shimizu |
890ddd |
Port0NotConnected = 1 << 2,
|
|
Toshihiro Shimizu |
890ddd |
Port1NotConnected = 1 << 3,
|
|
Toshihiro Shimizu |
890ddd |
NoPortsConnected = Port0NotConnected | Port1NotConnected
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
inline Status operator|(const Status &l, const Status &r)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Status(((int)l | (int)r));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
inline int operator&(const Status &l)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return int(l);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
Status getFxStatus(const TRasterFxPort &port0, const TRasterFxPort &port1)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Status status = StatusGood;
|
|
Toshihiro Shimizu |
890ddd |
if (!port0.isConnected())
|
|
Toshihiro Shimizu |
890ddd |
status = status | Port0NotConnected;
|
|
Toshihiro Shimizu |
890ddd |
if (!port1.isConnected())
|
|
Toshihiro Shimizu |
890ddd |
status = status | Port1NotConnected;
|
|
Toshihiro Shimizu |
890ddd |
return status;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*inline*/
|
|
Toshihiro Shimizu |
890ddd |
template <typename p="" q,="" t,="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
void doLocalTransparency(TRasterPT<t> out, TRasterPT<t> src, TRasterPT<t> ref, double transp)</t></t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
out->lock();
|
|
Toshihiro Shimizu |
890ddd |
ref->lock();
|
|
Toshihiro Shimizu |
890ddd |
src->lock();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T *outRow = out->pixels();
|
|
Toshihiro Shimizu |
890ddd |
T *refRow = ref->pixels();
|
|
Toshihiro Shimizu |
890ddd |
T *srcRow = src->pixels();
|
|
Toshihiro Shimizu |
890ddd |
int outWrap = out->getWrap();
|
|
Toshihiro Shimizu |
890ddd |
int refWrap = ref->getWrap();
|
|
Toshihiro Shimizu |
890ddd |
int srcWrap = src->getWrap();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T *outPix = outRow;
|
|
Toshihiro Shimizu |
890ddd |
T *srcPix = srcRow;
|
|
Toshihiro Shimizu |
890ddd |
T *refPix = refRow;
|
|
Toshihiro Shimizu |
890ddd |
T *lastPix = outRow + outWrap * out->getLy();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const int cropVal = T::maxChannelValue;
|
|
Toshihiro Shimizu |
890ddd |
double factor = transp / (double)cropVal;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (outPix < lastPix) {
|
|
Toshihiro Shimizu |
890ddd |
T *endPix = outPix + out->getLx();
|
|
Toshihiro Shimizu |
890ddd |
while (outPix < endPix) {
|
|
Toshihiro Shimizu |
890ddd |
double local_transp = 1 - (Q::from(*refPix).value) * factor;
|
|
Toshihiro Shimizu |
890ddd |
if (local_transp > 0.0) {
|
|
Toshihiro Shimizu |
890ddd |
int val = (int)(local_transp * srcPix->r + 0.5);
|
|
Toshihiro Shimizu |
890ddd |
outPix->r = (P)((val < cropVal) ? val : cropVal);
|
|
Toshihiro Shimizu |
890ddd |
val = (int)(local_transp * srcPix->g + 0.5);
|
|
Toshihiro Shimizu |
890ddd |
outPix->g = (P)((val < cropVal) ? val : cropVal);
|
|
Toshihiro Shimizu |
890ddd |
val = (int)(local_transp * srcPix->b + 0.5);
|
|
Toshihiro Shimizu |
890ddd |
outPix->b = (P)((val < cropVal) ? val : cropVal);
|
|
Toshihiro Shimizu |
890ddd |
val = (int)(local_transp * srcPix->m + 0.5);
|
|
Toshihiro Shimizu |
890ddd |
outPix->m = (P)((val < cropVal) ? val : cropVal);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
outPix->r = outPix->g = outPix->b = outPix->m = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
++outPix;
|
|
Toshihiro Shimizu |
890ddd |
++refPix;
|
|
Toshihiro Shimizu |
890ddd |
++srcPix;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
srcRow += srcWrap;
|
|
Toshihiro Shimizu |
890ddd |
outRow += outWrap;
|
|
Toshihiro Shimizu |
890ddd |
refRow += refWrap;
|
|
Toshihiro Shimizu |
890ddd |
srcPix = srcRow;
|
|
Toshihiro Shimizu |
890ddd |
outPix = outRow;
|
|
Toshihiro Shimizu |
890ddd |
refPix = refRow;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
out->unlock();
|
|
Toshihiro Shimizu |
890ddd |
ref->unlock();
|
|
Toshihiro Shimizu |
890ddd |
src->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline double func(int x, int y, int lx, int ly)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return ((1 + sin(3.14 * x / (0.5 * lx))) * (1 + cos(3.14 * y / (0.5 * ly))));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void drawCheckboard(TRaster32P &raster)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int lx = raster->getLx();
|
|
Toshihiro Shimizu |
890ddd |
int ly = raster->getLy();
|
|
Toshihiro Shimizu |
890ddd |
//int chessSize = 4;
|
|
Toshihiro Shimizu |
890ddd |
int x, y;
|
|
Toshihiro Shimizu |
890ddd |
raster->lock();
|
|
Toshihiro Shimizu |
890ddd |
for (y = 0; y < ly; ++y) {
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 *pix = raster->pixels(y);
|
|
Toshihiro Shimizu |
890ddd |
for (x = 0; x < lx; ++x, ++pix) {
|
|
Toshihiro Shimizu |
890ddd |
pix->r = pix->g = pix->b = troundp(255.0 * func(x, y, lx, ly) / func(lx - 1, ly - 1, lx, ly));
|
|
Toshihiro Shimizu |
890ddd |
pix->m = 255;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
raster->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class LocalTransparencyFx : public TStandardRasterFx
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
FX_PLUGIN_DECLARATION(LocalTransparencyFx)
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Toshihiro Shimizu |
890ddd |
TRasterFxPort m_src, m_ref;
|
|
Toshihiro Shimizu |
890ddd |
TDoubleParamP m_value;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
LocalTransparencyFx()
|
|
Toshihiro Shimizu |
890ddd |
: m_value(100)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
addInputPort("Source", m_src);
|
|
Toshihiro Shimizu |
890ddd |
addInputPort("Reference", m_ref);
|
|
Toshihiro Shimizu |
890ddd |
bindParam(this, "value", m_value);
|
|
Toshihiro Shimizu |
890ddd |
m_value->setValueRange(0, 100);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
virtual ~LocalTransparencyFx() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_src.isConnected())
|
|
Toshihiro Shimizu |
890ddd |
return m_src->doGetBBox(frame, bBox, info);
|
|
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 |
if (!checkBeforeCompute(tile, frame, ri))
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
TTile srcTile;
|
|
Toshihiro Shimizu |
890ddd |
m_src->allocateAndCompute(srcTile, tile.m_pos, tile.getRaster()->getSize(), tile.getRaster(), frame, ri);
|
|
Toshihiro Shimizu |
890ddd |
//TTile refTile = tile;
|
|
Toshihiro Shimizu |
890ddd |
m_ref->compute(tile, frame, ri);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//TRaster32P ref32 (refTile.getRaster());
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P out32(tile.getRaster());
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P src32(srcTile.getRaster());
|
|
Toshihiro Shimizu |
890ddd |
if (out32 && src32)
|
|
Toshihiro Shimizu |
890ddd |
doLocalTransparency<tpixelrgbm32, tpixelgr8,="" uchar="">(out32, src32, out32, m_value->getValue(frame) / 100.);</tpixelrgbm32,>
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
//TRaster64P ref64(refTile.getRaster());
|
|
Toshihiro Shimizu |
890ddd |
TRaster64P out64(tile.getRaster());
|
|
Toshihiro Shimizu |
890ddd |
TRaster64P src64(srcTile.getRaster());
|
|
Toshihiro Shimizu |
890ddd |
if (out64 && src64)
|
|
Toshihiro Shimizu |
890ddd |
doLocalTransparency<tpixelrgbm64, tpixelgr16,="" ushort="">(out64, src64, out64, m_value->getValue(frame) / 100.);</tpixelrgbm64,>
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
throw TException("LocalTransparencyFx: unsupported raster type");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool checkBeforeCompute(TTile &tile, double frame, const TRenderSettings &info)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Status status = getFxStatus(m_src, m_ref);
|
|
Toshihiro Shimizu |
890ddd |
if ((status & NoPortsConnected) == NoPortsConnected)
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if ((status & OutOfTime) == OutOfTime)
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if ((status & Port0NotConnected) == Port0NotConnected)
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if ((status & Port1NotConnected) == Port1NotConnected) {
|
|
Toshihiro Shimizu |
890ddd |
m_src->compute(tile, frame, info);
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
assert(status == StatusGood);
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool canHandle(const TRenderSettings &info, double frame) { return true; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int getMemoryRequirement(const TRectD &rect, double frame, const TRenderSettings &info)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TRasterFx::memorySize(rect, info.m_bpp);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FX_PLUGIN_IDENTIFIER(LocalTransparencyFx, "localTransparencyFx")
|