1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:57:34 +00:00

LibGfx: Sprinkle [[nodiscard]] on Gfx::Bitmap

This commit is contained in:
Andreas Kling 2021-07-21 18:08:42 +02:00
parent 583d6741ed
commit 3d0c5814d2

View file

@ -109,49 +109,49 @@ public:
return false; return false;
} }
RefPtr<Gfx::Bitmap> clone() const; [[nodiscard]] RefPtr<Gfx::Bitmap> clone() const;
RefPtr<Gfx::Bitmap> rotated(Gfx::RotationDirection) const; [[nodiscard]] RefPtr<Gfx::Bitmap> rotated(Gfx::RotationDirection) const;
RefPtr<Gfx::Bitmap> flipped(Gfx::Orientation) const; [[nodiscard]] RefPtr<Gfx::Bitmap> flipped(Gfx::Orientation) const;
RefPtr<Gfx::Bitmap> scaled(int sx, int sy) const; [[nodiscard]] RefPtr<Gfx::Bitmap> scaled(int sx, int sy) const;
RefPtr<Gfx::Bitmap> scaled(float sx, float sy) const; [[nodiscard]] RefPtr<Gfx::Bitmap> scaled(float sx, float sy) const;
RefPtr<Gfx::Bitmap> cropped(Gfx::IntRect) const; [[nodiscard]] RefPtr<Gfx::Bitmap> cropped(Gfx::IntRect) const;
RefPtr<Bitmap> to_bitmap_backed_by_anonymous_buffer() const; [[nodiscard]] RefPtr<Bitmap> to_bitmap_backed_by_anonymous_buffer() const;
ByteBuffer serialize_to_byte_buffer() const; [[nodiscard]] ByteBuffer serialize_to_byte_buffer() const;
ShareableBitmap to_shareable_bitmap() const; [[nodiscard]] ShareableBitmap to_shareable_bitmap() const;
~Bitmap(); ~Bitmap();
u8* scanline_u8(int physical_y); [[nodiscard]] u8* scanline_u8(int physical_y);
const u8* scanline_u8(int physical_y) const; [[nodiscard]] const u8* scanline_u8(int physical_y) const;
RGBA32* scanline(int physical_y); [[nodiscard]] RGBA32* scanline(int physical_y);
const RGBA32* scanline(int physical_y) const; [[nodiscard]] const RGBA32* scanline(int physical_y) const;
IntRect rect() const { return { {}, m_size }; } [[nodiscard]] IntRect rect() const { return { {}, m_size }; }
IntSize size() const { return m_size; } [[nodiscard]] IntSize size() const { return m_size; }
int width() const { return m_size.width(); } [[nodiscard]] int width() const { return m_size.width(); }
int height() const { return m_size.height(); } [[nodiscard]] int height() const { return m_size.height(); }
int scale() const { return m_scale; } [[nodiscard]] int scale() const { return m_scale; }
IntRect physical_rect() const { return rect() * scale(); } [[nodiscard]] IntRect physical_rect() const { return rect() * scale(); }
IntSize physical_size() const { return size() * scale(); } [[nodiscard]] IntSize physical_size() const { return size() * scale(); }
int physical_width() const { return physical_size().width(); } [[nodiscard]] int physical_width() const { return physical_size().width(); }
int physical_height() const { return physical_size().height(); } [[nodiscard]] int physical_height() const { return physical_size().height(); }
size_t pitch() const { return m_pitch; } [[nodiscard]] size_t pitch() const { return m_pitch; }
ALWAYS_INLINE bool is_indexed() const [[nodiscard]] ALWAYS_INLINE bool is_indexed() const
{ {
return is_indexed(m_format); return is_indexed(m_format);
} }
ALWAYS_INLINE static bool is_indexed(BitmapFormat format) [[nodiscard]] ALWAYS_INLINE static bool is_indexed(BitmapFormat format)
{ {
return format == BitmapFormat::Indexed8 || format == BitmapFormat::Indexed4 return format == BitmapFormat::Indexed8 || format == BitmapFormat::Indexed4
|| format == BitmapFormat::Indexed2 || format == BitmapFormat::Indexed1; || format == BitmapFormat::Indexed2 || format == BitmapFormat::Indexed1;
} }
static size_t palette_size(BitmapFormat format) [[nodiscard]] static size_t palette_size(BitmapFormat format)
{ {
switch (format) { switch (format) {
case BitmapFormat::Indexed1: case BitmapFormat::Indexed1:
@ -167,9 +167,9 @@ public:
} }
} }
Vector<RGBA32> palette_to_vector() const; [[nodiscard]] Vector<RGBA32> palette_to_vector() const;
static unsigned bpp_for_format(BitmapFormat format) [[nodiscard]] static unsigned bpp_for_format(BitmapFormat format)
{ {
switch (format) { switch (format) {
case BitmapFormat::Indexed1: case BitmapFormat::Indexed1:
@ -190,30 +190,30 @@ public:
} }
} }
static size_t minimum_pitch(size_t physical_width, BitmapFormat); [[nodiscard]] static size_t minimum_pitch(size_t physical_width, BitmapFormat);
unsigned bpp() const [[nodiscard]] unsigned bpp() const
{ {
return bpp_for_format(m_format); return bpp_for_format(m_format);
} }
void fill(Color); void fill(Color);
bool has_alpha_channel() const { return m_format == BitmapFormat::BGRA8888; } [[nodiscard]] bool has_alpha_channel() const { return m_format == BitmapFormat::BGRA8888; }
BitmapFormat format() const { return m_format; } [[nodiscard]] BitmapFormat format() const { return m_format; }
void set_mmap_name(String const&); void set_mmap_name(String const&);
static constexpr size_t size_in_bytes(size_t pitch, int physical_height) { return pitch * physical_height; } [[nodiscard]] static constexpr size_t size_in_bytes(size_t pitch, int physical_height) { return pitch * physical_height; }
size_t size_in_bytes() const { return size_in_bytes(m_pitch, physical_height()); } [[nodiscard]] size_t size_in_bytes() const { return size_in_bytes(m_pitch, physical_height()); }
Color palette_color(u8 index) const { return Color::from_rgba(m_palette[index]); } [[nodiscard]] Color palette_color(u8 index) const { return Color::from_rgba(m_palette[index]); }
void set_palette_color(u8 index, Color color) { m_palette[index] = color.value(); } void set_palette_color(u8 index, Color color) { m_palette[index] = color.value(); }
template<StorageFormat> template<StorageFormat>
Color get_pixel(int physical_x, int physical_y) const; [[nodiscard]] Color get_pixel(int physical_x, int physical_y) const;
Color get_pixel(int physical_x, int physical_y) const; [[nodiscard]] Color get_pixel(int physical_x, int physical_y) const;
Color get_pixel(const IntPoint& physical_position) const [[nodiscard]] Color get_pixel(const IntPoint& physical_position) const
{ {
return get_pixel(physical_position.x(), physical_position.y()); return get_pixel(physical_position.x(), physical_position.y());
} }
@ -226,13 +226,13 @@ public:
set_pixel(physical_position.x(), physical_position.y(), color); set_pixel(physical_position.x(), physical_position.y(), color);
} }
bool is_purgeable() const { return m_purgeable; } [[nodiscard]] bool is_purgeable() const { return m_purgeable; }
bool is_volatile() const { return m_volatile; } [[nodiscard]] bool is_volatile() const { return m_volatile; }
void set_volatile(); void set_volatile();
[[nodiscard]] bool set_nonvolatile(); [[nodiscard]] bool set_nonvolatile();
Core::AnonymousBuffer& anonymous_buffer() { return m_buffer; } [[nodiscard]] Core::AnonymousBuffer& anonymous_buffer() { return m_buffer; }
const Core::AnonymousBuffer& anonymous_buffer() const { return m_buffer; } [[nodiscard]] Core::AnonymousBuffer const& anonymous_buffer() const { return m_buffer; }
private: private:
enum class Purgeable { enum class Purgeable {