Toshihiro Shimizu 890ddd
#include <sstream> /* std::ostringstream */</sstream>
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ino_common.h"
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Shinya Kitaoka 120a6e
class ino_hls_adjust : public TStandardRasterFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(ino_hls_adjust)
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Shinya Kitaoka 120a6e
  TRasterFxPort m_refer;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDoubleParamP m_hue_pivot;
Shinya Kitaoka 120a6e
  TDoubleParamP m_hue_scale;
Shinya Kitaoka 120a6e
  TDoubleParamP m_hue_shift;
Shinya Kitaoka 120a6e
  TDoubleParamP m_lig_pivot;
Shinya Kitaoka 120a6e
  TDoubleParamP m_lig_scale;
Shinya Kitaoka 120a6e
  TDoubleParamP m_lig_shift;
Shinya Kitaoka 120a6e
  TDoubleParamP m_sat_pivot;
Shinya Kitaoka 120a6e
  TDoubleParamP m_sat_scale;
Shinya Kitaoka 120a6e
  TDoubleParamP m_sat_shift;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TBoolParamP m_anti_alias;
Shinya Kitaoka 120a6e
  TIntEnumParamP m_ref_mode;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ino_hls_adjust()
Shinya Kitaoka 120a6e
      : m_hue_pivot(0.0)
Shinya Kitaoka 120a6e
      , m_hue_scale(1.0 * ino::param_range())
Shinya Kitaoka 120a6e
      , m_hue_shift(0.0)
Shinya Kitaoka 120a6e
      , m_lig_pivot(0.0 * ino::param_range())
Shinya Kitaoka 120a6e
      , m_lig_scale(1.0 * ino::param_range())
Shinya Kitaoka 120a6e
      , m_lig_shift(0.0 * ino::param_range())
Shinya Kitaoka 120a6e
      , m_sat_pivot(0.0 * ino::param_range())
Shinya Kitaoka 120a6e
      , m_sat_scale(1.0 * ino::param_range())
Shinya Kitaoka 120a6e
      , m_sat_shift(0.0 * ino::param_range())
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      , m_anti_alias(true)
Shinya Kitaoka 120a6e
      , m_ref_mode(new TIntEnumParam(0, "Red")) {
Shinya Kitaoka 120a6e
    addInputPort("Source", this->m_input);
Shinya Kitaoka 120a6e
    addInputPort("Reference", this->m_refer);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    bindParam(this, "pivot_hue", this->m_hue_pivot);
Shinya Kitaoka 120a6e
    bindParam(this, "pivot_lightness", this->m_lig_pivot);
Shinya Kitaoka 120a6e
    bindParam(this, "pivot_saturation", this->m_sat_pivot);
Shinya Kitaoka 120a6e
    bindParam(this, "scale_hue", this->m_hue_scale);
Shinya Kitaoka 120a6e
    bindParam(this, "scale_lightness", this->m_lig_scale);
Shinya Kitaoka 120a6e
    bindParam(this, "scale_saturation", this->m_sat_scale);
Shinya Kitaoka 120a6e
    bindParam(this, "shift_hue", this->m_hue_shift);
Shinya Kitaoka 120a6e
    bindParam(this, "shift_lightness", this->m_lig_shift);
Shinya Kitaoka 120a6e
    bindParam(this, "shift_saturation", this->m_sat_shift);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    bindParam(this, "anti_alias", this->m_anti_alias);
Shinya Kitaoka 120a6e
    bindParam(this, "reference", this->m_ref_mode);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    this->m_hue_pivot->setValueRange(0.0, 360.0);
Shinya Kitaoka 120a6e
    this->m_hue_scale->setValueRange(0.0 * ino::param_range(),
Shinya Kitaoka 120a6e
                                     std::numeric_limits<double>::max());</double>
Shinya Kitaoka 120a6e
    this->m_lig_pivot->setValueRange(0.0 * ino::param_range(),
Shinya Kitaoka 120a6e
                                     1.0 * ino::param_range());
Shinya Kitaoka 120a6e
    this->m_lig_scale->setValueRange(0.0 * ino::param_range(),
Shinya Kitaoka 120a6e
                                     std::numeric_limits<double>::max());</double>
Shinya Kitaoka 120a6e
    this->m_sat_pivot->setValueRange(0.0 * ino::param_range(),
Shinya Kitaoka 120a6e
                                     1.0 * ino::param_range());
Shinya Kitaoka 120a6e
    this->m_sat_scale->setValueRange(0.0 * ino::param_range(),
Shinya Kitaoka 120a6e
                                     std::numeric_limits<double>::max());</double>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    this->m_ref_mode->addItem(1, "Green");
Shinya Kitaoka 120a6e
    this->m_ref_mode->addItem(2, "Blue");
Shinya Kitaoka 120a6e
    this->m_ref_mode->addItem(3, "Alpha");
Shinya Kitaoka 120a6e
    this->m_ref_mode->addItem(4, "Luminance");
Shinya Kitaoka 120a6e
    this->m_ref_mode->addItem(-1, "Nothing");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  bool doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info) override {
Shinya Kitaoka 120a6e
    if (this->m_input.isConnected()) {
Shinya Kitaoka 120a6e
      return this->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 473e70
  bool canHandle(const TRenderSettings &rend_sets, double frame) override {
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void doCompute(TTile &tile, double frame, const TRenderSettings &rend_sets) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(ino_hls_adjust, "inohlsAdjustFx");
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Toshihiro Shimizu 890ddd
#include "igs_hls_adjust.h"
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
void fx_(TRasterP in_ras, const TRasterP refer_ras, const int ref_mode,
Shinya Kitaoka 120a6e
         const double hue_pivot, const double hue_scale, const double hue_shift,
Shinya Kitaoka 120a6e
         const double lig_pivot, const double lig_scale, const double lig_shift,
Shinya Kitaoka 120a6e
         const double sat_pivot, const double sat_scale, const double sat_shift,
Shinya Kitaoka 120a6e
         const bool anti_alias_sw) {
Shinya Kitaoka 120a6e
  /***std::vector<unsigned char=""> in_vec;</unsigned>
Shinya Kitaoka 120a6e
  ino::ras_to_vec( in_ras, ino::channels(), in_vec );***/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterGR8P in_gr8(in_ras->getLy(),
Shinya Kitaoka 120a6e
                     in_ras->getLx() * ino::channels() *
Shinya Kitaoka 120a6e
                         ((TRaster64P)in_ras ? sizeof(unsigned short)
Shinya Kitaoka 120a6e
                                             : sizeof(unsigned char)));
Shinya Kitaoka 120a6e
  in_gr8->lock();
Shinya Kitaoka 120a6e
  ino::ras_to_arr(in_ras, ino::channels(), in_gr8->getRawData());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  igs::hls_adjust::change(
Shinya Kitaoka 120a6e
      // in_ras->getRawData() // BGRA
Shinya Kitaoka 120a6e
      //&in_vec.at(0) // RGBA
Shinya Kitaoka 120a6e
      in_gr8->getRawData()
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          ,
Shinya Kitaoka 120a6e
      in_ras->getLy(), in_ras->getLx()  // Not use in_ras->getWrap()
Shinya Kitaoka 120a6e
      ,
Shinya Kitaoka 120a6e
      ino::channels(), ino::bits(in_ras)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                           ,
Shinya Kitaoka 120a6e
      (((0 <= ref_mode) && (0 != refer_ras)) ? refer_ras->getRawData()
Shinya Kitaoka 120a6e
                                             : 0)  // BGRA
Shinya Kitaoka 120a6e
      ,
Shinya Kitaoka 120a6e
      (((0 <= ref_mode) && (0 != refer_ras)) ? ino::bits(refer_ras) : 0),
Shinya Kitaoka 120a6e
      ref_mode
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      ,
Shinya Kitaoka 120a6e
      hue_pivot, hue_scale, hue_shift, lig_pivot, lig_scale, lig_shift,
Shinya Kitaoka 120a6e
      sat_pivot, sat_scale, sat_shift
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      //,true	/* add_blend_sw */
Shinya Kitaoka 120a6e
      ,
Shinya Kitaoka 120a6e
      anti_alias_sw);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /***ino::vec_to_ras( in_vec, ino::channels(), in_ras, 0 );***/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ino::arr_to_ras(in_gr8->getRawData(), ino::channels(), in_ras, 0);
Shinya Kitaoka 120a6e
  in_gr8->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Shinya Kitaoka 120a6e
void ino_hls_adjust::doCompute(TTile &tile, double frame,
Shinya Kitaoka 120a6e
                               const TRenderSettings &rend_sets) {
Shinya Kitaoka 120a6e
  /* ------ 接続していなければ処理しない -------------------- */
Shinya Kitaoka 120a6e
  if (!this->m_input.isConnected()) {
Shinya Kitaoka 120a6e
    tile.getRaster()->clear(); /* 塗りつぶしクリア */
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* ------ サポートしていないPixelタイプはエラーを投げる --- */
Shinya Kitaoka 120a6e
  if (!((TRaster32P)tile.getRaster()) && !((TRaster64P)tile.getRaster())) {
Shinya Kitaoka 120a6e
    throw TRopException("unsupported input pixel type");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* ------ 動作パラメータを得る ---------------------------- */
Shinya Kitaoka 120a6e
  const double hue_pivot = this->m_hue_pivot->getValue(frame);
Shinya Kitaoka 120a6e
  const double hue_scale =
Shinya Kitaoka 120a6e
      this->m_hue_scale->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const double hue_shift = this->m_hue_shift->getValue(frame);
Shinya Kitaoka 120a6e
  const double lig_pivot =
Shinya Kitaoka 120a6e
      this->m_lig_pivot->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const double lig_scale =
Shinya Kitaoka 120a6e
      this->m_lig_scale->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const double lig_shift =
Shinya Kitaoka 120a6e
      this->m_lig_shift->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const double sat_pivot =
Shinya Kitaoka 120a6e
      this->m_sat_pivot->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const double sat_scale =
Shinya Kitaoka 120a6e
      this->m_sat_scale->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const double sat_shift =
Shinya Kitaoka 120a6e
      this->m_sat_shift->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const bool anti_alias_sw = this->m_anti_alias->getValue();
Shinya Kitaoka 120a6e
  const int ref_mode       = this->m_ref_mode->getValue();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* ------ 画像生成 ---------------------------------------- */
Shinya Kitaoka 120a6e
  this->m_input->compute(tile, frame, rend_sets);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*------ 参照画像生成 --------------------------------------*/
Shinya Kitaoka 120a6e
  TTile reference_tile;
Shinya Kitaoka 120a6e
  bool reference_sw = false;
Shinya Kitaoka 120a6e
  if (this->m_refer.isConnected()) {
Shinya Kitaoka 120a6e
    reference_sw = true;
Shinya Kitaoka 120a6e
    this->m_refer->allocateAndCompute(
Shinya Kitaoka 120a6e
        reference_tile, tile.m_pos,
Shinya Kitaoka 120a6e
        TDimensionI(/* Pixel単位 */
Shinya Kitaoka 120a6e
                    tile.getRaster()->getLx(), tile.getRaster()->getLy()),
Shinya Kitaoka 120a6e
        tile.getRaster(), frame, rend_sets);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* ------ (app_begin)log記憶 ------------------------------ */
Shinya Kitaoka 120a6e
  const bool log_sw = ino::log_enable_sw();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (log_sw) {
Shinya Kitaoka 120a6e
    std::ostringstream os;
Shinya Kitaoka 120a6e
    os << "params"
Shinya Kitaoka 120a6e
       << "  h_pvt " << hue_pivot << "  h_scl " << hue_scale << "  h_sft "
Shinya Kitaoka 120a6e
       << hue_shift << "  l_pvt " << lig_pivot << "  l_scl " << lig_scale
Shinya Kitaoka 120a6e
       << "  l_sft " << lig_shift << "  s_pvt " << sat_pivot << "  s_scl "
Shinya Kitaoka 120a6e
       << sat_scale << "  s_sft " << sat_shift << "  anti_alias "
Shinya Kitaoka 120a6e
       << anti_alias_sw << "  reference " << ref_mode << "   tile w "
Shinya Kitaoka 120a6e
       << tile.getRaster()->getLx() << "  h " << tile.getRaster()->getLy()
Shinya Kitaoka 120a6e
       << "  pixbits " << ino::pixel_bits(tile.getRaster()) << "   frame "
Shinya Kitaoka 120a6e
       << frame;
Shinya Kitaoka 120a6e
    if (reference_sw) {
Shinya Kitaoka 120a6e
      os << "  reference_tile.m_pos " << reference_tile.m_pos
Shinya Kitaoka 120a6e
         << "  reference_tile_getLx " << reference_tile.getRaster()->getLx()
Shinya Kitaoka 120a6e
         << "  y " << reference_tile.getRaster()->getLy();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /* ------ fx処理 ------------------------------------------ */
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    tile.getRaster()->lock();
Shinya Kitaoka 120a6e
    fx_(tile.getRaster(), (reference_sw ? reference_tile.getRaster() : nullptr),
Shinya Kitaoka 120a6e
        ref_mode, hue_pivot, hue_scale, hue_shift, lig_pivot, lig_scale,
Shinya Kitaoka 120a6e
        lig_shift, sat_pivot, sat_scale, sat_shift,
Shinya Kitaoka 120a6e
        anti_alias_sw  // --> add_blend_sw, default is true
Shinya Kitaoka 120a6e
        );
Shinya Kitaoka 120a6e
    tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /* ------ error処理 --------------------------------------- */
Shinya Kitaoka 120a6e
  catch (std::bad_alloc &e) {
Shinya Kitaoka 120a6e
    tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
    if (log_sw) {
Shinya Kitaoka 120a6e
      std::string str("std::bad_alloc <");
Shinya Kitaoka 120a6e
      str += e.what();
Shinya Kitaoka 120a6e
      str += '>';
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    throw;
Shinya Kitaoka 120a6e
  } catch (std::exception &e) {
Shinya Kitaoka 120a6e
    tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
    if (log_sw) {
Shinya Kitaoka 120a6e
      std::string str("exception <");
Shinya Kitaoka 120a6e
      str += e.what();
Shinya Kitaoka 120a6e
      str += '>';
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    throw;
Shinya Kitaoka 120a6e
  } catch (...) {
Shinya Kitaoka 120a6e
    tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
    if (log_sw) {
Shinya Kitaoka 120a6e
      std::string str("other exception");
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    throw;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}