artisteacher fd1c1e
#pragma once
shun-iwasawa 25dc51
shun-iwasawa 25dc51
/*------------------------------------
shun-iwasawa 25dc51
Iwa_GlareFx
shun-iwasawa 25dc51
------------------------------------*/
shun-iwasawa 25dc51
shun-iwasawa 25dc51
#ifndef IWA_GLAREFX_H
shun-iwasawa 25dc51
#define IWA_GLAREFX_H
shun-iwasawa 25dc51
shun-iwasawa 25dc51
#include "stdfx.h"
shun-iwasawa 25dc51
#include "tfxparam.h"
shun-iwasawa 25dc51
#include "traster.h"
shun-iwasawa 25dc51
#include "tparamset.h"
shun-iwasawa 25dc51
shun-iwasawa 25dc51
#include <qlist></qlist>
shun-iwasawa 25dc51
#include <qthread></qthread>
shun-iwasawa 25dc51
shun-iwasawa 25dc51
#include "tools/kiss_fftnd.h"
shun-iwasawa 25dc51
shun-iwasawa 25dc51
const int LAYER_NUM = 5;
shun-iwasawa 25dc51
shun-iwasawa 25dc51
struct double2 {
shun-iwasawa 25dc51
  double x, y;
shun-iwasawa 25dc51
};
shun-iwasawa 25dc51
struct int2 {
shun-iwasawa 25dc51
  int x, y;
shun-iwasawa 25dc51
};
shun-iwasawa 25dc51
struct double3 {
shun-iwasawa 25dc51
  double x, y, z;
shun-iwasawa 25dc51
};
shun-iwasawa 25dc51
shun-iwasawa 25dc51
class Iwa_GlareFx : public TStandardRasterFx {
shun-iwasawa 25dc51
  FX_PLUGIN_DECLARATION(Iwa_GlareFx)
shun-iwasawa 25dc51
shun-iwasawa 25dc51
protected:
shun-iwasawa 25dc51
  TRasterFxPort m_source;
shun-iwasawa 25dc51
  TRasterFxPort m_iris;
shun-iwasawa c1adfa
  // rendering mode (filter preview / render / iris)
shun-iwasawa 25dc51
  TIntEnumParamP m_renderMode;
shun-iwasawa c1adfa
  TIntEnumParamP m_irisMode;
shun-iwasawa c1adfa
shun-iwasawa c1adfa
  TDoubleParamP m_irisScale;
shun-iwasawa c1adfa
  TDoubleParamP m_irisGearEdgeCount;
shun-iwasawa c1adfa
  TIntParamP m_irisRandomSeed;
shun-iwasawa c1adfa
  TDoubleParamP m_irisSymmetry;
shun-iwasawa c1adfa
  TIntEnumParamP m_irisAppearance;
shun-iwasawa c1adfa
shun-iwasawa 25dc51
  TDoubleParamP m_intensity;
shun-iwasawa 25dc51
  TDoubleParamP m_size;
shun-iwasawa 25dc51
shun-iwasawa 25dc51
  TDoubleParamP m_rotation;
shun-iwasawa c1adfa
  TDoubleParamP m_aberration;
shun-iwasawa 25dc51
shun-iwasawa 25dc51
  TDoubleParamP m_noise_factor;
shun-iwasawa 25dc51
  TDoubleParamP m_noise_size;
shun-iwasawa 25dc51
  TIntEnumParamP m_noise_octave;
shun-iwasawa 25dc51
  TDoubleParamP m_noise_evolution;
shun-iwasawa 25dc51
  TPointParamP m_noise_offset;
shun-iwasawa 25dc51
shun-iwasawa 481b59
  enum { RenderMode_FilterPreview = 0, RenderMode_Render, RenderMode_Iris };
shun-iwasawa c1adfa
shun-iwasawa c1adfa
  enum {
shun-iwasawa c1adfa
    Iris_InputImage = 0,
shun-iwasawa c1adfa
    Iris_Square,
shun-iwasawa c1adfa
    Iris_Hexagon,
shun-iwasawa c1adfa
    Iris_Octagon,
shun-iwasawa c1adfa
    Iris_GearShape
shun-iwasawa c1adfa
  };
shun-iwasawa c1adfa
shun-iwasawa c1adfa
  enum {
shun-iwasawa c1adfa
    Appearance_ThinLine,
shun-iwasawa c1adfa
    Appearance_MediumLine,
shun-iwasawa c1adfa
    Appearance_ThickLine,
shun-iwasawa c1adfa
    Appearance_Fill,
shun-iwasawa c1adfa
  };
shun-iwasawa 25dc51
shun-iwasawa 25dc51
  double getSizePixelAmount(const double val, const TAffine affine);
shun-iwasawa 25dc51
shun-iwasawa c1adfa
  void drawPresetIris(TRaster32P irisRas, double irisSize, const double frame);
shun-iwasawa c1adfa
shun-iwasawa 25dc51
  // Resize / flip the iris image according to the size ratio.
shun-iwasawa 25dc51
  // Normalize the brightness of the iris image.
shun-iwasawa 25dc51
  // Enlarge the iris to the output size.
shun-iwasawa 25dc51
  void convertIris(kiss_fft_cpx *kissfft_comp_iris_before, const int &dimIris,
shun-iwasawa c1adfa
                   const TRectD &irisBBox, const TRasterP irisRaster);
shun-iwasawa 25dc51
shun-iwasawa 25dc51
  void powerSpectrum2GlarePattern(const double frame, const TAffine affine,
shun-iwasawa 25dc51
                                  kiss_fft_cpx *spectrum, double3 *glare,
shun-iwasawa 25dc51
                                  int dimIris, double intensity,
shun-iwasawa 25dc51
                                  double irisResizeFactor);
shun-iwasawa 25dc51
shun-iwasawa 25dc51
  void distortGlarePattern(const double frame, const TAffine affine,
shun-iwasawa 25dc51
                           double *glare, const int dimIris);
shun-iwasawa 25dc51
shun-iwasawa 25dc51
  // filter preview mode
shun-iwasawa 25dc51
  template <typename pixel="" raster,="" typename=""></typename>
shun-iwasawa 25dc51
  void setFilterPreviewToResult(const RASTER ras, double3 *glare, int dimIris,
shun-iwasawa 25dc51
                                int2 margin);
shun-iwasawa 25dc51
shun-iwasawa 25dc51
  // put the source tile's brightness to fft buffer
shun-iwasawa 25dc51
  template <typename pixel="" raster,="" typename=""></typename>
shun-iwasawa 25dc51
  void setSourceTileToBuffer(const RASTER ras, kiss_fft_cpx *buf);
shun-iwasawa 481b59
  template <typename pixel="" raster,="" typename=""></typename>
shun-iwasawa 481b59
  void setSourceTileToBuffer(const RASTER ras, kiss_fft_cpx *buf, int channel);
shun-iwasawa 25dc51
shun-iwasawa 25dc51
  void setGlarePatternToBuffer(const double3 *glare, kiss_fft_cpx *buf,
shun-iwasawa 25dc51
                               const int channel, const int dimIris,
shun-iwasawa 25dc51
                               const TDimensionI &dimOut);
shun-iwasawa 25dc51
shun-iwasawa 25dc51
  void multiplyFilter(kiss_fft_cpx *glare, const kiss_fft_cpx *source,
shun-iwasawa 25dc51
                      const int count);
shun-iwasawa 25dc51
shun-iwasawa 25dc51
  template <typename pixel="" raster,="" typename=""></typename>
shun-iwasawa 25dc51
  void setChannelToResult(const RASTER ras, kiss_fft_cpx *buf, int channel,
shun-iwasawa 25dc51
                          const TDimensionI &dimOut);
shun-iwasawa 25dc51
shun-iwasawa 25dc51
public:
shun-iwasawa 25dc51
  Iwa_GlareFx();
shun-iwasawa 25dc51
shun-iwasawa ce90c2
  void doCompute(TTile &tile, double frame,
shun-iwasawa ce90c2
                 const TRenderSettings &settings) override;
shun-iwasawa 25dc51
shun-iwasawa ce90c2
  bool doGetBBox(double frame, TRectD &bBox,
shun-iwasawa ce90c2
                 const TRenderSettings &info) override;
shun-iwasawa 25dc51
artisteacher fd1c1e
  bool canHandle(const TRenderSettings &info, double frame) override;
shun-iwasawa 25dc51
shun-iwasawa 25dc51
  void getParamUIs(TParamUIConcept *&concepts, int &length) override;
shun-iwasawa 481b59
shun-iwasawa 481b59
  bool toBeComputedInLinearColorSpace(bool settingsIsLinear,
shun-iwasawa 481b59
                                      bool tileIsLinear) const override;
shun-iwasawa 25dc51
};
shun-iwasawa 25dc51
artisteacher fd1c1e
#endif