[Libreoffice-commits] core.git: drawinglayer/source include/basegfx

Noel (via logerrit) logerrit at kemper.freedesktop.org
Fri Jan 8 16:21:00 UTC 2021


 drawinglayer/source/primitive2d/sceneprimitive2d.cxx   |   20 +++----
 drawinglayer/source/processor3d/zbufferprocessor3d.cxx |    8 +-
 include/basegfx/pixel/bpixel.hxx                       |   48 ++++++++---------
 3 files changed, 38 insertions(+), 38 deletions(-)

New commits:
commit 9cc41b9ad52e3da734ce72223946bd00bfc92d14
Author:     Noel <noel.grandin at collabora.co.uk>
AuthorDate: Fri Jan 8 12:57:54 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Jan 8 17:20:23 2021 +0100

    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 at collabora.co.uk>

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
diff --git a/include/basegfx/pixel/bpixel.hxx b/include/basegfx/pixel/bpixel.hxx
index ee42f29c6318..50209ec2ce47 100644
--- a/include/basegfx/pixel/bpixel.hxx
+++ b/include/basegfx/pixel/bpixel.hxx
@@ -33,62 +33,62 @@ namespace basegfx
                 unsigned                                mnR : 8;        // red intensity
                 unsigned                                mnG : 8;        // green intensity
                 unsigned                                mnB : 8;        // blue intensity
-                unsigned                                mnO : 8;        // opacity, 0 == full transparence
-            } maRGBO;
+                unsigned                                mnA : 8;        // opacity, 0 == full transparence
+            } maRGBA;
 
             struct
             {
                 unsigned                                mnValue : 32;   // all values
-            } maCombinedRGBO;
+            } maCombinedRGBA;
         } maPixelUnion;
 
     public:
         BPixel()
         {
-            maPixelUnion.maCombinedRGBO.mnValue = 0;
+            maPixelUnion.maCombinedRGBA.mnValue = 0;
         }
 
         // use explicit here to make sure everyone knows what he is doing. Values range from
         // 0..255 integer here.
-        explicit BPixel(sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue, sal_uInt8 nOpacity)
+        explicit BPixel(sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue, sal_uInt8 nAlpha)
         {
-            maPixelUnion.maRGBO.mnR = nRed;
-            maPixelUnion.maRGBO.mnG = nGreen;
-            maPixelUnion.maRGBO.mnB = nBlue;
-            maPixelUnion.maRGBO.mnO = nOpacity;
+            maPixelUnion.maRGBA.mnR = nRed;
+            maPixelUnion.maRGBA.mnG = nGreen;
+            maPixelUnion.maRGBA.mnB = nBlue;
+            maPixelUnion.maRGBA.mnA = nAlpha;
         }
 
         // constructor from BColor which uses double precision color, so change it
         // to local integer format. It will also be clamped here.
-        BPixel(const BColor& rColor, sal_uInt8 nOpacity)
+        BPixel(const BColor& rColor, sal_uInt8 nAlpha)
         {
-            maPixelUnion.maRGBO.mnR = sal_uInt8((rColor.getRed() * 255.0) + 0.5);
-            maPixelUnion.maRGBO.mnG = sal_uInt8((rColor.getGreen() * 255.0) + 0.5);
-            maPixelUnion.maRGBO.mnB = sal_uInt8((rColor.getBlue() * 255.0) + 0.5);
-            maPixelUnion.maRGBO.mnO = nOpacity;
+            maPixelUnion.maRGBA.mnR = sal_uInt8((rColor.getRed() * 255.0) + 0.5);
+            maPixelUnion.maRGBA.mnG = sal_uInt8((rColor.getGreen() * 255.0) + 0.5);
+            maPixelUnion.maRGBA.mnB = sal_uInt8((rColor.getBlue() * 255.0) + 0.5);
+            maPixelUnion.maRGBA.mnA = nAlpha;
         }
 
         // data access read
-        sal_uInt8 getRed() const { return maPixelUnion.maRGBO.mnR; }
-        sal_uInt8 getGreen() const { return maPixelUnion.maRGBO.mnG; }
-        sal_uInt8 getBlue() const { return maPixelUnion.maRGBO.mnB; }
-        sal_uInt8 getOpacity() const { return maPixelUnion.maRGBO.mnO; }
+        sal_uInt8 getRed() const { return maPixelUnion.maRGBA.mnR; }
+        sal_uInt8 getGreen() const { return maPixelUnion.maRGBA.mnG; }
+        sal_uInt8 getBlue() const { return maPixelUnion.maRGBA.mnB; }
+        sal_uInt8 getAlpha() const { return maPixelUnion.maRGBA.mnA; }
 
         // data access write
-        void setRed(sal_uInt8 nNew) { maPixelUnion.maRGBO.mnR = nNew; }
-        void setGreen(sal_uInt8 nNew) { maPixelUnion.maRGBO.mnG = nNew; }
-        void setBlue(sal_uInt8 nNew) { maPixelUnion.maRGBO.mnB = nNew; }
-        void setOpacity(sal_uInt8 nNew) { maPixelUnion.maRGBO.mnO = nNew; }
+        void setRed(sal_uInt8 nNew) { maPixelUnion.maRGBA.mnR = nNew; }
+        void setGreen(sal_uInt8 nNew) { maPixelUnion.maRGBA.mnG = nNew; }
+        void setBlue(sal_uInt8 nNew) { maPixelUnion.maRGBA.mnB = nNew; }
+        void setAlpha(sal_uInt8 nNew) { maPixelUnion.maRGBA.mnA = nNew; }
 
         // comparators
         bool operator==( const BPixel& rPixel ) const
         {
-            return (rPixel.maPixelUnion.maCombinedRGBO.mnValue == maPixelUnion.maCombinedRGBO.mnValue);
+            return (rPixel.maPixelUnion.maCombinedRGBA.mnValue == maPixelUnion.maCombinedRGBA.mnValue);
         }
 
         bool operator!=( const BPixel& rPixel ) const
         {
-            return (rPixel.maPixelUnion.maCombinedRGBO.mnValue != maPixelUnion.maCombinedRGBO.mnValue);
+            return (rPixel.maPixelUnion.maCombinedRGBA.mnValue != maPixelUnion.maCombinedRGBA.mnValue);
         }
     };
 


More information about the Libreoffice-commits mailing list