Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
void ropSharpen(const TRasterPT<t> &rin, TRasterPT<t> &rout,</t></t>
Shinya Kitaoka 120a6e
                int sharpen_max_corr) {
Shinya Kitaoka 120a6e
  T *bufin, *east, *northeast, *southeast;
Shinya Kitaoka 120a6e
  T *bufout, *pixout;
Shinya Kitaoka 120a6e
  int lx, ly, wrapin, wrapout, x, y, count;
Shinya Kitaoka 120a6e
  int cntr_r, east_r, col_west_r, col_cntr_r, col_east_r;
Shinya Kitaoka 120a6e
  int cntr_g, east_g, col_west_g, col_cntr_g, col_east_g;
Shinya Kitaoka 120a6e
  int cntr_b, east_b, col_west_b, col_cntr_b, col_east_b;
Shinya Kitaoka 120a6e
  int cntr_m, east_m, col_west_m, col_cntr_m, col_east_m;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int lapl, out;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#define SET_PIXOUT(X)                                                          \
Shinya Kitaoka 120a6e
  {                                                                            \
Shinya Kitaoka 120a6e
    lapl = (cntr_##X << 3) + cntr_##X -                                        \
Shinya Kitaoka 120a6e
           (col_west_##X + col_cntr_##X + col_east_##X);                       \
Shinya Kitaoka 120a6e
    if (lapl < 0) {                                                            \
Shinya Kitaoka 120a6e
      out       = cntr_##X - ((256 * 4 - lapl * sharpen_max_corr) >> (8 + 3)); \
Shinya Kitaoka 120a6e
      pixout->X = (out <= 0) ? 0 : out;                                        \
Shinya Kitaoka 120a6e
    } else {                                                                   \
Shinya Kitaoka 120a6e
      out       = cntr_##X + ((256 * 4 + lapl * sharpen_max_corr) >> (8 + 3)); \
Shinya Kitaoka 120a6e
      pixout->X = (out >= maxChanVal) ? maxChanVal : out;                      \
Shinya Kitaoka 120a6e
    }                                                                          \
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  rin->lock();
Shinya Kitaoka 120a6e
  rout->lock();
Shinya Kitaoka 120a6e
  bufin          = (T *)rin->getRawData();
Shinya Kitaoka 120a6e
  bufout         = (T *)rout->getRawData();
Shinya Kitaoka 120a6e
  lx             = std::min(rin->getLx(), rout->getLx());
Shinya Kitaoka 120a6e
  ly             = std::min(rin->getLy(), rout->getLy());
Shinya Kitaoka 120a6e
  wrapin         = rin->getWrap();
Shinya Kitaoka 120a6e
  wrapout        = rout->getWrap();
Shinya Kitaoka 120a6e
  int maxChanVal = T::maxChannelValue;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (lx <= 1 || ly <= 1) {
Shinya Kitaoka 120a6e
    for (y = 0; y < ly; y++)
Shinya Kitaoka 120a6e
      for (x = 0; x < lx; x++) bufout[x + y * wrapout] = bufin[x + y * wrapin];
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  east       = bufin;
Shinya Kitaoka 120a6e
  northeast  = east + wrapin;
Shinya Kitaoka 120a6e
  east_r     = east->r;
Shinya Kitaoka 120a6e
  east_g     = east->g;
Shinya Kitaoka 120a6e
  east_b     = east->b;
Shinya Kitaoka 120a6e
  east_m     = east->m;
Shinya Kitaoka 120a6e
  col_east_r = 2 * east_r + northeast->r;
Shinya Kitaoka 120a6e
  col_east_g = 2 * east_g + northeast->g;
Shinya Kitaoka 120a6e
  col_east_b = 2 * east_b + northeast->b;
Shinya Kitaoka 120a6e
  col_east_m = 2 * east_m + northeast->m;
Shinya Kitaoka 120a6e
  col_cntr_r = col_east_r;
Shinya Kitaoka 120a6e
  col_cntr_g = col_east_g;
Shinya Kitaoka 120a6e
  col_cntr_b = col_east_b;
Shinya Kitaoka 120a6e
  col_cntr_m = col_east_m;
Shinya Kitaoka 120a6e
  east++;
Shinya Kitaoka 120a6e
  northeast++;
Shinya Kitaoka 120a6e
  pixout = bufout;
Shinya Kitaoka 120a6e
  for (count = lx - 1; count > 0; count--, east++, northeast++, pixout++) {
Shinya Kitaoka 120a6e
    cntr_r     = east_r;
Shinya Kitaoka 120a6e
    east_r     = east->r;
Shinya Kitaoka 120a6e
    col_west_r = col_cntr_r;
Shinya Kitaoka 120a6e
    col_cntr_r = col_east_r;
Shinya Kitaoka 120a6e
    col_east_r = 2 * east_r + northeast->r;
Shinya Kitaoka 120a6e
    SET_PIXOUT(r)
Shinya Kitaoka 120a6e
    cntr_g     = east_g;
Shinya Kitaoka 120a6e
    east_g     = east->g;
Shinya Kitaoka 120a6e
    col_west_g = col_cntr_g;
Shinya Kitaoka 120a6e
    col_cntr_g = col_east_g;
Shinya Kitaoka 120a6e
    col_east_g = 2 * east_g + northeast->g;
Shinya Kitaoka 120a6e
    SET_PIXOUT(g)
Shinya Kitaoka 120a6e
    cntr_b     = east_b;
Shinya Kitaoka 120a6e
    east_b     = east->b;
Shinya Kitaoka 120a6e
    col_west_b = col_cntr_b;
Shinya Kitaoka 120a6e
    col_cntr_b = col_east_b;
Shinya Kitaoka 120a6e
    col_east_b = 2 * east_b + northeast->b;
Shinya Kitaoka 120a6e
    SET_PIXOUT(b)
Shinya Kitaoka 120a6e
    cntr_m     = east_m;
Shinya Kitaoka 120a6e
    east_m     = east->m;
Shinya Kitaoka 120a6e
    col_west_m = col_cntr_m;
Shinya Kitaoka 120a6e
    col_cntr_m = col_east_m;
Shinya Kitaoka 120a6e
    col_east_m = 2 * east_m + northeast->m;
Shinya Kitaoka 120a6e
    SET_PIXOUT(m)
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  cntr_r     = east_r;
Shinya Kitaoka 120a6e
  col_west_r = col_cntr_r;
Shinya Kitaoka 120a6e
  col_cntr_r = col_east_r;
Shinya Kitaoka 120a6e
  SET_PIXOUT(r)
Shinya Kitaoka 120a6e
  cntr_g     = east_g;
Shinya Kitaoka 120a6e
  col_west_g = col_cntr_g;
Shinya Kitaoka 120a6e
  col_cntr_g = col_east_g;
Shinya Kitaoka 120a6e
  SET_PIXOUT(g)
Shinya Kitaoka 120a6e
  cntr_b     = east_b;
Shinya Kitaoka 120a6e
  col_west_b = col_cntr_b;
Shinya Kitaoka 120a6e
  col_cntr_b = col_east_b;
Shinya Kitaoka 120a6e
  SET_PIXOUT(b)
Shinya Kitaoka 120a6e
  cntr_m     = east_m;
Shinya Kitaoka 120a6e
  col_west_m = col_cntr_m;
Shinya Kitaoka 120a6e
  col_cntr_m = col_east_m;
Shinya Kitaoka 120a6e
  SET_PIXOUT(m)
Shinya Kitaoka 120a6e
  for (y = 1; y < ly - 1; y++) {
Shinya Kitaoka 120a6e
    east       = bufin + y * wrapin;
Shinya Kitaoka 120a6e
    northeast  = east + wrapin;
Shinya Kitaoka 120a6e
    southeast  = east - wrapin;
Shinya Kitaoka 120a6e
    east_r     = east->r;
Shinya Kitaoka 120a6e
    east_g     = east->g;
Shinya Kitaoka 120a6e
    east_b     = east->b;
Shinya Kitaoka 120a6e
    east_m     = east->m;
Shinya Kitaoka 120a6e
    col_east_r = east_r + northeast->r + southeast->r;
Shinya Kitaoka 120a6e
    col_east_g = east_g + northeast->g + southeast->g;
Shinya Kitaoka 120a6e
    col_east_b = east_b + northeast->b + southeast->b;
Shinya Kitaoka 120a6e
    col_east_m = east_m + northeast->m + southeast->m;
Shinya Kitaoka 120a6e
    col_cntr_r = col_east_r;
Shinya Kitaoka 120a6e
    col_cntr_g = col_east_g;
Shinya Kitaoka 120a6e
    col_cntr_b = col_east_b;
Shinya Kitaoka 120a6e
    col_cntr_m = col_east_m;
Shinya Kitaoka 120a6e
    east++;
Shinya Kitaoka 120a6e
    northeast++;
Shinya Kitaoka 120a6e
    southeast++;
Shinya Kitaoka 120a6e
    pixout = bufout + y * wrapout;
Shinya Kitaoka 120a6e
    for (count = lx - 1; count > 0;
Shinya Kitaoka 120a6e
         count--, east++, northeast++, southeast++, pixout++) {
Shinya Kitaoka 120a6e
      cntr_r     = east_r;
Shinya Kitaoka 120a6e
      east_r     = east->r;
Shinya Kitaoka 120a6e
      col_west_r = col_cntr_r;
Shinya Kitaoka 120a6e
      col_cntr_r = col_east_r;
Shinya Kitaoka 120a6e
      col_east_r = east_r + northeast->r + southeast->r;
Shinya Kitaoka 120a6e
      SET_PIXOUT(r)
Shinya Kitaoka 120a6e
      cntr_g     = east_g;
Shinya Kitaoka 120a6e
      east_g     = east->g;
Shinya Kitaoka 120a6e
      col_west_g = col_cntr_g;
Shinya Kitaoka 120a6e
      col_cntr_g = col_east_g;
Shinya Kitaoka 120a6e
      col_east_g = east_g + northeast->g + southeast->g;
Shinya Kitaoka 120a6e
      SET_PIXOUT(g)
Shinya Kitaoka 120a6e
      cntr_b     = east_b;
Shinya Kitaoka 120a6e
      east_b     = east->b;
Shinya Kitaoka 120a6e
      col_west_b = col_cntr_b;
Shinya Kitaoka 120a6e
      col_cntr_b = col_east_b;
Shinya Kitaoka 120a6e
      col_east_b = east_b + northeast->b + southeast->b;
Shinya Kitaoka 120a6e
      SET_PIXOUT(b)
Shinya Kitaoka 120a6e
      cntr_m     = east_m;
Shinya Kitaoka 120a6e
      east_m     = east->m;
Shinya Kitaoka 120a6e
      col_west_m = col_cntr_m;
Shinya Kitaoka 120a6e
      col_cntr_m = col_east_m;
Shinya Kitaoka 120a6e
      col_east_m = east_m + northeast->m + southeast->m;
Shinya Kitaoka 120a6e
      SET_PIXOUT(m)
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    cntr_r     = east_r;
Shinya Kitaoka 120a6e
    col_west_r = col_cntr_r;
Shinya Kitaoka 120a6e
    col_cntr_r = col_east_r;
Shinya Kitaoka 120a6e
    SET_PIXOUT(r)
Shinya Kitaoka 120a6e
    cntr_g     = east_g;
Shinya Kitaoka 120a6e
    col_west_g = col_cntr_g;
Shinya Kitaoka 120a6e
    col_cntr_g = col_east_g;
Shinya Kitaoka 120a6e
    SET_PIXOUT(g)
Shinya Kitaoka 120a6e
    cntr_b     = east_b;
Shinya Kitaoka 120a6e
    col_west_b = col_cntr_b;
Shinya Kitaoka 120a6e
    col_cntr_b = col_east_b;
Shinya Kitaoka 120a6e
    SET_PIXOUT(b)
Shinya Kitaoka 120a6e
    cntr_m     = east_m;
Shinya Kitaoka 120a6e
    col_west_m = col_cntr_m;
Shinya Kitaoka 120a6e
    col_cntr_m = col_east_m;
Shinya Kitaoka 120a6e
    SET_PIXOUT(m)
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  east       = bufin + y * wrapin;
Shinya Kitaoka 120a6e
  southeast  = east - wrapin;
Shinya Kitaoka 120a6e
  east_r     = east->r;
Shinya Kitaoka 120a6e
  east_g     = east->g;
Shinya Kitaoka 120a6e
  east_b     = east->b;
Shinya Kitaoka 120a6e
  east_m     = east->m;
Shinya Kitaoka 120a6e
  col_east_r = 2 * east_r + southeast->r;
Shinya Kitaoka 120a6e
  col_east_g = 2 * east_g + southeast->g;
Shinya Kitaoka 120a6e
  col_east_b = 2 * east_b + southeast->b;
Shinya Kitaoka 120a6e
  col_east_m = 2 * east_m + southeast->m;
Shinya Kitaoka 120a6e
  col_cntr_r = col_east_r;
Shinya Kitaoka 120a6e
  col_cntr_g = col_east_g;
Shinya Kitaoka 120a6e
  col_cntr_b = col_east_b;
Shinya Kitaoka 120a6e
  col_cntr_m = col_east_m;
Shinya Kitaoka 120a6e
  east++;
Shinya Kitaoka 120a6e
  southeast++;
Shinya Kitaoka 120a6e
  pixout = bufout + y * wrapout;
Shinya Kitaoka 120a6e
  for (count = lx - 1; count > 0; count--, east++, southeast++, pixout++) {
Shinya Kitaoka 120a6e
    cntr_r     = east_r;
Shinya Kitaoka 120a6e
    east_r     = east->r;
Shinya Kitaoka 120a6e
    col_west_r = col_cntr_r;
Shinya Kitaoka 120a6e
    col_cntr_r = col_east_r;
Shinya Kitaoka 120a6e
    col_east_r = 2 * east_r + southeast->r;
Shinya Kitaoka 120a6e
    SET_PIXOUT(r)
Shinya Kitaoka 120a6e
    cntr_g     = east_g;
Shinya Kitaoka 120a6e
    east_g     = east->g;
Shinya Kitaoka 120a6e
    col_west_g = col_cntr_g;
Shinya Kitaoka 120a6e
    col_cntr_g = col_east_g;
Shinya Kitaoka 120a6e
    col_east_g = 2 * east_g + southeast->g;
Shinya Kitaoka 120a6e
    SET_PIXOUT(g)
Shinya Kitaoka 120a6e
    cntr_b     = east_b;
Shinya Kitaoka 120a6e
    east_b     = east->b;
Shinya Kitaoka 120a6e
    col_west_b = col_cntr_b;
Shinya Kitaoka 120a6e
    col_cntr_b = col_east_b;
Shinya Kitaoka 120a6e
    col_east_b = 2 * east_b + southeast->b;
Shinya Kitaoka 120a6e
    SET_PIXOUT(b)
Shinya Kitaoka 120a6e
    cntr_m     = east_m;
Shinya Kitaoka 120a6e
    east_m     = east->m;
Shinya Kitaoka 120a6e
    col_west_m = col_cntr_m;
Shinya Kitaoka 120a6e
    col_cntr_m = col_east_m;
Shinya Kitaoka 120a6e
    col_east_m = 2 * east_m + southeast->m;
Shinya Kitaoka 120a6e
    SET_PIXOUT(m)
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  cntr_r     = east_r;
Shinya Kitaoka 120a6e
  col_west_r = col_cntr_r;
Shinya Kitaoka 120a6e
  col_cntr_r = col_east_r;
Shinya Kitaoka 120a6e
  SET_PIXOUT(r)
Shinya Kitaoka 120a6e
  cntr_g     = east_g;
Shinya Kitaoka 120a6e
  col_west_g = col_cntr_g;
Shinya Kitaoka 120a6e
  col_cntr_g = col_east_g;
Shinya Kitaoka 120a6e
  SET_PIXOUT(g)
Shinya Kitaoka 120a6e
  cntr_b     = east_b;
Shinya Kitaoka 120a6e
  col_west_b = col_cntr_b;
Shinya Kitaoka 120a6e
  col_cntr_b = col_east_b;
Shinya Kitaoka 120a6e
  SET_PIXOUT(b)
Shinya Kitaoka 120a6e
  cntr_m     = east_m;
Shinya Kitaoka 120a6e
  col_west_m = col_cntr_m;
Shinya Kitaoka 120a6e
  col_cntr_m = col_east_m;
Shinya Kitaoka 120a6e
  SET_PIXOUT(m)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  rin->unlock();
Shinya Kitaoka 120a6e
  rout->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class SharpenFx final : public TStandardRasterFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(SharpenFx)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Shinya Kitaoka 120a6e
  TDoubleParamP m_intensity;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SharpenFx()
Shinya Kitaoka 120a6e
      : m_intensity(50)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    bindParam(this, "intensity", m_intensity);
Shinya Kitaoka 120a6e
    addInputPort("Source", m_input);
Shinya Kitaoka 120a6e
    m_intensity->setValueRange(0.0, 999999, 1);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ~SharpenFx(){};
Toshihiro Shimizu 890ddd
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
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void doCompute(TTile &tile, double frame, const TRenderSettings &ri) override;
Toshihiro Shimizu 890ddd
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
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SharpenFx::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
  int intensity = troundp(m_intensity->getValue(frame));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRasterP srcRas = tile.getRaster()->create(tile.getRaster()->getLx(),
Shinya Kitaoka 120a6e
                                             tile.getRaster()->getLy());
Shinya Kitaoka 120a6e
  // TRaster32P srcRas(tile.getRaster()->getLx() + border*2,
Shinya Kitaoka 120a6e
  // tile.getRaster()->getLy() + border*2);
Shinya Kitaoka 120a6e
  TTile srcTile(srcRas, tile.m_pos);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_input->compute(srcTile, frame, ri);
Shinya Kitaoka 120a6e
  TRaster32P raster32    = tile.getRaster();
Shinya Kitaoka 120a6e
  TRaster32P srcraster32 = srcTile.getRaster();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (raster32) ropSharpen<tpixel32>(srcraster32, raster32, intensity);</tpixel32>
Shinya Kitaoka 120a6e
  // doEmboss<tpixel32, tpixelgr8,="" uchar="">(raster32, srcraster32, azimuth,</tpixel32,>
Shinya Kitaoka 120a6e
  // elevation, intensity, border);
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    TRaster64P raster64    = tile.getRaster();
Shinya Kitaoka 120a6e
    TRaster64P srcraster64 = srcTile.getRaster();
Shinya Kitaoka 120a6e
    if (raster64)
Shinya Kitaoka 120a6e
      ropSharpen<tpixel64>(srcraster64, raster64, intensity);</tpixel64>
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      throw TException("sharpen: unsupported Pixel Type");
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(SharpenFx, "sharpenFx");