| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-01-29 22:29:27 +01: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
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  | #include <AK/Array.h>
 | 
					
						
							| 
									
										
										
										
											2021-01-16 13:43:08 +01:00
										 |  |  | #include <AK/Debug.h>
 | 
					
						
							| 
									
										
										
										
											2020-05-26 14:52:44 +03:00
										 |  |  | #include <AK/LexicalPath.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-15 01:06:32 +01:00
										 |  |  | #include <AK/MappedFile.h>
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:29:28 +02:00
										 |  |  | #include <AK/Math.h>
 | 
					
						
							| 
									
										
										
										
											2021-01-29 22:29:27 +01:00
										 |  |  | #include <AK/Memory.h>
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  | #include <AK/MemoryStream.h>
 | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | #include <AK/NonnullOwnPtrVector.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-06 12:04:00 +01:00
										 |  |  | #include <LibGfx/GIFLoader.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-08 12:05:14 +01:00
										 |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 11:56:38 +01:00
										 |  |  | namespace Gfx { | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-21 10:30:21 +01:00
										 |  |  | // Row strides and offsets for each interlace pass.
 | 
					
						
							|  |  |  | static const int INTERLACE_ROW_STRIDES[] = { 8, 8, 4, 2 }; | 
					
						
							|  |  |  | static const int INTERLACE_ROW_OFFSETS[] = { 0, 4, 2, 1 }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-28 07:01:52 +02:00
										 |  |  | struct GIFImageDescriptor { | 
					
						
							| 
									
										
										
										
											2020-08-20 19:41:29 +02:00
										 |  |  |     u16 x { 0 }; | 
					
						
							|  |  |  |     u16 y { 0 }; | 
					
						
							|  |  |  |     u16 width { 0 }; | 
					
						
							|  |  |  |     u16 height { 0 }; | 
					
						
							|  |  |  |     bool use_global_color_map { true }; | 
					
						
							| 
									
										
										
										
											2020-08-29 16:05:24 +01:00
										 |  |  |     bool interlaced { false }; | 
					
						
							| 
									
										
										
										
											2020-08-30 08:47:56 +01:00
										 |  |  |     Color color_map[256]; | 
					
						
							| 
									
										
										
										
											2020-08-20 19:41:29 +02:00
										 |  |  |     u8 lzw_min_code_size { 0 }; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     Vector<u8> lzw_encoded_bytes; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Fields from optional graphic control extension block
 | 
					
						
							|  |  |  |     enum DisposalMethod : u8 { | 
					
						
							|  |  |  |         None = 0, | 
					
						
							|  |  |  |         InPlace = 1, | 
					
						
							|  |  |  |         RestoreBackground = 2, | 
					
						
							|  |  |  |         RestorePrevious = 3, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     DisposalMethod disposal_method { None }; | 
					
						
							|  |  |  |     u8 transparency_index { 0 }; | 
					
						
							|  |  |  |     u16 duration { 0 }; | 
					
						
							|  |  |  |     bool transparent { false }; | 
					
						
							|  |  |  |     bool user_input { false }; | 
					
						
							| 
									
										
										
										
											2020-08-30 16:49:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const IntRect rect() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return { this->x, this->y, this->width, this->height }; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct LogicalScreen { | 
					
						
							|  |  |  |     u16 width; | 
					
						
							|  |  |  |     u16 height; | 
					
						
							| 
									
										
										
										
											2020-08-30 08:47:56 +01:00
										 |  |  |     Color color_map[256]; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct GIFLoadingContext { | 
					
						
							|  |  |  |     enum State { | 
					
						
							|  |  |  |         NotDecoded = 0, | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |         FrameDescriptorsLoaded, | 
					
						
							| 
									
										
										
										
											2020-08-29 17:48:17 +01:00
										 |  |  |         FrameComplete, | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  |     State state { NotDecoded }; | 
					
						
							| 
									
										
										
										
											2020-11-08 17:01:44 +00:00
										 |  |  |     enum ErrorState { | 
					
						
							|  |  |  |         NoError = 0, | 
					
						
							|  |  |  |         FailedToDecodeAllFrames, | 
					
						
							|  |  |  |         FailedToDecodeAnyFrame, | 
					
						
							|  |  |  |         FailedToLoadFrameDescriptors, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     ErrorState error_state { NoError }; | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |     const u8* data { nullptr }; | 
					
						
							|  |  |  |     size_t data_size { 0 }; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     LogicalScreen logical_screen {}; | 
					
						
							|  |  |  |     u8 background_color_index { 0 }; | 
					
						
							| 
									
										
										
										
											2021-05-28 07:01:52 +02:00
										 |  |  |     NonnullOwnPtrVector<GIFImageDescriptor> images {}; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     size_t loops { 1 }; | 
					
						
							| 
									
										
										
										
											2020-08-29 17:48:17 +01:00
										 |  |  |     RefPtr<Gfx::Bitmap> frame_buffer; | 
					
						
							|  |  |  |     size_t current_frame { 0 }; | 
					
						
							| 
									
										
										
										
											2020-08-31 13:22:38 +01:00
										 |  |  |     RefPtr<Gfx::Bitmap> prev_frame_buffer; | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-02-06 11:56:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-16 23:40:49 +02:00
										 |  |  | RefPtr<Gfx::Bitmap> load_gif(String const& path) | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-10 15:55:54 +01:00
										 |  |  |     auto file_or_error = MappedFile::map(path); | 
					
						
							|  |  |  |     if (file_or_error.is_error()) | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |         return nullptr; | 
					
						
							| 
									
										
										
										
											2021-09-07 21:13:29 +10:00
										 |  |  |     return load_gif_from_memory((u8 const*)file_or_error.value()->data(), file_or_error.value()->size(), LexicalPath::canonicalized_path(path)); | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 21:13:29 +10:00
										 |  |  | RefPtr<Gfx::Bitmap> load_gif_from_memory(u8 const* data, size_t length, String const& mmap_name) | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |     GIFImageDecoderPlugin gif_decoder(data, length); | 
					
						
							|  |  |  |     auto bitmap = gif_decoder.bitmap(); | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |     if (bitmap) | 
					
						
							| 
									
										
										
										
											2021-09-07 21:13:29 +10:00
										 |  |  |         bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded GIF: {}", bitmap->size(), mmap_name)); | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |     return bitmap; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | enum class GIFFormat { | 
					
						
							|  |  |  |     GIF87a, | 
					
						
							|  |  |  |     GIF89a, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  | static Optional<GIFFormat> decode_gif_header(InputMemoryStream& stream) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:45:41 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-21 10:30:21 +01:00
										 |  |  |     static const char valid_header_87[] = "GIF87a"; | 
					
						
							|  |  |  |     static const char valid_header_89[] = "GIF89a"; | 
					
						
							| 
									
										
										
										
											2020-04-25 13:45:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |     Array<u8, 6> header; | 
					
						
							|  |  |  |     stream >> header; | 
					
						
							| 
									
										
										
										
											2020-04-25 13:45:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |     if (stream.handle_any_error()) | 
					
						
							| 
									
										
										
										
											2020-04-25 17:03:40 +02:00
										 |  |  |         return {}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |     if (header.span() == ReadonlyBytes { valid_header_87, 6 }) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:45:41 +01:00
										 |  |  |         return GIFFormat::GIF87a; | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |     if (header.span() == ReadonlyBytes { valid_header_89, 6 }) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:45:41 +01:00
										 |  |  |         return GIFFormat::GIF89a; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return {}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  | class LZWDecoder { | 
					
						
							| 
									
										
										
										
											2020-05-03 19:06:14 +01:00
										 |  |  | private: | 
					
						
							|  |  |  |     static constexpr int max_code_size = 12; | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 19:06:14 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |     explicit LZWDecoder(const Vector<u8>& lzw_bytes, u8 min_code_size) | 
					
						
							|  |  |  |         : m_lzw_bytes(lzw_bytes) | 
					
						
							|  |  |  |         , m_code_size(min_code_size) | 
					
						
							|  |  |  |         , m_original_code_size(min_code_size) | 
					
						
							| 
									
										
										
										
											2021-07-17 18:29:28 +02:00
										 |  |  |         , m_table_capacity(AK::exp2<u32>(min_code_size)) | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         init_code_table(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     u16 add_control_code() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         const u16 control_code = m_code_table.size(); | 
					
						
							| 
									
										
										
										
											2020-05-03 19:06:14 +01:00
										 |  |  |         m_code_table.append(Vector<u8> {}); | 
					
						
							|  |  |  |         m_original_code_table.append(Vector<u8> {}); | 
					
						
							|  |  |  |         if (m_code_table.size() >= m_table_capacity && m_code_size < max_code_size) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |             ++m_code_size; | 
					
						
							|  |  |  |             ++m_original_code_size; | 
					
						
							| 
									
										
										
										
											2020-05-03 19:06:14 +01:00
										 |  |  |             m_table_capacity *= 2; | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         return control_code; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void reset() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_code_table.clear(); | 
					
						
							| 
									
										
										
										
											2021-06-12 13:24:45 +02:00
										 |  |  |         m_code_table.extend(m_original_code_table); | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |         m_code_size = m_original_code_size; | 
					
						
							| 
									
										
										
										
											2021-07-17 18:29:28 +02:00
										 |  |  |         m_table_capacity = AK::exp2<u32>(m_code_size); | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |         m_output.clear(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Optional<u16> next_code() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         size_t current_byte_index = m_current_bit_index / 8; | 
					
						
							|  |  |  |         if (current_byte_index >= m_lzw_bytes.size()) { | 
					
						
							|  |  |  |             return {}; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 14:40:30 +01:00
										 |  |  |         // Extract the code bits using a 32-bit mask to cover the possibility that if
 | 
					
						
							|  |  |  |         // the current code size > 9 bits then the code can span 3 bytes.
 | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |         u8 current_bit_offset = m_current_bit_index % 8; | 
					
						
							| 
									
										
										
										
											2020-05-03 19:06:14 +01:00
										 |  |  |         u32 mask = (u32)(m_table_capacity - 1) << current_bit_offset; | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 17:30:09 +01:00
										 |  |  |         // Make a padded copy of the final bytes in the data to ensure we don't read past the end.
 | 
					
						
							|  |  |  |         if (current_byte_index + sizeof(mask) > m_lzw_bytes.size()) { | 
					
						
							|  |  |  |             u8 padded_last_bytes[sizeof(mask)] = { 0 }; | 
					
						
							|  |  |  |             for (int i = 0; current_byte_index + i < m_lzw_bytes.size(); ++i) { | 
					
						
							|  |  |  |                 padded_last_bytes[i] = m_lzw_bytes[current_byte_index + i]; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             const u32* addr = (const u32*)&padded_last_bytes; | 
					
						
							|  |  |  |             m_current_code = (*addr & mask) >> current_bit_offset; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2021-05-24 08:23:35 -06:00
										 |  |  |             u32 tmp_word; | 
					
						
							|  |  |  |             memcpy(&tmp_word, &m_lzw_bytes.at(current_byte_index), sizeof(u32)); | 
					
						
							|  |  |  |             m_current_code = (tmp_word & mask) >> current_bit_offset; | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (m_current_code > m_code_table.size()) { | 
					
						
							| 
									
										
										
										
											2021-02-07 15:33:24 +03:30
										 |  |  |             dbgln_if(GIF_DEBUG, "Corrupted LZW stream, invalid code: {} at bit index {}, code table size: {}", | 
					
						
							| 
									
										
										
										
											2021-01-16 13:43:08 +01:00
										 |  |  |                 m_current_code, | 
					
						
							|  |  |  |                 m_current_bit_index, | 
					
						
							|  |  |  |                 m_code_table.size()); | 
					
						
							| 
									
										
										
										
											2020-12-28 12:31:09 +00:00
										 |  |  |             return {}; | 
					
						
							|  |  |  |         } else if (m_current_code == m_code_table.size() && m_output.is_empty()) { | 
					
						
							| 
									
										
										
										
											2021-02-07 15:33:24 +03:30
										 |  |  |             dbgln_if(GIF_DEBUG, "Corrupted LZW stream, valid new code but output buffer is empty: {} at bit index {}, code table size: {}", | 
					
						
							| 
									
										
										
										
											2021-01-16 13:43:08 +01:00
										 |  |  |                 m_current_code, | 
					
						
							|  |  |  |                 m_current_bit_index, | 
					
						
							|  |  |  |                 m_code_table.size()); | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |             return {}; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_current_bit_index += m_code_size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return m_current_code; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 19:06:14 +01:00
										 |  |  |     Vector<u8>& get_output() | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-02-23 20:42:32 +01:00
										 |  |  |         VERIFY(m_current_code <= m_code_table.size()); | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |         if (m_current_code < m_code_table.size()) { | 
					
						
							|  |  |  |             Vector<u8> new_entry = m_output; | 
					
						
							| 
									
										
										
										
											2020-05-03 19:06:14 +01:00
										 |  |  |             m_output = m_code_table.at(m_current_code); | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |             new_entry.append(m_output[0]); | 
					
						
							|  |  |  |             extend_code_table(new_entry); | 
					
						
							|  |  |  |         } else if (m_current_code == m_code_table.size()) { | 
					
						
							| 
									
										
										
										
											2021-02-23 20:42:32 +01:00
										 |  |  |             VERIFY(!m_output.is_empty()); | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |             m_output.append(m_output[0]); | 
					
						
							|  |  |  |             extend_code_table(m_output); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return m_output; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     void init_code_table() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-05-30 19:31:32 +02:00
										 |  |  |         m_code_table.ensure_capacity(m_table_capacity); | 
					
						
							| 
									
										
										
										
											2020-05-03 19:06:14 +01:00
										 |  |  |         for (u16 i = 0; i < m_table_capacity; ++i) { | 
					
						
							| 
									
										
										
										
											2021-05-30 19:31:32 +02:00
										 |  |  |             m_code_table.unchecked_append({ (u8)i }); | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         m_original_code_table = m_code_table; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 19:06:14 +01:00
										 |  |  |     void extend_code_table(const Vector<u8>& entry) | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         if (entry.size() > 1 && m_code_table.size() < 4096) { | 
					
						
							| 
									
										
										
										
											2020-05-03 19:06:14 +01:00
										 |  |  |             m_code_table.append(entry); | 
					
						
							|  |  |  |             if (m_code_table.size() >= m_table_capacity && m_code_size < max_code_size) { | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |                 ++m_code_size; | 
					
						
							| 
									
										
										
										
											2020-05-03 19:06:14 +01:00
										 |  |  |                 m_table_capacity *= 2; | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const Vector<u8>& m_lzw_bytes; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int m_current_bit_index { 0 }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 19:06:14 +01:00
										 |  |  |     Vector<Vector<u8>> m_code_table {}; | 
					
						
							|  |  |  |     Vector<Vector<u8>> m_original_code_table {}; | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     u8 m_code_size { 0 }; | 
					
						
							|  |  |  |     u8 m_original_code_size { 0 }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 19:06:14 +01:00
										 |  |  |     u32 m_table_capacity { 0 }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 12:59:11 +01:00
										 |  |  |     u16 m_current_code { 0 }; | 
					
						
							|  |  |  |     Vector<u8> m_output {}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-31 13:22:38 +01:00
										 |  |  | static void copy_frame_buffer(Bitmap& dest, const Bitmap& src) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-23 20:42:32 +01:00
										 |  |  |     VERIFY(dest.size_in_bytes() == src.size_in_bytes()); | 
					
						
							| 
									
										
										
										
											2020-08-31 13:22:38 +01:00
										 |  |  |     memcpy(dest.scanline(0), src.scanline(0), dest.size_in_bytes()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-29 22:29:27 +01:00
										 |  |  | static void clear_rect(Bitmap& bitmap, const IntRect& rect, Color color) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-10-21 23:38:13 +02:00
										 |  |  |     auto intersection_rect = rect.intersected(bitmap.rect()); | 
					
						
							|  |  |  |     if (intersection_rect.is_empty()) | 
					
						
							| 
									
										
										
										
											2021-01-29 22:29:27 +01:00
										 |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-21 23:38:13 +02:00
										 |  |  |     RGBA32* dst = bitmap.scanline(intersection_rect.top()) + intersection_rect.left(); | 
					
						
							| 
									
										
										
										
											2021-01-29 22:29:27 +01:00
										 |  |  |     const size_t dst_skip = bitmap.pitch() / sizeof(RGBA32); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-21 23:38:13 +02:00
										 |  |  |     for (int i = intersection_rect.height() - 1; i >= 0; --i) { | 
					
						
							|  |  |  |         fast_u32_fill(dst, color.value(), intersection_rect.width()); | 
					
						
							| 
									
										
										
										
											2021-01-29 22:29:27 +01:00
										 |  |  |         dst += dst_skip; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-29 17:48:17 +01:00
										 |  |  | static bool decode_frame(GIFLoadingContext& context, size_t frame_index) | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     if (frame_index >= context.images.size()) { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-29 17:48:17 +01:00
										 |  |  |     if (context.state >= GIFLoadingContext::State::FrameComplete && frame_index == context.current_frame) { | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     size_t start_frame = context.current_frame + 1; | 
					
						
							|  |  |  |     if (context.state < GIFLoadingContext::State::FrameComplete) { | 
					
						
							|  |  |  |         start_frame = 0; | 
					
						
							| 
									
										
										
										
											2021-07-24 18:31:59 +02:00
										 |  |  |         context.frame_buffer = Bitmap::try_create(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height }); | 
					
						
							| 
									
										
										
										
											2020-12-20 16:04:29 +01:00
										 |  |  |         if (!context.frame_buffer) | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2021-07-24 18:31:59 +02:00
										 |  |  |         context.prev_frame_buffer = Bitmap::try_create(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height }); | 
					
						
							| 
									
										
										
										
											2020-12-20 16:04:29 +01:00
										 |  |  |         if (!context.prev_frame_buffer) | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2020-08-29 17:48:17 +01:00
										 |  |  |     } else if (frame_index < context.current_frame) { | 
					
						
							|  |  |  |         start_frame = 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (size_t i = start_frame; i <= frame_index; ++i) { | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |         auto& image = context.images.at(i); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-28 07:01:52 +02:00
										 |  |  |         const auto previous_image_disposal_method = i > 0 ? context.images.at(i - 1).disposal_method : GIFImageDescriptor::DisposalMethod::None; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-29 15:04:41 +01:00
										 |  |  |         if (i == 0) { | 
					
						
							| 
									
										
										
										
											2020-08-31 13:22:38 +01:00
										 |  |  |             context.frame_buffer->fill(Color::Transparent); | 
					
						
							| 
									
										
										
										
											2021-05-28 07:01:52 +02:00
										 |  |  |         } else if (i > 0 && image.disposal_method == GIFImageDescriptor::DisposalMethod::RestorePrevious | 
					
						
							|  |  |  |             && previous_image_disposal_method != GIFImageDescriptor::DisposalMethod::RestorePrevious) { | 
					
						
							| 
									
										
										
										
											2020-08-31 13:22:38 +01:00
										 |  |  |             // This marks the start of a run of frames that once disposed should be restored to the
 | 
					
						
							|  |  |  |             // previous underlying image contents. Therefore we make a copy of the current frame
 | 
					
						
							|  |  |  |             // buffer so that it can be restored later.
 | 
					
						
							|  |  |  |             copy_frame_buffer(*context.prev_frame_buffer, *context.frame_buffer); | 
					
						
							| 
									
										
										
										
											2020-08-29 15:04:41 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-28 07:01:52 +02:00
										 |  |  |         if (previous_image_disposal_method == GIFImageDescriptor::DisposalMethod::RestoreBackground) { | 
					
						
							| 
									
										
										
										
											2020-08-31 13:22:38 +01:00
										 |  |  |             // Note: RestoreBackground could be interpreted either as restoring the underlying
 | 
					
						
							|  |  |  |             // background of the entire image (e.g. container element's background-color), or the
 | 
					
						
							|  |  |  |             // background color of the GIF itself. It appears that all major browsers and most other
 | 
					
						
							|  |  |  |             // GIF decoders adhere to the former interpretation, therefore we will do the same by
 | 
					
						
							|  |  |  |             // clearing the entire frame buffer to transparent.
 | 
					
						
							| 
									
										
										
										
											2021-01-29 22:29:27 +01:00
										 |  |  |             clear_rect(*context.frame_buffer, context.images.at(i - 1).rect(), Color::Transparent); | 
					
						
							| 
									
										
										
										
											2021-05-28 07:01:52 +02:00
										 |  |  |         } else if (i > 0 && previous_image_disposal_method == GIFImageDescriptor::DisposalMethod::RestorePrevious) { | 
					
						
							| 
									
										
										
										
											2020-08-31 13:22:38 +01:00
										 |  |  |             // Previous frame indicated that once disposed, it should be restored to *its* previous
 | 
					
						
							|  |  |  |             // underlying image contents, therefore we restore the saved previous frame buffer.
 | 
					
						
							|  |  |  |             copy_frame_buffer(*context.frame_buffer, *context.prev_frame_buffer); | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-30 20:03:32 +02:00
										 |  |  |         if (image.lzw_min_code_size > 8) | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-31 13:22:38 +01:00
										 |  |  |         LZWDecoder decoder(image.lzw_encoded_bytes, image.lzw_min_code_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Add GIF-specific control codes
 | 
					
						
							|  |  |  |         const int clear_code = decoder.add_control_code(); | 
					
						
							|  |  |  |         const int end_of_information_code = decoder.add_control_code(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const auto& color_map = image.use_global_color_map ? context.logical_screen.color_map : image.color_map; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |         int pixel_index = 0; | 
					
						
							| 
									
										
										
										
											2020-08-29 16:05:24 +01:00
										 |  |  |         int row = 0; | 
					
						
							|  |  |  |         int interlace_pass = 0; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |         while (true) { | 
					
						
							|  |  |  |             Optional<u16> code = decoder.next_code(); | 
					
						
							|  |  |  |             if (!code.has_value()) { | 
					
						
							| 
									
										
										
										
											2021-05-01 21:10:08 +02:00
										 |  |  |                 dbgln_if(GIF_DEBUG, "Unexpectedly reached end of gif frame data"); | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |                 return false; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (code.value() == clear_code) { | 
					
						
							|  |  |  |                 decoder.reset(); | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-11-29 14:01:16 -05:00
										 |  |  |             if (code.value() == end_of_information_code) | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             if (!image.width) | 
					
						
							|  |  |  |                 continue; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             auto colors = decoder.get_output(); | 
					
						
							|  |  |  |             for (const auto& color : colors) { | 
					
						
							| 
									
										
										
										
											2020-08-30 08:47:56 +01:00
										 |  |  |                 auto c = color_map[color]; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 21:48:15 +03:00
										 |  |  |                 int x = pixel_index % image.width + image.x; | 
					
						
							| 
									
										
										
										
											2020-08-29 16:05:24 +01:00
										 |  |  |                 int y = row + image.y; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-01 15:26:26 +00:00
										 |  |  |                 if (context.frame_buffer->rect().contains(x, y) && (!image.transparent || color != image.transparency_index)) { | 
					
						
							| 
									
										
										
										
											2020-08-29 17:48:17 +01:00
										 |  |  |                     context.frame_buffer->set_pixel(x, y, c); | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-06-17 21:48:15 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |                 ++pixel_index; | 
					
						
							| 
									
										
										
										
											2020-08-29 16:05:24 +01:00
										 |  |  |                 if (pixel_index % image.width == 0) { | 
					
						
							|  |  |  |                     if (image.interlaced) { | 
					
						
							| 
									
										
										
										
											2021-02-26 22:31:07 +00:00
										 |  |  |                         if (interlace_pass < 4) { | 
					
						
							|  |  |  |                             if (row + INTERLACE_ROW_STRIDES[interlace_pass] >= image.height) { | 
					
						
							|  |  |  |                                 ++interlace_pass; | 
					
						
							|  |  |  |                                 if (interlace_pass < 4) | 
					
						
							|  |  |  |                                     row = INTERLACE_ROW_OFFSETS[interlace_pass]; | 
					
						
							|  |  |  |                             } else { | 
					
						
							| 
									
										
										
										
											2021-02-07 11:18:55 +01:00
										 |  |  |                                 row += INTERLACE_ROW_STRIDES[interlace_pass]; | 
					
						
							| 
									
										
										
										
											2021-02-26 22:31:07 +00:00
										 |  |  |                             } | 
					
						
							| 
									
										
										
										
											2020-08-29 16:05:24 +01:00
										 |  |  |                         } | 
					
						
							|  |  |  |                     } else { | 
					
						
							|  |  |  |                         ++row; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-08 17:01:44 +00:00
										 |  |  |         context.current_frame = i; | 
					
						
							|  |  |  |         context.state = GIFLoadingContext::State::FrameComplete; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-29 17:48:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-11 00:09:28 +02:00
										 |  |  | static bool load_gif_frame_descriptors(GIFLoadingContext& context) | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |     if (context.data_size < 32) | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |     InputMemoryStream stream { { context.data, context.data_size } }; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 13:45:41 +01:00
										 |  |  |     Optional<GIFFormat> format = decode_gif_header(stream); | 
					
						
							|  |  |  |     if (!format.has_value()) { | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2020-04-25 13:45:41 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |     LittleEndian<u16> value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stream >> value; | 
					
						
							|  |  |  |     context.logical_screen.width = value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stream >> value; | 
					
						
							|  |  |  |     context.logical_screen.height = value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (stream.handle_any_error()) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |         return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-25 00:19:06 +01:00
										 |  |  |     if (context.logical_screen.width > maximum_width_for_decoded_images || context.logical_screen.height > maximum_height_for_decoded_images) { | 
					
						
							|  |  |  |         dbgln("This GIF is too large for comfort: {}x{}", context.logical_screen.width, context.logical_screen.height); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |     u8 gcm_info = 0; | 
					
						
							|  |  |  |     stream >> gcm_info; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |     if (stream.handle_any_error()) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     stream >> context.background_color_index; | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |     if (stream.handle_any_error()) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     u8 pixel_aspect_ratio = 0; | 
					
						
							|  |  |  |     stream >> pixel_aspect_ratio; | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |     if (stream.handle_any_error()) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-08 17:43:01 +00:00
										 |  |  |     u8 bits_per_pixel = (gcm_info & 7) + 1; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |     int color_map_entry_count = 1; | 
					
						
							|  |  |  |     for (int i = 0; i < bits_per_pixel; ++i) | 
					
						
							|  |  |  |         color_map_entry_count *= 2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int i = 0; i < color_map_entry_count; ++i) { | 
					
						
							| 
									
										
										
										
											2020-08-30 10:40:40 +02:00
										 |  |  |         u8 r = 0; | 
					
						
							|  |  |  |         u8 g = 0; | 
					
						
							|  |  |  |         u8 b = 0; | 
					
						
							| 
									
										
										
										
											2020-08-30 08:47:56 +01:00
										 |  |  |         stream >> r >> g >> b; | 
					
						
							|  |  |  |         context.logical_screen.color_map[i] = { r, g, b }; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |     if (stream.handle_any_error()) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-28 07:01:52 +02:00
										 |  |  |     NonnullOwnPtr<GIFImageDescriptor> current_image = make<GIFImageDescriptor>(); | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |     for (;;) { | 
					
						
							|  |  |  |         u8 sentinel = 0; | 
					
						
							|  |  |  |         stream >> sentinel; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-13 11:49:33 +01:00
										 |  |  |         if (stream.handle_any_error()) | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 20:11:25 -05:00
										 |  |  |         if (sentinel == '!') { | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |             u8 extension_type = 0; | 
					
						
							|  |  |  |             stream >> extension_type; | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |             if (stream.handle_any_error()) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             u8 sub_block_length = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |             Vector<u8> sub_block {}; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |             for (;;) { | 
					
						
							|  |  |  |                 stream >> sub_block_length; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |                 if (stream.handle_any_error()) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |                     return false; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 if (sub_block_length == 0) | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-23 14:34:53 -04:00
										 |  |  |                 u8 dummy = 0; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |                 for (u16 i = 0; i < sub_block_length; ++i) { | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |                     stream >> dummy; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |                     sub_block.append(dummy); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |                 if (stream.handle_any_error()) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |                     return false; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (extension_type == 0xF9) { | 
					
						
							|  |  |  |                 if (sub_block.size() != 4) { | 
					
						
							| 
									
										
										
										
											2021-05-01 21:10:08 +02:00
										 |  |  |                     dbgln_if(GIF_DEBUG, "Unexpected graphic control size"); | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |                     continue; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 u8 disposal_method = (sub_block[0] & 0x1C) >> 2; | 
					
						
							| 
									
										
										
										
											2021-05-28 07:01:52 +02:00
										 |  |  |                 current_image->disposal_method = (GIFImageDescriptor::DisposalMethod)disposal_method; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 u8 user_input = (sub_block[0] & 0x2) >> 1; | 
					
						
							|  |  |  |                 current_image->user_input = user_input == 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 u8 transparent = sub_block[0] & 1; | 
					
						
							|  |  |  |                 current_image->transparent = transparent == 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-30 12:37:17 +02:00
										 |  |  |                 u16 duration = sub_block[1] + ((u16)sub_block[2] << 8); | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |                 current_image->duration = duration; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 current_image->transparency_index = sub_block[3]; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (extension_type == 0xFF) { | 
					
						
							|  |  |  |                 if (sub_block.size() != 14) { | 
					
						
							| 
									
										
										
										
											2021-02-07 15:33:24 +03:30
										 |  |  |                     dbgln_if(GIF_DEBUG, "Unexpected application extension size: {}", sub_block.size()); | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |                     continue; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (sub_block[11] != 1) { | 
					
						
							| 
									
										
										
										
											2021-02-07 15:33:24 +03:30
										 |  |  |                     dbgln_if(GIF_DEBUG, "Unexpected application extension format"); | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |                     continue; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 u16 loops = sub_block[12] + (sub_block[13] << 8); | 
					
						
							|  |  |  |                 context.loops = loops; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 20:11:25 -05:00
										 |  |  |         if (sentinel == ',') { | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |             context.images.append(move(current_image)); | 
					
						
							|  |  |  |             auto& image = context.images.last(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |             LittleEndian<u16> tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-23 01:32:00 +01:00
										 |  |  |             u8 packed_fields { 0 }; | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             stream >> tmp; | 
					
						
							|  |  |  |             image.x = tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             stream >> tmp; | 
					
						
							|  |  |  |             image.y = tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             stream >> tmp; | 
					
						
							|  |  |  |             image.width = tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             stream >> tmp; | 
					
						
							|  |  |  |             image.height = tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |             stream >> packed_fields; | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |             if (stream.handle_any_error()) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2020-08-20 19:41:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             image.use_global_color_map = !(packed_fields & 0x80); | 
					
						
							| 
									
										
										
										
											2020-08-29 16:05:24 +01:00
										 |  |  |             image.interlaced = (packed_fields & 0x40) != 0; | 
					
						
							| 
									
										
										
										
											2020-08-20 19:41:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (!image.use_global_color_map) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:29:28 +02:00
										 |  |  |                 size_t local_color_table_size = AK::exp2<size_t>((packed_fields & 7) + 1); | 
					
						
							| 
									
										
										
										
											2020-08-20 19:41:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 for (size_t i = 0; i < local_color_table_size; ++i) { | 
					
						
							| 
									
										
										
										
											2020-08-30 10:40:40 +02:00
										 |  |  |                     u8 r = 0; | 
					
						
							|  |  |  |                     u8 g = 0; | 
					
						
							|  |  |  |                     u8 b = 0; | 
					
						
							| 
									
										
										
										
											2020-08-30 08:47:56 +01:00
										 |  |  |                     stream >> r >> g >> b; | 
					
						
							|  |  |  |                     image.color_map[i] = { r, g, b }; | 
					
						
							| 
									
										
										
										
											2020-08-20 19:41:52 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |             stream >> image.lzw_min_code_size; | 
					
						
							| 
									
										
										
										
											2020-11-29 14:04:14 -05:00
										 |  |  |             if (stream.handle_any_error()) | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             u8 lzw_encoded_bytes_expected = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for (;;) { | 
					
						
							|  |  |  |                 stream >> lzw_encoded_bytes_expected; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |                 if (stream.handle_any_error()) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |                     return false; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 if (lzw_encoded_bytes_expected == 0) | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |                 Array<u8, 256> buffer; | 
					
						
							|  |  |  |                 stream >> buffer.span().trim(lzw_encoded_bytes_expected); | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |                 if (stream.handle_any_error()) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |                     return false; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 for (int i = 0; i < lzw_encoded_bytes_expected; ++i) { | 
					
						
							|  |  |  |                     image.lzw_encoded_bytes.append(buffer[i]); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-28 07:01:52 +02:00
										 |  |  |             current_image = make<GIFImageDescriptor>(); | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 20:11:25 -05:00
										 |  |  |         if (sentinel == ';') { | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     context.state = GIFLoadingContext::State::FrameDescriptorsLoaded; | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 13:29:12 +01:00
										 |  |  | GIFImageDecoderPlugin::GIFImageDecoderPlugin(const u8* data, size_t size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_context = make<GIFLoadingContext>(); | 
					
						
							|  |  |  |     m_context->data = data; | 
					
						
							|  |  |  |     m_context->data_size = size; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-05 14:09:38 +02:00
										 |  |  | GIFImageDecoderPlugin::~GIFImageDecoderPlugin() { } | 
					
						
							| 
									
										
										
										
											2020-04-25 13:29:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  | IntSize GIFImageDecoderPlugin::size() | 
					
						
							| 
									
										
										
										
											2020-04-25 13:29:12 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-08 17:01:44 +00:00
										 |  |  |     if (m_context->error_state == GIFLoadingContext::ErrorState::FailedToLoadFrameDescriptors) { | 
					
						
							| 
									
										
										
										
											2020-04-25 13:29:12 +01:00
										 |  |  |         return {}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     if (m_context->state < GIFLoadingContext::State::FrameDescriptorsLoaded) { | 
					
						
							|  |  |  |         if (!load_gif_frame_descriptors(*m_context)) { | 
					
						
							| 
									
										
										
										
											2020-11-08 17:01:44 +00:00
										 |  |  |             m_context->error_state = GIFLoadingContext::ErrorState::FailedToLoadFrameDescriptors; | 
					
						
							| 
									
										
										
										
											2020-04-25 13:29:12 +01:00
										 |  |  |             return {}; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     return { m_context->logical_screen.width, m_context->logical_screen.height }; | 
					
						
							| 
									
										
										
										
											2020-04-25 13:29:12 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 13:17:06 +01:00
										 |  |  | RefPtr<Gfx::Bitmap> GIFImageDecoderPlugin::bitmap() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-29 17:48:17 +01:00
										 |  |  |     if (m_context->state < GIFLoadingContext::State::FrameComplete) { | 
					
						
							|  |  |  |         return frame(0).image; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return m_context->frame_buffer; | 
					
						
							| 
									
										
										
										
											2019-11-23 16:48:28 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-02-06 11:56:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 13:29:12 +01:00
										 |  |  | void GIFImageDecoderPlugin::set_volatile() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-29 17:48:17 +01:00
										 |  |  |     if (m_context->frame_buffer) { | 
					
						
							|  |  |  |         m_context->frame_buffer->set_volatile(); | 
					
						
							| 
									
										
										
										
											2020-04-25 13:29:12 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-24 22:49:48 +02:00
										 |  |  | bool GIFImageDecoderPlugin::set_nonvolatile(bool& was_purged) | 
					
						
							| 
									
										
										
										
											2020-04-25 13:29:12 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-07-24 22:49:48 +02:00
										 |  |  |     if (!m_context->frame_buffer) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     return m_context->frame_buffer->set_nonvolatile(was_purged); | 
					
						
							| 
									
										
										
										
											2020-04-25 13:29:12 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 13:51:00 +01:00
										 |  |  | bool GIFImageDecoderPlugin::sniff() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-19 19:18:21 +02:00
										 |  |  |     InputMemoryStream stream { { m_context->data, m_context->data_size } }; | 
					
						
							| 
									
										
										
										
											2020-04-25 13:51:00 +01:00
										 |  |  |     return decode_gif_header(stream).has_value(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-03 17:12:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | bool GIFImageDecoderPlugin::is_animated() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-08 17:01:44 +00:00
										 |  |  |     if (m_context->error_state != GIFLoadingContext::ErrorState::NoError) { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     if (m_context->state < GIFLoadingContext::State::FrameDescriptorsLoaded) { | 
					
						
							|  |  |  |         if (!load_gif_frame_descriptors(*m_context)) { | 
					
						
							| 
									
										
										
										
											2020-11-08 17:01:44 +00:00
										 |  |  |             m_context->error_state = GIFLoadingContext::ErrorState::FailedToLoadFrameDescriptors; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return m_context->images.size() > 1; | 
					
						
							| 
									
										
										
										
											2020-05-03 17:12:54 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | size_t GIFImageDecoderPlugin::loop_count() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-08 17:01:44 +00:00
										 |  |  |     if (m_context->error_state != GIFLoadingContext::ErrorState::NoError) { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     if (m_context->state < GIFLoadingContext::State::FrameDescriptorsLoaded) { | 
					
						
							|  |  |  |         if (!load_gif_frame_descriptors(*m_context)) { | 
					
						
							| 
									
										
										
										
											2020-11-08 17:01:44 +00:00
										 |  |  |             m_context->error_state = GIFLoadingContext::ErrorState::FailedToLoadFrameDescriptors; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |             return 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return m_context->loops; | 
					
						
							| 
									
										
										
										
											2020-05-03 17:12:54 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | size_t GIFImageDecoderPlugin::frame_count() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-08 17:01:44 +00:00
										 |  |  |     if (m_context->error_state != GIFLoadingContext::ErrorState::NoError) { | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     if (m_context->state < GIFLoadingContext::State::FrameDescriptorsLoaded) { | 
					
						
							|  |  |  |         if (!load_gif_frame_descriptors(*m_context)) { | 
					
						
							| 
									
										
										
										
											2020-11-08 17:01:44 +00:00
										 |  |  |             m_context->error_state = GIFLoadingContext::ErrorState::FailedToLoadFrameDescriptors; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |             return 1; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return m_context->images.size(); | 
					
						
							| 
									
										
										
										
											2020-05-03 17:12:54 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ImageFrameDescriptor GIFImageDecoderPlugin::frame(size_t i) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-08 17:01:44 +00:00
										 |  |  |     if (m_context->error_state >= GIFLoadingContext::ErrorState::FailedToDecodeAnyFrame) { | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |         return {}; | 
					
						
							| 
									
										
										
										
											2020-05-03 17:12:54 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_context->state < GIFLoadingContext::State::FrameDescriptorsLoaded) { | 
					
						
							|  |  |  |         if (!load_gif_frame_descriptors(*m_context)) { | 
					
						
							| 
									
										
										
										
											2020-11-08 17:01:44 +00:00
										 |  |  |             m_context->error_state = GIFLoadingContext::ErrorState::FailedToLoadFrameDescriptors; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |             return {}; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-08 17:01:44 +00:00
										 |  |  |     if (m_context->error_state == GIFLoadingContext::ErrorState::NoError && !decode_frame(*m_context, i)) { | 
					
						
							|  |  |  |         if (m_context->state < GIFLoadingContext::State::FrameComplete || !decode_frame(*m_context, 0)) { | 
					
						
							|  |  |  |             m_context->error_state = GIFLoadingContext::ErrorState::FailedToDecodeAnyFrame; | 
					
						
							|  |  |  |             return {}; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         m_context->error_state = GIFLoadingContext::ErrorState::FailedToDecodeAllFrames; | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-06 11:52:35 +01:00
										 |  |  |     auto image_or_error = m_context->frame_buffer->clone(); | 
					
						
							|  |  |  |     if (image_or_error.is_error()) { | 
					
						
							|  |  |  |         m_context->error_state = GIFLoadingContext::ErrorState::FailedToDecodeAllFrames; | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     ImageFrameDescriptor frame {}; | 
					
						
							| 
									
										
										
										
											2021-11-06 11:52:35 +01:00
										 |  |  |     frame.image = image_or_error.release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2020-05-08 12:03:20 +01:00
										 |  |  |     frame.duration = m_context->images.at(i).duration * 10; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (frame.duration <= 10) { | 
					
						
							|  |  |  |         frame.duration = 100; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return frame; | 
					
						
							| 
									
										
										
										
											2020-05-03 17:12:54 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 11:56:38 +01:00
										 |  |  | } |