2 * Copyright (c) 2024 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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/common/dali-vector.h>
20 #include <dali/public-api/images/pixel-data.h>
21 #include <dali/public-api/images/pixel.h>
23 #include <dali/integration-api/pixel-data-integ.h>
29 int UtcDaliPixelData01(void)
31 TestApplication application;
33 unsigned int width = 10u;
34 unsigned int height = 10u;
35 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGB888);
37 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
38 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
40 DALI_TEST_CHECK(pixelData);
41 DALI_TEST_CHECK(pixelData.GetWidth() == width);
42 DALI_TEST_CHECK(pixelData.GetHeight() == height);
43 DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::RGB888);
48 int UtcDaliPixelData02(void)
50 TestApplication application;
52 unsigned int width = 10u;
53 unsigned int height = 10u;
54 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
55 unsigned char* buffer = new unsigned char[bufferSize];
58 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
60 DALI_TEST_CHECK(pixelData);
61 DALI_TEST_CHECK(pixelData.GetWidth() == width);
62 DALI_TEST_CHECK(pixelData.GetHeight() == height);
63 DALI_TEST_CHECK(pixelData.GetStride() == 0);
64 DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
69 int UtcDaliPixelData03(void)
71 TestApplication application;
74 uint32_t height = 10u;
75 uint32_t stride = 12u;
76 uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::RGB888);
78 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
79 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::RGB888, PixelData::FREE);
81 DALI_TEST_CHECK(pixelData);
82 DALI_TEST_CHECK(pixelData.GetWidth() == width);
83 DALI_TEST_CHECK(pixelData.GetHeight() == height);
84 DALI_TEST_CHECK(pixelData.GetStride() == stride);
85 DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::RGB888);
90 int UtcDaliPixelData04(void)
92 TestApplication application;
95 uint32_t height = 10u;
96 uint32_t stride = 12u;
97 uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::L8);
98 uint8_t* buffer = new uint8_t[bufferSize];
101 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::L8, PixelData::DELETE_ARRAY);
103 DALI_TEST_CHECK(pixelData);
104 DALI_TEST_CHECK(pixelData.GetWidth() == width);
105 DALI_TEST_CHECK(pixelData.GetHeight() == height);
106 DALI_TEST_CHECK(pixelData.GetStride() == stride);
107 DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
112 int UtcDaliPixelDataCopyConstructor(void)
114 TestApplication application;
116 unsigned int width = 10u;
117 unsigned int height = 10u;
118 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
119 unsigned char* buffer = new unsigned char[bufferSize];
120 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
122 PixelData pixelDataCopy(pixelData);
124 DALI_TEST_EQUALS((bool)pixelDataCopy, true, TEST_LOCATION);
128 int UtcDaliPixelDataAssignmentOperator(void)
130 TestApplication application;
132 unsigned int width = 10u;
133 unsigned int height = 10u;
134 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
135 unsigned char* buffer = new unsigned char[bufferSize];
136 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
138 PixelData pixelData2;
139 DALI_TEST_EQUALS((bool)pixelData2, false, TEST_LOCATION);
141 pixelData2 = pixelData;
142 DALI_TEST_EQUALS((bool)pixelData2, true, TEST_LOCATION);
147 int UtcDaliPixelDataMoveConstructor(void)
149 TestApplication application;
151 unsigned int width = 10u;
152 unsigned int height = 10u;
153 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
154 unsigned char* buffer = new unsigned char[bufferSize];
156 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
157 DALI_TEST_CHECK(pixelData);
158 DALI_TEST_EQUALS(width, pixelData.GetWidth(), TEST_LOCATION);
159 DALI_TEST_EQUALS(height, pixelData.GetHeight(), TEST_LOCATION);
161 PixelData moved = std::move(pixelData);
162 DALI_TEST_CHECK(moved);
163 DALI_TEST_EQUALS(width, moved.GetWidth(), TEST_LOCATION);
164 DALI_TEST_EQUALS(height, moved.GetHeight(), TEST_LOCATION);
165 DALI_TEST_CHECK(!pixelData);
170 int UtcDaliPixelDataMoveAssignment(void)
172 TestApplication application;
174 unsigned int width = 10u;
175 unsigned int height = 10u;
176 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
177 unsigned char* buffer = new unsigned char[bufferSize];
179 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
180 DALI_TEST_CHECK(pixelData);
181 DALI_TEST_EQUALS(width, pixelData.GetWidth(), TEST_LOCATION);
182 DALI_TEST_EQUALS(height, pixelData.GetHeight(), TEST_LOCATION);
185 moved = std::move(pixelData);
186 DALI_TEST_CHECK(moved);
187 DALI_TEST_EQUALS(width, moved.GetWidth(), TEST_LOCATION);
188 DALI_TEST_EQUALS(height, moved.GetHeight(), TEST_LOCATION);
189 DALI_TEST_CHECK(!pixelData);
194 int UtcDaliPixelDataGetPixelFormatNegative(void)
196 TestApplication application;
197 Dali::PixelData instance;
200 instance.GetPixelFormat();
201 DALI_TEST_CHECK(false); // Should not get here
205 DALI_TEST_CHECK(true); // We expect an assert
210 int UtcDaliPixelDataGetWidthNegative(void)
212 TestApplication application;
213 Dali::PixelData instance;
217 DALI_TEST_CHECK(false); // Should not get here
221 DALI_TEST_CHECK(true); // We expect an assert
226 int UtcDaliPixelDataGetHeightNegative(void)
228 TestApplication application;
229 Dali::PixelData instance;
232 instance.GetHeight();
233 DALI_TEST_CHECK(false); // Should not get here
237 DALI_TEST_CHECK(true); // We expect an assert
242 int UtcDaliPixelDataGetPixelDataBuffer(void)
244 TestApplication application;
246 uint32_t width = 10u;
247 uint32_t height = 10u;
248 uint32_t stride = 12u;
249 uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::L8);
250 uint8_t* buffer = new uint8_t[bufferSize];
253 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::L8, PixelData::DELETE_ARRAY);
255 DALI_TEST_CHECK(pixelData);
256 DALI_TEST_CHECK(pixelData.GetWidth() == width);
257 DALI_TEST_CHECK(pixelData.GetHeight() == height);
258 DALI_TEST_CHECK(pixelData.GetStride() == stride);
259 DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
261 Dali::Integration::PixelDataBuffer pixelDataBuffer = Dali::Integration::GetPixelDataBuffer(pixelData);
263 DALI_TEST_CHECK(pixelData);
265 DALI_TEST_EQUALS(pixelDataBuffer.bufferSize, bufferSize, TEST_LOCATION);
266 DALI_TEST_EQUALS(pixelDataBuffer.buffer[0], static_cast<uint8_t>('a'), TEST_LOCATION);
271 int UtcDaliPixelDataReleasePixelDataBuffer(void)
273 TestApplication application;
275 uint32_t width = 10u;
276 uint32_t height = 10u;
277 uint32_t stride = 12u;
278 uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::L8);
279 uint8_t* buffer = new uint8_t[bufferSize];
282 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::L8, PixelData::DELETE_ARRAY);
284 DALI_TEST_CHECK(pixelData);
285 DALI_TEST_CHECK(pixelData.GetWidth() == width);
286 DALI_TEST_CHECK(pixelData.GetHeight() == height);
287 DALI_TEST_CHECK(pixelData.GetStride() == stride);
288 DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
290 Dali::Integration::ReleasePixelDataBuffer(pixelData);
292 Dali::Integration::PixelDataBuffer pixelDataBuffer = Dali::Integration::GetPixelDataBuffer(pixelData);
294 DALI_TEST_CHECK(pixelDataBuffer.buffer == nullptr);
299 int UtcDaliPixelDataNewPixelDataWithReleaseAfterUpload(void)
301 TestApplication application;
303 uint32_t width = 10u;
304 uint32_t height = 10u;
305 uint32_t stride = 12u;
306 uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::L8);
307 uint8_t* buffer = new uint8_t[bufferSize];
310 PixelData pixelData = Dali::Integration::NewPixelDataWithReleaseAfterUpload(buffer, bufferSize, width, height, stride, Pixel::L8, PixelData::DELETE_ARRAY);
312 DALI_TEST_CHECK(pixelData);
313 DALI_TEST_CHECK(pixelData.GetWidth() == width);
314 DALI_TEST_CHECK(pixelData.GetHeight() == height);
315 DALI_TEST_CHECK(pixelData.GetStride() == stride);
316 DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
317 DALI_TEST_EQUALS(Dali::Integration::IsPixelDataReleaseAfterUpload(pixelData), true, TEST_LOCATION);
319 Dali::Integration::PixelDataBuffer pixelDataBuffer = Dali::Integration::GetPixelDataBuffer(pixelData);
321 DALI_TEST_EQUALS(pixelDataBuffer.bufferSize, bufferSize, TEST_LOCATION);
322 DALI_TEST_EQUALS(pixelDataBuffer.buffer[0], static_cast<uint8_t>('a'), TEST_LOCATION);