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"
34 const float ARBITRARY_FIELD_OF_VIEW = Math::PI / 4.0f;
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 )
45 ImageFilter::~ImageFilter()
49 void ImageFilter::SetRefreshOnDemand( bool onDemand )
51 mRefreshOnDemand = onDemand;
54 void ImageFilter::SetInputImage( Image image )
59 void ImageFilter::SetOutputImage( FrameBufferImage image )
64 void ImageFilter::SetSize( const Vector2& size )
69 void ImageFilter::SetPixelFormat( Pixel::Format pixelFormat )
71 mPixelFormat = pixelFormat;
74 void ImageFilter::SetKernel( const FilterKernel& kernel )
79 const ImageFilter::FilterKernel& ImageFilter::GetKernel() const
84 size_t ImageFilter::GetKernelSize() const
86 return mKernel.size();
89 void ImageFilter::CreateKernel( const float* weights, size_t count )
91 if( (mTargetSize.width * mTargetSize.height ) > 0.0f )
93 Vector2 pixelsToUV( 1.0f / mTargetSize.width, 1.0f / mTargetSize.height );
97 mKernel.push_back( Vector3( 0.0f, 0.0f, weights[0] ) );
98 for( size_t i = 0; i < count >> 1; ++i )
100 float offset = 1.5f + (i << 1);
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] ) );
108 void ImageFilter::SetRootActor( Actor rootActor )
110 mRootActor = rootActor;
113 void ImageFilter::SetBackgroundColor( const Vector4& color )
115 mBackgroundColor = color;
118 void ImageFilter::SetupCamera()
122 // create a camera for the render task, corresponding to its render target size
123 mCameraActor = CameraActor::New(mTargetSize);
124 mCameraActor.SetParentOrigin(ParentOrigin::CENTER);
125 mCameraActor.SetInvertYAxis( true );
126 mRootActor.Add( mCameraActor );
130 // place the camera for the render task, corresponding to its render target size
131 mCameraActor.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW);
132 mCameraActor.SetNearClippingPlane(1.0f);
133 mCameraActor.SetAspectRatio(mTargetSize.width / mTargetSize.height);
134 mCameraActor.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
135 mCameraActor.SetPosition(0.0f, 0.0f, ((mTargetSize.height * 0.5f) / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f)));
140 } // namespace Internal
142 } // namespace Toolkit