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