mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:17:44 +00:00
LibGfx: Move common loader functionality to load from memory functions
This will share functionality between the load from path and load from memory functions.
This commit is contained in:
parent
eb5320023a
commit
c966c32571
19 changed files with 54 additions and 70 deletions
|
@ -9,7 +9,6 @@
|
|||
#include <AK/Debug.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/MappedFile.h>
|
||||
#include <AK/Math.h>
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <AK/String.h>
|
||||
|
@ -1238,17 +1237,14 @@ RefPtr<Gfx::Bitmap> load_jpg(String const& path)
|
|||
auto file_or_error = MappedFile::map(path);
|
||||
if (file_or_error.is_error())
|
||||
return nullptr;
|
||||
auto bitmap = load_jpg_impl((const u8*)file_or_error.value()->data(), file_or_error.value()->size());
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded JPG: {}", bitmap->size(), LexicalPath::canonicalized_path(path)));
|
||||
return bitmap;
|
||||
return load_jpg_from_memory((u8 const*)file_or_error.value()->data(), file_or_error.value()->size(), path);
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Bitmap> load_jpg_from_memory(const u8* data, size_t length)
|
||||
RefPtr<Gfx::Bitmap> load_jpg_from_memory(u8 const* data, size_t length, String const& mmap_name)
|
||||
{
|
||||
auto bitmap = load_jpg_impl(data, length);
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded jpg: <memory>", bitmap->size()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded jpg: {}", bitmap->size(), mmap_name));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue