Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
#pragma warning(disable : 4996)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ttzpimagefx.h"
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "trasterfx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------------------
Shinya Kitaoka d1f6c4
class BlendTzFx final : public TStandardRasterFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(BlendTzFx)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Shinya Kitaoka 120a6e
  TStringParamP m_colorIndex;
Shinya Kitaoka 120a6e
  TBoolParamP m_noBlending;
Shinya Kitaoka 120a6e
  TDoubleParamP m_amount;
Shinya Kitaoka 120a6e
  TDoubleParamP m_smoothness;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  BlendTzFx()
Shinya Kitaoka 120a6e
      : m_colorIndex(L"1,2,3")
Shinya Kitaoka 120a6e
      , m_noBlending(false)
Shinya Kitaoka 120a6e
      , m_amount(10)
Shinya Kitaoka 120a6e
      , m_smoothness(10) {
Shinya Kitaoka 120a6e
    m_amount->setMeasureName("fxLength");
Shinya Kitaoka 120a6e
    bindParam(this, "Color_Index", m_colorIndex);
Shinya Kitaoka 120a6e
    bindParam(this, "Amount", m_amount);
Shinya Kitaoka 120a6e
    bindParam(this, "Smoothness", m_smoothness);
Shinya Kitaoka 120a6e
    bindParam(this, "noBlending", m_noBlending);
Shinya Kitaoka 120a6e
    addInputPort("Source", m_input);
Shinya Kitaoka 120a6e
    m_amount->setValueRange(0, std::numeric_limits<double>::max());</double>
Shinya Kitaoka 120a6e
    m_smoothness->setValueRange(0, std::numeric_limits<double>::max());</double>
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~BlendTzFx() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------------
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;
Shinya Kitaoka 473e70
  void doCompute(TTile &tile, double frame, const TRenderSettings &ri) override;
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
      // Build the render data
Shinya Kitaoka 120a6e
      TRenderSettings info2(info);
Shinya Kitaoka 120a6e
      buildBlendData(info2, frame);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      return m_input->doGetBBox(frame, bBox, info2);
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 120a6e
  //-----------------------------------------------------------------------------
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 120a6e
  //-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  bool allowUserCacheOnPort(int port) override { return false; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  void getValues(const char *argv[], int argc, double frame) {
Shinya Kitaoka 120a6e
    double values[6];
Shinya Kitaoka 120a6e
    values[2] = m_smoothness->getValue(frame);
Shinya Kitaoka 120a6e
    values[3] = m_amount->getValue(frame) * 0.5;
Shinya Kitaoka 120a6e
    values[4] = m_noBlending->getValue() ? 1.0 : 0.0;
Shinya Kitaoka 120a6e
    convertParam(values, argv, argc);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  char *strsave(const char *t) {
Shinya Kitaoka 120a6e
    char *s;
Shinya Kitaoka 120a6e
    s = (char *)malloc(strlen(t) + 1);
Shinya Kitaoka 120a6e
    strcpy(s, t);
Shinya Kitaoka 120a6e
    return s;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //-----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void convertParam(double param[], const char *cParam[], int cParamLen) {
Shinya Kitaoka 120a6e
    std::string app;
Shinya Kitaoka 120a6e
    for (int i = 2; i < cParamLen - 1; i++) {
Shinya Kitaoka 120a6e
      app       = std::to_string(param[i]);
Shinya Kitaoka 120a6e
      cParam[i] = strsave(app.c_str());
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //-------------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int getBorder(int argc, int shrink, double frame) {
Shinya Kitaoka 120a6e
    double blendSize;
Shinya Kitaoka 120a6e
    int defaultBorder = 5;
Shinya Kitaoka 120a6e
    if (argc != 6) return defaultBorder;
Shinya Kitaoka 120a6e
    blendSize                 = m_amount->getValue(frame) * 0.5;
Shinya Kitaoka 120a6e
    if (shrink > 0) blendSize = blendSize / (double)shrink;
Shinya Kitaoka 120a6e
    // if (blendcmapImgDpi>0.0 )
Shinya Kitaoka 120a6e
    //	blendSize*=(blendcmapImgDpi*0.01);
Shinya Kitaoka 120a6e
    return (int)blendSize + 1 + defaultBorder;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //-------------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void buildBlendData(TRenderSettings &ri, double frame) {
Shinya Kitaoka 120a6e
    int shrink = tround((ri.m_shrinkX + ri.m_shrinkY) / 2.0);
Shinya Kitaoka 120a6e
    int argc   = 6;
Shinya Kitaoka 120a6e
    const char *argv[6];
Shinya Kitaoka 120a6e
    argv[0] = strsave(::to_string(m_colorIndex->getValue()).c_str());
Shinya Kitaoka 120a6e
    argv[1] = argv[0];
Shinya Kitaoka 120a6e
    argv[5] = "1";
Shinya Kitaoka 120a6e
    getValues(argv, argc, frame);
Shinya Kitaoka 120a6e
    SandorFxRenderData *blendData =
Shinya Kitaoka 120a6e
        new SandorFxRenderData(BlendTz, argc, argv, 0, shrink);
Shinya Kitaoka 120a6e
    BlendTzParams ¶ms = blendData->m_blendParams;
Shinya Kitaoka 120a6e
    params.m_amount       = m_amount->getValue(frame) * 0.5;
Shinya Kitaoka 120a6e
    params.m_colorIndex   = m_colorIndex->getValue();
Shinya Kitaoka 120a6e
    params.m_smoothness   = m_smoothness->getValue(frame);
Shinya Kitaoka 120a6e
    params.m_noBlending   = m_noBlending->getValue();
Shinya Kitaoka 120a6e
    ri.m_data.push_back(blendData);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(BlendTzFx, "blendTzFx")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void BlendTzFx::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
  infoOnInput                = infoOnOutput;
Shinya Kitaoka 120a6e
  infoOnInput.m_userCachable = false;
Shinya Kitaoka 120a6e
  buildBlendData(infoOnInput, frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void BlendTzFx::doCompute(TTile &tile, double frame,
Shinya Kitaoka 120a6e
                          const TRenderSettings &ri) {
Shinya Kitaoka 120a6e
  if (!m_input.isConnected()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRenderSettings ri2(ri);
Shinya Kitaoka 120a6e
  buildBlendData(ri2, frame);
Shinya Kitaoka 120a6e
  ri2.m_userCachable = false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_input->compute(tile, frame, ri2);
Toshihiro Shimizu 890ddd
}