mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:17:35 +00:00
LibGfx: Use premultiplied alpha when scaling images
This commit replaces usages of `Color::interpolate()` with `Color::mixed_with()` in image scaling functions. The latter uses premultiplied alpha, which results in more visually pleasing edges when images are scaled against a transparent background. These changes affect the SmoothPixels and BilinearBlend scaling modes of `Painter::draw_scaled_bitmap()` as well as the `Bitmap::scaled()` function. Fixes #17153.
This commit is contained in:
parent
2480b94ae7
commit
5a6b995444
2 changed files with 11 additions and 11 deletions
|
@ -403,9 +403,9 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const
|
||||||
auto c = get_pixel(i, j + 1);
|
auto c = get_pixel(i, j + 1);
|
||||||
auto d = get_pixel(i + 1, j + 1);
|
auto d = get_pixel(i + 1, j + 1);
|
||||||
|
|
||||||
auto e = a.interpolate(b, u);
|
auto e = a.mixed_with(b, u);
|
||||||
auto f = c.interpolate(d, u);
|
auto f = c.mixed_with(d, u);
|
||||||
auto color = e.interpolate(f, v);
|
auto color = e.mixed_with(f, v);
|
||||||
new_bitmap->set_pixel(x, y, color);
|
new_bitmap->set_pixel(x, y, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -421,7 +421,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const
|
||||||
|
|
||||||
auto a = get_pixel(i, old_bottom_y);
|
auto a = get_pixel(i, old_bottom_y);
|
||||||
auto b = get_pixel(i + 1, old_bottom_y);
|
auto b = get_pixel(i + 1, old_bottom_y);
|
||||||
auto color = a.interpolate(b, u);
|
auto color = a.mixed_with(b, u);
|
||||||
new_bitmap->set_pixel(x, new_bottom_y, color);
|
new_bitmap->set_pixel(x, new_bottom_y, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,7 +437,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const
|
||||||
auto c = get_pixel(old_right_x, j);
|
auto c = get_pixel(old_right_x, j);
|
||||||
auto d = get_pixel(old_right_x, j + 1);
|
auto d = get_pixel(old_right_x, j + 1);
|
||||||
|
|
||||||
auto color = c.interpolate(d, v);
|
auto color = c.mixed_with(d, v);
|
||||||
new_bitmap->set_pixel(new_right_x, y, color);
|
new_bitmap->set_pixel(new_right_x, y, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1230,10 +1230,10 @@ ALWAYS_INLINE static void do_draw_scaled_bitmap(Gfx::Bitmap& target, IntRect con
|
||||||
auto bottom_left = get_pixel(source, scaled_x0, scaled_y1);
|
auto bottom_left = get_pixel(source, scaled_x0, scaled_y1);
|
||||||
auto bottom_right = get_pixel(source, scaled_x1, scaled_y1);
|
auto bottom_right = get_pixel(source, scaled_x1, scaled_y1);
|
||||||
|
|
||||||
auto top = top_left.interpolate(top_right, x_ratio);
|
auto top = top_left.mixed_with(top_right, x_ratio);
|
||||||
auto bottom = bottom_left.interpolate(bottom_right, x_ratio);
|
auto bottom = bottom_left.mixed_with(bottom_right, x_ratio);
|
||||||
|
|
||||||
src_pixel = top.interpolate(bottom, y_ratio);
|
src_pixel = top.mixed_with(bottom, y_ratio);
|
||||||
} else if constexpr (scaling_mode == Painter::ScalingMode::SmoothPixels) {
|
} else if constexpr (scaling_mode == Painter::ScalingMode::SmoothPixels) {
|
||||||
auto scaled_x1 = clamp(desired_x >> 32, clipped_src_rect.left(), clipped_src_rect.right());
|
auto scaled_x1 = clamp(desired_x >> 32, clipped_src_rect.left(), clipped_src_rect.right());
|
||||||
auto scaled_x0 = clamp(scaled_x1 - 1, clipped_src_rect.left(), clipped_src_rect.right());
|
auto scaled_x0 = clamp(scaled_x1 - 1, clipped_src_rect.left(), clipped_src_rect.right());
|
||||||
|
@ -1251,10 +1251,10 @@ ALWAYS_INLINE static void do_draw_scaled_bitmap(Gfx::Bitmap& target, IntRect con
|
||||||
auto bottom_left = get_pixel(source, scaled_x0, scaled_y1);
|
auto bottom_left = get_pixel(source, scaled_x0, scaled_y1);
|
||||||
auto bottom_right = get_pixel(source, scaled_x1, scaled_y1);
|
auto bottom_right = get_pixel(source, scaled_x1, scaled_y1);
|
||||||
|
|
||||||
auto top = top_left.interpolate(top_right, scaled_x_ratio);
|
auto top = top_left.mixed_with(top_right, scaled_x_ratio);
|
||||||
auto bottom = bottom_left.interpolate(bottom_right, scaled_x_ratio);
|
auto bottom = bottom_left.mixed_with(bottom_right, scaled_x_ratio);
|
||||||
|
|
||||||
src_pixel = top.interpolate(bottom, scaled_y_ratio);
|
src_pixel = top.mixed_with(bottom, scaled_y_ratio);
|
||||||
} else {
|
} else {
|
||||||
auto scaled_x = clamp(desired_x >> 32, clipped_src_rect.left(), clipped_src_rect.right());
|
auto scaled_x = clamp(desired_x >> 32, clipped_src_rect.left(), clipped_src_rect.right());
|
||||||
auto scaled_y = clamp(desired_y >> 32, clipped_src_rect.top(), clipped_src_rect.bottom());
|
auto scaled_y = clamp(desired_y >> 32, clipped_src_rect.top(), clipped_src_rect.bottom());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue