Coverage Report

Created: 2026-11-13 08:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibGfx/ImageFormats/PGMLoader.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2020, Hüseyin ASLITÜRK <asliturk@hotmail.com>
3
 * Copyright (c) 2022, the SerenityOS developers.
4
 *
5
 * SPDX-License-Identifier: BSD-2-Clause
6
 */
7
8
#include "PGMLoader.h"
9
#include "PortableImageLoaderCommon.h"
10
11
namespace Gfx {
12
13
ErrorOr<void> read_image_data(PGMLoadingContext& context)
14
345
{
15
345
    TRY(create_bitmap(context));
16
17
339
    auto& stream = *context.stream;
18
339
    auto const context_size = context.width * context.height;
19
20
339
    if (context.type == PGMLoadingContext::Type::ASCII) {
21
325k
        for (u64 i = 0; i < context_size; ++i) {
22
325k
            auto value = TRY(read_number(stream));
23
24
325k
            TRY(read_whitespace(context));
25
26
325k
            Color color { static_cast<u8>(value), static_cast<u8>(value), static_cast<u8>(value) };
27
325k
            if (context.format_details.max_val < 255)
28
324k
                color = adjust_color(context.format_details.max_val, color);
29
30
325k
            context.bitmap->set_pixel(i % context.width, i / context.width, color);
31
325k
        }
32
223
    } else if (context.type == PGMLoadingContext::Type::RAWBITS) {
33
1.70M
        for (u64 i = 0; i < context_size; ++i) {
34
1.70M
            auto const pixel = TRY(stream.read_value<u8>());
35
1.70M
            context.bitmap->set_pixel(i % context.width, i / context.width, { pixel, pixel, pixel });
36
1.70M
        }
37
116
    }
38
39
339
    return {};
40
339
}
41
}