2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Runtime.InteropServices;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Binding;
22 using System.ComponentModel;
27 /// GaussianBlurView is a class for applying a render process that blurs an image.
29 /// <since_tizen> 6 </since_tizen>
30 [EditorBrowsable(EditorBrowsableState.Never)]
31 public class GaussianBlurView : View
33 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public static readonly BindableProperty BlurStrengthProperty = BindableProperty.Create(nameof(BlurStrength), typeof(float), typeof(GaussianBlurView), default(float), propertyChanged: (bindable, oldValue, newValue) =>
37 var gaussianBlurView = (GaussianBlurView)bindable;
40 Tizen.NUI.Object.SetProperty(gaussianBlurView.swigCPtr, gaussianBlurView.GetBlurStrengthPropertyIndex(), new Tizen.NUI.PropertyValue((float)newValue));
43 defaultValueCreator: (bindable) =>
45 var gaussianBlurView = (GaussianBlurView)bindable;
47 Tizen.NUI.Object.GetProperty(gaussianBlurView.swigCPtr, gaussianBlurView.GetBlurStrengthPropertyIndex()).Get(out temp);
50 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
52 internal GaussianBlurView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
54 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
57 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
59 Interop.GaussianBlurView.DeleteGaussianBlurView(swigCPtr);
63 /// Dispose GaussianBlurView and all children on it.
65 /// <param name="type">Dispose type.</param>
66 /// <since_tizen> 6 </since_tizen>
67 protected override void Dispose(DisposeTypes type)
74 //Release your own unmanaged resources here.
75 //You should not access any managed member here except static instance.
76 //because the execution order of Finalizes is non-deterministic.
77 if (finishedCallback != null)
79 FinishedSignal().Disconnect(finishedCallback);
85 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
86 private delegate void FinishedCallbackType(IntPtr application);
87 private DaliEventHandler<object, EventArgs> finishedEventHandler;
88 private FinishedCallbackType finishedCallback;
91 /// If ActivateOnce has been called, then connect to this signal to be notified when the target actor has been rendered.
93 /// <since_tizen> 6 </since_tizen>
94 [EditorBrowsable(EditorBrowsableState.Never)]
95 public event DaliEventHandler<object, EventArgs> Finished
99 // Restricted to only one listener
100 if (finishedEventHandler == null)
102 finishedCallback = new FinishedCallbackType(OnFinished);
103 FinishedSignal().Connect(finishedCallback);
105 finishedEventHandler += value;
110 finishedEventHandler -= value;
112 if (finishedEventHandler == null && FinishedSignal().Empty() == false)
114 FinishedSignal().Disconnect(finishedCallback);
119 // Callback for GaussianBlurView FinishedSignal
120 private void OnFinished(IntPtr data)
122 EventArgs e = new EventArgs();
124 if (finishedEventHandler != null)
126 //here we send all data to user event handlers
127 finishedEventHandler(this, e);
132 /// The BlurStrength property. A value of 0.0 is zero blur and 1.0 is full blur. Default is 1.0.
133 /// if you set the blur to 0.0, the result will be no blur BUT the internal rendering will still be happening.
134 /// If you wish to turn the blur off, you should remove the GaussianBlurView object from the window also.
136 /// <since_tizen> 6 </since_tizen>
137 [EditorBrowsable(EditorBrowsableState.Never)]
138 public float BlurStrength
142 return (float)GetValue(BlurStrengthProperty);
146 SetValue(BlurStrengthProperty, value);
147 NotifyPropertyChanged();
154 [EditorBrowsable(EditorBrowsableState.Never)]
155 public GaussianBlurView() : this(Interop.GaussianBlurView.New(), true)
157 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161 /// Constructor with parameters.
163 /// <param name="numSamples">The size of the Gaussian blur kernel (number of samples in horizontal / vertical blur directions)</param>
164 /// <param name="blurBellCurveWidth">
165 /// The constant controlling the Gaussian function, must be > 0.0. Controls the width of the bell curve, i.e. the look of the blur and also indirectly
166 /// the amount of blurriness Smaller numbers for a tighter curve. Useful values in the range [0.5..3.0] - near the bottom of that range the curve is weighted heavily towards
167 /// the centre pixel of the kernel (so there won't be much blur), near the top of that range the pixels have nearly equal weighting (closely approximating a box filter
168 /// therefore). Values close to zero result in the bell curve lying almost entirely within a single pixel, in other words there will be basically no blur as neighbouring pixels
169 /// have close to zero weights.
171 /// <param name="renderTargetPixelFormat">The pixel format of the render targets we are using to perform the blur.</param>
172 /// <param name="downsampleWidthScale">
173 /// width scale factor applied during the blur process, scaling the size of the source image to the size of the final blurred image output.
174 /// Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
176 /// <param name="downsampleHeightScale">
177 /// The height scale factor applied during the blur process, scaling the size of the source image to the size of the final blurred image output.
178 /// Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
180 /// <param name="blurUserImage">
181 /// If this is set to true, the GaussianBlurView object will operate in a special mode that allows the user to blur an image of their choice. See
182 /// SetUserImageAndOutputRenderTarget().
184 /// <since_tizen> 6 </since_tizen>
185 [EditorBrowsable(EditorBrowsableState.Never)]
186 public GaussianBlurView(uint numSamples, float blurBellCurveWidth, PixelFormat renderTargetPixelFormat, float downsampleWidthScale, float downsampleHeightScale, bool blurUserImage) : this(Interop.GaussianBlurView.New(numSamples, blurBellCurveWidth, (int)renderTargetPixelFormat, downsampleWidthScale, downsampleHeightScale, blurUserImage), true)
188 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194 /// <since_tizen> 6 </since_tizen>
195 [EditorBrowsable(EditorBrowsableState.Never)]
196 public GaussianBlurView(GaussianBlurView handle) : this(Interop.GaussianBlurView.NewGaussianBlurView(GaussianBlurView.getCPtr(handle)), true)
198 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202 /// Start rendering the GaussianBlurView. Must be called after you Add() it to the window.
204 /// <since_tizen> 6 </since_tizen>
205 [EditorBrowsable(EditorBrowsableState.Never)]
206 public void Activate()
208 Interop.GaussianBlurView.Activate(swigCPtr);
209 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213 /// Render the GaussianBlurView once.
214 /// Must be called after you Add() it to the window.
215 /// Listen to the Finished signal to determine when the rendering has completed.
217 /// <since_tizen> 6 </since_tizen>
218 [EditorBrowsable(EditorBrowsableState.Never)]
219 public void ActivateOnce()
221 Interop.GaussianBlurView.ActivateOnce(swigCPtr);
222 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226 /// Stop rendering the GaussianBlurView. Must be called after you Remove() it from the window.
228 /// <since_tizen> 6 </since_tizen>
229 [EditorBrowsable(EditorBrowsableState.Never)]
230 public void Deactivate()
232 Interop.GaussianBlurView.Deactivate(swigCPtr);
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236 private int GetBlurStrengthPropertyIndex()
238 int ret = Interop.GaussianBlurView.GetBlurStrengthPropertyIndex(swigCPtr);
239 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 internal void SetBackgroundColor(Vector4 color)
246 Interop.GaussianBlurView.SetBackgroundColor(swigCPtr, Vector4.getCPtr(color));
247 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250 internal Vector4 GetBackgroundColor()
252 Vector4 ret = new Vector4(Interop.GaussianBlurView.GetBackgroundColor(swigCPtr), true);
253 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257 private GaussianBlurViewSignal FinishedSignal()
259 GaussianBlurViewSignal ret = new GaussianBlurViewSignal(Interop.GaussianBlurView.FinishedSignal(swigCPtr), false);
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264 internal void SetUserImageAndOutputRenderTarget(Texture inputTexture, FrameBuffer outputRenderTarget)
266 Interop.GaussianBlurView.SetUserImageAndOutputRenderTarget(swigCPtr, Texture.getCPtr(inputTexture), FrameBuffer.getCPtr(outputRenderTarget));
267 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();