mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:47:35 +00:00
PixelPaint: Add ProjectLoader to abstract away opening of files
This new class will open and parse files (either images directly or .pp project files) and one can get the parsed Image as well as other information from it. This patch removes a bunch of 'try_create_from..." methods from Image in favor of using the ProjectLoader. The only json_metadata that is available are Guides for now.
This commit is contained in:
parent
b3f53a0b5a
commit
508d563189
6 changed files with 142 additions and 115 deletions
35
Userland/Applications/PixelPaint/ProjectLoader.h
Normal file
35
Userland/Applications/PixelPaint/ProjectLoader.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Image.h"
|
||||
#include <AK/JsonArray.h>
|
||||
#include <AK/Result.h>
|
||||
#include <AK/StringView.h>
|
||||
|
||||
namespace PixelPaint {
|
||||
|
||||
class ProjectLoader {
|
||||
public:
|
||||
ProjectLoader() = default;
|
||||
~ProjectLoader() = default;
|
||||
|
||||
Result<void, String> try_load_from_fd_and_close(int fd, StringView path);
|
||||
Result<void, String> try_load_from_path(StringView path);
|
||||
|
||||
bool is_raw_image() const { return m_is_raw_image; }
|
||||
bool has_image() const { return !m_image.is_null(); }
|
||||
RefPtr<Image> release_image() const { return move(m_image); }
|
||||
JsonArray const& json_metadata() const { return m_json_metadata; }
|
||||
|
||||
private:
|
||||
RefPtr<Image> m_image { nullptr };
|
||||
bool m_is_raw_image { false };
|
||||
JsonArray m_json_metadata {};
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue