mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-20 09:21:55 +00:00
LibGfx+ImageDecoder: Use RefPtr<Bitmap> instead of optional
Simplify the list of bitmaps a bit by changing `Optional<NonnullRefPtr<Bitmap>>` into `RefPtr<Bitmap>`. No functional changes.
This commit is contained in:
parent
19bee8393d
commit
e4a5be0206
Notes:
github-actions[bot]
2025-03-22 16:50:52 +00:00
Author: https://github.com/gmta
Commit: e4a5be0206
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3705
4 changed files with 11 additions and 12 deletions
|
@ -66,8 +66,8 @@ ErrorOr<void> encode(Encoder& encoder, Gfx::BitmapSequence const& bitmap_sequenc
|
||||||
for (auto const& bitmap_option : bitmaps) {
|
for (auto const& bitmap_option : bitmaps) {
|
||||||
Optional<Gfx::BitmapMetadata> data = {};
|
Optional<Gfx::BitmapMetadata> data = {};
|
||||||
|
|
||||||
if (bitmap_option.has_value()) {
|
if (bitmap_option) {
|
||||||
data = get_metadata(bitmap_option.value());
|
data = get_metadata(*bitmap_option);
|
||||||
total_buffer_size += data->size_in_bytes;
|
total_buffer_size += data->size_in_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,9 +84,8 @@ ErrorOr<void> encode(Encoder& encoder, Gfx::BitmapSequence const& bitmap_sequenc
|
||||||
|
|
||||||
Bytes buffer_bytes = { collated_buffer.data<u8>(), collated_buffer.size() };
|
Bytes buffer_bytes = { collated_buffer.data<u8>(), collated_buffer.size() };
|
||||||
size_t write_offset = 0;
|
size_t write_offset = 0;
|
||||||
for (auto const& bitmap_option : bitmaps) {
|
for (auto const& bitmap : bitmaps) {
|
||||||
if (bitmap_option.has_value()) {
|
if (bitmap) {
|
||||||
auto const& bitmap = bitmap_option.value();
|
|
||||||
buffer_bytes.overwrite(write_offset, bitmap->scanline(0), bitmap->size_in_bytes());
|
buffer_bytes.overwrite(write_offset, bitmap->scanline(0), bitmap->size_in_bytes());
|
||||||
write_offset += bitmap->size_in_bytes();
|
write_offset += bitmap->size_in_bytes();
|
||||||
}
|
}
|
||||||
|
@ -118,7 +117,7 @@ ErrorOr<Gfx::BitmapSequence> decode(Decoder& decoder)
|
||||||
|
|
||||||
// sequentially read each valid bitmap's data from the collated buffer
|
// sequentially read each valid bitmap's data from the collated buffer
|
||||||
for (auto const& metadata_option : metadata_list) {
|
for (auto const& metadata_option : metadata_list) {
|
||||||
Optional<NonnullRefPtr<Gfx::Bitmap>> bitmap = {};
|
RefPtr<Gfx::Bitmap> bitmap;
|
||||||
|
|
||||||
if (metadata_option.has_value()) {
|
if (metadata_option.has_value()) {
|
||||||
auto metadata = metadata_option.value();
|
auto metadata = metadata_option.value();
|
||||||
|
@ -139,7 +138,7 @@ ErrorOr<Gfx::BitmapSequence> decode(Decoder& decoder)
|
||||||
bitmap = TRY(Gfx::Bitmap::create_with_anonymous_buffer(metadata.format, metadata.alpha_type, move(buffer), metadata.size));
|
bitmap = TRY(Gfx::Bitmap::create_with_anonymous_buffer(metadata.format, metadata.alpha_type, move(buffer), metadata.size));
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmaps.append(move(bitmap));
|
bitmaps.append(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
struct BitmapSequence {
|
struct BitmapSequence {
|
||||||
Vector<Optional<NonnullRefPtr<Gfx::Bitmap>>> bitmaps;
|
Vector<RefPtr<Gfx::Bitmap>> bitmaps;
|
||||||
};
|
};
|
||||||
|
|
||||||
// a struct to temporarily store bitmap fields before the buffer data is decoded
|
// a struct to temporarily store bitmap fields before the buffer data is decoded
|
||||||
|
|
|
@ -76,13 +76,13 @@ void Client::did_decode_image(i64 image_id, bool is_animated, u32 loop_count, Gf
|
||||||
image.frames.ensure_capacity(bitmaps.size());
|
image.frames.ensure_capacity(bitmaps.size());
|
||||||
image.color_space = move(color_space);
|
image.color_space = move(color_space);
|
||||||
for (size_t i = 0; i < bitmaps.size(); ++i) {
|
for (size_t i = 0; i < bitmaps.size(); ++i) {
|
||||||
if (!bitmaps[i].has_value()) {
|
if (!bitmaps[i]) {
|
||||||
dbgln("ImageDecoderClient: Invalid bitmap for request {} at index {}", image_id, i);
|
dbgln("ImageDecoderClient: Invalid bitmap for request {} at index {}", image_id, i);
|
||||||
promise->reject(Error::from_string_literal("Invalid bitmap"));
|
promise->reject(Error::from_string_literal("Invalid bitmap"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
image.frames.empend(bitmaps[i].release_value(), durations[i]);
|
image.frames.empend(bitmaps[i].release_nonnull(), durations[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
promise->resolve(move(image));
|
promise->resolve(move(image));
|
||||||
|
|
|
@ -84,7 +84,7 @@ Messages::ImageDecoderServer::ConnectNewClientsResponse ConnectionFromClient::co
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void decode_image_to_bitmaps_and_durations_with_decoder(Gfx::ImageDecoder const& decoder, Optional<Gfx::IntSize> ideal_size, Vector<Optional<NonnullRefPtr<Gfx::Bitmap>>>& bitmaps, Vector<u32>& durations)
|
static void decode_image_to_bitmaps_and_durations_with_decoder(Gfx::ImageDecoder const& decoder, Optional<Gfx::IntSize> ideal_size, Vector<RefPtr<Gfx::Bitmap>>& bitmaps, Vector<u32>& durations)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < decoder.frame_count(); ++i) {
|
for (size_t i = 0; i < decoder.frame_count(); ++i) {
|
||||||
auto frame_or_error = decoder.frame(i, ideal_size);
|
auto frame_or_error = decoder.frame(i, ideal_size);
|
||||||
|
@ -118,7 +118,7 @@ static ErrorOr<ConnectionFromClient::DecodeResult> decode_image_to_details(Core:
|
||||||
else
|
else
|
||||||
dbgln("Invalid color profile: {}", maybe_icc_data.error());
|
dbgln("Invalid color profile: {}", maybe_icc_data.error());
|
||||||
|
|
||||||
Vector<Optional<NonnullRefPtr<Gfx::Bitmap>>> bitmaps;
|
Vector<RefPtr<Gfx::Bitmap>> bitmaps;
|
||||||
|
|
||||||
if (auto maybe_metadata = decoder->metadata(); maybe_metadata.has_value() && is<Gfx::ExifMetadata>(*maybe_metadata)) {
|
if (auto maybe_metadata = decoder->metadata(); maybe_metadata.has_value() && is<Gfx::ExifMetadata>(*maybe_metadata)) {
|
||||||
auto const& exif = static_cast<Gfx::ExifMetadata const&>(maybe_metadata.value());
|
auto const& exif = static_cast<Gfx::ExifMetadata const&>(maybe_metadata.value());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue