/// <summary>
        /// Initializes a new instance of the <see cref="BokehBlurProcessor{TPixel}"/> class.
        /// </summary>
        /// <param name="definition">The <see cref="BoxBlurProcessor"/> defining the processor parameters.</param>
        /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
        /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
        public BokehBlurProcessor(BokehBlurProcessor definition, Image <TPixel> source, Rectangle sourceRectangle)
            : base(source, sourceRectangle)
        {
            this.radius          = definition.Radius;
            this.kernelSize      = (this.radius * 2) + 1;
            this.componentsCount = definition.Components;
            this.gamma           = definition.Gamma;
            this.executionMode   = definition.ExecutionMode;

            // Reuse the initialized values from the cache, if possible
            var parameters = new BokehBlurParameters(this.radius, this.componentsCount);

            if (Cache.TryGetValue(parameters, out BokehBlurKernelData info))
            {
                this.kernelParameters = info.Parameters;
                this.kernelsScale     = info.Scale;
                this.kernels          = info.Kernels;
            }
            else
            {
                // Initialize the complex kernels and parameters with the current arguments
                (this.kernelParameters, this.kernelsScale) = this.GetParameters();
                this.kernels = this.CreateComplexKernels();
                this.NormalizeKernels();

                // Store them in the cache for future use
                Cache.TryAdd(parameters, new BokehBlurKernelData(this.kernelParameters, this.kernelsScale, this.kernels));
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BokehBlurProcessor{TPixel}"/> class.
        /// </summary>
        /// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
        /// <param name="definition">The <see cref="BoxBlurProcessor"/> defining the processor parameters.</param>
        /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
        /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
        public BokehBlurProcessor(Configuration configuration, BokehBlurProcessor definition, Image <TPixel> source, Rectangle sourceRectangle)
            : base(configuration, source, sourceRectangle)
        {
            this.gamma = definition.Gamma;

            // Get the bokeh blur data
            BokehBlurKernelData data = BokehBlurKernelDataProvider.GetBokehBlurKernelData(
                definition.Radius,
                (definition.Radius * 2) + 1,
                definition.Components);

            this.kernelParameters = data.Parameters;
            this.kernels          = data.Kernels;
        }