mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 05:17:34 +00:00
LibGfx: Use ErrorOr<T> for Bitmap::try_create()
Another one that was used in a fajillion places.
This commit is contained in:
parent
235f39e449
commit
0de33b3d6c
43 changed files with 157 additions and 141 deletions
|
@ -64,7 +64,7 @@ static RefPtr<Gfx::Bitmap> s_background_inverted;
|
|||
|
||||
Card::Card(Type type, uint8_t value)
|
||||
: m_rect(Gfx::IntRect({}, { width, height }))
|
||||
, m_front(*Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { width, height }))
|
||||
, m_front(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { width, height }).release_value_but_fixme_should_propagate_errors())
|
||||
, m_type(type)
|
||||
, m_value(value)
|
||||
{
|
||||
|
@ -72,7 +72,7 @@ Card::Card(Type type, uint8_t value)
|
|||
Gfx::IntRect paint_rect({ 0, 0 }, { width, height });
|
||||
|
||||
if (s_background.is_null()) {
|
||||
s_background = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { width, height });
|
||||
s_background = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { width, height }).release_value_but_fixme_should_propagate_errors();
|
||||
Gfx::Painter bg_painter(*s_background);
|
||||
|
||||
auto image = Gfx::Bitmap::try_load_from_file("/res/icons/cards/buggie-deck.png").release_value_but_fixme_should_propagate_errors();
|
||||
|
|
|
@ -478,7 +478,7 @@ static Gfx::IntSize closest_multiple(const Gfx::IntSize& min_size, size_t step)
|
|||
}
|
||||
|
||||
SoftwareRasterizer::SoftwareRasterizer(const Gfx::IntSize& min_size)
|
||||
: m_render_target { Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, closest_multiple(min_size, RASTERIZER_BLOCK_SIZE)) }
|
||||
: m_render_target { Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, closest_multiple(min_size, RASTERIZER_BLOCK_SIZE)).release_value_but_fixme_should_propagate_errors() }
|
||||
, m_depth_buffer { adopt_own(*new DepthBuffer(closest_multiple(min_size, RASTERIZER_BLOCK_SIZE))) }
|
||||
{
|
||||
}
|
||||
|
@ -547,7 +547,7 @@ void SoftwareRasterizer::resize(const Gfx::IntSize& min_size)
|
|||
{
|
||||
wait_for_all_threads();
|
||||
|
||||
m_render_target = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, closest_multiple(min_size, RASTERIZER_BLOCK_SIZE));
|
||||
m_render_target = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, closest_multiple(min_size, RASTERIZER_BLOCK_SIZE)).release_value_but_fixme_should_propagate_errors();
|
||||
m_depth_buffer = adopt_own(*new DepthBuffer(m_render_target->size()));
|
||||
}
|
||||
|
||||
|
|
|
@ -94,9 +94,12 @@ RefPtr<Gfx::Bitmap> Clipboard::bitmap() const
|
|||
auto clipping_bitmap_or_error = Gfx::Bitmap::try_create_wrapper((Gfx::BitmapFormat)format.value(), { (int)width.value(), (int)height.value() }, scale.value(), pitch.value(), clipping.data.data());
|
||||
if (clipping_bitmap_or_error.is_error())
|
||||
return nullptr;
|
||||
auto clipping_bitmap = clipping_bitmap_or_error.release_value();
|
||||
auto clipping_bitmap = clipping_bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { (int)width.value(), (int)height.value() }, scale.value());
|
||||
auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { (int)width.value(), (int)height.value() }, scale.value());
|
||||
if (bitmap_or_error.is_error())
|
||||
return nullptr;
|
||||
auto bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
for (int y = 0; y < clipping_bitmap->physical_height(); ++y) {
|
||||
for (int x = 0; x < clipping_bitmap->physical_width(); ++x) {
|
||||
|
|
|
@ -532,7 +532,7 @@ ColorField::ColorField(Color color)
|
|||
|
||||
void ColorField::create_color_bitmap()
|
||||
{
|
||||
m_color_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 256, 256 });
|
||||
m_color_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 256, 256 }).release_value_but_fixme_should_propagate_errors();
|
||||
auto painter = Gfx::Painter(*m_color_bitmap);
|
||||
|
||||
Gfx::HSV hsv;
|
||||
|
@ -658,7 +658,7 @@ void ColorField::resize_event(ResizeEvent&)
|
|||
ColorSlider::ColorSlider(double value)
|
||||
: m_value(value)
|
||||
{
|
||||
m_color_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 32, 360 });
|
||||
m_color_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 32, 360 }).release_value_but_fixme_should_propagate_errors();
|
||||
auto painter = Gfx::Painter(*m_color_bitmap);
|
||||
|
||||
for (int h = 0; h < 360; h++) {
|
||||
|
|
|
@ -624,10 +624,14 @@ static RefPtr<Gfx::Bitmap> render_thumbnail(StringView const& path)
|
|||
|
||||
double scale = min(32 / (double)bitmap->width(), 32 / (double)bitmap->height());
|
||||
|
||||
auto thumbnail = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { 32, 32 });
|
||||
auto thumbnail_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { 32, 32 });
|
||||
if (thumbnail_or_error.is_error())
|
||||
return nullptr;
|
||||
auto thumbnail = thumbnail_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
auto destination = Gfx::IntRect(0, 0, (int)(bitmap->width() * scale), (int)(bitmap->height() * scale)).centered_within(thumbnail->rect());
|
||||
|
||||
Painter painter(*thumbnail);
|
||||
Painter painter(thumbnail);
|
||||
painter.draw_scaled_bitmap(destination, *bitmap, bitmap->rect());
|
||||
return thumbnail;
|
||||
}
|
||||
|
|
|
@ -903,8 +903,7 @@ void Window::set_icon(const Gfx::Bitmap* icon)
|
|||
|
||||
Gfx::IntSize icon_size = icon ? icon->size() : Gfx::IntSize(16, 16);
|
||||
|
||||
m_icon = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, icon_size);
|
||||
VERIFY(m_icon);
|
||||
m_icon = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, icon_size).release_value_but_fixme_should_propagate_errors();
|
||||
if (icon) {
|
||||
Painter painter(*m_icon);
|
||||
painter.blit({ 0, 0 }, *icon, icon->rect());
|
||||
|
|
|
@ -1187,12 +1187,15 @@ static bool decode_bmp_pixel_data(BMPLoadingContext& context)
|
|||
|
||||
const u32 width = abs(context.dib.core.width);
|
||||
const u32 height = abs(context.dib.core.height);
|
||||
context.bitmap = Bitmap::try_create(format, { static_cast<int>(width), static_cast<int>(height) });
|
||||
if (!context.bitmap) {
|
||||
dbgln("BMP appears to have overly large dimensions");
|
||||
|
||||
auto bitmap_or_error = Bitmap::try_create(format, { static_cast<int>(width), static_cast<int>(height) });
|
||||
if (bitmap_or_error.is_error()) {
|
||||
// FIXME: Propagate the *real* error.
|
||||
return false;
|
||||
}
|
||||
|
||||
context.bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
ByteBuffer rle_buffer;
|
||||
ReadonlyBytes bytes { context.file_bytes + context.data_offset, context.file_size - context.data_offset };
|
||||
|
||||
|
|
|
@ -67,12 +67,10 @@ static bool size_would_overflow(BitmapFormat format, IntSize const& size, int sc
|
|||
return Checked<size_t>::multiplication_would_overflow(pitch, size.height() * scale_factor);
|
||||
}
|
||||
|
||||
RefPtr<Bitmap> Bitmap::try_create(BitmapFormat format, IntSize const& size, int scale_factor)
|
||||
ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create(BitmapFormat format, IntSize const& size, int scale_factor)
|
||||
{
|
||||
auto backing_store_or_error = Bitmap::allocate_backing_store(format, size, scale_factor);
|
||||
if (backing_store_or_error.is_error())
|
||||
return nullptr;
|
||||
return adopt_ref(*new Bitmap(format, size, scale_factor, backing_store_or_error.release_value()));
|
||||
auto backing_store = TRY(Bitmap::allocate_backing_store(format, size, scale_factor));
|
||||
return AK::adopt_nonnull_ref_or_enomem(new (nothrow) Bitmap(format, size, scale_factor, backing_store));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_shareable(BitmapFormat format, IntSize const& size, int scale_factor)
|
||||
|
@ -250,9 +248,10 @@ RefPtr<Bitmap> Bitmap::try_create_from_serialized_byte_buffer(ByteBuffer&& buffe
|
|||
|
||||
auto data = stream.bytes().slice(stream.offset(), actual_size);
|
||||
|
||||
auto bitmap = Bitmap::try_create(format, { width, height }, scale_factor);
|
||||
if (!bitmap)
|
||||
auto bitmap_or_error = Bitmap::try_create(format, { width, height }, scale_factor);
|
||||
if (bitmap_or_error.is_error())
|
||||
return {};
|
||||
auto bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
bitmap->m_palette = new RGBA32[palette_size];
|
||||
memcpy(bitmap->m_palette, palette.data(), palette_size * sizeof(RGBA32));
|
||||
|
@ -309,26 +308,17 @@ Bitmap::Bitmap(BitmapFormat format, Core::AnonymousBuffer buffer, IntSize const&
|
|||
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::clone() const
|
||||
{
|
||||
auto new_bitmap = Bitmap::try_create(format(), size(), scale());
|
||||
|
||||
if (!new_bitmap) {
|
||||
// FIXME: Propagate the *real* error, once we have it.
|
||||
return Error::from_errno(ENOMEM);
|
||||
}
|
||||
auto new_bitmap = TRY(Bitmap::try_create(format(), size(), scale()));
|
||||
|
||||
VERIFY(size_in_bytes() == new_bitmap->size_in_bytes());
|
||||
memcpy(new_bitmap->scanline(0), scanline(0), size_in_bytes());
|
||||
|
||||
return new_bitmap.release_nonnull();
|
||||
return new_bitmap;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::rotated(Gfx::RotationDirection rotation_direction) const
|
||||
{
|
||||
auto new_bitmap = Gfx::Bitmap::try_create(this->format(), { height(), width() }, scale());
|
||||
if (!new_bitmap) {
|
||||
// FIXME: Propagate the *real* error, once we have it.
|
||||
return Error::from_errno(ENOMEM);
|
||||
}
|
||||
auto new_bitmap = TRY(Gfx::Bitmap::try_create(this->format(), { height(), width() }, scale()));
|
||||
|
||||
auto w = this->physical_width();
|
||||
auto h = this->physical_height();
|
||||
|
@ -344,16 +334,12 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::rotated(Gfx::RotationDirection rotat
|
|||
}
|
||||
}
|
||||
|
||||
return new_bitmap.release_nonnull();
|
||||
return new_bitmap;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::flipped(Gfx::Orientation orientation) const
|
||||
{
|
||||
auto new_bitmap = Gfx::Bitmap::try_create(this->format(), { width(), height() }, scale());
|
||||
if (!new_bitmap) {
|
||||
// FIXME: Propagate the *real* error, once we have it.
|
||||
return Error::from_errno(ENOMEM);
|
||||
}
|
||||
auto new_bitmap = TRY(Gfx::Bitmap::try_create(this->format(), { width(), height() }, scale()));
|
||||
|
||||
auto w = this->physical_width();
|
||||
auto h = this->physical_height();
|
||||
|
@ -367,7 +353,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::flipped(Gfx::Orientation orientation
|
|||
}
|
||||
}
|
||||
|
||||
return new_bitmap.release_nonnull();
|
||||
return new_bitmap;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(int sx, int sy) const
|
||||
|
@ -376,11 +362,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(int sx, int sy) const
|
|||
if (sx == 1 && sy == 1)
|
||||
return NonnullRefPtr { *this };
|
||||
|
||||
auto new_bitmap = Gfx::Bitmap::try_create(format(), { width() * sx, height() * sy }, scale());
|
||||
if (!new_bitmap) {
|
||||
// FIXME: Propagate the *real* error, once we have it.
|
||||
return Error::from_errno(ENOMEM);
|
||||
}
|
||||
auto new_bitmap = TRY(Gfx::Bitmap::try_create(format(), { width() * sx, height() * sy }, scale()));
|
||||
|
||||
auto old_width = physical_width();
|
||||
auto old_height = physical_height();
|
||||
|
@ -399,7 +381,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(int sx, int sy) const
|
|||
}
|
||||
}
|
||||
|
||||
return new_bitmap.release_nonnull();
|
||||
return new_bitmap;
|
||||
}
|
||||
|
||||
// http://fourier.eng.hmc.edu/e161/lectures/resize/node3.html
|
||||
|
@ -412,11 +394,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const
|
|||
int scaled_width = (int)ceilf(sx * (float)width());
|
||||
int scaled_height = (int)ceilf(sy * (float)height());
|
||||
|
||||
auto new_bitmap = Gfx::Bitmap::try_create(format(), { scaled_width, scaled_height }, scale());
|
||||
if (!new_bitmap) {
|
||||
// FIXME: Propagate the *real* error, once we have it.
|
||||
return Error::from_errno(ENOMEM);
|
||||
}
|
||||
auto new_bitmap = TRY(Gfx::Bitmap::try_create(format(), { scaled_width, scaled_height }, scale()));
|
||||
|
||||
auto old_width = physical_width();
|
||||
auto old_height = physical_height();
|
||||
|
@ -483,16 +461,12 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const
|
|||
// Bottom-right pixel
|
||||
new_bitmap->set_pixel(new_width - 1, new_height - 1, get_pixel(physical_width() - 1, physical_height() - 1));
|
||||
|
||||
return new_bitmap.release_nonnull();
|
||||
return new_bitmap;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::cropped(Gfx::IntRect crop) const
|
||||
{
|
||||
auto new_bitmap = Gfx::Bitmap::try_create(format(), { crop.width(), crop.height() }, 1);
|
||||
if (!new_bitmap) {
|
||||
// FIXME: Propagate the *real* error, once we have it.
|
||||
return Error::from_errno(ENOMEM);
|
||||
}
|
||||
auto new_bitmap = TRY(Gfx::Bitmap::try_create(format(), { crop.width(), crop.height() }, 1));
|
||||
|
||||
for (int y = 0; y < crop.height(); ++y) {
|
||||
for (int x = 0; x < crop.width(); ++x) {
|
||||
|
@ -505,7 +479,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::cropped(Gfx::IntRect crop) const
|
|||
}
|
||||
}
|
||||
}
|
||||
return new_bitmap.release_nonnull();
|
||||
return new_bitmap;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::to_bitmap_backed_by_anonymous_buffer() const
|
||||
|
|
|
@ -90,7 +90,7 @@ enum RotationDirection {
|
|||
|
||||
class Bitmap : public RefCounted<Bitmap> {
|
||||
public:
|
||||
[[nodiscard]] static RefPtr<Bitmap> try_create(BitmapFormat, IntSize const&, int intrinsic_scale = 1);
|
||||
[[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_create(BitmapFormat, IntSize const&, int intrinsic_scale = 1);
|
||||
[[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_create_shareable(BitmapFormat, IntSize const&, int intrinsic_scale = 1);
|
||||
[[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_create_wrapper(BitmapFormat, IntSize const&, int intrinsic_scale, size_t pitch, void*);
|
||||
[[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_load_from_file(String const& path, int scale_factor = 1);
|
||||
|
|
|
@ -793,7 +793,7 @@ static bool decode_dds(DDSLoadingContext& context)
|
|||
dbgln_if(DDS_DEBUG, "There are {} bytes remaining, we need {} for mipmap level {} of the image", stream.remaining(), needed_bytes, mipmap_level);
|
||||
VERIFY(stream.remaining() >= needed_bytes);
|
||||
|
||||
context.bitmap = Bitmap::try_create(BitmapFormat::BGRA8888, { width, height });
|
||||
context.bitmap = Bitmap::try_create(BitmapFormat::BGRA8888, { width, height }).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
decode_bitmap(stream, context, format, width, height);
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ public:
|
|||
if (&target == &source && (!apply_cache.m_target || !apply_cache.m_target->size().contains(source_rect.size()))) {
|
||||
// TODO: We probably don't need the entire source_rect, we could inflate
|
||||
// the target_rect appropriately
|
||||
apply_cache.m_target = Gfx::Bitmap::try_create(source.format(), source_rect.size());
|
||||
apply_cache.m_target = Gfx::Bitmap::try_create(source.format(), source_rect.size()).release_value_but_fixme_should_propagate_errors();
|
||||
target_rect.translate_by(-target_rect.location());
|
||||
}
|
||||
|
||||
|
|
|
@ -292,12 +292,18 @@ static bool decode_frame(GIFLoadingContext& context, size_t frame_index)
|
|||
size_t start_frame = context.current_frame + 1;
|
||||
if (context.state < GIFLoadingContext::State::FrameComplete) {
|
||||
start_frame = 0;
|
||||
context.frame_buffer = Bitmap::try_create(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height });
|
||||
if (!context.frame_buffer)
|
||||
return false;
|
||||
context.prev_frame_buffer = Bitmap::try_create(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height });
|
||||
if (!context.prev_frame_buffer)
|
||||
return false;
|
||||
{
|
||||
auto bitmap_or_error = Bitmap::try_create(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height });
|
||||
if (bitmap_or_error.is_error())
|
||||
return false;
|
||||
context.frame_buffer = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
{
|
||||
auto bitmap_or_error = Bitmap::try_create(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height });
|
||||
if (bitmap_or_error.is_error())
|
||||
return false;
|
||||
context.prev_frame_buffer = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
} else if (frame_index < context.current_frame) {
|
||||
start_frame = 0;
|
||||
}
|
||||
|
|
|
@ -241,9 +241,10 @@ static bool load_ico_bmp(ICOLoadingContext& context, ICOImageDescriptor& desc)
|
|||
return false;
|
||||
}
|
||||
|
||||
desc.bitmap = Bitmap::try_create(BitmapFormat::BGRA8888, { desc.width, desc.height });
|
||||
if (!desc.bitmap)
|
||||
auto bitmap_or_error = Bitmap::try_create(BitmapFormat::BGRA8888, { desc.width, desc.height });
|
||||
if (bitmap_or_error.is_error())
|
||||
return false;
|
||||
desc.bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
Bitmap& bitmap = *desc.bitmap;
|
||||
const u8* image_base = context.data + desc.offset + sizeof(info);
|
||||
const BMP_ARGB* data_base = (const BMP_ARGB*)image_base;
|
||||
|
|
|
@ -1063,8 +1063,11 @@ static void ycbcr_to_rgb(const JPGLoadingContext& context, Vector<Macroblock>& m
|
|||
|
||||
static bool compose_bitmap(JPGLoadingContext& context, const Vector<Macroblock>& macroblocks)
|
||||
{
|
||||
context.bitmap = Bitmap::try_create(BitmapFormat::BGRx8888, { context.frame.width, context.frame.height });
|
||||
if (!context.bitmap)
|
||||
auto bitmap_or_error = Bitmap::try_create(BitmapFormat::BGRx8888, { context.frame.width, context.frame.height });
|
||||
if (bitmap_or_error.is_error())
|
||||
return false;
|
||||
context.bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
if (bitmap_or_error.is_error())
|
||||
return false;
|
||||
|
||||
for (u32 y = context.frame.height - 1; y < context.frame.height; y--) {
|
||||
|
|
|
@ -47,7 +47,7 @@ struct [[gnu::packed]] PaletteEntry {
|
|||
u8 r;
|
||||
u8 g;
|
||||
u8 b;
|
||||
//u8 a;
|
||||
// u8 a;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -603,13 +603,13 @@ static bool decode_png_bitmap_simple(PNGLoadingContext& context)
|
|||
}
|
||||
}
|
||||
|
||||
context.bitmap = Bitmap::try_create(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height });
|
||||
|
||||
if (!context.bitmap) {
|
||||
auto bitmap_or_error = Bitmap::try_create(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height });
|
||||
if (bitmap_or_error.is_error()) {
|
||||
context.state = PNGLoadingContext::State::Error;
|
||||
return false;
|
||||
}
|
||||
|
||||
context.bitmap = bitmap_or_error.release_value();
|
||||
return unfilter(context);
|
||||
}
|
||||
|
||||
|
@ -705,7 +705,11 @@ static bool decode_adam7_pass(PNGLoadingContext& context, Streamer& streamer, in
|
|||
}
|
||||
}
|
||||
|
||||
subimage_context.bitmap = Bitmap::try_create(context.bitmap->format(), { subimage_context.width, subimage_context.height });
|
||||
auto bitmap_or_error = Bitmap::try_create(context.bitmap->format(), { subimage_context.width, subimage_context.height });
|
||||
if (bitmap_or_error.is_error())
|
||||
return false;
|
||||
|
||||
subimage_context.bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
if (!unfilter(subimage_context)) {
|
||||
subimage_context.bitmap = nullptr;
|
||||
return false;
|
||||
|
@ -723,9 +727,10 @@ static bool decode_adam7_pass(PNGLoadingContext& context, Streamer& streamer, in
|
|||
static bool decode_png_adam7(PNGLoadingContext& context)
|
||||
{
|
||||
Streamer streamer(context.decompression_buffer->data(), context.decompression_buffer->size());
|
||||
context.bitmap = Bitmap::try_create(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height });
|
||||
if (!context.bitmap)
|
||||
auto bitmap_or_error = Bitmap::try_create(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height });
|
||||
if (bitmap_or_error.is_error())
|
||||
return false;
|
||||
context.bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
for (int pass = 1; pass <= 7; ++pass) {
|
||||
if (!decode_adam7_pass(context, streamer, pass))
|
||||
|
|
|
@ -178,11 +178,12 @@ static bool read_max_val(TContext& context, Streamer& streamer)
|
|||
template<typename TContext>
|
||||
static bool create_bitmap(TContext& context)
|
||||
{
|
||||
context.bitmap = Bitmap::try_create(BitmapFormat::BGRx8888, { context.width, context.height });
|
||||
if (!context.bitmap) {
|
||||
auto bitmap_or_error = Bitmap::try_create(BitmapFormat::BGRx8888, { context.width, context.height });
|
||||
if (bitmap_or_error.is_error()) {
|
||||
context.state = TContext::State::Error;
|
||||
return false;
|
||||
}
|
||||
context.bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -207,9 +207,10 @@ void Rasterizer::draw_path(Gfx::Path& path)
|
|||
|
||||
RefPtr<Gfx::Bitmap> Rasterizer::accumulate()
|
||||
{
|
||||
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, m_size);
|
||||
if (!bitmap)
|
||||
auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, m_size);
|
||||
if (bitmap_or_error.is_error())
|
||||
return {};
|
||||
auto bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
Color base_color = Color::from_rgb(0xffffff);
|
||||
for (int y = 0; y < m_size.height(); y++) {
|
||||
float accumulator = 0.0;
|
||||
|
|
|
@ -80,8 +80,12 @@ bool HTMLCanvasElement::create_bitmap()
|
|||
m_bitmap = nullptr;
|
||||
return false;
|
||||
}
|
||||
if (!m_bitmap || m_bitmap->size() != size)
|
||||
m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, size);
|
||||
if (!m_bitmap || m_bitmap->size() != size) {
|
||||
auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, size);
|
||||
if (bitmap_or_error.is_error())
|
||||
return false;
|
||||
m_bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
return m_bitmap;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,11 +30,12 @@ void paint_box_shadow(PaintContext& context, Gfx::IntRect const& content_rect, B
|
|||
if (bitmap_rect.is_empty())
|
||||
return;
|
||||
|
||||
auto new_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, bitmap_rect.size());
|
||||
if (!new_bitmap) {
|
||||
dbgln("Unable to allocate temporary bitmap for box-shadow rendering");
|
||||
auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, bitmap_rect.size());
|
||||
if (bitmap_or_error.is_error()) {
|
||||
dbgln("Unable to allocate temporary bitmap for box-shadow rendering: {}", bitmap_or_error.error());
|
||||
return;
|
||||
}
|
||||
auto new_bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
Gfx::Painter painter(*new_bitmap);
|
||||
painter.fill_rect({ { 2 * box_shadow_data.blur_radius, 2 * box_shadow_data.blur_radius }, content_rect.size() }, box_shadow_data.color);
|
||||
|
|
|
@ -117,14 +117,14 @@ void StackingContext::paint(PaintContext& context)
|
|||
return;
|
||||
|
||||
if (opacity < 1.0f) {
|
||||
auto bitmap = context.painter().target();
|
||||
auto new_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, bitmap->size());
|
||||
if (!new_bitmap)
|
||||
auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, context.painter().target()->size());
|
||||
if (bitmap_or_error.is_error())
|
||||
return;
|
||||
Gfx::Painter painter(*new_bitmap);
|
||||
auto bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
Gfx::Painter painter(bitmap);
|
||||
PaintContext paint_context(painter, context.palette(), context.scroll_offset());
|
||||
paint_internal(paint_context);
|
||||
context.painter().blit(Gfx::IntPoint(m_box.absolute_position()), *new_bitmap, Gfx::IntRect(m_box.absolute_rect()), opacity);
|
||||
context.painter().blit(Gfx::IntPoint(m_box.absolute_position()), bitmap, Gfx::IntRect(m_box.absolute_rect()), opacity);
|
||||
} else {
|
||||
paint_internal(context);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue