/src/serenity/Userland/Libraries/LibWeb/HTML/AnimatedBitmapDecodedImageData.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2023, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibGfx/Bitmap.h> |
8 | | #include <LibJS/Heap/Heap.h> |
9 | | #include <LibJS/Runtime/Realm.h> |
10 | | #include <LibWeb/HTML/AnimatedBitmapDecodedImageData.h> |
11 | | |
12 | | namespace Web::HTML { |
13 | | |
14 | | JS_DEFINE_ALLOCATOR(AnimatedBitmapDecodedImageData); |
15 | | |
16 | | ErrorOr<JS::NonnullGCPtr<AnimatedBitmapDecodedImageData>> AnimatedBitmapDecodedImageData::create(JS::Realm& realm, Vector<Frame>&& frames, size_t loop_count, bool animated) |
17 | 0 | { |
18 | 0 | return realm.heap().allocate<AnimatedBitmapDecodedImageData>(realm, move(frames), loop_count, animated); |
19 | 0 | } |
20 | | |
21 | | AnimatedBitmapDecodedImageData::AnimatedBitmapDecodedImageData(Vector<Frame>&& frames, size_t loop_count, bool animated) |
22 | 0 | : m_frames(move(frames)) |
23 | 0 | , m_loop_count(loop_count) |
24 | 0 | , m_animated(animated) |
25 | 0 | { |
26 | 0 | } |
27 | | |
28 | 0 | AnimatedBitmapDecodedImageData::~AnimatedBitmapDecodedImageData() = default; |
29 | | |
30 | | RefPtr<Gfx::ImmutableBitmap> AnimatedBitmapDecodedImageData::bitmap(size_t frame_index, Gfx::IntSize) const |
31 | 0 | { |
32 | 0 | if (frame_index >= m_frames.size()) |
33 | 0 | return nullptr; |
34 | 0 | return m_frames[frame_index].bitmap; |
35 | 0 | } |
36 | | |
37 | | int AnimatedBitmapDecodedImageData::frame_duration(size_t frame_index) const |
38 | 0 | { |
39 | 0 | if (frame_index >= m_frames.size()) |
40 | 0 | return 0; |
41 | 0 | return m_frames[frame_index].duration; |
42 | 0 | } |
43 | | |
44 | | Optional<CSSPixels> AnimatedBitmapDecodedImageData::intrinsic_width() const |
45 | 0 | { |
46 | 0 | return m_frames.first().bitmap->width(); |
47 | 0 | } |
48 | | |
49 | | Optional<CSSPixels> AnimatedBitmapDecodedImageData::intrinsic_height() const |
50 | 0 | { |
51 | 0 | return m_frames.first().bitmap->height(); |
52 | 0 | } |
53 | | |
54 | | Optional<CSSPixelFraction> AnimatedBitmapDecodedImageData::intrinsic_aspect_ratio() const |
55 | 0 | { |
56 | 0 | return CSSPixels(m_frames.first().bitmap->width()) / CSSPixels(m_frames.first().bitmap->height()); |
57 | 0 | } |
58 | | |
59 | | } |