diff options
author | Tim Schumacher <timschumi@gmx.de> | 2023-01-20 20:06:05 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-26 20:24:37 +0000 |
commit | 82a152b69602de05a28034864185545207639a8c (patch) | |
tree | 308eb816ef76a6579934786822d39f186bad385b /Userland/Libraries/LibGfx/Bitmap.cpp | |
parent | 1971bff31455306b6976fe7e69db851c94a30794 (diff) | |
download | serenity-82a152b69602de05a28034864185545207639a8c.zip |
LibGfx: Remove `try_` prefix from bitmap creation functions
Those don't have any non-try counterpart, so we might as well just omit
it.
Diffstat (limited to 'Userland/Libraries/LibGfx/Bitmap.cpp')
-rw-r--r-- | Userland/Libraries/LibGfx/Bitmap.cpp | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp index e46161f321..e5dcb609d8 100644 --- a/Userland/Libraries/LibGfx/Bitmap.cpp +++ b/Userland/Libraries/LibGfx/Bitmap.cpp @@ -65,22 +65,22 @@ static bool size_would_overflow(BitmapFormat format, IntSize size, int scale_fac return Checked<size_t>::multiplication_would_overflow(pitch, size.height() * scale_factor); } -ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create(BitmapFormat format, IntSize size, int scale_factor) +ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::create(BitmapFormat format, IntSize size, int scale_factor) { auto backing_store = TRY(Bitmap::allocate_backing_store(format, size, scale_factor)); return AK::adopt_nonnull_ref_or_enomem(new (nothrow) Bitmap(format, size, scale_factor, backing_store)); } -ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_shareable(BitmapFormat format, IntSize size, int scale_factor) +ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::create_shareable(BitmapFormat format, IntSize size, int scale_factor) { if (size_would_overflow(format, size, scale_factor)) - return Error::from_string_literal("Gfx::Bitmap::try_create_shareable size overflow"); + return Error::from_string_literal("Gfx::Bitmap::create_shareable size overflow"); 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, {})); + auto bitmap = TRY(Bitmap::create_with_anonymous_buffer(format, buffer, size, scale_factor, {})); return bitmap; } @@ -99,14 +99,14 @@ Bitmap::Bitmap(BitmapFormat format, IntSize size, int scale_factor, BackingStore m_needs_munmap = true; } -ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_wrapper(BitmapFormat format, IntSize size, int scale_factor, size_t pitch, void* data) +ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::create_wrapper(BitmapFormat format, IntSize size, int scale_factor, size_t pitch, void* data) { if (size_would_overflow(format, size, scale_factor)) - return Error::from_string_literal("Gfx::Bitmap::try_create_wrapper size overflow"); + return Error::from_string_literal("Gfx::Bitmap::create_wrapper size overflow"); return adopt_ref(*new Bitmap(format, size, scale_factor, pitch, data)); } -ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_load_from_file(StringView path, int scale_factor) +ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::load_from_file(StringView path, int scale_factor) { if (scale_factor > 1 && path.starts_with("/res/"sv)) { auto load_scaled_bitmap = [](StringView path, int scale_factor) -> ErrorOr<NonnullRefPtr<Bitmap>> { @@ -117,9 +117,9 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_load_from_file(StringView path, int s auto highdpi_icon_string = highdpi_icon_path.string_view(); auto fd = TRY(Core::System::open(highdpi_icon_string, O_RDONLY)); - auto bitmap = TRY(try_load_from_fd_and_close(fd, highdpi_icon_string)); + auto bitmap = TRY(load_from_fd_and_close(fd, highdpi_icon_string)); if (bitmap->width() % scale_factor != 0 || bitmap->height() % scale_factor != 0) - return Error::from_string_literal("Bitmap::try_load_from_file: HighDPI image size should be divisible by scale factor"); + return Error::from_string_literal("Bitmap::load_from_file: HighDPI image size should be divisible by scale factor"); bitmap->m_size.set_width(bitmap->width() / scale_factor); bitmap->m_size.set_height(bitmap->height() / scale_factor); bitmap->m_scale = scale_factor; @@ -138,10 +138,10 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_load_from_file(StringView path, int s } auto fd = TRY(Core::System::open(path, O_RDONLY)); - return try_load_from_fd_and_close(fd, path); + return load_from_fd_and_close(fd, path); } -ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_load_from_fd_and_close(int fd, StringView path) +ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::load_from_fd_and_close(int fd, StringView path) { auto file = TRY(Core::MappedFile::map_from_fd_and_close(fd, path)); auto mime_type = Core::guess_mime_type_based_on_filename(path); @@ -188,17 +188,17 @@ static bool check_size(IntSize size, int scale_factor, BitmapFormat format, unsi return true; } -ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_with_anonymous_buffer(BitmapFormat format, Core::AnonymousBuffer buffer, IntSize size, int scale_factor, Vector<ARGB32> const& palette) +ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::create_with_anonymous_buffer(BitmapFormat format, Core::AnonymousBuffer buffer, IntSize size, int scale_factor, Vector<ARGB32> const& palette) { if (size_would_overflow(format, size, scale_factor)) - return Error::from_string_literal("Gfx::Bitmap::try_create_with_anonymous_buffer size overflow"); + return Error::from_string_literal("Gfx::Bitmap::create_with_anonymous_buffer size overflow"); return adopt_nonnull_ref_or_enomem(new (nothrow) Bitmap(format, move(buffer), size, scale_factor, palette)); } -ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_from_serialized_byte_buffer(ByteBuffer&& buffer) +ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::create_from_serialized_byte_buffer(ByteBuffer&& buffer) { - return try_create_from_serialized_bytes(buffer.bytes()); + return create_from_serialized_bytes(buffer.bytes()); } /// Read a bitmap as described by: @@ -210,7 +210,7 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_from_serialized_byte_buffer(By /// - palette count /// - palette data (= palette count * BGRA8888) /// - image data (= actual size * u8) -ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_from_serialized_bytes(ReadonlyBytes bytes) +ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::create_from_serialized_bytes(ReadonlyBytes bytes) { InputMemoryStream stream { bytes }; size_t actual_size; @@ -228,26 +228,26 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_from_serialized_bytes(Readonly }; if (!read(actual_size) || !read(width) || !read(height) || !read(scale_factor) || !read(format) || !read(palette_size)) - return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed"); + return Error::from_string_literal("Gfx::Bitmap::create_from_serialized_byte_buffer: decode failed"); if (format > BitmapFormat::BGRA8888 || format < BitmapFormat::Indexed1) - return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed"); + return Error::from_string_literal("Gfx::Bitmap::create_from_serialized_byte_buffer: decode failed"); if (!check_size({ width, height }, scale_factor, format, actual_size)) - return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed"); + return Error::from_string_literal("Gfx::Bitmap::create_from_serialized_byte_buffer: decode failed"); palette.ensure_capacity(palette_size); for (size_t i = 0; i < palette_size; ++i) { if (!read(palette[i])) - return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed"); + return Error::from_string_literal("Gfx::Bitmap::create_from_serialized_byte_buffer: decode failed"); } if (stream.remaining() < actual_size) - return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed"); + return Error::from_string_literal("Gfx::Bitmap::create_from_serialized_byte_buffer: decode failed"); auto data = stream.bytes().slice(stream.offset(), actual_size); - auto bitmap = TRY(Bitmap::try_create(format, { width, height }, scale_factor)); + auto bitmap = TRY(Bitmap::create(format, { width, height }, scale_factor)); bitmap->m_palette = new ARGB32[palette_size]; memcpy(bitmap->m_palette, palette.data(), palette_size * sizeof(ARGB32)); @@ -303,7 +303,7 @@ Bitmap::Bitmap(BitmapFormat format, Core::AnonymousBuffer buffer, IntSize size, ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::clone() const { - auto new_bitmap = TRY(Bitmap::try_create(format(), size(), scale())); + auto new_bitmap = TRY(Bitmap::create(format(), size(), scale())); VERIFY(size_in_bytes() == new_bitmap->size_in_bytes()); memcpy(new_bitmap->scanline(0), scanline(0), size_in_bytes()); @@ -313,7 +313,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::clone() const ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::rotated(Gfx::RotationDirection rotation_direction) const { - auto new_bitmap = TRY(Gfx::Bitmap::try_create(this->format(), { height(), width() }, scale())); + auto new_bitmap = TRY(Gfx::Bitmap::create(this->format(), { height(), width() }, scale())); auto w = this->physical_width(); auto h = this->physical_height(); @@ -334,7 +334,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::rotated(Gfx::RotationDirection rotat ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::flipped(Gfx::Orientation orientation) const { - auto new_bitmap = TRY(Gfx::Bitmap::try_create(this->format(), { width(), height() }, scale())); + auto new_bitmap = TRY(Gfx::Bitmap::create(this->format(), { width(), height() }, scale())); auto w = this->physical_width(); auto h = this->physical_height(); @@ -357,7 +357,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(int sx, int sy) const if (sx == 1 && sy == 1) return NonnullRefPtr { *this }; - auto new_bitmap = TRY(Gfx::Bitmap::try_create(format(), { width() * sx, height() * sy }, scale())); + auto new_bitmap = TRY(Gfx::Bitmap::create(format(), { width() * sx, height() * sy }, scale())); auto old_width = physical_width(); auto old_height = physical_height(); @@ -389,7 +389,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const int scaled_width = (int)ceilf(sx * (float)width()); int scaled_height = (int)ceilf(sy * (float)height()); - auto new_bitmap = TRY(Gfx::Bitmap::try_create(format(), { scaled_width, scaled_height }, scale())); + auto new_bitmap = TRY(Gfx::Bitmap::create(format(), { scaled_width, scaled_height }, scale())); auto old_width = physical_width(); auto old_height = physical_height(); @@ -461,7 +461,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::cropped(Gfx::IntRect crop, Optional<BitmapFormat> new_bitmap_format) const { - auto new_bitmap = TRY(Gfx::Bitmap::try_create(new_bitmap_format.value_or(format()), { crop.width(), crop.height() }, scale())); + auto new_bitmap = TRY(Gfx::Bitmap::create(new_bitmap_format.value_or(format()), { crop.width(), crop.height() }, scale())); auto scaled_crop = crop * scale(); for (int y = 0; y < scaled_crop.height(); ++y) { @@ -483,7 +483,7 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::to_bitmap_backed_by_anonymous_buffer() co if (m_buffer.is_valid()) return NonnullRefPtr { *this }; auto buffer = TRY(Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(size_in_bytes(), PAGE_SIZE))); - auto bitmap = TRY(Bitmap::try_create_with_anonymous_buffer(m_format, move(buffer), size(), scale(), palette_to_vector())); + auto bitmap = TRY(Bitmap::create_with_anonymous_buffer(m_format, move(buffer), size(), scale(), palette_to_vector())); memcpy(bitmap->scanline(0), scanline(0), size_in_bytes()); return bitmap; } |