LibGfx: Report premultiplied alpha type for opaque Skia surfaces
We don't discern between opaque and non-opaque alpha types in LibGfx, which at some point we might need to do. But for now, assume all opaque Skia surfaces have premultiplied alpha. Fixes #6892.
This commit is contained in:
parent
6790a695da
commit
3b7eede694
4 changed files with 17 additions and 3 deletions
|
|
@ -41,9 +41,11 @@ IntSize ImmutableBitmap::size() const
|
|||
return { width(), height() };
|
||||
}
|
||||
|
||||
Gfx::AlphaType ImmutableBitmap::alpha_type() const
|
||||
AlphaType ImmutableBitmap::alpha_type() const
|
||||
{
|
||||
return m_impl->sk_image->alphaType() == kPremul_SkAlphaType ? Gfx::AlphaType::Premultiplied : Gfx::AlphaType::Unpremultiplied;
|
||||
// We assume premultiplied alpha type for opaque surfaces since that is Skia's preferred alpha type and the
|
||||
// effective pixel data is identical between premultiplied and unpremultiplied in that case.
|
||||
return m_impl->sk_image->alphaType() == kUnpremul_SkAlphaType ? AlphaType::Unpremultiplied : AlphaType::Premultiplied;
|
||||
}
|
||||
|
||||
SkImage const* ImmutableBitmap::sk_image() const
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public:
|
|||
IntRect rect() const;
|
||||
IntSize size() const;
|
||||
|
||||
Gfx::AlphaType alpha_type() const;
|
||||
AlphaType alpha_type() const;
|
||||
|
||||
SkImage const* sk_image() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
50, 75, 100, 255
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const ctx = document.createElement("canvas").getContext("2d", {alpha: false});
|
||||
ctx.fillStyle = "rgba(100, 150, 200, 0.5)";
|
||||
ctx.fillRect(0, 0, 300, 150);
|
||||
const color = ctx.getImageData(0, 0, 300, 150);
|
||||
println(`${color.data[0]}, ${color.data[1]}, ${color.data[2]}, ${color.data[3]}`);
|
||||
});
|
||||
</script>
|
||||
Loading…
Reference in a new issue