| #pragma once |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #ifndef IWA_BOKEH_REF_H |
| #define IWA_BOKEH_REF_H |
| |
| #include "stdfx.h" |
| #include "tfxparam.h" |
| |
| #include <QVector> |
| #include <QThread> |
| |
| #include "tools/kiss_fftnd.h" |
| |
| struct float4 { |
| float x, y, z, w; |
| }; |
| |
| |
| |
| class BokehRefThread : public QThread { |
| int m_channel; |
| volatile bool m_finished; |
| |
| kiss_fft_cpx* m_fftcpx_channel_before; |
| kiss_fft_cpx* m_fftcpx_channel; |
| kiss_fft_cpx* m_fftcpx_alpha; |
| kiss_fft_cpx* m_fftcpx_iris; |
| float4* m_result_buff; |
| |
| kiss_fftnd_cfg m_kissfft_plan_fwd, m_kissfft_plan_bkwd; |
| |
| TDimensionI m_dim; |
| bool m_isTerminated; |
| |
| public: |
| BokehRefThread(int channel, kiss_fft_cpx* fftcpx_channel_before, |
| kiss_fft_cpx* fftcpx_channel, kiss_fft_cpx* fftcpx_alpha, |
| kiss_fft_cpx* fftcpx_iris, float4* result_buff, |
| kiss_fftnd_cfg kissfft_plan_fwd, |
| kiss_fftnd_cfg kissfft_plan_bkwd, TDimensionI& dim); |
| |
| void run() override; |
| |
| bool isFinished() { return m_finished; } |
| void terminateThread() { m_isTerminated = true; } |
| }; |
| |
| |
| |
| class Iwa_BokehRefFx : public TStandardRasterFx { |
| FX_PLUGIN_DECLARATION(Iwa_BokehRefFx) |
| |
| protected: |
| TRasterFxPort m_iris; |
| TRasterFxPort m_source; |
| TRasterFxPort m_depth; |
| |
| TDoubleParamP m_onFocusDistance; |
| TDoubleParamP m_bokehAmount; |
| |
| |
| TDoubleParamP m_hardness; |
| TIntParamP m_distancePrecision; |
| |
| TBoolParamP m_fillGap; |
| |
| |
| |
| |
| TBoolParamP m_doMedian; |
| |
| |
| |
| float getBokehPixelAmount(const double frame, const TAffine affine); |
| |
| |
| |
| template <typename RASTER, typename PIXEL> |
| bool setSourceRaster(const RASTER srcRas, float4* dstMem, TDimensionI dim); |
| |
| |
| |
| template <typename RASTER, typename PIXEL> |
| void setDepthRaster(const RASTER srcRas, unsigned char* dstMem, |
| TDimensionI dim); |
| template <typename RASTER, typename PIXEL> |
| void setDepthRasterGray(const RASTER srcRas, unsigned char* dstMem, |
| TDimensionI dim); |
| |
| |
| void defineSegemntDepth(const unsigned char* indexMap_main, |
| const unsigned char* indexMap_sub, |
| const float* mainSub_ratio, |
| const unsigned char* depth_buff, |
| const TDimensionI& dimOut, const double frame, |
| QVector<float>& segmentDepth_main, |
| QVector<float>& segmentDepth_sub); |
| |
| |
| template <typename RASTER, typename PIXEL> |
| void setOutputRaster(float4* srcMem, const RASTER dstRas, TDimensionI dim, |
| TDimensionI margin); |
| |
| |
| float calcIrisSize(const float depth, const float bokehPixelAmount, |
| const double onFocusDistance); |
| |
| |
| |
| |
| void convertIris(const float irisSize, const TRectD& irisBBox, |
| const TTile& irisTile, const TDimensionI& enlargedDim, |
| kiss_fft_cpx* fftcpx_iris_before); |
| |
| |
| void convertRGBToExposure(const float4* source_buff, int size, |
| float filmGamma, bool sourceIsPremultiplied); |
| |
| |
| |
| void retrieveLayer(const float4* source_buff, |
| const float4* segment_layer_buff, |
| const unsigned char* indexMap_mainSub, int index, int lx, |
| int ly, bool fillGap, bool doMedian, int margin); |
| |
| |
| void doSingleMedian(const float4* source_buff, |
| const float4* segment_layer_buff, |
| const unsigned char* indexMap_mainSub, int index, int lx, |
| int ly, const unsigned char* generation_buff, int curGen); |
| |
| |
| void compositeAsIs(const float4* segment_layer_buff, |
| const float4* result_buff_mainSub, int size); |
| |
| |
| void retrieveChannel(const float4* segment_layer_buff, |
| kiss_fft_cpx* fftcpx_r_before, |
| kiss_fft_cpx* fftcpx_g_before, |
| kiss_fft_cpx* fftcpx_b_before, |
| kiss_fft_cpx* fftcpx_a_before, |
| int size); |
| |
| |
| void multiplyFilter(kiss_fft_cpx* fftcpx_channel, |
| kiss_fft_cpx* fftcpx_iris, |
| int size); |
| |
| |
| void compositeAlpha(const float4* result_buff, |
| const kiss_fft_cpx* fftcpx_alpha, |
| int lx, int ly); |
| |
| |
| |
| |
| void interpolateExposureAndConvertToRGB( |
| const float4* result_main_buff, |
| const float4* result_sub_buff, |
| const float* mainSub_ratio, |
| float filmGamma, |
| const float4* source_buff, |
| int size); |
| |
| public: |
| Iwa_BokehRefFx(); |
| |
| void doCompute(TTile& tile, double frame, const TRenderSettings& settings); |
| |
| bool doGetBBox(double frame, TRectD& bBox, const TRenderSettings& info); |
| |
| bool canHandle(const TRenderSettings& info, double frame); |
| |
| void doCompute_CPU(const double frame, const TRenderSettings& settings, |
| float bokehPixelAmount, float maxIrisSize, int margin, |
| TDimensionI& dimOut, float4* source_buff, |
| unsigned char* indexMap_main, unsigned char* indexMap_sub, |
| float* mainSub_ratio, QVector<float>& segmentDepth_main, |
| QVector<float>& segmentDepth_sub, TTile& irisTile, |
| TRectD& irisBBox, bool sourceIsPremultiplied); |
| }; |
| |
| #endif |