LibGfx: Remove draw_signed_distance_field() in Gfx::Painter

No longer used since we switched to vector paths for checkbox rendering.
This commit is contained in:
Aliaksandr Kalenik 2024-06-13 17:41:12 +03:00 committed by Andreas Kling
parent 9502926b76
commit 57c735dec4
Notes: sideshowbarker 2024-07-17 01:53:23 +09:00
2 changed files with 0 additions and 49 deletions

View File

@ -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<float>(sdf.width() - 1) / (dst_rect.width() - 1);
auto y_ratio = static_cast<float>(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<int>(x_ratio * sample_point.x());
auto target_y = static_cast<int>(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);
}
}
}
}

View File

@ -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,