| 78 | /////////////////////////////////////////// |
| 79 | |
| 80 | tex_t dev_texture(const char *id, color128 base_color, float contrast_boost) { |
| 81 | tex_t result = tex_create(); |
| 82 | tex_set_id(result, id); |
| 83 | |
| 84 | const int32_t size = 256; // Texture total size |
| 85 | const int32_t slices = 4; // Slice this up into 4x4 squares |
| 86 | const int32_t slice_size = size / slices; // Size in px of each square |
| 87 | const int32_t slice_half = slice_size/2; // precalculate half (for lines) |
| 88 | const int32_t slice_quarter = slice_size/4; // precalculate quarter (for lines) |
| 89 | const int32_t checker_size = size / (slices * 2); // Alternate core color in a checker pattern, with 2 checkers per slice |
| 90 | |
| 91 | vec3 lab = color_to_lab(base_color); |
| 92 | color32 core_color = color_to_32(base_color); |
| 93 | color32 core_color2 = color_to_32(color_lab(lab.x * powf(0.9f, contrast_boost), lab.y, lab.z, 1)); |
| 94 | color32 line_color = color_to_32(color_lab(lab.x * powf(0.8f, contrast_boost), lab.y, lab.z, 1)); |
| 95 | color32 line2_color = color_to_32(color_lab(lab.x * powf(0.75f, contrast_boost), lab.y, lab.z, 1)); |
| 96 | |
| 97 | color32 *data = sk_malloc_t(color32, size * size); |
| 98 | for (int32_t y = 0; y < size; y++) { |
| 99 | int ydist = abs(slice_half - ((y + slice_half ) % slice_size)); |
| 100 | int ydist2 = abs(slice_quarter - ((y + slice_quarter) % slice_half)); |
| 101 | |
| 102 | for (int32_t x = 0; x < size; x++) { |
| 103 | int xdist = abs(slice_half - ((x + slice_half ) % slice_size)); |
| 104 | int xdist2 = abs(slice_quarter - ((x + slice_quarter) % slice_half)); |
| 105 | |
| 106 | int32_t i = x + y * size; |
| 107 | if (xdist < 2 || ydist <2) data[i] = line_color; |
| 108 | else if (xdist2< 1 || ydist2<1) data[i] = line2_color; |
| 109 | else data[i] = ((x/checker_size) + (y/checker_size)) %2 == 0 ? core_color : core_color2; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | tex_set_colors(result, size, size, data); |
| 114 | sk_free(data); |
| 115 | |
| 116 | return result; |
| 117 | } |
| 118 | |
| 119 | /////////////////////////////////////////// |
| 120 |
no test coverage detected