reduce magic numbers

This commit is contained in:
Vogel, Rick 2023-03-16 12:44:14 +01:00
parent ea8e02db13
commit f36296111d
1 changed files with 6 additions and 3 deletions

View File

@ -242,7 +242,10 @@ namespace QskRgb
QSK_EXPORT Q_REQUIRED_RESULT constexpr QRgb fromHexString( QSK_EXPORT Q_REQUIRED_RESULT constexpr QRgb fromHexString(
const char* const str, const size_t len ) noexcept const char* const str, const size_t len ) noexcept
{ {
if ( len != 7 && len != 9 ) constexpr auto rgb_len = 7;
constexpr auto rgba_len = 9;
if ( len != rgb_len && len != rgba_len )
{ {
return 0; return 0;
} }
@ -335,13 +338,13 @@ namespace QskRgb
} }
// add default 0xFF for alpha channel // add default 0xFF for alpha channel
if ( len > 1 && len <= 7 ) if ( len == rgb_len )
{ {
rgb |= 0xFF000000; rgb |= 0xFF000000;
} }
// convert rrggbbaa to aarrggbb // convert rrggbbaa to aarrggbb
if ( len > 7 ) if ( len == rgba_len )
{ {
rgb = ( 0x000000FF & rgb ) << 24 | ( rgb >> 8 ); rgb = ( 0x000000FF & rgb ) << 24 | ( rgb >> 8 );
} }