shun-iwasawa 13c4cf
#pragma once
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
#ifndef IWA_FLOWBLURFX
shun-iwasawa 13c4cf
#define IWA_FLOWBLURFX
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
#include "stdfx.h"
shun-iwasawa 13c4cf
#include "tfxparam.h"
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
#include <qthread></qthread>
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
struct double2 {
shun-iwasawa 13c4cf
  double x = 0., y = 0.;
shun-iwasawa 13c4cf
};
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
struct double4 {
shun-iwasawa 13c4cf
  double x = 0., y = 0., z = 0, w = 0.;
shun-iwasawa 13c4cf
};
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
enum FILTER_TYPE { Linear = 0, Gaussian, Flat };
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
class FlowBlurWorker : public QThread {
shun-iwasawa 13c4cf
  double4 *m_source_buf;
shun-iwasawa 13c4cf
  double2 *m_flow_buf;
shun-iwasawa 13c4cf
  double4 *m_out_buf;
shun-iwasawa 13c4cf
  double *m_reference_buf;
shun-iwasawa 13c4cf
  TDimension m_dim;
shun-iwasawa 13c4cf
  double m_krnlen;
shun-iwasawa 13c4cf
  int m_yFrom, m_yTo;
shun-iwasawa 13c4cf
  FILTER_TYPE m_filterType;
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
public:
shun-iwasawa 13c4cf
  FlowBlurWorker(double4 *source_buf, double2 *flow_buf, double4 *out_buf,
shun-iwasawa 13c4cf
                 double *ref_buf, TDimension dim, double krnlen, int yFrom,
shun-iwasawa 13c4cf
                 int yTo, FILTER_TYPE filterType)
shun-iwasawa 13c4cf
      : m_source_buf(source_buf)
shun-iwasawa 13c4cf
      , m_flow_buf(flow_buf)
shun-iwasawa 13c4cf
      , m_out_buf(out_buf)
shun-iwasawa 13c4cf
      , m_reference_buf(ref_buf)
shun-iwasawa 13c4cf
      , m_dim(dim)
shun-iwasawa 13c4cf
      , m_krnlen(krnlen)
shun-iwasawa 13c4cf
      , m_yFrom(yFrom)
shun-iwasawa 13c4cf
      , m_yTo(yTo)
shun-iwasawa 13c4cf
      , m_filterType(filterType) {}
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
  void run();
shun-iwasawa 13c4cf
};
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
class Iwa_FlowBlurFx final : public TStandardRasterFx {
shun-iwasawa 13c4cf
  FX_PLUGIN_DECLARATION(Iwa_FlowBlurFx)
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
protected:
shun-iwasawa 13c4cf
  TRasterFxPort m_source;
shun-iwasawa 13c4cf
  TRasterFxPort m_flow;
shun-iwasawa 13c4cf
  TRasterFxPort m_reference;
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
  TDoubleParamP m_length;
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
  TBoolParamP m_linear;
shun-iwasawa 13c4cf
  TDoubleParamP m_gamma;
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
  /*- リニア/ガウシアン/平均化 -*/
shun-iwasawa 13c4cf
  TIntEnumParamP m_filterType;
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
  // Reference, Blue Channel of Flow Image
shun-iwasawa 13c4cf
  TIntEnumParamP m_referenceMode;
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
  enum ReferenceMode { REFERENCE = 0, FLOW_BLUE_CHANNEL };
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
  template <typename pixel="" raster,="" typename=""></typename>
shun-iwasawa 13c4cf
  void setSourceTileToBuffer(const RASTER srcRas, double4 *buf, bool isLinear,
shun-iwasawa 13c4cf
                             double gamma);
shun-iwasawa 13c4cf
  template <typename pixel="" raster,="" typename=""></typename>
shun-iwasawa 13c4cf
  void setFlowTileToBuffer(const RASTER flowRas, double2 *buf, double *refBuf);
shun-iwasawa 13c4cf
  template <typename pixel="" raster,="" typename=""></typename>
shun-iwasawa 13c4cf
  void setReferenceTileToBuffer(const RASTER srcRas, double *buf);
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
  template <typename pixel="" raster,="" typename=""></typename>
shun-iwasawa 13c4cf
  void setOutputRaster(double4 *out_buf, const RASTER dstRas, bool isLinear,
shun-iwasawa 13c4cf
                       double gamma);
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
public:
shun-iwasawa 13c4cf
  Iwa_FlowBlurFx();
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
  void doCompute(TTile &tile, double frame,
shun-iwasawa 13c4cf
                 const TRenderSettings &settings) override;
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
  bool doGetBBox(double frame, TRectD &bBox,
shun-iwasawa 13c4cf
                 const TRenderSettings &info) override;
shun-iwasawa 13c4cf
shun-iwasawa 13c4cf
  bool canHandle(const TRenderSettings &info, double frame) override;
shun-iwasawa 13c4cf
};
shun-iwasawa 13c4cf
#endif