1/*
2 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 <vector>
17#include "gtest/gtest.h"
18#include "image/pixelmap_native.h"
19
20using namespace std;
21
22OH_PixelmapNative *GET_OH_PixelmapNative()
23{
24    OH_Pixelmap_InitializationOptions *options = nullptr;
25    OH_PixelmapNative *pixelMap = nullptr;
26    OH_PixelmapInitializationOptions_Create(&options);
27    // 4 means width
28    uint32_t width = 4;
29    OH_PixelmapInitializationOptions_SetWidth(options, width);
30    // 4 means height
31    uint32_t height = 4;
32    OH_PixelmapInitializationOptions_SetHeight(options, height);
33    // 4 means RGBA format
34    int32_t pixelFormat = 3;
35    OH_PixelmapInitializationOptions_SetPixelFormat(options, pixelFormat);
36    // 2 means ALPHA_FORMAT_PREMUL format
37    int32_t alphaType = 2;
38    OH_PixelmapInitializationOptions_SetAlphaType(options, alphaType);
39    // 255 means rgba data
40    uint8_t data[] = {255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255};
41    // 16 means data length
42    size_t dataLength = 16;
43    OH_PixelmapNative_CreatePixelmap(data, dataLength, options, &pixelMap);
44    OH_PixelmapInitializationOptions_Release(options);
45    return pixelMap;
46}
47
48OH_PixelmapNative *GET_OH_PixelmapNative(
49    uint32_t width, uint32_t height)
50{
51    OH_Pixelmap_InitializationOptions *options = nullptr;
52    OH_PixelmapNative *pixelMap = nullptr;
53    OH_PixelmapInitializationOptions_Create(&options);
54    OH_PixelmapInitializationOptions_SetWidth(options, width);
55    OH_PixelmapInitializationOptions_SetHeight(options, height);
56    // 4 means RGBA format
57    int32_t pixelFormat = 3;
58    OH_PixelmapInitializationOptions_SetPixelFormat(options, pixelFormat);
59    // 2 means ALPHA_FORMAT_PREMUL format
60    int32_t alphaType = 2;
61    OH_PixelmapInitializationOptions_SetAlphaType(options, alphaType);
62    // 255 means rgba data
63    uint8_t data[] = {255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255};
64    // 16 means data length
65    size_t dataLength = 16;
66    OH_PixelmapNative_CreatePixelmap(data, dataLength, options, &pixelMap);
67    OH_PixelmapInitializationOptions_Release(options);
68    return pixelMap;
69}
70
71OH_PixelmapNative *GET_OH_PixelmapNative4KBoundary()
72{
73    OH_Pixelmap_InitializationOptions *options = nullptr;
74    OH_PixelmapNative *pixelMap = nullptr;
75    OH_PixelmapInitializationOptions_Create(&options);
76    // 4096 means width
77    uint32_t width = 4096;
78    OH_PixelmapInitializationOptions_SetWidth(options, width);
79    // 2160 means height
80    uint32_t height = 2160;
81    OH_PixelmapInitializationOptions_SetHeight(options, height);
82    // 3 means RGBA format
83    int32_t pixelFormat = 3;
84    OH_PixelmapInitializationOptions_SetPixelFormat(options, pixelFormat);
85    // 2 means ALPHA_FORMAT_PREMUL format
86    int32_t alphaType = 2;
87    OH_PixelmapInitializationOptions_SetAlphaType(options, alphaType);
88    // 255/0 means rgba data
89    vector<uint8_t> data;
90    uint8_t value[] = {255, 255, 0, 255};
91    size_t repeatTimes = 4096 * 2160 / 4;
92    uint8_t *valueData = nullptr;
93
94    for (size_t i = 0; i < repeatTimes; ++i) {
95        data.insert(data.end(), begin(value), end(value));
96        valueData = data.data();
97    }
98
99    // 4096 * 2160 means data length
100    size_t dataLength = 4096 * 2160;
101    OH_PixelmapNative_CreatePixelmap(valueData, dataLength, options, &pixelMap);
102    OH_PixelmapInitializationOptions_Release(options);
103    return pixelMap;
104}
105