From 449d56ef746cde5563cd42d33b1cff0b79d2e10c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 29 Jan 2021 22:29:27 +0100 Subject: LibGfx: Don't use Gfx::Painter in GIF decoder Painter currently tries to load fonts, which won't work if we're in a tightly pledged process. It was only used to fill a rect with transparent pixels, so just do that manually instead. --- Userland/Libraries/LibGfx/GIFLoader.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'Userland/Libraries/LibGfx/GIFLoader.cpp') diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp index 76d2b0adcd..12d9eebba5 100644 --- a/Userland/Libraries/LibGfx/GIFLoader.cpp +++ b/Userland/Libraries/LibGfx/GIFLoader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2021, Andreas Kling * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,10 +29,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -289,6 +289,22 @@ static void copy_frame_buffer(Bitmap& dest, const Bitmap& src) memcpy(dest.scanline(0), src.scanline(0), dest.size_in_bytes()); } +static void clear_rect(Bitmap& bitmap, const IntRect& rect, Color color) +{ + if (rect.is_empty()) + return; + + ASSERT(bitmap.rect().contains(rect)); + + RGBA32* dst = bitmap.scanline(rect.top()) + rect.left(); + const size_t dst_skip = bitmap.pitch() / sizeof(RGBA32); + + for (int i = rect.height() - 1; i >= 0; --i) { + fast_u32_fill(dst, color.value(), rect.width()); + dst += dst_skip; + } +} + static bool decode_frame(GIFLoadingContext& context, size_t frame_index) { if (frame_index >= context.images.size()) { @@ -333,8 +349,7 @@ static bool decode_frame(GIFLoadingContext& context, size_t frame_index) // background color of the GIF itself. It appears that all major browsers and most other // GIF decoders adhere to the former interpretation, therefore we will do the same by // clearing the entire frame buffer to transparent. - Painter painter(*context.frame_buffer); - painter.clear_rect(context.images.at(i - 1).rect(), Color::Transparent); + clear_rect(*context.frame_buffer, context.images.at(i - 1).rect(), Color::Transparent); } else if (i > 0 && previous_image_disposal_method == ImageDescriptor::DisposalMethod::RestorePrevious) { // Previous frame indicated that once disposed, it should be restored to *its* previous // underlying image contents, therefore we restore the saved previous frame buffer. -- cgit v1.2.3