| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-07-27 01:12:53 +02:00
										 |  |  |  * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-01 21:32:54 +02:00
										 |  |  | #include <AK/ByteBuffer.h>
 | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | #include <AK/OwnPtr.h>
 | 
					
						
							|  |  |  | #include <AK/RefCounted.h>
 | 
					
						
							| 
									
										
										
										
											2020-05-03 17:12:54 +01:00
										 |  |  | #include <AK/RefPtr.h>
 | 
					
						
							| 
									
										
										
										
											2021-01-21 20:55:37 +01:00
										 |  |  | #include <LibGfx/Bitmap.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-06 12:04:00 +01:00
										 |  |  | #include <LibGfx/Size.h>
 | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 11:56:38 +01:00
										 |  |  | namespace Gfx { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Bitmap; | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-25 00:19:06 +01:00
										 |  |  | static constexpr size_t maximum_width_for_decoded_images = 16384; | 
					
						
							|  |  |  | static constexpr size_t maximum_height_for_decoded_images = 16384; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 17:12:54 +01:00
										 |  |  | struct ImageFrameDescriptor { | 
					
						
							|  |  |  |     RefPtr<Bitmap> image; | 
					
						
							|  |  |  |     int duration { 0 }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-19 19:56:49 +02:00
										 |  |  | class ImageDecoderPlugin { | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2022-03-14 13:26:37 -06:00
										 |  |  |     virtual ~ImageDecoderPlugin() = default; | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     virtual IntSize size() = 0; | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-08 23:52:52 -04:00
										 |  |  |     virtual ErrorOr<void> initialize() { return {}; } | 
					
						
							| 
									
										
										
										
											2020-04-25 13:51:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 17:12:54 +01:00
										 |  |  |     virtual bool is_animated() = 0; | 
					
						
							|  |  |  |     virtual size_t loop_count() = 0; | 
					
						
							|  |  |  |     virtual size_t frame_count() = 0; | 
					
						
							| 
									
										
										
										
											2023-04-07 20:41:22 -06:00
										 |  |  |     virtual size_t first_animated_frame_index() = 0; | 
					
						
							| 
									
										
										
										
											2023-07-02 22:20:06 +01:00
										 |  |  |     virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) = 0; | 
					
						
							| 
									
										
										
										
											2023-01-26 07:23:59 -05:00
										 |  |  |     virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() = 0; | 
					
						
							| 
									
										
										
										
											2020-05-03 17:12:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2022-03-14 13:26:37 -06:00
										 |  |  |     ImageDecoderPlugin() = default; | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-19 19:56:49 +02:00
										 |  |  | class ImageDecoder : public RefCounted<ImageDecoder> { | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-01-20 03:27:10 +02:00
										 |  |  |     static RefPtr<ImageDecoder> try_create_for_raw_bytes(ReadonlyBytes, Optional<DeprecatedString> mime_type = {}); | 
					
						
							| 
									
										
										
										
											2022-03-14 13:26:37 -06:00
										 |  |  |     ~ImageDecoder() = default; | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-27 01:12:53 +02:00
										 |  |  |     IntSize size() const { return m_plugin->size(); } | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  |     int width() const { return size().width(); } | 
					
						
							|  |  |  |     int height() const { return size().height(); } | 
					
						
							| 
									
										
										
										
											2021-07-27 01:12:53 +02:00
										 |  |  |     bool is_animated() const { return m_plugin->is_animated(); } | 
					
						
							|  |  |  |     size_t loop_count() const { return m_plugin->loop_count(); } | 
					
						
							|  |  |  |     size_t frame_count() const { return m_plugin->frame_count(); } | 
					
						
							| 
									
										
										
										
											2023-04-07 20:41:22 -06:00
										 |  |  |     size_t first_animated_frame_index() const { return m_plugin->first_animated_frame_index(); } | 
					
						
							| 
									
										
										
										
											2023-07-02 22:20:06 +01:00
										 |  |  |     ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) const { return m_plugin->frame(index, ideal_size); } | 
					
						
							| 
									
										
										
										
											2023-01-26 07:23:59 -05:00
										 |  |  |     ErrorOr<Optional<ReadonlyBytes>> icc_data() const { return m_plugin->icc_data(); } | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2021-07-27 01:12:53 +02:00
										 |  |  |     explicit ImageDecoder(NonnullOwnPtr<ImageDecoderPlugin>); | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-27 01:12:53 +02:00
										 |  |  |     NonnullOwnPtr<ImageDecoderPlugin> mutable m_plugin; | 
					
						
							| 
									
										
										
										
											2019-10-15 21:48:08 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-02-06 11:56:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |