b08fd440dd3e8cfb5681d61c29e2391226d69392
[platform/core/uifw/dali-toolkit.git] / optional / 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) 2014 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
23 // INTERNAL INCLUDES
24 #include <dali/dali.h>
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-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   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   /**
141    * Enable optional debug output in the shader
142    * @param[in] flag Set true to enable, dalse to disable.
143    */
144   void RenderDebug( bool flag );
145
146 protected:
147   Image            mInputImage;
148   FrameBufferImage mOutputImage;
149   FilterKernel     mKernel;
150   Actor            mRootActor;
151   Vector4          mBackgroundColor;
152   Vector2          mTargetSize;
153   Pixel::Format    mPixelFormat;
154   bool             mRefreshOnDemand;
155   bool             mDebugRender;
156 }; // class Imagefilter
157
158 } // namespace Internal
159
160 } // namespace Toolkit
161
162 } // namespace Dali
163
164 #endif // __DALI_TOOLKIT_INTERNAL_IMAGE_FILTER_H__
165