Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "tspectrumparam.h"
Toshihiro Shimizu 890ddd
#include "tparamuiconcept.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef max
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class SquareGradientFx final : public TStandardZeraryFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(SquareGradientFx)
Shinya Kitaoka 120a6e
  TSpectrumParamP m_colors;
Shinya Kitaoka 120a6e
  TDoubleParamP m_size;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SquareGradientFx() : m_size(200.0) {
Shinya Kitaoka 120a6e
    m_size->setMeasureName("fxLength");
Shinya Kitaoka 120a6e
    TSpectrum::ColorKey colors[] = {
Shinya Kitaoka 120a6e
        TSpectrum::ColorKey(0, TPixel32::White),
Shinya Kitaoka 120a6e
        // TSpectrum::ColorKey(0.5,TPixel32::Yellow),
Shinya Kitaoka 120a6e
        TSpectrum::ColorKey(1, TPixel32::Red)};
Shinya Kitaoka 120a6e
    m_colors = TSpectrumParamP(tArrayCount(colors), colors);
Shinya Kitaoka 120a6e
    bindParam(this, "colors", m_colors);
Shinya Kitaoka 120a6e
    bindParam(this, "size", m_size);
Shinya Kitaoka 120a6e
    m_size->setValueRange(0, std::numeric_limits<double>::max());</double>
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  ~SquareGradientFx(){};
Toshihiro Shimizu 890ddd
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 473e70
  void doCompute(TTile &tile, double frame, const TRenderSettings &ri) override;
Shinya Kitaoka 38fd86
  bool canHandle(const TRenderSettings &info, double frame) override {
Shinya Kitaoka 38fd86
    return true;
Shinya Kitaoka 38fd86
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void getParamUIs(TParamUIConcept *&concepts, int &length) override {
Shinya Kitaoka 120a6e
    concepts = new TParamUIConcept[length = 1];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    concepts[0].m_type  = TParamUIConcept::DIAMOND;
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
template <typename pixel=""></typename>
Shinya Kitaoka 120a6e
void doSquareGradient(const TRasterPT<pixel> &ras,</pixel>
Shinya Kitaoka 120a6e
                      const TSpectrumT<pixel> &spectrum, TPointD &posTrasf,</pixel>
Shinya Kitaoka 120a6e
                      TAffine aff, double size) {
Shinya Kitaoka 120a6e
  PIXEL outpixel = spectrum.getPremultipliedValue(1.);
Shinya Kitaoka 120a6e
  int j;
Shinya Kitaoka 120a6e
  ras->lock();
Shinya Kitaoka 120a6e
  for (j = 0; j < ras->getLy(); j++) {
Shinya Kitaoka 120a6e
    TPointD posAux = posTrasf;
Shinya Kitaoka 120a6e
    TPointD fp;
Shinya Kitaoka 120a6e
    PIXEL *pix    = ras->pixels(j);
Shinya Kitaoka 120a6e
    PIXEL *endPix = pix + ras->getLx();
Shinya Kitaoka 120a6e
    while (pix < endPix) {
Shinya Kitaoka 120a6e
      double s;
Shinya Kitaoka 120a6e
      fp.x = fabs(posAux.x) / size;
Shinya Kitaoka 120a6e
      fp.y = fabs(posAux.y) / size;
Shinya Kitaoka 120a6e
      if ((fp.x + fp.y) < 1) {
Shinya Kitaoka 120a6e
        s      = fp.x + fp.y;
Shinya Kitaoka 120a6e
        *pix++ = spectrum.getPremultipliedValue(s);
Shinya Kitaoka 120a6e
      } else
Shinya Kitaoka 120a6e
        *pix++ = outpixel;
Shinya Kitaoka 120a6e
      posAux.x += aff.a11;
Shinya Kitaoka 120a6e
      posAux.y += aff.a21;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    posTrasf.x += aff.a12;
Shinya Kitaoka 120a6e
    posTrasf.y += aff.a22;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SquareGradientFx::doCompute(TTile &tile, double frame,
Shinya Kitaoka 120a6e
                                 const TRenderSettings &ri) {
Shinya Kitaoka 120a6e
  double size = m_size->getValue(frame) / ri.m_shrinkX;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ;
Shinya Kitaoka 120a6e
  TAffine aff      = ri.m_affine.inv();
Shinya Kitaoka 120a6e
  TPointD posTrasf = aff * tile.m_pos;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (TRaster32P raster32 = tile.getRaster())
Shinya Kitaoka 120a6e
    doSquareGradient<tpixel32>(raster32, m_colors->getValue(frame), posTrasf,</tpixel32>
Shinya Kitaoka 120a6e
                               aff, size);
Shinya Kitaoka 120a6e
  else if (TRaster64P raster64 = tile.getRaster())
Shinya Kitaoka 120a6e
    doSquareGradient<tpixel64>(raster64, m_colors->getValue64(frame), posTrasf,</tpixel64>
Shinya Kitaoka 120a6e
                               aff, size);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    throw TException("SquareGradientFx: unsupported Pixel Type");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(SquareGradientFx, "squareGradientFx");