2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "image-filter.h"
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 ),
46 ImageFilter::~ImageFilter()
50 void ImageFilter::SetRefreshOnDemand( bool onDemand )
52 mRefreshOnDemand = onDemand;
55 void ImageFilter::SetInputImage( Image image )
60 void ImageFilter::SetOutputImage( FrameBufferImage image )
65 void ImageFilter::SetSize( const Vector2& size )
70 void ImageFilter::SetPixelFormat( Pixel::Format pixelFormat )
72 mPixelFormat = pixelFormat;
75 void ImageFilter::SetKernel( const FilterKernel& kernel )
80 const ImageFilter::FilterKernel& ImageFilter::GetKernel() const
85 size_t ImageFilter::GetKernelSize() const
87 return mKernel.size();
90 void ImageFilter::CreateKernel( const float* weights, size_t count )
92 if( (mTargetSize.width * mTargetSize.height ) > 0.0f )
94 Vector2 pixelsToUV( 1.0f / mTargetSize.width, 1.0f / mTargetSize.height );
98 mKernel.push_back( Vector3( 0.0f, 0.0f, weights[0] ) );
99 for( size_t i = 0; i < count >> 1; ++i )
101 float offset = 1.5f + (i << 1);
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] ) );
109 void ImageFilter::SetRootActor( Actor rootActor )
111 mRootActor = rootActor;
114 void ImageFilter::SetBackgroundColor( const Vector4& color )
116 mBackgroundColor = color;
119 void ImageFilter::RenderDebug( bool flag )
124 } // namespace Internal
126 } // namespace Toolkit