mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:37:45 +00:00
LibGfx: Add LumaFilter
This allows you to specify a luminosity range, all pixels that fall outside this range are set to black, the others are untouched.
This commit is contained in:
parent
06ae5b3536
commit
e4b7d38e18
3 changed files with 58 additions and 0 deletions
|
@ -16,6 +16,7 @@ set(SOURCES
|
||||||
Emoji.cpp
|
Emoji.cpp
|
||||||
Filters/ColorBlindnessFilter.cpp
|
Filters/ColorBlindnessFilter.cpp
|
||||||
Filters/FastBoxBlurFilter.cpp
|
Filters/FastBoxBlurFilter.cpp
|
||||||
|
Filters/LumaFilter.cpp
|
||||||
FontDatabase.cpp
|
FontDatabase.cpp
|
||||||
GIFLoader.cpp
|
GIFLoader.cpp
|
||||||
ICOLoader.cpp
|
ICOLoader.cpp
|
||||||
|
|
33
Userland/Libraries/LibGfx/Filters/LumaFilter.cpp
Normal file
33
Userland/Libraries/LibGfx/Filters/LumaFilter.cpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "LumaFilter.h"
|
||||||
|
namespace Gfx {
|
||||||
|
|
||||||
|
void LumaFilter::apply(u8 lower_bound, u8 upper_bound)
|
||||||
|
{
|
||||||
|
if (upper_bound < lower_bound)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int height = m_bitmap.height();
|
||||||
|
int width = m_bitmap.width();
|
||||||
|
|
||||||
|
auto format = m_bitmap.format();
|
||||||
|
VERIFY(format == BitmapFormat::BGRA8888 || format == BitmapFormat::BGRx8888);
|
||||||
|
|
||||||
|
for (int y = 0; y < height; ++y) {
|
||||||
|
for (int x = 0; x < width; ++x) {
|
||||||
|
Color color;
|
||||||
|
color = m_bitmap.get_pixel(x, y);
|
||||||
|
|
||||||
|
auto luma = color.luminosity();
|
||||||
|
if (lower_bound > luma || upper_bound < luma)
|
||||||
|
m_bitmap.set_pixel(x, y, { 0, 0, 0, color.alpha() });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
Userland/Libraries/LibGfx/Filters/LumaFilter.h
Normal file
24
Userland/Libraries/LibGfx/Filters/LumaFilter.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibGfx/Bitmap.h>
|
||||||
|
|
||||||
|
namespace Gfx {
|
||||||
|
|
||||||
|
class LumaFilter {
|
||||||
|
public:
|
||||||
|
LumaFilter(Bitmap& bitmap)
|
||||||
|
: m_bitmap(bitmap) {};
|
||||||
|
|
||||||
|
void apply(u8 lower_bound, u8 upper_bound);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Bitmap& m_bitmap;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue