MCPcopy Create free account
hub / github.com/BinomialLLC/basis_universal / wrap_image

Function wrap_image

example/example.cpp:572–649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

570}
571
572void wrap_image(const image& src, image& dst, int gridX, int gridY, float maxOffset, bool randomize, basisu::rand &rnd)
573{
574 if (gridX < 1) gridX = 1;
575 if (gridY < 1) gridY = 1;
576
577 const int vxCountX = gridX + 1;
578 const int vxCountY = gridY + 1;
579 const int stride = vxCountX;
580
581 const int w = src.get_width();
582 const int h = src.get_height();
583
584 dst.resize(w, h);
585
586 dst.set_all(g_black_color);
587
588 basisu::vector<vec2F> verts(vxCountX * vxCountY);
589 basisu::vector<vec2F> uvs(vxCountX * vxCountY);
590 basisu::vector<color_rgba> cols(vxCountX * vxCountY);
591
592 for (int gy = 0; gy <= gridY; ++gy)
593 {
594 for (int gx = 0; gx <= gridX; ++gx)
595 {
596 float x = (gx / float(gridX)) * (w - 1);
597 float y = (gy / float(gridY)) * (h - 1);
598
599 float rx = x;
600 float ry = y;
601
602 if (randomize)
603 {
604 rx += rnd.frand(-maxOffset, maxOffset);
605 ry += rnd.frand(-maxOffset, maxOffset);
606 }
607
608 verts[gy * stride + gx] = { rx, ry };
609
610 float u = gx / float(gridX);
611 float v = gy / float(gridY);
612
613 u = std::max(0.0f, std::min(1.0f, u));
614 v = std::max(0.0f, std::min(1.0f, v));
615
616 uvs[gy * stride + gx] = { u, v };
617
618 color_rgba c(g_white_color);
619
620 cols[gy * stride + gx] = c;
621 }
622 }
623
624 for (int gy = 0; gy < gridY; ++gy)
625 {
626 for (int gx = 0; gx < gridX; ++gx)
627 {
628 int i0 = gy * stride + gx;
629 int i1 = i0 + 1;

Callers 1

random_compress_testFunction · 0.85

Calls 8

draw_tri2Function · 0.85
maxFunction · 0.50
minFunction · 0.50
get_widthMethod · 0.45
get_heightMethod · 0.45
resizeMethod · 0.45
set_allMethod · 0.45
frandMethod · 0.45

Tested by

no test coverage detected