Split dali-toolkit into Base & Optional
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / filters / image-filter.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 // CLASS HEADER
18 #include "image-filter.h"
19
20 // INTERNAL INCLUDES
21
22 namespace Dali
23 {
24
25 namespace Toolkit
26 {
27
28 namespace Internal
29 {
30
31 namespace
32 {
33
34 } // namespace
35
36 ImageFilter::ImageFilter()
37 : mBackgroundColor( Vector4( 1.0f, 1.0f, 1.0f, 0.0f ) ),
38   mTargetSize( Vector2::ZERO ),
39   mPixelFormat( Pixel::RGBA8888 ),
40   mRefreshOnDemand( false ),
41   mDebugRender( false )
42 {
43 }
44
45 ImageFilter::~ImageFilter()
46 {
47 }
48
49 void ImageFilter::SetRefreshOnDemand( bool onDemand )
50 {
51   mRefreshOnDemand = onDemand;
52 }
53
54 void ImageFilter::SetInputImage( Image image )
55 {
56   mInputImage = image;
57 }
58
59 void ImageFilter::SetOutputImage( FrameBufferImage image )
60 {
61   mOutputImage = image;
62 }
63
64 void ImageFilter::SetSize( const Vector2& size )
65 {
66   mTargetSize = size;
67 }
68
69 void ImageFilter::SetPixelFormat( Pixel::Format pixelFormat )
70 {
71   mPixelFormat = pixelFormat;
72 }
73
74 void ImageFilter::SetKernel( const FilterKernel& kernel )
75 {
76   mKernel = kernel;
77 }
78
79 const ImageFilter::FilterKernel& ImageFilter::GetKernel() const
80 {
81   return mKernel;
82 }
83
84 size_t ImageFilter::GetKernelSize() const
85 {
86   return mKernel.size();
87 }
88
89 void ImageFilter::CreateKernel( const float* weights, size_t count )
90 {
91   if( (mTargetSize.width * mTargetSize.height ) > 0.0f )
92   {
93     Vector2 pixelsToUV( 1.0f / mTargetSize.width, 1.0f / mTargetSize.height );
94
95     mKernel.clear();
96
97     mKernel.push_back( Vector3( 0.0f, 0.0f, weights[0] ) );
98     for( size_t i = 0; i < count >> 1; ++i )
99     {
100       float offset = 1.5f + (i << 1);
101
102       mKernel.push_back( Vector3( pixelsToUV.x * offset, pixelsToUV.y * offset, weights[(i << 1) + 1] ) );
103       mKernel.push_back( Vector3( -pixelsToUV.x * offset, -pixelsToUV.y * offset, weights[(i << 1) + 2] ) );
104     }
105   }
106 }
107
108 void ImageFilter::SetRootActor( Actor rootActor )
109 {
110   mRootActor = rootActor;
111 }
112
113 void ImageFilter::SetBackgroundColor( const Vector4& color )
114 {
115   mBackgroundColor = color;
116 }
117
118 void ImageFilter::RenderDebug( bool flag )
119 {
120   mDebugRender = flag;
121 }
122
123 } // namespace Internal
124
125 } // namespace Toolkit
126
127 } // namespace Dali