Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tbasefx.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tdoubleparam.h"
Toshihiro Shimizu 890ddd
#include "tnotanimatableparam.h"
Toshihiro Shimizu 890ddd
#include "trasterfx.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
shun_iwasawa 2c0f50
#include "tparamset.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#define ALLOW_SHEAR
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TGeometryFx::TGeometryFx() { setName(L"Geometry"); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TGeometryFx::doCompute(TTile &tile, double frame,
Shinya Kitaoka 120a6e
                            const TRenderSettings &ri) {
Shinya Kitaoka 120a6e
  TRasterFxPort *input = dynamic_cast<trasterfxport *="">(getInputPort(0));</trasterfxport>
Shinya Kitaoka 120a6e
  assert(input);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!input->isConnected()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!getActiveTimeRegion().contains(frame)) {
Shinya Kitaoka 120a6e
    TRasterFxP(input->getFx())->compute(tile, frame, ri);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!TRaster32P(tile.getRaster()) && !TRaster64P(tile.getRaster()))
Shinya Kitaoka 120a6e
    throw TException("AffineFx unsupported pixel type");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TAffine aff1 = getPlacement(frame);
Shinya Kitaoka 120a6e
  TRenderSettings ri2(ri);
Shinya Kitaoka 120a6e
  ri2.m_affine = ri2.m_affine * aff1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRasterFxP src = getInputPort("source")->getFx();
Shinya Kitaoka 120a6e
  src->compute(tile, frame, ri2);
Shinya Kitaoka 120a6e
  return;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TGeometryFx::doGetBBox(double frame, TRectD &bBox,
Shinya Kitaoka 120a6e
                            const TRenderSettings &info) {
Shinya Kitaoka 120a6e
  TRasterFxPort *input = dynamic_cast<trasterfxport *="">(getInputPort(0));</trasterfxport>
Shinya Kitaoka 120a6e
  assert(input);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (input->isConnected()) {
Shinya Kitaoka 120a6e
    TRasterFxP fx = input->getFx();
Shinya Kitaoka 120a6e
    assert(fx);
Shinya Kitaoka 120a6e
    bool ret = fx->doGetBBox(frame, bBox, info);
Shinya Kitaoka 120a6e
    if (getActiveTimeRegion().contains(frame))
Shinya Kitaoka 120a6e
      bBox = getPlacement(frame) * bBox;
Shinya Kitaoka 120a6e
    return ret;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    bBox = TRectD();
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::string TGeometryFx::getAlias(double frame,
Shinya Kitaoka 120a6e
                                  const TRenderSettings &info) const {
Shinya Kitaoka 120a6e
  TGeometryFx *tthis = const_cast<tgeometryfx *="">(this);</tgeometryfx>
Shinya Kitaoka 120a6e
  TAffine affine     = tthis->getPlacement(frame);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::string alias = getFxType();
Shinya Kitaoka 120a6e
  alias += "[";
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // alias degli effetti connessi alle porte di input separati da virgole
Shinya Kitaoka 120a6e
  // una porta non connessa da luogo a un alias vuoto (stringa vuota)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int i = 0; i < getInputPortCount(); ++i) {
Shinya Kitaoka 120a6e
    TFxPort *port = getInputPort(i);
Shinya Kitaoka 120a6e
    if (port->isConnected()) {
Shinya Kitaoka 120a6e
      TRasterFxP ifx = port->getFx();
Shinya Kitaoka 120a6e
      assert(ifx);
Shinya Kitaoka 120a6e
      alias += ifx->getAlias(frame, info);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    alias += ",";
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return alias +
Shinya Kitaoka 120a6e
         (areAlmostEqual(affine.a11, 0) ? "0" : ::to_string(affine.a11, 5)) +
Shinya Kitaoka 120a6e
         "," +
Shinya Kitaoka 120a6e
         (areAlmostEqual(affine.a12, 0) ? "0" : ::to_string(affine.a12, 5)) +
Shinya Kitaoka 120a6e
         "," +
Shinya Kitaoka 120a6e
         (areAlmostEqual(affine.a13, 0) ? "0" : ::to_string(affine.a13, 5)) +
Shinya Kitaoka 120a6e
         "," +
Shinya Kitaoka 120a6e
         (areAlmostEqual(affine.a21, 0) ? "0" : ::to_string(affine.a21, 5)) +
Shinya Kitaoka 120a6e
         "," +
Shinya Kitaoka 120a6e
         (areAlmostEqual(affine.a22, 0) ? "0" : ::to_string(affine.a22, 5)) +
Shinya Kitaoka 120a6e
         "," +
Shinya Kitaoka 120a6e
         (areAlmostEqual(affine.a23, 0) ? "0" : ::to_string(affine.a23, 5)) +
Shinya Kitaoka 120a6e
         "]";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TGeometryFx::transform(double frame, int port, const TRectD &rectOnOutput,
Shinya Kitaoka 120a6e
                            const TRenderSettings &infoOnOutput,
Shinya Kitaoka 120a6e
                            TRectD &rectOnInput, TRenderSettings &infoOnInput) {
Shinya Kitaoka 120a6e
  rectOnInput = rectOnOutput;
Shinya Kitaoka 120a6e
  TAffine aff = getPlacement(frame);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  infoOnInput          = infoOnOutput;
Shinya Kitaoka 120a6e
  infoOnInput.m_affine = infoOnInput.m_affine * aff;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
NaAffineFx::NaAffineFx(bool isDpiAffine)
Shinya Kitaoka 120a6e
    : m_aff(TAffine()), m_isDpiAffine(isDpiAffine) {
Shinya Kitaoka 120a6e
  addInputPort("source", m_port);
Shinya Kitaoka 120a6e
  setName(L"Geometry-NaAffineFx");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFx *NaAffineFx::clone(bool recursive) const {
Shinya Kitaoka 120a6e
  NaAffineFx *clonedFx = dynamic_cast<naaffinefx *="">(TFx::clone(recursive));</naaffinefx>
Shinya Kitaoka 120a6e
  assert(clonedFx);
Shinya Kitaoka 120a6e
  clonedFx->m_aff         = m_aff;
Shinya Kitaoka 120a6e
  clonedFx->m_isDpiAffine = m_isDpiAffine;
Shinya Kitaoka 120a6e
  return clonedFx;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_IDENTIFIER_IS_HIDDEN(NaAffineFx, "naAffineFx")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
shun_iwasawa 2c0f50
//  ColumnColorFilterFx
shun_iwasawa 2c0f50
//==================================================================
shun_iwasawa 2c0f50
shun_iwasawa 2c0f50
ColumnColorFilterFx::ColumnColorFilterFx() : m_colorFilter(TPixel::Black) {
shun_iwasawa 2c0f50
  setName(L"ColumnColorFilterFx");
shun_iwasawa 2c0f50
  addInputPort("source", m_port);
shun_iwasawa 2c0f50
}
shun_iwasawa 2c0f50
shun_iwasawa 2c0f50
bool ColumnColorFilterFx::doGetBBox(double frame, TRectD &bBox,
shun_iwasawa 2c0f50
                                    const TRenderSettings &info) {
shun_iwasawa 2c0f50
  if (!m_port.isConnected()) return false;
shun_iwasawa 2c0f50
  TRasterFxP fx = m_port.getFx();
shun_iwasawa 2c0f50
  assert(fx);
shun_iwasawa 2c0f50
  bool ret = fx->doGetBBox(frame, bBox, info);
shun_iwasawa 2c0f50
  return ret;
shun_iwasawa 2c0f50
}
shun_iwasawa 2c0f50
shun_iwasawa 2c0f50
void ColumnColorFilterFx::doCompute(TTile &tile, double frame,
shun_iwasawa 2c0f50
                                    const TRenderSettings &ri) {
shun_iwasawa 2c0f50
  if (!m_port.isConnected()) return;
shun_iwasawa 2c0f50
shun_iwasawa 2c0f50
  if (!TRaster32P(tile.getRaster()) && !TRaster64P(tile.getRaster()))
shun_iwasawa 2c0f50
    throw TException("AffineFx unsupported pixel type");
shun_iwasawa 2c0f50
shun_iwasawa 2c0f50
  TRasterFxP src = m_port.getFx();
shun_iwasawa 2c0f50
  src->compute(tile, frame, ri);
shun_iwasawa 2c0f50
shun_iwasawa 2c0f50
  TRop::applyColorScale(tile.getRaster(), m_colorFilter);
shun_iwasawa 2c0f50
}
shun_iwasawa 2c0f50
shun_iwasawa 2c0f50
std::string ColumnColorFilterFx::getAlias(double frame,
shun_iwasawa 2c0f50
                                          const TRenderSettings &info) const {
shun_iwasawa 2c0f50
  std::string alias = getFxType();
shun_iwasawa 2c0f50
  alias += "[";
shun_iwasawa 2c0f50
  if (m_port.isConnected()) {
shun_iwasawa 2c0f50
    TRasterFxP ifx = m_port.getFx();
shun_iwasawa 2c0f50
    assert(ifx);
shun_iwasawa 2c0f50
    alias += ifx->getAlias(frame, info);
shun_iwasawa 2c0f50
  }
shun_iwasawa 2c0f50
  alias += ",";
shun_iwasawa 2c0f50
shun_iwasawa 2c0f50
  return alias + std::to_string(m_colorFilter.r) + "," +
shun_iwasawa 2c0f50
         std::to_string(m_colorFilter.g) + "," +
shun_iwasawa 2c0f50
         std::to_string(m_colorFilter.b) + "," +
shun_iwasawa 2c0f50
         std::to_string(m_colorFilter.m) + "]";
shun_iwasawa 2c0f50
}
shun_iwasawa 2c0f50
shun_iwasawa 2c0f50
//--------------------------------------------------
shun_iwasawa 2c0f50
shun_iwasawa 2c0f50
FX_IDENTIFIER_IS_HIDDEN(ColumnColorFilterFx, "columnColorFilterFx")
shun_iwasawa 2c0f50
shun_iwasawa 2c0f50
//==================================================================
Toshihiro Shimizu 890ddd
//  Geometric Fx
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class InvertFx final : public TBaseRasterFx {
Shinya Kitaoka 120a6e
  FX_DECLARATION(InvertFx)
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Shinya Kitaoka 120a6e
  TBoolParamP m_redChan, m_greenChan, m_blueChan, m_alphaChan;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  InvertFx()
Shinya Kitaoka 120a6e
      : m_redChan(true)
Shinya Kitaoka 120a6e
      , m_greenChan(true)
Shinya Kitaoka 120a6e
      , m_blueChan(true)
Shinya Kitaoka 120a6e
      , m_alphaChan(false) {
Shinya Kitaoka 120a6e
    addInputPort("source", m_input);
Shinya Kitaoka 120a6e
    //   bindParam(this, "red_channel"  , m_redChan);
Shinya Kitaoka 120a6e
    //   bindParam(this, "green_channel", m_greenChan);
Shinya Kitaoka 120a6e
    //   bindParam(this, "blue_channel" , m_blueChan);
Shinya Kitaoka 120a6e
    //   bindParam(this, "alpha_channel", m_alphaChan);
Shinya Kitaoka 120a6e
    setName(L"InvertFx");
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~InvertFx(){};
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  bool canHandle(const TRenderSettings &info, double frame) override {
Shinya Kitaoka 38fd86
    return true;
Shinya Kitaoka 38fd86
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  bool doGetBBox(double frame, TRectD &bBox,
Shinya Kitaoka 38fd86
                 const TRenderSettings &info) override {
Shinya Kitaoka 120a6e
    if (m_input.isConnected()) {
Shinya Kitaoka 120a6e
      bool ret = m_input->doGetBBox(frame, bBox, info);
Shinya Kitaoka 120a6e
      return ret;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      bBox = TRectD();
Shinya Kitaoka 120a6e
      return false;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  void doCompute(TTile &tile, double frame,
Shinya Kitaoka 38fd86
                 const TRenderSettings &ri) override {
Shinya Kitaoka 120a6e
    if (!m_input.isConnected()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_input->compute(tile, frame, ri);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TRop::invert(tile.getRaster(), m_redChan->getValue(),
Shinya Kitaoka 120a6e
                 m_greenChan->getValue(), m_blueChan->getValue(),
Shinya Kitaoka 120a6e
                 m_alphaChan->getValue());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
//  Video Fx
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Geometric
Shinya Kitaoka 120a6e
// FX_IDENTIFIER(ScaleFx,       "scaleFx")
Shinya Kitaoka 120a6e
// FX_IDENTIFIER(MoveFx,        "moveFx")
Shinya Kitaoka 120a6e
// FX_IDENTIFIER(AffineFx,      "affineFx")
Shinya Kitaoka 120a6e
// FX_IDENTIFIER(CropFx,        "cropFx")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Color
Toshihiro Shimizu 890ddd
FX_IDENTIFIER(InvertFx, "invertFx")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Video
Shinya Kitaoka 120a6e
// FX_IDENTIFIER(FieldFx,       "fieldFx")
Shinya Kitaoka 120a6e
// FX_IDENTIFIER(SwapFieldsFx,  "swapFieldsFx")
Shinya Kitaoka 120a6e
// FX_IDENTIFIER(DeInterlaceFx, "deInterlaceFx")
Shinya Kitaoka 120a6e
// FX_IDENTIFIER(InterlaceFx,   "interlaceFx")