mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:27:45 +00:00
LibGfx: Commonize P[BGP]M file loading contexts
Much of the code in PBM, PGM, and PPM image loaders is common. The contexts are nearly identical. Instead of writing multiple contexts, write 1 with a template argument to pass in the details of the given format.
This commit is contained in:
parent
5c21f963ff
commit
786b02730c
8 changed files with 109 additions and 124 deletions
48
Userland/Libraries/LibGfx/PortableImageMapLoader.h
Normal file
48
Userland/Libraries/LibGfx/PortableImageMapLoader.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Hüseyin ASLITÜRK <asliturk@hotmail.com>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
template<class TFormatDetails>
|
||||
struct PortableImageMapLoadingContext {
|
||||
using FormatDetails = TFormatDetails;
|
||||
|
||||
enum class Type {
|
||||
Unknown,
|
||||
ASCII,
|
||||
RAWBITS
|
||||
};
|
||||
|
||||
enum class State {
|
||||
NotDecoded = 0,
|
||||
Error,
|
||||
MagicNumber,
|
||||
Width,
|
||||
Height,
|
||||
Maxval,
|
||||
Bitmap,
|
||||
Decoded
|
||||
};
|
||||
|
||||
Type type { Type::Unknown };
|
||||
State state { State::NotDecoded };
|
||||
u8 const* data { nullptr };
|
||||
size_t data_size { 0 };
|
||||
size_t width { 0 };
|
||||
size_t height { 0 };
|
||||
FormatDetails format_details {};
|
||||
RefPtr<Gfx::Bitmap> bitmap;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue