mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:27:35 +00:00
LibGfx/DDS: Read the header in create()
and remove initialize()
This is done as a part of #19893.
This commit is contained in:
parent
aa9470880f
commit
0520490577
2 changed files with 8 additions and 15 deletions
|
@ -31,6 +31,7 @@ struct DDSLoadingContext {
|
||||||
enum State {
|
enum State {
|
||||||
NotDecoded = 0,
|
NotDecoded = 0,
|
||||||
Error,
|
Error,
|
||||||
|
HeaderDecoded,
|
||||||
BitmapDecoded,
|
BitmapDecoded,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -465,12 +466,14 @@ static ErrorOr<void> decode_header(DDSLoadingContext& context)
|
||||||
return Error::from_string_literal("Format type is not supported at the moment");
|
return Error::from_string_literal("Format type is not supported at the moment");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.state = DDSLoadingContext::HeaderDecoded;
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> decode_dds(DDSLoadingContext& context)
|
static ErrorOr<void> decode_dds(DDSLoadingContext& context)
|
||||||
{
|
{
|
||||||
TRY(decode_header(context));
|
VERIFY(context.state == DDSLoadingContext::HeaderDecoded);
|
||||||
|
|
||||||
// We support parsing mipmaps, but we only care about the largest one :^) (At least for now)
|
// We support parsing mipmaps, but we only care about the largest one :^) (At least for now)
|
||||||
if (size_t mipmap_level = 0; mipmap_level < max(context.header.mip_map_count, 1u)) {
|
if (size_t mipmap_level = 0; mipmap_level < max(context.header.mip_map_count, 1u)) {
|
||||||
|
@ -631,18 +634,7 @@ DDSImageDecoderPlugin::~DDSImageDecoderPlugin() = default;
|
||||||
|
|
||||||
IntSize DDSImageDecoderPlugin::size()
|
IntSize DDSImageDecoderPlugin::size()
|
||||||
{
|
{
|
||||||
if (m_context->state == DDSLoadingContext::State::Error)
|
return { m_context->header.width, m_context->header.height };
|
||||||
return {};
|
|
||||||
|
|
||||||
if (m_context->state == DDSLoadingContext::State::BitmapDecoded)
|
|
||||||
return { m_context->header.width, m_context->header.height };
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorOr<void> DDSImageDecoderPlugin::initialize()
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DDSImageDecoderPlugin::sniff(ReadonlyBytes data)
|
bool DDSImageDecoderPlugin::sniff(ReadonlyBytes data)
|
||||||
|
@ -658,7 +650,9 @@ bool DDSImageDecoderPlugin::sniff(ReadonlyBytes data)
|
||||||
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> DDSImageDecoderPlugin::create(ReadonlyBytes data)
|
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> DDSImageDecoderPlugin::create(ReadonlyBytes data)
|
||||||
{
|
{
|
||||||
FixedMemoryStream stream { data };
|
FixedMemoryStream stream { data };
|
||||||
return adopt_nonnull_own_or_enomem(new (nothrow) DDSImageDecoderPlugin(move(stream)));
|
auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) DDSImageDecoderPlugin(move(stream))));
|
||||||
|
TRY(decode_header(*plugin->m_context));
|
||||||
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DDSImageDecoderPlugin::is_animated()
|
bool DDSImageDecoderPlugin::is_animated()
|
||||||
|
|
|
@ -243,7 +243,6 @@ public:
|
||||||
|
|
||||||
virtual IntSize size() override;
|
virtual IntSize size() override;
|
||||||
|
|
||||||
virtual ErrorOr<void> initialize() override;
|
|
||||||
virtual bool is_animated() override;
|
virtual bool is_animated() override;
|
||||||
virtual size_t loop_count() override;
|
virtual size_t loop_count() override;
|
||||||
virtual size_t frame_count() override;
|
virtual size_t frame_count() override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue