Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
//#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class AdjustLevelsFx final : public TStandardRasterFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(AdjustLevelsFx)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Shinya Kitaoka 120a6e
  TRangeParamP m_in_rgb;
Shinya Kitaoka 120a6e
  TRangeParamP m_in_r;
Shinya Kitaoka 120a6e
  TRangeParamP m_in_g;
Shinya Kitaoka 120a6e
  TRangeParamP m_in_b;
Shinya Kitaoka 120a6e
  TRangeParamP m_in_m;
Shinya Kitaoka 120a6e
  TRangeParamP m_out_rgb;
Shinya Kitaoka 120a6e
  TRangeParamP m_out_r;
Shinya Kitaoka 120a6e
  TRangeParamP m_out_g;
Shinya Kitaoka 120a6e
  TRangeParamP m_out_b;
Shinya Kitaoka 120a6e
  TRangeParamP m_out_m;
Shinya Kitaoka 120a6e
  TDoubleParamP m_gamma_rgb;
Shinya Kitaoka 120a6e
  TDoubleParamP m_gamma_r;
Shinya Kitaoka 120a6e
  TDoubleParamP m_gamma_g;
Shinya Kitaoka 120a6e
  TDoubleParamP m_gamma_b;
Shinya Kitaoka 120a6e
  TDoubleParamP m_gamma_m;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  AdjustLevelsFx()
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      : m_in_rgb(DoublePair(0.0, 255.0))
Shinya Kitaoka 120a6e
      , m_in_r(DoublePair(0.0, 255.0))
Shinya Kitaoka 120a6e
      , m_in_g(DoublePair(0.0, 255.0))
Shinya Kitaoka 120a6e
      , m_in_b(DoublePair(0.0, 255.0))
Shinya Kitaoka 120a6e
      , m_in_m(DoublePair(0.0, 255.0))
Shinya Kitaoka 120a6e
      , m_out_rgb(DoublePair(0.0, 255.0))
Shinya Kitaoka 120a6e
      , m_out_r(DoublePair(0.0, 255.0))
Shinya Kitaoka 120a6e
      , m_out_g(DoublePair(0.0, 255.0))
Shinya Kitaoka 120a6e
      , m_out_b(DoublePair(0.0, 255.0))
Shinya Kitaoka 120a6e
      , m_out_m(DoublePair(0.0, 255.0))
Shinya Kitaoka 120a6e
      , m_gamma_rgb(1.0)
Shinya Kitaoka 120a6e
      , m_gamma_r(1.0)
Shinya Kitaoka 120a6e
      , m_gamma_g(1.0)
Shinya Kitaoka 120a6e
      , m_gamma_b(1.0)
Shinya Kitaoka 120a6e
      , m_gamma_m(1.0) {
Shinya Kitaoka 120a6e
    bindParam(this, "in_rgb", m_in_rgb);
Shinya Kitaoka 120a6e
    bindParam(this, "in_r", m_in_r);
Shinya Kitaoka 120a6e
    bindParam(this, "in_g", m_in_g);
Shinya Kitaoka 120a6e
    bindParam(this, "in_b", m_in_b);
Shinya Kitaoka 120a6e
    bindParam(this, "in_m", m_in_m);
Shinya Kitaoka 120a6e
    bindParam(this, "out_rgb", m_out_rgb);
Shinya Kitaoka 120a6e
    bindParam(this, "out_r", m_out_r);
Shinya Kitaoka 120a6e
    bindParam(this, "out_g", m_out_g);
Shinya Kitaoka 120a6e
    bindParam(this, "out_b", m_out_b);
Shinya Kitaoka 120a6e
    bindParam(this, "out_m", m_out_m);
Shinya Kitaoka 120a6e
    bindParam(this, "gamma_rgb", m_gamma_rgb);
Shinya Kitaoka 120a6e
    bindParam(this, "gamma_r", m_gamma_r);
Shinya Kitaoka 120a6e
    bindParam(this, "gamma_g", m_gamma_g);
Shinya Kitaoka 120a6e
    bindParam(this, "gamma_b", m_gamma_b);
Shinya Kitaoka 120a6e
    bindParam(this, "gamma_m", m_gamma_m);
Shinya Kitaoka 120a6e
    addInputPort("Source", m_input);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_in_rgb->getMin()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_in_rgb->getMax()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_in_r->getMin()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_in_r->getMax()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_in_g->getMin()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_in_g->getMax()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_in_b->getMin()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_in_b->getMax()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_in_m->getMin()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_in_m->getMax()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_out_rgb->getMin()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_out_rgb->getMax()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_out_r->getMin()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_out_r->getMax()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_out_g->getMin()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_out_g->getMax()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_out_b->getMin()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_out_b->getMax()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_out_m->getMin()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_out_m->getMax()->setValueRange(0, 255);
Shinya Kitaoka 120a6e
    m_gamma_rgb->setValueRange(0.0, 200.0);
Shinya Kitaoka 120a6e
    m_gamma_r->setValueRange(0.0, 200.0);
Shinya Kitaoka 120a6e
    m_gamma_g->setValueRange(0.0, 200.0);
Shinya Kitaoka 120a6e
    m_gamma_b->setValueRange(0.0, 200.0);
Shinya Kitaoka 120a6e
    m_gamma_m->setValueRange(0.0, 200.0);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~AdjustLevelsFx(){};
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  bool canHandle(const TRenderSettings &info, double frame) override {
Shinya Kitaoka 38fd86
    return true;
Shinya Kitaoka 38fd86
  }
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
      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
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void doCompute(TTile &tile, double frame, const TRenderSettings &ri) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void AdjustLevelsFx::doCompute(TTile &tile, double frame,
Shinya Kitaoka 120a6e
                               const TRenderSettings &ri) {
Shinya Kitaoka 120a6e
  if (!m_input.isConnected()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_input->compute(tile, frame, ri);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double gamma_rgb = m_gamma_rgb->getValue(frame);
Shinya Kitaoka 120a6e
  double gamma_r   = m_gamma_r->getValue(frame);
Shinya Kitaoka 120a6e
  double gamma_g   = m_gamma_g->getValue(frame);
Shinya Kitaoka 120a6e
  double gamma_b   = m_gamma_b->getValue(frame);
Shinya Kitaoka 120a6e
  double gamma_m   = m_gamma_m->getValue(frame);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  DoublePair vin_rgb  = m_in_rgb->getValue(frame);
Shinya Kitaoka 120a6e
  DoublePair vin_r    = m_in_r->getValue(frame);
Shinya Kitaoka 120a6e
  DoublePair vin_g    = m_in_g->getValue(frame);
Shinya Kitaoka 120a6e
  DoublePair vin_b    = m_in_b->getValue(frame);
Shinya Kitaoka 120a6e
  DoublePair vin_m    = m_in_m->getValue(frame);
Shinya Kitaoka 120a6e
  DoublePair vout_rgb = m_out_rgb->getValue(frame);
Shinya Kitaoka 120a6e
  DoublePair vout_r   = m_out_r->getValue(frame);
Shinya Kitaoka 120a6e
  DoublePair vout_g   = m_out_g->getValue(frame);
Shinya Kitaoka 120a6e
  DoublePair vout_b   = m_out_b->getValue(frame);
Shinya Kitaoka 120a6e
  DoublePair vout_m   = m_out_m->getValue(frame);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int in0[5], in1[5], out0[5], out1[5];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  in0[0] = vin_rgb.first, in1[0] = vin_rgb.second;
Shinya Kitaoka 120a6e
  out0[0] = vout_rgb.first, out1[0] = vout_rgb.second;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  in0[1] = vin_r.first, in1[1] = vin_r.second;
Shinya Kitaoka 120a6e
  out0[1] = vout_r.first, out1[1] = vout_r.second;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  in0[2] = vin_g.first, in1[2] = vin_g.second;
Shinya Kitaoka 120a6e
  out0[2] = vout_g.first, out1[2] = vout_g.second;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  in0[3] = vin_b.first, in1[3] = vin_b.second;
Shinya Kitaoka 120a6e
  out0[3] = vout_b.first, out1[3] = vout_b.second;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  in0[4] = vin_m.first, in1[4] = vin_m.second;
Shinya Kitaoka 120a6e
  out0[4] = vout_m.first, out1[4] = vout_m.second;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRasterP ras = tile.getRaster();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRop::rgbmAdjust(ras, ras, in0, in1, out0, out1);
Shinya Kitaoka 120a6e
  TRop::gammaCorrect(ras, gamma_rgb);
Shinya Kitaoka 120a6e
  TRop::gammaCorrectRGBM(ras, gamma_r, gamma_g, gamma_b, gamma_m);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(AdjustLevelsFx, "adjustLevelsFx");