summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/ImageFormats/PGMLoader.cpp
diff options
context:
space:
mode:
authorLucas CHOLLET <lucas.chollet@free.fr>2023-03-12 20:08:29 -0400
committerAndreas Kling <kling@serenityos.org>2023-03-24 10:56:58 +0100
commit7cafd7d177fa1aa009a12447f5e6d66b8c4d90ac (patch)
tree779792ff364048fc976c1363419372bd336740c0 /Userland/Libraries/LibGfx/ImageFormats/PGMLoader.cpp
parentb9574c180e9d3d896a43feaf764f3e577db8132a (diff)
downloadserenity-7cafd7d177fa1aa009a12447f5e6d66b8c4d90ac.zip
LibGfx/PortableFormat: Port to Stream
Each one of `[PBM, PGM, PPM]Loader` used yet another stream-like relic. This patch ports all of them to `AK::Stream`.
Diffstat (limited to 'Userland/Libraries/LibGfx/ImageFormats/PGMLoader.cpp')
-rw-r--r--Userland/Libraries/LibGfx/ImageFormats/PGMLoader.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/Userland/Libraries/LibGfx/ImageFormats/PGMLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/PGMLoader.cpp
index 432ecfe39f..18a3d7fd74 100644
--- a/Userland/Libraries/LibGfx/ImageFormats/PGMLoader.cpp
+++ b/Userland/Libraries/LibGfx/ImageFormats/PGMLoader.cpp
@@ -5,11 +5,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <AK/Endian.h>
-#include <LibGfx/ImageFormats/PGMLoader.h>
-#include <LibGfx/ImageFormats/PortableImageLoaderCommon.h>
-#include <LibGfx/Streamer.h>
-#include <string.h>
+#include "PGMLoader.h"
+#include "PortableImageLoaderCommon.h"
namespace Gfx {
@@ -28,8 +25,9 @@ static void set_adjusted_pixels(PGMLoadingContext& context, Vector<Gfx::Color> c
}
}
-bool read_image_data(PGMLoadingContext& context, Streamer& streamer)
+bool read_image_data(PGMLoadingContext& context)
{
+ auto& stream = *context.stream;
Vector<Gfx::Color> color_data;
auto const context_size = context.width * context.height;
@@ -37,21 +35,22 @@ bool read_image_data(PGMLoadingContext& context, Streamer& streamer)
if (context.type == PGMLoadingContext::Type::ASCII) {
for (u64 i = 0; i < context_size; ++i) {
- auto number_or_error = read_number(streamer);
+ auto number_or_error = read_number(stream);
if (number_or_error.is_error())
return false;
auto value = number_or_error.value();
- if (read_whitespace(context, streamer).is_error())
+ if (read_whitespace(context).is_error())
return false;
color_data[i] = { (u8)value, (u8)value, (u8)value };
}
} else if (context.type == PGMLoadingContext::Type::RAWBITS) {
for (u64 i = 0; i < context_size; ++i) {
- u8 pixel;
- if (!streamer.read(pixel))
+ auto pixel_or_error = stream.read_value<u8>();
+ if (pixel_or_error.is_error())
return false;
+ auto const pixel = pixel_or_error.value();
color_data[i] = { pixel, pixel, pixel };
}
}