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 #include "image_source.h"
18 #include "media_errors.h"
19 #include "pixel_map.h"
20 #include "color_space.h"
21 
22 using namespace testing::ext;
23 using namespace OHOS::Media;
24 
25 namespace OHOS {
26 namespace Multimedia {
27 static constexpr int32_t PIXEL_MAP_TEST_WIDTH = 3;
28 static constexpr int32_t PIXEL_MAP_TEST_HEIGHT = 3;
29 static constexpr int32_t PIXEL_MAP_RGB565_BYTE = 2;
30 static constexpr int32_t PIXEL_MAP_RGB888_BYTE = 3;
31 static constexpr int32_t PIXEL_MAP_ARGB8888_BYTE = 4;
32 constexpr int32_t PIXEL_MAP_BIG_TEST_WIDTH = 4 * 1024;
33 constexpr int32_t PIXEL_MAP_BIG_TEST_HEIGHT = 3 * 100;
34 
35 class ImagePixelMapTest : public testing::Test {
36 public:
ImagePixelMapTest()37     ImagePixelMapTest() {}
~ImagePixelMapTest()38     ~ImagePixelMapTest() {}
39 };
40 
ConstructPixmap()41     std::unique_ptr<PixelMap> ConstructPixmap()
42     {
43         int32_t pixelMapWidth = 4;
44         int32_t pixelMapHeight = 3;
45         int32_t bytesPerPixel = 3;
46         std::unique_ptr<PixelMap> pixelMap = std::make_unique<PixelMap>();
47         ImageInfo info;
48         info.size.width = pixelMapWidth;
49         info.size.height = pixelMapHeight;
50         info.pixelFormat = PixelFormat::RGB_888;
51         info.colorSpace = ColorSpace::SRGB;
52         pixelMap->SetImageInfo(info);
53 
54         int32_t rowDataSize = pixelMapWidth * bytesPerPixel;
55         uint32_t bufferSize = rowDataSize * pixelMapHeight;
56         if (bufferSize <= 0) {
57             return nullptr;
58         }
59         void *buffer = malloc(bufferSize);
60         if (buffer == nullptr) {
61             return nullptr;
62         }
63         char *ch = static_cast<char *>(buffer);
64         for (unsigned int i = 0; i < bufferSize; i++) {
65             *(ch++) = (char)i;
66         }
67 
68         pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
69         return pixelMap;
70     }
71 
ConstructBigPixmap()72     std::unique_ptr<PixelMap> ConstructBigPixmap()
73     {
74         int32_t pixelMapWidth = PIXEL_MAP_BIG_TEST_WIDTH;
75         int32_t pixelMapHeight = PIXEL_MAP_BIG_TEST_HEIGHT;
76         std::unique_ptr<PixelMap> pixelMap = std::make_unique<PixelMap>();
77         ImageInfo info;
78         info.size.width = pixelMapWidth;
79         info.size.height = pixelMapHeight;
80         info.pixelFormat = PixelFormat::RGB_888;
81         info.colorSpace = ColorSpace::SRGB;
82         pixelMap->SetImageInfo(info);
83 
84         int32_t bufferSize = pixelMap->GetByteCount();
85         if (bufferSize <= 0) {
86             return nullptr;
87         }
88         void *buffer = malloc(bufferSize);
89         if (buffer == nullptr) {
90             return nullptr;
91         }
92         char *ch = reinterpret_cast<char *>(buffer);
93         for (int32_t i = 0; i < bufferSize; i++) {
94             *(ch++) = 'a';
95         }
96 
97         pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
98         return pixelMap;
99     }
100 
ConstructPixelMap(uint32_t ** dataIn)101     std::unique_ptr<PixelMap> ConstructPixelMap(uint32_t** dataIn)
102     {
103         const uint32_t dataLength = PIXEL_MAP_TEST_WIDTH * PIXEL_MAP_TEST_HEIGHT;
104         uint32_t* data = new uint32_t[dataLength];
105         for (uint32_t i = 0; i < dataLength; i++) {
106             data[i] = 0xFFFF0000;
107         }
108         InitializationOptions opts;
109         opts.pixelFormat = OHOS::Media::PixelFormat::ARGB_8888;
110         opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
111         opts.size.width = PIXEL_MAP_TEST_WIDTH;
112         opts.size.height = PIXEL_MAP_TEST_HEIGHT;
113         std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
114         *dataIn = data;
115         return pixelMap;
116     }
117 
118 /**
119  * @tc.name: ImagePixelMap001
120  * @tc.desc: ALPHA_8 pixel format pixel map operation
121  * @tc.type: FUNC
122  */
123 HWTEST_F(ImagePixelMapTest, ImagePixelMap001, TestSize.Level3)
124 {
125     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap001 start";
126     /**
127      * @tc.steps: step1. Set image info and alloc pixel map memory.
128      * @tc.expected: step1. The pixel map info is correct.
129      */
130     PixelMap pixelMap;
131     ImageInfo info;
132     info.size.width = PIXEL_MAP_TEST_WIDTH;
133     info.size.height = PIXEL_MAP_TEST_HEIGHT;
134     info.pixelFormat = PixelFormat::ALPHA_8;
135     info.colorSpace = ColorSpace::SRGB;
136     pixelMap.SetImageInfo(info);
137     int32_t rowDataSize = (PIXEL_MAP_TEST_WIDTH + 3) / 4 * 4;
138     uint32_t bufferSize = rowDataSize * PIXEL_MAP_TEST_HEIGHT;
139     void *buffer = malloc(bufferSize);
140     EXPECT_NE(buffer, nullptr);
141     pixelMap.SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
142     uint8_t *data = const_cast<uint8_t *>(pixelMap.GetPixels());
143     EXPECT_NE(data, nullptr);
144     EXPECT_EQ(pixelMap.GetHeight(), PIXEL_MAP_TEST_HEIGHT);
145     EXPECT_EQ(pixelMap.GetWidth(), PIXEL_MAP_TEST_WIDTH);
146     EXPECT_EQ(pixelMap.GetPixelFormat(), PixelFormat::ALPHA_8);
147     EXPECT_EQ(pixelMap.GetColorSpace(), ColorSpace::SRGB);
148     EXPECT_EQ(pixelMap.GetPixelBytes(), 1);
149     EXPECT_EQ(pixelMap.GetRowBytes(), rowDataSize);
150     EXPECT_EQ(pixelMap.GetByteCount(), PIXEL_MAP_TEST_HEIGHT * rowDataSize);
151     /**
152      * @tc.steps: step2. Get image info.
153      * @tc.expected: step2. The pixel map info is correct
154      */
155     ImageInfo outInfo;
156     pixelMap.GetImageInfo(outInfo);
157     EXPECT_EQ(outInfo.size.width, info.size.width);
158     EXPECT_EQ(outInfo.size.height, info.size.height);
159     EXPECT_EQ(outInfo.pixelFormat, info.pixelFormat);
160     EXPECT_EQ(outInfo.colorSpace, info.colorSpace);
161     /**
162      * @tc.steps: step3. Set image color data and get image color value.
163      * @tc.expected: step3. The image color value is correct
164      */
165     for (int32_t i = 0; i < rowDataSize * PIXEL_MAP_TEST_HEIGHT; i++) {
166         data[i] = i;
167     }
168     uint32_t color = 0;
169     EXPECT_NE(pixelMap.GetPixel8(1, 1), nullptr);
170     EXPECT_EQ(*pixelMap.GetPixel8(1, 1), 0x05);
171     EXPECT_EQ(pixelMap.GetARGB32Color(1, 1, color), true);
172     EXPECT_EQ(pixelMap.GetARGB32ColorA(color), 5);
173     EXPECT_EQ(pixelMap.GetARGB32ColorR(color), 0);
174     EXPECT_EQ(pixelMap.GetARGB32ColorG(color), 0);
175     EXPECT_EQ(pixelMap.GetARGB32ColorB(color), 0);
176     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap001 end";
177 }
178 
179 /**
180  * @tc.name: ImagePixelMap002
181  * @tc.desc: RGB_565 pixel format pixel map operation
182  * @tc.type: FUNC
183  */
184 HWTEST_F(ImagePixelMapTest, ImagePixelMap002, TestSize.Level3)
185 {
186     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap002 start";
187     /**
188      * @tc.steps: step1. Set image info and alloc pixel map memory.
189      * @tc.expected: step1. The pixel map info is correct.
190      */
191     PixelMap pixelMap;
192     int8_t bytesPerPixel = 2;
193     int8_t rowDataSize = PIXEL_MAP_TEST_WIDTH * bytesPerPixel;
194     ImageInfo info;
195     info.size.width = PIXEL_MAP_TEST_WIDTH;
196     info.size.height = PIXEL_MAP_TEST_HEIGHT;
197     info.pixelFormat = PixelFormat::RGB_565;
198     info.colorSpace = ColorSpace::SRGB;
199     pixelMap.SetImageInfo(info);
200     uint32_t bufferSize = rowDataSize * PIXEL_MAP_TEST_HEIGHT;
201     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap002 start" << bufferSize;
202     void *buffer = malloc(bufferSize);
203     EXPECT_NE(buffer, nullptr);
204     pixelMap.SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
205     uint8_t *data = const_cast<uint8_t *>(pixelMap.GetPixels());
206     EXPECT_NE(data, nullptr);
207     EXPECT_EQ(pixelMap.GetHeight(), PIXEL_MAP_TEST_HEIGHT);
208     EXPECT_EQ(pixelMap.GetWidth(), PIXEL_MAP_TEST_WIDTH);
209     EXPECT_EQ(pixelMap.GetPixelFormat(), PixelFormat::RGB_565);
210     EXPECT_EQ(pixelMap.GetColorSpace(), ColorSpace::SRGB);
211     EXPECT_EQ(pixelMap.GetPixelBytes(), bytesPerPixel);
212     EXPECT_EQ(pixelMap.GetRowBytes(), rowDataSize);
213     EXPECT_EQ(pixelMap.GetByteCount(), PIXEL_MAP_TEST_HEIGHT * rowDataSize);
214     /**
215      * @tc.steps: step2. Set image color data and get image color value.
216      * @tc.expected: step2. The image color value is correct
217      */
218     for (int32_t i = 0; i < PIXEL_MAP_TEST_WIDTH * PIXEL_MAP_RGB565_BYTE * PIXEL_MAP_TEST_HEIGHT; i++) {
219         data[i] = i;
220     }
221     EXPECT_NE(pixelMap.GetPixel16(1, 1), nullptr);
222     EXPECT_EQ(*pixelMap.GetPixel16(1, 1), 0x0908);
223     uint32_t color = 0;
224     uint32_t expect = 0xFF422008;
225     EXPECT_EQ(pixelMap.GetARGB32Color(1, 1, color), true);
226     EXPECT_EQ(color, expect);
227     // RGB565: binary: 0000100100001000
228     // split to :         00001       001000          01000
229     //                      |           |                |
230     //                      B           G                R
231     // transfer to RGB888:
232     //                      1           8                8
233     // multi 256(8bit length)
234     //                 256*1/2^5    256*8/2^6       256*8/2^5
235     // another method:
236     //                 (x<<3 | x>>2)  (x<<2 | x>>4)
237     EXPECT_EQ(pixelMap.GetARGB32ColorA(color), 255);
238     EXPECT_EQ(pixelMap.GetARGB32ColorR(color), 66);  // (8<<3 | 8 >> 2)
239     EXPECT_EQ(pixelMap.GetARGB32ColorG(color), 32);  // (8<<2 | 8 >> 4)
240     EXPECT_EQ(pixelMap.GetARGB32ColorB(color), 8);   // (1<<3 | 1 >> 2)
241     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap002 end";
242 }
243 
244 /**
245  * @tc.name: ImagePixelMap003
246  * @tc.desc: ARGB_8888 pixel format pixel map operation
247  * @tc.type: FUNC
248  */
249 HWTEST_F(ImagePixelMapTest, ImagePixelMap003, TestSize.Level3)
250 {
251     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap003 start";
252     /**
253      * @tc.steps: step1. Set image info and alloc pixel map memory.
254      * @tc.expected: step1. The pixel map info is correct.
255      */
256     int8_t bytesPerPixel = 4;
257     int8_t rowDataSize = PIXEL_MAP_TEST_WIDTH * bytesPerPixel;
258     ImageInfo info;
259     info.size.width = PIXEL_MAP_TEST_WIDTH;
260     info.size.height = PIXEL_MAP_TEST_HEIGHT;
261     info.pixelFormat = PixelFormat::ARGB_8888;
262     info.colorSpace = ColorSpace::SRGB;
263     PixelMap pixelMap;
264     pixelMap.SetImageInfo(info);
265     uint32_t bufferSize = rowDataSize * PIXEL_MAP_TEST_HEIGHT;
266     void *buffer = malloc(bufferSize);
267     EXPECT_NE(buffer, nullptr);
268     pixelMap.SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
269     uint8_t *data = const_cast<uint8_t *>(pixelMap.GetPixels());
270     EXPECT_NE(data, nullptr);
271     EXPECT_EQ(pixelMap.GetHeight(), PIXEL_MAP_TEST_HEIGHT);
272     EXPECT_EQ(pixelMap.GetWidth(), PIXEL_MAP_TEST_WIDTH);
273     EXPECT_EQ(pixelMap.GetPixelFormat(), PixelFormat::ARGB_8888);
274     EXPECT_EQ(pixelMap.GetColorSpace(), ColorSpace::SRGB);
275     EXPECT_EQ(pixelMap.GetPixelBytes(), bytesPerPixel);
276     EXPECT_EQ(pixelMap.GetRowBytes(), rowDataSize);
277     EXPECT_EQ(pixelMap.GetByteCount(), PIXEL_MAP_TEST_HEIGHT * rowDataSize);
278     /**
279      * @tc.steps: step2. Set image color data and get image color value.
280      * @tc.expected: step2. The image color value is correct
281      */
282     for (int32_t i = 0; i < PIXEL_MAP_TEST_WIDTH * PIXEL_MAP_ARGB8888_BYTE * PIXEL_MAP_TEST_HEIGHT; i++) {
283         data[i] = i;
284     }
285     EXPECT_NE(pixelMap.GetPixel(1, 1), nullptr);
286     EXPECT_EQ(*pixelMap.GetPixel32(1, 1), static_cast<uint32_t>(0x13121110));
287     uint32_t color = 0;
288     EXPECT_EQ(pixelMap.GetARGB32Color(1, 1, color), true);
289     EXPECT_EQ(pixelMap.GetARGB32ColorA(color), 0x10);
290     EXPECT_EQ(pixelMap.GetARGB32ColorR(color), 0x11);
291     EXPECT_EQ(pixelMap.GetARGB32ColorG(color), 0x12);
292     EXPECT_EQ(pixelMap.GetARGB32ColorB(color), 0x13);
293     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap003 end";
294 }
295 
296 /**
297  * @tc.name: ImagePixelMap004
298  * @tc.desc: Get pixel position out of image range
299  * @tc.type: FUNC
300  */
301 HWTEST_F(ImagePixelMapTest, ImagePixelMap004, TestSize.Level3)
302 {
303     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap004 start";
304     /**
305      * @tc.steps: step1. Set image info and alloc pixel map memory.
306      * @tc.expected: step1. The pixel map info is correct.
307      */
308     PixelMap pixelMap;
309     int8_t bytesPerPixel = 4;
310     int8_t rowDataSize = PIXEL_MAP_TEST_WIDTH * bytesPerPixel;
311     ImageInfo info;
312     info.size.width = PIXEL_MAP_TEST_WIDTH;
313     info.size.height = PIXEL_MAP_TEST_HEIGHT;
314     info.pixelFormat = PixelFormat::ARGB_8888;
315     info.colorSpace = ColorSpace::SRGB;
316     pixelMap.SetImageInfo(info);
317     uint32_t bufferSize = rowDataSize * PIXEL_MAP_TEST_HEIGHT;
318     void *buffer = malloc(bufferSize);
319     EXPECT_NE(buffer, nullptr);
320     pixelMap.SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
321     uint8_t *data = const_cast<uint8_t *>(pixelMap.GetPixels());
322     EXPECT_NE(data, nullptr);
323     EXPECT_EQ(pixelMap.GetHeight(), PIXEL_MAP_TEST_HEIGHT);
324     EXPECT_EQ(pixelMap.GetWidth(), PIXEL_MAP_TEST_WIDTH);
325     EXPECT_EQ(pixelMap.GetPixelFormat(), PixelFormat::ARGB_8888);
326     EXPECT_EQ(pixelMap.GetColorSpace(), ColorSpace::SRGB);
327     EXPECT_EQ(pixelMap.GetByteCount(), PIXEL_MAP_TEST_HEIGHT * rowDataSize);
328     /**
329      * @tc.steps: step2. Set image color data and get image color value.
330      * @tc.expected: step2. Get image color value failed, because of position out of image range.
331      */
332     for (int32_t i = 0; i < PIXEL_MAP_TEST_WIDTH * PIXEL_MAP_ARGB8888_BYTE * PIXEL_MAP_TEST_HEIGHT; i++) {
333         data[i] = i;
334     }
335     EXPECT_EQ(pixelMap.GetPixel32(4, 4), nullptr);
336     EXPECT_EQ(pixelMap.GetPixel(-1, -1), nullptr);
337     uint32_t color = 0;
338     EXPECT_EQ(pixelMap.GetARGB32Color(4, 4, color), false);
339     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap004 end";
340 }
341 
342 /**
343  * @tc.name: ImagePixelMap005
344  * @tc.desc: Set error image size
345  * @tc.type: FUNC
346  */
347 HWTEST_F(ImagePixelMapTest, ImagePixelMap005, TestSize.Level3)
348 {
349     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap005 start";
350     /**
351      * @tc.steps: step1. Set image error info include image height and width.
352      * @tc.expected: step1. The pixel map info is default value.
353      */
354     PixelMap pixelMap;
355     ImageInfo info;
356     info.size.width = -10;
357     info.size.height = 10;
358     EXPECT_EQ(pixelMap.SetImageInfo(info), ERR_IMAGE_DATA_ABNORMAL);
359     EXPECT_EQ(pixelMap.GetHeight(), 0);
360     EXPECT_EQ(pixelMap.GetWidth(), 0);
361     EXPECT_EQ(pixelMap.GetPixelFormat(), PixelFormat::UNKNOWN);
362     EXPECT_EQ(pixelMap.GetColorSpace(), ColorSpace::SRGB);
363     EXPECT_EQ(pixelMap.GetByteCount(), 0);
364     uint8_t *data = const_cast<uint8_t *>(pixelMap.GetPixels());
365     EXPECT_EQ(data, nullptr);
366     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap005 end";
367 }
368 
369 /**
370  * @tc.name: ImagePixelMap006
371  * @tc.desc: Set unknown pixel format and color space
372  * @tc.type: FUNC
373  */
374 HWTEST_F(ImagePixelMapTest, ImagePixelMap006, TestSize.Level3)
375 {
376     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap006 start";
377     /**
378      * @tc.steps: step1. Set image unknown pixel format and color space info.
379      * @tc.expected: step1. The pixel map info is default value.
380      */
381     PixelMap pixelMap;
382     ImageInfo info;
383     info.size.width = 10;
384     info.size.height = 10;
385     EXPECT_EQ(pixelMap.SetImageInfo(info), ERR_IMAGE_DATA_UNSUPPORT);
386     EXPECT_EQ(pixelMap.GetHeight(), 0);
387     EXPECT_EQ(pixelMap.GetWidth(), 0);
388     EXPECT_EQ(pixelMap.GetPixelFormat(), PixelFormat::UNKNOWN);
389     EXPECT_EQ(pixelMap.GetColorSpace(), ColorSpace::SRGB);
390     EXPECT_EQ(pixelMap.GetByteCount(), 0);
391     uint8_t *data = const_cast<uint8_t *>(pixelMap.GetPixels());
392     EXPECT_EQ(data, nullptr);
393     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap006 end";
394 }
395 
396 /**
397  * @tc.name: ImagePixelMap007
398  * @tc.desc: Set pixel map size out of max value
399  * @tc.type: FUNC
400  */
401 HWTEST_F(ImagePixelMapTest, ImagePixelMap007, TestSize.Level3)
402 {
403     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap007 start";
404     /**
405      * @tc.steps: step1. Set image size out of max value (500MB).
406      * @tc.expected: step1. The pixel map info is default value.
407      */
408     PixelMap pixelMap;
409     ImageInfo info;
410     info.size.width = 500 * 1024;
411     info.size.height = 500 * 1024;
412     info.pixelFormat = PixelFormat::ARGB_8888;
413     info.colorSpace = ColorSpace::SRGB;
414     EXPECT_EQ(pixelMap.SetImageInfo(info), ERR_IMAGE_TOO_LARGE);
415     EXPECT_EQ(pixelMap.GetHeight(), 0);
416     EXPECT_EQ(pixelMap.GetWidth(), 0);
417     EXPECT_EQ(pixelMap.GetByteCount(), 0);
418     uint8_t *data = const_cast<uint8_t *>(pixelMap.GetPixels());
419     EXPECT_EQ(data, nullptr);
420     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap007 end";
421 }
422 
423 /**
424  * @tc.name: ImagePixelMap008
425  * @tc.desc: RGB_888 pixel format pixel map operation
426  * @tc.type: FUNC
427  */
428 HWTEST_F(ImagePixelMapTest, ImagePixelMap008, TestSize.Level3)
429 {
430     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap008 start";
431     /**
432      * @tc.steps: step1. Set image info and alloc pixel map memory.
433      * @tc.expected: step1. The pixel map info is correct.
434      */
435     int8_t bytesPerPixel = 3;
436     int8_t rowDataSize = PIXEL_MAP_TEST_WIDTH * bytesPerPixel;
437     ImageInfo info;
438     info.size.width = PIXEL_MAP_TEST_WIDTH;
439     info.size.height = PIXEL_MAP_TEST_HEIGHT;
440     info.pixelFormat = PixelFormat::RGB_888;
441     info.colorSpace = ColorSpace::SRGB;
442     PixelMap pixelMap;
443     pixelMap.SetImageInfo(info);
444     uint32_t bufferSize = rowDataSize * PIXEL_MAP_TEST_HEIGHT;
445     void *buffer = malloc(bufferSize);
446     EXPECT_NE(buffer, nullptr);
447     pixelMap.SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
448     uint8_t *data = const_cast<uint8_t *>(pixelMap.GetPixels());
449     EXPECT_NE(data, nullptr);
450     EXPECT_EQ(pixelMap.GetHeight(), PIXEL_MAP_TEST_HEIGHT);
451     EXPECT_EQ(pixelMap.GetWidth(), PIXEL_MAP_TEST_WIDTH);
452     EXPECT_EQ(pixelMap.GetPixelFormat(), PixelFormat::RGB_888);
453     EXPECT_EQ(pixelMap.GetColorSpace(), ColorSpace::SRGB);
454     EXPECT_EQ(pixelMap.GetPixelBytes(), bytesPerPixel);
455     EXPECT_EQ(pixelMap.GetRowBytes(), rowDataSize);
456     EXPECT_EQ(pixelMap.GetByteCount(), PIXEL_MAP_TEST_HEIGHT * rowDataSize);
457     /**
458      * @tc.steps: step2. Set image color data and get image color value.
459      * @tc.expected: step2. The image color value is correct
460      */
461     for (int32_t i = 0; i < PIXEL_MAP_TEST_WIDTH * PIXEL_MAP_RGB888_BYTE * PIXEL_MAP_TEST_HEIGHT; i++) {
462         data[i] = i;
463     }
464     EXPECT_NE(pixelMap.GetPixel(1, 1), nullptr);
465     uint32_t color = 0;
466     EXPECT_EQ(pixelMap.GetARGB32Color(1, 1, color), true);
467     EXPECT_EQ(pixelMap.GetARGB32ColorA(color), 255);
468     EXPECT_EQ(pixelMap.GetARGB32ColorR(color), 12);
469     EXPECT_EQ(pixelMap.GetARGB32ColorG(color), 13);
470     EXPECT_EQ(pixelMap.GetARGB32ColorB(color), 14);
471     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap008 end";
472 }
473 
474 /**
475  * @tc.name: ImagePixelMap009
476  * @tc.desc: create pixelmap with wrong source and correct initialization options
477  * @tc.type: FUNC
478  */
479 HWTEST_F(ImagePixelMapTest, ImagePixelMap009, TestSize.Level3)
480 {
481     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap009 start";
482     /**
483      * @tc.steps: step1. set source pixelmap wrong and correct initialization options
484      * @tc.expected: step1. The new pixelmap is null.
485      */
486     PixelMap srcPixelMap;
487     ImageInfo imageInfo;
488     srcPixelMap.SetImageInfo(imageInfo);
489     InitializationOptions opts;
490     opts.size.width = 200;
491     opts.size.height = 300;
492     opts.pixelFormat = PixelFormat::ARGB_8888;
493     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
494     std::unique_ptr<PixelMap> newPixelMap = PixelMap::Create(srcPixelMap, opts);
495     EXPECT_EQ(newPixelMap, nullptr);
496     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap009 end";
497 }
498 
499 /**
500 * @tc.name: ImagePixelMap010
501 * @tc.desc: test WriteToParcel
502 * @tc.type: FUNC
503 * @tc.require: AR000FTAMO
504 */
505 HWTEST_F(ImagePixelMapTest, ImagePixelMap010, TestSize.Level3)
506 {
507     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap010 start";
508     Parcel data;
509     std::unique_ptr<PixelMap> pixelmap = ConstructPixmap();
510     bool ret = pixelmap.get()->Marshalling(data);
511     EXPECT_EQ(true, ret);
512 
513     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap010 end";
514 }
515 
516 /**
517 * @tc.name: ImagePixelMap011
518 * @tc.desc: test CreateFromParcel
519 * @tc.type: FUNC
520 * @tc.require: AR000FTAMO
521 */
522 HWTEST_F(ImagePixelMapTest, ImagePixelMap011, TestSize.Level3)
523 {
524     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap011 start";
525 
526     Parcel data;
527     std::unique_ptr<PixelMap> pixelmap1 = ConstructPixmap();
528     bool ret = pixelmap1.get()->Marshalling(data);
529     EXPECT_EQ(true, ret);
530 
531     PixelMap *pixelmap2 = PixelMap::Unmarshalling(data);
532     EXPECT_EQ(pixelmap1->GetHeight(), pixelmap2->GetHeight());
533     EXPECT_EQ(pixelmap1->GetWidth(), pixelmap2->GetWidth());
534     EXPECT_EQ(pixelmap1->GetPixelFormat(), pixelmap2->GetPixelFormat());
535     EXPECT_EQ(pixelmap1->GetColorSpace(), pixelmap2->GetColorSpace());
536 
537     Parcel data2;
538     pixelmap2->Marshalling(data2);
539     PIXEL_MAP_ERR err;
540     PixelMap *pixelmap3 = PixelMap::Unmarshalling(data2, err);
541     EXPECT_EQ(pixelmap2->GetHeight(), pixelmap3->GetHeight());
542     EXPECT_EQ(pixelmap2->GetWidth(), pixelmap3->GetWidth());
543     EXPECT_EQ(pixelmap2->GetPixelFormat(), pixelmap3->GetPixelFormat());
544     EXPECT_EQ(pixelmap2->GetColorSpace(), pixelmap3->GetColorSpace());
545 
546     uint32_t code = 10; // test num.
547     pixelmap3->SetPixelMapError(code, "error");
548     EXPECT_EQ(code, pixelmap3->errorCode);
549     EXPECT_EQ("error", pixelmap3->errorInfo);
550 
551     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap011 end";
552 }
553 
554 /**
555  * @tc.name: ImagePixelMap012
556  * @tc.desc: create pixelmap with color,colorlength,offset,width and initialization options
557  * @tc.type: FUNC
558  */
559 HWTEST_F(ImagePixelMapTest, ImagePixelMap012, TestSize.Level3)
560 {
561     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap012 start";
562     /**
563      * @tc.steps: step1. set color,colorlength,offset,width and initialization options
564      * @tc.expected: step1. The new pixelmap is not null.
565      */
566     const uint32_t color[8] = { 0x80, 0x02, 0x04, 0x08, 0x40, 0x02, 0x04, 0x08 };
567     uint32_t colorlength = sizeof(color) / sizeof(color[0]);
568     const int32_t offset = 1;
569     InitializationOptions opts;
570     opts.size.width = 200;
571     opts.size.height = 300;
572     opts.pixelFormat = PixelFormat::ARGB_8888;
573     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
574     int32_t width = opts.size.width;
575 
576     std::unique_ptr<PixelMap> newPixelMap = PixelMap::Create(color, colorlength, offset, width, opts);
577     EXPECT_EQ(newPixelMap, nullptr);
578     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap012 end";
579 }
580 
581 
582 /**
583 * @tc.name: ImagePixelMap013
584 * @tc.desc: test CreateFromParcel
585 * @tc.type: FUNC
586 * @tc.require: AR000FTAMO
587 */
588 HWTEST_F(ImagePixelMapTest, ImagePixelMap013, TestSize.Level3)
589 {
590     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap013 start";
591 
592     Parcel data;
593     std::unique_ptr<PixelMap> pixelmap1 = ConstructBigPixmap();
594     EXPECT_NE(pixelmap1, nullptr);
595     GTEST_LOG_(INFO) << "ImagePixelMap013 ConstructPixmap success";
596     bool ret = pixelmap1.get()->Marshalling(data);
597     GTEST_LOG_(INFO) << "ImagePixelMap013 Marshalling success";
598     EXPECT_EQ(true, ret);
599 
600     PixelMap *pixelmap2 = PixelMap::Unmarshalling(data);
601     GTEST_LOG_(INFO) << "ImagePixelMap013 Unmarshalling success";
602     GTEST_LOG_(INFO) << "ImagePixelMap013 pixelmap1 GetHeight :" << pixelmap1->GetHeight();
603     GTEST_LOG_(INFO) << "ImagePixelMap013 pixelmap2 GetHeight :" << pixelmap2->GetHeight();
604     EXPECT_EQ(pixelmap1->GetHeight(), pixelmap2->GetHeight());
605     GTEST_LOG_(INFO) << "ImagePixelMap013 GetHeight success";
606     EXPECT_EQ(pixelmap1->GetWidth(), pixelmap2->GetWidth());
607     GTEST_LOG_(INFO) << "ImagePixelMap013 GetWidth success";
608     EXPECT_EQ(pixelmap1->GetPixelFormat(), pixelmap2->GetPixelFormat());
609     GTEST_LOG_(INFO) << "ImagePixelMap013 GetPixelFormat success";
610     EXPECT_EQ(pixelmap1->GetColorSpace(), pixelmap2->GetColorSpace());
611     GTEST_LOG_(INFO) << "ImagePixelMap013 GetColorSpace success";
612     EXPECT_EQ(true, pixelmap1->IsSameImage(*pixelmap2));
613     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap013 end";
614 }
615 
616 
617 /**
618 * @tc.name: ImagePixelMap014
619 * @tc.desc: test GetPixel8
620 * @tc.type: FUNC
621 * @tc.require: AR000FTAMO
622 */
623 HWTEST_F(ImagePixelMapTest, ImagePixelMap014, TestSize.Level3)
624 {
625     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap014 GetPixel8 start";
626     PixelMap pixelMap;
627     int32_t x = 1;
628     int32_t y = 1;
629     uint8_t *ret = 0;
630     EXPECT_EQ(ret, pixelMap.GetPixel8(x, y));
631     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap014 GetPixel8 end";
632 }
633 
634 /**
635 * @tc.name: ImagePixelMap015
636 * @tc.desc: test GetPixel16
637 * @tc.type: FUNC
638 * @tc.require: AR000FTAMO
639 */
640 HWTEST_F(ImagePixelMapTest, ImagePixelMap015, TestSize.Level3)
641 {
642     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap015 GetPixel16 start";
643     PixelMap pixelMap;
644     int32_t x = 1;
645     int32_t y = 1;
646     uint16_t *ret = 0;
647     EXPECT_EQ(ret, pixelMap.GetPixel16(x, y));
648     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap015 GetPixel16 end";
649 }
650 
651 /**
652 * @tc.name: ImagePixelMap016
653 * @tc.desc: test GetPixelBytes
654 * @tc.type: FUNC
655 * @tc.require: AR000FTAMO
656 */
657 HWTEST_F(ImagePixelMapTest, ImagePixelMap016, TestSize.Level3)
658 {
659     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap016 GetPixelBytes start";
660     PixelMap pixelMap;
661     int32_t ret = 0;
662     EXPECT_EQ(ret, pixelMap.GetPixelBytes());
663     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap016 GetPixelBytes end";
664 }
665 
666 /**
667 * @tc.name: ImagePixelMap017
668 * @tc.desc: test GetPixelBytes
669 * @tc.type: FUNC
670 * @tc.require: AR000FTAMO
671 */
672 HWTEST_F(ImagePixelMapTest, ImagePixelMap017, TestSize.Level3)
673 {
674     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap017 scale start";
675     uint32_t* data = nullptr;
676     std::unique_ptr<PixelMap> pixelMap = ConstructPixelMap(&data);
677     EXPECT_NE(pixelMap, nullptr);
678     float xAxis = 2.0;
679     float yAxis = 1.0;
680     pixelMap->scale(xAxis, yAxis);
681     ImageInfo outInfo;
682     pixelMap->GetImageInfo(outInfo);
683     int32_t width = PIXEL_MAP_TEST_WIDTH * 2;
684     int32_t height = PIXEL_MAP_TEST_HEIGHT;
685     EXPECT_EQ(width, outInfo.size.width);
686     EXPECT_EQ(height, outInfo.size.height);
687     if (data != nullptr) {
688         delete[] data;
689     }
690     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap017 scale end";
691 }
692 
693 /**
694 * @tc.name: ImagePixelMap018
695 * @tc.desc: test translate
696 * @tc.type: FUNC
697 * @tc.require: AR000FTAMO
698 */
699 HWTEST_F(ImagePixelMapTest, ImagePixelMap018, TestSize.Level3)
700 {
701     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap018 translate start";
702     uint32_t* data = nullptr;
703     std::unique_ptr<PixelMap> pixelMap = ConstructPixelMap(&data);
704     EXPECT_NE(pixelMap, nullptr);
705     float xAxis = 2.0;
706     float yAxis = 1.0;
707     pixelMap->translate(xAxis, yAxis);
708     ImageInfo outInfo;
709     pixelMap->GetImageInfo(outInfo);
710     if (data != nullptr) {
711         delete[] data;
712     }
713     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap018 translate end";
714 }
715 
716 /**
717 * @tc.name: ImagePixelMap019
718 * @tc.desc: test rotate
719 * @tc.type: FUNC
720 * @tc.require: AR000FTAMO
721 */
722 HWTEST_F(ImagePixelMapTest, ImagePixelMap019, TestSize.Level3)
723 {
724     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap019 rotate start";
725     uint32_t* data = nullptr;
726     std::unique_ptr<PixelMap> pixelMap = ConstructPixelMap(&data);
727     EXPECT_NE(pixelMap, nullptr);
728     float degrees = 90.0;
729     pixelMap->rotate(degrees);
730     ImageInfo outInfo;
731     pixelMap->GetImageInfo(outInfo);
732     int32_t width = PIXEL_MAP_TEST_HEIGHT;
733     int32_t height = PIXEL_MAP_TEST_WIDTH;
734     EXPECT_EQ(width, outInfo.size.width);
735     EXPECT_EQ(height, outInfo.size.height);
736     if (data != nullptr) {
737         delete[] data;
738     }
739     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap019 rotate end";
740 }
741 
742 /**
743 * @tc.name: ImagePixelMap020
744 * @tc.desc: test flip
745 * @tc.type: FUNC
746 * @tc.require: AR000FTAMO
747 */
748 HWTEST_F(ImagePixelMapTest, ImagePixelMap020, TestSize.Level3)
749 {
750     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap020 flip start";
751     uint32_t* data = nullptr;
752     std::unique_ptr<PixelMap> pixelMap = ConstructPixelMap(&data);
753     EXPECT_NE(pixelMap, nullptr);
754     pixelMap->flip(false, true);
755     ImageInfo outInfo;
756     pixelMap->GetImageInfo(outInfo);
757     int32_t width = PIXEL_MAP_TEST_WIDTH;
758     int32_t height = PIXEL_MAP_TEST_HEIGHT;
759     EXPECT_EQ(width, outInfo.size.width);
760     EXPECT_EQ(height, outInfo.size.height);
761     if (data != nullptr) {
762         delete[] data;
763     }
764     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap020 flip end";
765 }
766 
767 /**
768 * @tc.name: ImagePixelMap021
769 * @tc.desc: test crop
770 * @tc.type: FUNC
771 * @tc.require: AR000FTAMO
772 */
773 HWTEST_F(ImagePixelMapTest, ImagePixelMap021, TestSize.Level3)
774 {
775     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap021 crop start";
776     uint32_t* data = nullptr;
777     std::unique_ptr<PixelMap> pixelMap = ConstructPixelMap(&data);
778     EXPECT_NE(pixelMap, nullptr);
779     Rect rect;
780     rect.left = 0;
781     rect.top = 0;
782     rect.height = 1;
783     rect.width = 1;
784     pixelMap->crop(rect);
785     ImageInfo outInfo;
786     pixelMap->GetImageInfo(outInfo);
787     int32_t width = 1;
788     int32_t height = 1;
789     EXPECT_EQ(width, outInfo.size.width);
790     EXPECT_EQ(height, outInfo.size.height);
791     if (data != nullptr) {
792         delete[] data;
793     }
794     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap021 crop end";
795 }
796 
797 /**
798 * @tc.name: ImagePixelMap022
799 * @tc.desc: test SetAlpha
800 * @tc.type: FUNC
801 * @tc.require: AR000FTAMO
802 */
803 HWTEST_F(ImagePixelMapTest, ImagePixelMap022, TestSize.Level3)
804 {
805     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap022 SetAlpha start";
806     PixelMap pixelMap;
807     ImageInfo info;
808     info.size.width = PIXEL_MAP_TEST_WIDTH;
809     info.size.height = PIXEL_MAP_TEST_HEIGHT;
810     info.pixelFormat = PixelFormat::RGB_888;
811     info.colorSpace = ColorSpace::SRGB;
812     pixelMap.SetImageInfo(info);
813     float percent = 0.5;
814     pixelMap.SetAlpha(percent);
815     ImageInfo outInfo;
816     pixelMap.GetImageInfo(outInfo);
817     bool getAlpha = false;
818     if (outInfo.pixelFormat != info.pixelFormat) {
819         getAlpha = true;
820     }
821     EXPECT_EQ(false, getAlpha);
822     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap022 SetAlpha end";
823 }
824 
825 /**
826 * @tc.name: ImagePixelMap023
827 * @tc.desc: test GetARGB32ColorA
828 * @tc.type: FUNC
829 * @tc.require: AR000FTAMO
830 */
831 HWTEST_F(ImagePixelMapTest, ImagePixelMap023, TestSize.Level3)
832 {
833     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap023 GetARGB32ColorA start";
834     PixelMap pixelMap;
835     ImageInfo info;
836     info.size.width = PIXEL_MAP_TEST_WIDTH;
837     info.size.height = PIXEL_MAP_TEST_HEIGHT;
838     info.pixelFormat = PixelFormat::ALPHA_8;
839     info.colorSpace = ColorSpace::SRGB;
840     pixelMap.SetImageInfo(info);
841     uint32_t color = 1;
842     pixelMap.GetARGB32ColorA(color);
843     ImageInfo outInfo;
844     pixelMap.GetImageInfo(outInfo);
845     int32_t width = PIXEL_MAP_TEST_WIDTH;
846     int32_t height = PIXEL_MAP_TEST_HEIGHT;
847     EXPECT_EQ(width, outInfo.size.width);
848     EXPECT_EQ(height, outInfo.size.height);
849     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap023 GetARGB32ColorA end";
850 }
851 
852 /**
853 * @tc.name: ImagePixelMap024
854 * @tc.desc: test GetARGB32ColorR
855 * @tc.type: FUNC
856 * @tc.require: AR000FTAMO
857 */
858 HWTEST_F(ImagePixelMapTest, ImagePixelMap024, TestSize.Level3)
859 {
860     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap024 GetARGB32ColorR start";
861     PixelMap pixelMap;
862     ImageInfo info;
863     info.size.width = PIXEL_MAP_TEST_WIDTH;
864     info.size.height = PIXEL_MAP_TEST_HEIGHT;
865     info.pixelFormat = PixelFormat::ALPHA_8;
866     info.colorSpace = ColorSpace::SRGB;
867     pixelMap.SetImageInfo(info);
868     uint32_t color = 1;
869     pixelMap.GetARGB32ColorR(color);
870     ImageInfo outInfo;
871     pixelMap.GetImageInfo(outInfo);
872     int32_t width = PIXEL_MAP_TEST_WIDTH;
873     int32_t height = PIXEL_MAP_TEST_HEIGHT;
874     EXPECT_EQ(width, outInfo.size.width);
875     EXPECT_EQ(height, outInfo.size.height);
876     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap024 GetARGB32ColorR end";
877 }
878 
879 /**
880 * @tc.name: ImagePixelMap025
881 * @tc.desc: test GetARGB32ColorG
882 * @tc.type: FUNC
883 * @tc.require: AR000FTAMO
884 */
885 HWTEST_F(ImagePixelMapTest, ImagePixelMap025, TestSize.Level3)
886 {
887     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap025 GetARGB32ColorG start";
888     PixelMap pixelMap;
889     ImageInfo info;
890     info.size.width = PIXEL_MAP_TEST_WIDTH;
891     info.size.height = PIXEL_MAP_TEST_HEIGHT;
892     info.pixelFormat = PixelFormat::ALPHA_8;
893     info.colorSpace = ColorSpace::SRGB;
894     pixelMap.SetImageInfo(info);
895     uint32_t color = 1;
896     pixelMap.GetARGB32ColorG(color);
897     ImageInfo outInfo;
898     pixelMap.GetImageInfo(outInfo);
899     int32_t width = PIXEL_MAP_TEST_WIDTH;
900     int32_t height = PIXEL_MAP_TEST_HEIGHT;
901     EXPECT_EQ(width, outInfo.size.width);
902     EXPECT_EQ(height, outInfo.size.height);
903     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap025 GetARGB32ColorG end";
904 }
905 
906 /**
907 * @tc.name: ImagePixelMap026
908 * @tc.desc: test GetARGB32ColorB
909 * @tc.type: FUNC
910 * @tc.require: AR000FTAMO
911 */
912 HWTEST_F(ImagePixelMapTest, ImagePixelMap026, TestSize.Level3)
913 {
914     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap026 GetARGB32ColorB start";
915     PixelMap pixelMap;
916     ImageInfo info;
917     info.size.width = PIXEL_MAP_TEST_WIDTH;
918     info.size.height = PIXEL_MAP_TEST_HEIGHT;
919     info.pixelFormat = PixelFormat::ALPHA_8;
920     info.colorSpace = ColorSpace::SRGB;
921     pixelMap.SetImageInfo(info);
922     uint32_t color = 1;
923     pixelMap.GetARGB32ColorB(color);
924     ImageInfo outInfo;
925     pixelMap.GetImageInfo(outInfo);
926     int32_t width = PIXEL_MAP_TEST_WIDTH;
927     int32_t height = PIXEL_MAP_TEST_HEIGHT;
928     EXPECT_EQ(width, outInfo.size.width);
929     EXPECT_EQ(height, outInfo.size.height);
930     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap026 GetARGB32ColorB end";
931 }
932 
933 /**
934 * @tc.name: ImagePixelMap027
935 * @tc.desc: test IsSameImage
936 * @tc.type: FUNC
937 * @tc.require: AR000FTAMO
938 */
939 HWTEST_F(ImagePixelMapTest, ImagePixelMap027, TestSize.Level3)
940 {
941     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap027 IsSameImage start";
942     PixelMap pixelMap, pixelMap1;
943     ImageInfo info;
944     info.size.width = PIXEL_MAP_TEST_WIDTH;
945     info.size.height = PIXEL_MAP_TEST_HEIGHT;
946     info.pixelFormat = PixelFormat::ALPHA_8;
947     info.colorSpace = ColorSpace::SRGB;
948     pixelMap.SetImageInfo(info);
949     pixelMap1.SetImageInfo(info);
950     bool ret = pixelMap.IsSameImage(pixelMap1);
951     EXPECT_EQ(false, ret);
952     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap027 IsSameImage end";
953 }
954 
955 /**
956 * @tc.name: ImagePixelMap028
957 * @tc.desc: test ReadPixels
958 * @tc.type: FUNC
959 * @tc.require: AR000FTAMO
960 */
961 HWTEST_F(ImagePixelMapTest, ImagePixelMap028, TestSize.Level3)
962 {
963     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap028 ReadPixels start";
964     PixelMap pixelMap;
965     ImageInfo info;
966     info.size.width = PIXEL_MAP_TEST_WIDTH;
967     info.size.height = PIXEL_MAP_TEST_HEIGHT;
968     info.pixelFormat = PixelFormat::ALPHA_8;
969     info.colorSpace = ColorSpace::SRGB;
970     pixelMap.SetImageInfo(info);
971     uint64_t bufferSize = 96;
972     uint32_t offset = 0;
973     uint32_t stride = 8;
974     Rect rect;
975     rect.left = 0;
976     rect.top = 0;
977     rect.height = 1;
978     rect.width = 2;
979     uint8_t *dst = 0;
980     uint32_t ret = pixelMap.ReadPixels(bufferSize, offset, stride, rect, dst);
981     bool getReadPixels = true;
982     if (ret != SUCCESS) {
983         getReadPixels = false;
984     }
985     EXPECT_EQ(false, getReadPixels);
986     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap028 ReadPixels end";
987 }
988 
989 /**
990 * @tc.name: ImagePixelMap029
991 * @tc.desc: test ReadPixels
992 * @tc.type: FUNC
993 * @tc.require: AR000FTAMO
994 */
995 HWTEST_F(ImagePixelMapTest, ImagePixelMap029, TestSize.Level3)
996 {
997     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap029 ReadPixels start";
998     PixelMap pixelMap;
999     ImageInfo info;
1000     info.size.width = PIXEL_MAP_TEST_WIDTH;
1001     info.size.height = PIXEL_MAP_TEST_HEIGHT;
1002     info.pixelFormat = PixelFormat::ALPHA_8;
1003     info.colorSpace = ColorSpace::SRGB;
1004     pixelMap.SetImageInfo(info);
1005     uint64_t bufferSize = 96;
1006     uint8_t *dst = 0;
1007     uint32_t ret = pixelMap.ReadPixels(bufferSize, dst);
1008     bool getReadPixels = true;
1009     if (ret != SUCCESS) {
1010         getReadPixels = false;
1011     }
1012     EXPECT_EQ(false, getReadPixels);
1013     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap029 ReadPixels end";
1014 }
1015 
1016 /**
1017 * @tc.name: ImagePixelMap030
1018 * @tc.desc: test ReadPixel
1019 * @tc.type: FUNC
1020 * @tc.require: AR000FTAMO
1021 */
1022 HWTEST_F(ImagePixelMapTest, ImagePixelMap030, TestSize.Level3)
1023 {
1024     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap030 ReadPixel start";
1025     PixelMap pixelMap;
1026     ImageInfo info;
1027     info.size.width = PIXEL_MAP_TEST_WIDTH;
1028     info.size.height = PIXEL_MAP_TEST_HEIGHT;
1029     info.pixelFormat = PixelFormat::ALPHA_8;
1030     info.colorSpace = ColorSpace::SRGB;
1031     pixelMap.SetImageInfo(info);
1032     int32_t x = 0;
1033     int32_t y = 0;
1034     Position position;
1035     position.x = x;
1036     position.y = y;
1037     uint32_t dst = 0;
1038     uint32_t ret = pixelMap.ReadPixel(position, dst);
1039     bool getReadPixel = true;
1040     if (ret != SUCCESS) {
1041         getReadPixel = false;
1042     }
1043     EXPECT_EQ(false, getReadPixel);
1044     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap030 ReadPixel end";
1045 }
1046 
1047 /**
1048 * @tc.name: ImagePixelMap031
1049 * @tc.desc: test ResetConfig
1050 * @tc.type: FUNC
1051 * @tc.require: AR000FTAMO
1052 */
1053 HWTEST_F(ImagePixelMapTest, ImagePixelMap031, TestSize.Level3)
1054 {
1055     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap031 ResetConfig start";
1056     PixelMap pixelMap;
1057     ImageInfo info;
1058     info.size.width = PIXEL_MAP_TEST_WIDTH;
1059     info.size.height = PIXEL_MAP_TEST_HEIGHT;
1060     info.pixelFormat = PixelFormat::ALPHA_8;
1061     info.colorSpace = ColorSpace::SRGB;
1062     pixelMap.SetImageInfo(info);
1063     Size size;
1064     size.width = 2 * PIXEL_MAP_TEST_WIDTH;
1065     size.height = 2 * PIXEL_MAP_TEST_HEIGHT;
1066     PixelFormat pixelFormat = PixelFormat::RGBA_8888;
1067     uint32_t ret = pixelMap.ResetConfig(size, pixelFormat);
1068     bool getResetConfig = true;
1069     if (ret != SUCCESS) {
1070         getResetConfig = false;
1071     }
1072     EXPECT_EQ(false, getResetConfig);
1073     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap031 ResetConfig end";
1074 }
1075 
1076 /**
1077 * @tc.name: ImagePixelMap032
1078 * @tc.desc: test SetAlphaType
1079 * @tc.type: FUNC
1080 * @tc.require: AR000FTAMO
1081 */
1082 HWTEST_F(ImagePixelMapTest, ImagePixelMap032, TestSize.Level3)
1083 {
1084     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap032 SetAlphaType start";
1085     PixelMap pixelMap;
1086     ImageInfo info;
1087     info.size.width = PIXEL_MAP_TEST_WIDTH;
1088     info.size.height = PIXEL_MAP_TEST_HEIGHT;
1089     info.pixelFormat = PixelFormat::ALPHA_8;
1090     info.colorSpace = ColorSpace::SRGB;
1091     pixelMap.SetImageInfo(info);
1092     AlphaType alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
1093     bool ret = pixelMap.SetAlphaType(alphaType);
1094     EXPECT_EQ(true, ret);
1095     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap032 SetAlphaType end";
1096 }
1097 
1098 /**
1099 * @tc.name: ImagePixelMap033
1100 * @tc.desc: test SetAlphaType
1101 * @tc.type: FUNC
1102 * @tc.require: AR000FTAMO
1103 */
1104 HWTEST_F(ImagePixelMapTest, ImagePixelMap033, TestSize.Level3)
1105 {
1106     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap033 SetAlphaType start";
1107     PixelMap pixelMap;
1108     ImageInfo info;
1109     info.size.width = PIXEL_MAP_TEST_WIDTH;
1110     info.size.height = PIXEL_MAP_TEST_HEIGHT;
1111     info.pixelFormat = PixelFormat::ALPHA_8;
1112     info.colorSpace = ColorSpace::SRGB;
1113     pixelMap.SetImageInfo(info);
1114     AlphaType alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
1115     bool ret = pixelMap.SetAlphaType(alphaType);
1116     EXPECT_EQ(true, ret);
1117     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap033 SetAlphaType end";
1118 }
1119 
1120 /**
1121 * @tc.name: ImagePixelMap034
1122 * @tc.desc: test WritePixel
1123 * @tc.type: FUNC
1124 * @tc.require: AR000FTAMO
1125 */
1126 HWTEST_F(ImagePixelMapTest, ImagePixelMap034, TestSize.Level3)
1127 {
1128     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap034 WritePixel start";
1129     PixelMap pixelMap;
1130     ImageInfo info;
1131     info.size.width = PIXEL_MAP_TEST_WIDTH;
1132     info.size.height = PIXEL_MAP_TEST_HEIGHT;
1133     info.pixelFormat = PixelFormat::ALPHA_8;
1134     info.colorSpace = ColorSpace::SRGB;
1135     pixelMap.SetImageInfo(info);
1136     int32_t x = 0;
1137     int32_t y = 0;
1138     Position position;
1139     position.x = x;
1140     position.y = y;
1141     uint32_t color = 9;
1142     uint32_t ret = pixelMap.WritePixel(position, color);
1143     bool getWritePixel = true;
1144     if (ret != SUCCESS) {
1145         getWritePixel = false;
1146     }
1147     EXPECT_EQ(false, getWritePixel);
1148     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap034 WritePixel end";
1149 }
1150 
1151 /**
1152 * @tc.name: ImagePixelMap035
1153 * @tc.desc: test GetFd
1154 * @tc.type: FUNC
1155 * @tc.require: AR000FTAMO
1156 */
1157 HWTEST_F(ImagePixelMapTest, ImagePixelMap035, TestSize.Level3)
1158 {
1159     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap035 GetFd start";
1160     PixelMap pixelMap;
1161     ImageInfo info;
1162     info.size.width = PIXEL_MAP_TEST_WIDTH;
1163     info.size.height = PIXEL_MAP_TEST_HEIGHT;
1164     info.pixelFormat = PixelFormat::ALPHA_8;
1165     info.colorSpace = ColorSpace::SRGB;
1166     pixelMap.SetImageInfo(info);
1167 
1168     void *ret = pixelMap.GetFd();
1169     bool isFd = false;
1170     if (ret != nullptr) {
1171         isFd = true;
1172     }
1173     EXPECT_EQ(false, isFd);
1174     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap035 GetFd end";
1175 }
1176 
1177 /**
1178 * @tc.name: ImagePixelMap036
1179 * @tc.desc: test GetCapacity
1180 * @tc.type: FUNC
1181 * @tc.require: AR000FTAMO
1182 */
1183 HWTEST_F(ImagePixelMapTest, ImagePixelMap036, TestSize.Level3)
1184 {
1185     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap036 GetCapacity start";
1186     PixelMap pixelMap;
1187     ImageInfo info;
1188     info.size.width = PIXEL_MAP_TEST_WIDTH;
1189     info.size.height = PIXEL_MAP_TEST_HEIGHT;
1190     info.pixelFormat = PixelFormat::ALPHA_8;
1191     info.colorSpace = ColorSpace::SRGB;
1192     pixelMap.SetImageInfo(info);
1193     uint32_t ret = pixelMap.GetCapacity();
1194     bool getCapacity = false;
1195     if (ret != 0) {
1196         getCapacity = true;
1197     }
1198     EXPECT_EQ(false, getCapacity);
1199     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap036 GetCapacity end";
1200 }
1201 
1202 /**
1203 * @tc.name: ImagePixelMap037
1204 * @tc.desc: test IsSourceAsResponse
1205 * @tc.type: FUNC
1206 * @tc.require: AR000FTAMO
1207 */
1208 HWTEST_F(ImagePixelMapTest, ImagePixelMap037, TestSize.Level3)
1209 {
1210     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap037 IsSourceAsResponse start";
1211     PixelMap pixelMap;
1212     ImageInfo info;
1213     info.size.width = PIXEL_MAP_TEST_WIDTH;
1214     info.size.height = PIXEL_MAP_TEST_HEIGHT;
1215     info.pixelFormat = PixelFormat::ALPHA_8;
1216     info.colorSpace = ColorSpace::SRGB;
1217     pixelMap.SetImageInfo(info);
1218     bool ret = pixelMap.IsSourceAsResponse();
1219     EXPECT_EQ(false, ret);
1220     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap037 IsSourceAsResponse end";
1221 }
1222 
1223 /**
1224 * @tc.name: ImagePixelMap038
1225 * @tc.desc: test GetWritablePixels
1226 * @tc.type: FUNC
1227 * @tc.require: AR000FTAMO
1228 */
1229 HWTEST_F(ImagePixelMapTest, ImagePixelMap038, TestSize.Level3)
1230 {
1231     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap038 GetWritablePixels start";
1232     PixelMap pixelMap;
1233     ImageInfo info;
1234     info.size.width = PIXEL_MAP_TEST_WIDTH;
1235     info.size.height = PIXEL_MAP_TEST_HEIGHT;
1236     info.pixelFormat = PixelFormat::ALPHA_8;
1237     info.colorSpace = ColorSpace::SRGB;
1238     pixelMap.SetImageInfo(info);
1239     void *ret = pixelMap.GetWritablePixels();
1240     bool getPixels = true;
1241     if (ret == nullptr) {
1242         getPixels = false;
1243     }
1244     EXPECT_EQ(false, getPixels);
1245     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap038 GetWritablePixels end";
1246 }
1247 #ifdef IMAGE_COLORSPACE_FLAG
1248 /**
1249 * @tc.name: ImagePixelMap039
1250 * @tc.desc: test InnerSetColorSpace
1251 * @tc.type: FUNC
1252 * @tc.require: AR000FTAMO
1253 */
1254 HWTEST_F(ImagePixelMapTest, ImagePixelMap039, TestSize.Level3)
1255 {
1256     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap039 InnerSetColorSpace start";
1257     PixelMap pixelMap;
1258     ImageInfo info;
1259     info.size.width = PIXEL_MAP_TEST_WIDTH;
1260     info.size.height = PIXEL_MAP_TEST_HEIGHT;
1261     info.pixelFormat = PixelFormat::ALPHA_8;
1262     info.colorSpace = ColorSpace::SRGB;
1263     pixelMap.SetImageInfo(info);
1264     OHOS::ColorManager::ColorSpace grColorSpace =
1265         OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::SRGB);
1266     pixelMap.InnerSetColorSpace(grColorSpace);
1267     OHOS::ColorManager::ColorSpace outColorSpace = pixelMap.InnerGetGrColorSpace();
1268     EXPECT_TRUE(SkColorSpace::Equals(
1269         outColorSpace.ToSkColorSpace().get(), grColorSpace.ToSkColorSpace().get()));
1270     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap039 InnerSetColorSpace end";
1271 }
1272 
1273 static constexpr uint32_t PIXEL_MAP_TEST_PIXEL = 0xFF994422;
1274 static constexpr uint32_t PIXEL_MAP_TEST_DISPLAY_P3_PIXEL = 0xFF2B498E;
1275 static constexpr uint32_t PIXEL_MAP_TEST_ADOBE_RGB_PIXEL = 0xFF294686;
1276 static constexpr uint32_t PIXEL_MAP_TEST_DCI_P3_PIXEL = 0xFF3D5A9D;
1277 static constexpr uint32_t PIXEL_MAP_TEST_BT2020_PIXEL = 0xFF1C3E74;
1278 static constexpr int32_t POINT_ZERO = 0;
1279 
1280 /**
1281 * @tc.name: ImagePixelMap040
1282 * @tc.desc: test ApplyColorSpace DISPLAY_P3
1283 * @tc.type: FUNC
1284 */
1285 HWTEST_F(ImagePixelMapTest, ImagePixelMap040, TestSize.Level3)
1286 {
1287     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap040 ApplyColorSpace start";
1288     const uint32_t dataLength = PIXEL_MAP_TEST_WIDTH * PIXEL_MAP_TEST_HEIGHT;
1289     vector<uint32_t> data(dataLength, PIXEL_MAP_TEST_PIXEL);
1290     InitializationOptions opts;
1291     opts.pixelFormat = OHOS::Media::PixelFormat::RGBA_8888;
1292     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
1293     opts.size.width = PIXEL_MAP_TEST_WIDTH;
1294     opts.size.height = PIXEL_MAP_TEST_HEIGHT;
1295 
1296     auto pixelmap = PixelMap::Create(data.data(), dataLength, opts);
1297     auto grColorSpace = OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::SRGB);
1298     pixelmap->InnerSetColorSpace(grColorSpace);
1299     auto applyGrColorSpace = OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::DISPLAY_P3);
1300     pixelmap->ApplyColorSpace(applyGrColorSpace);
1301 
1302     auto pixelZero = pixelmap->GetPixel32(POINT_ZERO, POINT_ZERO);
1303     EXPECT_EQ(*pixelZero, PIXEL_MAP_TEST_DISPLAY_P3_PIXEL);
1304     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap040 ApplyColorSpace end";
1305 }
1306 
1307 /**
1308 * @tc.name: ImagePixelMap041
1309 * @tc.desc: test ApplyColorSpace ADOBE_RGB
1310 * @tc.type: FUNC
1311 */
1312 HWTEST_F(ImagePixelMapTest, ImagePixelMap041, TestSize.Level3)
1313 {
1314     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap040 ApplyColorSpace start";
1315     const uint32_t dataLength = PIXEL_MAP_TEST_WIDTH * PIXEL_MAP_TEST_HEIGHT;
1316     vector<uint32_t> data(dataLength, PIXEL_MAP_TEST_PIXEL);
1317     InitializationOptions opts;
1318     opts.pixelFormat = OHOS::Media::PixelFormat::RGBA_8888;
1319     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
1320     opts.size.width = PIXEL_MAP_TEST_WIDTH;
1321     opts.size.height = PIXEL_MAP_TEST_HEIGHT;
1322 
1323     auto pixelmap = PixelMap::Create(data.data(), dataLength, opts);
1324     auto grColorSpace = OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::SRGB);
1325     pixelmap->InnerSetColorSpace(grColorSpace);
1326     auto applyGrColorSpace = OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::ADOBE_RGB);
1327     pixelmap->ApplyColorSpace(applyGrColorSpace);
1328 
1329     auto pixelZero = pixelmap->GetPixel32(POINT_ZERO, POINT_ZERO);
1330     EXPECT_EQ(*pixelZero, PIXEL_MAP_TEST_ADOBE_RGB_PIXEL);
1331     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap041 ApplyColorSpace end";
1332 }
1333 
1334 /**
1335 * @tc.name: ImagePixelMap042
1336 * @tc.desc: test ApplyColorSpace DCI_P3
1337 * @tc.type: FUNC
1338 */
1339 HWTEST_F(ImagePixelMapTest, ImagePixelMap042, TestSize.Level3)
1340 {
1341     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap042 ApplyColorSpace start";
1342     const uint32_t dataLength = PIXEL_MAP_TEST_WIDTH * PIXEL_MAP_TEST_HEIGHT;
1343     vector<uint32_t> data(dataLength, PIXEL_MAP_TEST_PIXEL);
1344     InitializationOptions opts;
1345     opts.pixelFormat = OHOS::Media::PixelFormat::RGBA_8888;
1346     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
1347     opts.size.width = PIXEL_MAP_TEST_WIDTH;
1348     opts.size.height = PIXEL_MAP_TEST_HEIGHT;
1349 
1350     auto pixelmap = PixelMap::Create(data.data(), dataLength, opts);
1351     auto grColorSpace = OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::SRGB);
1352     pixelmap->InnerSetColorSpace(grColorSpace);
1353     auto applyGrColorSpace = OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::DCI_P3);
1354     pixelmap->ApplyColorSpace(applyGrColorSpace);
1355 
1356     auto pixelZero = pixelmap->GetPixel32(POINT_ZERO, POINT_ZERO);
1357     EXPECT_EQ(*pixelZero, PIXEL_MAP_TEST_DCI_P3_PIXEL);
1358     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap042 ApplyColorSpace end";
1359 }
1360 
1361 /**
1362 * @tc.name: ImagePixelMap043
1363 * @tc.desc: test ApplyColorSpace Rec.2020
1364 * @tc.type: FUNC
1365 */
1366 HWTEST_F(ImagePixelMapTest, ImagePixelMap043, TestSize.Level3)
1367 {
1368     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap043 ApplyColorSpace start";
1369     const uint32_t dataLength = PIXEL_MAP_TEST_WIDTH * PIXEL_MAP_TEST_HEIGHT;
1370     vector<uint32_t> data(dataLength, PIXEL_MAP_TEST_PIXEL);
1371     InitializationOptions opts;
1372     opts.pixelFormat = OHOS::Media::PixelFormat::RGBA_8888;
1373     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
1374     opts.size.width = PIXEL_MAP_TEST_WIDTH;
1375     opts.size.height = PIXEL_MAP_TEST_HEIGHT;
1376 
1377     auto pixelmap = PixelMap::Create(data.data(), dataLength, opts);
1378     auto grColorSpace = OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::SRGB);
1379     pixelmap->InnerSetColorSpace(grColorSpace);
1380     auto applyGrColorSpace = OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::BT2020);
1381     pixelmap->ApplyColorSpace(applyGrColorSpace);
1382 
1383     auto pixelZero = pixelmap->GetPixel32(POINT_ZERO, POINT_ZERO);
1384     EXPECT_EQ(*pixelZero, PIXEL_MAP_TEST_BT2020_PIXEL);
1385     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap043 ApplyColorSpace end";
1386 }
1387 #endif
1388 
1389 /**
1390 * @tc.name: ImagePixelMap044
1391 * @tc.desc: test getEncodedFormat
1392 * @tc.type: FUNC
1393 * @tc.require: AR000FTAMO
1394 */
1395 HWTEST_F(ImagePixelMapTest, ImagePixelMap044, TestSize.Level3)
1396 {
1397     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap044 getEncodedFormat start";
1398     PixelMap pixelMap;
1399     ImageInfo info;
1400     info.size.width = PIXEL_MAP_TEST_WIDTH;
1401     info.size.height = PIXEL_MAP_TEST_HEIGHT;
1402     info.pixelFormat = PixelFormat::ALPHA_8;
1403     info.colorSpace = ColorSpace::SRGB;
1404     pixelMap.SetImageInfo(info);
1405     ImageInfo info1;
1406     pixelMap.GetImageInfo(info1);
1407     EXPECT_EQ(info1.encodedFormat.empty(), true);
1408     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap044 getEncodedFormat end";
1409 }
1410 
CreatePixelMapCommon(int32_t width,int32_t height)1411 std::unique_ptr<PixelMap> CreatePixelMapCommon(int32_t width, int32_t height)
1412 {
1413     const uint32_t dataLength = width * height;
1414     uint32_t *data = new uint32_t[dataLength];
1415     for (uint32_t i = 0; i < dataLength; i++) {
1416         data[i] = 0xFFFF0000;
1417     }
1418     InitializationOptions opts;
1419     opts.pixelFormat = OHOS::Media::PixelFormat::ARGB_8888;
1420     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
1421     opts.size.width = width;
1422     opts.size.height = height;
1423     std::unique_ptr<PixelMap> pixelmap = PixelMap::Create(data, dataLength, opts);
1424     delete[] data;
1425     return pixelmap;
1426 }
1427 
1428 /**
1429 * @tc.name: CheckPixelsInput001
1430 * @tc.desc: test CheckPixelsInput
1431 * @tc.type: FUNC
1432 */
1433 HWTEST_F(ImagePixelMapTest, CheckPixelsInput001, TestSize.Level3)
1434 {
1435     GTEST_LOG_(INFO) << "ImagePixelMapTest: CheckPixelsInput001 start";
1436     std::unique_ptr<PixelMap> pixelMap = CreatePixelMapCommon(8, 8);;
1437     ASSERT_NE(pixelMap.get(), nullptr);
1438 
1439     uint8_t *source = nullptr;
1440     int32_t bufferSize = 0;
1441     uint32_t stride = 0;
1442     uint32_t offset = 0;
1443     struct Rect region = {0};
1444     uint32_t status = 0;
1445 
1446     ImageInfo imageInfo;
1447     pixelMap->GetImageInfo(imageInfo);
1448 
1449     // test source is nullptr
1450     ASSERT_EQ(source, nullptr);
1451     status = pixelMap->WritePixels(source, bufferSize, offset, stride, region);
1452     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1453 
1454     // test bufferSize is 0
1455     source = static_cast<uint8_t *>(malloc(1));
1456     ASSERT_NE(source, nullptr);
1457 
1458     ASSERT_EQ(bufferSize, 0);
1459     status = pixelMap->WritePixels(source, bufferSize, offset, stride, region);
1460     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1461 
1462     bufferSize = pixelMap->GetByteCount();
1463     ASSERT_NE(bufferSize, 0);
1464 
1465     // test region.left < 0
1466     region = {.left = -1, .top = 0, .width = imageInfo.size.width, .height = imageInfo.size.height};
1467     ASSERT_EQ(region.left < 0 ? 0 : 1, 0);
1468     status = pixelMap->WritePixels(source, bufferSize, offset, stride, region);
1469     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1470 
1471     // test region.top < 0
1472     region = {.left = 0, .top = -1, .width = imageInfo.size.width, .height = imageInfo.size.height};
1473     ASSERT_NE(region.left < 0 ? 0 : 1, 0);
1474     ASSERT_EQ(region.top < 0 ? 0 : 1, 0);
1475     status = pixelMap->WritePixels(source, bufferSize, offset, stride, region);
1476     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1477 
1478     free(source);
1479     GTEST_LOG_(INFO) << "ImagePixelMapTest: CheckPixelsInput001 end";
1480 }
1481 
1482 /**
1483 * @tc.name: CheckPixelsInput002
1484 * @tc.desc: test CheckPixelsInput
1485 * @tc.type: FUNC
1486 */
1487 HWTEST_F(ImagePixelMapTest, CheckPixelsInput002, TestSize.Level3)
1488 {
1489     GTEST_LOG_(INFO) << "ImagePixelMapTest: CheckPixelsInput002 start";
1490     std::unique_ptr<PixelMap> pixelMap = CreatePixelMapCommon(8, 8);;
1491     ASSERT_NE(pixelMap.get(), nullptr);
1492 
1493     uint8_t *source = static_cast<uint8_t *>(malloc(1));
1494     uint64_t bufferSize = static_cast<uint64_t>(pixelMap->GetByteCount());
1495     uint32_t stride = 0;
1496     uint32_t offset = 0;
1497     struct Rect region = {0};
1498     uint32_t status = 0;
1499 
1500     ASSERT_NE(source, nullptr);
1501 
1502     ImageInfo imageInfo;
1503     pixelMap->GetImageInfo(imageInfo);
1504 
1505     region = {.left = 0, .top = 0, .width = imageInfo.size.width, .height = imageInfo.size.height};
1506     ASSERT_NE(region.left < 0 ? 0 : 1, 0);
1507     ASSERT_NE(region.top < 0 ? 0 : 1, 0);
1508 
1509     // test stride > numeric_limits<int32_t>::max()
1510     stride = std::numeric_limits<uint32_t>::max();
1511     ASSERT_EQ(stride > std::numeric_limits<int32_t>::max() ? 0 : 1, 0);
1512     status = pixelMap->WritePixels(source, bufferSize, offset, stride, region);
1513     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1514 
1515     stride = 0;
1516     ASSERT_NE(stride > std::numeric_limits<int32_t>::max() ? 0 : 1, 0);
1517 
1518     // test static_cast<uint64_t>(offset) > bufferSize
1519     offset = static_cast<uint32_t>(bufferSize + 1);
1520     ASSERT_EQ(static_cast<uint64_t>(offset) > bufferSize ? 0 : 1, 0);
1521     status = pixelMap->WritePixels(source, bufferSize, offset, stride, region);
1522     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1523 
1524     offset = 0;
1525     ASSERT_NE(static_cast<uint64_t>(offset) > bufferSize ? 0 : 1, 0);
1526     status = pixelMap->WritePixels(source, bufferSize, offset, stride, region);
1527     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1528 
1529     free(source);
1530     GTEST_LOG_(INFO) << "ImagePixelMapTest: CheckPixelsInput002 end";
1531 }
1532 
1533 /**
1534 * @tc.name: CheckPixelsInput003
1535 * @tc.desc: test CheckPixelsInput
1536 * @tc.type: FUNC
1537 */
1538 HWTEST_F(ImagePixelMapTest, CheckPixelsInput003, TestSize.Level3)
1539 {
1540     GTEST_LOG_(INFO) << "ImagePixelMapTest: CheckPixelsInput003 start";
1541     // 8 means pixelmap width and height
1542     std::unique_ptr<PixelMap> pixelMap = CreatePixelMapCommon(8, 8);;
1543     ASSERT_NE(pixelMap.get(), nullptr);
1544     ImageInfo imageInfo;
1545     pixelMap->GetImageInfo(imageInfo);
1546 
1547     // 1 means bytecount
1548     uint8_t *source = static_cast<uint8_t *>(malloc(1));
1549     uint64_t bufferSize = static_cast<uint64_t>(pixelMap->GetByteCount());
1550     uint32_t stride = 0; // 0 means stride for test
1551     uint32_t offset = 0; // 0 means offset for test
1552     struct Rect region = {.left = 0, .top = 0, .width = imageInfo.size.width, .height = imageInfo.size.height};
1553     uint32_t status = 0;
1554 
1555     ASSERT_NE(source, nullptr);
1556     ASSERT_NE(bufferSize, 0);
1557     ASSERT_NE(region.left < 0 ? 0 : 1, 0);
1558     ASSERT_NE(region.top < 0 ? 0 : 1, 0);
1559     ASSERT_NE(stride > std::numeric_limits<int32_t>::max() ? 0 : 1, 0);
1560     ASSERT_NE(static_cast<uint64_t>(offset) > bufferSize ? 0 : 1, 0);
1561     // -1 means region width for test
1562     region.width = -1;
1563     ASSERT_EQ(region.width < 0 ? 0 : 1, 0);
1564     status = pixelMap->WritePixels(source, bufferSize, offset, stride, region);
1565     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1566     region.width = imageInfo.size.width;
1567     ASSERT_NE(region.width < 0 ? 0 : 1, 0);
1568     // -1 means region height for test
1569     region.height = -1;
1570     ASSERT_EQ(region.height < 0 ? 0 : 1, 0);
1571     status = pixelMap->WritePixels(source, bufferSize, offset, stride, region);
1572     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1573     region.height = imageInfo.size.height;
1574     ASSERT_NE(region.height < 0 ? 0 : 1, 0);
1575     // INT32_MAX >> 2 means region max width/height
1576     int maxDimension = INT32_MAX >> 2;
1577     // 1 used to check overflow
1578     region.width = maxDimension + 1;
1579     ASSERT_EQ(region.width > maxDimension ? 0 : 1, 0);
1580     status = pixelMap->WritePixels(source, bufferSize, offset, stride, region);
1581     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1582     region.width = imageInfo.size.width;
1583     ASSERT_NE(region.width > maxDimension ? 0 : 1, 0);
1584     // 1 used to check overflow
1585     region.height = maxDimension + 1;
1586     ASSERT_EQ(region.height > maxDimension ? 0 : 1, 0);
1587     status = pixelMap->WritePixels(source, bufferSize, offset, stride, region);
1588     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1589     region.height = imageInfo.size.height;
1590     ASSERT_NE(region.height > maxDimension ? 0 : 1, 0);
1591 
1592     free(source);
1593     GTEST_LOG_(INFO) << "ImagePixelMapTest: CheckPixelsInput003 end";
1594 }
1595 
1596 /**
1597 * @tc.name: CheckPixelsInput004
1598 * @tc.desc: test CheckPixelsInput
1599 * @tc.type: FUNC
1600 */
1601 HWTEST_F(ImagePixelMapTest, CheckPixelsInput004, TestSize.Level3)
1602 {
1603     GTEST_LOG_(INFO) << "ImagePixelMapTest: CheckPixelsInput004 start";
1604     // 8 means pixelmap width and height
1605     std::unique_ptr<PixelMap> pixelMap = CreatePixelMapCommon(8, 8);;
1606     ASSERT_NE(pixelMap.get(), nullptr);
1607 
1608     ImageInfo info;
1609     pixelMap->GetImageInfo(info);
1610 
1611     uint8_t *source4 = static_cast<uint8_t *>(malloc(1));
1612     uint64_t size4 = static_cast<uint64_t>(pixelMap->GetByteCount());
1613     uint32_t stride4 = 0; // 0 means stride for test
1614     uint32_t offset4 = 0; // 0 means offset for test
1615     struct Rect region4 = {.left = 0, .top = 0, .width = info.size.width, .height = info.size.height};
1616     uint32_t status = 0;
1617 
1618     ASSERT_NE(source4, nullptr);
1619     ASSERT_NE(size4, 0);
1620     ASSERT_NE(region4.left < 0 ? 0 : 1, 0);
1621     ASSERT_NE(region4.top < 0 ? 0 : 1, 0);
1622     ASSERT_NE(stride4 > std::numeric_limits<int32_t>::max() ? 0 : 1, 0);
1623     ASSERT_NE(static_cast<uint64_t>(offset4) > size4 ? 0 : 1, 0);
1624 
1625     // INT32_MAX >> 2 means region max width/height
1626     int maxDimension = INT32_MAX >> 2;
1627     ASSERT_NE(region4.width < 0 ? 0 : 1, 0);
1628     ASSERT_NE(region4.height < 0 ? 0 : 1, 0);
1629     ASSERT_NE(region4.width > maxDimension ? 0 : 1, 0);
1630     ASSERT_NE(region4.height > maxDimension ? 0 : 1, 0);
1631 
1632     int32_t left = pixelMap->GetWidth() - region4.width;
1633     // 1 for test
1634     region4.left = left + 1;
1635     ASSERT_EQ(region4.left > left ? 0 : 1, 0);
1636     status = pixelMap->WritePixels(source4, size4, offset4, stride4, region4);
1637     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1638 
1639     // 0 for test
1640     region4.left = 0;
1641     ASSERT_NE(region4.left > left ? 0 : 1, 0);
1642 
1643     int32_t top = pixelMap->GetHeight() - region4.height;
1644     // 1 for test
1645     region4.top = top + 1;
1646     ASSERT_EQ(region4.top > top ? 0 : 1, 0);
1647     status = pixelMap->WritePixels(source4, size4, offset4, stride4, region4);
1648     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1649 
1650     // 0 for test
1651     region4.top = 0;
1652     ASSERT_NE(region4.top > top ? 0 : 1, 0);
1653 
1654     free(source4);
1655     GTEST_LOG_(INFO) << "ImagePixelMapTest: CheckPixelsInput004 end";
1656 }
1657 
1658 /**
1659 * @tc.name: CheckPixelsInput005
1660 * @tc.desc: test CheckPixelsInput
1661 * @tc.type: FUNC
1662 */
1663 HWTEST_F(ImagePixelMapTest, CheckPixelsInput005, TestSize.Level3)
1664 {
1665     GTEST_LOG_(INFO) << "ImagePixelMapTest: CheckPixelsInput005 start";
1666     // 8 means pixelmap width and height
1667     std::unique_ptr<PixelMap> pixelMap = CreatePixelMapCommon(8, 8);;
1668     ASSERT_NE(pixelMap.get(), nullptr);
1669 
1670     ImageInfo info;
1671     pixelMap->GetImageInfo(info);
1672 
1673     uint8_t *source5 = static_cast<uint8_t *>(malloc(1));
1674     uint64_t size5 = static_cast<uint64_t>(pixelMap->GetByteCount());
1675     uint32_t stride5 = 0; // 0 means stride for test
1676     uint32_t offset5 = 0; // 0 means offset for test
1677     struct Rect region5 = {.left = 0, .top = 0, .width = info.size.width, .height = info.size.height};
1678     uint32_t status = 0;
1679 
1680     ASSERT_NE(source5, nullptr);
1681     ASSERT_NE(size5, 0);
1682     ASSERT_NE(region5.left < 0 ? 0 : 1, 0);
1683     ASSERT_NE(region5.top < 0 ? 0 : 1, 0);
1684     ASSERT_NE(stride5 > std::numeric_limits<int32_t>::max() ? 0 : 1, 0);
1685     ASSERT_NE(static_cast<uint64_t>(offset5) > size5 ? 0 : 1, 0);
1686 
1687     // INT32_MAX >> 2 means region max width/height
1688     int maxDimension = INT32_MAX >> 2;
1689     ASSERT_NE(region5.width < 0 ? 0 : 1, 0);
1690     ASSERT_NE(region5.height < 0 ? 0 : 1, 0);
1691     ASSERT_NE(region5.width > maxDimension ? 0 : 1, 0);
1692     ASSERT_NE(region5.height > maxDimension ? 0 : 1, 0);
1693 
1694     ASSERT_NE(region5.left > pixelMap->GetWidth() - region5.width ? 0 : 1, 0);
1695     ASSERT_NE(region5.top > pixelMap->GetHeight() - region5.height ? 0 : 1, 0);
1696 
1697     // 4 means pixel bytes
1698     uint32_t regionStride = static_cast<uint32_t>(region5.width) * 4;
1699     // 1 for test
1700     stride5 = regionStride - 1;
1701     ASSERT_EQ(stride5 < regionStride ? 0 : 1, 0);
1702     status = pixelMap->WritePixels(source5, size5, offset5, stride5, region5);
1703     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1704 
1705     stride5 = regionStride;
1706     ASSERT_NE(stride5 < regionStride ? 0 : 1, 0);
1707 
1708     // 1 for test
1709     size5 = regionStride - 1;
1710     ASSERT_EQ(size5 < regionStride ? 0 : 1, 0);
1711     status = pixelMap->WritePixels(source5, size5, offset5, stride5, region5);
1712     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1713 
1714     free(source5);
1715     GTEST_LOG_(INFO) << "ImagePixelMapTest: CheckPixelsInput005 end";
1716 }
1717 
1718 /**
1719 * @tc.name: CheckPixelsInput006
1720 * @tc.desc: test CheckPixelsInput
1721 * @tc.type: FUNC
1722 */
1723 HWTEST_F(ImagePixelMapTest, CheckPixelsInput006, TestSize.Level3)
1724 {
1725     GTEST_LOG_(INFO) << "ImagePixelMapTest: CheckPixelsInput006 start";
1726     // 8 means pixelmap width and height
1727     std::unique_ptr<PixelMap> pixelMap = CreatePixelMapCommon(8, 8);;
1728     ASSERT_NE(pixelMap.get(), nullptr);
1729     ImageInfo info;
1730     pixelMap->GetImageInfo(info);
1731 
1732     // 1 means bytecount
1733     uint8_t *source6 = static_cast<uint8_t *>(malloc(1));
1734     uint64_t size6 = static_cast<uint64_t>(pixelMap->GetByteCount());
1735     uint32_t stride6 = 0; // 0 means stride for test
1736     uint32_t offset6 = 0; // 0 means offset for test
1737     struct Rect region6 = {.left = 0, .top = 0, .width = info.size.width, .height = info.size.height};
1738     uint32_t status = 0;
1739     ASSERT_NE(source6, nullptr);
1740     ASSERT_NE(size6, 0);
1741     ASSERT_NE(region6.left < 0 ? 0 : 1, 0);
1742     ASSERT_NE(region6.top < 0 ? 0 : 1, 0);
1743     ASSERT_NE(stride6 > std::numeric_limits<int32_t>::max() ? 0 : 1, 0);
1744     ASSERT_NE(static_cast<uint64_t>(offset6) > size6 ? 0 : 1, 0);
1745 
1746     // INT32_MAX >> 2 means region max width/height
1747     int maxDimension = INT32_MAX >> 2;
1748     ASSERT_NE(region6.width < 0 ? 0 : 1, 0);
1749     ASSERT_NE(region6.height < 0 ? 0 : 1, 0);
1750     ASSERT_NE(region6.width > maxDimension ? 0 : 1, 0);
1751     ASSERT_NE(region6.height > maxDimension ? 0 : 1, 0);
1752     ASSERT_NE(region6.left > pixelMap->GetWidth() - region6.width ? 0 : 1, 0);
1753     ASSERT_NE(region6.top > pixelMap->GetHeight() - region6.height ? 0 : 1, 0);
1754     uint32_t regionStride = static_cast<uint32_t>(region6.width) * 4;
1755     stride6 = regionStride;
1756     ASSERT_NE(stride6 < regionStride ? 0 : 1, 0);
1757     ASSERT_NE(size6 < regionStride ? 0 : 1, 0);
1758     // 1 for test
1759     offset6 = static_cast<uint32_t>(size6 - regionStride) + 1;
1760     ASSERT_EQ(static_cast<uint64_t>(offset6) > (size6 - regionStride) ? 0 : 1, 0);
1761     status = pixelMap->WritePixels(source6, size6, offset6, stride6, region6);
1762     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1763     // 0 for test
1764     offset6 = 0;
1765     ASSERT_NE(static_cast<uint64_t>(offset6) > (size6 - regionStride) ? 0 : 1, 0);
1766     uint64_t lastLinePos = offset6 + static_cast<uint64_t>(region6.height - 1) * stride6;
1767     // 1 for test
1768     size6 = lastLinePos + regionStride - 1;
1769     ASSERT_EQ(lastLinePos > (size6  - regionStride) ? 0 : 1, 0);
1770     status = pixelMap->WritePixels(source6, size6, offset6, stride6, region6);
1771     ASSERT_EQ(status, ERR_IMAGE_INVALID_PARAMETER);
1772     size6 = static_cast<uint64_t>(pixelMap->GetByteCount());
1773     ASSERT_NE(lastLinePos > (size6  - regionStride) ? 0 : 1, 0);
1774     status = pixelMap->WritePixels(source6, size6, offset6, stride6, region6);
1775     ASSERT_NE(status, ERR_IMAGE_INVALID_PARAMETER);
1776     free(source6);
1777     GTEST_LOG_(INFO) << "ImagePixelMapTest: CheckPixelsInput006 end";
1778 }
1779 
1780 /**
1781 * @tc.name: SetAlpha001
1782 * @tc.desc: test SetAlpha
1783 * @tc.type: FUNC
1784 */
1785 HWTEST_F(ImagePixelMapTest, SetAlpha001, TestSize.Level3)
1786 {
1787     GTEST_LOG_(INFO) << "ImagePixelMapTest: SetAlpha001 start";
1788     // 64 means data length
1789     const uint32_t dataLength = 64;
1790     uint32_t data[64] = {0};
1791     InitializationOptions opts;
1792     opts.pixelFormat = OHOS::Media::PixelFormat::RGBA_F16;
1793     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
1794     opts.size.width = 8; // 8 means pielmap width
1795     opts.size.height = 8; // 8 means pielmap height
1796     std::unique_ptr<PixelMap> pixelmap = PixelMap::Create(data, dataLength, opts);
1797     ASSERT_NE(pixelmap.get(), nullptr);
1798 
1799     AlphaType alphaType = pixelmap->GetAlphaType();
1800     ASSERT_NE(alphaType, AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN);
1801     ASSERT_NE(alphaType, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE);
1802 
1803     float percent = 0.5f; // 0.5f means alpha value
1804     ASSERT_NE(percent <= 0 ? 0 : 1, 0);
1805     ASSERT_NE(percent > 1 ? 0 : 1, 0);
1806 
1807     ASSERT_EQ(pixelmap->GetPixelFormat(), PixelFormat::RGBA_F16);
1808 
1809     int8_t alphaIndex = 3; // 3 means alphaIndex
1810     ASSERT_NE(alphaIndex, -1);
1811 
1812     int32_t pixelByte = pixelmap->GetPixelBytes();
1813     ASSERT_EQ(pixelByte, 8); // 8 means pixelByte
1814     ASSERT_NE(pixelmap->GetPixelFormat(), PixelFormat::ALPHA_8);
1815 
1816     uint32_t pixelsSize = pixelmap->GetByteCount();
1817     ASSERT_EQ(pixelsSize > 0 ? 0 : 1, 0);
1818 
1819     uint32_t status = pixelmap->SetAlpha(percent);
1820     ASSERT_EQ(status, SUCCESS);
1821 
1822     ASSERT_EQ(alphaType, AlphaType::IMAGE_ALPHA_TYPE_PREMUL);
1823     GTEST_LOG_(INFO) << "ImagePixelMapTest: SetAlpha001 end";
1824 }
1825 
1826 /**
1827 * @tc.name: SetAlpha002
1828 * @tc.desc: test SetAlpha
1829 * @tc.type: FUNC
1830 */
1831 HWTEST_F(ImagePixelMapTest, SetAlpha002, TestSize.Level3)
1832 {
1833     GTEST_LOG_(INFO) << "ImagePixelMapTest: SetAlpha002 start";
1834     // 64 means data length
1835     const uint32_t dataLength = 64;
1836     uint32_t data[64] = {0};
1837     InitializationOptions opts;
1838     opts.pixelFormat = OHOS::Media::PixelFormat::ALPHA_8;
1839     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
1840     opts.size.width = 8; // 8 means pielmap width
1841     opts.size.height = 8; // 8 means pielmap height
1842     std::unique_ptr<PixelMap> pixelmap2 = PixelMap::Create(data, dataLength, opts);
1843     ASSERT_NE(pixelmap2.get(), nullptr);
1844 
1845     AlphaType alphaType = pixelmap2->GetAlphaType();
1846     ASSERT_NE(alphaType, AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN);
1847     ASSERT_NE(alphaType, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE);
1848 
1849     float percent = 0.8f; // 0.8f means alpha value
1850     ASSERT_NE(percent <= 0 ? 0 : 1, 0);
1851     ASSERT_NE(percent > 1 ? 0 : 1, 0);
1852 
1853     ASSERT_EQ(pixelmap2->GetPixelFormat(), PixelFormat::ALPHA_8);
1854 
1855     int8_t alphaIndex = 0; // 0 means alphaIndex
1856     ASSERT_NE(alphaIndex, -1);
1857 
1858     int32_t pixelByte = pixelmap2->GetPixelBytes();
1859     ASSERT_EQ(pixelByte, 1); // 1 means pixelByte
1860     ASSERT_NE(pixelmap2->GetPixelFormat(), PixelFormat::RGBA_F16);
1861 
1862     uint32_t pixelsSize = pixelmap2->GetByteCount();
1863     ASSERT_EQ(pixelsSize > 0 ? 0 : 1, 0);
1864 
1865     uint32_t status = pixelmap2->SetAlpha(percent);
1866     ASSERT_EQ(status, 0);
1867     ASSERT_EQ(alphaType, AlphaType::IMAGE_ALPHA_TYPE_PREMUL);
1868     GTEST_LOG_(INFO) << "ImagePixelMapTest: SetAlpha002 end";
1869 }
1870 
1871 /**
1872 * @tc.name: TlvEncode001
1873 * @tc.desc: test TlvEncode
1874 * @tc.type: FUNC
1875 */
1876 HWTEST_F(ImagePixelMapTest, TlvEncode001, TestSize.Level3)
1877 {
1878     GTEST_LOG_(INFO) << "ImagePixelMapTest: TlvEncode001 start";
1879     // 8 means pixelmap width and height
1880     std::unique_ptr<PixelMap> pixelMap = CreatePixelMapCommon(8, 8);;
1881     ASSERT_NE(pixelMap.get(), nullptr);
1882 
1883     std::vector<uint8_t> buff;
1884     bool success = pixelMap->EncodeTlv(buff);
1885     ASSERT_EQ(success, true);
1886 
1887     PixelMap *pixelMap2 = PixelMap::DecodeTlv(buff);
1888     ASSERT_NE(pixelMap2, nullptr);
1889 
1890     GTEST_LOG_(INFO) << "ImagePixelMapTest: TlvEncode001 end";
1891 }
1892 
1893 /**
1894  * @tc.name: TransformData001
1895  * @tc.desc: ASTC transform test
1896  * @tc.type: FUNC
1897  */
1898 HWTEST_F(ImagePixelMapTest, TransformData001, TestSize.Level3)
1899 {
1900     GTEST_LOG_(INFO) << "ImagePixelMapTest: TransformData001 start";
1901     // 3 means bytesPerPixel
1902     int8_t bytesPerPixel = 3;
1903     int8_t rowDataSize = PIXEL_MAP_TEST_WIDTH * bytesPerPixel;
1904     ImageInfo imgInfo;
1905     imgInfo.size.width = PIXEL_MAP_TEST_WIDTH;
1906     imgInfo.size.height = PIXEL_MAP_TEST_HEIGHT;
1907     imgInfo.pixelFormat = PixelFormat::RGB_888;
1908     imgInfo.colorSpace = ColorSpace::SRGB;
1909     PixelMap pixelMap;
1910     pixelMap.SetImageInfo(imgInfo);
1911     uint32_t pixelsSize = rowDataSize * PIXEL_MAP_TEST_HEIGHT;
1912     void *buffer = malloc(pixelsSize);
1913     EXPECT_NE(buffer, nullptr);
1914     pixelMap.SetPixelsAddr(buffer, nullptr, pixelsSize, AllocatorType::HEAP_ALLOC, nullptr);
1915     // {1.5, 1.5, 0, -1, -1, -1, -1, 0, 0, false, false} means astc transform data
1916     TransformData transformData = {1.5, 1.5, 0, -1, -1, -1, -1, 0, 0, false, false};
1917     pixelMap.SetTransformData(transformData);
1918     TransformData transformData2;
1919     pixelMap.GetTransformData(transformData2);
1920     EXPECT_EQ(transformData2.scaleX, transformData.scaleX);
1921     EXPECT_EQ(transformData2.scaleY, transformData.scaleY);
1922     EXPECT_EQ(transformData2.flipX, transformData.flipX);
1923     EXPECT_EQ(transformData2.flipY, transformData.flipY);
1924     GTEST_LOG_(INFO) << "ImagePixelMapTest: TransformData001 end";
1925 }
1926 
1927 /**
1928  * @tc.name: ModifyImageProperty001
1929  * @tc.desc: ModifyImageProperty test
1930  * @tc.type: FUNC
1931  */
1932 HWTEST_F(ImagePixelMapTest, ModifyImageProperty001, TestSize.Level3)
1933 {
1934     GTEST_LOG_(INFO) << "ImagePixelMapTest: ModifyImageProperty001 start";
1935     uint32_t errorCode = 0;
1936     SourceOptions opts;
1937     opts.formatHint = "image/jpeg";
1938     std::string path = "/data/local/tmp/image/test_exif.jpg";
1939     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(path, opts, errorCode);
1940     ASSERT_EQ(errorCode, SUCCESS);
1941 
1942     DecodeOptions decopts;
1943     uint32_t ret = SUCCESS;
1944     auto pixelMap = imageSource->CreatePixelMap(decopts, ret);
1945     ASSERT_EQ(ret, SUCCESS);
1946 
1947     std::string key = "Model";
1948     std::string imagesource_org_value = "TNY-AL00";
1949     pixelMap->ModifyImageProperty(key, "Test");
1950     std::string getValue;
1951     pixelMap->GetImagePropertyString(key, getValue);
1952     EXPECT_EQ(getValue, "Test");
1953     imageSource->GetImagePropertyString(0, key, getValue);
1954     EXPECT_EQ(getValue, imagesource_org_value);
1955     GTEST_LOG_(INFO) << "ImagePixelMapTest: ModifyImageProperty001 end";
1956 }
1957 
ConstructSLRPixelMap(uint32_t ** dataIn)1958 std::unique_ptr<PixelMap> ConstructSLRPixelMap(uint32_t** dataIn)
1959 {
1960     const uint32_t dataLength = PIXEL_MAP_TEST_WIDTH * PIXEL_MAP_TEST_HEIGHT;
1961     uint32_t* data = new uint32_t[dataLength];
1962     for (uint32_t i = 0; i < dataLength; i++) {
1963         data[i] = 0xFFFF0000;
1964     }
1965     InitializationOptions opts;
1966     opts.pixelFormat = OHOS::Media::PixelFormat::RGBA_8888;
1967     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
1968     opts.size.width = PIXEL_MAP_TEST_WIDTH;
1969     opts.size.height = PIXEL_MAP_TEST_HEIGHT;
1970     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
1971     *dataIn = data;
1972     return pixelMap;
1973 }
1974 
ConstructSLRBigPixmap()1975 std::unique_ptr<PixelMap> ConstructSLRBigPixmap()
1976 {
1977     int32_t pixelMapWidth = PIXEL_MAP_BIG_TEST_WIDTH;
1978     int32_t pixelMapHeight = PIXEL_MAP_BIG_TEST_HEIGHT;
1979     std::unique_ptr<PixelMap> pixelMap = std::make_unique<PixelMap>();
1980     ImageInfo info;
1981     info.size.width = pixelMapWidth;
1982     info.size.height = pixelMapHeight;
1983     info.pixelFormat = PixelFormat::RGBA_8888;
1984     info.colorSpace = ColorSpace::SRGB;
1985     pixelMap->SetImageInfo(info);
1986 
1987     int32_t bufferSize = pixelMap->GetByteCount();
1988     if (bufferSize <= 0) {
1989         return nullptr;
1990     }
1991     void *buffer = malloc(bufferSize);
1992     if (buffer == nullptr) {
1993         return nullptr;
1994     }
1995     char *ch = reinterpret_cast<char *>(buffer);
1996     for (int32_t i = 0; i < bufferSize; i++) {
1997         *(ch++) = 'a';
1998     }
1999 
2000     pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
2001     return pixelMap;
2002 }
2003 
2004 /**
2005 * @tc.name: ImagePixelMapSLR001
2006 * @tc.desc: test SLR
2007 * @tc.type: FUNC
2008 */
2009 HWTEST_F(ImagePixelMapTest, ImagePixelMapSLR001, TestSize.Level3)
2010 {
2011     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMapSLR001 scale start";
2012     uint32_t* data = nullptr;
2013     std::unique_ptr<PixelMap> pixelMap = ConstructSLRPixelMap(&data);
2014     EXPECT_NE(pixelMap, nullptr);
2015     float xAxis = 1.5f; // 1.5f scale test
2016     float yAxis = 1.8f; // 1.8f scale test
2017     pixelMap->scale(xAxis, yAxis, AntiAliasingOption::SLR);
2018     ImageInfo outInfo;
2019     pixelMap->GetImageInfo(outInfo);
2020     int32_t width = PIXEL_MAP_TEST_WIDTH * xAxis;
2021     int32_t height = PIXEL_MAP_TEST_HEIGHT * yAxis;
2022     EXPECT_EQ(width, outInfo.size.width);
2023     EXPECT_EQ(height, outInfo.size.height);
2024     if (data != nullptr) {
2025         delete[] data;
2026         data = nullptr;
2027     }
2028     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMapSLR001 scale end";
2029 }
2030 
2031 /**
2032 * @tc.name: ImagePixelMapSLR002
2033 * @tc.desc: test SLR
2034 * @tc.type: FUNC
2035 */
2036 HWTEST_F(ImagePixelMapTest, ImagePixelMapSLR002, TestSize.Level3)
2037 {
2038     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMapSLR002 scale start";
2039     std::unique_ptr<PixelMap> pixelMap = ConstructSLRBigPixmap();
2040     EXPECT_NE(pixelMap, nullptr);
2041     float xAxis = 0.7f; // 0.7f scale test
2042     float yAxis = 0.9f; // 0.9f scale test
2043     pixelMap->scale(xAxis, yAxis, AntiAliasingOption::SLR);
2044     ImageInfo outInfo;
2045     pixelMap->GetImageInfo(outInfo);
2046     int32_t width = PIXEL_MAP_BIG_TEST_WIDTH * xAxis;
2047     int32_t height = PIXEL_MAP_BIG_TEST_HEIGHT * yAxis;
2048     EXPECT_EQ(width, outInfo.size.width);
2049     EXPECT_EQ(height, outInfo.size.height);
2050     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMapSLR002 scale end";
2051 }
2052 
2053 /**
2054 * @tc.name: ImagePixelMapSLR003
2055 * @tc.desc: test SLR invalid param
2056 * @tc.type: FUNC
2057 */
2058 HWTEST_F(ImagePixelMapTest, ImagePixelMapSLR003, TestSize.Level3)
2059 {
2060     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMapSLR003 scale start";
2061     uint32_t* data = nullptr;
2062     std::unique_ptr<PixelMap> pixelMap = ConstructSLRPixelMap(&data);
2063     EXPECT_NE(pixelMap, nullptr);
2064     float xAxis = .0f; // .0f invalid scale size
2065     float yAxis = .0f; // .0f invalid scale size
2066     pixelMap->scale(xAxis, yAxis, AntiAliasingOption::SLR);
2067     ImageInfo outInfo;
2068     pixelMap->GetImageInfo(outInfo);
2069     int32_t width = PIXEL_MAP_TEST_WIDTH;
2070     int32_t height = PIXEL_MAP_TEST_HEIGHT;
2071     EXPECT_EQ(width, outInfo.size.width);
2072     EXPECT_EQ(height, outInfo.size.height);
2073     if (data != nullptr) {
2074         delete[] data;
2075         data = nullptr;
2076     }
2077     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMapSLR003 scale end";
2078 }
2079 
2080 /**
2081 * @tc.name: ImagePixelMapSLR004
2082 * @tc.desc: test SLR invalid param
2083 * @tc.type: FUNC
2084 */
2085 HWTEST_F(ImagePixelMapTest, ImagePixelMapSLR004, TestSize.Level3)
2086 {
2087     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMapSLR004 scale start";
2088     uint32_t* data = nullptr;
2089     std::unique_ptr<PixelMap> pixelMap = ConstructSLRPixelMap(&data);
2090     EXPECT_NE(pixelMap, nullptr);
2091     float xAxis = -1.0f; // -1.0f invalid scale size
2092     float yAxis = -2.0f; // -2.0f invalid scale size
2093     pixelMap->scale(xAxis, yAxis, AntiAliasingOption::SLR);
2094     ImageInfo outInfo;
2095     pixelMap->GetImageInfo(outInfo);
2096     int32_t width = PIXEL_MAP_TEST_WIDTH;
2097     int32_t height = PIXEL_MAP_TEST_HEIGHT;
2098     EXPECT_EQ(width, outInfo.size.width);
2099     EXPECT_EQ(height, outInfo.size.height);
2100     if (data != nullptr) {
2101         delete[] data;
2102         data = nullptr;
2103     }
2104     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMapSLR004 scale end";
2105 }
2106 
2107 /**
2108 * @tc.name: ImagePixelMapSLR005
2109 * @tc.desc: test SLR invalid param
2110 * @tc.type: FUNC
2111 */
2112 HWTEST_F(ImagePixelMapTest, ImagePixelMapSLR005, TestSize.Level3)
2113 {
2114     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMapSLR005 scale start";
2115     uint32_t* data = nullptr;
2116     std::unique_ptr<PixelMap> pixelMap = ConstructSLRPixelMap(&data);
2117     EXPECT_NE(pixelMap, nullptr);
2118     float xAxis = static_cast<float>(INT32_MAX) / PIXEL_MAP_TEST_WIDTH;
2119     float yAxis = static_cast<float>(INT32_MAX) / PIXEL_MAP_TEST_HEIGHT;
2120     pixelMap->scale(xAxis, yAxis, AntiAliasingOption::SLR);
2121     ImageInfo outInfo;
2122     pixelMap->GetImageInfo(outInfo);
2123     int32_t width = PIXEL_MAP_TEST_WIDTH;
2124     int32_t height = PIXEL_MAP_TEST_HEIGHT;
2125     EXPECT_EQ(width, outInfo.size.width);
2126     EXPECT_EQ(height, outInfo.size.height);
2127     if (data != nullptr) {
2128         delete[] data;
2129         data = nullptr;
2130     }
2131     GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMapSLR005 scale end";
2132 }
2133 } // namespace Multimedia
2134 } // namespace OHOS
2135