b6c3a8876d2a8c644927a04a7acccc1c8e787f4d
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / bloom-view / bloom-view.h
1 #ifndef __DALI_TOOLKIT_BLOOM_VIEW_H__
2 #define __DALI_TOOLKIT_BLOOM_VIEW_H__
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/images/pixel.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal DALI_INTERNAL
34 {
35
36 /**
37  * BloomView implementation class
38  */
39 class BloomView;
40
41 } // namespace Internal
42
43 /**
44  *
45  * BloomView is a class for applying a render process that intensifies and blurs the bright parts of an image, bleeding bright areas into darker ones and making bright
46  * light look more realistic.
47  *
48  * Basic idea:-
49  *
50  * 1) The BloomView object will render all its child actors offscreen.\n
51  * 2) The BloomView object then extract the parts of that image that are brighter than the bloom threshold.\n
52  * 3) The BloomView object then blurs the result of step 2), which makes the brightness bleed into surrounding areas.\n
53  * 3) The BloomView object then composites the bloom from step 3) with the child actors image from step 1), using parameters that can be set by the user.
54  * The compositing is additive (image + bloom).\n
55  * 4) The BloomView object gets rendered automatically, either to the screen via the default render task, or via a RenderTask the user has created for
56  * e.g. further offscreen rendering.
57  *
58  * Fundamentally, the BloomView is simply an Actor in the normal actor tree that affects all of its children. It should be added to your Actor tree and manipulated in the
59  * normal ways. It can be considered a 'portal' in the sense that all child actors are clipped to the BloomView actor bounds.
60  *
61  * ************\n
62  * NB: It is essential to remove the BloomView from the stage and also to call Deactivate() on it when you are not using it. This will ensure that resources are freed and
63  * rendering stops.\n
64  * ************\n
65  *
66  *
67  * Usage example:-
68  *
69  *  // initialise\n
70  *  BloomView bloomView = BloomView::New();\n
71  *
72  *  // create and add some visible actors to the BloomView, all these child actors will therefore get bloomed\n
73  *  Image image = Image::New(...);\n
74  *  ImageView imageView = ImageView::New(image);\n
75  *  bloomView.Add(imageView);\n
76  *  ...\n
77  *
78  *  // Start rendering the BloomView\n
79  *  Stage::GetCurrent().Add(bloomView);\n
80  *  bloomView.Activate();\n
81  *  ...\n
82  *
83  *  // animate the strength of the bloom - this can fade between no bloom and your desired max bloom. See GetBloomIntensityPropertyIndex().\n
84  *  Animation blurAnimation = Animation::New( ... );\n
85  *  blurAnimation.AnimateTo( Property( bloomView, bloomView.GetBloomIntensityPropertyIndex() ), ... );\n
86  *  blurAnimation.Play();\n
87  *
88  *  ...\n
89  *  // Stop rendering the BloomView\n
90  *  Stage::GetCurrent().Remove(bloomView);\n
91  *  bloomView.Deactivate();\n
92  */
93 class DALI_TOOLKIT_API BloomView : public Control
94 {
95 public:
96
97   /**
98    * Create an uninitialized BloomView; this can be initialized with BloomView::New()
99    * Calling member functions with an uninitialized Dali::Object is not allowed.
100    */
101   BloomView();
102
103   /**
104    * Copy constructor. Creates another handle that points to the same real object
105    */
106   BloomView(const BloomView& handle);
107
108   /**
109    * Assignment operator. Changes this handle to point to another real object
110    */
111   BloomView& operator=(const BloomView& ZoomView);
112
113   /**
114    * @brief Destructor
115    *
116    * This is non-virtual since derived Handle types must not contain data or virtual methods.
117    */
118   ~BloomView();
119
120   /**
121    * Downcast an Object handle to BloomView. If handle points to a BloomView the
122    * downcast produces valid handle. If not the returned handle is left uninitialized.
123    * @param[in] handle Handle to an object
124    * @return handle to a BloomView or an uninitialized handle
125    */
126   static BloomView DownCast( BaseHandle handle );
127
128   /**
129    * Create an initialized BloomView, using default settings. The default settings are:-\n
130    *
131    * numSamples = 5\n
132    * blurBellCurveWidth = 1.5\n
133    * renderTargetPixelFormat = RGB888\n
134    * downsampleWidthScale = 0.5\n
135    * downsampleHeightScale = 0.5\n
136    * @return A handle to a newly allocated Dali resource
137    */
138   static BloomView New();
139
140  /**
141   * Create an initialized BloomView.
142   * @param numSamples The size of the Gaussian blur kernel (number of samples in horizontal / vertical blur directions) that is used to blur the bloom
143   * @param blurBellCurveWidth 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
144   * 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
145   * 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
146   * 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
147   * have close to zero weights.
148   * @param renderTargetPixelFormat The pixel format of the render targets we are using to perform the bloom.
149   * @param downsampleWidthScale The width scale factor applied during the blur process, scaling the size of the source image to the size of the final blurred image output.
150   * Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
151   * @param downsampleHeightScale 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.
152   * Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
153   * @return A handle to a newly allocated Dali resource
154   */
155   static BloomView New(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
156                               const float downsampleWidthScale, const float downsampleHeightScale);
157
158   /**
159    * Start rendering the BloomView. Must be called after you Add() it to the stage.
160    */
161   void Activate();
162
163   /**
164    * Stop rendering the BloomView. Must be called after you Remove() it from the stage.
165    */
166   void Deactivate();
167
168   /**
169    * Get the property index that controls the intensity threshold above which the pixels will be bloomed. Useful for animating this property.
170    * This property represents a value such that pixels brighter than this threshold will be bloomed. Values are normalised, i.e. RGB 0.0 = 0, 1.0 = 255.  Default 0.25.
171    * @return The property index that can be used with e.g. AnimateTo( ... )
172    */
173   Dali::Property::Index GetBloomThresholdPropertyIndex() const;
174
175   /**
176    * Get the property index that controls the strength of the blur applied to the bloom. Useful for animating this property.
177    * This property represents a value in the range [0.0 - 1.0] where 0.0 is no blur and 1.0 is full blur. Default 1.0.
178    * @return The property index that can be used with e.g. AnimateTo( ... )
179    */
180   Dali::Property::Index GetBlurStrengthPropertyIndex() const;
181
182   /**
183    * Get the property index that controls the intensity of the child actor render texture used during compositing. Useful for animating this property.
184    * This property represents a multiplier on the intensity of the bloom texture. Default 1.0.
185    * @return The property index that can be used with e.g. AnimateTo( ... )
186    */
187   Dali::Property::Index GetBloomIntensityPropertyIndex() const;
188
189   /**
190    * Get the property index that controls the saturation of the child actor render texture used during compositing. Useful for animating this property.
191    * This property represents a multiplier on the saturation of the bloom texture. Default 1.0.
192    * @return The property index that can be used with e.g. AnimateTo( ... )
193    */
194   Dali::Property::Index GetBloomSaturationPropertyIndex() const;
195
196   /**
197    * Get the property index that controls the intensity of the child actor render texture used during compositing. Useful for animating this property.
198    * This property represents a multiplier on the intensity of the image texture. Default 1.0.
199    * @return The property index that can be used with e.g. AnimateTo( ... )
200    */
201   Dali::Property::Index GetImageIntensityPropertyIndex() const;
202
203   /**
204    * Get the property index that controls the saturation of the child actor render texture used during compositing. Useful for animating this property.
205    * This property represents a multiplier on the saturation of the image texture. Default 1.0.
206    * @return The property index that can be used with e.g. AnimateTo( ... )
207    */
208   Dali::Property::Index GetImageSaturationPropertyIndex() const;
209
210 public:
211
212   /**
213    * Creates a handle using the Toolkit::Internal implementation.
214    * @param[in]  implementation  The UI Control implementation.
215    */
216   DALI_INTERNAL BloomView( Internal::BloomView& implementation );
217
218   /**
219    * Allows the creation of this UI Control from an Internal::CustomActor pointer.
220    * @param[in]  internal  A pointer to the internal CustomActor.
221    */
222   explicit DALI_INTERNAL BloomView( Dali::Internal::CustomActor* internal );
223
224 };
225
226 } // namespace Toolkit
227
228 } // namespace Dali
229
230 #endif // __DALI_TOOLKIT_BLOOM_VIEW_H__