From 782b1d20f5e5f14c7107be2942a2ac00747a8e65 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Thu, 16 Feb 2023 10:51:16 -0500 Subject: [PATCH] LibGfx: Remove `Bitmap::load_from_fd_and_close()` The method was only used in `load_from_file(StringView path)` and replacing it with `load_from_file(NonnullOwnPtr)` is very straightforward. --- Userland/Libraries/LibGfx/Bitmap.cpp | 21 ++++----------------- Userland/Libraries/LibGfx/Bitmap.h | 1 - 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp index f9c777e1e7..db03f7234e 100644 --- a/Userland/Libraries/LibGfx/Bitmap.cpp +++ b/Userland/Libraries/LibGfx/Bitmap.cpp @@ -116,9 +116,9 @@ ErrorOr> Bitmap::load_from_file(StringView path, int scale TRY(highdpi_icon_path.try_appendff("{}/{}-{}x.{}", lexical_path.dirname(), lexical_path.title(), scale_factor, lexical_path.extension())); auto highdpi_icon_string = highdpi_icon_path.string_view(); - auto fd = TRY(Core::System::open(highdpi_icon_string, O_RDONLY)); + auto file = TRY(Core::File::open(highdpi_icon_string, Core::File::OpenMode::Read)); - auto bitmap = TRY(load_from_fd_and_close(fd, highdpi_icon_string)); + auto bitmap = TRY(load_from_file(move(file), highdpi_icon_string)); if (bitmap->width() % scale_factor != 0 || bitmap->height() % scale_factor != 0) 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); @@ -138,8 +138,8 @@ ErrorOr> Bitmap::load_from_file(StringView path, int scale } } - auto fd = TRY(Core::System::open(path, O_RDONLY)); - return load_from_fd_and_close(fd, path); + auto file = TRY(Core::File::open(path, Core::File::OpenMode::Read)); + return load_from_file(move(file), path); } ErrorOr> Bitmap::load_from_file(NonnullOwnPtr file, StringView path) @@ -155,19 +155,6 @@ ErrorOr> Bitmap::load_from_file(NonnullOwnPtr return Error::from_string_literal("Gfx::Bitmap unable to load from file"); } -ErrorOr> 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); - if (auto decoder = ImageDecoder::try_create_for_raw_bytes(file->bytes(), mime_type)) { - auto frame = TRY(decoder->frame(0)); - if (auto& bitmap = frame.image) - return bitmap.release_nonnull(); - } - - return Error::from_string_literal("Gfx::Bitmap unable to load from fd"); -} - Bitmap::Bitmap(BitmapFormat format, IntSize size, int scale_factor, size_t pitch, void* data) : m_size(size) , m_scale(scale_factor) diff --git a/Userland/Libraries/LibGfx/Bitmap.h b/Userland/Libraries/LibGfx/Bitmap.h index 0734b8a2dc..362c68a8c9 100644 --- a/Userland/Libraries/LibGfx/Bitmap.h +++ b/Userland/Libraries/LibGfx/Bitmap.h @@ -99,7 +99,6 @@ public: [[nodiscard]] static ErrorOr> create_wrapper(BitmapFormat, IntSize, int intrinsic_scale, size_t pitch, void*); [[nodiscard]] static ErrorOr> load_from_file(StringView path, int scale_factor = 1); [[nodiscard]] static ErrorOr> load_from_file(NonnullOwnPtr, StringView path); - [[nodiscard]] static ErrorOr> load_from_fd_and_close(int fd, StringView path); [[nodiscard]] static ErrorOr> create_with_anonymous_buffer(BitmapFormat, Core::AnonymousBuffer, IntSize, int intrinsic_scale, Vector const& palette); static ErrorOr> create_from_serialized_bytes(ReadonlyBytes); static ErrorOr> create_from_serialized_byte_buffer(ByteBuffer&&);