summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorRodrigo Tobar <rtobar@icrar.org>2022-11-25 10:56:48 +0800
committerAndreas Kling <kling@serenityos.org>2022-12-10 10:49:03 +0100
commite818c955b34f456d4bf0940137f7157d1c36442c (patch)
tree95537400a33364b4767a9cb95fec41d15a21a30b /Userland/Libraries
parent17676705a5f9db8e3ff93b204bc9a347c78e378f (diff)
downloadserenity-e818c955b34f456d4bf0940137f7157d1c36442c.zip
LibGfx: Allow creating Bitmaps from ReadonlyBytes objects
The existing try_create_from_serialized_byte_buffer function accepts a ByteBuffer, but in reality it requires only a ReadonlyBytes, since internally the only thing it does is calling buffer.bytes(). There is thus no reason to have a function that simply accepts ReadonlyBytes, and implement the former in terms of the newer.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGfx/Bitmap.cpp9
-rw-r--r--Userland/Libraries/LibGfx/Bitmap.h1
2 files changed, 8 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp
index 6f5b3e8cd6..cd91702f1a 100644
--- a/Userland/Libraries/LibGfx/Bitmap.cpp
+++ b/Userland/Libraries/LibGfx/Bitmap.cpp
@@ -194,6 +194,11 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_with_anonymous_buffer(BitmapFo
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)
+{
+ return try_create_from_serialized_bytes(buffer.bytes());
+}
+
/// Read a bitmap as described by:
/// - actual size
/// - width
@@ -203,9 +208,9 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_with_anonymous_buffer(BitmapFo
/// - palette count
/// - palette data (= palette count * BGRA8888)
/// - image data (= actual size * u8)
-ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_from_serialized_byte_buffer(ByteBuffer&& buffer)
+ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_from_serialized_bytes(ReadonlyBytes bytes)
{
- InputMemoryStream stream { buffer };
+ InputMemoryStream stream { bytes };
size_t actual_size;
unsigned width;
unsigned height;
diff --git a/Userland/Libraries/LibGfx/Bitmap.h b/Userland/Libraries/LibGfx/Bitmap.h
index c694634ce7..b1dcf9bb65 100644
--- a/Userland/Libraries/LibGfx/Bitmap.h
+++ b/Userland/Libraries/LibGfx/Bitmap.h
@@ -98,6 +98,7 @@ public:
[[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_load_from_file(StringView path, int scale_factor = 1);
[[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_load_from_fd_and_close(int fd, StringView path);
[[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_create_with_anonymous_buffer(BitmapFormat, Core::AnonymousBuffer, IntSize, int intrinsic_scale, Vector<ARGB32> const& palette);
+ static ErrorOr<NonnullRefPtr<Bitmap>> try_create_from_serialized_bytes(ReadonlyBytes);
static ErrorOr<NonnullRefPtr<Bitmap>> try_create_from_serialized_byte_buffer(ByteBuffer&&);
static bool is_path_a_supported_image_format(StringView path)