1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:07:47 +00:00

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`.
This commit is contained in:
Lucas CHOLLET 2023-03-12 20:08:29 -04:00 committed by Andreas Kling
parent b9574c180e
commit 7cafd7d177
8 changed files with 88 additions and 79 deletions

View file

@ -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 };
}
}