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);
51 internal GaussianBlurView(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn)
55 internal GaussianBlurView(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, cRegister)
59 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
61 Interop.GaussianBlurView.DeleteGaussianBlurView(swigCPtr);
65 /// Dispose GaussianBlurView and all children on it.
67 /// <param name="type">Dispose type.</param>
68 /// <since_tizen> 6 </since_tizen>
69 protected override void Dispose(DisposeTypes type)
76 //Release your own unmanaged resources here.
77 //You should not access any managed member here except static instance.
78 //because the execution order of Finalizes is non-deterministic.
79 if (finishedCallback != null)
81 FinishedSignal().Disconnect(finishedCallback);
87 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
88 private delegate void FinishedCallbackType(IntPtr application);
89 private DaliEventHandler<object, EventArgs> finishedEventHandler;
90 private FinishedCallbackType finishedCallback;
93 /// If ActivateOnce has been called, then connect to this signal to be notified when the target actor has been rendered.
95 /// <since_tizen> 6 </since_tizen>
96 [EditorBrowsable(EditorBrowsableState.Never)]
97 public event DaliEventHandler<object, EventArgs> Finished
101 // Restricted to only one listener
102 if (finishedEventHandler == null)
104 finishedCallback = new FinishedCallbackType(OnFinished);
105 FinishedSignal().Connect(finishedCallback);
107 finishedEventHandler += value;
112 finishedEventHandler -= value;
114 if (finishedEventHandler == null && FinishedSignal().Empty() == false)
116 FinishedSignal().Disconnect(finishedCallback);
121 // Callback for GaussianBlurView FinishedSignal
122 private void OnFinished(IntPtr data)
124 EventArgs e = new EventArgs();
126 if (finishedEventHandler != null)
128 //here we send all data to user event handlers
129 finishedEventHandler(this, e);
134 /// The BlurStrength property. A value of 0.0 is zero blur and 1.0 is full blur. Default is 1.0.
135 /// if you set the blur to 0.0, the result will be no blur BUT the internal rendering will still be happening.
136 /// If you wish to turn the blur off, you should remove the GaussianBlurView object from the window also.
138 /// <since_tizen> 6 </since_tizen>
139 [EditorBrowsable(EditorBrowsableState.Never)]
140 public float BlurStrength
144 return (float)GetValue(BlurStrengthProperty);
148 SetValue(BlurStrengthProperty, value);
149 NotifyPropertyChanged();
156 [EditorBrowsable(EditorBrowsableState.Never)]
157 public GaussianBlurView() : this(Interop.GaussianBlurView.New(), true)
159 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163 /// Constructor with parameters.
165 /// <param name="numSamples">The size of the Gaussian blur kernel (number of samples in horizontal / vertical blur directions)</param>
166 /// <param name="blurBellCurveWidth">
167 /// 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
168 /// 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
169 /// 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
170 /// 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
171 /// have close to zero weights.
173 /// <param name="renderTargetPixelFormat">The pixel format of the render targets we are using to perform the blur.</param>
174 /// <param name="downsampleWidthScale">
175 /// width scale factor applied during the blur process, scaling the size of the source image to the size of the final blurred image output.
176 /// Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
178 /// <param name="downsampleHeightScale">
179 /// 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.
180 /// Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
182 /// <param name="blurUserImage">
183 /// 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
184 /// SetUserImageAndOutputRenderTarget().
186 /// <since_tizen> 6 </since_tizen>
187 [EditorBrowsable(EditorBrowsableState.Never)]
188 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)
190 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196 /// <since_tizen> 6 </since_tizen>
197 [EditorBrowsable(EditorBrowsableState.Never)]
198 public GaussianBlurView(GaussianBlurView handle) : this(Interop.GaussianBlurView.NewGaussianBlurView(GaussianBlurView.getCPtr(handle)), true, false)
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204 /// Start rendering the GaussianBlurView. Must be called after you Add() it to the window.
206 /// <since_tizen> 6 </since_tizen>
207 [EditorBrowsable(EditorBrowsableState.Never)]
208 public void Activate()
210 Interop.GaussianBlurView.Activate(SwigCPtr);
211 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215 /// Render the GaussianBlurView once.
216 /// Must be called after you Add() it to the window.
217 /// Listen to the Finished signal to determine when the rendering has completed.
219 /// <since_tizen> 6 </since_tizen>
220 [EditorBrowsable(EditorBrowsableState.Never)]
221 public void ActivateOnce()
223 Interop.GaussianBlurView.ActivateOnce(SwigCPtr);
224 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228 /// Stop rendering the GaussianBlurView. Must be called after you Remove() it from the window.
230 /// <since_tizen> 6 </since_tizen>
231 [EditorBrowsable(EditorBrowsableState.Never)]
232 public void Deactivate()
234 Interop.GaussianBlurView.Deactivate(SwigCPtr);
235 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 private int GetBlurStrengthPropertyIndex()
240 int ret = Interop.GaussianBlurView.GetBlurStrengthPropertyIndex(SwigCPtr);
241 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246 internal void SetBackgroundColor(Vector4 color)
248 Interop.GaussianBlurView.SetBackgroundColor(SwigCPtr, Vector4.getCPtr(color));
249 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 internal Vector4 GetBackgroundColor()
254 Vector4 ret = new Vector4(Interop.GaussianBlurView.GetBackgroundColor(SwigCPtr), true);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 private GaussianBlurViewSignal FinishedSignal()
261 GaussianBlurViewSignal ret = new GaussianBlurViewSignal(Interop.GaussianBlurView.FinishedSignal(SwigCPtr), false);
262 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 internal void SetUserImageAndOutputRenderTarget(Texture inputTexture, FrameBuffer outputRenderTarget)
268 Interop.GaussianBlurView.SetUserImageAndOutputRenderTarget(SwigCPtr, Texture.getCPtr(inputTexture), FrameBuffer.getCPtr(outputRenderTarget));
269 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();