Warning: That file was not part of the compilation database. It may have many parsing errors.

1/*
2 * Copyright (C) 2005 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef EXTRACT_H
18#define EXTRACT_H
19
20#include <cstdint>
21#include <cstring>
22// shamelessly stolen from ResourceTypes.h Android's sources
23/**
24 * This chunk specifies how to split an image into segments for
25 * scaling.
26 *
27 * There are J horizontal and K vertical segments. These segments divide
28 * the image into J*K regions as follows (where J=4 and K=3):
29 *
30 * F0 S0 F1 S1
31 * +-----+----+------+-------+
32 * S2| 0 | 1 | 2 | 3 |
33 * +-----+----+------+-------+
34 * | | | | |
35 * | | | | |
36 * F2| 4 | 5 | 6 | 7 |
37 * | | | | |
38 * | | | | |
39 * +-----+----+------+-------+
40 * S3| 8 | 9 | 10 | 11 |
41 * +-----+----+------+-------+
42 *
43 * Each horizontal and vertical segment is considered to by either
44 * stretchable (marked by the Sx labels) or fixed (marked by the Fy
45 * labels), in the horizontal or vertical axis, respectively. In the
46 * above example, the first is horizontal segment (F0) is fixed, the
47 * next is stretchable and then they continue to alternate. Note that
48 * the segment list for each axis can begin or end with a stretchable
49 * or fixed segment.
50 *
51 * The relative sizes of the stretchy segments indicates the relative
52 * amount of stretchiness of the regions bordered by the segments. For
53 * example, regions 3, 7 and 11 above will take up more horizontal space
54 * than regions 1, 5 and 9 since the horizontal segment associated with
55 * the first set of regions is larger than the other set of regions. The
56 * ratios of the amount of horizontal (or vertical) space taken by any
57 * two stretchable slices is exactly the ratio of their corresponding
58 * segment lengths.
59 *
60 * xDivs and yDivs point to arrays of horizontal and vertical pixel
61 * indices. The first pair of Divs (in either array) indicate the
62 * starting and ending points of the first stretchable segment in that
63 * axis. The next pair specifies the next stretchable segment, etc. So
64 * in the above example xDiv[0] and xDiv[1] specify the horizontal
65 * coordinates for the regions labeled 1, 5 and 9. xDiv[2] and
66 * xDiv[3] specify the coordinates for regions 3, 7 and 11. Note that
67 * the leftmost slices always start at x=0 and the rightmost slices
68 * always end at the end of the image. So, for example, the regions 0,
69 * 4 and 8 (which are fixed along the X axis) start at x value 0 and
70 * go to xDiv[0] and slices 2, 6 and 10 start at xDiv[1] and end at
71 * xDiv[2].
72 *
73 * The array pointed to by the colors field lists contains hints for
74 * each of the regions. They are ordered according left-to-right and
75 * top-to-bottom as indicated above. For each segment that is a solid
76 * color the array entry will contain that color value; otherwise it
77 * will contain NO_COLOR. Segments that are completely transparent
78 * will always have the value TRANSPARENT_COLOR.
79 *
80 * The PNG chunk type is "npTc".
81 */
82struct Res_png_9patch
83{
84 Res_png_9patch() : wasDeserialized(false), xDivs(NULL),
85 yDivs(NULL), colors(NULL) { }
86
87 int8_t wasDeserialized;
88 int8_t numXDivs;
89 int8_t numYDivs;
90 int8_t numColors;
91
92 // These tell where the next section of a patch starts.
93 // For example, the first patch includes the pixels from
94 // 0 to xDivs[0]-1 and the second patch includes the pixels
95 // from xDivs[0] to xDivs[1]-1.
96 // Note: allocation/free of these pointers is left to the caller.
97 int32_t* xDivs;
98 int32_t* yDivs;
99
100 int32_t paddingLeft, paddingRight;
101 int32_t paddingTop, paddingBottom;
102
103 enum {
104 // The 9 patch segment is not a solid color.
105 NO_COLOR = 0x00000001,
106
107 // The 9 patch segment is completely transparent.
108 TRANSPARENT_COLOR = 0x00000000
109 };
110 // Note: allocation/free of this pointer is left to the caller.
111 uint32_t* colors;
112
113 // Deserialize/Unmarshall the patch data
114 static Res_png_9patch* deserialize(const void* data);
115};
116
117struct Res_png_9patch20
118{
119 Res_png_9patch20() : wasDeserialized(false), numXDivs(0), numYDivs(0), numColors(0), xDivsOffset(0),
120 yDivsOffset(0),paddingLeft(0), paddingRight(0), paddingTop(0), paddingBottom(0),
121 colorsOffset(0) { }
122
123 int8_t wasDeserialized;
124 int8_t numXDivs;
125 int8_t numYDivs;
126 int8_t numColors;
127
128 // The offset (from the start of this structure) to the xDivs & yDivs
129 // array for this 9patch. To get a pointer to this array, call
130 // getXDivs or getYDivs. Note that the serialized form for 9patches places
131 // the xDivs, yDivs and colors arrays immediately after the location
132 // of the Res_png_9patch struct.
133 uint32_t xDivsOffset;
134 uint32_t yDivsOffset;
135
136 int32_t paddingLeft, paddingRight;
137 int32_t paddingTop, paddingBottom;
138
139 enum {
140 // The 9 patch segment is not a solid color.
141 NO_COLOR = 0x00000001,
142
143 // The 9 patch segment is completely transparent.
144 TRANSPARENT_COLOR = 0x00000000
145 };
146
147 // The offset (from the start of this structure) to the colors array
148 // for this 9patch.
149 uint32_t colorsOffset;
150
151 // Deserialize/Unmarshall the patch data
152 static Res_png_9patch20* deserialize(void* data);
153
154 // These tell where the next section of a patch starts.
155 // For example, the first patch includes the pixels from
156 // 0 to xDivs[0]-1 and the second patch includes the pixels
157 // from xDivs[0] to xDivs[1]-1.
158 inline int32_t* getXDivs() const {
159 return reinterpret_cast<int32_t*>(reinterpret_cast<uintptr_t>(this) + xDivsOffset);
160 }
161 inline int32_t* getYDivs() const {
162 return reinterpret_cast<int32_t*>(reinterpret_cast<uintptr_t>(this) + yDivsOffset);
163 }
164 inline uint32_t* getColors() const {
165 return reinterpret_cast<uint32_t*>(reinterpret_cast<uintptr_t>(this) + colorsOffset);
166 }
167
168} __attribute__((packed));
169
170#endif
171

Warning: That file was not part of the compilation database. It may have many parsing errors.