Merge branch 'devel/master' into sandbox/dkdk/tizen
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / pixel-buffer.cpp
1 /*
2  * Copyright (c) 2020 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 <dali/devel-api/adaptor-framework/pixel-buffer.h>
20
21 // EXTERNAL INLCUDES
22 #include <stdlib.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/internal/imaging/common/pixel-buffer-impl.h>
26
27 namespace Dali
28 {
29 namespace Devel
30 {
31 PixelBuffer PixelBuffer::New(unsigned int        width,
32                              unsigned int        height,
33                              Dali::Pixel::Format pixelFormat)
34 {
35   Internal::Adaptor::PixelBufferPtr internal =
36     Internal::Adaptor::PixelBuffer::New(width, height, pixelFormat);
37   return Devel::PixelBuffer(internal.Get());
38 }
39
40 Dali::PixelData PixelBuffer::Convert(PixelBuffer& pixelBuffer)
41 {
42   Dali::PixelData pixelData =
43     Internal::Adaptor::PixelBuffer::Convert(GetImplementation(pixelBuffer));
44   pixelBuffer.Reset();
45   return pixelData;
46 }
47
48 Dali::PixelData PixelBuffer::CreatePixelData() const
49 {
50   return GetImplementation(*this).CreatePixelData();
51 }
52
53 PixelBuffer::PixelBuffer()
54 {
55 }
56
57 PixelBuffer::~PixelBuffer()
58 {
59 }
60
61 PixelBuffer::PixelBuffer(Internal::Adaptor::PixelBuffer* internal)
62 : BaseHandle(internal)
63 {
64 }
65
66 PixelBuffer::PixelBuffer(const PixelBuffer& handle)
67 : BaseHandle(handle)
68 {
69 }
70
71 PixelBuffer& PixelBuffer::operator=(const PixelBuffer& rhs)
72 {
73   BaseHandle::operator=(rhs);
74   return *this;
75 }
76
77 unsigned int PixelBuffer::GetWidth() const
78 {
79   return GetImplementation(*this).GetWidth();
80 }
81
82 unsigned int PixelBuffer::GetHeight() const
83 {
84   return GetImplementation(*this).GetHeight();
85 }
86
87 Pixel::Format PixelBuffer::GetPixelFormat() const
88 {
89   return GetImplementation(*this).GetPixelFormat();
90 }
91
92 unsigned char* PixelBuffer::GetBuffer()
93 {
94   return GetImplementation(*this).GetBuffer();
95 }
96
97 const unsigned char* const PixelBuffer::GetBuffer() const
98 {
99   return GetImplementation(*this).GetConstBuffer();
100 }
101
102 void PixelBuffer::ApplyMask(PixelBuffer mask, float contentScale, bool cropToMask)
103 {
104   GetImplementation(*this).ApplyMask(GetImplementation(mask), contentScale, cropToMask);
105 }
106
107 void PixelBuffer::ApplyGaussianBlur(const float blurRadius)
108 {
109   GetImplementation(*this).ApplyGaussianBlur(blurRadius);
110 }
111
112 void PixelBuffer::Crop(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
113 {
114   GetImplementation(*this).Crop(x, y, ImageDimensions(width, height));
115 }
116
117 void PixelBuffer::Resize(uint16_t width, uint16_t height)
118 {
119   GetImplementation(*this).Resize(ImageDimensions(width, height));
120 }
121
122 void PixelBuffer::MultiplyColorByAlpha()
123 {
124   GetImplementation(*this).MultiplyColorByAlpha();
125 }
126
127 bool PixelBuffer::GetMetadata(Property::Map& metadata) const
128 {
129   return GetImplementation(*this).GetMetadata(metadata);
130 }
131
132 bool PixelBuffer::Rotate(Degree angle)
133 {
134   return GetImplementation(*this).Rotate(angle);
135 }
136
137 bool PixelBuffer::IsAlphaPreMultiplied() const
138 {
139   return GetImplementation(*this).IsAlphaPreMultiplied();
140 }
141
142 } // namespace Devel
143
144 } // namespace Dali