|
@@ -344,6 +344,25 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::flipped(Gfx::Orientation orientation
|
|
return new_bitmap;
|
|
return new_bitmap;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void Bitmap::apply_mask(Gfx::Bitmap const& mask, MaskKind mask_kind)
|
|
|
|
+{
|
|
|
|
+ VERIFY(size() == mask.size());
|
|
|
|
+
|
|
|
|
+ for (int y = 0; y < height(); y++) {
|
|
|
|
+ for (int x = 0; x < width(); x++) {
|
|
|
|
+ auto color = get_pixel(x, y);
|
|
|
|
+ auto mask_color = mask.get_pixel(x, y);
|
|
|
|
+ if (mask_kind == MaskKind::Luminance) {
|
|
|
|
+ color = color.with_alpha(color.alpha() * mask_color.alpha() * mask_color.luminosity() / (255 * 255));
|
|
|
|
+ } else {
|
|
|
|
+ VERIFY(mask_kind == MaskKind::Alpha);
|
|
|
|
+ color = color.with_alpha(color.alpha() * mask_color.alpha() / 255);
|
|
|
|
+ }
|
|
|
|
+ set_pixel(x, y, color);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(int sx, int sy) const
|
|
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(int sx, int sy) const
|
|
{
|
|
{
|
|
VERIFY(sx >= 0 && sy >= 0);
|
|
VERIFY(sx >= 0 && sy >= 0);
|