| 
									
										
										
										
											2020-04-21 23:49:51 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2022-09-02 23:07:05 +02:00
										 |  |  |  * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2024-03-23 21:45:59 +01:00
										 |  |  |  * Copyright (c) 2024, Kenneth Myhra <kennethmyhra@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-04-21 23:49:51 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-04-21 23:49:51 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibGfx/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2024-03-23 21:45:59 +01:00
										 |  |  | #include <LibWeb/Bindings/ImageDataPrototype.h>
 | 
					
						
							| 
									
										
										
										
											2022-09-02 23:07:05 +02:00
										 |  |  | #include <LibWeb/Bindings/PlatformObject.h>
 | 
					
						
							| 
									
										
										
										
											2020-04-21 23:49:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 18:20:36 +02:00
										 |  |  | namespace Web::HTML { | 
					
						
							| 
									
										
										
										
											2020-04-21 23:49:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-23 21:45:59 +01:00
										 |  |  | struct ImageDataSettings { | 
					
						
							|  |  |  |     Bindings::PredefinedColorSpace color_space; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-02 23:07:05 +02:00
										 |  |  | class ImageData final : public Bindings::PlatformObject { | 
					
						
							|  |  |  |     WEB_PLATFORM_OBJECT(ImageData, Bindings::PlatformObject); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  |     JS_DECLARE_ALLOCATOR(ImageData); | 
					
						
							| 
									
										
										
										
											2020-04-21 23:49:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-02 23:07:05 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-03-23 21:45:59 +01:00
										 |  |  |     [[nodiscard]] static WebIDL::ExceptionOr<JS::NonnullGCPtr<ImageData>> create(JS::Realm&, u32 sw, u32 sh, Optional<ImageDataSettings> const& settings = {}); | 
					
						
							| 
									
										
										
										
											2024-03-26 14:31:32 +01:00
										 |  |  |     [[nodiscard]] static WebIDL::ExceptionOr<JS::NonnullGCPtr<ImageData>> create(JS::Realm&, JS::Handle<WebIDL::BufferSource> const& data, u32 sw, Optional<u32> sh = {}, Optional<ImageDataSettings> const& settings = {}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-23 21:45:59 +01:00
										 |  |  |     [[nodiscard]] static WebIDL::ExceptionOr<JS::NonnullGCPtr<ImageData>> construct_impl(JS::Realm&, u32 sw, u32 sh, Optional<ImageDataSettings> const& settings = {}); | 
					
						
							| 
									
										
										
										
											2024-03-26 14:31:32 +01:00
										 |  |  |     [[nodiscard]] static WebIDL::ExceptionOr<JS::NonnullGCPtr<ImageData>> construct_impl(JS::Realm&, JS::Handle<WebIDL::BufferSource> const& data, u32 sw, Optional<u32> sh = {}, Optional<ImageDataSettings> const& settings = {}); | 
					
						
							| 
									
										
										
										
											2024-03-23 21:45:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-02 23:07:05 +02:00
										 |  |  |     virtual ~ImageData() override; | 
					
						
							| 
									
										
										
										
											2020-04-21 23:49:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-21 15:57:10 +02:00
										 |  |  |     unsigned width() const; | 
					
						
							|  |  |  |     unsigned height() const; | 
					
						
							| 
									
										
										
										
											2020-04-21 23:49:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Gfx::Bitmap& bitmap() { return m_bitmap; } | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  |     Gfx::Bitmap const& bitmap() const { return m_bitmap; } | 
					
						
							| 
									
										
										
										
											2020-04-21 23:49:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     JS::Uint8ClampedArray* data(); | 
					
						
							|  |  |  |     const JS::Uint8ClampedArray* data() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2022-09-25 16:38:21 -06:00
										 |  |  |     ImageData(JS::Realm&, NonnullRefPtr<Gfx::Bitmap>, JS::NonnullGCPtr<JS::Uint8ClampedArray>); | 
					
						
							| 
									
										
										
										
											2022-09-02 23:07:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |     virtual void initialize(JS::Realm&) override; | 
					
						
							| 
									
										
										
										
											2022-09-02 23:07:05 +02:00
										 |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							| 
									
										
										
										
											2020-04-21 23:49:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     NonnullRefPtr<Gfx::Bitmap> m_bitmap; | 
					
						
							| 
									
										
										
										
											2022-09-02 23:07:05 +02:00
										 |  |  |     JS::NonnullGCPtr<JS::Uint8ClampedArray> m_data; | 
					
						
							| 
									
										
										
										
											2020-04-21 23:49:51 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |