1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:07:35 +00:00

LibGfx+PixelPaint: Fix distortions in convolutions with size != 4 or 5

This commit is contained in:
AnotherTest 2020-10-04 22:56:20 +03:30 committed by Andreas Kling
parent 95434d70ed
commit 93f4388e45
3 changed files with 32 additions and 12 deletions

View file

@ -73,6 +73,7 @@ public:
class ApplyCache {
template<size_t>
friend class GenericConvolutionFilter;
private:
RefPtr<Gfx::Bitmap> m_target;
};
@ -120,23 +121,24 @@ public:
Bitmap* render_target_bitmap = (&target != &source) ? &target : apply_cache.m_target.ptr();
// FIXME: Help! I am naive!
constexpr static ssize_t offset = N / 2;
for (auto i_ = 0; i_ < target_rect.width(); ++i_) {
auto i = i_ + target_rect.x();
ssize_t i = i_ + target_rect.x();
for (auto j_ = 0; j_ < target_rect.height(); ++j_) {
auto j = j_ + target_rect.y();
ssize_t j = j_ + target_rect.y();
FloatVector3 value(0, 0, 0);
for (auto k = 0; k < 4; ++k) {
auto ki = i + k - 2;
if (i < source_rect.x() || i > source_rect.right()) {
for (auto k = 0l; k < (ssize_t)N; ++k) {
auto ki = i + k - offset;
if (ki < source_rect.x() || ki > source_rect.right()) {
if (parameters.should_wrap())
ki = (ki + source.size().width()) % source.size().width(); // TODO: fix up using source_rect
else
continue;
}
for (auto l = 0; l < 4; ++l) {
auto lj = j + l - 2;
if (j < source_rect.y() || j > source_rect.bottom()) {
for (auto l = 0l; l < (ssize_t)N; ++l) {
auto lj = j + l - offset;
if (lj < source_rect.y() || lj > source_rect.bottom()) {
if (parameters.should_wrap())
lj = (lj + source.size().height()) % source.size().height(); // TODO: fix up using source_rect
else
@ -150,7 +152,7 @@ public:
}
}
// The float->u8 overflow is intentional.
value.clamp(0, 255);
render_target_bitmap->set_pixel(i, j, Color(value.x(), value.y(), value.z(), source.get_pixel(i + source_delta_x, j + source_delta_y).alpha()));
}
}