53 #ifndef STB_INCLUDE_STB_RECT_PACK_H 54 #define STB_INCLUDE_STB_RECT_PACK_H 56 #define STB_RECT_PACK_VERSION 1 59 #define STBRP_DEF static 61 #define STBRP_DEF extern 72 #ifdef STBRP_LARGE_RECTS 190 #ifdef STB_RECT_PACK_IMPLEMENTATION 193 #define STBRP_SORT qsort 198 #define STBRP_ASSERT assert 203 STBRP__INIT_skyline = 1
209 case STBRP__INIT_skyline:
220 if (allow_out_of_mem)
241 #ifndef STBRP_LARGE_RECTS 245 for (i=0; i < num_nodes-1; ++
i)
246 nodes[i].
next = &nodes[i+1];
248 context->
init_mode = STBRP__INIT_skyline;
262 #ifdef STBRP_LARGE_RECTS 263 context->
extra[1].
y = (1<<30);
265 context->
extra[1].
y = 65535;
276 int min_y, visited_width, waste_area;
292 while (node->
x < x1) {
293 if (node->
y > min_y) {
297 waste_area += visited_width * (node->
y - min_y);
301 visited_width += node->
next->
x -
x0;
303 visited_width += node->
next->
x - node->
x;
306 int under_width = node->
next->
x - node->
x;
307 if (under_width + visited_width > width)
308 under_width = width - visited_width;
309 waste_area += under_width * (min_y - node->
y);
310 visited_width += under_width;
315 *pwaste = waste_area;
327 int best_waste = (1<<30), best_x, best_y = (1 << 30);
328 stbrp__findresult fr;
340 y = stbrp__skyline_find_min_y(c, node, node->
x, width, &waste);
351 if (y < best_y || (y == best_y && waste < best_waste)) {
362 best_x = (best ==
NULL) ? 0 : (*best)->
x;
386 while (tail->
x < width)
393 while (node->
next->
x <= xpos) {
398 y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
401 if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
423 stbrp__findresult
res = stbrp__skyline_find_best_pos(context,
width, height);
431 res.prev_link =
NULL;
446 cur = *res.prev_link;
447 if (cur->
x < res.x) {
453 *res.prev_link = node;
469 if (cur->
x < res.x +
width)
474 while (cur->
x < context->
width) {
502 static int rect_height_compare(
const void *
a,
const void *
b)
510 return (p->
w > q->
w) ? -1 : (p->
w < q->
w);
513 static int rect_width_compare(
const void *
a,
const void *
b)
521 return (p->
h > q->
h) ? -1 : (p->
h < q->
h);
524 static int rect_original_order(
const void *
a,
const void *
b)
531 #ifdef STBRP_LARGE_RECTS 532 #define STBRP__MAXVAL 0xffffffff 534 #define STBRP__MAXVAL 0xffff 542 for (i=0; i < num_rects; ++
i) {
544 #ifndef STBRP_LARGE_RECTS 550 STBRP_SORT(rects, num_rects,
sizeof(rects[0]), rect_height_compare);
552 for (i=0; i < num_rects; ++
i) {
553 if (rects[i].
w == 0 || rects[i].
h == 0) {
554 rects[
i].
x = rects[
i].
y = 0;
556 stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].
w, rects[i].
h);
561 rects[
i].
x = rects[
i].
y = STBRP__MAXVAL;
567 STBRP_SORT(rects, num_rects,
sizeof(rects[0]), rect_original_order);
570 for (i=0; i < num_rects; ++
i)
571 rects[i].
was_packed = !(rects[i].
x == STBRP__MAXVAL && rects[i].
y == STBRP__MAXVAL);
GLboolean GLboolean GLboolean b
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
GLdouble GLdouble GLdouble w
GLfloat GLfloat GLfloat GLfloat h
GLboolean GLboolean GLboolean GLboolean a
unsigned short stbrp_coord
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
GLint GLsizei GLsizei height
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
void next(auto_any_t cur, type2type< T, C > *)
GLuint GLfloat GLfloat GLfloat x1
GLdouble GLdouble GLdouble q