From 1268b39ba0b3c7e8a70baf19672c0a65205963cd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 18 Aug 2021 11:26:36 +0200 Subject: [PATCH] LibGfx: Make FastBoxBlurFilter go faster When entering FastBoxBlurFilter::apply_single_pass(), we VERIFY that the bitmap format is BGRA8888. This invariant allows us to use get_pixel() instead of the generic get_pixel() throughout the function. This removes a lot of branches and makes the filter significantly faster. :^) --- Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.h b/Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.h index 4ae97faf101..8389ad9abad 100644 --- a/Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.h +++ b/Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.h @@ -41,7 +41,7 @@ public: sum_red = sum_green = sum_blue = sum_alpha = 0; // Setup sliding window for (int i = -radius; i <= radius; i++) { - auto color_at_px = m_bitmap.get_pixel(clamp(i, 0, width - 1), y); + auto color_at_px = m_bitmap.get_pixel(clamp(i, 0, width - 1), y); sum_red += red_value(color_at_px); sum_green += green_value(color_at_px); sum_blue += blue_value(color_at_px); @@ -57,8 +57,8 @@ public: auto leftmost_x_coord = max(x - radius, 0); auto rightmost_x_coord = min(x + radius + 1, width - 1); - auto leftmost_x_color = m_bitmap.get_pixel(leftmost_x_coord, y); - auto rightmost_x_color = m_bitmap.get_pixel(rightmost_x_coord, y); + auto leftmost_x_color = m_bitmap.get_pixel(leftmost_x_coord, y); + auto rightmost_x_color = m_bitmap.get_pixel(rightmost_x_coord, y); sum_red -= red_value(leftmost_x_color); sum_red += red_value(rightmost_x_color); @@ -90,7 +90,7 @@ public: sum_blue / div, sum_alpha / div); - m_bitmap.set_pixel(x, y, color); + m_bitmap.set_pixel(x, y, color); auto topmost_y_coord = max(y - radius, 0); auto bottommost_y_coord = min(y + radius + 1, height - 1);