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
Shinya Kitaoka 120a6e
class DiamondGradientFx : public TStandardZeraryFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(DiamondGradientFx)
Shinya Kitaoka 120a6e
  TSpectrumParamP m_colors;
Shinya Kitaoka 120a6e
  TDoubleParamP m_size;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DiamondGradientFx() : m_size(100.0) {
Shinya Kitaoka 120a6e
    TSpectrum::ColorKey colors[] = {TSpectrum::ColorKey(0, TPixel32::White),
Shinya Kitaoka 120a6e
                                    TSpectrum::ColorKey(0.2, TPixel32::Yellow),
Shinya Kitaoka 120a6e
                                    TSpectrum::ColorKey(0.4, TPixel32::Blue),
Shinya Kitaoka 120a6e
                                    TSpectrum::ColorKey(0.6, TPixel32::Green),
Shinya Kitaoka 120a6e
                                    TSpectrum::ColorKey(0.8, TPixel32::Magenta),
Shinya Kitaoka 120a6e
                                    TSpectrum::ColorKey(1, TPixel32::Red)};
Shinya Kitaoka 120a6e
    m_colors = TSpectrumParamP(tArrayCount(colors), colors);
Shinya Kitaoka 120a6e
    m_size->setMeasureName("fxLength");
Shinya Kitaoka 120a6e
    bindParam(this, "colors", m_colors);
Shinya Kitaoka 120a6e
    bindParam(this, "size", m_size);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  ~DiamondGradientFx(){};
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 473e70
  bool canHandle(const TRenderSettings &info, double frame) override { return false; }
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::RADIUS;
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 doDiamondGradient(const TRasterPT<pixel> &ras,</pixel>
Shinya Kitaoka 120a6e
                       const TSpectrumT<pixel> &spectrum, TPointD &tilepos,</pixel>
Shinya Kitaoka 120a6e
                       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 pos = tilepos;
Shinya Kitaoka 120a6e
    pos.y += j;
Shinya Kitaoka 120a6e
    double fy     = fabs(pos.y) / size;
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
      double fx = fabs(pos.x) / size;
Shinya Kitaoka 120a6e
      if ((fx * fy) < 1) {
Shinya Kitaoka 120a6e
        s      = fx * fy;
Shinya Kitaoka 120a6e
        *pix++ = spectrum.getPremultipliedValue(s);
Shinya Kitaoka 120a6e
      } else
Shinya Kitaoka 120a6e
        *pix++ = outpixel;
Shinya Kitaoka 120a6e
      pos.x += 1.0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DiamondGradientFx::doCompute(TTile &tile, double frame,
Shinya Kitaoka 120a6e
                                  const TRenderSettings &ri) {
Shinya Kitaoka 120a6e
  double size = m_size->getValue(frame) * ri.m_affine.a11 / ri.m_shrinkX;
Shinya Kitaoka 120a6e
  TPointD pos = tile.m_pos;
Shinya Kitaoka 120a6e
  if (TRaster32P raster32 = tile.getRaster())
Shinya Kitaoka 120a6e
    doDiamondGradient<tpixel32>(raster32, m_colors->getValue(frame), pos, size);</tpixel32>
Shinya Kitaoka 120a6e
  else if (TRaster64P raster64 = tile.getRaster())
Shinya Kitaoka 120a6e
    doDiamondGradient<tpixel64>(raster64, m_colors->getValue64(frame), pos,</tpixel64>
Shinya Kitaoka 120a6e
                                size);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    throw TException("DiamondGradientFx: unsupported Pixel Type");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(DiamondGradientFx, "diamondGradientFx");