shun-iwasawa 1b1839
#pragma once
shun-iwasawa 1b1839
//----------------------------------------
shun-iwasawa 1b1839
// Iwa_BokehAdvancedFx
shun-iwasawa 1b1839
// Advanced version of Bokeh Fx Iwa
shun-iwasawa 1b1839
// - Enabled to set different hardness for each layer
luz paz 6454c4
// - Enabled to apply the depth reference image for each layer
shun-iwasawa 1b1839
//----------------------------------------
shun-iwasawa 1b1839
shun-iwasawa 1b1839
#ifndef IWA_BOKEH_ADVANCED_H
shun-iwasawa 1b1839
#define IWA_BOKEH_ADVANCED_H
shun-iwasawa 1b1839
shun-iwasawa 1b1839
#include "stdfx.h"
shun-iwasawa 1b1839
#include "tfxparam.h"
shun-iwasawa 1b1839
#include "traster.h"
shun-iwasawa 1b1839
shun-iwasawa 1b1839
#include "kiss_fft.h"
shun-iwasawa 1b1839
#include "tools/kiss_fftnd.h"
shun-iwasawa 1b1839
#include "iwa_bokeh_util.h"
shun-iwasawa 1b1839
shun-iwasawa 1b1839
#include <array></array>
shun-iwasawa 1b1839
#include <qthread></qthread>
shun-iwasawa 1b1839
shun-iwasawa 1b1839
const int LAYER_NUM = 5;
shun-iwasawa 1b1839
shun-iwasawa 1b1839
//------------------------------------
shun-iwasawa 1b1839
shun-iwasawa 1b1839
class Iwa_BokehAdvancedFx : public Iwa_BokehCommonFx {
shun-iwasawa 1b1839
  FX_PLUGIN_DECLARATION(Iwa_BokehAdvancedFx)
shun-iwasawa 1b1839
shun-iwasawa 1b1839
protected:
shun-iwasawa 1b1839
  TFxPortDG m_control;
shun-iwasawa 1b1839
shun-iwasawa 1b1839
  TBoolParamP m_hardnessPerSource;  // switch between layer and master hardness
shun-iwasawa 1b1839
shun-iwasawa 1b1839
  struct LAYERPARAM {
shun-iwasawa 1b1839
    TRasterFxPort m_source;
shun-iwasawa 1b1839
    TDoubleParamP m_distance;  // The layer distance from the camera (0-1)
shun-iwasawa 1b1839
    TDoubleParamP m_bokehAdjustment;  // Factor for adjusting distance (= focal
shun-iwasawa 1b1839
                                      // distance - layer distance) (0-2.0)
shun-iwasawa 1b1839
    TDoubleParamP m_hardness;         // film gamma for each layer
shun-iwasawa 1b1839
    TIntParamP m_depth_ref;           // port index of depth reference image
shun-iwasawa 1b1839
    TDoubleParamP m_depthRange;       // distance range varies depends on the
shun-iwasawa 1b1839
                                      // brightness of the reference image (0-1)
shun-iwasawa 1b1839
  };
shun-iwasawa 1b1839
  std::array<layerparam, layer_num=""> m_layerParams;</layerparam,>
shun-iwasawa 1b1839
shun-iwasawa 1b1839
  // sort source images
shun-iwasawa 1b1839
  QList<int> getSortedSourceIndices(double frame);</int>
shun-iwasawa 1b1839
  // Compute the bokeh size for each layer. The source tile will be enlarged by
shun-iwasawa 1b1839
  // the largest size of them.
shun-iwasawa 1b1839
  QMap<int, double=""> getIrisSizes(const double frame,</int,>
shun-iwasawa 1b1839
                                 const QList<int> sourceIndices,</int>
shun-iwasawa 1b1839
                                 const double bokehPixelAmount,
shun-iwasawa 1b1839
                                 double& maxIrisSize);
shun-iwasawa 1b1839
  // return true if the control image is available and used
shun-iwasawa 1b1839
  bool portIsUsed(int portIndex);
shun-iwasawa 1b1839
shun-iwasawa 1b1839
public:
shun-iwasawa 1b1839
  Iwa_BokehAdvancedFx();
shun-iwasawa 1b1839
shun-iwasawa 1b1839
  void doCompute(TTile& tile, double frame,
shun-iwasawa 1b1839
                 const TRenderSettings& settings) override;
shun-iwasawa 1b1839
shun-iwasawa 1b1839
  int dynamicPortGroupsCount() const override { return 1; }
shun-iwasawa 1b1839
  const TFxPortDG* dynamicPortGroup(int g) const override {
shun-iwasawa 1b1839
    return (g == 0) ? &m_control : 0;
shun-iwasawa 1b1839
  }
shun-iwasawa 1b1839
};
shun-iwasawa 1b1839
shun-iwasawa 1b1839
#endif