[Libreoffice-commits] core.git: include/tools include/vcl

Stephan Bergmann sbergman at redhat.com
Sat Mar 25 12:52:03 UTC 2017


 include/tools/colordata.hxx |   12 +++++++++---
 include/vcl/salgtype.hxx    |    6 +++++-
 2 files changed, 14 insertions(+), 4 deletions(-)

New commits:
commit f175ded3aef01cf598a1838cf93b8b3f37b6933c
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Sat Mar 25 10:38:47 2017 +0100

    Replace some macros with constexpr functions
    
    ...in preparation of teaching loplugin:redundantcast about C-style casts in
    macro bodies.
    
    TRGB_COLORDATA contained a curious cast to sal_Int32 (instead of sal_uInt32 aka
    ColorData), but for one that affected (by accident?) only the fist term of the
    ... | ... | ... | ... expression (so the ultimate expression was of type
    sal_uInt32), and for another before a83698b980424be214829b3ee7cdbf8d2a778755
    "tools: split out color macros into own header" there were two different
    definitions of TRGB_COLORDATA, and only one casted to sal_Int32 (the other to
    ColorData).
    
    Change-Id: I5bfffe5614d0424202268ef7adaf6a0da61ec30a
    Reviewed-on: https://gerrit.libreoffice.org/35679
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/include/tools/colordata.hxx b/include/tools/colordata.hxx
index 1d0fb42b4e39..c303957411df 100644
--- a/include/tools/colordata.hxx
+++ b/include/tools/colordata.hxx
@@ -24,10 +24,16 @@
 // Color types
 typedef sal_uInt32 ColorData;
 
-#define TRGB_COLORDATA(TRANSPARENCE,RED,GREEN,BLUE) \
-        ((sal_Int32)(((sal_uInt32)((sal_uInt8)(BLUE))))|(((sal_uInt32)((sal_uInt8)(GREEN)))<<8)|(((sal_uInt32)((sal_uInt8)(RED)))<<16)|(((sal_uInt32)((sal_uInt8)(TRANSPARENCE)))<<24))
+constexpr ColorData TRGB_COLORDATA(
+    sal_uInt8 TRANSPARENCE, sal_uInt8 RED, sal_uInt8 GREEN, sal_uInt8 BLUE)
+{
+    return sal_uInt32(BLUE) | (sal_uInt32(GREEN) << 8) | (sal_uInt32(RED) << 16)
+        | (sal_uInt32(TRANSPARENCE) << 24);
+}
 
-#define RGB_COLORDATA( r,g,b )      ((ColorData)(((sal_uInt32)((sal_uInt8)(b))))|(((sal_uInt32)((sal_uInt8)(g)))<<8)|(((sal_uInt32)((sal_uInt8)(r)))<<16))
+constexpr ColorData RGB_COLORDATA(sal_uInt8 r, sal_uInt8 g, sal_uInt8 b) {
+    return sal_uInt32(b) | (sal_uInt32(g) << 8) | (sal_uInt32(r) << 16);
+}
 
 #define COLORDATA_RED( n )          ((sal_uInt8)((n)>>16))
 #define COLORDATA_GREEN( n )        ((sal_uInt8)(((sal_uInt16)(n)) >> 8))
diff --git a/include/vcl/salgtype.hxx b/include/vcl/salgtype.hxx
index b9eb6ae74dcb..df708b4fe196 100644
--- a/include/vcl/salgtype.hxx
+++ b/include/vcl/salgtype.hxx
@@ -33,7 +33,11 @@ enum class DeviceFormat {
                         };
 
 typedef sal_uInt32 SalColor;
-#define MAKE_SALCOLOR( r, g, b )    ((SalColor)(((sal_uInt32)((sal_uInt8)(b))))|(((sal_uInt32)((sal_uInt8)(g)))<<8)|(((sal_uInt32)((sal_uInt8)(r)))<<16))
+
+constexpr SalColor MAKE_SALCOLOR(sal_uInt8 r, sal_uInt8 g, sal_uInt8 b) {
+    return sal_uInt32(b) | (sal_uInt32(g) << 8) | (sal_uInt32(r) << 16);
+}
+
 #define SALCOLOR_RED( n )           ((sal_uInt8)((n)>>16))
 #define SALCOLOR_GREEN( n )         ((sal_uInt8)(((sal_uInt16)(n)) >> 8))
 #define SALCOLOR_BLUE( n )          ((sal_uInt8)(n))


More information about the Libreoffice-commits mailing list