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"
31 const float ARBITRARY_FIELD_OF_VIEW = Math::PI / 4.0f;
34 ImageFilter::ImageFilter()
35 : mBackgroundColor(Vector4(1.0f, 1.0f, 1.0f, 0.0f)),
36 mTargetSize(Vector2::ZERO),
37 mPixelFormat(Pixel::RGBA8888),
38 mRefreshOnDemand(false)
42 ImageFilter::~ImageFilter()
46 void ImageFilter::SetRefreshOnDemand(bool onDemand)
48 mRefreshOnDemand = onDemand;
51 void ImageFilter::SetInputTexture(Texture texture)
53 mInputTexture = texture;
56 void ImageFilter::SetOutputFrameBuffer(FrameBuffer frameBuffer)
58 mOutputFrameBuffer = frameBuffer;
61 void ImageFilter::SetSize(const Vector2& size)
66 void ImageFilter::SetPixelFormat(Pixel::Format pixelFormat)
68 mPixelFormat = pixelFormat;
71 void ImageFilter::SetKernel(const FilterKernel& kernel)
76 const ImageFilter::FilterKernel& ImageFilter::GetKernel() const
81 size_t ImageFilter::GetKernelSize() const
83 return mKernel.size();
86 void ImageFilter::CreateKernel(const float* weights, size_t count)
88 if((mTargetSize.width * mTargetSize.height) > 0.0f)
90 Vector2 pixelsToUV(1.0f / mTargetSize.width, 1.0f / mTargetSize.height);
94 mKernel.push_back(Vector3(0.0f, 0.0f, weights[0]));
95 for(size_t i = 0; i < count >> 1; ++i)
97 float offset = 1.5f + (i << 1);
99 mKernel.push_back(Vector3(pixelsToUV.x * offset, pixelsToUV.y * offset, weights[(i << 1) + 1]));
100 mKernel.push_back(Vector3(-pixelsToUV.x * offset, -pixelsToUV.y * offset, weights[(i << 1) + 2]));
105 void ImageFilter::SetRootActor(Actor rootActor)
107 mRootActor = rootActor;
110 void ImageFilter::SetBackgroundColor(const Vector4& color)
112 mBackgroundColor = color;
115 void ImageFilter::SetupCamera()
119 // create a camera for the render task, corresponding to its render target size
120 mCameraActor = CameraActor::New(mTargetSize);
121 mCameraActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
122 mCameraActor.SetInvertYAxis(true);
123 mRootActor.Add(mCameraActor);
127 // place the camera for the render task, corresponding to its render target size
128 mCameraActor.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW);
129 mCameraActor.SetNearClippingPlane(1.0f);
130 mCameraActor.SetAspectRatio(mTargetSize.width / mTargetSize.height);
131 mCameraActor.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
132 mCameraActor.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, ((mTargetSize.height * 0.5f) / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f))));
136 } // namespace Internal
138 } // namespace Toolkit