Toshihiro Shimizu 890ddd
#include <sstream> /* std::ostringstream */</sstream>
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Shinya Kitaoka 120a6e
#include "tparamset.h"  // TPointParamP
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Shinya Kitaoka 120a6e
#include "tparamuiconcept.h"  //add 20140130
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ino_common.h"
Toshihiro Shimizu 890ddd
#include "igs_radial_blur.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
const double ino_param_range = 100.0;
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka d1f6c4
class ino_radial_blur final : public TStandardRasterFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(ino_radial_blur)
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Shinya Kitaoka 120a6e
  TRasterFxPort m_refer;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPointParamP m_center;
Shinya Kitaoka 120a6e
  TDoubleParamP m_blur;
Shinya Kitaoka 120a6e
  TDoubleParamP m_radius;
Shinya Kitaoka 120a6e
  TDoubleParamP m_twist;
Shinya Kitaoka 120a6e
  // TDoubleParamP m_twist_radius;
Shinya Kitaoka 120a6e
  TBoolParamP m_alpha_rendering;
Shinya Kitaoka 120a6e
  TBoolParamP m_anti_alias;
Shinya Kitaoka 120a6e
  TIntEnumParamP m_ref_mode;
shun-iwasawa a6544b
  TIntEnumParamP m_type;
shun-iwasawa a6544b
  // elliptical shape
shun-iwasawa a6544b
  TDoubleParamP m_ellipse_aspect_ratio;
shun-iwasawa a6544b
  TDoubleParamP m_ellipse_angle;
shun-iwasawa a6544b
  TDoubleParamP m_intensity_correlation_with_ellipse;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ino_radial_blur()
Shinya Kitaoka 120a6e
      : m_center(TPointD(0.0, 0.0))
Shinya Kitaoka 120a6e
      , m_blur(0.01 * ino_param_range)
Shinya Kitaoka 120a6e
      , m_radius(0.0)
Shinya Kitaoka 120a6e
      , m_twist(0.0)
Shinya Kitaoka 120a6e
      // ,m_twist_radius(0.0)
Shinya Kitaoka 120a6e
      , m_alpha_rendering(true)
Shinya Kitaoka 120a6e
      , m_anti_alias(false)
shun-iwasawa a6544b
      , m_ref_mode(new TIntEnumParam(0, "Red"))
shun-iwasawa a6544b
      , m_type(new TIntEnumParam(0, "Accelerator"))
shun-iwasawa a6544b
      , m_ellipse_aspect_ratio(1.0)
shun-iwasawa a6544b
      , m_ellipse_angle(0.0)
shun-iwasawa a6544b
      , m_intensity_correlation_with_ellipse(0.0) {
Shinya Kitaoka 120a6e
    this->m_center->getX()->setMeasureName("fxLength");
Shinya Kitaoka 120a6e
    this->m_center->getY()->setMeasureName("fxLength");
Shinya Kitaoka 120a6e
    this->m_radius->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    addInputPort("Source", this->m_input);
Shinya Kitaoka 120a6e
    addInputPort("Reference", this->m_refer);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    bindParam(this, "center", this->m_center);
Shinya Kitaoka 120a6e
    bindParam(this, "blur", this->m_blur);
Shinya Kitaoka 120a6e
    bindParam(this, "radius", this->m_radius);
Shinya Kitaoka 120a6e
    bindParam(this, "twist", this->m_twist);
Shinya Kitaoka 120a6e
    // bindParam(this,"twist_radius", this->m_twist_radius);
Shinya Kitaoka 120a6e
    bindParam(this, "alpha_rendering", this->m_alpha_rendering);
Shinya Kitaoka 120a6e
    bindParam(this, "anti_alias", this->m_anti_alias);
Shinya Kitaoka 120a6e
    bindParam(this, "reference", this->m_ref_mode);
shun-iwasawa a6544b
    bindParam(this, "type", this->m_type);
shun-iwasawa a6544b
    bindParam(this, "ellipse_aspect_ratio", this->m_ellipse_aspect_ratio);
shun-iwasawa a6544b
    bindParam(this, "ellipse_angle", this->m_ellipse_angle);
shun-iwasawa a6544b
    bindParam(this, "intensity_correlation_with_ellipse",
shun-iwasawa a6544b
              this->m_intensity_correlation_with_ellipse);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    this->m_radius->setValueRange(0, (std::numeric_limits<double>::max)());</double>
Shinya Kitaoka 120a6e
    /* 拡大のしすぎを防ぐためにMaxを制限する */
Shinya Kitaoka 120a6e
    this->m_blur->setValueRange(0.0 * ino_param_range, 1.0 * ino_param_range);
shun-iwasawa a6544b
    this->m_ellipse_aspect_ratio->setValueRange(0.1, 10.0);
shun-iwasawa a6544b
    this->m_ellipse_angle->setValueRange(-180.0, 180.0);
Shinya Kitaoka 120a6e
    this->m_twist->setValueRange(-180.0, 180.0);
Shinya Kitaoka 120a6e
    // this->m_twist_radius->setValueRange(0.0,1000.0);
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");
shun-iwasawa a6544b
    this->m_type->addItem(1, "Uniform Length");
shun-iwasawa a6544b
    this->m_intensity_correlation_with_ellipse->setValueRange(-1.0, 1.0);
shun-iwasawa 481b59
shun-iwasawa 481b59
    enableComputeInFloat(true);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  //------------------------------------------------------------
Shinya Kitaoka 120a6e
  TPointD get_render_center(const double frame, const TPointD &pos,
Shinya Kitaoka 120a6e
                            const TAffine affine) {
Shinya Kitaoka 120a6e
    /*--- 表示画像の中心をゼロとしたミリメートル単位の位置 ---*/
Shinya Kitaoka 120a6e
    TPointD center = this->m_center->getValue(frame);
Shinya Kitaoka 120a6e
    /*--- 単位変換(mm --> render用pixel) ---*/
Shinya Kitaoka 120a6e
    center = center * ino::pixel_per_mm();
Shinya Kitaoka 120a6e
    /*--- Affine変換(Geometry&Shrink&原点を中心から左下へ) ---*/
Shinya Kitaoka 120a6e
    center = affine * center;
Shinya Kitaoka 120a6e
    /*--- カメラ座標をrender画像座標の原点に ---*/
Shinya Kitaoka 120a6e
    return center - pos;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  int get_render_int_margin(const double frame, const TRectD &bBox,
shun-iwasawa a6544b
                            const TAffine affine, TPointD center,
shun-iwasawa a6544b
                            double blur_radius, double pivot_radius) {
Shinya Kitaoka 120a6e
    /*--- 単位変換(mm-->render用pixel)と長さ(scale)変換 ---*/
Shinya Kitaoka 120a6e
    const double scale = ino::pixel_per_mm() * sqrt(fabs(affine.det()));
Shinya Kitaoka 120a6e
    /*--- margin計算...Twist時正確でない ---*/
Shinya Kitaoka 120a6e
    return igs::radial_blur::reference_margin(
Shinya Kitaoka 120a6e
        static_cast<int>(ceil(bBox.getLy())),</int>
shun-iwasawa a6544b
        static_cast<int>(ceil(bBox.getLx())), center,</int>
shun-iwasawa a6544b
        this->m_twist->getValue(frame) * M_PI_180, pivot_radius,
shun-iwasawa a6544b
        this->m_blur->getValue(frame) / ino_param_range, blur_radius,
shun-iwasawa a6544b
        this->m_type->getValue(), this->m_ellipse_aspect_ratio->getValue(frame),
shun-iwasawa a6544b
        this->m_ellipse_angle->getValue(frame),
shun-iwasawa a6544b
        this->m_intensity_correlation_with_ellipse->getValue(frame));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void get_render_enlarge(const double frame, const TAffine affine,
shun-iwasawa a6544b
                          TRectD &bBox, double blur_radius,
shun-iwasawa a6544b
                          double pivot_radius) {
Shinya Kitaoka 120a6e
    TPointD center(this->get_render_center(frame, bBox.getP00(), affine));
shun-iwasawa a6544b
    int margin = this->get_render_int_margin(frame, bBox, affine, center,
shun-iwasawa a6544b
                                             blur_radius, pivot_radius);
Shinya Kitaoka 120a6e
    if (0 < margin) {
Shinya Kitaoka 120a6e
      /* 拡大のしすぎを防ぐテキトーな制限 */
Shinya Kitaoka 120a6e
      if (4096 < margin) {
Shinya Kitaoka 120a6e
        margin = 4096;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      bBox = bBox.enlarge(margin);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  //------------------------------------------------------------
Shinya Kitaoka 38fd86
  bool doGetBBox(double frame, TRectD &bBox,
Shinya Kitaoka 38fd86
                 const TRenderSettings &info) override {
Shinya Kitaoka 120a6e
    if (!this->m_input.isConnected()) {
Shinya Kitaoka 120a6e
      bBox = TRectD();
Shinya Kitaoka 120a6e
      return false;
Shinya Kitaoka 120a6e
    }
shun-iwasawa a6544b
    const bool ret      = this->m_input->doGetBBox(frame, bBox, info);
shun-iwasawa a6544b
    const double scale  = ino::pixel_per_mm() * sqrt(fabs(info.m_affine.det()));
shun-iwasawa a6544b
    const double radius = this->m_radius->getValue(frame) * scale;
shun-iwasawa a6544b
    const double pivot_radius = info.m_cameraBox.getLy() / 2.0;
shun-iwasawa a6544b
    this->get_render_enlarge(frame, info.m_affine, bBox, radius, pivot_radius);
Shinya Kitaoka 120a6e
    return ret;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  int getMemoryRequirement(const TRectD &rect, double frame,
Shinya Kitaoka 473e70
                           const TRenderSettings &info) override {
Shinya Kitaoka 120a6e
    TRectD bBox(rect);
shun-iwasawa a6544b
    const double scale  = ino::pixel_per_mm() * sqrt(fabs(info.m_affine.det()));
shun-iwasawa a6544b
    const double radius = this->m_radius->getValue(frame) * scale;
shun-iwasawa a6544b
    const double pivot_radius = info.m_cameraBox.getLy() / 2.0;
shun-iwasawa a6544b
    this->get_render_enlarge(frame, info.m_affine, bBox, radius, pivot_radius);
Shinya Kitaoka 120a6e
    return TRasterFx::memorySize(bBox, info.m_bpp);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void transform(double frame, int port, const TRectD &rectOnOutput,
Shinya Kitaoka 120a6e
                 const TRenderSettings &infoOnOutput, TRectD &rectOnInput,
Shinya Kitaoka 473e70
                 TRenderSettings &infoOnInput) override {
Shinya Kitaoka 120a6e
    rectOnInput = rectOnOutput;
Shinya Kitaoka 120a6e
    infoOnInput = infoOnOutput;
shun-iwasawa a6544b
    const double scale =
shun-iwasawa a6544b
        ino::pixel_per_mm() * sqrt(fabs(infoOnInput.m_affine.det()));
shun-iwasawa a6544b
    const double radius       = this->m_radius->getValue(frame) * scale;
shun-iwasawa a6544b
    const double pivot_radius = infoOnInput.m_cameraBox.getLy() / 2.0;
shun-iwasawa a6544b
    this->get_render_enlarge(frame, infoOnOutput.m_affine, rectOnInput, radius,
shun-iwasawa a6544b
                             pivot_radius);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  bool canHandle(const TRenderSettings &info, double frame) override {
Shinya Kitaoka 120a6e
    // return false; // toonz has geometry control
Shinya Kitaoka 120a6e
    // return true;
Shinya Kitaoka 120a6e
    /* 2012-11-14:
Shinya Kitaoka 120a6e
     * trueのとき、Fx処理がジオメトリ変換の最後にまとめられてしまう。 */
Shinya Kitaoka 120a6e
    return m_blur->getValue(frame) == 0 ? true
Shinya Kitaoka 120a6e
                                        : isAlmostIsotropic(info.m_affine);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void doCompute(TTile &tile, double frame, const TRenderSettings &ri) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // add 20140130
Shinya Kitaoka 473e70
  void getParamUIs(TParamUIConcept *&concepts, int &length) override {
shun-iwasawa a6544b
    concepts            = new TParamUIConcept[length = 2];
shun-iwasawa a6544b
    concepts[0].m_type  = TParamUIConcept::ELLIPSE;
shun-iwasawa a6544b
    concepts[0].m_label = "Radius";
shun-iwasawa a6544b
    concepts[0].m_params.push_back(m_radius);
Shinya Kitaoka 120a6e
    concepts[0].m_params.push_back(m_center);
shun-iwasawa a6544b
    concepts[0].m_params.push_back(m_ellipse_aspect_ratio);
shun-iwasawa a6544b
    concepts[0].m_params.push_back(m_ellipse_angle);
shun-iwasawa a6544b
    concepts[0].m_params.push_back(m_twist);
Toshihiro Shimizu 890ddd
shun-iwasawa a6544b
    concepts[1].m_type = TParamUIConcept::COMPASS;
Shinya Kitaoka 120a6e
    concepts[1].m_params.push_back(m_center);
shun-iwasawa a6544b
    concepts[1].m_params.push_back(m_ellipse_aspect_ratio);
shun-iwasawa a6544b
    concepts[1].m_params.push_back(m_ellipse_angle);
shun-iwasawa a6544b
    concepts[1].m_params.push_back(m_twist);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  // add 20140130
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(ino_radial_blur, "inoRadialBlurFx");
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Shinya Kitaoka 120a6e
namespace {
shun-iwasawa a6544b
void fx_(const TRasterP in_ras,  // with margin
shun-iwasawa a6544b
         const int margin, /* ここではinとrefは同サイズで使用している */
shun-iwasawa a6544b
         const TRasterP refer_ras,  // no margin
shun-iwasawa a6544b
         const int refer_mode,
shun-iwasawa a6544b
         TRasterP out_ras,  // no margin
shun-iwasawa a6544b
         const TPointD center, const double twist, const double blur,
shun-iwasawa a6544b
         const double radius, const double pivot_radius,
shun-iwasawa a6544b
         const bool alpha_rendering_sw, const bool anti_alias_sw,
shun-iwasawa a6544b
         const int type, const double ellipse_aspect_ratio,
shun-iwasawa a6544b
         const double ellipse_angle,
shun-iwasawa a6544b
         const double intensity_correlation_with_ellipse) {
shun-iwasawa a6544b
  TRasterGR8P ref_gr8;
shun-iwasawa a6544b
  if ((refer_ras != nullptr) && (0 <= refer_mode)) {
shun-iwasawa a6544b
    ref_gr8 = TRasterGR8P(out_ras->getLy(), out_ras->getLx() * sizeof(float));
shun-iwasawa a6544b
    ref_gr8->lock();
shun-iwasawa a6544b
    ino::ras_to_ref_float_arr(refer_ras,
shun-iwasawa a6544b
                              reinterpret_cast<float *="">(ref_gr8->getRawData()),</float>
shun-iwasawa a6544b
                              refer_mode);
shun-iwasawa a6544b
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRasterGR8P in_gr8(in_ras->getLy(),
shun-iwasawa a6544b
                     in_ras->getLx() * ino::channels() * sizeof(float));
Shinya Kitaoka 120a6e
  in_gr8->lock();
shun-iwasawa a6544b
  ino::ras_to_float_arr(in_ras, ino::channels(),
shun-iwasawa a6544b
                        reinterpret_cast<float *="">(in_gr8->getRawData()));</float>
Toshihiro Shimizu 890ddd
shun-iwasawa a6544b
  TRasterGR8P out_buffer(out_ras->getLy(),
shun-iwasawa a6544b
                         out_ras->getLx() * ino::channels() * sizeof(float));
shun-iwasawa a6544b
  out_buffer->lock();
Toshihiro Shimizu 890ddd
shun-iwasawa a6544b
  igs::radial_blur::convert(
shun-iwasawa a6544b
      reinterpret_cast<float *="">(in_gr8->getRawData()),</float>
shun-iwasawa a6544b
      reinterpret_cast<float *="">(out_buffer->getRawData()), margin,</float>
shun-iwasawa a6544b
      out_ras->getSize(), ino::channels(),
shun-iwasawa a6544b
      (ref_gr8) ? reinterpret_cast<float *="">(ref_gr8->getRawData()) : nullptr,</float>
shun-iwasawa a6544b
      center + TPointD(margin, margin), twist, pivot_radius, blur, radius, type,
shun-iwasawa a6544b
      anti_alias_sw, alpha_rendering_sw, ellipse_aspect_ratio, ellipse_angle,
shun-iwasawa a6544b
      intensity_correlation_with_ellipse);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  in_gr8->unlock();
shun-iwasawa a6544b
  ino::float_arr_to_ras(out_buffer->getRawData(), ino::channels(), out_ras, 0);
shun-iwasawa a6544b
  out_buffer->unlock();
shun-iwasawa 481b59
shun-iwasawa a6544b
  if (ref_gr8) ref_gr8->unlock();
Toshihiro Shimizu 890ddd
}
shun-iwasawa 888af2
}  // namespace
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Shinya Kitaoka 120a6e
void ino_radial_blur::doCompute(TTile &tile, double frame,
Shinya Kitaoka 120a6e
                                const TRenderSettings &ri) {
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
  /*------ サポートしていないPixelタイプはエラーを投げる -----*/
shun-iwasawa 481b59
  if (!((TRaster32P)tile.getRaster()) && !((TRaster64P)tile.getRaster()) &&
shun-iwasawa 481b59
      !((TRasterFP)tile.getRaster())) {
Shinya Kitaoka 120a6e
    throw TRopException("unsupported input pixel type");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /*------ パラメータを得る ----------------------------------*/
Shinya Kitaoka 120a6e
  const double scale  = ino::pixel_per_mm() * sqrt(fabs(ri.m_affine.det()));
Shinya Kitaoka 120a6e
  const double blur   = this->m_blur->getValue(frame) / ino_param_range;
Shinya Kitaoka 120a6e
  const double radius = this->m_radius->getValue(frame) * scale;
Shinya Kitaoka 120a6e
  const double twist =
Shinya Kitaoka 120a6e
      this->m_twist->getValue(frame) * 3.14159265358979 / 180.0;
Shinya Kitaoka 120a6e
  // const double twist_radius = this->m_twist_radius->getValue(frame)*scale;
Shinya Kitaoka 120a6e
  const bool alpha_rend_sw = this->m_alpha_rendering->getValue();
Shinya Kitaoka 120a6e
  const bool anti_alias_sw = this->m_anti_alias->getValue();
masafumi-inoue 26f824
  const int refer_mode     = this->m_ref_mode->getValue();
shun-iwasawa a6544b
  const int type           = this->m_type->getValue();
shun-iwasawa a6544b
  const double ellipse_aspect_ratio =
shun-iwasawa a6544b
      this->m_ellipse_aspect_ratio->getValue(frame);
shun-iwasawa a6544b
  const double ellipse_angle = this->m_ellipse_angle->getValue(frame);
shun-iwasawa a6544b
  const double pivot_radius  = ri.m_cameraBox.getLy() / 2.0;
shun-iwasawa a6544b
  const double intensity_correlation_with_ellipse =
shun-iwasawa a6544b
      this->m_intensity_correlation_with_ellipse->getValue(frame);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPointD center = this->m_center->getValue(frame);
Shinya Kitaoka 120a6e
  TPointD render_center(
Shinya Kitaoka 120a6e
      this->get_render_center(frame, tile.m_pos, ri.m_affine));
Shinya Kitaoka 120a6e
  /*------ 入力画像の範囲を得る ------------------------------*/
Shinya Kitaoka 120a6e
  TRectD tile_with_margin =
Shinya Kitaoka 120a6e
      TRectD(tile.m_pos /* Render画像上(Pixel単位)の位置 */
Shinya Kitaoka 120a6e
             ,
Shinya Kitaoka 120a6e
             TDimensionD(/* Render画像上(Pixel単位)のサイズ */
Shinya Kitaoka 120a6e
                         tile.getRaster()->getLx(), tile.getRaster()->getLy()));
Shinya Kitaoka 120a6e
  /*------ 入力画像のエリアの拡大 ----------------------------*/
Shinya Kitaoka 120a6e
  int margin = this->get_render_int_margin(frame, tile_with_margin, ri.m_affine,
shun-iwasawa a6544b
                                           render_center, radius, pivot_radius);
Shinya Kitaoka 120a6e
  if (0 < margin) {
Shinya Kitaoka 120a6e
    /* 拡大のしすぎを防ぐテキトーな制限 */
Shinya Kitaoka 120a6e
    if (4096 < margin) {
Shinya Kitaoka 120a6e
      margin = 4096;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    tile_with_margin = tile_with_margin.enlarge(margin);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /*------ 入力画像生成 --------------------------------------*/
masafumi-inoue 26f824
  TTile enlarge_tile;
Shinya Kitaoka 120a6e
  this->m_input->allocateAndCompute(
masafumi-inoue 26f824
      enlarge_tile, tile_with_margin.getP00(),
Shinya Kitaoka 120a6e
      TDimensionI(/* Pixel単位で四捨五入 */
Shinya Kitaoka 120a6e
                  static_cast<int>(tile_with_margin.getLx() + 0.5),</int>
Shinya Kitaoka 120a6e
                  static_cast<int>(tile_with_margin.getLy() + 0.5)),</int>
Shinya Kitaoka 120a6e
      tile.getRaster(), frame, ri);
Shinya Kitaoka 120a6e
  /*------ 参照画像生成 --------------------------------------*/
masafumi-inoue 26f824
  TTile refer_tile;
masafumi-inoue 26f824
  bool refer_sw = false;
Shinya Kitaoka 120a6e
  if (this->m_refer.isConnected()) {
masafumi-inoue 26f824
    refer_sw = true;
Shinya Kitaoka 120a6e
    this->m_refer->allocateAndCompute(
shun-iwasawa a6544b
        refer_tile, tile.m_pos,
shun-iwasawa a6544b
        TDimension(tile.getRaster()->getLx(), tile.getRaster()->getLy()),
Shinya Kitaoka 120a6e
        tile.getRaster(), frame, ri);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /* ------ 保存すべき画像メモリを塗りつぶしクリア ---------- */
Shinya Kitaoka 120a6e
  tile.getRaster()->clear(); /* 塗りつぶしクリア */
Shinya Kitaoka 120a6e
  /* ------ (app_begin)log記憶 ------------------------------ */
Shinya Kitaoka 120a6e
  const bool log_sw = ino::log_enable_sw();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (log_sw) {
Shinya Kitaoka 120a6e
    std::ostringstream os;
Shinya Kitaoka 120a6e
    os << "params"
Shinya Kitaoka 120a6e
       << "  cx " << center.x << "  cy " << center.y << "  blur " << blur
shun-iwasawa 888af2
       << "  radius " << radius << "  twist "
shun-iwasawa 888af2
       << twist
Shinya Kitaoka 120a6e
       // << "  twist_radius " << twist_radius
masafumi-inoue 26f824
       << "  reference " << refer_mode << "  alpha_rendering " << alpha_rend_sw
Shinya Kitaoka 120a6e
       << "  anti_alias " << anti_alias_sw << "  render_center "
Shinya Kitaoka 120a6e
       << render_center << "  frame " << frame << "  pixbits "
Shinya Kitaoka 120a6e
       << ino::pixel_bits(tile.getRaster()) << "  tile.m_pos " << tile.m_pos
Shinya Kitaoka 120a6e
       << "  tile_getLx " << tile.getRaster()->getLx() << "  y "
Shinya Kitaoka 120a6e
       << tile.getRaster()->getLy() << "  ri.m_cameraBox " << ri.m_cameraBox
Shinya Kitaoka 120a6e
       << "  ri.m_affine " << ri.m_affine << "  ri_m_affine_det "
Shinya Kitaoka 120a6e
       << ri.m_affine.det() << "  shrink_x " << ri.m_shrinkX << "  shrink_y "
Shinya Kitaoka 120a6e
       << ri.m_shrinkY << "  tile_with_margin " << tile_with_margin
masafumi-inoue 26f824
       << "  enlarge_tile.m_pos " << enlarge_tile.m_pos
masafumi-inoue 26f824
       << "  tile_allocated_getLx " << enlarge_tile.getRaster()->getLx()
masafumi-inoue 26f824
       << "  y " << enlarge_tile.getRaster()->getLy();
masafumi-inoue 26f824
    if (refer_sw) {
masafumi-inoue 26f824
      os << "  refer_tile.m_pos " << refer_tile.m_pos << "  refer_tile_getLx "
masafumi-inoue 26f824
         << refer_tile.getRaster()->getLx() << "  y "
masafumi-inoue 26f824
         << refer_tile.getRaster()->getLy();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /* ------ fx処理 ------------------------------------------ */
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    tile.getRaster()->lock();
masafumi-inoue 26f824
    enlarge_tile.getRaster()->lock();
masafumi-inoue 26f824
    if (refer_tile.getRaster() != nullptr) {
masafumi-inoue 26f824
      refer_tile.getRaster()->lock();
masafumi-inoue 26f824
    }
shun-iwasawa a6544b
    fx_(enlarge_tile.getRaster(), margin, refer_tile.getRaster(), refer_mode,
shun-iwasawa a6544b
        tile.getRaster(), render_center, twist, blur, radius, pivot_radius,
shun-iwasawa a6544b
        alpha_rend_sw, anti_alias_sw, type, ellipse_aspect_ratio, ellipse_angle,
shun-iwasawa a6544b
        intensity_correlation_with_ellipse);
masafumi-inoue 26f824
    if (refer_tile.getRaster() != nullptr) {
masafumi-inoue 26f824
      refer_tile.getRaster()->unlock();
masafumi-inoue 26f824
    }
masafumi-inoue 26f824
    enlarge_tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
    tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /* ------ error処理 --------------------------------------- */
Shinya Kitaoka 120a6e
  catch (std::bad_alloc &e) {
masafumi-inoue 26f824
    if (refer_tile.getRaster() != nullptr) {
masafumi-inoue 26f824
      refer_tile.getRaster()->unlock();
masafumi-inoue 26f824
    }
masafumi-inoue 26f824
    enlarge_tile.getRaster()->unlock();
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) {
masafumi-inoue 26f824
    if (refer_tile.getRaster() != nullptr) {
masafumi-inoue 26f824
      refer_tile.getRaster()->unlock();
masafumi-inoue 26f824
    }
masafumi-inoue 26f824
    enlarge_tile.getRaster()->unlock();
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 (...) {
masafumi-inoue 26f824
    if (refer_tile.getRaster() != nullptr) {
masafumi-inoue 26f824
      refer_tile.getRaster()->unlock();
masafumi-inoue 26f824
    }
masafumi-inoue 26f824
    enlarge_tile.getRaster()->unlock();
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
}