summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/Bitmap.cpp
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/LibGfx/Bitmap.cpp
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/LibGfx/Bitmap.cpp')
-rw-r--r--Userland/Libraries/LibGfx/Bitmap.cpp9
1 files changed, 7 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;