dbab5b126b7b9fcce40863a4bcd7bd27a6419a02
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / filters / image-filter.h
1 #ifndef DALI_TOOLKIT_INTERNAL_IMAGE_FILTER_H
2 #define DALI_TOOLKIT_INTERNAL_IMAGE_FILTER_H
3
4 /*
5  * Copyright (c) 2019 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/actors/camera-actor.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/devel-api/controls/effects-view/effects-view.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal
35 {
36
37 /**
38  * An interface class that provides a interface for image filters that perform
39  * a simple shader effect on an input image, rendering the output to a FrameBufferImage.
40  */
41 class ImageFilter
42 {
43 public:
44   typedef std::vector< Vector3 > FilterKernel;
45
46 public:
47
48   /**
49    * Default constructor
50    */
51   ImageFilter();
52
53   /**
54    * Destructor
55    */
56   virtual ~ImageFilter();
57
58   /**
59    * Enable effect, allocates any necessary resources
60    */
61   virtual void Enable() = 0;
62
63   /**
64    * Disable effect, releases any allocated resources
65    */
66   virtual void Disable() = 0;
67
68   /**
69    * Refresh the filter output
70    */
71   virtual void Refresh() = 0;
72
73   /**
74    * @copydoc Dali::Toolkit::EffectsView::SetRefreshOnDemand
75    */
76   void SetRefreshOnDemand( bool onDemand );
77
78   /**
79    * Set the input image
80    * @param[in] The input/original image.
81    */
82   void SetInputImage( Image image );
83
84   /**
85    * Set the output image
86    * @return The output image.
87    */
88   void SetOutputImage( FrameBufferImage image );
89
90   /**
91    * Set size of ImageFilter. Used to create internal offscreen buffers
92    * @param[in] size  THe size.
93    */
94   virtual void SetSize( const Vector2& size );
95
96   /**
97    * Set the pixel format for internal offscreen buffers
98    * @param[in] pixelFormat The pixel format.
99    */
100   void SetPixelFormat( Pixel::Format pixelFormat );
101
102   /**
103    * Set the filter kernel
104    * @param[in] The filter kernel
105    */
106   void SetKernel( const FilterKernel& kernel );
107
108   /**
109    * Get a const reference to the internal filter kernel
110    * @Return A a const reference to the internal filter kernel
111    */
112   const FilterKernel& GetKernel() const;
113
114   /**
115    * Get the number of steps/elements in the kernel
116    * @return The number of steps/elements in the kernel
117    */
118   size_t GetKernelSize() const;
119
120   /**
121    * Create a kernel from an array of weights
122    * @param[in] weights
123    * @param[in] count
124    */
125   void CreateKernel( const float* weights, size_t count);
126
127   /**
128    * Set the actor which acts as the root actor for all internal actors for connection to stage
129    * @param[in] rootActor   An actor which acts as the root actor for any internal actors that need
130    *                        to be created
131    */
132   void SetRootActor( Actor rootActor );
133
134   /**
135    * Set the background / clear color
136    * @param[in] color The background / clear color
137    */
138   void SetBackgroundColor( const Vector4& color );
139
140 protected:
141
142   /**
143    * Setup position and parameters for camera
144    */
145   void SetupCamera();
146
147 protected:
148   Image            mInputImage;
149   FrameBufferImage mOutputImage;
150   FilterKernel     mKernel;
151   Actor            mRootActor;
152   CameraActor      mCameraActor;
153   Vector4          mBackgroundColor;
154   Vector2          mTargetSize;
155   Pixel::Format    mPixelFormat;
156   bool             mRefreshOnDemand;
157
158 }; // class Imagefilter
159
160 } // namespace Internal
161
162 } // namespace Toolkit
163
164 } // namespace Dali
165
166 #endif // DALI_TOOLKIT_INTERNAL_IMAGE_FILTER_H
167