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/CMYKBitmap.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2024, Nico Weber <thakis@chromium.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/ByteBuffer.h>
10
#include <AK/Format.h>
11
#include <AK/NonnullRefPtr.h>
12
#include <AK/RefCounted.h>
13
#include <LibGfx/Bitmap.h>
14
#include <LibGfx/Size.h>
15
16
namespace Gfx {
17
18
struct CMYK {
19
    u8 c;
20
    u8 m;
21
    u8 y;
22
    u8 k;
23
24
    int operator<=>(CMYK const&) const = default;
25
};
26
27
class CMYKBitmap : public RefCounted<CMYKBitmap> {
28
public:
29
    static ErrorOr<NonnullRefPtr<CMYKBitmap>> create_with_size(IntSize const& size);
30
31
0
    IntSize const& size() const { return m_size; }
32
33
    [[nodiscard]] CMYK* scanline(int y);
34
    [[nodiscard]] CMYK const* scanline(int y) const;
35
36
    [[nodiscard]] CMYK* begin();
37
    [[nodiscard]] CMYK* end();
38
0
    [[nodiscard]] ReadonlyBytes data() const { return m_data; }
39
0
    [[nodiscard]] size_t data_size() const { return m_data.size(); }
40
41
    ErrorOr<RefPtr<Bitmap>> to_low_quality_rgb() const;
42
43
private:
44
    CMYKBitmap(IntSize const& size, ByteBuffer data)
45
243
        : m_size(size)
46
243
        , m_data(move(data))
47
243
    {
48
243
    }
49
50
    IntSize m_size;
51
    ByteBuffer m_data;
52
53
    mutable RefPtr<Bitmap> m_rgb_bitmap;
54
};
55
56
inline CMYK* CMYKBitmap::scanline(int y)
57
15.1M
{
58
15.1M
    VERIFY(y >= 0 && y < m_size.height());
59
15.1M
    return reinterpret_cast<CMYK*>(m_data.data() + y * m_size.width() * sizeof(CMYK));
60
15.1M
}
61
62
inline CMYK const* CMYKBitmap::scanline(int y) const
63
15.2M
{
64
15.2M
    VERIFY(y >= 0 && y < m_size.height());
65
15.2M
    return reinterpret_cast<CMYK const*>(m_data.data() + y * m_size.width() * sizeof(CMYK));
66
15.2M
}
67
68
inline CMYK* CMYKBitmap::begin()
69
129
{
70
129
    return reinterpret_cast<CMYK*>(m_data.data());
71
129
}
72
73
inline CMYK* CMYKBitmap::end()
74
0
{
75
0
    return reinterpret_cast<CMYK*>(m_data.data() + data_size());
76
0
}
77
78
}
79
80
namespace AK {
81
82
template<>
83
struct Formatter<Gfx::CMYK> : Formatter<FormatString> {
84
    ErrorOr<void> format(FormatBuilder& builder, Gfx::CMYK const& value)
85
0
    {
86
0
        return Formatter<FormatString>::format(builder, "{:#02x}{:02x}{:02x}{:02x}"sv, value.c, value.m, value.y, value.k);
87
0
    }
88
};
89
90
}