Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
template <typename pixel="" t,="" typename=""></typename>
Shinya Kitaoka 120a6e
void prepare_lut(double max, int edge, std::vector<t> &lut) {</t>
Shinya Kitaoka 120a6e
  double aux = (double)PIXEL::maxChannelValue;
Shinya Kitaoka 120a6e
  int i      = 0;
Shinya Kitaoka 120a6e
  for (i = 0; i <= edge; i++) {
Shinya Kitaoka 120a6e
    lut[i] = (int)((max / edge) * i);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  for (i = edge + 1; i < PIXEL::maxChannelValue + 1; i++) {
Shinya Kitaoka 120a6e
    lut[i] = (int)((max / (edge - aux)) * (i - aux));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class SolarizeFx final : public TStandardRasterFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(SolarizeFx)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Shinya Kitaoka 120a6e
  TDoubleParamP m_maximum;
Shinya Kitaoka 120a6e
  TDoubleParamP m_edge;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SolarizeFx() : m_maximum(1.0), m_edge(128.0) {
Shinya Kitaoka 120a6e
    bindParam(this, "maximum", m_maximum);
Shinya Kitaoka 120a6e
    bindParam(this, "peak_edge", m_edge);
Shinya Kitaoka 120a6e
    addInputPort("Source", m_input);
Shinya Kitaoka 120a6e
    // m_value->setValueRange(0, std::numeric_limits<double>::max());</double>
Shinya Kitaoka 120a6e
    m_maximum->setValueRange(0.0, 10.0);
Shinya Kitaoka 120a6e
    m_edge->setValueRange(0.0, 255.0);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~SolarizeFx(){};
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
      bool ret = m_input->doGetBBox(frame, bBox, info);
Shinya Kitaoka 120a6e
      return ret;
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;
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
};
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
template <typename t=""></typename>
Shinya Kitaoka 120a6e
void update_param(T ¶m, TRaster32P ras) {
Shinya Kitaoka 120a6e
  return;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename t=""></typename>
Shinya Kitaoka 120a6e
void update_param(T ¶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 doSolarize(TRasterPT<pixel> ras, double max, int edge) {</pixel>
Shinya Kitaoka 120a6e
  std::vector<channel_type> solarize_lut(PIXEL::maxChannelValue + 1);</channel_type>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  update_param(max, ras);
Shinya Kitaoka 120a6e
  update_param(edge, ras);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  prepare_lut<channel_type, pixel="">(max, edge, solarize_lut);</channel_type,>
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->r = (CHANNEL_TYPE)(solarize_lut[(int)(pix->r)]);
Shinya Kitaoka 120a6e
      pix->g = (CHANNEL_TYPE)(solarize_lut[(int)(pix->g)]);
Shinya Kitaoka 120a6e
      pix->b = (CHANNEL_TYPE)(solarize_lut[(int)(pix->b)]);
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
Shinya Kitaoka 120a6e
void SolarizeFx::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 min, max, step;
Shinya Kitaoka 120a6e
  m_maximum->getValueRange(min, max, step);
Shinya Kitaoka 120a6e
  double maxValue = 128 * tcrop(m_maximum->getValue(frame), min, max);
Shinya Kitaoka 120a6e
  m_edge->getValueRange(min, max, step);
Shinya Kitaoka 120a6e
  int edge = (int)tcrop(m_edge->getValue(frame), min, max);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRaster32P raster32 = tile.getRaster();
Shinya Kitaoka 120a6e
  if (raster32)
Shinya Kitaoka 120a6e
    doSolarize<tpixel32, uchar="">(raster32, maxValue, edge);</tpixel32,>
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    TRaster64P raster64 = tile.getRaster();
Shinya Kitaoka 120a6e
    if (raster64)
Shinya Kitaoka 120a6e
      doSolarize<tpixel64, ushort="">(raster64, maxValue, edge);</tpixel64,>
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      throw TException("SolarizeFx: unsupported Pixel Type");
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(SolarizeFx, "solarizeFx");