|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "stdfx.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tfxparam.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "ttzpimagefx.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "timage_io.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class TileFx final : public TStandardRasterFx {
|
|
Shinya Kitaoka |
120a6e |
FX_PLUGIN_DECLARATION(TileFx)
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
enum tilingMode { eTile = 1, eTileHorizontally = 2, eTileVertically = 3 };
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRasterFxPort m_input;
|
|
Shinya Kitaoka |
120a6e |
TIntEnumParamP m_mode;
|
|
Shinya Kitaoka |
120a6e |
TBoolParamP m_xMirror;
|
|
Shinya Kitaoka |
120a6e |
TBoolParamP m_yMirror;
|
|
Shinya Kitaoka |
120a6e |
TDoubleParamP m_margin;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
TileFx();
|
|
Shinya Kitaoka |
120a6e |
~TileFx();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
38fd86 |
bool doGetBBox(double frame, TRectD &bBox,
|
|
Shinya Kitaoka |
38fd86 |
const TRenderSettings &info) override;
|
|
Shinya Kitaoka |
473e70 |
bool canHandle(const TRenderSettings &info, double frame) override;
|
|
Shinya Kitaoka |
473e70 |
void doCompute(TTile &tile, double frame, const TRenderSettings &ri) override;
|
|
Shinya Kitaoka |
120a6e |
int getMemoryRequirement(const TRectD &rect, double frame,
|
|
Shinya Kitaoka |
473e70 |
const TRenderSettings &info) override;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void transform(double frame, int port, const TRectD &rectOnOutput,
|
|
Shinya Kitaoka |
120a6e |
const TRenderSettings &infoOnOutput, TRectD &rectOnInput,
|
|
Shinya Kitaoka |
473e70 |
TRenderSettings &infoOnInput) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Shinya Kitaoka |
120a6e |
void makeTile(const TTile &inputTile, const TTile &tile) const;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TileFx::TileFx()
|
|
Shinya Kitaoka |
120a6e |
: m_mode(new TIntEnumParam(eTile, "Tile"))
|
|
Shinya Kitaoka |
120a6e |
, m_xMirror(false)
|
|
Shinya Kitaoka |
120a6e |
, m_yMirror(false)
|
|
Shinya Kitaoka |
120a6e |
, m_margin(-1.0) {
|
|
Shinya Kitaoka |
120a6e |
m_margin->setMeasureName("fxLength");
|
|
Shinya Kitaoka |
120a6e |
addInputPort("Source", m_input);
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "mode", m_mode);
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "xMirror", m_xMirror);
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "yMirror", m_yMirror);
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "margin", m_margin);
|
|
Shinya Kitaoka |
120a6e |
m_mode->addItem(eTileHorizontally, "Tile Horizontally");
|
|
Shinya Kitaoka |
120a6e |
m_mode->addItem(eTileVertically, "Tile Vertically");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TileFx::~TileFx() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool TileFx::canHandle(const TRenderSettings &info, double frame) {
|
|
Shinya Kitaoka |
120a6e |
// Currently, only affines which transform the X and Y axis into themselves
|
|
Shinya Kitaoka |
120a6e |
// may
|
|
Shinya Kitaoka |
120a6e |
// be handled by this fx...
|
|
Shinya Kitaoka |
120a6e |
return (fabs(info.m_affine.a12) < 0.0001 &&
|
|
Shinya Kitaoka |
120a6e |
fabs(info.m_affine.a21) < 0.0001) ||
|
|
Shinya Kitaoka |
120a6e |
(fabs(info.m_affine.a11) < 0.0001 && fabs(info.m_affine.a22) < 0.0001);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool TileFx::doGetBBox(double frame, TRectD &bBox,
|
|
Shinya Kitaoka |
120a6e |
const TRenderSettings &info) {
|
|
Shinya Kitaoka |
120a6e |
if (m_input.isConnected()) {
|
|
Shinya Kitaoka |
120a6e |
bBox = TConsts::infiniteRectD;
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
bBox = TRectD();
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TileFx::transform(double frame, int port, const TRectD &rectOnOutput,
|
|
Shinya Kitaoka |
120a6e |
const TRenderSettings &infoOnOutput, TRectD &rectOnInput,
|
|
Shinya Kitaoka |
120a6e |
TRenderSettings &infoOnInput) {
|
|
Shinya Kitaoka |
120a6e |
infoOnInput = infoOnOutput;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRectD inputBox;
|
|
Shinya Kitaoka |
120a6e |
m_input->getBBox(frame, inputBox, infoOnOutput);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double scale = sqrt(fabs(infoOnOutput.m_affine.det()));
|
|
Shinya Kitaoka |
120a6e |
int margin = m_margin->getValue(frame) * scale;
|
|
Shinya Kitaoka |
120a6e |
inputBox = inputBox.enlarge(margin);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (inputBox.isEmpty()) {
|
|
Shinya Kitaoka |
120a6e |
rectOnInput.empty();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (inputBox == TConsts::infiniteRectD) {
|
|
Shinya Kitaoka |
120a6e |
infoOnInput = infoOnOutput;
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TDimensionD size(0, 0);
|
|
Shinya Kitaoka |
120a6e |
size.lx = tceil(inputBox.getLx());
|
|
Shinya Kitaoka |
120a6e |
size.ly = tceil(inputBox.getLy());
|
|
Shinya Kitaoka |
120a6e |
rectOnInput = TRectD(inputBox.getP00(), size);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int TileFx::getMemoryRequirement(const TRectD &rect, double frame,
|
|
Shinya Kitaoka |
120a6e |
const TRenderSettings &info) {
|
|
Shinya Kitaoka |
120a6e |
TRectD inputBox;
|
|
Shinya Kitaoka |
120a6e |
m_input->getBBox(frame, inputBox, info);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
double scale = sqrt(fabs(info.m_affine.det()));
|
|
Shinya Kitaoka |
120a6e |
int margin = m_margin->getValue(frame) * scale;
|
|
Shinya Kitaoka |
120a6e |
inputBox = inputBox.enlarge(margin);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return TRasterFx::memorySize(inputBox, info.m_bpp);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TileFx::doCompute(TTile &tile, double frame, const TRenderSettings &ri) {
|
|
Shinya Kitaoka |
120a6e |
if (!m_input.isConnected()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRectD inputBox;
|
|
Shinya Kitaoka |
120a6e |
m_input->getBBox(frame, inputBox, ri);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
double scale = sqrt(fabs(ri.m_affine.det()));
|
|
Shinya Kitaoka |
120a6e |
int margin = m_margin->getValue(frame) * scale;
|
|
Shinya Kitaoka |
120a6e |
inputBox = inputBox.enlarge(margin);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (inputBox.isEmpty()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (inputBox == TConsts::infiniteRectD) {
|
|
Shinya Kitaoka |
120a6e |
m_input->compute(tile, frame, ri);
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TDimension size(0, 0);
|
|
Shinya Kitaoka |
120a6e |
size.lx = tceil(inputBox.getLx());
|
|
Shinya Kitaoka |
120a6e |
size.ly = tceil(inputBox.getLy());
|
|
Shinya Kitaoka |
120a6e |
TTile inputTile;
|
|
Shinya Kitaoka |
120a6e |
m_input->allocateAndCompute(inputTile, inputBox.getP00(), size,
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster(), frame, ri);
|
|
Shinya Kitaoka |
120a6e |
makeTile(inputTile, tile);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//! Make the tile of the image contained in \b inputTile in \b tile
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
void TileFx::makeTile(const TTile &inputTile, const TTile &tile) const {
|
|
Shinya Kitaoka |
120a6e |
// Build the mirroring pattern. It obviously repeats itself out of 2x2 tile
|
|
Shinya Kitaoka |
120a6e |
// blocks.
|
|
Shinya Kitaoka |
120a6e |
std::map<std::pair<bool, bool="">, TRasterP> mirrorRaster;</std::pair<bool,>
|
|
Shinya Kitaoka |
120a6e |
mirrorRaster[std::pair<bool, bool="">(false, false)] = inputTile.getRaster();</bool,>
|
|
Shinya Kitaoka |
120a6e |
mirrorRaster[std::pair<bool, bool="">(false, true)] =</bool,>
|
|
Shinya Kitaoka |
120a6e |
inputTile.getRaster()->clone();
|
|
Shinya Kitaoka |
120a6e |
mirrorRaster[std::pair<bool, bool="">(false, true)]->yMirror();</bool,>
|
|
Shinya Kitaoka |
120a6e |
mirrorRaster[std::pair<bool, bool="">(true, false)] =</bool,>
|
|
Shinya Kitaoka |
120a6e |
inputTile.getRaster()->clone();
|
|
Shinya Kitaoka |
120a6e |
mirrorRaster[std::pair<bool, bool="">(true, false)]->xMirror();</bool,>
|
|
Shinya Kitaoka |
120a6e |
mirrorRaster[std::pair<bool, bool="">(true, true)] =</bool,>
|
|
Shinya Kitaoka |
120a6e |
mirrorRaster[std::pair<bool, bool="">(true, false)]->clone();</bool,>
|
|
Shinya Kitaoka |
120a6e |
mirrorRaster[std::pair<bool, bool="">(true, true)]->yMirror();</bool,>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPoint animatedPos = convert(inputTile.m_pos - tile.m_pos);
|
|
Shinya Kitaoka |
120a6e |
TDimension inSize = inputTile.getRaster()->getSize();
|
|
Shinya Kitaoka |
120a6e |
TDimension outSize = tile.getRaster()->getSize();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool mirrorX = false, mirrorY = false;
|
|
Shinya Kitaoka |
120a6e |
int mode = m_mode->getValue();
|
|
Shinya Kitaoka |
120a6e |
bool tileOrizontally = mode == 1 || mode == 2;
|
|
Shinya Kitaoka |
120a6e |
bool tileVertically = mode == 1 || mode == 3;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Reach the lower left tiling position
|
|
Shinya Kitaoka |
120a6e |
while (animatedPos.x > 0 && tileOrizontally) {
|
|
Shinya Kitaoka |
120a6e |
animatedPos.x -= inSize.lx;
|
|
Shinya Kitaoka |
120a6e |
mirrorX = !mirrorX;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
while (animatedPos.x + inSize.lx < 0 && tileOrizontally) {
|
|
Shinya Kitaoka |
120a6e |
animatedPos.x += inSize.lx;
|
|
Shinya Kitaoka |
120a6e |
mirrorX = !mirrorX;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
while (animatedPos.y > 0 && tileVertically) {
|
|
Shinya Kitaoka |
120a6e |
animatedPos.y -= inSize.ly;
|
|
Shinya Kitaoka |
120a6e |
mirrorY = !mirrorY;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
while (animatedPos.y + inSize.ly < 0 && tileVertically) {
|
|
Shinya Kitaoka |
120a6e |
animatedPos.y += inSize.ly;
|
|
Shinya Kitaoka |
120a6e |
mirrorY = !mirrorY;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
bool doMirroX = mirrorX, doMirroY = mirrorY;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Write the tiling blocks.
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->lock();
|
|
Shinya Kitaoka |
120a6e |
inputTile.getRaster()->lock();
|
|
Shinya Kitaoka |
120a6e |
TPoint startTilingPos = animatedPos;
|
|
Shinya Kitaoka |
120a6e |
do {
|
|
Shinya Kitaoka |
120a6e |
do {
|
|
Shinya Kitaoka |
120a6e |
std::pair<bool, bool=""> doMirror(doMirroX && m_xMirror->getValue(),</bool,>
|
|
Shinya Kitaoka |
120a6e |
doMirroY && m_yMirror->getValue());
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->copy(mirrorRaster[doMirror], startTilingPos);
|
|
Shinya Kitaoka |
120a6e |
startTilingPos.x += inSize.lx;
|
|
Shinya Kitaoka |
120a6e |
doMirroX = !doMirroX;
|
|
Shinya Kitaoka |
120a6e |
} while (startTilingPos.x < outSize.lx && tileOrizontally);
|
|
Shinya Kitaoka |
120a6e |
startTilingPos.y += inSize.ly;
|
|
Shinya Kitaoka |
120a6e |
startTilingPos.x = animatedPos.x;
|
|
Shinya Kitaoka |
120a6e |
doMirroY = !doMirroY;
|
|
Shinya Kitaoka |
120a6e |
doMirroX = mirrorX;
|
|
Shinya Kitaoka |
120a6e |
} while (startTilingPos.y < outSize.ly && tileVertically);
|
|
Shinya Kitaoka |
120a6e |
inputTile.getRaster()->unlock();
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FX_PLUGIN_IDENTIFIER(TileFx, "tileFx");
|