summaryrefslogtreecommitdiff
path: root/drawinglayer/source/tools
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2021-04-16 20:33:10 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-07-25 08:38:12 +0200
commit81994cb2b8b32453a92bcb011830fcb884f22ff3 (patch)
treeae1750e92421ad2e0ec3f50351c3be6581841598 /drawinglayer/source/tools
parentdabedcaf27b0af1e38a611b8d8e48444f848e01d (diff)
Convert internal vcl bitmap formats transparency->alpha (II)
(Second attempt at landing this) Image formats and graphics APIs use alpha, not transparency, so change our internal formats and data structures to work directly with alpha, so we don't need to modify data before we push it to graphics APIs. Add a couple of new Color constants to make the intention of the vcl code clearer. Notes (*) On macOS, tweaking the logic in CreateWithSalBitmapAndMask to more accurately reflect the requirements of the CGImageCreateWithMask function seems to fix some tests. (*) The vcl code does not properly support gradients with transparency. So the previous code was wrong, and this change is going to result in slightly different wrongness. Change-Id: I9e21c2e98d88ecfdc5f75db13bd1ffff7c38db98 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114168 Tested-by: Jenkins Reviewed-by: Patrick Luby <plubius@neooffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'drawinglayer/source/tools')
-rw-r--r--drawinglayer/source/tools/converters.cxx27
1 files changed, 19 insertions, 8 deletions
diff --git a/drawinglayer/source/tools/converters.cxx b/drawinglayer/source/tools/converters.cxx
index 001019cd9623..80ae15a3b6a9 100644
--- a/drawinglayer/source/tools/converters.cxx
+++ b/drawinglayer/source/tools/converters.cxx
@@ -95,7 +95,7 @@ AlphaMask implcreateAlphaMask(drawinglayer::primitive2d::Primitive2DContainer& r
// prepare for mask creation
pContent->SetMapMode(MapMode(MapUnit::MapPixel));
- // set alpha to all white (fully transparent)
+ // set transparency to all white (fully transparent)
pContent->Erase();
basegfx::BColorModifierSharedPtr aBColorModifier;
@@ -107,7 +107,7 @@ AlphaMask implcreateAlphaMask(drawinglayer::primitive2d::Primitive2DContainer& r
}
else
{
- // Embed primitives to paint them black
+ // Embed primitives to paint them black (fully opaque)
aBColorModifier
= std::make_shared<basegfx::BColorModifier_replace>(basegfx::BColor(0.0, 0.0, 0.0));
}
@@ -123,7 +123,14 @@ AlphaMask implcreateAlphaMask(drawinglayer::primitive2d::Primitive2DContainer& r
// get alpha channel from vdev
pContent->EnableMapMode(false);
const Point aEmptyPoint;
- return AlphaMask(pContent->GetBitmap(aEmptyPoint, rSizePixel));
+
+ // Convert from transparency->alpha.
+ // FIXME in theory I should be able to directly construct alpha by using black as background
+ // and white as foreground, but that doesn't work for some reason.
+ Bitmap aContentBitmap = pContent->GetBitmap(aEmptyPoint, rSizePixel);
+ aContentBitmap.Invert();
+
+ return AlphaMask(aContentBitmap);
}
}
@@ -257,12 +264,16 @@ BitmapEx convertToBitmapEx(drawinglayer::primitive2d::Primitive2DContainer&& rSe
if (aAlpha.hasAlpha())
{
// Need to correct content using known alpha to get to background-free
- // RGBA result, usable e.g. in PNG export(s) or convert-to-bitmap
- aRetval.RemoveBlendedStartColor(COL_WHITE, aAlpha);
+ // RGBA result, usable e.g. in PNG export(s) or convert-to-bitmap.
+ // Now that vcl supports bitmaps with an alpha channel, only apply
+ // this correction to bitmaps without an alpha channel.
+ if (pContent->GetBitCount() < 32)
+ aRetval.RemoveBlendedStartColor(COL_WHITE, aAlpha);
+ // return combined result
+ return BitmapEx(aRetval, aAlpha);
}
-
- // return combined result
- return BitmapEx(aRetval, aAlpha);
+ else
+ return BitmapEx(aRetval);
}
BitmapEx convertPrimitive2DContainerToBitmapEx(primitive2d::Primitive2DContainer&& rSequence,