1 /*
2  * Copyright (c) 2020-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 #ifndef GRAPHIC_LITE_PIXEL_FORMAT_UTILS
17 #define GRAPHIC_LITE_PIXEL_FORMAT_UTILS
18 
19 #include <stdint.h>
20 
21 namespace OHOS {
22 union PF_ARGB1555 {
23     struct {
24         uint16_t blue : 5;
25         uint16_t green : 5;
26         uint16_t red : 5;
27         uint16_t alpha : 1;
28     };
29     uint16_t full;
30 };
31 
32 union PF_ARGB8888 {
33     struct {
34         uint32_t blue : 8;
35         uint32_t green : 8;
36         uint32_t red : 8;
37         uint32_t alpha : 8;
38     };
39     uint32_t full;
40 };
41 
42 /**
43  * @brief Enumerates a pixel format.
44  */
45 enum ImagePixelFormat {
46     /** Invalid pixel format */
47     IMAGE_PIXEL_FORMAT_NONE = 0,
48     /** RGB565 pixel format */
49     IMAGE_PIXEL_FORMAT_RGB565 = 101,
50     /** ARGB555 pixel format */
51     IMAGE_PIXEL_FORMAT_ARGB1555,
52     /** RGB888 pixel format */
53     IMAGE_PIXEL_FORMAT_RGB888,
54     /** ARGB8888 pixel format */
55     IMAGE_PIXEL_FORMAT_ARGB8888,
56     /** YUYV pixel format */
57     IMAGE_PIXEL_FORMAT_YUYV = 201,
58     /** YVYU pixel format */
59     IMAGE_PIXEL_FORMAT_YVYU,
60     /** UYVY pixel format */
61     IMAGE_PIXEL_FORMAT_UYVY,
62     /** VYUY pixel format */
63     IMAGE_PIXEL_FORMAT_VYUY,
64     /** AYUV pixel format */
65     IMAGE_PIXEL_FORMAT_AYUV,
66     /** YUV410 pixel format */
67     IMAGE_PIXEL_FORMAT_YUV410,
68     /** YVU410 pixel format */
69     IMAGE_PIXEL_FORMAT_YVU410,
70     /** YUV411 pixel format */
71     IMAGE_PIXEL_FORMAT_YUV411,
72     /** YVU411 pixel format */
73     IMAGE_PIXEL_FORMAT_YVU411,
74     /** YUV420 pixel format */
75     IMAGE_PIXEL_FORMAT_YUV420,
76     /** YVU420 pixel format */
77     IMAGE_PIXEL_FORMAT_YVU420,
78     /** YUV422 pixel format */
79     IMAGE_PIXEL_FORMAT_YUV422,
80     /** YVU422 pixel format */
81     IMAGE_PIXEL_FORMAT_YVU422,
82     /** YUV444 pixel format */
83     IMAGE_PIXEL_FORMAT_YUV444,
84     /** YVU444 pixel format */
85     IMAGE_PIXEL_FORMAT_YVU444,
86     /** NV12 pixel format */
87     IMAGE_PIXEL_FORMAT_NV12 = 301,
88     /** NV21 pixel format */
89     IMAGE_PIXEL_FORMAT_NV21,
90     /** NV16 pixel format */
91     IMAGE_PIXEL_FORMAT_NV16,
92     /** NV61 pixel format */
93     IMAGE_PIXEL_FORMAT_NV61
94 };
95 
96 class PixelFormatUtils {
97 public:
98     static bool BppOfPixelFormat(ImagePixelFormat pixelFormat, int16_t& bpp);
99     static uint16_t ARGB8888ToARGB1555(uint32_t color);
100     static uint32_t ARGB1555ToARGB8888(uint16_t color);
101 };
102 } // namespace OHOS
103 #endif
104