imstb_rectpack.h 20 KB

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