stb_rect_pack.h 19.6 KB
Newer Older
S
Sean Barrett 已提交
1
// stb_rect_pack.h - v1.00 - public domain - rectangle packing
2
// Sean Barrett 2014
S
Sean Barrett 已提交
3 4
//
// Useful for e.g. packing rectangular textures into an atlas.
5
// Does not do rotation.
S
Sean Barrett 已提交
6
//
7 8 9 10 11 12 13 14
// Not necessarily the awesomest packing method, but better than
// the totally naive one in stb_truetype (which is primarily what
// this is meant to replace).
//
// Has only had a few tests run, may have issues.
//
// More docs to come.
//
N
nothings 已提交
15
// No memory allocations; uses qsort() and assert() from stdlib.
16
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
S
Sean Barrett 已提交
17 18 19 20 21
//
// This library currently uses the Skyline Bottom-Left algorithm.
//
// Please note: better rectangle packers are welcome! Please
// implement them to the same API, but with a different init
22
// function.
S
Sean Barrett 已提交
23
//
24 25 26 27 28 29
// Credits
//
//  Library
//    Sean Barrett
//  Minor features
//    Martins Mozeiko
S
Sean Barrett 已提交
30
//    github:IntellectualKitty
S
Sean Barrett 已提交
31
//
32
//  Bugfixes / warning fixes
33
//    Jeremy Jaussaud
F
Fabian Giesen 已提交
34
//    Fabian Giesen
35
//
S
Sean Barrett 已提交
36 37
// Version history:
//
S
Sean Barrett 已提交
38
//     1.00  (2019-02-25)  avoid small space waste; gracefully fail too-wide rectangles
S
Sean Barrett 已提交
39
//     0.99  (2019-02-07)  warning fixes
S
Sean Barrett 已提交
40
//     0.11  (2017-03-03)  return packing success/fail result
S
Sean Barrett 已提交
41
//     0.10  (2016-10-25)  remove cast-away-const to avoid warnings
S
Sean Barrett 已提交
42
//     0.09  (2016-08-27)  fix compiler warnings
S
Sean Barrett 已提交
43
//     0.08  (2015-09-13)  really fix bug with empty rects (w=0 or h=0)
44
//     0.07  (2015-09-13)  fix bug with empty rects (w=0 or h=0)
45
//     0.06  (2015-04-15)  added STBRP_SORT to allow replacing qsort
S
Sean Barrett 已提交
46
//     0.05:  added STBRP_ASSERT to allow replacing assert
S
Sean Barrett 已提交
47 48
//     0.04:  fixed minor bug in STBRP_LARGE_RECTS support
//     0.01:  initial release
49 50 51
//
// LICENSE
//
52
//   See end of file for license information.
53 54 55 56 57 58

//////////////////////////////////////////////////////////////////////////////
//
//       INCLUDE SECTION
//

S
Sean Barrett 已提交
59 60 61
#ifndef STB_INCLUDE_STB_RECT_PACK_H
#define STB_INCLUDE_STB_RECT_PACK_H

62 63
#define STB_RECT_PACK_VERSION  1

S
Sean Barrett 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77
#ifdef STBRP_STATIC
#define STBRP_DEF static
#else
#define STBRP_DEF extern
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef struct stbrp_context stbrp_context;
typedef struct stbrp_node    stbrp_node;
typedef struct stbrp_rect    stbrp_rect;

78 79 80 81 82
#ifdef STBRP_LARGE_RECTS
typedef int            stbrp_coord;
#else
typedef unsigned short stbrp_coord;
#endif
S
Sean Barrett 已提交
83

84
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
85
// Assign packed locations to rectangles. The rectangles are of type
86 87 88 89 90 91 92 93 94 95 96 97
// 'stbrp_rect' defined below, stored in the array 'rects', and there
// are 'num_rects' many of them.
//
// Rectangles which are successfully packed have the 'was_packed' flag
// set to a non-zero value and 'x' and 'y' store the minimum location
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
// if you imagine y increasing downwards). Rectangles which do not fit
// have the 'was_packed' flag set to 0.
//
// You should not try to access the 'rects' array from another thread
// while this function is running, as the function temporarily reorders
// the array while it executes.
98 99 100 101 102 103 104
//
// To pack into another rectangle, you need to call stbrp_init_target
// again. To continue packing into the same rectangle, you can call
// this function again. Calling this multiple times with multiple rect
// arrays will probably produce worse packing results than calling it
// a single time with the full rectangle array, but the option is
// available.
105 106 107
//
// The function returns 1 if all of the rectangles were successfully
// packed and 0 otherwise.
S
Sean Barrett 已提交
108 109 110 111 112 113 114

struct stbrp_rect
{
   // reserved for your use:
   int            id;

   // input:
115
   stbrp_coord    w, h;
S
Sean Barrett 已提交
116 117

   // output:
118
   stbrp_coord    x, y;
S
Sean Barrett 已提交
119
   int            was_packed;  // non-zero if valid packing
120

S
Sean Barrett 已提交
121 122
}; // 16 bytes, nominally

123

124
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
125 126 127 128
// Initialize a rectangle packer to:
//    pack a rectangle that is 'width' by 'height' in dimensions
//    using temporary storage provided by the array 'nodes', which is 'num_nodes' long
//
129 130 131 132 133 134
// You must call this function every time you start packing into a new target.
//
// There is no "shutdown" function. The 'nodes' memory must stay valid for
// the following stbrp_pack_rects() call (or calls), but can be freed after
// the call (or calls) finish.
//
135 136 137 138 139 140 141 142 143 144 145 146 147
// Note: to guarantee best results, either:
//       1. make sure 'num_nodes' >= 'width'
//   or  2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
//
// If you don't do either of the above things, widths will be quantized to multiples
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
//
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
// may run out of temporary storage and be unable to pack some rectangles.

STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
// Optionally call this function after init but before doing any packing to
// change the handling of the out-of-temp-memory scenario, described above.
S
Sean Barrett 已提交
148
// If you call init again, this will be reset to the default (false).
149 150 151 152 153


STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
// Optionally select which packing heuristic the library should use. Different
// heuristics will produce better/worse results for different data sets.
S
Sean Barrett 已提交
154
// If you call init again, this will be reset to the default.
155

156 157 158 159
enum
{
   STBRP_HEURISTIC_Skyline_default=0,
   STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
C
cosmy1 已提交
160
   STBRP_HEURISTIC_Skyline_BF_sortHeight
161 162 163
};


164 165
//////////////////////////////////////////////////////////////////////////////
//
S
Sean Barrett 已提交
166
// the details of the following structures don't matter to you, but they must
167
// be visible so you can handle the memory allocations for them
168

S
Sean Barrett 已提交
169 170
struct stbrp_node
{
171 172
   stbrp_coord  x,y;
   stbrp_node  *next;
S
Sean Barrett 已提交
173 174 175 176 177 178 179 180 181 182 183 184
};

struct stbrp_context
{
   int width;
   int height;
   int align;
   int init_mode;
   int heuristic;
   int num_nodes;
   stbrp_node *active_head;
   stbrp_node *free_head;
185
   stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
S
Sean Barrett 已提交
186 187 188 189 190 191 192 193
};

#ifdef __cplusplus
}
#endif

#endif

194 195 196 197
//////////////////////////////////////////////////////////////////////////////
//
//     IMPLEMENTATION SECTION
//
S
Sean Barrett 已提交
198 199

#ifdef STB_RECT_PACK_IMPLEMENTATION
200
#ifndef STBRP_SORT
S
Sean Barrett 已提交
201
#include <stdlib.h>
202
#define STBRP_SORT qsort
203
#endif
S
Sean Barrett 已提交
204 205

#ifndef STBRP_ASSERT
206
#include <assert.h>
S
Sean Barrett 已提交
207 208
#define STBRP_ASSERT assert
#endif
S
Sean Barrett 已提交
209

C
cosmy1 已提交
210 211 212 213 214 215
#ifdef _MSC_VER
#define STBRP__NOTUSED(v)  (void)(v)
#else
#define STBRP__NOTUSED(v)  (void)sizeof(v)
#endif

S
Sean Barrett 已提交
216 217
enum
{
C
cosmy1 已提交
218
   STBRP__INIT_skyline = 1
S
Sean Barrett 已提交
219 220
};

221
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
S
Sean Barrett 已提交
222 223 224
{
   switch (context->init_mode) {
      case STBRP__INIT_skyline:
S
Sean Barrett 已提交
225
         STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
226
         context->heuristic = heuristic;
S
Sean Barrett 已提交
227 228
         break;
      default:
S
Sean Barrett 已提交
229
         STBRP_ASSERT(0);
S
Sean Barrett 已提交
230 231 232
   }
}

233
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
S
Sean Barrett 已提交
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
{
   if (allow_out_of_mem)
      // if it's ok to run out of memory, then don't bother aligning them;
      // this gives better packing, but may fail due to OOM (even though
      // the rectangles easily fit). @TODO a smarter approach would be to only
      // quantize once we've hit OOM, then we could get rid of this parameter.
      context->align = 1;
   else {
      // if it's not ok to run out of memory, then quantize the widths
      // so that num_nodes is always enough nodes.
      //
      // I.e. num_nodes * align >= width
      //                  align >= width / num_nodes
      //                  align = ceil(width/num_nodes)

      context->align = (context->width + context->num_nodes-1) / context->num_nodes;
   }
}

253
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
S
Sean Barrett 已提交
254 255
{
   int i;
256
#ifndef STBRP_LARGE_RECTS
S
Sean Barrett 已提交
257
   STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
258 259
#endif

S
Sean Barrett 已提交
260 261 262 263 264 265 266 267
   for (i=0; i < num_nodes-1; ++i)
      nodes[i].next = &nodes[i+1];
   nodes[i].next = NULL;
   context->init_mode = STBRP__INIT_skyline;
   context->heuristic = STBRP_HEURISTIC_Skyline_default;
   context->free_head = &nodes[0];
   context->active_head = &context->extra[0];
   context->width = width;
268
   context->height = height;
S
Sean Barrett 已提交
269
   context->num_nodes = num_nodes;
270
   stbrp_setup_allow_out_of_mem(context, 0);
S
Sean Barrett 已提交
271 272 273 274 275

   // node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
   context->extra[0].x = 0;
   context->extra[0].y = 0;
   context->extra[0].next = &context->extra[1];
276
   context->extra[1].x = (stbrp_coord) width;
277 278 279
#ifdef STBRP_LARGE_RECTS
   context->extra[1].y = (1<<30);
#else
S
Sean Barrett 已提交
280
   context->extra[1].y = 65535;
281 282
#endif
   context->extra[1].next = NULL;
S
Sean Barrett 已提交
283 284 285 286 287 288 289 290
}

// find minimum y position if it starts at x1
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
{
   stbrp_node *node = first;
   int x1 = x0 + width;
   int min_y, visited_width, waste_area;
S
Sean Barrett 已提交
291

C
cosmy1 已提交
292
   STBRP__NOTUSED(c);
S
Sean Barrett 已提交
293

S
Sean Barrett 已提交
294
   STBRP_ASSERT(first->x <= x0);
S
Sean Barrett 已提交
295 296 297 298 299 300

   #if 0
   // skip in case we're past the node
   while (node->next->x <= x0)
      ++node;
   #else
S
Sean Barrett 已提交
301
   STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
S
Sean Barrett 已提交
302 303
   #endif

S
Sean Barrett 已提交
304
   STBRP_ASSERT(node->x <= x0);
S
Sean Barrett 已提交
305 306 307 308

   min_y = 0;
   waste_area = 0;
   visited_width = 0;
309
   while (node->x < x1) {
S
Sean Barrett 已提交
310 311 312
      if (node->y > min_y) {
         // raise min_y higher.
         // we've accounted for all waste up to min_y,
313
         // but we'll now add more waste for everything we've visted
S
Sean Barrett 已提交
314 315
         waste_area += visited_width * (node->y - min_y);
         min_y = node->y;
316 317 318 319 320
         // the first time through, visited_width might be reduced
         if (node->x < x0)
            visited_width += node->next->x - x0;
         else
            visited_width += node->next->x - node->x;
S
Sean Barrett 已提交
321 322 323 324 325 326
      } else {
         // add waste area
         int under_width = node->next->x - node->x;
         if (under_width + visited_width > width)
            under_width = width - visited_width;
         waste_area += under_width * (min_y - node->y);
327
         visited_width += under_width;
S
Sean Barrett 已提交
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
      }
      node = node->next;
   }

   *pwaste = waste_area;
   return min_y;
}

typedef struct
{
   int x,y;
   stbrp_node **prev_link;
} stbrp__findresult;

static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
{
344
   int best_waste = (1<<30), best_x, best_y = (1 << 30);
S
Sean Barrett 已提交
345 346 347 348 349 350
   stbrp__findresult fr;
   stbrp_node **prev, *node, *tail, **best = NULL;

   // align to multiple of c->align
   width = (width + c->align - 1);
   width -= width % c->align;
S
Sean Barrett 已提交
351
   STBRP_ASSERT(width % c->align == 0);
S
Sean Barrett 已提交
352

F
Fabian Giesen 已提交
353 354 355 356 357 358 359
   // if it can't possibly fit, bail immediately
   if (width > c->width || height > c->height) {
      fr.prev_link = NULL;
      fr.x = fr.y = 0;
      return fr;
   }

S
Sean Barrett 已提交
360 361
   node = c->active_head;
   prev = &c->active_head;
362
   while (node->x + width <= c->width) {
S
Sean Barrett 已提交
363 364 365 366 367 368 369 370 371 372
      int y,waste;
      y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
      if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
         // bottom left
         if (y < best_y) {
            best_y = y;
            best = prev;
         }
      } else {
         // best-fit
373
         if (y + height <= c->height) {
S
Sean Barrett 已提交
374
            // can only use it if it first vertically
375
            if (y < best_y || (y == best_y && waste < best_waste)) {
S
Sean Barrett 已提交
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
               best_y = y;
               best_waste = waste;
               best = prev;
            }
         }
      }
      prev = &node->next;
      node = node->next;
   }

   best_x = (best == NULL) ? 0 : (*best)->x;

   // if doing best-fit (BF), we also have to try aligning right edge to each node position
   //
   // e.g, if fitting
   //
   //     ____________________
   //    |____________________|
   //
   //            into
   //
   //   |                         |
   //   |             ____________|
   //   |____________|
   //
   // then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
   //
   // This makes BF take about 2x the time

   if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
      tail = c->active_head;
      node = c->active_head;
      prev = &c->active_head;
      // find first node that's admissible
      while (tail->x < width)
         tail = tail->next;
412
      while (tail) {
S
Sean Barrett 已提交
413 414
         int xpos = tail->x - width;
         int y,waste;
S
Sean Barrett 已提交
415
         STBRP_ASSERT(xpos >= 0);
S
Sean Barrett 已提交
416 417
         // find the left position that matches this
         while (node->next->x <= xpos) {
418
            prev = &node->next;
S
Sean Barrett 已提交
419 420
            node = node->next;
         }
S
Sean Barrett 已提交
421
         STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
S
Sean Barrett 已提交
422
         y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
F
Fabian Giesen 已提交
423
         if (y + height <= c->height) {
424 425 426
            if (y <= best_y) {
               if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
                  best_x = xpos;
S
Sean Barrett 已提交
427
                  STBRP_ASSERT(y <= best_y);
428 429 430 431
                  best_y = y;
                  best_waste = waste;
                  best = prev;
               }
S
Sean Barrett 已提交
432 433 434
            }
         }
         tail = tail->next;
S
Sean Barrett 已提交
435
      }
S
Sean Barrett 已提交
436 437
   }

438
   fr.prev_link = best;
S
Sean Barrett 已提交
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
   fr.x = best_x;
   fr.y = best_y;
   return fr;
}

static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
{
   // find best position according to heuristic
   stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
   stbrp_node *node, *cur;

   // bail if:
   //    1. it failed
   //    2. the best node doesn't fit (we don't always check this)
   //    3. we're out of memory
   if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
      res.prev_link = NULL;
      return res;
   }

   // on success, create new node
   node = context->free_head;
461 462
   node->x = (stbrp_coord) res.x;
   node->y = (stbrp_coord) (res.y + height);
S
Sean Barrett 已提交
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479

   context->free_head = node->next;

   // insert the new node into the right starting point, and
   // let 'cur' point to the remaining nodes needing to be
   // stiched back in

   cur = *res.prev_link;
   if (cur->x < res.x) {
      // preserve the existing one, so start testing with the next one
      stbrp_node *next = cur->next;
      cur->next = node;
      cur = next;
   } else {
      *res.prev_link = node;
   }

480
   // from here, traverse cur and free the nodes, until we get to one
S
Sean Barrett 已提交
481
   // that shouldn't be freed
482
   while (cur->next && cur->next->x <= res.x + width) {
S
Sean Barrett 已提交
483 484 485
      stbrp_node *next = cur->next;
      // move the current node to the free list
      cur->next = context->free_head;
486
      context->free_head = cur;
S
Sean Barrett 已提交
487 488 489
      cur = next;
   }

490
   // stitch the list back in
S
Sean Barrett 已提交
491 492 493
   node->next = cur;

   if (cur->x < res.x + width)
494
      cur->x = (stbrp_coord) (res.x + width);
S
Sean Barrett 已提交
495 496 497 498

#ifdef _DEBUG
   cur = context->active_head;
   while (cur->x < context->width) {
S
Sean Barrett 已提交
499
      STBRP_ASSERT(cur->x < cur->next->x);
S
Sean Barrett 已提交
500 501
      cur = cur->next;
   }
S
Sean Barrett 已提交
502
   STBRP_ASSERT(cur->next == NULL);
503 504 505 506 507 508 509 510 511 512 513 514 515

   {
      int count=0;
      cur = context->active_head;
      while (cur) {
         cur = cur->next;
         ++count;
      }
      cur = context->free_head;
      while (cur) {
         cur = cur->next;
         ++count;
      }
S
Sean Barrett 已提交
516
      STBRP_ASSERT(count == context->num_nodes+2);
517
   }
S
Sean Barrett 已提交
518 519 520 521 522 523 524
#endif

   return res;
}

static int rect_height_compare(const void *a, const void *b)
{
525 526
   const stbrp_rect *p = (const stbrp_rect *) a;
   const stbrp_rect *q = (const stbrp_rect *) b;
S
Sean Barrett 已提交
527 528 529 530 531 532 533 534 535
   if (p->h > q->h)
      return -1;
   if (p->h < q->h)
      return  1;
   return (p->w > q->w) ? -1 : (p->w < q->w);
}

static int rect_original_order(const void *a, const void *b)
{
536 537
   const stbrp_rect *p = (const stbrp_rect *) a;
   const stbrp_rect *q = (const stbrp_rect *) b;
S
Sean Barrett 已提交
538 539 540
   return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
}

S
Sean Barrett 已提交
541 542 543 544 545 546
#ifdef STBRP_LARGE_RECTS
#define STBRP__MAXVAL  0xffffffff
#else
#define STBRP__MAXVAL  0xffff
#endif

547
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
S
Sean Barrett 已提交
548
{
549
   int i, all_rects_packed = 1;
S
Sean Barrett 已提交
550 551

   // we use the 'was_packed' field internally to allow sorting/unsorting
552
   for (i=0; i < num_rects; ++i) {
S
Sean Barrett 已提交
553
      rects[i].was_packed = i;
554
   }
S
Sean Barrett 已提交
555 556

   // sort according to heuristic
557
   STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
S
Sean Barrett 已提交
558 559

   for (i=0; i < num_rects; ++i) {
560 561
      if (rects[i].w == 0 || rects[i].h == 0) {
         rects[i].x = rects[i].y = 0;  // empty rect needs no space
S
Sean Barrett 已提交
562
      } else {
S
Sean Barrett 已提交
563
         stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
564 565 566 567 568 569
         if (fr.prev_link) {
            rects[i].x = (stbrp_coord) fr.x;
            rects[i].y = (stbrp_coord) fr.y;
         } else {
            rects[i].x = rects[i].y = STBRP__MAXVAL;
         }
S
Sean Barrett 已提交
570 571 572 573
      }
   }

   // unsort
574
   STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
S
Sean Barrett 已提交
575

576
   // set was_packed flags and all_rects_packed status
S
Sean Barrett 已提交
577 578 579
   for (i=0; i < num_rects; ++i) {
      rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
      if (!rects[i].was_packed)
580 581 582 583 584
         all_rects_packed = 0;
   }

   // return the all_rects_packed status
   return all_rects_packed;
S
Sean Barrett 已提交
585 586
}
#endif
587 588 589 590 591 592 593

/*
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2017 Sean Barrett
S
Sean Barrett 已提交
594 595 596 597 598
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
599
so, subject to the following conditions:
S
Sean Barrett 已提交
600
The above copyright notice and this permission notice shall be included in all
601
copies or substantial portions of the Software.
S
Sean Barrett 已提交
602 603 604 605 606 607
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
608 609 610 611
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
S
Sean Barrett 已提交
612 613
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
614
commercial or non-commercial, and by any means.
S
Sean Barrett 已提交
615 616 617 618 619
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
620
this software under copyright law.
S
Sean Barrett 已提交
621 622 623 624 625
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
626 627 628
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
*/