Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RGBMCutFx final : public TStandardRasterFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(RGBMCutFx)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Shinya Kitaoka 120a6e
  TRangeParamP m_r_range;
Shinya Kitaoka 120a6e
  TRangeParamP m_g_range;
Shinya Kitaoka 120a6e
  TRangeParamP m_b_range;
Shinya Kitaoka 120a6e
  TRangeParamP m_m_range;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RGBMCutFx()
Shinya Kitaoka 120a6e
      : m_r_range(DoublePair(0., 255.))
Shinya Kitaoka 120a6e
      , m_g_range(DoublePair(0., 255.))
Shinya Kitaoka 120a6e
      , m_b_range(DoublePair(0., 255.))
Shinya Kitaoka 120a6e
      , m_m_range(DoublePair(0., 255.)) {
Shinya Kitaoka 120a6e
    bindParam(this, "r_range", m_r_range);
Shinya Kitaoka 120a6e
    bindParam(this, "g_range", m_g_range);
Shinya Kitaoka 120a6e
    bindParam(this, "b_range", m_b_range);
Shinya Kitaoka 120a6e
    bindParam(this, "m_range", m_m_range);
Shinya Kitaoka 120a6e
    m_r_range->getMin()->setValueRange(0., 255.);
Shinya Kitaoka 120a6e
    m_g_range->getMin()->setValueRange(0., 255.);
Shinya Kitaoka 120a6e
    m_b_range->getMin()->setValueRange(0., 255.);
Shinya Kitaoka 120a6e
    m_m_range->getMin()->setValueRange(0., 255.);
Shinya Kitaoka 120a6e
    m_r_range->getMax()->setValueRange(0., 255.);
Shinya Kitaoka 120a6e
    m_g_range->getMax()->setValueRange(0., 255.);
Shinya Kitaoka 120a6e
    m_b_range->getMax()->setValueRange(0., 255.);
Shinya Kitaoka 120a6e
    m_m_range->getMax()->setValueRange(0., 255.);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    addInputPort("Source", m_input);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~RGBMCutFx(){};
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  bool doGetBBox(double frame, TRectD &bBox,
Shinya Kitaoka 38fd86
                 const TRenderSettings &info) override {
Shinya Kitaoka 120a6e
    return m_input.getFx() && m_input->doGetBBox(frame, bBox, info);
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
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
void update_param(double ¶m, TRaster32P ras) { return; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void update_param(double ¶m, TRaster64P ras) {
Shinya Kitaoka 120a6e
  param = param * 257;
Shinya Kitaoka 120a6e
  return;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename channel_type="" pixel,="" typename=""></typename>
Shinya Kitaoka 120a6e
void doRGBMCut(TRasterPT<pixel> ras, double hi_m, double hi_r, double hi_g,</pixel>
Shinya Kitaoka 120a6e
               double hi_b, double lo_m, double lo_r, double lo_g,
Shinya Kitaoka 120a6e
               double lo_b) {
Shinya Kitaoka 120a6e
  update_param(hi_m, ras);
Shinya Kitaoka 120a6e
  update_param(hi_r, ras);
Shinya Kitaoka 120a6e
  update_param(hi_g, ras);
Shinya Kitaoka 120a6e
  update_param(hi_b, ras);
Shinya Kitaoka 120a6e
  update_param(lo_m, ras);
Shinya Kitaoka 120a6e
  update_param(lo_r, ras);
Shinya Kitaoka 120a6e
  update_param(lo_g, ras);
Shinya Kitaoka 120a6e
  update_param(lo_b, ras);
Shinya Kitaoka 120a6e
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
      if (pix->m != 0) {
Shinya Kitaoka 120a6e
        *pix = depremultiply(*pix);
Shinya Kitaoka 120a6e
        if (lo_m == 0)
Shinya Kitaoka 120a6e
          pix->m = tcrop((int)pix->m, (int)lo_m, (int)hi_m);
Shinya Kitaoka 120a6e
        else
Shinya Kitaoka 120a6e
          pix->m = (pix->m) ? tcrop((int)pix->m, (int)lo_m, (int)hi_m) : 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        pix->r = tcrop((int)pix->r, (int)lo_r, (int)hi_r);
Shinya Kitaoka 120a6e
        pix->g = tcrop((int)pix->g, (int)lo_g, (int)hi_g);
Shinya Kitaoka 120a6e
        pix->b = tcrop((int)pix->b, (int)lo_b, (int)hi_b);
Shinya Kitaoka 120a6e
        *pix   = premultiply(*pix);
Shinya Kitaoka 120a6e
      }
Rozhuk Ivan 823a31
      pix++;
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 RGBMCutFx::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 hi_m = m_m_range->getMax()->getValue(frame);
Shinya Kitaoka 120a6e
  double hi_r = m_r_range->getMax()->getValue(frame);
Shinya Kitaoka 120a6e
  double hi_g = m_g_range->getMax()->getValue(frame);
Shinya Kitaoka 120a6e
  double hi_b = m_b_range->getMax()->getValue(frame);
Shinya Kitaoka 120a6e
  double lo_m = m_m_range->getMin()->getValue(frame);
Shinya Kitaoka 120a6e
  double lo_r = m_r_range->getMin()->getValue(frame);
Shinya Kitaoka 120a6e
  double lo_g = m_g_range->getMin()->getValue(frame);
Shinya Kitaoka 120a6e
  double lo_b = m_b_range->getMin()->getValue(frame);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRaster32P raster32 = tile.getRaster();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (raster32)
Shinya Kitaoka 120a6e
    doRGBMCut<tpixel32, uchar="">(raster32, hi_m, hi_r, hi_g, hi_b, lo_m, lo_r,</tpixel32,>
Shinya Kitaoka 120a6e
                               lo_g, lo_b);
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    TRaster64P raster64 = tile.getRaster();
Shinya Kitaoka 120a6e
    if (raster64)
Shinya Kitaoka 120a6e
      doRGBMCut<tpixel64, ushort="">(raster64, hi_m, hi_r, hi_g, hi_b, lo_m, lo_r,</tpixel64,>
Shinya Kitaoka 120a6e
                                  lo_g, lo_b);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      throw TException("RGBMCutFx: unsupported Pixel Type");
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(RGBMCutFx, "rgbmCutFx")