summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas CHOLLET <lucas.chollet@free.fr>2023-06-02 11:54:23 -0400
committerAndreas Kling <kling@serenityos.org>2023-06-02 20:07:27 +0200
commit9e6d91032eceb987e32ceb4860e7a34023ac1807 (patch)
treeb39175d1bd84c7bcca90415a377eabc566f80352
parentb5e9b9a939cb4f54c551143ccbbea44be0cd12c5 (diff)
downloadserenity-9e6d91032eceb987e32ceb4860e7a34023ac1807.zip
LibGfx/JPEG: Use `Error` to propagate errors
This patch removes a long time remnant of the pre-`AK::Error` era.
-rw-r--r--Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp25
1 files changed, 12 insertions, 13 deletions
diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp
index 6ead2fcf53..e95862627d 100644
--- a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp
+++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp
@@ -18,8 +18,6 @@
#include <AK/Vector.h>
#include <LibGfx/ImageFormats/JPEGLoader.h>
-#define JPEG_INVALID 0X0000
-
// These names are defined in B.1.1.3 - Marker assignments
#define JPEG_APPN0 0XFFE0
@@ -807,18 +805,20 @@ static inline bool is_supported_marker(Marker const marker)
static inline ErrorOr<Marker> read_marker_at_cursor(Stream& stream)
{
u16 marker = TRY(stream.read_value<BigEndian<u16>>());
+
+ if (marker == 0xFFFF) {
+ u8 next { 0xFF };
+
+ while (next == 0xFF)
+ next = TRY(stream.read_value<u8>());
+
+ marker = 0xFF00 | next;
+ }
+
if (is_supported_marker(marker))
return marker;
- if (marker != 0xFFFF)
- return JPEG_INVALID;
- u8 next;
- do {
- next = TRY(stream.read_value<u8>());
- if (next == 0x00)
- return JPEG_INVALID;
- } while (next == 0xFF);
- marker = 0xFF00 | (u16)next;
- return is_supported_marker(marker) ? marker : JPEG_INVALID;
+
+ return Error::from_string_literal("Reached an unsupported marker");
}
static ErrorOr<u16> read_effective_chunk_size(Stream& stream)
@@ -1765,7 +1765,6 @@ static ErrorOr<void> parse_header(Stream& stream, JPEGLoadingContext& context)
context.frame.type = static_cast<StartOfFrame::FrameType>(marker & 0xF);
switch (marker) {
- case JPEG_INVALID:
case JPEG_RST0:
case JPEG_RST1:
case JPEG_RST2: