| 103 | } |
| 104 | |
| 105 | void HyperImage::radialFill(int center_x, int center_y, double diag, const std::vector<uint8_t>& points) |
| 106 | { |
| 107 | auto data = _surface.rawMem(); |
| 108 | auto h = this->height(); |
| 109 | auto w = this->width(); |
| 110 | |
| 111 | if (points.size() < 5 || points.size() % 5) |
| 112 | return; |
| 113 | |
| 114 | for (int y = 0; y < h; y++) |
| 115 | { |
| 116 | for (int x = 0; x < w; x++) |
| 117 | { |
| 118 | ColorRgb c; |
| 119 | float dx = (center_x - x); |
| 120 | float dy = (center_y - y); |
| 121 | float len = dx * dx + dy * dy; |
| 122 | int currentAngle = 0; |
| 123 | |
| 124 | if (len > 0.0) |
| 125 | { |
| 126 | currentAngle = ColorRgb::clamp(std::round(std::sqrt(len) * 255.0 / diag )); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | int lastAngle = 0, lastAlfa = 0; |
| 131 | ColorRgb lastColor; |
| 132 | |
| 133 | for (size_t index = 0; index < points.size(); index += 5) |
| 134 | { |
| 135 | int nextAngle = points[index]; |
| 136 | ColorRgb nextColor = ColorRgb(points[index + 1], points[index + 2], points[index + 3]); |
| 137 | int nextAlfa = points[index + 4]; |
| 138 | |
| 139 | if (index > 0) |
| 140 | { |
| 141 | if (lastAngle <= currentAngle && currentAngle <= nextAngle) |
| 142 | { |
| 143 | float distance = nextAngle - lastAngle; |
| 144 | float aspect2 = (currentAngle - lastAngle) / distance; |
| 145 | float aspect1 = 1.0 - aspect2; |
| 146 | |
| 147 | if (nextAlfa > 0 && lastAlfa > 0) |
| 148 | { |
| 149 | c.red = ColorRgb::clamp(lastColor.red * aspect1 + nextColor.red * aspect2); |
| 150 | c.green = ColorRgb::clamp(lastColor.green * aspect1 + nextColor.green * aspect2); |
| 151 | c.blue = ColorRgb::clamp(lastColor.blue * aspect1 + nextColor.blue * aspect2); |
| 152 | if (nextAlfa != lastAlfa) |
| 153 | lastAlfa = ColorRgb::clamp(std::round(nextAlfa * aspect2 + lastAlfa * aspect1)); |
| 154 | } |
| 155 | else if (nextAlfa > 0) |
| 156 | { |
| 157 | c.red = ColorRgb::clamp(nextColor.red * aspect2 * nextAlfa / 255.0); |
| 158 | c.green = ColorRgb::clamp(nextColor.green * aspect2 * nextAlfa / 255.0); |
| 159 | c.blue = ColorRgb::clamp(nextColor.blue * aspect2 * nextAlfa / 255.0); |
| 160 | lastAlfa = ColorRgb::clamp(std::round(nextAlfa * aspect2)); |
| 161 | } |
| 162 | else if (lastAlfa > 0) |