1f6603c60Sopenharmony_ci/*
2f6603c60Sopenharmony_ci * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License.
5f6603c60Sopenharmony_ci * You may obtain a copy of the License at
6f6603c60Sopenharmony_ci *
7f6603c60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8f6603c60Sopenharmony_ci *
9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and
13f6603c60Sopenharmony_ci * limitations under the License.
14f6603c60Sopenharmony_ci */
15f6603c60Sopenharmony_ci
16f6603c60Sopenharmony_ci#include <vector>
17f6603c60Sopenharmony_ci#include "gtest/gtest.h"
18f6603c60Sopenharmony_ci#include "image/pixelmap_native.h"
19f6603c60Sopenharmony_ci
20f6603c60Sopenharmony_ciusing namespace std;
21f6603c60Sopenharmony_ci
22f6603c60Sopenharmony_ciOH_PixelmapNative *GET_OH_PixelmapNative()
23f6603c60Sopenharmony_ci{
24f6603c60Sopenharmony_ci    OH_Pixelmap_InitializationOptions *options = nullptr;
25f6603c60Sopenharmony_ci    OH_PixelmapNative *pixelMap = nullptr;
26f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_Create(&options);
27f6603c60Sopenharmony_ci    // 4 means width
28f6603c60Sopenharmony_ci    uint32_t width = 4;
29f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_SetWidth(options, width);
30f6603c60Sopenharmony_ci    // 4 means height
31f6603c60Sopenharmony_ci    uint32_t height = 4;
32f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_SetHeight(options, height);
33f6603c60Sopenharmony_ci    // 4 means RGBA format
34f6603c60Sopenharmony_ci    int32_t pixelFormat = 3;
35f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_SetPixelFormat(options, pixelFormat);
36f6603c60Sopenharmony_ci    // 2 means ALPHA_FORMAT_PREMUL format
37f6603c60Sopenharmony_ci    int32_t alphaType = 2;
38f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_SetAlphaType(options, alphaType);
39f6603c60Sopenharmony_ci    // 255 means rgba data
40f6603c60Sopenharmony_ci    uint8_t data[] = {255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255};
41f6603c60Sopenharmony_ci    // 16 means data length
42f6603c60Sopenharmony_ci    size_t dataLength = 16;
43f6603c60Sopenharmony_ci    OH_PixelmapNative_CreatePixelmap(data, dataLength, options, &pixelMap);
44f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_Release(options);
45f6603c60Sopenharmony_ci    return pixelMap;
46f6603c60Sopenharmony_ci}
47f6603c60Sopenharmony_ci
48f6603c60Sopenharmony_ciOH_PixelmapNative *GET_OH_PixelmapNative(
49f6603c60Sopenharmony_ci    uint32_t width, uint32_t height)
50f6603c60Sopenharmony_ci{
51f6603c60Sopenharmony_ci    OH_Pixelmap_InitializationOptions *options = nullptr;
52f6603c60Sopenharmony_ci    OH_PixelmapNative *pixelMap = nullptr;
53f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_Create(&options);
54f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_SetWidth(options, width);
55f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_SetHeight(options, height);
56f6603c60Sopenharmony_ci    // 4 means RGBA format
57f6603c60Sopenharmony_ci    int32_t pixelFormat = 3;
58f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_SetPixelFormat(options, pixelFormat);
59f6603c60Sopenharmony_ci    // 2 means ALPHA_FORMAT_PREMUL format
60f6603c60Sopenharmony_ci    int32_t alphaType = 2;
61f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_SetAlphaType(options, alphaType);
62f6603c60Sopenharmony_ci    // 255 means rgba data
63f6603c60Sopenharmony_ci    uint8_t data[] = {255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255};
64f6603c60Sopenharmony_ci    // 16 means data length
65f6603c60Sopenharmony_ci    size_t dataLength = 16;
66f6603c60Sopenharmony_ci    OH_PixelmapNative_CreatePixelmap(data, dataLength, options, &pixelMap);
67f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_Release(options);
68f6603c60Sopenharmony_ci    return pixelMap;
69f6603c60Sopenharmony_ci}
70f6603c60Sopenharmony_ci
71f6603c60Sopenharmony_ciOH_PixelmapNative *GET_OH_PixelmapNative4KBoundary()
72f6603c60Sopenharmony_ci{
73f6603c60Sopenharmony_ci    OH_Pixelmap_InitializationOptions *options = nullptr;
74f6603c60Sopenharmony_ci    OH_PixelmapNative *pixelMap = nullptr;
75f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_Create(&options);
76f6603c60Sopenharmony_ci    // 4096 means width
77f6603c60Sopenharmony_ci    uint32_t width = 4096;
78f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_SetWidth(options, width);
79f6603c60Sopenharmony_ci    // 2160 means height
80f6603c60Sopenharmony_ci    uint32_t height = 2160;
81f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_SetHeight(options, height);
82f6603c60Sopenharmony_ci    // 3 means RGBA format
83f6603c60Sopenharmony_ci    int32_t pixelFormat = 3;
84f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_SetPixelFormat(options, pixelFormat);
85f6603c60Sopenharmony_ci    // 2 means ALPHA_FORMAT_PREMUL format
86f6603c60Sopenharmony_ci    int32_t alphaType = 2;
87f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_SetAlphaType(options, alphaType);
88f6603c60Sopenharmony_ci    // 255/0 means rgba data
89f6603c60Sopenharmony_ci    vector<uint8_t> data;
90f6603c60Sopenharmony_ci    uint8_t value[] = {255, 255, 0, 255};
91f6603c60Sopenharmony_ci    size_t repeatTimes = 4096 * 2160 / 4;
92f6603c60Sopenharmony_ci    uint8_t *valueData = nullptr;
93f6603c60Sopenharmony_ci
94f6603c60Sopenharmony_ci    for (size_t i = 0; i < repeatTimes; ++i) {
95f6603c60Sopenharmony_ci        data.insert(data.end(), begin(value), end(value));
96f6603c60Sopenharmony_ci        valueData = data.data();
97f6603c60Sopenharmony_ci    }
98f6603c60Sopenharmony_ci
99f6603c60Sopenharmony_ci    // 4096 * 2160 means data length
100f6603c60Sopenharmony_ci    size_t dataLength = 4096 * 2160;
101f6603c60Sopenharmony_ci    OH_PixelmapNative_CreatePixelmap(valueData, dataLength, options, &pixelMap);
102f6603c60Sopenharmony_ci    OH_PixelmapInitializationOptions_Release(options);
103f6603c60Sopenharmony_ci    return pixelMap;
104f6603c60Sopenharmony_ci}
105