Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include <math.h></math.h>
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "hsvutil.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class HSVScaleFx final : public TStandardRasterFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(HSVScaleFx)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Shinya Kitaoka 120a6e
  TDoubleParamP m_hue;
Shinya Kitaoka 120a6e
  TDoubleParamP m_sat;
Shinya Kitaoka 120a6e
  TDoubleParamP m_value;
Shinya Kitaoka 120a6e
  TDoubleParamP m_hueScale;
Shinya Kitaoka 120a6e
  TDoubleParamP m_satScale;
Shinya Kitaoka 120a6e
  TDoubleParamP m_valueScale;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  HSVScaleFx()
Shinya Kitaoka 120a6e
      : m_hue(0.0)
Shinya Kitaoka 120a6e
      , m_sat(0.0)
Shinya Kitaoka 120a6e
      , m_value(0.0)
Shinya Kitaoka 120a6e
      , m_hueScale(100.0)
Shinya Kitaoka 120a6e
      , m_satScale(100.0)
Shinya Kitaoka 120a6e
      , m_valueScale(100.0)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    bindParam(this, "hue", m_hue);
Shinya Kitaoka 120a6e
    bindParam(this, "saturation", m_sat);
Shinya Kitaoka 120a6e
    bindParam(this, "value", m_value);
Shinya Kitaoka 120a6e
    bindParam(this, "hue_scale", m_hueScale);
Shinya Kitaoka 120a6e
    bindParam(this, "saturation_scale", m_satScale);
Shinya Kitaoka 120a6e
    bindParam(this, "value_scale", m_valueScale);
Shinya Kitaoka 120a6e
    m_hue->setValueRange(-180, 180);
Shinya Kitaoka 120a6e
    m_sat->setValueRange(-1, 1);
Shinya Kitaoka 120a6e
    m_value->setValueRange(-1, 1);
Shinya Kitaoka 120a6e
    m_hueScale->setValueRange(0, (std::numeric_limits<double>::max)());</double>
Shinya Kitaoka 120a6e
    m_satScale->setValueRange(0, (std::numeric_limits<double>::max)());</double>
Shinya Kitaoka 120a6e
    m_valueScale->setValueRange(0, (std::numeric_limits<double>::max)());</double>
Shinya Kitaoka 120a6e
    addInputPort("Source", m_input);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~HSVScaleFx(){};
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
      m_input->doGetBBox(frame, bBox, info);
Shinya Kitaoka 120a6e
      return true;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void doCompute(TTile &tile, double frame, const TRenderSettings &) override;
Shinya Kitaoka 120a6e
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 channel_type="" pixel,="" typename=""></typename>
Shinya Kitaoka 120a6e
void doHSVScale(const TRasterPT<pixel> &ras, double hue, double sat,</pixel>
Shinya Kitaoka 120a6e
                double value, double hueScale, double satScale,
Shinya Kitaoka 120a6e
                double valueScale) {
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
Shinya Kitaoka 120a6e
    for (; pix < endPix; ++pix) {
Shinya Kitaoka 120a6e
      if (pix->m == 0) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      double m = pix->m;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      double r, g, b, h, s, v;
Shinya Kitaoka 120a6e
      // depremult(pix);
Shinya Kitaoka 120a6e
      r = pix->r / m;
Shinya Kitaoka 120a6e
      g = pix->g / m;
Shinya Kitaoka 120a6e
      b = pix->b / m;
Shinya Kitaoka 120a6e
      OLDRGB2HSV(r, g, b, &h, &s, &v);
Shinya Kitaoka 120a6e
      /*     int hsv[3];
Shinya Kitaoka 120a6e
rgb2hsv(hsv, *pix);
Shinya Kitaoka 120a6e
h =((double)hsv[0]/255.)*360.;
Shinya Kitaoka 120a6e
s =hsv[1]/255.;
Shinya Kitaoka 120a6e
v =hsv[2]/255.;*/
Shinya Kitaoka 120a6e
      h += hue;
Shinya Kitaoka 120a6e
      s += sat;
Shinya Kitaoka 120a6e
      v += value;
Shinya Kitaoka 120a6e
      h *= hueScale;
Shinya Kitaoka 120a6e
      s *= satScale;
Shinya Kitaoka 120a6e
      v *= valueScale;
Shinya Kitaoka 120a6e
      /*     hsv[0]=tcrop((int)((h/360.)*255.),0,255);
Shinya Kitaoka 120a6e
hsv[1]=tcrop((int)s*255, 0,255);
Shinya Kitaoka 120a6e
hsv[2]=tcrop((int)v*255, 0,255);
Shinya Kitaoka 120a6e
hsv2rgb(*pix,hsv);*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      OLDHSV2RGB(h, s, v, &r, &g, &b);
Shinya Kitaoka 120a6e
      pix->r = (CHANNEL_TYPE)(r * m);
Shinya Kitaoka 120a6e
      pix->g = (CHANNEL_TYPE)(g * m);
Shinya Kitaoka 120a6e
      pix->b = (CHANNEL_TYPE)(b * m);
Shinya Kitaoka 120a6e
      // premultiply(*pix);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void HSVScaleFx::doCompute(TTile &tile, double frame,
Shinya Kitaoka 120a6e
                           const TRenderSettings &ri) {
Shinya Kitaoka 120a6e
  if (!m_input.isConnected()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_input->compute(tile, frame, ri);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double hue        = m_hue->getValue(frame);
Shinya Kitaoka 120a6e
  double sat        = m_sat->getValue(frame);
Shinya Kitaoka 120a6e
  double value      = m_value->getValue(frame);
Shinya Kitaoka 120a6e
  double hueScale   = m_hueScale->getValue(frame) / 100.0;
Shinya Kitaoka 120a6e
  double satScale   = m_satScale->getValue(frame) / 100.0;
Shinya Kitaoka 120a6e
  double valueScale = m_valueScale->getValue(frame) / 100.0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRaster32P raster32 = tile.getRaster();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (raster32)
Shinya Kitaoka 120a6e
    doHSVScale<tpixel32, uchar="">(raster32, hue, sat, value, hueScale, satScale,</tpixel32,>
Shinya Kitaoka 120a6e
                                valueScale);
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    TRaster64P raster64 = tile.getRaster();
Shinya Kitaoka 120a6e
    if (raster64)
Shinya Kitaoka 120a6e
      doHSVScale<tpixel64, ushort="">(raster64, hue, sat, value, hueScale,</tpixel64,>
Shinya Kitaoka 120a6e
                                   satScale, valueScale);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      throw TException("HSVScale: unsupported Pixel Type");
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(HSVScaleFx, "hsvScaleFx")