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 a83698b980
"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@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann
2017-03-25 10:38:47 +01:00
parent 4b788a1238
commit f175ded3ae
2 changed files with 14 additions and 4 deletions

View File

@@ -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))

View File

@@ -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))