LibWeb: Fix wrapping glitches on repeating-linear-gradient()s

This fixes some off-by-one wrapping issues that became visible when
running on x86_64. The problem still existed on i686, but by chance
did not show up due to a -/+ 0.000001 difference between the two.
This commit is contained in:
MacDue 2022-10-09 13:48:25 +01:00 committed by Andreas Kling
parent bbc053fa56
commit 35b714163d
Notes: sideshowbarker 2024-07-17 06:06:56 +09:00

View file

@ -209,17 +209,18 @@ void paint_linear_gradient(PaintContext& context, Gfx::IntRect const& gradient_r
return gradient_line_colors[clamp(loc, 0, gradient_color_count - 1)];
};
auto repeat_wrap_if_required = [&](float loc) {
if (data.repeat_length.has_value())
loc = AK::fmod(loc + length, *data.repeat_length);
return loc;
};
for (int y = 0; y < gradient_rect.height(); y++) {
for (int x = 0; x < gradient_rect.width(); x++) {
auto loc = (x * cos_angle - (gradient_rect.height() - y) * -sin_angle) - rotated_start_point_x - start_offset;
if (data.repeat_length.has_value()) {
loc = AK::fmod(loc, *data.repeat_length);
if (loc < 0)
loc = *data.repeat_length + loc;
}
// Blend between the two neighbouring colors (this fixes some nasty aliasing issues at small angles)
auto loc = repeat_wrap_if_required((x * cos_angle - (gradient_rect.height() - y) * -sin_angle) - rotated_start_point_x - start_offset);
auto blend = loc - static_cast<int>(loc);
auto gradient_color = lookup_color(loc - 1).mixed_with(lookup_color(loc), blend);
// Blend between the two neighbouring colors (this fixes some nasty aliasing issues at small angles)
auto gradient_color = lookup_color(loc).mixed_with(lookup_color(repeat_wrap_if_required(loc + 1)), blend);
context.painter().set_pixel(gradient_rect.x() + x, gradient_rect.y() + y, gradient_color, gradient_color.alpha() < 255);
}
}