1*61046927SAndroid Build Coastguard Worker // [DEAR IMGUI]
2*61046927SAndroid Build Coastguard Worker // This is a slightly modified version of stb_rect_pack.h 0.99.
3*61046927SAndroid Build Coastguard Worker // Those changes would need to be pushed into nothings/stb:
4*61046927SAndroid Build Coastguard Worker // - Added STBRP__CDECL
5*61046927SAndroid Build Coastguard Worker // Grep for [DEAR IMGUI] to find the changes.
6*61046927SAndroid Build Coastguard Worker
7*61046927SAndroid Build Coastguard Worker // stb_rect_pack.h - v0.99 - public domain - rectangle packing
8*61046927SAndroid Build Coastguard Worker // Sean Barrett 2014
9*61046927SAndroid Build Coastguard Worker //
10*61046927SAndroid Build Coastguard Worker // Useful for e.g. packing rectangular textures into an atlas.
11*61046927SAndroid Build Coastguard Worker // Does not do rotation.
12*61046927SAndroid Build Coastguard Worker //
13*61046927SAndroid Build Coastguard Worker // Not necessarily the awesomest packing method, but better than
14*61046927SAndroid Build Coastguard Worker // the totally naive one in stb_truetype (which is primarily what
15*61046927SAndroid Build Coastguard Worker // this is meant to replace).
16*61046927SAndroid Build Coastguard Worker //
17*61046927SAndroid Build Coastguard Worker // Has only had a few tests run, may have issues.
18*61046927SAndroid Build Coastguard Worker //
19*61046927SAndroid Build Coastguard Worker // More docs to come.
20*61046927SAndroid Build Coastguard Worker //
21*61046927SAndroid Build Coastguard Worker // No memory allocations; uses qsort() and assert() from stdlib.
22*61046927SAndroid Build Coastguard Worker // Can override those by defining STBRP_SORT and STBRP_ASSERT.
23*61046927SAndroid Build Coastguard Worker //
24*61046927SAndroid Build Coastguard Worker // This library currently uses the Skyline Bottom-Left algorithm.
25*61046927SAndroid Build Coastguard Worker //
26*61046927SAndroid Build Coastguard Worker // Please note: better rectangle packers are welcome! Please
27*61046927SAndroid Build Coastguard Worker // implement them to the same API, but with a different init
28*61046927SAndroid Build Coastguard Worker // function.
29*61046927SAndroid Build Coastguard Worker //
30*61046927SAndroid Build Coastguard Worker // Credits
31*61046927SAndroid Build Coastguard Worker //
32*61046927SAndroid Build Coastguard Worker // Library
33*61046927SAndroid Build Coastguard Worker // Sean Barrett
34*61046927SAndroid Build Coastguard Worker // Minor features
35*61046927SAndroid Build Coastguard Worker // Martins Mozeiko
36*61046927SAndroid Build Coastguard Worker // github:IntellectualKitty
37*61046927SAndroid Build Coastguard Worker //
38*61046927SAndroid Build Coastguard Worker // Bugfixes / warning fixes
39*61046927SAndroid Build Coastguard Worker // Jeremy Jaussaud
40*61046927SAndroid Build Coastguard Worker //
41*61046927SAndroid Build Coastguard Worker // Version history:
42*61046927SAndroid Build Coastguard Worker //
43*61046927SAndroid Build Coastguard Worker // 0.99 (2019-02-07) warning fixes
44*61046927SAndroid Build Coastguard Worker // 0.11 (2017-03-03) return packing success/fail result
45*61046927SAndroid Build Coastguard Worker // 0.10 (2016-10-25) remove cast-away-const to avoid warnings
46*61046927SAndroid Build Coastguard Worker // 0.09 (2016-08-27) fix compiler warnings
47*61046927SAndroid Build Coastguard Worker // 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
48*61046927SAndroid Build Coastguard Worker // 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
49*61046927SAndroid Build Coastguard Worker // 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
50*61046927SAndroid Build Coastguard Worker // 0.05: added STBRP_ASSERT to allow replacing assert
51*61046927SAndroid Build Coastguard Worker // 0.04: fixed minor bug in STBRP_LARGE_RECTS support
52*61046927SAndroid Build Coastguard Worker // 0.01: initial release
53*61046927SAndroid Build Coastguard Worker //
54*61046927SAndroid Build Coastguard Worker // LICENSE
55*61046927SAndroid Build Coastguard Worker //
56*61046927SAndroid Build Coastguard Worker // See end of file for license information.
57*61046927SAndroid Build Coastguard Worker
58*61046927SAndroid Build Coastguard Worker //////////////////////////////////////////////////////////////////////////////
59*61046927SAndroid Build Coastguard Worker //
60*61046927SAndroid Build Coastguard Worker // INCLUDE SECTION
61*61046927SAndroid Build Coastguard Worker //
62*61046927SAndroid Build Coastguard Worker
63*61046927SAndroid Build Coastguard Worker #ifndef STB_INCLUDE_STB_RECT_PACK_H
64*61046927SAndroid Build Coastguard Worker #define STB_INCLUDE_STB_RECT_PACK_H
65*61046927SAndroid Build Coastguard Worker
66*61046927SAndroid Build Coastguard Worker #define STB_RECT_PACK_VERSION 1
67*61046927SAndroid Build Coastguard Worker
68*61046927SAndroid Build Coastguard Worker #ifdef STBRP_STATIC
69*61046927SAndroid Build Coastguard Worker #define STBRP_DEF static
70*61046927SAndroid Build Coastguard Worker #else
71*61046927SAndroid Build Coastguard Worker #define STBRP_DEF extern
72*61046927SAndroid Build Coastguard Worker #endif
73*61046927SAndroid Build Coastguard Worker
74*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus
75*61046927SAndroid Build Coastguard Worker extern "C" {
76*61046927SAndroid Build Coastguard Worker #endif
77*61046927SAndroid Build Coastguard Worker
78*61046927SAndroid Build Coastguard Worker typedef struct stbrp_context stbrp_context;
79*61046927SAndroid Build Coastguard Worker typedef struct stbrp_node stbrp_node;
80*61046927SAndroid Build Coastguard Worker typedef struct stbrp_rect stbrp_rect;
81*61046927SAndroid Build Coastguard Worker
82*61046927SAndroid Build Coastguard Worker #ifdef STBRP_LARGE_RECTS
83*61046927SAndroid Build Coastguard Worker typedef int stbrp_coord;
84*61046927SAndroid Build Coastguard Worker #else
85*61046927SAndroid Build Coastguard Worker typedef unsigned short stbrp_coord;
86*61046927SAndroid Build Coastguard Worker #endif
87*61046927SAndroid Build Coastguard Worker
88*61046927SAndroid Build Coastguard Worker STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
89*61046927SAndroid Build Coastguard Worker // Assign packed locations to rectangles. The rectangles are of type
90*61046927SAndroid Build Coastguard Worker // 'stbrp_rect' defined below, stored in the array 'rects', and there
91*61046927SAndroid Build Coastguard Worker // are 'num_rects' many of them.
92*61046927SAndroid Build Coastguard Worker //
93*61046927SAndroid Build Coastguard Worker // Rectangles which are successfully packed have the 'was_packed' flag
94*61046927SAndroid Build Coastguard Worker // set to a non-zero value and 'x' and 'y' store the minimum location
95*61046927SAndroid Build Coastguard Worker // on each axis (i.e. bottom-left in cartesian coordinates, top-left
96*61046927SAndroid Build Coastguard Worker // if you imagine y increasing downwards). Rectangles which do not fit
97*61046927SAndroid Build Coastguard Worker // have the 'was_packed' flag set to 0.
98*61046927SAndroid Build Coastguard Worker //
99*61046927SAndroid Build Coastguard Worker // You should not try to access the 'rects' array from another thread
100*61046927SAndroid Build Coastguard Worker // while this function is running, as the function temporarily reorders
101*61046927SAndroid Build Coastguard Worker // the array while it executes.
102*61046927SAndroid Build Coastguard Worker //
103*61046927SAndroid Build Coastguard Worker // To pack into another rectangle, you need to call stbrp_init_target
104*61046927SAndroid Build Coastguard Worker // again. To continue packing into the same rectangle, you can call
105*61046927SAndroid Build Coastguard Worker // this function again. Calling this multiple times with multiple rect
106*61046927SAndroid Build Coastguard Worker // arrays will probably produce worse packing results than calling it
107*61046927SAndroid Build Coastguard Worker // a single time with the full rectangle array, but the option is
108*61046927SAndroid Build Coastguard Worker // available.
109*61046927SAndroid Build Coastguard Worker //
110*61046927SAndroid Build Coastguard Worker // The function returns 1 if all of the rectangles were successfully
111*61046927SAndroid Build Coastguard Worker // packed and 0 otherwise.
112*61046927SAndroid Build Coastguard Worker
113*61046927SAndroid Build Coastguard Worker struct stbrp_rect
114*61046927SAndroid Build Coastguard Worker {
115*61046927SAndroid Build Coastguard Worker // reserved for your use:
116*61046927SAndroid Build Coastguard Worker int id;
117*61046927SAndroid Build Coastguard Worker
118*61046927SAndroid Build Coastguard Worker // input:
119*61046927SAndroid Build Coastguard Worker stbrp_coord w, h;
120*61046927SAndroid Build Coastguard Worker
121*61046927SAndroid Build Coastguard Worker // output:
122*61046927SAndroid Build Coastguard Worker stbrp_coord x, y;
123*61046927SAndroid Build Coastguard Worker int was_packed; // non-zero if valid packing
124*61046927SAndroid Build Coastguard Worker
125*61046927SAndroid Build Coastguard Worker }; // 16 bytes, nominally
126*61046927SAndroid Build Coastguard Worker
127*61046927SAndroid Build Coastguard Worker
128*61046927SAndroid Build Coastguard Worker STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
129*61046927SAndroid Build Coastguard Worker // Initialize a rectangle packer to:
130*61046927SAndroid Build Coastguard Worker // pack a rectangle that is 'width' by 'height' in dimensions
131*61046927SAndroid Build Coastguard Worker // using temporary storage provided by the array 'nodes', which is 'num_nodes' long
132*61046927SAndroid Build Coastguard Worker //
133*61046927SAndroid Build Coastguard Worker // You must call this function every time you start packing into a new target.
134*61046927SAndroid Build Coastguard Worker //
135*61046927SAndroid Build Coastguard Worker // There is no "shutdown" function. The 'nodes' memory must stay valid for
136*61046927SAndroid Build Coastguard Worker // the following stbrp_pack_rects() call (or calls), but can be freed after
137*61046927SAndroid Build Coastguard Worker // the call (or calls) finish.
138*61046927SAndroid Build Coastguard Worker //
139*61046927SAndroid Build Coastguard Worker // Note: to guarantee best results, either:
140*61046927SAndroid Build Coastguard Worker // 1. make sure 'num_nodes' >= 'width'
141*61046927SAndroid Build Coastguard Worker // or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
142*61046927SAndroid Build Coastguard Worker //
143*61046927SAndroid Build Coastguard Worker // If you don't do either of the above things, widths will be quantized to multiples
144*61046927SAndroid Build Coastguard Worker // of small integers to guarantee the algorithm doesn't run out of temporary storage.
145*61046927SAndroid Build Coastguard Worker //
146*61046927SAndroid Build Coastguard Worker // If you do #2, then the non-quantized algorithm will be used, but the algorithm
147*61046927SAndroid Build Coastguard Worker // may run out of temporary storage and be unable to pack some rectangles.
148*61046927SAndroid Build Coastguard Worker
149*61046927SAndroid Build Coastguard Worker STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
150*61046927SAndroid Build Coastguard Worker // Optionally call this function after init but before doing any packing to
151*61046927SAndroid Build Coastguard Worker // change the handling of the out-of-temp-memory scenario, described above.
152*61046927SAndroid Build Coastguard Worker // If you call init again, this will be reset to the default (false).
153*61046927SAndroid Build Coastguard Worker
154*61046927SAndroid Build Coastguard Worker
155*61046927SAndroid Build Coastguard Worker STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
156*61046927SAndroid Build Coastguard Worker // Optionally select which packing heuristic the library should use. Different
157*61046927SAndroid Build Coastguard Worker // heuristics will produce better/worse results for different data sets.
158*61046927SAndroid Build Coastguard Worker // If you call init again, this will be reset to the default.
159*61046927SAndroid Build Coastguard Worker
160*61046927SAndroid Build Coastguard Worker enum
161*61046927SAndroid Build Coastguard Worker {
162*61046927SAndroid Build Coastguard Worker STBRP_HEURISTIC_Skyline_default=0,
163*61046927SAndroid Build Coastguard Worker STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
164*61046927SAndroid Build Coastguard Worker STBRP_HEURISTIC_Skyline_BF_sortHeight
165*61046927SAndroid Build Coastguard Worker };
166*61046927SAndroid Build Coastguard Worker
167*61046927SAndroid Build Coastguard Worker
168*61046927SAndroid Build Coastguard Worker //////////////////////////////////////////////////////////////////////////////
169*61046927SAndroid Build Coastguard Worker //
170*61046927SAndroid Build Coastguard Worker // the details of the following structures don't matter to you, but they must
171*61046927SAndroid Build Coastguard Worker // be visible so you can handle the memory allocations for them
172*61046927SAndroid Build Coastguard Worker
173*61046927SAndroid Build Coastguard Worker struct stbrp_node
174*61046927SAndroid Build Coastguard Worker {
175*61046927SAndroid Build Coastguard Worker stbrp_coord x,y;
176*61046927SAndroid Build Coastguard Worker stbrp_node *next;
177*61046927SAndroid Build Coastguard Worker };
178*61046927SAndroid Build Coastguard Worker
179*61046927SAndroid Build Coastguard Worker struct stbrp_context
180*61046927SAndroid Build Coastguard Worker {
181*61046927SAndroid Build Coastguard Worker int width;
182*61046927SAndroid Build Coastguard Worker int height;
183*61046927SAndroid Build Coastguard Worker int align;
184*61046927SAndroid Build Coastguard Worker int init_mode;
185*61046927SAndroid Build Coastguard Worker int heuristic;
186*61046927SAndroid Build Coastguard Worker int num_nodes;
187*61046927SAndroid Build Coastguard Worker stbrp_node *active_head;
188*61046927SAndroid Build Coastguard Worker stbrp_node *free_head;
189*61046927SAndroid Build Coastguard Worker stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
190*61046927SAndroid Build Coastguard Worker };
191*61046927SAndroid Build Coastguard Worker
192*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus
193*61046927SAndroid Build Coastguard Worker }
194*61046927SAndroid Build Coastguard Worker #endif
195*61046927SAndroid Build Coastguard Worker
196*61046927SAndroid Build Coastguard Worker #endif
197*61046927SAndroid Build Coastguard Worker
198*61046927SAndroid Build Coastguard Worker //////////////////////////////////////////////////////////////////////////////
199*61046927SAndroid Build Coastguard Worker //
200*61046927SAndroid Build Coastguard Worker // IMPLEMENTATION SECTION
201*61046927SAndroid Build Coastguard Worker //
202*61046927SAndroid Build Coastguard Worker
203*61046927SAndroid Build Coastguard Worker #ifdef STB_RECT_PACK_IMPLEMENTATION
204*61046927SAndroid Build Coastguard Worker #ifndef STBRP_SORT
205*61046927SAndroid Build Coastguard Worker #include <stdlib.h>
206*61046927SAndroid Build Coastguard Worker #define STBRP_SORT qsort
207*61046927SAndroid Build Coastguard Worker #endif
208*61046927SAndroid Build Coastguard Worker
209*61046927SAndroid Build Coastguard Worker #ifndef STBRP_ASSERT
210*61046927SAndroid Build Coastguard Worker #include <assert.h>
211*61046927SAndroid Build Coastguard Worker #define STBRP_ASSERT assert
212*61046927SAndroid Build Coastguard Worker #endif
213*61046927SAndroid Build Coastguard Worker
214*61046927SAndroid Build Coastguard Worker // [DEAR IMGUI] Added STBRP__CDECL
215*61046927SAndroid Build Coastguard Worker #ifdef _MSC_VER
216*61046927SAndroid Build Coastguard Worker #define STBRP__NOTUSED(v) (void)(v)
217*61046927SAndroid Build Coastguard Worker #define STBRP__CDECL __cdecl
218*61046927SAndroid Build Coastguard Worker #else
219*61046927SAndroid Build Coastguard Worker #define STBRP__NOTUSED(v) (void)sizeof(v)
220*61046927SAndroid Build Coastguard Worker #define STBRP__CDECL
221*61046927SAndroid Build Coastguard Worker #endif
222*61046927SAndroid Build Coastguard Worker
223*61046927SAndroid Build Coastguard Worker enum
224*61046927SAndroid Build Coastguard Worker {
225*61046927SAndroid Build Coastguard Worker STBRP__INIT_skyline = 1
226*61046927SAndroid Build Coastguard Worker };
227*61046927SAndroid Build Coastguard Worker
stbrp_setup_heuristic(stbrp_context * context,int heuristic)228*61046927SAndroid Build Coastguard Worker STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
229*61046927SAndroid Build Coastguard Worker {
230*61046927SAndroid Build Coastguard Worker switch (context->init_mode) {
231*61046927SAndroid Build Coastguard Worker case STBRP__INIT_skyline:
232*61046927SAndroid Build Coastguard Worker STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
233*61046927SAndroid Build Coastguard Worker context->heuristic = heuristic;
234*61046927SAndroid Build Coastguard Worker break;
235*61046927SAndroid Build Coastguard Worker default:
236*61046927SAndroid Build Coastguard Worker STBRP_ASSERT(0);
237*61046927SAndroid Build Coastguard Worker }
238*61046927SAndroid Build Coastguard Worker }
239*61046927SAndroid Build Coastguard Worker
stbrp_setup_allow_out_of_mem(stbrp_context * context,int allow_out_of_mem)240*61046927SAndroid Build Coastguard Worker STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
241*61046927SAndroid Build Coastguard Worker {
242*61046927SAndroid Build Coastguard Worker if (allow_out_of_mem)
243*61046927SAndroid Build Coastguard Worker // if it's ok to run out of memory, then don't bother aligning them;
244*61046927SAndroid Build Coastguard Worker // this gives better packing, but may fail due to OOM (even though
245*61046927SAndroid Build Coastguard Worker // the rectangles easily fit). @TODO a smarter approach would be to only
246*61046927SAndroid Build Coastguard Worker // quantize once we've hit OOM, then we could get rid of this parameter.
247*61046927SAndroid Build Coastguard Worker context->align = 1;
248*61046927SAndroid Build Coastguard Worker else {
249*61046927SAndroid Build Coastguard Worker // if it's not ok to run out of memory, then quantize the widths
250*61046927SAndroid Build Coastguard Worker // so that num_nodes is always enough nodes.
251*61046927SAndroid Build Coastguard Worker //
252*61046927SAndroid Build Coastguard Worker // I.e. num_nodes * align >= width
253*61046927SAndroid Build Coastguard Worker // align >= width / num_nodes
254*61046927SAndroid Build Coastguard Worker // align = ceil(width/num_nodes)
255*61046927SAndroid Build Coastguard Worker
256*61046927SAndroid Build Coastguard Worker context->align = (context->width + context->num_nodes-1) / context->num_nodes;
257*61046927SAndroid Build Coastguard Worker }
258*61046927SAndroid Build Coastguard Worker }
259*61046927SAndroid Build Coastguard Worker
stbrp_init_target(stbrp_context * context,int width,int height,stbrp_node * nodes,int num_nodes)260*61046927SAndroid Build Coastguard Worker STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
261*61046927SAndroid Build Coastguard Worker {
262*61046927SAndroid Build Coastguard Worker int i;
263*61046927SAndroid Build Coastguard Worker #ifndef STBRP_LARGE_RECTS
264*61046927SAndroid Build Coastguard Worker STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
265*61046927SAndroid Build Coastguard Worker #endif
266*61046927SAndroid Build Coastguard Worker
267*61046927SAndroid Build Coastguard Worker for (i=0; i < num_nodes-1; ++i)
268*61046927SAndroid Build Coastguard Worker nodes[i].next = &nodes[i+1];
269*61046927SAndroid Build Coastguard Worker nodes[i].next = NULL;
270*61046927SAndroid Build Coastguard Worker context->init_mode = STBRP__INIT_skyline;
271*61046927SAndroid Build Coastguard Worker context->heuristic = STBRP_HEURISTIC_Skyline_default;
272*61046927SAndroid Build Coastguard Worker context->free_head = &nodes[0];
273*61046927SAndroid Build Coastguard Worker context->active_head = &context->extra[0];
274*61046927SAndroid Build Coastguard Worker context->width = width;
275*61046927SAndroid Build Coastguard Worker context->height = height;
276*61046927SAndroid Build Coastguard Worker context->num_nodes = num_nodes;
277*61046927SAndroid Build Coastguard Worker stbrp_setup_allow_out_of_mem(context, 0);
278*61046927SAndroid Build Coastguard Worker
279*61046927SAndroid Build Coastguard Worker // node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
280*61046927SAndroid Build Coastguard Worker context->extra[0].x = 0;
281*61046927SAndroid Build Coastguard Worker context->extra[0].y = 0;
282*61046927SAndroid Build Coastguard Worker context->extra[0].next = &context->extra[1];
283*61046927SAndroid Build Coastguard Worker context->extra[1].x = (stbrp_coord) width;
284*61046927SAndroid Build Coastguard Worker #ifdef STBRP_LARGE_RECTS
285*61046927SAndroid Build Coastguard Worker context->extra[1].y = (1<<30);
286*61046927SAndroid Build Coastguard Worker #else
287*61046927SAndroid Build Coastguard Worker context->extra[1].y = 65535;
288*61046927SAndroid Build Coastguard Worker #endif
289*61046927SAndroid Build Coastguard Worker context->extra[1].next = NULL;
290*61046927SAndroid Build Coastguard Worker }
291*61046927SAndroid Build Coastguard Worker
292*61046927SAndroid Build Coastguard Worker // find minimum y position if it starts at x1
stbrp__skyline_find_min_y(stbrp_context * c,stbrp_node * first,int x0,int width,int * pwaste)293*61046927SAndroid Build Coastguard Worker static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
294*61046927SAndroid Build Coastguard Worker {
295*61046927SAndroid Build Coastguard Worker stbrp_node *node = first;
296*61046927SAndroid Build Coastguard Worker int x1 = x0 + width;
297*61046927SAndroid Build Coastguard Worker int min_y, visited_width, waste_area;
298*61046927SAndroid Build Coastguard Worker
299*61046927SAndroid Build Coastguard Worker STBRP__NOTUSED(c);
300*61046927SAndroid Build Coastguard Worker
301*61046927SAndroid Build Coastguard Worker STBRP_ASSERT(first->x <= x0);
302*61046927SAndroid Build Coastguard Worker
303*61046927SAndroid Build Coastguard Worker #if 0
304*61046927SAndroid Build Coastguard Worker // skip in case we're past the node
305*61046927SAndroid Build Coastguard Worker while (node->next->x <= x0)
306*61046927SAndroid Build Coastguard Worker ++node;
307*61046927SAndroid Build Coastguard Worker #else
308*61046927SAndroid Build Coastguard Worker STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
309*61046927SAndroid Build Coastguard Worker #endif
310*61046927SAndroid Build Coastguard Worker
311*61046927SAndroid Build Coastguard Worker STBRP_ASSERT(node->x <= x0);
312*61046927SAndroid Build Coastguard Worker
313*61046927SAndroid Build Coastguard Worker min_y = 0;
314*61046927SAndroid Build Coastguard Worker waste_area = 0;
315*61046927SAndroid Build Coastguard Worker visited_width = 0;
316*61046927SAndroid Build Coastguard Worker while (node->x < x1) {
317*61046927SAndroid Build Coastguard Worker if (node->y > min_y) {
318*61046927SAndroid Build Coastguard Worker // raise min_y higher.
319*61046927SAndroid Build Coastguard Worker // we've accounted for all waste up to min_y,
320*61046927SAndroid Build Coastguard Worker // but we'll now add more waste for everything we've visted
321*61046927SAndroid Build Coastguard Worker waste_area += visited_width * (node->y - min_y);
322*61046927SAndroid Build Coastguard Worker min_y = node->y;
323*61046927SAndroid Build Coastguard Worker // the first time through, visited_width might be reduced
324*61046927SAndroid Build Coastguard Worker if (node->x < x0)
325*61046927SAndroid Build Coastguard Worker visited_width += node->next->x - x0;
326*61046927SAndroid Build Coastguard Worker else
327*61046927SAndroid Build Coastguard Worker visited_width += node->next->x - node->x;
328*61046927SAndroid Build Coastguard Worker } else {
329*61046927SAndroid Build Coastguard Worker // add waste area
330*61046927SAndroid Build Coastguard Worker int under_width = node->next->x - node->x;
331*61046927SAndroid Build Coastguard Worker if (under_width + visited_width > width)
332*61046927SAndroid Build Coastguard Worker under_width = width - visited_width;
333*61046927SAndroid Build Coastguard Worker waste_area += under_width * (min_y - node->y);
334*61046927SAndroid Build Coastguard Worker visited_width += under_width;
335*61046927SAndroid Build Coastguard Worker }
336*61046927SAndroid Build Coastguard Worker node = node->next;
337*61046927SAndroid Build Coastguard Worker }
338*61046927SAndroid Build Coastguard Worker
339*61046927SAndroid Build Coastguard Worker *pwaste = waste_area;
340*61046927SAndroid Build Coastguard Worker return min_y;
341*61046927SAndroid Build Coastguard Worker }
342*61046927SAndroid Build Coastguard Worker
343*61046927SAndroid Build Coastguard Worker typedef struct
344*61046927SAndroid Build Coastguard Worker {
345*61046927SAndroid Build Coastguard Worker int x,y;
346*61046927SAndroid Build Coastguard Worker stbrp_node **prev_link;
347*61046927SAndroid Build Coastguard Worker } stbrp__findresult;
348*61046927SAndroid Build Coastguard Worker
stbrp__skyline_find_best_pos(stbrp_context * c,int width,int height)349*61046927SAndroid Build Coastguard Worker static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
350*61046927SAndroid Build Coastguard Worker {
351*61046927SAndroid Build Coastguard Worker int best_waste = (1<<30), best_x, best_y = (1 << 30);
352*61046927SAndroid Build Coastguard Worker stbrp__findresult fr;
353*61046927SAndroid Build Coastguard Worker stbrp_node **prev, *node, *tail, **best = NULL;
354*61046927SAndroid Build Coastguard Worker
355*61046927SAndroid Build Coastguard Worker // align to multiple of c->align
356*61046927SAndroid Build Coastguard Worker width = (width + c->align - 1);
357*61046927SAndroid Build Coastguard Worker width -= width % c->align;
358*61046927SAndroid Build Coastguard Worker STBRP_ASSERT(width % c->align == 0);
359*61046927SAndroid Build Coastguard Worker
360*61046927SAndroid Build Coastguard Worker node = c->active_head;
361*61046927SAndroid Build Coastguard Worker prev = &c->active_head;
362*61046927SAndroid Build Coastguard Worker while (node->x + width <= c->width) {
363*61046927SAndroid Build Coastguard Worker int y,waste;
364*61046927SAndroid Build Coastguard Worker y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
365*61046927SAndroid Build Coastguard Worker if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
366*61046927SAndroid Build Coastguard Worker // bottom left
367*61046927SAndroid Build Coastguard Worker if (y < best_y) {
368*61046927SAndroid Build Coastguard Worker best_y = y;
369*61046927SAndroid Build Coastguard Worker best = prev;
370*61046927SAndroid Build Coastguard Worker }
371*61046927SAndroid Build Coastguard Worker } else {
372*61046927SAndroid Build Coastguard Worker // best-fit
373*61046927SAndroid Build Coastguard Worker if (y + height <= c->height) {
374*61046927SAndroid Build Coastguard Worker // can only use it if it first vertically
375*61046927SAndroid Build Coastguard Worker if (y < best_y || (y == best_y && waste < best_waste)) {
376*61046927SAndroid Build Coastguard Worker best_y = y;
377*61046927SAndroid Build Coastguard Worker best_waste = waste;
378*61046927SAndroid Build Coastguard Worker best = prev;
379*61046927SAndroid Build Coastguard Worker }
380*61046927SAndroid Build Coastguard Worker }
381*61046927SAndroid Build Coastguard Worker }
382*61046927SAndroid Build Coastguard Worker prev = &node->next;
383*61046927SAndroid Build Coastguard Worker node = node->next;
384*61046927SAndroid Build Coastguard Worker }
385*61046927SAndroid Build Coastguard Worker
386*61046927SAndroid Build Coastguard Worker best_x = (best == NULL) ? 0 : (*best)->x;
387*61046927SAndroid Build Coastguard Worker
388*61046927SAndroid Build Coastguard Worker // if doing best-fit (BF), we also have to try aligning right edge to each node position
389*61046927SAndroid Build Coastguard Worker //
390*61046927SAndroid Build Coastguard Worker // e.g, if fitting
391*61046927SAndroid Build Coastguard Worker //
392*61046927SAndroid Build Coastguard Worker // ____________________
393*61046927SAndroid Build Coastguard Worker // |____________________|
394*61046927SAndroid Build Coastguard Worker //
395*61046927SAndroid Build Coastguard Worker // into
396*61046927SAndroid Build Coastguard Worker //
397*61046927SAndroid Build Coastguard Worker // | |
398*61046927SAndroid Build Coastguard Worker // | ____________|
399*61046927SAndroid Build Coastguard Worker // |____________|
400*61046927SAndroid Build Coastguard Worker //
401*61046927SAndroid Build Coastguard Worker // then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
402*61046927SAndroid Build Coastguard Worker //
403*61046927SAndroid Build Coastguard Worker // This makes BF take about 2x the time
404*61046927SAndroid Build Coastguard Worker
405*61046927SAndroid Build Coastguard Worker if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
406*61046927SAndroid Build Coastguard Worker tail = c->active_head;
407*61046927SAndroid Build Coastguard Worker node = c->active_head;
408*61046927SAndroid Build Coastguard Worker prev = &c->active_head;
409*61046927SAndroid Build Coastguard Worker // find first node that's admissible
410*61046927SAndroid Build Coastguard Worker while (tail->x < width)
411*61046927SAndroid Build Coastguard Worker tail = tail->next;
412*61046927SAndroid Build Coastguard Worker while (tail) {
413*61046927SAndroid Build Coastguard Worker int xpos = tail->x - width;
414*61046927SAndroid Build Coastguard Worker int y,waste;
415*61046927SAndroid Build Coastguard Worker STBRP_ASSERT(xpos >= 0);
416*61046927SAndroid Build Coastguard Worker // find the left position that matches this
417*61046927SAndroid Build Coastguard Worker while (node->next->x <= xpos) {
418*61046927SAndroid Build Coastguard Worker prev = &node->next;
419*61046927SAndroid Build Coastguard Worker node = node->next;
420*61046927SAndroid Build Coastguard Worker }
421*61046927SAndroid Build Coastguard Worker STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
422*61046927SAndroid Build Coastguard Worker y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
423*61046927SAndroid Build Coastguard Worker if (y + height < c->height) {
424*61046927SAndroid Build Coastguard Worker if (y <= best_y) {
425*61046927SAndroid Build Coastguard Worker if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
426*61046927SAndroid Build Coastguard Worker best_x = xpos;
427*61046927SAndroid Build Coastguard Worker STBRP_ASSERT(y <= best_y);
428*61046927SAndroid Build Coastguard Worker best_y = y;
429*61046927SAndroid Build Coastguard Worker best_waste = waste;
430*61046927SAndroid Build Coastguard Worker best = prev;
431*61046927SAndroid Build Coastguard Worker }
432*61046927SAndroid Build Coastguard Worker }
433*61046927SAndroid Build Coastguard Worker }
434*61046927SAndroid Build Coastguard Worker tail = tail->next;
435*61046927SAndroid Build Coastguard Worker }
436*61046927SAndroid Build Coastguard Worker }
437*61046927SAndroid Build Coastguard Worker
438*61046927SAndroid Build Coastguard Worker fr.prev_link = best;
439*61046927SAndroid Build Coastguard Worker fr.x = best_x;
440*61046927SAndroid Build Coastguard Worker fr.y = best_y;
441*61046927SAndroid Build Coastguard Worker return fr;
442*61046927SAndroid Build Coastguard Worker }
443*61046927SAndroid Build Coastguard Worker
stbrp__skyline_pack_rectangle(stbrp_context * context,int width,int height)444*61046927SAndroid Build Coastguard Worker static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
445*61046927SAndroid Build Coastguard Worker {
446*61046927SAndroid Build Coastguard Worker // find best position according to heuristic
447*61046927SAndroid Build Coastguard Worker stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
448*61046927SAndroid Build Coastguard Worker stbrp_node *node, *cur;
449*61046927SAndroid Build Coastguard Worker
450*61046927SAndroid Build Coastguard Worker // bail if:
451*61046927SAndroid Build Coastguard Worker // 1. it failed
452*61046927SAndroid Build Coastguard Worker // 2. the best node doesn't fit (we don't always check this)
453*61046927SAndroid Build Coastguard Worker // 3. we're out of memory
454*61046927SAndroid Build Coastguard Worker if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
455*61046927SAndroid Build Coastguard Worker res.prev_link = NULL;
456*61046927SAndroid Build Coastguard Worker return res;
457*61046927SAndroid Build Coastguard Worker }
458*61046927SAndroid Build Coastguard Worker
459*61046927SAndroid Build Coastguard Worker // on success, create new node
460*61046927SAndroid Build Coastguard Worker node = context->free_head;
461*61046927SAndroid Build Coastguard Worker node->x = (stbrp_coord) res.x;
462*61046927SAndroid Build Coastguard Worker node->y = (stbrp_coord) (res.y + height);
463*61046927SAndroid Build Coastguard Worker
464*61046927SAndroid Build Coastguard Worker context->free_head = node->next;
465*61046927SAndroid Build Coastguard Worker
466*61046927SAndroid Build Coastguard Worker // insert the new node into the right starting point, and
467*61046927SAndroid Build Coastguard Worker // let 'cur' point to the remaining nodes needing to be
468*61046927SAndroid Build Coastguard Worker // stiched back in
469*61046927SAndroid Build Coastguard Worker
470*61046927SAndroid Build Coastguard Worker cur = *res.prev_link;
471*61046927SAndroid Build Coastguard Worker if (cur->x < res.x) {
472*61046927SAndroid Build Coastguard Worker // preserve the existing one, so start testing with the next one
473*61046927SAndroid Build Coastguard Worker stbrp_node *next = cur->next;
474*61046927SAndroid Build Coastguard Worker cur->next = node;
475*61046927SAndroid Build Coastguard Worker cur = next;
476*61046927SAndroid Build Coastguard Worker } else {
477*61046927SAndroid Build Coastguard Worker *res.prev_link = node;
478*61046927SAndroid Build Coastguard Worker }
479*61046927SAndroid Build Coastguard Worker
480*61046927SAndroid Build Coastguard Worker // from here, traverse cur and free the nodes, until we get to one
481*61046927SAndroid Build Coastguard Worker // that shouldn't be freed
482*61046927SAndroid Build Coastguard Worker while (cur->next && cur->next->x <= res.x + width) {
483*61046927SAndroid Build Coastguard Worker stbrp_node *next = cur->next;
484*61046927SAndroid Build Coastguard Worker // move the current node to the free list
485*61046927SAndroid Build Coastguard Worker cur->next = context->free_head;
486*61046927SAndroid Build Coastguard Worker context->free_head = cur;
487*61046927SAndroid Build Coastguard Worker cur = next;
488*61046927SAndroid Build Coastguard Worker }
489*61046927SAndroid Build Coastguard Worker
490*61046927SAndroid Build Coastguard Worker // stitch the list back in
491*61046927SAndroid Build Coastguard Worker node->next = cur;
492*61046927SAndroid Build Coastguard Worker
493*61046927SAndroid Build Coastguard Worker if (cur->x < res.x + width)
494*61046927SAndroid Build Coastguard Worker cur->x = (stbrp_coord) (res.x + width);
495*61046927SAndroid Build Coastguard Worker
496*61046927SAndroid Build Coastguard Worker #ifdef _DEBUG
497*61046927SAndroid Build Coastguard Worker cur = context->active_head;
498*61046927SAndroid Build Coastguard Worker while (cur->x < context->width) {
499*61046927SAndroid Build Coastguard Worker STBRP_ASSERT(cur->x < cur->next->x);
500*61046927SAndroid Build Coastguard Worker cur = cur->next;
501*61046927SAndroid Build Coastguard Worker }
502*61046927SAndroid Build Coastguard Worker STBRP_ASSERT(cur->next == NULL);
503*61046927SAndroid Build Coastguard Worker
504*61046927SAndroid Build Coastguard Worker {
505*61046927SAndroid Build Coastguard Worker int count=0;
506*61046927SAndroid Build Coastguard Worker cur = context->active_head;
507*61046927SAndroid Build Coastguard Worker while (cur) {
508*61046927SAndroid Build Coastguard Worker cur = cur->next;
509*61046927SAndroid Build Coastguard Worker ++count;
510*61046927SAndroid Build Coastguard Worker }
511*61046927SAndroid Build Coastguard Worker cur = context->free_head;
512*61046927SAndroid Build Coastguard Worker while (cur) {
513*61046927SAndroid Build Coastguard Worker cur = cur->next;
514*61046927SAndroid Build Coastguard Worker ++count;
515*61046927SAndroid Build Coastguard Worker }
516*61046927SAndroid Build Coastguard Worker STBRP_ASSERT(count == context->num_nodes+2);
517*61046927SAndroid Build Coastguard Worker }
518*61046927SAndroid Build Coastguard Worker #endif
519*61046927SAndroid Build Coastguard Worker
520*61046927SAndroid Build Coastguard Worker return res;
521*61046927SAndroid Build Coastguard Worker }
522*61046927SAndroid Build Coastguard Worker
523*61046927SAndroid Build Coastguard Worker // [DEAR IMGUI] Added STBRP__CDECL
rect_height_compare(const void * a,const void * b)524*61046927SAndroid Build Coastguard Worker static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
525*61046927SAndroid Build Coastguard Worker {
526*61046927SAndroid Build Coastguard Worker const stbrp_rect *p = (const stbrp_rect *) a;
527*61046927SAndroid Build Coastguard Worker const stbrp_rect *q = (const stbrp_rect *) b;
528*61046927SAndroid Build Coastguard Worker if (p->h > q->h)
529*61046927SAndroid Build Coastguard Worker return -1;
530*61046927SAndroid Build Coastguard Worker if (p->h < q->h)
531*61046927SAndroid Build Coastguard Worker return 1;
532*61046927SAndroid Build Coastguard Worker return (p->w > q->w) ? -1 : (p->w < q->w);
533*61046927SAndroid Build Coastguard Worker }
534*61046927SAndroid Build Coastguard Worker
535*61046927SAndroid Build Coastguard Worker // [DEAR IMGUI] Added STBRP__CDECL
rect_original_order(const void * a,const void * b)536*61046927SAndroid Build Coastguard Worker static int STBRP__CDECL rect_original_order(const void *a, const void *b)
537*61046927SAndroid Build Coastguard Worker {
538*61046927SAndroid Build Coastguard Worker const stbrp_rect *p = (const stbrp_rect *) a;
539*61046927SAndroid Build Coastguard Worker const stbrp_rect *q = (const stbrp_rect *) b;
540*61046927SAndroid Build Coastguard Worker return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
541*61046927SAndroid Build Coastguard Worker }
542*61046927SAndroid Build Coastguard Worker
543*61046927SAndroid Build Coastguard Worker #ifdef STBRP_LARGE_RECTS
544*61046927SAndroid Build Coastguard Worker #define STBRP__MAXVAL 0xffffffff
545*61046927SAndroid Build Coastguard Worker #else
546*61046927SAndroid Build Coastguard Worker #define STBRP__MAXVAL 0xffff
547*61046927SAndroid Build Coastguard Worker #endif
548*61046927SAndroid Build Coastguard Worker
stbrp_pack_rects(stbrp_context * context,stbrp_rect * rects,int num_rects)549*61046927SAndroid Build Coastguard Worker STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
550*61046927SAndroid Build Coastguard Worker {
551*61046927SAndroid Build Coastguard Worker int i, all_rects_packed = 1;
552*61046927SAndroid Build Coastguard Worker
553*61046927SAndroid Build Coastguard Worker // we use the 'was_packed' field internally to allow sorting/unsorting
554*61046927SAndroid Build Coastguard Worker for (i=0; i < num_rects; ++i) {
555*61046927SAndroid Build Coastguard Worker rects[i].was_packed = i;
556*61046927SAndroid Build Coastguard Worker }
557*61046927SAndroid Build Coastguard Worker
558*61046927SAndroid Build Coastguard Worker // sort according to heuristic
559*61046927SAndroid Build Coastguard Worker STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
560*61046927SAndroid Build Coastguard Worker
561*61046927SAndroid Build Coastguard Worker for (i=0; i < num_rects; ++i) {
562*61046927SAndroid Build Coastguard Worker if (rects[i].w == 0 || rects[i].h == 0) {
563*61046927SAndroid Build Coastguard Worker rects[i].x = rects[i].y = 0; // empty rect needs no space
564*61046927SAndroid Build Coastguard Worker } else {
565*61046927SAndroid Build Coastguard Worker stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
566*61046927SAndroid Build Coastguard Worker if (fr.prev_link) {
567*61046927SAndroid Build Coastguard Worker rects[i].x = (stbrp_coord) fr.x;
568*61046927SAndroid Build Coastguard Worker rects[i].y = (stbrp_coord) fr.y;
569*61046927SAndroid Build Coastguard Worker } else {
570*61046927SAndroid Build Coastguard Worker rects[i].x = rects[i].y = STBRP__MAXVAL;
571*61046927SAndroid Build Coastguard Worker }
572*61046927SAndroid Build Coastguard Worker }
573*61046927SAndroid Build Coastguard Worker }
574*61046927SAndroid Build Coastguard Worker
575*61046927SAndroid Build Coastguard Worker // unsort
576*61046927SAndroid Build Coastguard Worker STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
577*61046927SAndroid Build Coastguard Worker
578*61046927SAndroid Build Coastguard Worker // set was_packed flags and all_rects_packed status
579*61046927SAndroid Build Coastguard Worker for (i=0; i < num_rects; ++i) {
580*61046927SAndroid Build Coastguard Worker rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
581*61046927SAndroid Build Coastguard Worker if (!rects[i].was_packed)
582*61046927SAndroid Build Coastguard Worker all_rects_packed = 0;
583*61046927SAndroid Build Coastguard Worker }
584*61046927SAndroid Build Coastguard Worker
585*61046927SAndroid Build Coastguard Worker // return the all_rects_packed status
586*61046927SAndroid Build Coastguard Worker return all_rects_packed;
587*61046927SAndroid Build Coastguard Worker }
588*61046927SAndroid Build Coastguard Worker #endif
589*61046927SAndroid Build Coastguard Worker
590*61046927SAndroid Build Coastguard Worker /*
591*61046927SAndroid Build Coastguard Worker ------------------------------------------------------------------------------
592*61046927SAndroid Build Coastguard Worker This software is available under 2 licenses -- choose whichever you prefer.
593*61046927SAndroid Build Coastguard Worker ------------------------------------------------------------------------------
594*61046927SAndroid Build Coastguard Worker ALTERNATIVE A - MIT License
595*61046927SAndroid Build Coastguard Worker Copyright (c) 2017 Sean Barrett
596*61046927SAndroid Build Coastguard Worker Permission is hereby granted, free of charge, to any person obtaining a copy of
597*61046927SAndroid Build Coastguard Worker this software and associated documentation files (the "Software"), to deal in
598*61046927SAndroid Build Coastguard Worker the Software without restriction, including without limitation the rights to
599*61046927SAndroid Build Coastguard Worker use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
600*61046927SAndroid Build Coastguard Worker of the Software, and to permit persons to whom the Software is furnished to do
601*61046927SAndroid Build Coastguard Worker so, subject to the following conditions:
602*61046927SAndroid Build Coastguard Worker The above copyright notice and this permission notice shall be included in all
603*61046927SAndroid Build Coastguard Worker copies or substantial portions of the Software.
604*61046927SAndroid Build Coastguard Worker THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
605*61046927SAndroid Build Coastguard Worker IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
606*61046927SAndroid Build Coastguard Worker FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
607*61046927SAndroid Build Coastguard Worker AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
608*61046927SAndroid Build Coastguard Worker LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
609*61046927SAndroid Build Coastguard Worker OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
610*61046927SAndroid Build Coastguard Worker SOFTWARE.
611*61046927SAndroid Build Coastguard Worker ------------------------------------------------------------------------------
612*61046927SAndroid Build Coastguard Worker ALTERNATIVE B - Public Domain (www.unlicense.org)
613*61046927SAndroid Build Coastguard Worker This is free and unencumbered software released into the public domain.
614*61046927SAndroid Build Coastguard Worker Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
615*61046927SAndroid Build Coastguard Worker software, either in source code form or as a compiled binary, for any purpose,
616*61046927SAndroid Build Coastguard Worker commercial or non-commercial, and by any means.
617*61046927SAndroid Build Coastguard Worker In jurisdictions that recognize copyright laws, the author or authors of this
618*61046927SAndroid Build Coastguard Worker software dedicate any and all copyright interest in the software to the public
619*61046927SAndroid Build Coastguard Worker domain. We make this dedication for the benefit of the public at large and to
620*61046927SAndroid Build Coastguard Worker the detriment of our heirs and successors. We intend this dedication to be an
621*61046927SAndroid Build Coastguard Worker overt act of relinquishment in perpetuity of all present and future rights to
622*61046927SAndroid Build Coastguard Worker this software under copyright law.
623*61046927SAndroid Build Coastguard Worker THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
624*61046927SAndroid Build Coastguard Worker IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
625*61046927SAndroid Build Coastguard Worker FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
626*61046927SAndroid Build Coastguard Worker AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
627*61046927SAndroid Build Coastguard Worker ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
628*61046927SAndroid Build Coastguard Worker WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
629*61046927SAndroid Build Coastguard Worker ------------------------------------------------------------------------------
630*61046927SAndroid Build Coastguard Worker */
631