1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17
18 #include "image_type.h"
19 #include "image_utils.h"
20 #include "media_errors.h"
21 #include "pixel_map.h"
22 #include "pixel_convert_adapter.h"
23
24 using namespace testing::ext;
25 using namespace OHOS::Media;
26 namespace OHOS {
27 namespace Multimedia {
28 class PixelMapTest : public testing::Test {
29 public:
PixelMapTest()30 PixelMapTest() {}
~PixelMapTest()31 ~PixelMapTest() {}
32 };
33
ConstructPixmap(AllocatorType type)34 std::unique_ptr<PixelMap> ConstructPixmap(AllocatorType type)
35 {
36 int32_t pixelMapWidth = 4;
37 int32_t pixelMapHeight = 3;
38 int32_t bytesPerPixel = 3;
39 std::unique_ptr<PixelMap> pixelMap = std::make_unique<PixelMap>();
40 ImageInfo info;
41 info.size.width = pixelMapWidth;
42 info.size.height = pixelMapHeight;
43 info.pixelFormat = PixelFormat::RGB_888;
44 info.colorSpace = ColorSpace::SRGB;
45 pixelMap->SetImageInfo(info);
46
47 int32_t rowDataSize = pixelMapWidth * bytesPerPixel;
48 uint32_t bufferSize = rowDataSize * pixelMapHeight;
49 if (bufferSize <= 0) {
50 return nullptr;
51 }
52 void *buffer = malloc(bufferSize);
53 if (buffer == nullptr) {
54 return nullptr;
55 }
56 char *ch = static_cast<char *>(buffer);
57 for (unsigned int i = 0; i < bufferSize; i++) {
58 *(ch++) = (char)i;
59 }
60
61 pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, type, nullptr);
62
63 return pixelMap;
64 }
65
ConstructPixmap(int32_t width,int32_t height,PixelFormat format,AlphaType alphaType,AllocatorType type)66 std::unique_ptr<PixelMap> ConstructPixmap(int32_t width, int32_t height, PixelFormat format,
67 AlphaType alphaType, AllocatorType type)
68 {
69 std::unique_ptr<PixelMap> pixelMap = std::make_unique<PixelMap>();
70 ImageInfo info;
71 info.size.width = width;
72 info.size.height = height;
73 info.pixelFormat = format;
74 info.colorSpace = ColorSpace::SRGB;
75 info.alphaType = alphaType;
76 pixelMap->SetImageInfo(info);
77
78 int32_t bytesPerPixel = 3;
79 int32_t rowDataSize = width * bytesPerPixel;
80 uint32_t bufferSize = rowDataSize * height;
81 if (bufferSize <= 0) {
82 return nullptr;
83 }
84 void *buffer = malloc(bufferSize);
85 if (buffer == nullptr) {
86 return nullptr;
87 }
88 char *ch = static_cast<char *>(buffer);
89 for (unsigned int i = 0; i < bufferSize; i++) {
90 *(ch++) = (char)i;
91 }
92
93 pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, type, nullptr);
94
95 return pixelMap;
96 }
97
ConstructPixmap(PixelFormat format,AlphaType alphaType)98 std::unique_ptr<PixelMap> ConstructPixmap(PixelFormat format, AlphaType alphaType)
99 {
100 int32_t width = 200;
101 int32_t height = 300;
102 InitializationOptions opts;
103 opts.size.width = width;
104 opts.size.height = height;
105 opts.pixelFormat = format;
106 opts.alphaType = alphaType;
107 std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(opts);
108
109 return pixelMap;
110 }
111
112 /**
113 * @tc.name: PixelMapTestT001
114 * @tc.desc: delete PixelMap
115 * @tc.type: FUNC
116 */
117 HWTEST_F(PixelMapTest, PixelMapTest001, TestSize.Level3)
118 {
119 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest001 start";
120
121 auto pixelMap1 = ConstructPixmap(AllocatorType::SHARE_MEM_ALLOC);
122 EXPECT_TRUE(pixelMap1 != nullptr);
123 pixelMap1 = nullptr;
124
125 auto pixelMap2 = ConstructPixmap((AllocatorType)10);
126 EXPECT_TRUE(pixelMap2 != nullptr);
127 pixelMap2 = nullptr;
128
129 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest001 end";
130 }
131
132 /**
133 * @tc.name: PixelMapTestT002
134 * @tc.desc: Create PixelMap
135 * @tc.type: FUNC
136 */
137 HWTEST_F(PixelMapTest, PixelMapTest002, TestSize.Level3)
138 {
139 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest002 start";
140
141 const uint32_t color[8] = { 0x80, 0x02, 0x04, 0x08, 0x40, 0x02, 0x04, 0x08 };
142 uint32_t colorlength = sizeof(color) / sizeof(color[0]);
143 EXPECT_TRUE(colorlength == 8);
144 const int32_t offset = 0;
145 InitializationOptions opts;
146 opts.size.width = 3;
147 opts.size.height = 2;
148 opts.pixelFormat = PixelFormat::UNKNOWN;
149 opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
150 int32_t width = opts.size.width;
151 std::unique_ptr<PixelMap> pixelMap1 = PixelMap::Create(color, colorlength, offset, 0, opts);
152 EXPECT_EQ(pixelMap1, nullptr);
153
154 std::unique_ptr<PixelMap> pixelMap2 = PixelMap::Create(color, colorlength, offset, INT32_MAX, opts);
155 EXPECT_EQ(pixelMap2, nullptr);
156
157 std::unique_ptr<PixelMap> pixelMap3 = PixelMap::Create(color, colorlength, -1, width, opts);
158 EXPECT_EQ(pixelMap3, nullptr);
159
160 std::unique_ptr<PixelMap> pixelMap4= PixelMap::Create(color, colorlength, 100, width, opts);
161 EXPECT_EQ(pixelMap4, nullptr);
162
163 std::unique_ptr<PixelMap> pixelMap5= PixelMap::Create(color, colorlength, offset, width, opts);
164 EXPECT_TRUE(pixelMap5 != nullptr);
165
166 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest002 end";
167 }
168
169 /**
170 * @tc.name: PixelMapTestT003
171 * @tc.desc: Create PixelMap
172 * @tc.type: FUNC
173 */
174 HWTEST_F(PixelMapTest, PixelMapTestT003, TestSize.Level3)
175 {
176 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTestT003 start";
177
178 InitializationOptions opts1;
179 opts1.size.width = 200;
180 opts1.size.height = 300;
181 opts1.pixelFormat = PixelFormat::RGBA_8888;
182 opts1.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
183 std::unique_ptr<PixelMap> pixelMap1 = PixelMap::Create(opts1);
184 EXPECT_TRUE(pixelMap1 != nullptr);
185
186 InitializationOptions opts2;
187 opts2.size.width = 200;
188 opts2.size.height = 300;
189 opts2.pixelFormat = PixelFormat::BGRA_8888;
190 opts2.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
191 std::unique_ptr<PixelMap> pixelMap2 = PixelMap::Create(opts2);
192 EXPECT_TRUE(pixelMap2 != nullptr);
193
194 InitializationOptions opts3;
195 opts3.size.width = 200;
196 opts3.size.height = 300;
197 opts3.pixelFormat = PixelFormat::ARGB_8888;
198 opts3.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
199 std::unique_ptr<PixelMap> pixelMap3 = PixelMap::Create(opts3);
200 EXPECT_TRUE(pixelMap3 != nullptr);
201
202 InitializationOptions opts4;
203 opts4.size.width = 200;
204 opts4.size.height = 300;
205 opts4.pixelFormat = PixelFormat::RGB_565;
206 opts4.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
207 std::unique_ptr<PixelMap> pixelMap4 = PixelMap::Create(opts4);
208 EXPECT_TRUE(pixelMap4 != nullptr);
209
210 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTestT003 end";
211 }
212
213 /**
214 * @tc.name: PixelMapTest004
215 * @tc.desc: Create PixelMap
216 * @tc.type: FUNC
217 */
218 HWTEST_F(PixelMapTest, PixelMapTest004, TestSize.Level3)
219 {
220 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest004 start";
221
222 PixelMap srcPixelMap;
223 ImageInfo imageInfo;
224 imageInfo.size.width = 200;
225 imageInfo.size.height = 300;
226 imageInfo.pixelFormat = PixelFormat::ARGB_8888;
227 imageInfo.colorSpace = ColorSpace::SRGB;
228 srcPixelMap.SetImageInfo(imageInfo);
229 InitializationOptions opts;
230 opts.size.width = 200;
231 opts.size.height = 300;
232 opts.pixelFormat = PixelFormat::ARGB_8888;
233 opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
234 opts.useSourceIfMatch = true;
235 Rect srcRect1;
236 srcRect1.width = 200;
237 srcRect1.height = 300;
238 std::unique_ptr<PixelMap> pixelMap1 = PixelMap::Create(srcPixelMap, srcRect1, opts);
239 EXPECT_EQ(pixelMap1, nullptr);
240
241 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest004 end";
242 }
243
244 /**
245 * @tc.name: PixelMapTest005
246 * @tc.desc: SetImageInfo
247 * @tc.type: FUNC
248 */
249 HWTEST_F(PixelMapTest, PixelMapTest005, TestSize.Level3)
250 {
251 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest005 start";
252 std::unique_ptr<PixelMap> pixelMap1 = std::make_unique<PixelMap>();
253 ImageInfo info1;
254 info1.size.width = 200;
255 info1.size.height = 0;
256 info1.pixelFormat = PixelFormat::RGB_888;
257 info1.colorSpace = ColorSpace::SRGB;
258 auto ret = pixelMap1->SetImageInfo(info1);
259 EXPECT_EQ(ret, ERR_IMAGE_DATA_ABNORMAL);
260
261 std::unique_ptr<PixelMap> pixelMap2 = std::make_unique<PixelMap>();
262 ImageInfo info2;
263 info2.size.width = 200;
264 info2.size.height = 300;
265 info2.pixelFormat = PixelFormat::NV12;
266 info2.colorSpace = ColorSpace::SRGB;
267 ret = pixelMap2->SetImageInfo(info2);
268 EXPECT_EQ(ret, SUCCESS);
269
270 std::unique_ptr<PixelMap> pixelMap3 = std::make_unique<PixelMap>();
271 ImageInfo info3;
272 info3.size.width = 200;
273 info3.size.height = 300;
274 info3.pixelFormat = PixelFormat::NV21;
275 info3.colorSpace = ColorSpace::SRGB;
276 ret = pixelMap3->SetImageInfo(info3);
277 EXPECT_EQ(ret, SUCCESS);
278
279 std::unique_ptr<PixelMap> pixelMap4 = std::make_unique<PixelMap>();
280 ImageInfo info4;
281 info4.size.width = 200;
282 info4.size.height = 300;
283 info4.pixelFormat = PixelFormat::CMYK;
284 info4.colorSpace = ColorSpace::SRGB;
285 ret = pixelMap4->SetImageInfo(info4);
286 EXPECT_EQ(ret, SUCCESS);
287
288 std::unique_ptr<PixelMap> pixelMap5 = std::make_unique<PixelMap>();
289 ImageInfo info5;
290 info5.size.width = 200;
291 info5.size.height = 300;
292 info5.pixelFormat = PixelFormat::RGBA_F16;
293 info5.colorSpace = ColorSpace::SRGB;
294 ret = pixelMap5->SetImageInfo(info5);
295 EXPECT_EQ(ret, SUCCESS);
296 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest005 end";
297 }
298
299 /**
300 * @tc.name: PixelMapTest006
301 * @tc.desc: SetImageInfo
302 * @tc.type: FUNC
303 */
304 HWTEST_F(PixelMapTest, PixelMapTest006, TestSize.Level3)
305 {
306 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest006 start";
307 std::unique_ptr<PixelMap> pixelMap1 = std::make_unique<PixelMap>();
308 ImageInfo info1;
309 info1.size.width = INT32_MAX;
310 info1.size.height = 300;
311 info1.pixelFormat = PixelFormat::RGB_888;
312 info1.colorSpace = ColorSpace::SRGB;
313 auto ret = pixelMap1->SetImageInfo(info1);
314 EXPECT_EQ(ret, ERR_IMAGE_TOO_LARGE);
315
316 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest006 end";
317 }
318
319 /**
320 * @tc.name: PixelMapTest007
321 * @tc.desc: GetPixel
322 * @tc.type: FUNC
323 */
324 HWTEST_F(PixelMapTest, PixelMapTest007, TestSize.Level3)
325 {
326 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest007 start";
327
328 auto pixelMap1 = ConstructPixmap(200, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
329 AllocatorType::HEAP_ALLOC);
330 EXPECT_TRUE(pixelMap1 != nullptr);
331 auto ret1 = pixelMap1->GetPixel8(100, 200);
332 EXPECT_TRUE(ret1 == nullptr);
333
334 auto pixelMap2 = ConstructPixmap(200, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
335 AllocatorType::HEAP_ALLOC);
336 EXPECT_TRUE(pixelMap2 != nullptr);
337 auto ret2 = pixelMap2->GetPixel16(100, 200);
338 EXPECT_TRUE(ret2 == nullptr);
339
340 auto pixelMap3 = ConstructPixmap(200, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
341 AllocatorType::HEAP_ALLOC);
342 EXPECT_TRUE(pixelMap3 != nullptr);
343 auto ret3 = pixelMap3->GetPixel32(100, 200);
344 EXPECT_TRUE(ret3 == nullptr);
345
346 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest007 end";
347 }
348
349 /**
350 * @tc.name: PixelMapTest008
351 * @tc.desc: IsSameImage
352 * @tc.type: FUNC
353 */
354 HWTEST_F(PixelMapTest, PixelMapTest008, TestSize.Level3)
355 {
356 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest008 start";
357
358 std::unique_ptr<PixelMap> pixelMap = std::make_unique<PixelMap>();
359 ImageInfo info;
360 info.size.width = 200;
361 info.size.height = 300;
362 info.pixelFormat = PixelFormat::RGBA_F16;
363 info.colorSpace = ColorSpace::SRGB;
364 pixelMap->SetImageInfo(info);
365
366 auto pixelMap1 = ConstructPixmap(200, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
367 AllocatorType::HEAP_ALLOC);
368 EXPECT_TRUE(pixelMap1 != nullptr);
369 auto ret = pixelMap1->IsSameImage(*pixelMap);
370 EXPECT_FALSE(ret);
371
372 auto pixelMap2 = ConstructPixmap(300, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
373 AllocatorType::HEAP_ALLOC);
374 EXPECT_TRUE(pixelMap2 != nullptr);
375 ret = pixelMap1->IsSameImage(*pixelMap2);
376 EXPECT_FALSE(ret);
377
378 auto pixelMap3 = ConstructPixmap(200, 200, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
379 AllocatorType::HEAP_ALLOC);
380 EXPECT_TRUE(pixelMap3 != nullptr);
381 ret = pixelMap1->IsSameImage(*pixelMap3);
382 EXPECT_FALSE(ret);
383
384 auto pixelMap4 = ConstructPixmap(200, 300, PixelFormat::RGB_888, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
385 AllocatorType::HEAP_ALLOC);
386 EXPECT_TRUE(pixelMap4 != nullptr);
387 ret = pixelMap1->IsSameImage(*pixelMap4);
388 EXPECT_FALSE(ret);
389
390 auto pixelMap5 = ConstructPixmap(200, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_PREMUL,
391 AllocatorType::HEAP_ALLOC);
392 EXPECT_TRUE(pixelMap5 != nullptr);
393 ret = pixelMap1->IsSameImage(*pixelMap5);
394 EXPECT_FALSE(ret);
395
396 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest008 end";
397 }
398
399 /**
400 * @tc.name: PixelMapTest009
401 * @tc.desc: ReadPixels
402 * @tc.type: FUNC
403 */
404 HWTEST_F(PixelMapTest, PixelMapTest009, TestSize.Level3)
405 {
406 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest009 start";
407
408 std::unique_ptr<PixelMap> pixelMap1 = std::make_unique<PixelMap>();
409 ImageInfo info;
410 info.size.width = 200;
411 info.size.height = 300;
412 info.pixelFormat = PixelFormat::RGBA_F16;
413 info.colorSpace = ColorSpace::SRGB;
414 pixelMap1->SetImageInfo(info);
415 uint64_t bufferSize1 = 96;
416 uint8_t *dst1 = new uint8_t(0);
417 EXPECT_TRUE(dst1 != nullptr);
418 auto ret = pixelMap1->ReadPixels(bufferSize1, dst1);
419 EXPECT_TRUE(ret != SUCCESS);
420
421 auto pixelMap2 = ConstructPixmap(200, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
422 AllocatorType::HEAP_ALLOC);
423 EXPECT_TRUE(pixelMap2 != nullptr);
424 uint64_t bufferSize2 = 96;
425 uint8_t *dst2 = new uint8_t(0);
426 EXPECT_TRUE(dst2 != nullptr);
427 ret = pixelMap2->ReadPixels(bufferSize2, dst2);
428 EXPECT_TRUE(ret != SUCCESS);
429
430 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest009 end";
431 }
432
433 /**
434 * @tc.name: PixelMapTest010
435 * @tc.desc: ReadPixels
436 * @tc.type: FUNC
437 */
438 HWTEST_F(PixelMapTest, PixelMapTest010, TestSize.Level3)
439 {
440 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest010 start";
441 auto pixelMap1 = ConstructPixmap(200, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
442 AllocatorType::HEAP_ALLOC);
443 EXPECT_TRUE(pixelMap1 != nullptr);
444 uint64_t bufferSize1 = 96;
445 uint8_t *dst1 = new uint8_t(0);
446 uint32_t offset1 = 0;
447 uint32_t stride1 = 8;
448 Rect rect1;
449 rect1.left = 0;
450 rect1.top = 0;
451 rect1.height = 1;
452 rect1.width = 2;
453 EXPECT_TRUE(dst1 != nullptr);
454 auto ret = pixelMap1->ReadPixels(bufferSize1, offset1, stride1, rect1, dst1);
455 EXPECT_TRUE(ret == SUCCESS);
456
457 uint64_t bufferSize2 = 0;
458 uint8_t *dst2 = new uint8_t(0);
459 EXPECT_TRUE(dst2 != nullptr);
460 ret = pixelMap1->ReadPixels(bufferSize2, offset1, stride1, rect1, dst2);
461 EXPECT_TRUE(ret != SUCCESS);
462
463 uint64_t bufferSize3 = 96;
464 uint8_t *dst3 = new uint8_t(0);
465 uint32_t offset3 = 0;
466 uint32_t stride3 = 8;
467 Rect rect3;
468 rect3.left = -1;
469 rect3.top = 0;
470 rect3.height = 1;
471 rect3.width = 2;
472 ret = pixelMap1->ReadPixels(bufferSize3, offset3, stride3, rect3, dst3);
473 EXPECT_TRUE(ret != SUCCESS);
474
475 uint64_t bufferSize4 = 96;
476 uint8_t *dst4 = new uint8_t(0);
477 Rect rect4;
478 rect4.left = 0;
479 rect4.top = -1;
480 rect4.height = 1;
481 rect4.width = 2;
482 ret = pixelMap1->ReadPixels(bufferSize4, offset3, stride3, rect4, dst4);
483 EXPECT_TRUE(ret != SUCCESS);
484
485 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest010 end";
486 }
487
488 /**
489 * @tc.name: PixelMapTest011
490 * @tc.desc: ReadPixels
491 * @tc.type: FUNC
492 */
493 HWTEST_F(PixelMapTest, PixelMapTest011, TestSize.Level3)
494 {
495 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest011 start";
496 auto pixelMap1 = ConstructPixmap(200, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
497 AllocatorType::HEAP_ALLOC);
498 EXPECT_TRUE(pixelMap1 != nullptr);
499
500 uint64_t bufferSize1 = 96;
501 uint8_t *dst1 = new uint8_t(0);
502 uint32_t offset1 = 0;
503 uint32_t stride1 = 8;
504 Rect rect1;
505 rect1.left = 0;
506 rect1.top = 0;
507 rect1.height = -1;
508 rect1.width = 2;
509 auto ret = pixelMap1->ReadPixels(bufferSize1, offset1, stride1, rect1, dst1);
510 EXPECT_TRUE(ret != SUCCESS);
511
512 Rect rect2;
513 rect2.left = 0;
514 rect2.top = 0;
515 rect2.height = 1;
516 rect2.width = -1;
517 ret = pixelMap1->ReadPixels(bufferSize1, offset1, stride1, rect2, dst1);
518 EXPECT_TRUE(ret != SUCCESS);
519
520 Rect rect3;
521 rect3.left = 0;
522 rect3.top = 0;
523 rect3.height = (INT32_MAX >> 2) + 1;
524 rect3.width = 2;
525 ret = pixelMap1->ReadPixels(bufferSize1, offset1, stride1, rect3, dst1);
526 EXPECT_TRUE(ret != SUCCESS);
527
528 Rect rect4;
529 rect4.left = 0;
530 rect4.top = 0;
531 rect4.height = 1;
532 rect4.width = (INT32_MAX >> 2) + 1;
533 ret = pixelMap1->ReadPixels(bufferSize1, offset1, stride1, rect4, dst1);
534 EXPECT_TRUE(ret != SUCCESS);
535
536 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest011 end";
537 }
538
539 /**
540 * @tc.name: PixelMapTest012
541 * @tc.desc: ReadPixels
542 * @tc.type: FUNC
543 */
544 HWTEST_F(PixelMapTest, PixelMapTest012, TestSize.Level3)
545 {
546 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest012 start";
547 auto pixelMap1 = ConstructPixmap(200, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
548 AllocatorType::HEAP_ALLOC);
549 EXPECT_TRUE(pixelMap1 != nullptr);
550
551 uint64_t bufferSize1 = 96;
552 uint8_t *dst1 = new uint8_t(0);
553 uint32_t offset1 = 0;
554 uint32_t stride1 = 8;
555 Rect rect1;
556 rect1.left = 500;
557 rect1.top = 0;
558 rect1.height = 1;
559 rect1.width = 2;
560 auto ret = pixelMap1->ReadPixels(bufferSize1, offset1, stride1, rect1, dst1);
561 EXPECT_TRUE(ret != SUCCESS);
562
563 Rect rect2;
564 rect2.left = 0;
565 rect2.top = 500;
566 rect2.height = 1;
567 rect2.width = 2;
568 ret = pixelMap1->ReadPixels(bufferSize1, offset1, stride1, rect2, dst1);
569 EXPECT_TRUE(ret != SUCCESS);
570
571 uint32_t stride2 = 1;
572 Rect rect3;
573 rect3.left = 0;
574 rect3.top = 0;
575 rect3.height = 1;
576 rect3.width = 2;
577 ret = pixelMap1->ReadPixels(bufferSize1, offset1, stride2, rect3, dst1);
578 EXPECT_TRUE(ret != SUCCESS);
579
580 uint64_t bufferSize2 = 6;
581 ret = pixelMap1->ReadPixels(bufferSize2, offset1, stride1, rect3, dst1);
582 EXPECT_TRUE(ret != SUCCESS);
583
584 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest012 end";
585 }
586
587 /**
588 * @tc.name: PixelMapTest013
589 * @tc.desc: ReadPixels
590 * @tc.type: FUNC
591 */
592 HWTEST_F(PixelMapTest, PixelMapTest013, TestSize.Level3)
593 {
594 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest013 start";
595 auto pixelMap1 = ConstructPixmap(200, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
596 AllocatorType::HEAP_ALLOC);
597 EXPECT_TRUE(pixelMap1 != nullptr);
598
599 uint64_t bufferSize1 = 96;
600 uint8_t *dst1 = new uint8_t(0);
601 uint32_t offset1 = 500;
602 uint32_t stride1 = 8;
603 Rect rect1;
604 rect1.left = 0;
605 rect1.top = 0;
606 rect1.height = 1;
607 rect1.width = 2;
608 auto ret = pixelMap1->ReadPixels(bufferSize1, offset1, stride1, rect1, dst1);
609 EXPECT_TRUE(ret != SUCCESS);
610
611 std::unique_ptr<PixelMap> pixelMap2 = std::make_unique<PixelMap>();
612 ImageInfo info;
613 info.size.width = 200;
614 info.size.height = 300;
615 info.pixelFormat = PixelFormat::RGBA_F16;
616 info.colorSpace = ColorSpace::SRGB;
617 pixelMap2->SetImageInfo(info);
618 EXPECT_TRUE(pixelMap2 != nullptr);
619
620 uint64_t bufferSize2 = 96;
621 uint8_t *dst2 = new uint8_t(0);
622 uint32_t offset2 = 0;
623 uint32_t stride2 = 8;
624 Rect rect2;
625 rect2.left = 0;
626 rect2.top = 0;
627 rect2.height = 1;
628 rect2.width = 2;
629 ret = pixelMap2->ReadPixels(bufferSize2, offset2, stride2, rect2, dst2);
630 EXPECT_TRUE(ret != SUCCESS);
631
632 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest013 end";
633 }
634
635 /**
636 * @tc.name: PixelMapTest014
637 * @tc.desc: ReadPixels
638 * @tc.type: FUNC
639 */
640 HWTEST_F(PixelMapTest, PixelMapTest014, TestSize.Level3)
641 {
642 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest014 start";
643 auto pixelMap1 = ConstructPixmap(200, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
644 AllocatorType::HEAP_ALLOC);
645 EXPECT_TRUE(pixelMap1 != nullptr);
646
647 Position position;
648 position.x = 1;
649 position.y = 1;
650 uint32_t dst = 0;
651 auto ret = pixelMap1->ReadPixel(position, dst);
652 EXPECT_TRUE(ret == SUCCESS);
653
654 Position position1;
655 position1.x = -1;
656 position1.y = 1;
657 ret = pixelMap1->ReadPixel(position1, dst);
658 EXPECT_TRUE(ret != SUCCESS);
659
660 Position position2;
661 position2.x = 1;
662 position2.y = -1;
663 ret = pixelMap1->ReadPixel(position2, dst);
664 EXPECT_TRUE(ret != SUCCESS);
665
666 Position position3;
667 position3.x = 300;
668 position3.y = 1;
669 ret = pixelMap1->ReadPixel(position3, dst);
670 EXPECT_TRUE(ret != SUCCESS);
671
672 Position position4;
673 position4.x = 1;
674 position4.y = 400;
675 ret = pixelMap1->ReadPixel(position4, dst);
676 EXPECT_TRUE(ret != SUCCESS);
677
678 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest014 end";
679 }
680
681 /**
682 * @tc.name: PixelMapTest015
683 * @tc.desc: ResetConfig
684 * @tc.type: FUNC
685 */
686 HWTEST_F(PixelMapTest, PixelMapTest015, TestSize.Level3)
687 {
688 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest015 start";
689 auto pixelMap1 = ConstructPixmap(3, 3, PixelFormat::ALPHA_8, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
690 AllocatorType::HEAP_ALLOC);
691 EXPECT_TRUE(pixelMap1 != nullptr);
692 Size size1;
693 size1.width = 6;
694 size1.height = 6;
695 PixelFormat pixelFormat = PixelFormat::UNKNOWN;
696 auto ret = pixelMap1->ResetConfig(size1, pixelFormat);
697 EXPECT_TRUE(ret != SUCCESS);
698
699 Size size2;
700 size2.width = 1;
701 size2.height = 1;
702 PixelFormat pixelFormat2 = PixelFormat::RGB_888;
703 ret = pixelMap1->ResetConfig(size2, pixelFormat2);
704 EXPECT_TRUE(ret == SUCCESS);
705
706 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest015 end";
707 }
708
709 /**
710 * @tc.name: PixelMapTest016
711 * @tc.desc: ResetConfig
712 * @tc.type: FUNC
713 */
714 HWTEST_F(PixelMapTest, PixelMapTest016, TestSize.Level3)
715 {
716 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest016 start";
717 auto pixelMap1 = ConstructPixmap(3, 3, PixelFormat::ALPHA_8, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
718 AllocatorType::HEAP_ALLOC);
719 EXPECT_TRUE(pixelMap1 != nullptr);
720 Size size1;
721 size1.width = 6;
722 size1.height = 6;
723 PixelFormat pixelFormat = PixelFormat::UNKNOWN;
724 auto ret = pixelMap1->ResetConfig(size1, pixelFormat);
725 EXPECT_TRUE(ret != SUCCESS);
726
727 Size size2;
728 size2.width = 1;
729 size2.height = 1;
730 PixelFormat pixelFormat2 = PixelFormat::RGB_888;
731 ret = pixelMap1->ResetConfig(size2, pixelFormat2);
732 EXPECT_TRUE(ret == SUCCESS);
733
734 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest016 end";
735 }
736
737 /**
738 * @tc.name: PixelMapTest017
739 * @tc.desc: SetAlphaType
740 * @tc.type: FUNC
741 */
742 HWTEST_F(PixelMapTest, PixelMapTest017, TestSize.Level3)
743 {
744 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest017 start";
745 auto pixelMap1 = ConstructPixmap(3, 3, PixelFormat::ALPHA_8, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
746 AllocatorType::HEAP_ALLOC);
747 EXPECT_TRUE(pixelMap1 != nullptr);
748 auto ret = pixelMap1->SetAlphaType(AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN);
749 EXPECT_TRUE(ret);
750
751 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest017 end";
752 }
753
754 /**
755 * @tc.name: PixelMapTest018
756 * @tc.desc: WritePixel
757 * @tc.type: FUNC
758 */
759 HWTEST_F(PixelMapTest, PixelMapTest018, TestSize.Level3)
760 {
761 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest018 start";
762 InitializationOptions opts;
763 opts.size.width = 200;
764 opts.size.height = 300;
765 opts.pixelFormat = PixelFormat::ARGB_8888;
766 opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
767 opts.useSourceIfMatch = true;
768 opts.editable = true;
769 std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(opts);
770 EXPECT_TRUE(pixelMap != nullptr);
771
772 Position position;
773 position.x = 0;
774 position.y = 0;
775 uint32_t color = 9;
776 auto ret = pixelMap->WritePixel(position, color);
777 EXPECT_FALSE(ret);
778
779 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest018 end";
780 }
781
782 /**
783 * @tc.name: PixelMapTest019
784 * @tc.desc: WritePixel
785 * @tc.type: FUNC
786 */
787 HWTEST_F(PixelMapTest, PixelMapTest019, TestSize.Level3)
788 {
789 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest019 start";
790 PixelMap srcPixelMap;
791 ImageInfo imageInfo;
792 imageInfo.size.width = 200;
793 imageInfo.size.height = 300;
794 imageInfo.pixelFormat = PixelFormat::ARGB_8888;
795 imageInfo.colorSpace = ColorSpace::SRGB;
796 srcPixelMap.SetImageInfo(imageInfo);
797 int32_t rowDataSize = 200;
798 uint32_t bufferSize = rowDataSize * 300;
799 void *buffer = malloc(bufferSize);
800 char *ch = static_cast<char *>(buffer);
801 for (unsigned int i = 0; i < bufferSize; i++) {
802 *(ch++) = (char)i;
803 }
804 srcPixelMap.SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
805 InitializationOptions opts;
806 opts.size.width = 200;
807 opts.size.height = 300;
808 opts.pixelFormat = PixelFormat::ARGB_8888;
809 opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
810 opts.useSourceIfMatch = true;
811 opts.editable = true;
812 Rect srcRect1;
813 srcRect1.width = 200;
814 srcRect1.height = 300;
815 std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(srcPixelMap, srcRect1, opts);
816
817 uint64_t bufferSize1 = 96;
818 uint8_t *dst1 = new uint8_t(0);
819 uint32_t offset1 = 500;
820 uint32_t stride1 = 8;
821 Rect rect1;
822 rect1.left = 0;
823 rect1.top = 0;
824 rect1.height = 1;
825 rect1.width = 2;
826 auto ret = pixelMap->WritePixels(dst1, bufferSize1, offset1, stride1, rect1);
827 EXPECT_TRUE(ret);
828
829 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest019 end";
830 }
831
832 /**
833 * @tc.name: PixelMapTest020
834 * @tc.desc: WritePixel
835 * @tc.type: FUNC
836 */
837 HWTEST_F(PixelMapTest, PixelMapTest020, TestSize.Level3)
838 {
839 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest020 start";
840 InitializationOptions opts;
841 opts.size.width = 200;
842 opts.size.height = 300;
843 opts.pixelFormat = PixelFormat::ARGB_8888;
844 opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
845 opts.useSourceIfMatch = true;
846 opts.editable = true;
847 std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(opts);
848 EXPECT_TRUE(pixelMap != nullptr);
849
850 uint64_t bufferSize1 = 96;
851 uint8_t *dst1 = new uint8_t(0);
852 auto ret = pixelMap->WritePixels(dst1, bufferSize1);
853 EXPECT_TRUE(ret);
854
855 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest020 end";
856 }
857
858 /**
859 * @tc.name: PixelMapTest021
860 * @tc.desc: WritePixel
861 * @tc.type: FUNC
862 */
863 HWTEST_F(PixelMapTest, PixelMapTest021, TestSize.Level3)
864 {
865 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest021 start";
866 InitializationOptions opts;
867 opts.size.width = 200;
868 opts.size.height = 300;
869 opts.pixelFormat = PixelFormat::ARGB_8888;
870 opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
871 opts.useSourceIfMatch = true;
872 opts.editable = true;
873 std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(opts);
874 EXPECT_TRUE(pixelMap != nullptr);
875
876 uint32_t color = 1;
877 auto ret = pixelMap->WritePixels(color);
878 EXPECT_TRUE(ret);
879
880 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest021 end";
881 }
882
883 /**
884 * @tc.name: PixelMapTest022
885 * @tc.desc: Marshalling
886 * @tc.type: FUNC
887 */
888 HWTEST_F(PixelMapTest, PixelMapTest022, TestSize.Level3)
889 {
890 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest022 start";
891 InitializationOptions opts;
892 opts.size.width = 200;
893 opts.size.height = 300;
894 opts.pixelFormat = PixelFormat::ARGB_8888;
895 opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
896 opts.useSourceIfMatch = true;
897 opts.editable = true;
898 std::unique_ptr<PixelMap> pixelMap1 = PixelMap::Create(opts);
899 EXPECT_TRUE(pixelMap1 != nullptr);
900 Parcel data;
901 auto ret = pixelMap1->Marshalling(data);
902 EXPECT_TRUE(ret);
903 PixelMap *pixelMap2 = PixelMap::Unmarshalling(data);
904 EXPECT_EQ(pixelMap1->GetHeight(), pixelMap2->GetHeight());
905
906 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest022 end";
907 }
908
909 /**
910 * @tc.name: PixelMapTest023
911 * @tc.desc: SetAlpha
912 * @tc.type: FUNC
913 */
914 HWTEST_F(PixelMapTest, PixelMapTest023, TestSize.Level3)
915 {
916 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest023 start";
917 auto pixelMap1 = ConstructPixmap(PixelFormat::ALPHA_8, AlphaType::IMAGE_ALPHA_TYPE_PREMUL);
918 EXPECT_TRUE(pixelMap1 != nullptr);
919 auto ret = pixelMap1->SetAlpha(0.f);
920 EXPECT_TRUE(ret != SUCCESS);
921 ret = pixelMap1->SetAlpha(2.f);
922 EXPECT_TRUE(ret != SUCCESS);
923 ret = pixelMap1->SetAlpha(0.1f);
924 EXPECT_TRUE(ret == SUCCESS);
925
926 auto pixelMap2 = ConstructPixmap(PixelFormat::ARGB_8888, AlphaType::IMAGE_ALPHA_TYPE_PREMUL);
927 ret = pixelMap2->SetAlpha(0.1f);
928 EXPECT_TRUE(ret == SUCCESS);
929
930 auto pixelMap3 = ConstructPixmap(PixelFormat::RGBA_8888, AlphaType::IMAGE_ALPHA_TYPE_PREMUL);
931 ret = pixelMap3->SetAlpha(0.1f);
932 EXPECT_TRUE(ret == SUCCESS);
933
934 auto pixelMap4 = ConstructPixmap(PixelFormat::BGRA_8888, AlphaType::IMAGE_ALPHA_TYPE_PREMUL);
935 ret = pixelMap4->SetAlpha(0.1f);
936 EXPECT_TRUE(ret == SUCCESS);
937
938 auto pixelMap5 = ConstructPixmap(PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_PREMUL);
939 ret = pixelMap5->SetAlpha(0.1f);
940 EXPECT_TRUE(ret == SUCCESS);
941
942 auto pixelMap6 = ConstructPixmap(PixelFormat::CMYK, AlphaType::IMAGE_ALPHA_TYPE_PREMUL);
943 ret = pixelMap6->SetAlpha(0.1f);
944 EXPECT_TRUE(ret != SUCCESS);
945
946 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest023 end";
947 }
948
949 /**
950 * @tc.name: PixelMapTest024
951 * @tc.desc: Test of ReleaseSharedMemory
952 * @tc.type: FUNC
953 */
954 HWTEST_F(PixelMapTest, PixelMapTest024, TestSize.Level3)
955 {
956 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest024 start";
957 std::unique_ptr<PixelMap> pixelMap = std::make_unique<PixelMap>();
958 ImageInfo imageInfo;
959 imageInfo.size.width = 200;
960 imageInfo.size.height = 300;
961 imageInfo.pixelFormat = PixelFormat::ARGB_8888;
962 imageInfo.colorSpace = ColorSpace::SRGB;
963 pixelMap->SetImageInfo(imageInfo);
964 int32_t rowDataSize = 200;
965 uint32_t bufferSize = rowDataSize * 300;
966 void *buffer = malloc(bufferSize);
967 char *ch = static_cast<char *>(buffer);
968 for (unsigned int i = 0; i < bufferSize; i++) {
969 *(ch++) = (char)i;
970 }
971 int32_t contextSize = 10;
972 void *context = malloc(contextSize);
973 EXPECT_TRUE(context != nullptr);
974 char *contextChar = static_cast<char *>(context);
975 for (unsigned int i = 0; i < contextSize; i++) {
976 *(contextChar++) = (char)i;
977 }
978 pixelMap->SetPixelsAddr(buffer, context, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
979 EXPECT_TRUE(pixelMap != nullptr);
980 pixelMap = nullptr;
981
982 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest024 end";
983 }
984
985 /**
986 * @tc.name: PixelMapTest025
987 * @tc.desc: Test of Create
988 * @tc.type: FUNC
989 */
990 HWTEST_F(PixelMapTest, PixelMapTest025, TestSize.Level3)
991 {
992 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest025 start";
993 const uint32_t color[8] = { 0x80, 0x02, 0x04, 0x08, 0x40, 0x02, 0x04, 0x08 };
994 uint32_t colorlength = sizeof(color) / sizeof(color[0]);
995 EXPECT_TRUE(colorlength == 8);
996 const int32_t offset = -1;
997 InitializationOptions opts;
998 opts.size.width = 3;
999 opts.size.height = 2;
1000 opts.pixelFormat = PixelFormat::ARGB_8888;
1001 opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
1002 int32_t width = opts.size.width;
1003 std::unique_ptr<PixelMap> pixelMap1 = PixelMap::Create(color, colorlength, offset, 1, opts);
1004 EXPECT_EQ(pixelMap1, nullptr);
1005
1006 std::unique_ptr<PixelMap> pixelMap2 = PixelMap::Create(color, colorlength, offset, INT32_MAX, opts);
1007 EXPECT_EQ(pixelMap2, nullptr);
1008
1009 std::unique_ptr<PixelMap> pixelMap3= PixelMap::Create(color, colorlength, offset, width, opts);
1010 EXPECT_EQ(pixelMap3, nullptr);
1011
1012 std::unique_ptr<PixelMap> pixelMap4= PixelMap::Create(color, colorlength, 0, width, opts);
1013 EXPECT_TRUE(pixelMap4 != nullptr);
1014
1015 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest025 end";
1016 }
1017
1018 /**
1019 * @tc.name: PixelMapTest026
1020 * @tc.desc: Test of Create rect is abnormal
1021 * @tc.type: FUNC
1022 */
1023 HWTEST_F(PixelMapTest, PixelMapTest026, TestSize.Level3)
1024 {
1025 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest026 start";
1026 PixelMap srcPixelMap;
1027 ImageInfo imageInfo;
1028 imageInfo.size.width = 200;
1029 imageInfo.size.height = 300;
1030 imageInfo.pixelFormat = PixelFormat::ARGB_8888;
1031 imageInfo.colorSpace = ColorSpace::SRGB;
1032 srcPixelMap.SetImageInfo(imageInfo);
1033 int32_t rowDataSize = 200;
1034 uint32_t bufferSize = rowDataSize * 300;
1035 void *buffer = malloc(bufferSize);
1036 char *ch = static_cast<char *>(buffer);
1037 for (unsigned int i = 0; i < bufferSize; i++) {
1038 *(ch++) = (char)i;
1039 }
1040 srcPixelMap.SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
1041
1042 Rect rect;
1043 rect.left = -100;
1044 rect.top = 0;
1045 rect.height = 1;
1046 rect.width = 1;
1047 InitializationOptions opts;
1048 opts.size.width = 200;
1049 opts.size.height = 300;
1050 opts.pixelFormat = PixelFormat::ARGB_8888;
1051 opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
1052 opts.useSourceIfMatch = true;
1053 opts.editable = true;
1054 opts.scaleMode = ScaleMode::CENTER_CROP;
1055 std::unique_ptr<PixelMap> pixelMap1 = PixelMap::Create(srcPixelMap, rect, opts);
1056 EXPECT_TRUE(pixelMap1 == nullptr);
1057
1058 Rect rect2;
1059 rect2.left = 0;
1060 rect2.top = 0;
1061 rect2.height = 100;
1062 rect2.width = 100;
1063 std::unique_ptr<PixelMap> pixelMap2 = PixelMap::Create(srcPixelMap, rect2, opts);
1064 EXPECT_TRUE(pixelMap2 == nullptr);
1065
1066 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest026 end";
1067 }
1068
1069 /**
1070 * @tc.name: PixelMapTest027
1071 * @tc.desc: Test of Create useSourceIfMatch is true
1072 * @tc.type: FUNC
1073 */
1074 HWTEST_F(PixelMapTest, PixelMapTest027, TestSize.Level3)
1075 {
1076 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest027 start";
1077 PixelMap srcPixelMap;
1078 ImageInfo imageInfo;
1079 imageInfo.size.width = 200;
1080 imageInfo.size.height = 300;
1081 imageInfo.pixelFormat = PixelFormat::ARGB_8888;
1082 imageInfo.colorSpace = ColorSpace::SRGB;
1083 srcPixelMap.SetImageInfo(imageInfo);
1084 int32_t rowDataSize = 200;
1085 uint32_t bufferSize = rowDataSize * 300;
1086 void *buffer = malloc(bufferSize);
1087 char *ch = static_cast<char *>(buffer);
1088 for (unsigned int i = 0; i < bufferSize; i++) {
1089 *(ch++) = (char)i;
1090 }
1091 srcPixelMap.SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
1092
1093 Rect rect;
1094 rect.left = 0;
1095 rect.top = 0;
1096 rect.height = 100;
1097 rect.width = 100;
1098 InitializationOptions opts;
1099 opts.size.width = 0;
1100 opts.size.height = 300;
1101 opts.pixelFormat = PixelFormat::UNKNOWN;
1102 opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
1103 opts.useSourceIfMatch = true;
1104 opts.editable = true;
1105 opts.scaleMode = ScaleMode::CENTER_CROP;
1106 std::unique_ptr<PixelMap> pixelMap1 = PixelMap::Create(srcPixelMap, rect, opts);
1107 EXPECT_TRUE(pixelMap1 == nullptr);
1108
1109 InitializationOptions opts2;
1110 opts2.size.width = 0;
1111 opts2.size.height = 0;
1112 opts2.pixelFormat = PixelFormat::UNKNOWN;
1113 opts2.alphaType = AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
1114 opts2.useSourceIfMatch = true;
1115 opts2.editable = true;
1116 opts2.scaleMode = ScaleMode::CENTER_CROP;
1117 std::unique_ptr<PixelMap> pixelMap2 = PixelMap::Create(srcPixelMap, rect, opts2);
1118 EXPECT_TRUE(pixelMap2 == nullptr);
1119
1120 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest027 end";
1121 }
1122
1123 /**
1124 * @tc.name: PixelMapTest028
1125 * @tc.desc: Test of GetPixel8, GetPixel16, GetPixel32
1126 * @tc.type: FUNC
1127 */
1128 HWTEST_F(PixelMapTest, PixelMapTest028, TestSize.Level3)
1129 {
1130 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest028 start";
1131 auto pixelMap1 = ConstructPixmap(200, 300, PixelFormat::ALPHA_8, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
1132 AllocatorType::HEAP_ALLOC);
1133 EXPECT_TRUE(pixelMap1 != nullptr);
1134 auto ret1 = pixelMap1->GetPixel8(100, 200);
1135 EXPECT_TRUE(ret1 != nullptr);
1136
1137 auto pixelMap2 = ConstructPixmap(200, 300, PixelFormat::RGB_565, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
1138 AllocatorType::HEAP_ALLOC);
1139 EXPECT_TRUE(pixelMap2 != nullptr);
1140 auto ret2 = pixelMap2->GetPixel16(100, 200);
1141 EXPECT_TRUE(ret2 != nullptr);
1142
1143 auto pixelMap3 = ConstructPixmap(200, 300, PixelFormat::RGBA_8888, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
1144 AllocatorType::HEAP_ALLOC);
1145 EXPECT_TRUE(pixelMap3 != nullptr);
1146 auto ret3 = pixelMap3->GetPixel32(100, 200);
1147 EXPECT_TRUE(ret3 == nullptr);
1148
1149 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest028 end";
1150 }
1151
1152 /**
1153 * @tc.name: PixelMapTest029
1154 * @tc.desc: Test of IsSameImage
1155 * @tc.type: FUNC
1156 */
1157 HWTEST_F(PixelMapTest, PixelMapTest029, TestSize.Level3)
1158 {
1159 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest029 start";
1160 std::unique_ptr<PixelMap> pixelMap = std::make_unique<PixelMap>();
1161
1162 auto pixelMap1 = ConstructPixmap(200, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
1163 AllocatorType::HEAP_ALLOC);
1164 EXPECT_TRUE(pixelMap1 != nullptr);
1165 auto ret = pixelMap1->IsSameImage(*pixelMap);
1166 EXPECT_FALSE(ret);
1167
1168 auto pixelMap2 = ConstructPixmap(500, 600, PixelFormat::RGB_888, AlphaType::IMAGE_ALPHA_TYPE_PREMUL,
1169 AllocatorType::HEAP_ALLOC);
1170 EXPECT_TRUE(pixelMap2 != nullptr);
1171 ret = pixelMap1->IsSameImage(*pixelMap2);
1172 EXPECT_FALSE(ret);
1173
1174 auto pixelMap3 = ConstructPixmap(200, 300, PixelFormat::RGBA_F16, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE,
1175 AllocatorType::HEAP_ALLOC);
1176 EXPECT_TRUE(pixelMap3 != nullptr);
1177 ret = pixelMap1->IsSameImage(*pixelMap3);
1178 EXPECT_FALSE(ret);
1179
1180 GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTest029 end";
1181 }
1182
1183 #ifdef IMAGE_COLORSPACE_FLAG
1184 /**
1185 * @tc.name: ImagePixelMap030
1186 * @tc.desc: test InnerSetColorSpace
1187 * @tc.type: FUNC
1188 * @tc.require: AR000FTAMO
1189 */
1190 HWTEST_F(PixelMapTest, PixelMapTest030, TestSize.Level3)
1191 {
1192 GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap039 InnerSetColorSpace start";
1193 PixelMap pixelMap;
1194 ImageInfo info;
1195 info.size.width = 3;
1196 info.size.height = 3;
1197 info.pixelFormat = PixelFormat::ALPHA_8;
1198 info.colorSpace = ColorSpace::SRGB;
1199 pixelMap.SetImageInfo(info);
1200 OHOS::ColorManager::ColorSpace grColorSpace =
1201 OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::SRGB);
1202 pixelMap.InnerSetColorSpace(grColorSpace);
1203 OHOS::ColorManager::ColorSpace outColorSpace = pixelMap.InnerGetGrColorSpace();
1204 pixelMap.InnerSetColorSpace(outColorSpace);
1205 ASSERT_NE(&outColorSpace, nullptr);
1206 GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap039 InnerSetColorSpace end";
1207 }
1208
1209 /**
1210 * @tc.name: InnerGetGrColorSpacePtrTest
1211 * @tc.desc: test InnerGetGrColorSpacePtr
1212 * @tc.type: FUNC
1213 * @tc.require: AR000FTAMO
1214 */
1215 HWTEST_F(PixelMapTest, InnerGetGrColorSpacePtrTest, TestSize.Level3)
1216 {
1217 GTEST_LOG_(INFO) << "ImagePixelMapTest: InnerGetGrColorSpacePtrTest InnerSetColorSpace start";
1218 PixelMap pixelMap;
1219 ImageInfo info;
1220 info.size.width = 3;
1221 info.size.height = 3;
1222 info.pixelFormat = PixelFormat::ALPHA_8;
1223 info.colorSpace = ColorSpace::SRGB;
1224 pixelMap.SetImageInfo(info);
1225 OHOS::ColorManager::ColorSpace grColorSpace =
1226 OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::SRGB);
1227 pixelMap.InnerSetColorSpace(grColorSpace);
1228 std::shared_ptr<OHOS::ColorManager::ColorSpace> outColorSpace = pixelMap.InnerGetGrColorSpacePtr();
1229 ASSERT_NE(outColorSpace, nullptr);
1230 GTEST_LOG_(INFO) << "ImagePixelMapTest: InnerGetGrColorSpacePtrTest InnerSetColorSpace end";
1231 }
1232 #endif
1233
1234 #ifdef IMAGE_PURGEABLE_PIXELMAP
1235 /**
1236 * @tc.name: IsPurgeable
1237 * @tc.desc: test IsPurgeable
1238 * @tc.type: FUNC
1239 */
1240 HWTEST_F(PixelMapTest, IsPurgeableTest, TestSize.Level3)
1241 {
1242 GTEST_LOG_(INFO) << "ImagePixelMapTest: IsPurgeableTest IsPurgeable start";
1243 PixelMap pixelMap;
1244 ImageInfo info;
1245 info.size.width = 3;
1246 info.size.height = 3;
1247 info.pixelFormat = PixelFormat::ALPHA_8;
1248 info.colorSpace = ColorSpace::SRGB;
1249 pixelMap.SetImageInfo(info);
1250 bool res = pixelMap.IsPurgeable();
1251 ASSERT_EQ(res, false);
1252 GTEST_LOG_(INFO) << "ImagePixelMapTest: IsPurgeableTest IsPurgeable end";
1253 }
1254
1255 /**
1256 * @tc.name: GetPurgeableMemPtr
1257 * @tc.desc: test GetPurgeableMemPtr
1258 * @tc.type: FUNC
1259 */
1260 HWTEST_F(PixelMapTest, GetPurgeableMemPtrTest, TestSize.Level3)
1261 {
1262 GTEST_LOG_(INFO) << "ImagePixelMapTest: GetPurgeableMemPtrTest GetPurgeableMemPtr start";
1263 PixelMap pixelMap;
1264 ImageInfo info;
1265 info.size.width = 3;
1266 info.size.height = 3;
1267 info.pixelFormat = PixelFormat::ALPHA_8;
1268 info.colorSpace = ColorSpace::SRGB;
1269 pixelMap.SetImageInfo(info);
1270 std::shared_ptr<PurgeableMem::PurgeableMemBase> res = pixelMap.GetPurgeableMemPtr();
1271 ASSERT_EQ(res, nullptr);
1272 GTEST_LOG_(INFO) << "ImagePixelMapTest: GetPurgeableMemPtrTest GetPurgeableMemPtr end";
1273 }
1274
1275 /**
1276 * @tc.name: SetPurgeableMemPtr
1277 * @tc.desc: test SetPurgeableMemPtr
1278 * @tc.type: FUNC
1279 */
1280 HWTEST_F(PixelMapTest, SetPurgeableMemPtrTest, TestSize.Level3)
1281 {
1282 GTEST_LOG_(INFO) << "ImagePixelMapTest: SetPurgeableMemPtrTest SetPurgeableMemPtr start";
1283 PixelMap pixelMap;
1284 ImageInfo info;
1285 info.size.width = 3;
1286 info.size.height = 3;
1287 info.pixelFormat = PixelFormat::ALPHA_8;
1288 info.colorSpace = ColorSpace::SRGB;
1289 pixelMap.SetImageInfo(info);
1290 std::shared_ptr<PurgeableMem::PurgeableMemBase> res = pixelMap.GetPurgeableMemPtr();
1291 ASSERT_EQ(res, nullptr);
1292 pixelMap.SetPurgeableMemPtr(res);
1293 std::shared_ptr<PurgeableMem::PurgeableMemBase> ptr = pixelMap.GetPurgeableMemPtr();
1294 ASSERT_EQ(ptr, nullptr);
1295 GTEST_LOG_(INFO) << "ImagePixelMapTest: SetPurgeableMemPtrTest SetPurgeableMemPtr end";
1296 }
1297 #endif
1298 }
1299 }