From e07cf6f41b4ead77e7652e33a169e5784def5317 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 21 Sep 2021 15:36:32 +0100 Subject: [PATCH] LibWeb: Paint bitmaps with rounded_int_rect(), not enclosing_int_rect() This fixes the issue where an `` set to its native size would sometimes still appear blurry, because it had a fractional position, causing `enclosing_int_rect()` to expand by 1px. --- Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp | 2 +- Userland/Libraries/LibWeb/Layout/CanvasBox.cpp | 2 +- Userland/Libraries/LibWeb/Layout/ImageBox.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp index 4a2d45953d..e648d22ca0 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp +++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp @@ -100,7 +100,7 @@ void CanvasRenderingContext2D::draw_image(const HTMLImageElement& image_element, Gfx::FloatRect dst_rect = { x, y, (float)image_element.bitmap()->width(), (float)image_element.bitmap()->height() }; auto rect = m_transform.map(dst_rect); - painter->draw_scaled_bitmap(enclosing_int_rect(rect), *image_element.bitmap(), src_rect, 1.0f, Gfx::Painter::ScalingMode::BilinearBlend); + painter->draw_scaled_bitmap(rounded_int_rect(rect), *image_element.bitmap(), src_rect, 1.0f, Gfx::Painter::ScalingMode::BilinearBlend); } void CanvasRenderingContext2D::scale(float sx, float sy) diff --git a/Userland/Libraries/LibWeb/Layout/CanvasBox.cpp b/Userland/Libraries/LibWeb/Layout/CanvasBox.cpp index cdc9e2fad1..7a4731cf24 100644 --- a/Userland/Libraries/LibWeb/Layout/CanvasBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/CanvasBox.cpp @@ -39,7 +39,7 @@ void CanvasBox::paint(PaintContext& context, PaintPhase phase) return; if (dom_node().bitmap()) - context.painter().draw_scaled_bitmap(enclosing_int_rect(absolute_rect()), *dom_node().bitmap(), dom_node().bitmap()->rect(), 1.0f, Gfx::Painter::ScalingMode::BilinearBlend); + context.painter().draw_scaled_bitmap(rounded_int_rect(absolute_rect()), *dom_node().bitmap(), dom_node().bitmap()->rect(), 1.0f, Gfx::Painter::ScalingMode::BilinearBlend); } } diff --git a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp index 92e3aef9e1..8bfb1f08fa 100644 --- a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp @@ -96,7 +96,7 @@ void ImageBox::paint(PaintContext& context, PaintPhase phase) alt = image_element.src(); context.painter().draw_text(enclosing_int_rect(absolute_rect()), alt, Gfx::TextAlignment::Center, computed_values().color(), Gfx::TextElision::Right); } else if (auto bitmap = m_image_loader.bitmap(m_image_loader.current_frame_index())) { - context.painter().draw_scaled_bitmap(enclosing_int_rect(absolute_rect()), *bitmap, bitmap->rect(), 1.0f, Gfx::Painter::ScalingMode::BilinearBlend); + context.painter().draw_scaled_bitmap(rounded_int_rect(absolute_rect()), *bitmap, bitmap->rect(), 1.0f, Gfx::Painter::ScalingMode::BilinearBlend); } } }