Shinya Kitaoka 810553
#pragma once
Shinya Kitaoka 810553
Toshihiro Shimizu 890ddd
/*------------------------------------
Toshihiro Shimizu 890ddd
 Iwa_GradientWarpFx
Toshihiro Shimizu 890ddd
 参照画像の勾配方向にWarpするエフェクト
Toshihiro Shimizu 890ddd
------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef IWA_GRADIENT_WARP_H
Toshihiro Shimizu 890ddd
#define IWA_GRADIENT_WARP_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct float2 {
Shinya Kitaoka 120a6e
  float x, y;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
struct float4 {
shun-iwasawa 481b59
#if defined(TNZ_MACHINE_CHANNEL_ORDER_BGRM)
shun-iwasawa 481b59
  float z, y, x, w;
shun-iwasawa 481b59
#elif defined(TNZ_MACHINE_CHANNEL_ORDER_MBGR)
shun-iwasawa 481b59
  float w, x, y, x;
shun-iwasawa 481b59
#elif defined(TNZ_MACHINE_CHANNEL_ORDER_RGBM)
shun-iwasawa 481b59
  float x, y, x, w;
shun-iwasawa 481b59
#elif defined(TNZ_MACHINE_CHANNEL_ORDER_MRGB)
shun-iwasawa 481b59
  float w, x, y, z;
shun-iwasawa 481b59
#endif
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
struct int2 {
Shinya Kitaoka 120a6e
  int x, y;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class Iwa_GradientWarpFx final : public TStandardRasterFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(Iwa_GradientWarpFx)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  TRasterFxPort m_source; /*- 入力画像 -*/
Shinya Kitaoka 120a6e
  TRasterFxPort m_warper; /*- 参照画像 -*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDoubleParamP m_h_maxlen;
Shinya Kitaoka 120a6e
  TDoubleParamP m_v_maxlen;
Shinya Kitaoka 120a6e
  TDoubleParamP
Shinya Kitaoka 120a6e
      m_scale; /*- ワープ量を増やすスカラー値。この値はマージン値には影響しない
Shinya Kitaoka 120a6e
                  -*/
shun-iwasawa 748a28
  TDoubleParamP m_sampling_size;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void get_render_real_hv(const double frame, const TAffine affine,
Shinya Kitaoka 120a6e
                          double &h_maxlen, double &v_maxlen);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void get_render_enlarge(const double frame, const TAffine affine,
Shinya Kitaoka 120a6e
                          TRectD &bBox);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*- タイルの画像を0〜1に正規化してホストメモリに読み込む -*/
Shinya Kitaoka 120a6e
  template <typename pixel="" raster,="" typename=""></typename>
Shinya Kitaoka 120a6e
  void setSourceRaster(const RASTER srcRas, float4 *dstMem, TDimensionI dim);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*- タイルの画像の輝度値を0〜1に正規化してホストメモリに読み込む -*/
Shinya Kitaoka 120a6e
  template <typename pixel="" raster,="" typename=""></typename>
Shinya Kitaoka 120a6e
  void setWarperRaster(const RASTER srcRas, float *dstMem, TDimensionI dim);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*- 出力結果をChannel値に変換して格納 -*/
Shinya Kitaoka 120a6e
  template <typename pixel="" raster,="" typename=""></typename>
Shinya Kitaoka 120a6e
  void setOutputRaster(float4 *srcMem, const RASTER dstRas, TDimensionI dim,
Shinya Kitaoka 120a6e
                       int2 margin);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void doCompute_CPU(TTile &tile, const double frame,
Shinya Kitaoka 120a6e
                     const TRenderSettings &settings, double hLength,
Shinya Kitaoka 120a6e
                     double vLength, int margin, TDimensionI &enlargedDim,
Shinya Kitaoka 120a6e
                     float4 *source_host, float *warper_host,
shun-iwasawa 748a28
                     float4 *result_host, double sampling_size,
shun-iwasawa 748a28
                     double grad_factor);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  float4 getSourceVal_CPU(float4 *source_host, TDimensionI &enlargedDim,
Shinya Kitaoka 120a6e
                          int pos_x, int pos_y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  float4 interp_CPU(float4 val1, float4 val2, float ratio);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Iwa_GradientWarpFx();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  void doCompute(TTile &tile, double frame,
Shinya Kitaoka 38fd86
                 const TRenderSettings &settings) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  bool doGetBBox(double frame, TRectD &bBox,
Shinya Kitaoka 38fd86
                 const TRenderSettings &info) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  bool canHandle(const TRenderSettings &info, double frame) override;
shun-iwasawa 748a28
shun-iwasawa 748a28
  void onFxVersionSet() final override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif