mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:38:10 +00:00
LibGfx: Convert Gfx::Bitmap to east const style
This commit is contained in:
parent
d85d741c59
commit
16f064d9be
2 changed files with 28 additions and 28 deletions
|
@ -55,7 +55,7 @@ size_t Bitmap::minimum_pitch(size_t physical_width, BitmapFormat format)
|
|||
return physical_width * element_size;
|
||||
}
|
||||
|
||||
static bool size_would_overflow(BitmapFormat format, const IntSize& size, int scale_factor)
|
||||
static bool size_would_overflow(BitmapFormat format, IntSize const& size, int scale_factor)
|
||||
{
|
||||
if (size.width() < 0 || size.height() < 0)
|
||||
return true;
|
||||
|
@ -67,7 +67,7 @@ static bool size_would_overflow(BitmapFormat format, const IntSize& size, int sc
|
|||
return Checked<size_t>::multiplication_would_overflow(pitch, size.height() * scale_factor);
|
||||
}
|
||||
|
||||
RefPtr<Bitmap> Bitmap::try_create(BitmapFormat format, const IntSize& size, int scale_factor)
|
||||
RefPtr<Bitmap> Bitmap::try_create(BitmapFormat format, IntSize const& size, int scale_factor)
|
||||
{
|
||||
auto backing_store_or_error = Bitmap::allocate_backing_store(format, size, scale_factor);
|
||||
if (backing_store_or_error.is_error())
|
||||
|
@ -75,20 +75,20 @@ RefPtr<Bitmap> Bitmap::try_create(BitmapFormat format, const IntSize& size, int
|
|||
return adopt_ref(*new Bitmap(format, size, scale_factor, backing_store_or_error.release_value()));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_shareable(BitmapFormat format, const IntSize& size, int scale_factor)
|
||||
ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_shareable(BitmapFormat format, IntSize const& size, int scale_factor)
|
||||
{
|
||||
if (size_would_overflow(format, size, scale_factor))
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_shareable size overflow"sv);
|
||||
|
||||
const auto pitch = minimum_pitch(size.width() * scale_factor, format);
|
||||
const auto data_size = size_in_bytes(pitch, size.height() * scale_factor);
|
||||
auto const pitch = minimum_pitch(size.width() * scale_factor, format);
|
||||
auto const data_size = size_in_bytes(pitch, size.height() * scale_factor);
|
||||
|
||||
auto buffer = TRY(Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(data_size, PAGE_SIZE)));
|
||||
auto bitmap = TRY(Bitmap::try_create_with_anonymous_buffer(format, buffer, size, scale_factor, {}));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
Bitmap::Bitmap(BitmapFormat format, const IntSize& size, int scale_factor, const BackingStore& backing_store)
|
||||
Bitmap::Bitmap(BitmapFormat format, IntSize const& size, int scale_factor, BackingStore const& backing_store)
|
||||
: m_size(size)
|
||||
, m_scale(scale_factor)
|
||||
, m_data(backing_store.data)
|
||||
|
@ -134,7 +134,7 @@ RefPtr<Bitmap> Bitmap::try_load_from_fd_and_close(int fd, String const& path, in
|
|||
if (path.ends_with(Ext, CaseSensitivity::CaseInsensitive)) { \
|
||||
auto file = MappedFile::map_from_fd_and_close(fd, highdpi_icon_path.to_string()); \
|
||||
if (!file.is_error()) \
|
||||
bmp = load_##Name##_from_memory((const u8*)file.value()->data(), file.value()->size(), highdpi_icon_path.to_string()); \
|
||||
bmp = load_##Name##_from_memory((u8 const*)file.value()->data(), file.value()->size(), highdpi_icon_path.to_string()); \
|
||||
}
|
||||
ENUMERATE_IMAGE_FORMATS
|
||||
#undef __ENUMERATE_IMAGE_FORMAT
|
||||
|
@ -152,7 +152,7 @@ RefPtr<Bitmap> Bitmap::try_load_from_fd_and_close(int fd, String const& path, in
|
|||
if (path.ends_with(Ext, CaseSensitivity::CaseInsensitive)) { \
|
||||
auto file = MappedFile::map_from_fd_and_close(fd, path); \
|
||||
if (!file.is_error()) \
|
||||
return load_##Name##_from_memory((const u8*)file.value()->data(), file.value()->size(), path); \
|
||||
return load_##Name##_from_memory((u8 const*)file.value()->data(), file.value()->size(), path); \
|
||||
}
|
||||
ENUMERATE_IMAGE_FORMATS
|
||||
#undef __ENUMERATE_IMAGE_FORMAT
|
||||
|
@ -160,7 +160,7 @@ RefPtr<Bitmap> Bitmap::try_load_from_fd_and_close(int fd, String const& path, in
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Bitmap::Bitmap(BitmapFormat format, const IntSize& size, int scale_factor, size_t pitch, void* data)
|
||||
Bitmap::Bitmap(BitmapFormat format, IntSize const& size, int scale_factor, size_t pitch, void* data)
|
||||
: m_size(size)
|
||||
, m_scale(scale_factor)
|
||||
, m_data(data)
|
||||
|
@ -174,7 +174,7 @@ Bitmap::Bitmap(BitmapFormat format, const IntSize& size, int scale_factor, size_
|
|||
allocate_palette_from_format(format, {});
|
||||
}
|
||||
|
||||
static bool check_size(const IntSize& size, int scale_factor, BitmapFormat format, unsigned actual_size)
|
||||
static bool check_size(IntSize const& size, int scale_factor, BitmapFormat format, unsigned actual_size)
|
||||
{
|
||||
// FIXME: Code duplication of size_in_bytes() and m_pitch
|
||||
unsigned expected_size_min = Bitmap::minimum_pitch(size.width() * scale_factor, format) * size.height() * scale_factor;
|
||||
|
@ -194,7 +194,7 @@ static bool check_size(const IntSize& size, int scale_factor, BitmapFormat forma
|
|||
return true;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_with_anonymous_buffer(BitmapFormat format, Core::AnonymousBuffer buffer, const IntSize& size, int scale_factor, const Vector<RGBA32>& palette)
|
||||
ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_with_anonymous_buffer(BitmapFormat format, Core::AnonymousBuffer buffer, IntSize const& size, int scale_factor, Vector<RGBA32> const& palette)
|
||||
{
|
||||
if (size_would_overflow(format, size, scale_factor))
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_with_anonymous_buffer size overflow");
|
||||
|
@ -290,7 +290,7 @@ ByteBuffer Bitmap::serialize_to_byte_buffer() const
|
|||
return buffer;
|
||||
}
|
||||
|
||||
Bitmap::Bitmap(BitmapFormat format, Core::AnonymousBuffer buffer, const IntSize& size, int scale_factor, const Vector<RGBA32>& palette)
|
||||
Bitmap::Bitmap(BitmapFormat format, Core::AnonymousBuffer buffer, IntSize const& size, int scale_factor, Vector<RGBA32> const& palette)
|
||||
: m_size(size)
|
||||
, m_scale(scale_factor)
|
||||
, m_data(buffer.data<void>())
|
||||
|
@ -593,8 +593,8 @@ ErrorOr<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, IntSiz
|
|||
if (size_would_overflow(format, size, scale_factor))
|
||||
return Error::from_string_literal("Gfx::Bitmap backing store size overflow"sv);
|
||||
|
||||
const auto pitch = minimum_pitch(size.width() * scale_factor, format);
|
||||
const auto data_size_in_bytes = size_in_bytes(pitch, size.height() * scale_factor);
|
||||
auto const pitch = minimum_pitch(size.width() * scale_factor, format);
|
||||
auto const data_size_in_bytes = size_in_bytes(pitch, size.height() * scale_factor);
|
||||
|
||||
int map_flags = MAP_ANONYMOUS | MAP_PRIVATE;
|
||||
#ifdef __serenity__
|
||||
|
@ -608,7 +608,7 @@ ErrorOr<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, IntSiz
|
|||
return BackingStore { data, pitch, data_size_in_bytes };
|
||||
}
|
||||
|
||||
void Bitmap::allocate_palette_from_format(BitmapFormat format, const Vector<RGBA32>& source_palette)
|
||||
void Bitmap::allocate_palette_from_format(BitmapFormat format, Vector<RGBA32> const& source_palette)
|
||||
{
|
||||
size_t size = palette_size(format);
|
||||
if (size == 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue