1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:07:45 +00:00

LibGfx: Get rid of Gfx::Rect<float> area workaround in Painter

We can now trust `Gfx::Rect<T>` to correctly calculate rectangle
intersections when `T = float`.
This commit is contained in:
Jelle Raaijmakers 2023-05-22 00:58:42 +02:00 committed by Andreas Kling
parent f391ccfe53
commit a02b28e6c8

View file

@ -1179,20 +1179,6 @@ ALWAYS_INLINE static void do_draw_box_sampled_scaled_bitmap(Gfx::Bitmap& target,
float source_pixel_area = source_pixel_width * source_pixel_height; float source_pixel_area = source_pixel_width * source_pixel_height;
FloatRect const pixel_box = { 0.f, 0.f, 1.f, 1.f }; FloatRect const pixel_box = { 0.f, 0.f, 1.f, 1.f };
// FIXME: FloatRect.right() and .bottom() subtract 1 since that is what IntRect does as well.
// This is obviously wrong and causes issues with at least .intersect(). Probably the
// best course of action is to fix Rect's behavior for .right() and .bottom(), and then
// replace this with FloatRect.intersected(...).size().area().
auto float_rect_intersection_area_fixme = [](FloatRect const& a, FloatRect const& b) -> float {
float intersected_left = max(a.left(), b.left());
float intersected_right = min(a.left() + a.width(), b.left() + b.width());
float intersected_top = max(a.top(), b.top());
float intersected_bottom = min(a.top() + a.height(), b.top() + b.height());
if (intersected_left >= intersected_right || intersected_top >= intersected_bottom)
return 0.f;
return (intersected_right - intersected_left) * (intersected_bottom - intersected_top);
};
for (int y = clipped_rect.top(); y < clipped_rect.bottom(); ++y) { for (int y = clipped_rect.top(); y < clipped_rect.bottom(); ++y) {
auto* scanline = reinterpret_cast<Color*>(target.scanline(y)); auto* scanline = reinterpret_cast<Color*>(target.scanline(y));
for (int x = clipped_rect.left(); x < clipped_rect.right(); ++x) { for (int x = clipped_rect.left(); x < clipped_rect.right(); ++x) {
@ -1212,7 +1198,7 @@ ALWAYS_INLINE static void do_draw_box_sampled_scaled_bitmap(Gfx::Bitmap& target,
float total_area = 0.f; float total_area = 0.f;
for (int sy = enclosing_source_box.y(); sy < enclosing_source_box.bottom(); ++sy) { for (int sy = enclosing_source_box.y(); sy < enclosing_source_box.bottom(); ++sy) {
for (int sx = enclosing_source_box.x(); sx < enclosing_source_box.right(); ++sx) { for (int sx = enclosing_source_box.x(); sx < enclosing_source_box.right(); ++sx) {
float area = float_rect_intersection_area_fixme(source_box, pixel_box.translated(sx, sy)); float area = source_box.intersected(pixel_box.translated(sx, sy)).size().area();
auto pixel = get_pixel(source, sx, sy); auto pixel = get_pixel(source, sx, sy);
area *= pixel.alpha() / 255.f; area *= pixel.alpha() / 255.f;