diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 7b6dbbe16d9..d12962cebf1 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -1637,52 +1637,4 @@ void Painter::draw_scaled_bitmap_with_transform(IntRect const& dst_rect, Bitmap } } -void Painter::draw_signed_distance_field(IntRect const& dst_rect, Color color, Gfx::GrayscaleBitmap const& sdf, float smoothing) -{ - auto target_rect = dst_rect.translated(translation()); - auto clipped_rect = target_rect.intersected(clip_rect()); - if (clipped_rect.is_empty()) - return; - auto start_offset = clipped_rect.location() - target_rect.location(); - auto x_ratio = static_cast(sdf.width() - 1) / (dst_rect.width() - 1); - auto y_ratio = static_cast(sdf.height() - 1) / (dst_rect.height() - 1); - - auto smooth_step = [](auto edge0, auto edge1, auto x) { - x = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f); - return x * x * (3 - 2 * x); - }; - - auto pixel_at = [&](unsigned x, unsigned y) -> u8 { - // Returning 255 means this pixel is outside the shape. - if (x >= sdf.width() || y >= sdf.height()) - return 255; - return sdf.pixel_at(x, y); - }; - - for (int i = 0; i < clipped_rect.height(); ++i) { - for (int j = 0; j < clipped_rect.width(); ++j) { - auto point = IntPoint { j, i }; - auto sample_point = point + start_offset; - auto target_x = static_cast(x_ratio * sample_point.x()); - auto target_y = static_cast(y_ratio * sample_point.y()); - auto target_fraction_x = (x_ratio * sample_point.x()) - target_x; - auto target_fraction_y = (y_ratio * sample_point.y()) - target_y; - - auto a = pixel_at(target_x, target_y); - auto b = pixel_at(target_x + 1, target_y); - auto c = pixel_at(target_x, target_y + 1); - auto d = pixel_at(target_x + 1, target_y + 1); - - float distance = (a * (1 - target_fraction_x) * (1 - target_fraction_y) - + b * target_fraction_x * (1 - target_fraction_y) - + c * (1 - target_fraction_x) * target_fraction_y - + d * target_fraction_x * target_fraction_y) - / 255.0f; - - u8 alpha = (1 - clamp(smooth_step(0.5f - smoothing, 0.5f + smoothing, distance), 0.0f, 1.0f)) * 255; - set_physical_pixel(point + clipped_rect.location(), color.with_alpha(alpha), true); - } - } -} - } diff --git a/Userland/Libraries/LibGfx/Painter.h b/Userland/Libraries/LibGfx/Painter.h index 343be56e962..0325b9dbda7 100644 --- a/Userland/Libraries/LibGfx/Painter.h +++ b/Userland/Libraries/LibGfx/Painter.h @@ -76,7 +76,6 @@ public: void draw_emoji(IntPoint, Gfx::Bitmap const&, Font const&); void draw_glyph(FloatPoint, u32, Font const&, Color); void draw_glyph_or_emoji(FloatPoint, Utf8CodePointIterator&, Font const&, Color); - void draw_signed_distance_field(IntRect const& dst_rect, Color, Gfx::GrayscaleBitmap const&, float smoothing); enum class CornerOrientation { TopLeft,