diff options
author | Noel <noel.grandin@collabora.co.uk> | 2021-01-08 12:57:54 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-01-08 17:20:23 +0100 |
commit | 9cc41b9ad52e3da734ce72223946bd00bfc92d14 (patch) | |
tree | afb7874bb7be5bbb22dfd0f637fe1a362e9c0430 /drawinglayer | |
parent | e12e4dc835fcdd42b0966fd9dd02921654492ad8 (diff) |
opacity->alpha in BPixel
They are basically the same thing, but alpha is the preferred term
these days.
Also improve the mixing algorithm,
1 - opacity
is
255 - opacity
not
256 - opacity
since the range of sal_uInt8 is 0..255
Change-Id: I8788ac79285ab25c8d322b05817dffd3745fd699
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108963
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'drawinglayer')
-rw-r--r-- | drawinglayer/source/primitive2d/sceneprimitive2d.cxx | 20 | ||||
-rw-r--r-- | drawinglayer/source/processor3d/zbufferprocessor3d.cxx | 8 |
2 files changed, 14 insertions, 14 deletions
diff --git a/drawinglayer/source/primitive2d/sceneprimitive2d.cxx b/drawinglayer/source/primitive2d/sceneprimitive2d.cxx index e58c05e406af..fa35085e0f1f 100644 --- a/drawinglayer/source/primitive2d/sceneprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/sceneprimitive2d.cxx @@ -61,7 +61,7 @@ namespace sal_uInt16 nRed(0); sal_uInt16 nGreen(0); sal_uInt16 nBlue(0); - sal_uInt16 nOpacity(0); + sal_uInt16 nAlpha(0); sal_uInt32 nIndex(rRaster.getIndexFromXY(x * mnAntiAlialize, y * mnAntiAlialize)); for(sal_uInt32 c(0); c < mnAntiAlialize; c++) @@ -69,21 +69,21 @@ namespace for(sal_uInt32 d(0); d < mnAntiAlialize; d++) { const basegfx::BPixel& rPixel(rRaster.getBPixel(nIndex++)); - nRed = nRed + rPixel.getRed(); - nGreen = nGreen + rPixel.getGreen(); - nBlue = nBlue + rPixel.getBlue(); - nOpacity = nOpacity + rPixel.getOpacity(); + nRed += rPixel.getRed(); + nGreen += rPixel.getGreen(); + nBlue += rPixel.getBlue(); + nAlpha += rPixel.getAlpha(); } nIndex += rRaster.getWidth() - mnAntiAlialize; } - nOpacity = nOpacity / nDivisor; + nAlpha /= nDivisor; - if(nOpacity) + if(nAlpha) { aContent.SetPixel(y, x, Color( - 255 - static_cast<sal_uInt8>(nOpacity), + 255 - static_cast<sal_uInt8>(nAlpha), static_cast<sal_uInt8>(nRed / nDivisor), static_cast<sal_uInt8>(nGreen / nDivisor), static_cast<sal_uInt8>(nBlue / nDivisor) )); @@ -103,9 +103,9 @@ namespace { const basegfx::BPixel& rPixel(rRaster.getBPixel(nIndex++)); - if(rPixel.getOpacity()) + if(rPixel.getAlpha()) { - aContent.SetPixel(y, x, Color(255 - rPixel.getOpacity(), rPixel.getRed(), rPixel.getGreen(), rPixel.getBlue())); + aContent.SetPixel(y, x, Color(255 - rPixel.getAlpha(), rPixel.getRed(), rPixel.getGreen(), rPixel.getBlue())); } else aContent.SetPixel(y, x, Color(255, 0, 0, 0)); diff --git a/drawinglayer/source/processor3d/zbufferprocessor3d.cxx b/drawinglayer/source/processor3d/zbufferprocessor3d.cxx index a4f0deb33fc4..73587089b192 100644 --- a/drawinglayer/source/processor3d/zbufferprocessor3d.cxx +++ b/drawinglayer/source/processor3d/zbufferprocessor3d.cxx @@ -322,20 +322,20 @@ void ZBufferRasterConverter3D::processLineSpan(const basegfx::RasterConversionLi { basegfx::BPixel& rDest = mrBuffer.getBPixel(nScanlineIndex); - if(rDest.getOpacity()) + if(rDest.getAlpha()) { // mix new color by using // color' = color * (1 - opacity) + newcolor * opacity - const sal_uInt16 nTransparence(0x0100 - nOpacity); + const sal_uInt16 nTransparence(255 - nOpacity); rDest.setRed(static_cast<sal_uInt8>(((rDest.getRed() * nTransparence) + (static_cast<sal_uInt16>(255.0 * aNewColor.getRed()) * nOpacity)) >> 8)); rDest.setGreen(static_cast<sal_uInt8>(((rDest.getGreen() * nTransparence) + (static_cast<sal_uInt16>(255.0 * aNewColor.getGreen()) * nOpacity)) >> 8)); rDest.setBlue(static_cast<sal_uInt8>(((rDest.getBlue() * nTransparence) + (static_cast<sal_uInt16>(255.0 * aNewColor.getBlue()) * nOpacity)) >> 8)); - if(0xff != rDest.getOpacity()) + if(255 != rDest.getAlpha()) { // both are transparent, mix new opacity by using // opacity = newopacity * (1 - oldopacity) + oldopacity - rDest.setOpacity(static_cast<sal_uInt8>((nOpacity * (0x0100 - rDest.getOpacity())) >> 8) + rDest.getOpacity()); + rDest.setAlpha(static_cast<sal_uInt8>((nOpacity * (255 - rDest.getAlpha())) >> 8) + rDest.getAlpha()); } } else |