imstb_rectpack.h 20 KB

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