mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:37:46 +00:00
LibGfx: Use count_leading_zeroes
to calculate nearest power of 2
This removes the possibility of an infinite loop.
This commit is contained in:
parent
6e4c97a328
commit
7096ea82f9
2 changed files with 6 additions and 8 deletions
|
@ -63,10 +63,9 @@ static constexpr u32 WOFF_SIGNATURE = 0x774F4646;
|
||||||
|
|
||||||
static u16 pow_2_less_than_or_equal(u16 x)
|
static u16 pow_2_less_than_or_equal(u16 x)
|
||||||
{
|
{
|
||||||
u16 result = 1;
|
VERIFY(x > 0);
|
||||||
while (result < x)
|
VERIFY(x < 32769);
|
||||||
result <<= 1;
|
return 1 << (sizeof(u16) * 8 - count_leading_zeroes<u16>(x - 1));
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_file(DeprecatedString path, unsigned int index)
|
ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_file(DeprecatedString path, unsigned int index)
|
||||||
|
|
|
@ -111,10 +111,9 @@ static i16 be_i16(u8 const* ptr)
|
||||||
|
|
||||||
static u16 pow_2_less_than_or_equal(u16 x)
|
static u16 pow_2_less_than_or_equal(u16 x)
|
||||||
{
|
{
|
||||||
u16 result = 1;
|
VERIFY(x > 0);
|
||||||
while (result < x)
|
VERIFY(x < 32769);
|
||||||
result <<= 1;
|
return 1 << (sizeof(u16) * 8 - count_leading_zeroes<u16>(x - 1));
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class TransformationVersion {
|
enum class TransformationVersion {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue