[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / pixel-buffer.cpp
1 /*
2  * Copyright (c) 2024 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(uint32_t            width,
32                              uint32_t            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   return Convert(pixelBuffer, false);
43 }
44
45 Dali::PixelData PixelBuffer::Convert(PixelBuffer& pixelBuffer, bool releaseAfterUpload)
46 {
47   Dali::PixelData pixelData = Internal::Adaptor::PixelBuffer::Convert(GetImplementation(pixelBuffer), releaseAfterUpload);
48   pixelBuffer.Reset();
49   return pixelData;
50 }
51
52 Dali::PixelData PixelBuffer::CreatePixelData() const
53 {
54   return GetImplementation(*this).CreatePixelData();
55 }
56
57 PixelBuffer::PixelBuffer()
58 {
59 }
60
61 PixelBuffer::~PixelBuffer()
62 {
63 }
64
65 PixelBuffer::PixelBuffer(Internal::Adaptor::PixelBuffer* internal)
66 : BaseHandle(internal)
67 {
68 }
69
70 PixelBuffer::PixelBuffer(const PixelBuffer& handle) = default;
71
72 PixelBuffer& PixelBuffer::operator=(const PixelBuffer& rhs) = default;
73
74 PixelBuffer::PixelBuffer(PixelBuffer&& handle) = default;
75
76 PixelBuffer& PixelBuffer::operator=(PixelBuffer&& rhs) = default;
77
78 uint32_t PixelBuffer::GetWidth() const
79 {
80   return GetImplementation(*this).GetWidth();
81 }
82
83 uint32_t PixelBuffer::GetHeight() const
84 {
85   return GetImplementation(*this).GetHeight();
86 }
87
88 uint32_t PixelBuffer::GetStride() const
89 {
90   return GetImplementation(*this).GetStride();
91 }
92
93 Pixel::Format PixelBuffer::GetPixelFormat() const
94 {
95   return GetImplementation(*this).GetPixelFormat();
96 }
97
98 uint8_t* PixelBuffer::GetBuffer()
99 {
100   return GetImplementation(*this).GetBuffer();
101 }
102
103 const uint8_t* PixelBuffer::GetBuffer() const
104 {
105   return GetImplementation(*this).GetConstBuffer();
106 }
107
108 void PixelBuffer::ApplyMask(PixelBuffer mask, float contentScale, bool cropToMask)
109 {
110   GetImplementation(*this).ApplyMask(GetImplementation(mask), contentScale, cropToMask);
111 }
112
113 void PixelBuffer::ApplyGaussianBlur(const float blurRadius)
114 {
115   GetImplementation(*this).ApplyGaussianBlur(blurRadius);
116 }
117
118 void PixelBuffer::Crop(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
119 {
120   GetImplementation(*this).Crop(x, y, ImageDimensions(width, height));
121 }
122
123 void PixelBuffer::Resize(uint16_t width, uint16_t height)
124 {
125   GetImplementation(*this).Resize(ImageDimensions(width, height));
126 }
127
128 void PixelBuffer::MultiplyColorByAlpha()
129 {
130   GetImplementation(*this).MultiplyColorByAlpha();
131 }
132
133 bool PixelBuffer::GetMetadata(Property::Map& metadata) const
134 {
135   return GetImplementation(*this).GetMetadata(metadata);
136 }
137
138 bool PixelBuffer::Rotate(Degree angle)
139 {
140   return GetImplementation(*this).Rotate(angle);
141 }
142
143 bool PixelBuffer::IsAlphaPreMultiplied() const
144 {
145   return GetImplementation(*this).IsAlphaPreMultiplied();
146 }
147
148 uint32_t PixelBuffer::GetBrightness() const
149 {
150   return GetImplementation(*this).GetBrightness();
151 }
152
153 } // namespace Devel
154
155 } // namespace Dali