Skip to content

Commit 1cb425c

Browse files
LucasCholletnico
authored andcommitted
LibGfx: Make both BilevelImage[get,set]_bit() inline methods
Makes JBIG2's composite_bilevel_image() drop from 25% to 18% in profiles.
1 parent 5ce2810 commit 1cb425c

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

Userland/Libraries/LibGfx/ImageFormats/BilevelImage.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,6 @@ ErrorOr<NonnullOwnPtr<BilevelImage>> BilevelImage::create_from_byte_buffer(ByteB
2525
return adopt_nonnull_own_or_enomem(new (nothrow) BilevelImage(move(bitmap), width, height, pitch));
2626
}
2727

28-
bool BilevelImage::get_bit(size_t x, size_t y) const
29-
{
30-
VERIFY(x < m_width);
31-
VERIFY(y < m_height);
32-
size_t byte_offset = x / 8;
33-
size_t bit_offset = x % 8;
34-
u8 byte = m_bits[y * m_pitch + byte_offset];
35-
byte = (byte >> (8 - 1 - bit_offset)) & 1;
36-
return byte != 0;
37-
}
38-
39-
void BilevelImage::set_bit(size_t x, size_t y, bool b)
40-
{
41-
VERIFY(x < m_width);
42-
VERIFY(y < m_height);
43-
size_t byte_offset = x / 8;
44-
size_t bit_offset = x % 8;
45-
u8 byte = m_bits[y * m_pitch + byte_offset];
46-
u8 mask = 1u << (8 - 1 - bit_offset);
47-
if (b)
48-
byte |= mask;
49-
else
50-
byte &= ~mask;
51-
m_bits[y * m_pitch + byte_offset] = byte;
52-
}
53-
5428
void BilevelImage::fill(bool b)
5529
{
5630
u8 fill_byte = b ? 0xff : 0;

Userland/Libraries/LibGfx/ImageFormats/BilevelImage.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,32 @@ class BilevelImage {
3131
static ErrorOr<NonnullOwnPtr<BilevelImage>> create_from_byte_buffer(ByteBuffer bitmap, size_t width, size_t height);
3232
static ErrorOr<NonnullOwnPtr<BilevelImage>> create_from_bitmap(Gfx::Bitmap const& bitmap, DitheringAlgorithm dithering_algorithm);
3333

34-
bool get_bit(size_t x, size_t y) const;
35-
void set_bit(size_t x, size_t y, bool b);
34+
ALWAYS_INLINE bool get_bit(size_t x, size_t y) const
35+
{
36+
VERIFY(x < m_width);
37+
VERIFY(y < m_height);
38+
size_t byte_offset = x / 8;
39+
size_t bit_offset = x % 8;
40+
u8 byte = m_bits[y * m_pitch + byte_offset];
41+
byte = (byte >> (8 - 1 - bit_offset)) & 1;
42+
return byte != 0;
43+
}
44+
45+
ALWAYS_INLINE void set_bit(size_t x, size_t y, bool b)
46+
{
47+
VERIFY(x < m_width);
48+
VERIFY(y < m_height);
49+
size_t byte_offset = x / 8;
50+
size_t bit_offset = x % 8;
51+
u8 byte = m_bits[y * m_pitch + byte_offset];
52+
u8 mask = 1u << (8 - 1 - bit_offset);
53+
if (b)
54+
byte |= mask;
55+
else
56+
byte &= ~mask;
57+
m_bits[y * m_pitch + byte_offset] = byte;
58+
}
59+
3660
void fill(bool b);
3761

3862
ErrorOr<NonnullOwnPtr<BilevelImage>> subbitmap(Gfx::IntRect const& rect) const;

0 commit comments

Comments
 (0)