mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 19:19:44 +03:00
LibGfx: Handle signed distance field edges better
Small change to treat pixels outside the signed distance field bitmap as outside the shape.
This commit is contained in:
parent
fcaa535dec
commit
98040c508f
Notes:
sideshowbarker
2024-07-17 16:23:06 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/98040c508f Pull-request: https://github.com/SerenityOS/serenity/pull/18022 Reviewed-by: https://github.com/linusg ✅
@ -2583,6 +2583,13 @@ void Painter::draw_signed_distance_field(IntRect const& dst_rect, Color color, G
|
||||
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 };
|
||||
@ -2592,12 +2599,10 @@ void Painter::draw_signed_distance_field(IntRect const& dst_rect, Color color, G
|
||||
auto target_fraction_x = (x_ratio * sample_point.x()) - target_x;
|
||||
auto target_fraction_y = (y_ratio * sample_point.y()) - target_y;
|
||||
|
||||
auto x2 = min(target_x + 1, sdf.width() - 1);
|
||||
auto y2 = min(target_y + 1, sdf.height() - 1);
|
||||
auto a = sdf.pixel_at(target_x, target_y);
|
||||
auto b = sdf.pixel_at(x2, target_y);
|
||||
auto c = sdf.pixel_at(target_x, y2);
|
||||
auto d = sdf.pixel_at(x2, y2);
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user