/src/serenity/Userland/Libraries/LibGfx/ImageFormats/JPEG2000Span2D.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2025, Nico Weber <thakis@chromium.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/Span.h> |
10 | | #include <LibGfx/Size.h> |
11 | | |
12 | | namespace Gfx::JPEG2000 { |
13 | | |
14 | | template<class T> |
15 | | struct Span2D { |
16 | | Span<T> data; |
17 | | IntSize size; |
18 | | int pitch { 0 }; |
19 | | |
20 | 3.22M | Span2D() = default; Gfx::JPEG2000::Span2D<float>::Span2D() Line | Count | Source | 20 | 2.27M | Span2D() = default; |
Gfx::JPEG2000::Span2D<float const>::Span2D() Line | Count | Source | 20 | 953k | Span2D() = default; |
|
21 | | |
22 | | Span2D(Span<T> data, IntSize size, int pitch) |
23 | 1.15M | : data(data) |
24 | 1.15M | , size(size) |
25 | 1.15M | , pitch(pitch) |
26 | 1.15M | { |
27 | 1.15M | VERIFY(size.is_empty() || static_cast<int>(data.size()) >= (size.height() - 1) * pitch + size.width()); |
28 | 1.15M | } |
29 | | |
30 | | [[nodiscard]] ALWAYS_INLINE constexpr Span<T> scanline(int y) const |
31 | 76.6M | { |
32 | 76.6M | return data.slice(y * pitch, size.width()); |
33 | 76.6M | } |
34 | | |
35 | | [[nodiscard]] ALWAYS_INLINE constexpr T const& operator[](size_t index) const |
36 | | { |
37 | | return data[index]; |
38 | | } |
39 | | |
40 | | [[nodiscard]] ALWAYS_INLINE constexpr int width() const |
41 | 819k | { |
42 | 819k | return size.width(); |
43 | 819k | } |
44 | | |
45 | | [[nodiscard]] ALWAYS_INLINE constexpr int height() const |
46 | 819k | { |
47 | 819k | return size.height(); |
48 | 819k | } |
49 | | }; |
50 | | |
51 | | } |