diff options
author | Lucas CHOLLET <lucas.chollet@free.fr> | 2023-02-16 10:51:16 -0500 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-02-17 10:36:03 +0100 |
commit | 782b1d20f5e5f14c7107be2942a2ac00747a8e65 (patch) | |
tree | 303693a21d2f6848259b06c89f280d84ad8004fb /Userland/Libraries/LibGfx/Bitmap.cpp | |
parent | be717edd339c6d8c1c94e2ff1b203e443e5c36b3 (diff) | |
download | serenity-782b1d20f5e5f14c7107be2942a2ac00747a8e65.zip |
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<Core::File>)` is very
straightforward.
Diffstat (limited to 'Userland/Libraries/LibGfx/Bitmap.cpp')
-rw-r--r-- | Userland/Libraries/LibGfx/Bitmap.cpp | 21 |
1 files changed, 4 insertions, 17 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<NonnullRefPtr<Bitmap>> 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<NonnullRefPtr<Bitmap>> 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<NonnullRefPtr<Bitmap>> Bitmap::load_from_file(NonnullOwnPtr<Core::File> file, StringView path) @@ -155,19 +155,6 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::load_from_file(NonnullOwnPtr<Core::File> return Error::from_string_literal("Gfx::Bitmap unable to load from file"); } -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); - 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) |