Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
#include "tdoubleparam.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "tparamuiconcept.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tbasefx.h"
Toshihiro Shimizu 890ddd
#include "tzeraryfx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class ColorCardFx final : public TBaseZeraryFx {
Shinya Kitaoka 120a6e
  FX_DECLARATION(ColorCardFx)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPixelParamP m_color;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ColorCardFx() : m_color(TPixel32::Green) {
Shinya Kitaoka 120a6e
    bindParam(this, "color", m_color);
Shinya Kitaoka 120a6e
    m_color->setDefaultValue(TPixel32::Green);
Shinya Kitaoka 120a6e
    setName(L"ColorCardFx");
shun-iwasawa 481b59
    enableComputeInFloat(true);
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 38fd86
  bool doGetBBox(double frame, TRectD &bBox,
Shinya Kitaoka 38fd86
                 const TRenderSettings &info) override {
Shinya Kitaoka 120a6e
    bBox = TConsts::infiniteRectD;
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun-iwasawa 481b59
  void doCompute(TTile &tile, double frame,
shun-iwasawa 481b59
                 const TRenderSettings &ri) override {
shun-iwasawa 481b59
    TRaster32P ras32 = tile.getRaster();
shun-iwasawa 481b59
    TRaster64P ras64 = tile.getRaster();
shun-iwasawa 481b59
    TRasterFP rasF   = tile.getRaster();
shun-iwasawa 481b59
    // currently the tile should always be nonlinear
shun-iwasawa 481b59
    assert(!tile.getRaster()->isLinear());
shun-iwasawa 481b59
    if (!tile.getRaster()->isLinear()) {
shun-iwasawa 481b59
      if (ras32)
shun-iwasawa 481b59
        ras32->fill(m_color->getPremultipliedValue(frame));
shun-iwasawa 481b59
      else if (ras64)
Shinya Kitaoka 120a6e
        ras64->fill(toPixel64(m_color->getPremultipliedValue(frame)));
shun-iwasawa 481b59
      else if (rasF)
shun-iwasawa 481b59
        rasF->fill(toPixelF(m_color->getPremultipliedValue(frame)));
shun-iwasawa 481b59
      else
shun-iwasawa 481b59
        throw TException("ColorCardFx unsupported pixel type");
shun-iwasawa 481b59
    } else {  // linear color space
shun-iwasawa 481b59
      if (ras32)
shun-iwasawa 481b59
        ras32->fill(toLinear(m_color->getPremultipliedValue(frame),
shun-iwasawa 481b59
                             ri.m_colorSpaceGamma));
shun-iwasawa 481b59
      else if (ras64)
shun-iwasawa 481b59
        ras64->fill(toLinear(toPixel64(m_color->getPremultipliedValue(frame)),
shun-iwasawa 481b59
                             ri.m_colorSpaceGamma));
shun-iwasawa 481b59
      else if (rasF)
shun-iwasawa 481b59
        rasF->fill(toLinear(toPixelF(m_color->getPremultipliedValue(frame)),
shun-iwasawa 481b59
                            ri.m_colorSpaceGamma));
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        throw TException("ColorCardFx unsupported pixel type");
Shinya Kitaoka 120a6e
    }
shun-iwasawa 481b59
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class CheckBoardFx final : public TBaseZeraryFx {
Shinya Kitaoka 120a6e
  FX_DECLARATION(CheckBoardFx)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPixelParamP m_color1, m_color2;
Shinya Kitaoka 120a6e
  TDoubleParamP m_size;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  CheckBoardFx()
Shinya Kitaoka 120a6e
      : m_color1(TPixel32::Black), m_color2(TPixel32::White), m_size(50) {
Shinya Kitaoka 120a6e
    m_size->setMeasureName("fxLength");
Shinya Kitaoka 120a6e
    bindParam(this, "color1", m_color1);
Shinya Kitaoka 120a6e
    bindParam(this, "color2", m_color2);
Shinya Kitaoka 120a6e
    bindParam(this, "size", m_size);
Shinya Kitaoka 120a6e
    m_color1->setDefaultValue(TPixel32::Black);
Shinya Kitaoka 120a6e
    m_color2->setDefaultValue(TPixel32::White);
Shinya Kitaoka 120a6e
    m_size->setValueRange(1, 1000);
Shinya Kitaoka 120a6e
    m_size->setDefaultValue(50);
Shinya Kitaoka 120a6e
    setName(L"CheckBoardFx");
shun-iwasawa 481b59
    enableComputeInFloat(true);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  bool canHandle(const TRenderSettings &info, double frame) override {
Shinya Kitaoka 38fd86
    return false;
Shinya Kitaoka 38fd86
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  bool doGetBBox(double, TRectD &bBox, const TRenderSettings &info) override {
Shinya Kitaoka 120a6e
    bBox = TConsts::infiniteRectD;
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  void doCompute(TTile &tile, double frame,
Shinya Kitaoka 38fd86
                 const TRenderSettings &info) override {
shun-iwasawa 481b59
    bool isLinear = tile.getRaster()->isLinear();
shun-iwasawa 481b59
    // currently the tile should always be nonlinear
shun-iwasawa 481b59
    assert(!isLinear);
shun-iwasawa 481b59
    const TPixel32 &c1 =
shun-iwasawa 481b59
        m_color1->getValue(frame, isLinear, info.m_colorSpaceGamma);
shun-iwasawa 481b59
    const TPixel32 &c2 =
shun-iwasawa 481b59
        m_color2->getValue(frame, isLinear, info.m_colorSpaceGamma);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    double size = m_size->getValue(frame);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    assert(info.m_shrinkX == info.m_shrinkY);
Shinya Kitaoka 120a6e
    size *= info.m_affine.a11 / info.m_shrinkX;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TDimensionD dim(size, size);
Shinya Kitaoka 120a6e
    TRop::checkBoard(tile.getRaster(), c1, c2, dim, tile.m_pos);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void getParamUIs(TParamUIConcept *&concepts, int &length) override {
Shinya Kitaoka 120a6e
    concepts = new TParamUIConcept[length = 1];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    concepts[0].m_type  = TParamUIConcept::SIZE;
Shinya Kitaoka 120a6e
    concepts[0].m_label = "Size";
Shinya Kitaoka 120a6e
    concepts[0].m_params.push_back(m_size);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_IDENTIFIER(ColorCardFx, "colorCardFx")
Toshihiro Shimizu 890ddd
FX_IDENTIFIER(CheckBoardFx, "checkBoardFx")