1 #ifndef DALI_TOOLKIT_BLOOM_VIEW_H
2 #define DALI_TOOLKIT_BLOOM_VIEW_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/images/pixel.h>
25 #include <dali-toolkit/public-api/controls/control.h>
31 namespace Internal DALI_INTERNAL
34 * BloomView implementation class
38 } // namespace DALI_INTERNAL
42 * 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
43 * light look more realistic.
47 * 1) The BloomView object will render all its child actors offscreen.\n
48 * 2) The BloomView object then extract the parts of that image that are brighter than the bloom threshold.\n
49 * 3) The BloomView object then blurs the result of step 2), which makes the brightness bleed into surrounding areas.\n
50 * 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.
51 * The compositing is additive (image + bloom).\n
52 * 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
53 * e.g. further offscreen rendering.
55 * 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
56 * normal ways. It can be considered a 'portal' in the sense that all child actors are clipped to the BloomView actor bounds.
59 * 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
67 * BloomView bloomView = BloomView::New();\n
69 * // create and add some visible actors to the BloomView, all these child actors will therefore get bloomed\n
70 * Image image = Image::New(...);\n
71 * ImageView imageView = ImageView::New(image);\n
72 * bloomView.Add(imageView);\n
75 * // Start rendering the BloomView\n
76 * Stage::GetCurrent().Add(bloomView);\n
77 * bloomView.Activate();\n
80 * // animate the strength of the bloom - this can fade between no bloom and your desired max bloom. See GetBloomIntensityPropertyIndex().\n
81 * Animation blurAnimation = Animation::New( ... );\n
82 * blurAnimation.AnimateTo( Property( bloomView, bloomView.GetBloomIntensityPropertyIndex() ), ... );\n
83 * blurAnimation.Play();\n
86 * // Stop rendering the BloomView\n
87 * Stage::GetCurrent().Remove(bloomView);\n
88 * bloomView.Deactivate();\n
90 class DALI_TOOLKIT_API BloomView : public Control
94 * Create an uninitialized BloomView; this can be initialized with BloomView::New()
95 * Calling member functions with an uninitialized Dali::Object is not allowed.
100 * Copy constructor. Creates another handle that points to the same real object
101 * @param[in] handle The handle to copy from.
103 BloomView(const BloomView& handle);
106 * Assignment operator. Changes this handle to point to another real object
107 * @param[in] handle The handle to copy from.
108 * @return reference to this
110 BloomView& operator=(const BloomView& handle);
113 * Move constructor. Creates another handle that points to the same real object
114 * @param[in] handle The handle to move from.
116 BloomView(BloomView&& handle);
119 * Move assignment operator. Changes this handle to point to another real object
120 * @param[in] handle The handle to move from.
121 * @return reference to this
123 BloomView& operator=(BloomView&& handle);
128 * This is non-virtual since derived Handle types must not contain data or virtual methods.
133 * Downcast an Object handle to BloomView. If handle points to a BloomView the
134 * downcast produces valid handle. If not the returned handle is left uninitialized.
135 * @param[in] handle Handle to an object
136 * @return handle to a BloomView or an uninitialized handle
138 static BloomView DownCast(BaseHandle handle);
141 * Create an initialized BloomView, using default settings. The default settings are:-\n
144 * blurBellCurveWidth = 1.5\n
145 * renderTargetPixelFormat = RGB888\n
146 * downsampleWidthScale = 0.5\n
147 * downsampleHeightScale = 0.5\n
148 * @return A handle to a newly allocated Dali resource
150 static BloomView New();
153 * Create an initialized BloomView.
154 * @param numSamples The size of the Gaussian blur kernel (number of samples in horizontal / vertical blur directions) that is used to blur the bloom
155 * @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
156 * 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
157 * 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
158 * 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
159 * have close to zero weights.
160 * @param renderTargetPixelFormat The pixel format of the render targets we are using to perform the bloom.
161 * @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.
162 * Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
163 * @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.
164 * Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
165 * @return A handle to a newly allocated Dali resource
167 static BloomView New(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat, const float downsampleWidthScale, const float downsampleHeightScale);
170 * Start rendering the BloomView. Must be called after you Add() it to the stage.
175 * Stop rendering the BloomView. Must be called after you Remove() it from the stage.
180 * Get the property index that controls the intensity threshold above which the pixels will be bloomed. Useful for animating this property.
181 * 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.
182 * @return The property index that can be used with e.g. AnimateTo( ... )
184 Dali::Property::Index GetBloomThresholdPropertyIndex() const;
187 * Get the property index that controls the strength of the blur applied to the bloom. Useful for animating this property.
188 * 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.
189 * @return The property index that can be used with e.g. AnimateTo( ... )
191 Dali::Property::Index GetBlurStrengthPropertyIndex() const;
194 * Get the property index that controls the intensity of the child actor render texture used during compositing. Useful for animating this property.
195 * This property represents a multiplier on the intensity of the bloom texture. Default 1.0.
196 * @return The property index that can be used with e.g. AnimateTo( ... )
198 Dali::Property::Index GetBloomIntensityPropertyIndex() const;
201 * Get the property index that controls the saturation of the child actor render texture used during compositing. Useful for animating this property.
202 * This property represents a multiplier on the saturation of the bloom texture. Default 1.0.
203 * @return The property index that can be used with e.g. AnimateTo( ... )
205 Dali::Property::Index GetBloomSaturationPropertyIndex() const;
208 * Get the property index that controls the intensity of the child actor render texture used during compositing. Useful for animating this property.
209 * This property represents a multiplier on the intensity of the image texture. Default 1.0.
210 * @return The property index that can be used with e.g. AnimateTo( ... )
212 Dali::Property::Index GetImageIntensityPropertyIndex() const;
215 * Get the property index that controls the saturation of the child actor render texture used during compositing. Useful for animating this property.
216 * This property represents a multiplier on the saturation of the image texture. Default 1.0.
217 * @return The property index that can be used with e.g. AnimateTo( ... )
219 Dali::Property::Index GetImageSaturationPropertyIndex() const;
223 * Creates a handle using the Toolkit::Internal implementation.
224 * @param[in] implementation The UI Control implementation.
226 DALI_INTERNAL BloomView(Internal::BloomView& implementation);
229 * Allows the creation of this UI Control from an Internal::CustomActor pointer.
230 * @param[in] internal A pointer to the internal CustomActor.
232 explicit DALI_INTERNAL BloomView(Dali::Internal::CustomActor* internal);
235 } // namespace Toolkit
239 #endif // DALI_TOOLKIT_BLOOM_VIEW_H