diff --git a/Tests/LibWeb/Screenshot/canvas-unpremultiplied-image.html b/Tests/LibWeb/Screenshot/canvas-unpremultiplied-image.html
new file mode 100644
index 00000000000..ee63456d5c4
--- /dev/null
+++ b/Tests/LibWeb/Screenshot/canvas-unpremultiplied-image.html
@@ -0,0 +1,12 @@
+
+
+
diff --git a/Tests/LibWeb/Screenshot/images/canvas-arcs-and-ellipses-ref.png b/Tests/LibWeb/Screenshot/images/canvas-arcs-and-ellipses-ref.png
index 293384e6532..10bac372ebd 100644
Binary files a/Tests/LibWeb/Screenshot/images/canvas-arcs-and-ellipses-ref.png and b/Tests/LibWeb/Screenshot/images/canvas-arcs-and-ellipses-ref.png differ
diff --git a/Tests/LibWeb/Screenshot/images/canvas-implict-moves-and-lines-ref.png b/Tests/LibWeb/Screenshot/images/canvas-implict-moves-and-lines-ref.png
index ad2dc45ed72..435ff2c05d5 100644
Binary files a/Tests/LibWeb/Screenshot/images/canvas-implict-moves-and-lines-ref.png and b/Tests/LibWeb/Screenshot/images/canvas-implict-moves-and-lines-ref.png differ
diff --git a/Tests/LibWeb/Screenshot/images/canvas-path-rect-ref.png b/Tests/LibWeb/Screenshot/images/canvas-path-rect-ref.png
index e69d6daa079..bd857a603de 100644
Binary files a/Tests/LibWeb/Screenshot/images/canvas-path-rect-ref.png and b/Tests/LibWeb/Screenshot/images/canvas-path-rect-ref.png differ
diff --git a/Tests/LibWeb/Screenshot/images/canvas-text-ref.png b/Tests/LibWeb/Screenshot/images/canvas-text-ref.png
index d27f87c25b7..420b4467b65 100644
Binary files a/Tests/LibWeb/Screenshot/images/canvas-text-ref.png and b/Tests/LibWeb/Screenshot/images/canvas-text-ref.png differ
diff --git a/Tests/LibWeb/Screenshot/images/canvas-unpremultiplied-image-ref.png b/Tests/LibWeb/Screenshot/images/canvas-unpremultiplied-image-ref.png
new file mode 100644
index 00000000000..a8624cba97d
Binary files /dev/null and b/Tests/LibWeb/Screenshot/images/canvas-unpremultiplied-image-ref.png differ
diff --git a/Tests/LibWeb/Screenshot/reference/canvas-unpremultiplied-image-ref.html b/Tests/LibWeb/Screenshot/reference/canvas-unpremultiplied-image-ref.html
new file mode 100644
index 00000000000..a362c53237b
--- /dev/null
+++ b/Tests/LibWeb/Screenshot/reference/canvas-unpremultiplied-image-ref.html
@@ -0,0 +1,9 @@
+
+
diff --git a/Userland/Libraries/LibGfx/PainterSkia.cpp b/Userland/Libraries/LibGfx/PainterSkia.cpp
index 2dd2723da2b..03f10765ae3 100644
--- a/Userland/Libraries/LibGfx/PainterSkia.cpp
+++ b/Userland/Libraries/LibGfx/PainterSkia.cpp
@@ -28,6 +28,33 @@
namespace Gfx {
+static SkColorType to_skia_color_type(Gfx::BitmapFormat format)
+{
+ switch (format) {
+ case Gfx::BitmapFormat::Invalid:
+ return kUnknown_SkColorType;
+ case Gfx::BitmapFormat::BGRA8888:
+ case Gfx::BitmapFormat::BGRx8888:
+ return kBGRA_8888_SkColorType;
+ case Gfx::BitmapFormat::RGBA8888:
+ return kRGBA_8888_SkColorType;
+ default:
+ return kUnknown_SkColorType;
+ }
+}
+
+static SkAlphaType to_skia_alpha_type(Gfx::AlphaType alpha_type)
+{
+ switch (alpha_type) {
+ case AlphaType::Premultiplied:
+ return kPremul_SkAlphaType;
+ case AlphaType::Unpremultiplied:
+ return kUnpremul_SkAlphaType;
+ default:
+ VERIFY_NOT_REACHED();
+ }
+}
+
struct PainterSkia::Impl {
NonnullRefPtr gfx_bitmap;
OwnPtr sk_bitmap;
@@ -37,7 +64,7 @@ struct PainterSkia::Impl {
: gfx_bitmap(move(target_bitmap))
{
sk_bitmap = make();
- SkImageInfo info = SkImageInfo::Make(gfx_bitmap->width(), gfx_bitmap->height(), kBGRA_8888_SkColorType, kUnpremul_SkAlphaType);
+ SkImageInfo info = SkImageInfo::Make(gfx_bitmap->width(), gfx_bitmap->height(), to_skia_color_type(gfx_bitmap->format()), to_skia_alpha_type(gfx_bitmap->alpha_type()));
sk_bitmap->installPixels(info, gfx_bitmap->scanline(0), gfx_bitmap->pitch());
sk_canvas = make(*sk_bitmap);
@@ -109,25 +136,10 @@ static SkSamplingOptions to_skia_sampling_options(Gfx::ScalingMode scaling_mode)
}
}
-static SkColorType to_skia_color_type(Gfx::BitmapFormat format)
-{
- switch (format) {
- case Gfx::BitmapFormat::Invalid:
- return kUnknown_SkColorType;
- case Gfx::BitmapFormat::BGRA8888:
- case Gfx::BitmapFormat::BGRx8888:
- return kBGRA_8888_SkColorType;
- case Gfx::BitmapFormat::RGBA8888:
- return kRGBA_8888_SkColorType;
- default:
- return kUnknown_SkColorType;
- }
-}
-
void PainterSkia::draw_bitmap(Gfx::FloatRect const& dst_rect, Gfx::Bitmap const& src_bitmap, Gfx::IntRect const& src_rect, Gfx::ScalingMode scaling_mode, float global_alpha)
{
SkBitmap sk_bitmap;
- SkImageInfo info = SkImageInfo::Make(src_bitmap.width(), src_bitmap.height(), to_skia_color_type(src_bitmap.format()), kUnpremul_SkAlphaType);
+ SkImageInfo info = SkImageInfo::Make(src_bitmap.width(), src_bitmap.height(), to_skia_color_type(src_bitmap.format()), to_skia_alpha_type(src_bitmap.alpha_type()));
sk_bitmap.installPixels(info, const_cast(static_cast(src_bitmap.scanline(0))), src_bitmap.pitch());
SkPaint paint;