1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:47:37 +00:00

LibGfx: Make some coding style fixes to FastBoxBlurFilter

This commit is contained in:
Andreas Kling 2021-09-17 12:59:44 +02:00
parent e2e6c12ea0
commit 850795e088

View file

@ -6,7 +6,6 @@
#pragma once #pragma once
#include <LibCore/ElapsedTimer.h>
#include <LibGfx/Bitmap.h> #include <LibGfx/Bitmap.h>
namespace Gfx { namespace Gfx {
@ -29,18 +28,20 @@ public:
int div = 2 * radius + 1; int div = 2 * radius + 1;
size_t sum_red, sum_green, sum_blue, sum_alpha;
u8 intermediate_red[width * height]; u8 intermediate_red[width * height];
u8 intermediate_green[width * height]; u8 intermediate_green[width * height];
u8 intermediate_blue[width * height]; u8 intermediate_blue[width * height];
u8 intermediate_alpha[width * height]; u8 intermediate_alpha[width * height];
// First pass: vertical // First pass: vertical
for (int y = 0; y < height; y++) { for (int y = 0; y < height; ++y) {
sum_red = sum_green = sum_blue = sum_alpha = 0; size_t sum_red = 0;
size_t sum_green = 0;
size_t sum_blue = 0;
size_t sum_alpha = 0;
// Setup sliding window // Setup sliding window
for (int i = -radius; i <= radius; i++) { for (int i = -radius; i <= radius; ++i) {
auto color_at_px = m_bitmap.get_pixel<StorageFormat::BGRA8888>(clamp(i, 0, width - 1), y); auto color_at_px = m_bitmap.get_pixel<StorageFormat::BGRA8888>(clamp(i, 0, width - 1), y);
sum_red += red_value(color_at_px); sum_red += red_value(color_at_px);
sum_green += green_value(color_at_px); sum_green += green_value(color_at_px);
@ -48,7 +49,7 @@ public:
sum_alpha += color_at_px.alpha(); sum_alpha += color_at_px.alpha();
} }
// Slide horizontally // Slide horizontally
for (int x = 0; x < width; x++) { for (int x = 0; x < width; ++x) {
intermediate_red[y * width + x] = (sum_red / div); intermediate_red[y * width + x] = (sum_red / div);
intermediate_green[y * width + x] = (sum_green / div); intermediate_green[y * width + x] = (sum_green / div);
intermediate_blue[y * width + x] = (sum_blue / div); intermediate_blue[y * width + x] = (sum_blue / div);
@ -72,10 +73,14 @@ public:
} }
// Second pass: horizontal // Second pass: horizontal
for (int x = 0; x < width; x++) { for (int x = 0; x < width; ++x) {
sum_red = sum_green = sum_blue = sum_alpha = 0; size_t sum_red = 0;
size_t sum_green = 0;
size_t sum_blue = 0;
size_t sum_alpha = 0;
// Setup sliding window // Setup sliding window
for (int i = -radius; i <= radius; i++) { for (int i = -radius; i <= radius; ++i) {
int offset = clamp(i, 0, height - 1) * width + x; int offset = clamp(i, 0, height - 1) * width + x;
sum_red += intermediate_red[offset]; sum_red += intermediate_red[offset];
sum_green += intermediate_green[offset]; sum_green += intermediate_green[offset];
@ -83,7 +88,7 @@ public:
sum_alpha += intermediate_alpha[offset]; sum_alpha += intermediate_alpha[offset];
} }
for (int y = 0; y < height; y++) { for (int y = 0; y < height; ++y) {
auto color = Color( auto color = Color(
sum_red / div, sum_red / div,
sum_green / div, sum_green / div,
@ -113,16 +118,16 @@ public:
if (!radius) if (!radius)
return; return;
size_t no_of_passes = 3; constexpr size_t no_of_passes = 3;
double wIdeal = sqrt((12 * radius * radius / (double)no_of_passes) + 1); double w_ideal = sqrt((12 * radius * radius / (double)no_of_passes) + 1);
int wl = floor(wIdeal); int wl = floor(w_ideal);
if (wl % 2 == 0) if (wl % 2 == 0)
wl--; wl--;
int wu = wl - 2; int wu = wl - 2;
double mIdeal = (12 * radius * radius - no_of_passes * wl * wl - 4 * no_of_passes * wl - 3 * no_of_passes) / (double)(-4 * wl - 4); double m_ideal = (12 * radius * radius - no_of_passes * wl * wl - 4 * no_of_passes * wl - 3 * no_of_passes) / (double)(-4 * wl - 4);
int m = round(mIdeal); int m = round(m_ideal);
for (size_t i = 0; i < no_of_passes; i++) { for (size_t i = 0; i < no_of_passes; ++i) {
int weighted_radius = (int)i < m ? wl : wu; int weighted_radius = (int)i < m ? wl : wu;
if (weighted_radius < 2) if (weighted_radius < 2)
continue; continue;
@ -131,15 +136,15 @@ public:
} }
private: private:
ALWAYS_INLINE static u8 red_value(Color const& color) ALWAYS_INLINE static u8 red_value(Color color)
{ {
return (color.alpha() == 0) ? 0xFF : color.red(); return (color.alpha() == 0) ? 0xFF : color.red();
} }
ALWAYS_INLINE static u8 green_value(Color const& color) ALWAYS_INLINE static u8 green_value(Color color)
{ {
return (color.alpha() == 0) ? 0xFF : color.green(); return (color.alpha() == 0) ? 0xFF : color.green();
} }
ALWAYS_INLINE static u8 blue_value(Color const& color) ALWAYS_INLINE static u8 blue_value(Color color)
{ {
return (color.alpha() == 0) ? 0xFF : color.blue(); return (color.alpha() == 0) ? 0xFF : color.blue();
} }