LibGfx: Add data_size() accessors to Bitmap and CMYKBitmap

These return the size of the data in bytes.
This commit is contained in:
Nico Weber 2024-01-24 11:43:39 -05:00 committed by Andreas Kling
parent 0acc370f7b
commit 11b623b1fd
Notes: sideshowbarker 2024-07-17 07:35:03 +09:00
2 changed files with 9 additions and 2 deletions

View file

@ -142,6 +142,7 @@ public:
[[nodiscard]] ARGB32* begin();
[[nodiscard]] ARGB32* end();
[[nodiscard]] size_t data_size() const;
[[nodiscard]] IntRect rect() const { return { {}, m_size }; }
[[nodiscard]] IntSize size() const { return m_size; }
@ -282,7 +283,12 @@ ALWAYS_INLINE ARGB32* Bitmap::begin()
ALWAYS_INLINE ARGB32* Bitmap::end()
{
return reinterpret_cast<ARGB32*>(reinterpret_cast<u8*>(m_data) + (m_size.height() * m_pitch));
return reinterpret_cast<ARGB32*>(reinterpret_cast<u8*>(m_data) + data_size());
}
ALWAYS_INLINE size_t Bitmap::data_size() const
{
return m_size.height() * m_pitch;
}
template<>

View file

@ -32,6 +32,7 @@ public:
[[nodiscard]] CMYK* begin();
[[nodiscard]] CMYK* end();
[[nodiscard]] size_t data_size() const { return m_data.size(); }
ErrorOr<RefPtr<Bitmap>> to_low_quality_rgb() const;
@ -67,7 +68,7 @@ inline CMYK* CMYKBitmap::begin()
inline CMYK* CMYKBitmap::end()
{
return reinterpret_cast<CMYK*>(m_data.data() + m_data.size());
return reinterpret_cast<CMYK*>(m_data.data() + data_size());
}
}