summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/GIFLoader.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-29 22:29:27 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-29 22:30:12 +0100
commit449d56ef746cde5563cd42d33b1cff0b79d2e10c (patch)
tree2db27c0ae864c6ec54e51bc3d5661db7acc7711e /Userland/Libraries/LibGfx/GIFLoader.cpp
parenta8c823f242a49a5506117f43ab98d3c2bf2e4e76 (diff)
downloadserenity-449d56ef746cde5563cd42d33b1cff0b79d2e10c.zip
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.
Diffstat (limited to 'Userland/Libraries/LibGfx/GIFLoader.cpp')
-rw-r--r--Userland/Libraries/LibGfx/GIFLoader.cpp23
1 files changed, 19 insertions, 4 deletions
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 <kling@serenityos.org>
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,10 +29,10 @@
#include <AK/Debug.h>
#include <AK/LexicalPath.h>
#include <AK/MappedFile.h>
+#include <AK/Memory.h>
#include <AK/MemoryStream.h>
#include <AK/NonnullOwnPtrVector.h>
#include <LibGfx/GIFLoader.h>
-#include <LibGfx/Painter.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
@@ -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.