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 #ifndef PNG_NINEPATCH_RES_H
17 #define PNG_NINEPATCH_RES_H
18 
19 #include <cstdint>
20 #include <cstdio>
21 
22 namespace OHOS {
23 namespace ImagePlugin {
alignas(uintptr_t)24 struct alignas(uintptr_t) PngNinePatchRes {
25     PngNinePatchRes() : wasDeserialized(false), xDivsOffset(0), yDivsOffset(0), colorsOffset(0)
26     {}
27     ~PngNinePatchRes() = default;
28     void DeviceToFile();
29     void FileToDevice();
30     static PngNinePatchRes *Deserialize(void *data);
31     size_t SerializedSize() const;
32     inline int32_t *GetXDivs() const
33     {
34         return reinterpret_cast<int32_t *>(reinterpret_cast<uintptr_t>(this) + xDivsOffset);
35     }
36     inline int32_t *GetYDivs() const
37     {
38         return reinterpret_cast<int32_t *>(reinterpret_cast<uintptr_t>(this) + yDivsOffset);
39     }
40     inline uint32_t *GetColors() const
41     {
42         return reinterpret_cast<uint32_t *>(reinterpret_cast<uintptr_t>(this) + colorsOffset);
43     }
44     int8_t wasDeserialized;
45     uint8_t numXDivs;
46     uint8_t numYDivs;
47     uint8_t numColors;
48     uint32_t xDivsOffset;
49     uint32_t yDivsOffset;
50     int32_t paddingLeft;
51     int32_t paddingRight;
52     int32_t paddingTop;
53     int32_t paddingBottom;
54     // The offset (from the start of this structure) to the colors array
55     uint32_t colorsOffset;
56 } __attribute__((packed));
57 } // namespace ImagePlugin
58 } // namespace OHOS
59 #endif // PNG_NINEPATCH_RES_H
60