summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/ImageFormats/PPMLoader.cpp
diff options
context:
space:
mode:
authorLucas CHOLLET <lucas.chollet@free.fr>2023-03-12 15:02:03 -0400
committerAndreas Kling <kling@serenityos.org>2023-03-24 10:56:58 +0100
commit9052a6febf4217d60bbcddda0277ba080b3ab8b2 (patch)
treeea3fb2d31800faa3a573140f41e11017af9f4df4 /Userland/Libraries/LibGfx/ImageFormats/PPMLoader.cpp
parent387894cdf21103d4c89a93be2e9dbade2721d25e (diff)
downloadserenity-9052a6febf4217d60bbcddda0277ba080b3ab8b2.zip
LibGfx/PortableFormat: Simplify `read_number` signature
The function signature goes from: `bool read_number(Streamer& streamer, TValue* value)` to `ErrorOr<u16> read_number(Streamer& streamer)` It allows us to, on one hand use `ErrorOr` for error propagation, removing an out parameter in the meantime, and on the other hand remove the useless template.
Diffstat (limited to 'Userland/Libraries/LibGfx/ImageFormats/PPMLoader.cpp')
-rw-r--r--Userland/Libraries/LibGfx/ImageFormats/PPMLoader.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/Userland/Libraries/LibGfx/ImageFormats/PPMLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/PPMLoader.cpp
index c662e76b87..c8859350af 100644
--- a/Userland/Libraries/LibGfx/ImageFormats/PPMLoader.cpp
+++ b/Userland/Libraries/LibGfx/ImageFormats/PPMLoader.cpp
@@ -22,30 +22,29 @@ bool read_image_data(PPMLoadingContext& context, Streamer& streamer)
color_data.ensure_capacity(context.width * context.height);
if (context.type == PPMLoadingContext::Type::ASCII) {
- u16 red;
- u16 green;
- u16 blue;
-
while (true) {
- if (!read_number(streamer, &red))
+ auto const red_or_error = read_number(streamer);
+ if (red_or_error.is_error())
break;
if (!read_whitespace(context, streamer))
break;
- if (!read_number(streamer, &green))
+ auto const green_or_error = read_number(streamer);
+ if (green_or_error.is_error())
break;
if (!read_whitespace(context, streamer))
break;
- if (!read_number(streamer, &blue))
+ auto const blue_or_error = read_number(streamer);
+ if (blue_or_error.is_error())
break;
if (!read_whitespace(context, streamer))
break;
- Color color { (u8)red, (u8)green, (u8)blue };
+ Color color { (u8)red_or_error.value(), (u8)green_or_error.value(), (u8)blue_or_error.value() };
if (context.format_details.max_val < 255)
color = adjust_color(context.format_details.max_val, color);
color_data.append(color);