mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-29 14:32:55 +00:00
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.
This commit is contained in:
parent
17676705a5
commit
e818c955b3
Notes:
sideshowbarker
2024-07-17 04:41:05 +09:00
Author: https://github.com/rtobar
Commit: e818c955b3
Pull-request: https://github.com/SerenityOS/serenity/pull/16202
2 changed files with 8 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue