mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 02:02:45 +00:00 
			
		
		
		
	 6e6999ce57
			
		
	
	
		6e6999ce57
		
	
	
	
	
		
			
			Originally I simply thought that passing file paths is quite OK, but as Linus pointed to, it turned out that passing file paths to ensure some files are able to be decoded is awkward because it does not work with images being served over HTTP. Therefore, ideally we should just use the MIME type as an optional argument to ensure that we can always fallback to use that in case sniffing for the correct image type has failed so we can still detect files like with the TGA format, which has no magic bytes.
		
			
				
	
	
		
			43 lines
		
	
	
	
		
			982 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
	
		
			982 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/HashMap.h>
 | |
| #include <ImageDecoder/ImageDecoderClientEndpoint.h>
 | |
| #include <ImageDecoder/ImageDecoderServerEndpoint.h>
 | |
| #include <LibIPC/ConnectionToServer.h>
 | |
| 
 | |
| namespace ImageDecoderClient {
 | |
| 
 | |
| struct Frame {
 | |
|     RefPtr<Gfx::Bitmap> bitmap;
 | |
|     u32 duration { 0 };
 | |
| };
 | |
| 
 | |
| struct DecodedImage {
 | |
|     bool is_animated { false };
 | |
|     u32 loop_count { 0 };
 | |
|     Vector<Frame> frames;
 | |
| };
 | |
| 
 | |
| class Client final
 | |
|     : public IPC::ConnectionToServer<ImageDecoderClientEndpoint, ImageDecoderServerEndpoint>
 | |
|     , public ImageDecoderClientEndpoint {
 | |
|     IPC_CLIENT_CONNECTION(Client, "/tmp/session/%sid/portal/image"sv);
 | |
| 
 | |
| public:
 | |
|     Optional<DecodedImage> decode_image(ReadonlyBytes, Optional<DeprecatedString> mime_type = {});
 | |
| 
 | |
|     Function<void()> on_death;
 | |
| 
 | |
| private:
 | |
|     Client(NonnullOwnPtr<Core::Stream::LocalSocket>);
 | |
| 
 | |
|     virtual void die() override;
 | |
| };
 | |
| 
 | |
| }
 |