| 
									
										
										
										
											2023-05-20 16:11:36 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2023, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2023-05-20 16:11:36 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | #include <LibGC/Heap.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-20 16:11:36 +02:00
										 |  |  | #include <LibGfx/Bitmap.h>
 | 
					
						
							| 
									
										
										
										
											2023-12-12 20:07:19 +01:00
										 |  |  | #include <LibJS/Runtime/Realm.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-20 16:11:36 +02:00
										 |  |  | #include <LibWeb/HTML/AnimatedBitmapDecodedImageData.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::HTML { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | GC_DEFINE_ALLOCATOR(AnimatedBitmapDecodedImageData); | 
					
						
							| 
									
										
										
										
											2023-12-12 20:07:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | ErrorOr<GC::Ref<AnimatedBitmapDecodedImageData>> AnimatedBitmapDecodedImageData::create(JS::Realm& realm, Vector<Frame>&& frames, size_t loop_count, bool animated) | 
					
						
							| 
									
										
										
										
											2023-05-20 16:11:36 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-11-14 05:50:17 +13:00
										 |  |  |     return realm.create<AnimatedBitmapDecodedImageData>(move(frames), loop_count, animated); | 
					
						
							| 
									
										
										
										
											2023-05-20 16:11:36 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AnimatedBitmapDecodedImageData::AnimatedBitmapDecodedImageData(Vector<Frame>&& frames, size_t loop_count, bool animated) | 
					
						
							|  |  |  |     : m_frames(move(frames)) | 
					
						
							|  |  |  |     , m_loop_count(loop_count) | 
					
						
							|  |  |  |     , m_animated(animated) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AnimatedBitmapDecodedImageData::~AnimatedBitmapDecodedImageData() = default; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-24 14:45:45 +01:00
										 |  |  | RefPtr<Gfx::ImmutableBitmap> AnimatedBitmapDecodedImageData::bitmap(size_t frame_index, Gfx::IntSize) const | 
					
						
							| 
									
										
										
										
											2023-05-20 16:11:36 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (frame_index >= m_frames.size()) | 
					
						
							|  |  |  |         return nullptr; | 
					
						
							|  |  |  |     return m_frames[frame_index].bitmap; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int AnimatedBitmapDecodedImageData::frame_duration(size_t frame_index) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (frame_index >= m_frames.size()) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     return m_frames[frame_index].duration; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-20 16:27:31 +02:00
										 |  |  | Optional<CSSPixels> AnimatedBitmapDecodedImageData::intrinsic_width() const | 
					
						
							| 
									
										
										
										
											2023-05-20 16:11:36 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_frames.first().bitmap->width(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-20 16:27:31 +02:00
										 |  |  | Optional<CSSPixels> AnimatedBitmapDecodedImageData::intrinsic_height() const | 
					
						
							| 
									
										
										
										
											2023-05-20 16:11:36 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_frames.first().bitmap->height(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 17:33:58 -05:00
										 |  |  | Optional<CSSPixelFraction> AnimatedBitmapDecodedImageData::intrinsic_aspect_ratio() const | 
					
						
							| 
									
										
										
										
											2023-05-20 16:27:31 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-09-03 17:33:58 -05:00
										 |  |  |     return CSSPixels(m_frames.first().bitmap->width()) / CSSPixels(m_frames.first().bitmap->height()); | 
					
						
							| 
									
										
										
										
											2023-05-20 16:27:31 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-20 16:11:36 +02:00
										 |  |  | } |