mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:47:34 +00:00
LibGfx: Avoid AK::Function indirection in FastBoxBlurFilter + flatten it
This dropped a few percent when profiling Lubrsi's test.
This commit is contained in:
parent
bb48a61d50
commit
30a0ed6678
1 changed files with 26 additions and 23 deletions
|
@ -33,30 +33,9 @@ void FastBoxBlurFilter::apply_single_pass(size_t radius)
|
|||
apply_single_pass(radius, radius);
|
||||
}
|
||||
|
||||
// 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(size_t radius_x, size_t radius_y)
|
||||
template<typename GetPixelFunction, typename SetPixelFunction>
|
||||
static void do_single_pass(int width, int height, size_t radius_x, size_t radius_y, GetPixelFunction get_pixel_function, SetPixelFunction set_pixel_function)
|
||||
{
|
||||
auto format = m_bitmap.format();
|
||||
VERIFY(format == BitmapFormat::BGRA8888 || format == BitmapFormat::BGRx8888);
|
||||
|
||||
Function<Color(int, int)> get_pixel_function;
|
||||
Function<void(int, int, Color)> set_pixel_function;
|
||||
switch (format) {
|
||||
case BitmapFormat::BGRx8888:
|
||||
get_pixel_function = [&](int x, int y) { return m_bitmap.get_pixel<StorageFormat::BGRx8888>(x, y); };
|
||||
set_pixel_function = [&](int x, int y, Color color) { return m_bitmap.set_pixel<StorageFormat::BGRx8888>(x, y, color); };
|
||||
break;
|
||||
case BitmapFormat::BGRA8888:
|
||||
get_pixel_function = [&](int x, int y) { return m_bitmap.get_pixel<StorageFormat::BGRA8888>(x, y); };
|
||||
set_pixel_function = [&](int x, int y, Color color) { return m_bitmap.set_pixel<StorageFormat::BGRA8888>(x, y, color); };
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
int height = m_bitmap.height();
|
||||
int width = m_bitmap.width();
|
||||
|
||||
int div_x = 2 * radius_x + 1;
|
||||
int div_y = 2 * radius_y + 1;
|
||||
|
||||
|
@ -149,6 +128,30 @@ void FastBoxBlurFilter::apply_single_pass(size_t radius_x, size_t radius_y)
|
|||
}
|
||||
}
|
||||
|
||||
// Based on the super fast blur algorithm by Quasimondo, explored here: https://stackoverflow.com/questions/21418892/understanding-super-fast-blur-algorithm
|
||||
FLATTEN void FastBoxBlurFilter::apply_single_pass(size_t radius_x, size_t radius_y)
|
||||
{
|
||||
auto format = m_bitmap.format();
|
||||
VERIFY(format == BitmapFormat::BGRA8888 || format == BitmapFormat::BGRx8888);
|
||||
|
||||
switch (format) {
|
||||
case BitmapFormat::BGRx8888:
|
||||
do_single_pass(
|
||||
m_bitmap.width(), m_bitmap.height(), radius_x, radius_y,
|
||||
[&](int x, int y) { return m_bitmap.get_pixel<StorageFormat::BGRx8888>(x, y); },
|
||||
[&](int x, int y, Color color) { return m_bitmap.set_pixel<StorageFormat::BGRx8888>(x, y, color); });
|
||||
break;
|
||||
case BitmapFormat::BGRA8888:
|
||||
do_single_pass(
|
||||
m_bitmap.width(), m_bitmap.height(), radius_x, radius_y,
|
||||
[&](int x, int y) { return m_bitmap.get_pixel<StorageFormat::BGRA8888>(x, y); },
|
||||
[&](int x, int y, Color color) { return m_bitmap.set_pixel<StorageFormat::BGRA8888>(x, y, color); });
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
// Math from here: http://blog.ivank.net/fastest-gaussian-blur.html
|
||||
void FastBoxBlurFilter::apply_three_passes(size_t radius)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue