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 "tpixelutils.h"
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RGBMFadeFx final : public TStandardRasterFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(RGBMFadeFx)
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Shinya Kitaoka 120a6e
  TPixelParamP m_color;
Shinya Kitaoka 120a6e
  TDoubleParamP m_intensity;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RGBMFadeFx() : m_intensity(50.0), m_color(TPixel32::Black) {
Shinya Kitaoka 120a6e
    bindParam(this, "color", m_color);
Shinya Kitaoka 120a6e
    bindParam(this, "intensity", m_intensity);
Shinya Kitaoka 120a6e
    m_intensity->setValueRange(0, 100);
Shinya Kitaoka 120a6e
    addInputPort("Source", m_input);
Shinya Kitaoka 120a6e
    m_color->enableMatte(false);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  ~RGBMFadeFx(){};
Toshihiro Shimizu 890ddd
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
      return m_input->doGetBBox(frame, bBox, info);
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      bBox = TRectD();
Shinya Kitaoka 120a6e
      return false;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
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
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixel=""></typename>
Shinya Kitaoka 120a6e
void doRGBMFade(TRasterPT<pixel> &ras, const PIXEL &col, double intensity) {</pixel>
Shinya Kitaoka 120a6e
  int j;
Shinya Kitaoka 120a6e
  ras->lock();
Shinya Kitaoka 120a6e
  for (j = 0; j < ras->getLy(); j++) {
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
      pix->m        = pix->m;
Shinya Kitaoka 120a6e
      double factor = pix->m / (double)PIXEL::maxChannelValue;
Shinya Kitaoka 120a6e
      int val;
Shinya Kitaoka 120a6e
      val    = troundp(pix->r + intensity * (col.r * factor - pix->r));
Shinya Kitaoka 120a6e
      pix->r = (val > PIXEL::maxChannelValue) ? PIXEL::maxChannelValue : val;
Shinya Kitaoka 120a6e
      val    = troundp(pix->g + intensity * (col.g * factor - pix->g));
Shinya Kitaoka 120a6e
      pix->g = (val > PIXEL::maxChannelValue) ? PIXEL::maxChannelValue : val;
Shinya Kitaoka 120a6e
      val    = troundp(pix->b + intensity * (col.b * factor - pix->b));
Shinya Kitaoka 120a6e
      pix->b = (val > PIXEL::maxChannelValue) ? PIXEL::maxChannelValue : val;
Shinya Kitaoka 120a6e
      /*  qui si faceva il fade anche del matte
Shinya Kitaoka 120a6e
pix->r=(UCHAR)(pix->r+intensity*(col.r-pix->r));
Shinya Kitaoka 120a6e
pix->g=(UCHAR)(pix->g+intensity*(col.g-pix->g));
Shinya Kitaoka 120a6e
pix->b=(UCHAR)(pix->b+intensity*(col.b-pix->b));
Shinya Kitaoka 120a6e
pix->m=(UCHAR)(pix->m+intensity*(col.m-pix->m));*/
Shinya Kitaoka 120a6e
      ++pix;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RGBMFadeFx::doCompute(TTile &tile, double frame,
Shinya Kitaoka 120a6e
                           const TRenderSettings &ri) {
Shinya Kitaoka 120a6e
  if (!m_input.isConnected()) return;
Shinya Kitaoka 120a6e
  m_input->compute(tile, frame, ri);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPixel32 col = m_color->getValue(frame);
Shinya Kitaoka 120a6e
  double min, max, step;
Shinya Kitaoka 120a6e
  m_intensity->getValueRange(min, max, step);
Shinya Kitaoka 120a6e
  double intensity = tcrop(m_intensity->getValue(frame), min, max) / 100;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRaster32P raster32 = tile.getRaster();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (raster32)
Shinya Kitaoka 120a6e
    doRGBMFade<tpixel32>(raster32, col, intensity);</tpixel32>
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    TRaster64P raster64 = tile.getRaster();
Shinya Kitaoka 120a6e
    if (raster64)
Shinya Kitaoka 120a6e
      doRGBMFade<tpixel64>(raster64, toPixel64(col), intensity);</tpixel64>
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      throw TException("RGBMFadeFx: unsupported Pixel Type");
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(RGBMFadeFx, "rgbmFadeFx");