1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00
serenity/Userland/Libraries/LibGfx/PortableImageMapLoader.h
Lenny Maiorani 786b02730c 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.
2022-03-13 22:35:20 +01:00

48 lines
916 B
C++

/*
* 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;
};
}