summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTobias Christiansen <tobyase@serenityos.org>2022-03-16 13:52:31 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-17 20:03:05 +0100
commit5f063e832e504ce13d41fd642f6538a9b440fb4b (patch)
tree3b3661a0ba05287529bf14ec5391e1679edfb400 /Userland
parent9c56a83b7600aef977d7cdec567b1b7a0d134ab2 (diff)
downloadserenity-5f063e832e504ce13d41fd642f6538a9b440fb4b.zip
LibGfx: Make FastBoxBlurFilter::apply_single_pass's argument unsigned
It isn't sensible to have a negative radius for blurring, so an unsigned value is the right thing to do here. Now we have to cast the radius to int a few times when actually doing the calculations but I'm sure that can be done more intelligently, but that optimization is a thing for the future. It looked very goofy for the two different ways of invoking the Filter to have differently signed arguments.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.cpp16
-rw-r--r--Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.h2
2 files changed, 8 insertions, 10 deletions
diff --git a/Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.cpp b/Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.cpp
index 10f6181576..57c632521e 100644
--- a/Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.cpp
+++ b/Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.cpp
@@ -29,10 +29,8 @@ FastBoxBlurFilter::FastBoxBlurFilter(Bitmap& bitmap)
}
// Based on the super fast blur algorithm by Quasimondo, explored here: https://stackoverflow.com/questions/21418892/understanding-super-fast-blur-algorithm
-void FastBoxBlurFilter::apply_single_pass(int radius)
+void FastBoxBlurFilter::apply_single_pass(size_t radius)
{
- VERIFY(radius >= 0);
-
auto format = m_bitmap.format();
VERIFY(format == BitmapFormat::BGRA8888 || format == BitmapFormat::BGRx8888);
@@ -74,7 +72,7 @@ void FastBoxBlurFilter::apply_single_pass(int radius)
size_t sum_alpha = 0;
// Setup sliding window
- for (int i = -radius; i <= radius; ++i) {
+ for (int i = -(int)radius; i <= (int)radius; ++i) {
auto color_at_px = get_pixel_function(clamp(i, 0, width - 1), y);
sum_red += red_value(color_at_px);
sum_green += green_value(color_at_px);
@@ -88,8 +86,8 @@ void FastBoxBlurFilter::apply_single_pass(int radius)
intermediate_blue[y * width + x] = (sum_blue / div);
intermediate_alpha[y * width + x] = (sum_alpha / div);
- auto leftmost_x_coord = max(x - radius, 0);
- auto rightmost_x_coord = min(x + radius + 1, width - 1);
+ auto leftmost_x_coord = max(x - (int)radius, 0);
+ auto rightmost_x_coord = min(x + (int)radius + 1, width - 1);
auto leftmost_x_color = get_pixel_function(leftmost_x_coord, y);
auto rightmost_x_color = get_pixel_function(rightmost_x_coord, y);
@@ -113,7 +111,7 @@ void FastBoxBlurFilter::apply_single_pass(int radius)
size_t sum_alpha = 0;
// Setup sliding window
- for (int i = -radius; i <= radius; ++i) {
+ for (int i = -(int)radius; i <= (int)radius; ++i) {
int offset = clamp(i, 0, height - 1) * width + x;
sum_red += intermediate_red[offset];
sum_green += intermediate_green[offset];
@@ -130,8 +128,8 @@ void FastBoxBlurFilter::apply_single_pass(int radius)
set_pixel_function(x, y, color);
- auto topmost_y_coord = max(y - radius, 0);
- auto bottommost_y_coord = min(y + radius + 1, height - 1);
+ auto topmost_y_coord = max(y - (int)radius, 0);
+ auto bottommost_y_coord = min(y + (int)radius + 1, height - 1);
sum_red += intermediate_red[x + bottommost_y_coord * width];
sum_red -= intermediate_red[x + topmost_y_coord * width];
diff --git a/Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.h b/Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.h
index 5e7fa96126..57a6fd9c78 100644
--- a/Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.h
+++ b/Userland/Libraries/LibGfx/Filters/FastBoxBlurFilter.h
@@ -14,7 +14,7 @@ class FastBoxBlurFilter {
public:
FastBoxBlurFilter(Bitmap&);
- void apply_single_pass(int radius);
+ void apply_single_pass(size_t radius);
void apply_three_passes(size_t radius);
private: