summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2023-02-25 20:08:00 -0500
committerLinus Groh <mail@linusgroh.de>2023-02-26 15:54:22 +0100
commit9864963a08956227d18778edcd6e3784580fa2f2 (patch)
tree441e9b67e043d76f274d2f780a5731dd13aa0e84
parent15d2e8ca2ba614038469b5e8ab57ecd05b732a5e (diff)
downloadserenity-9864963a08956227d18778edcd6e3784580fa2f2.zip
LibGfx: In WebP, rename decode_webp_size to decode_webp_first_chunk
...and make it store the decoded details in the context.
-rw-r--r--Userland/Libraries/LibGfx/WebPLoader.cpp37
1 files changed, 21 insertions, 16 deletions
diff --git a/Userland/Libraries/LibGfx/WebPLoader.cpp b/Userland/Libraries/LibGfx/WebPLoader.cpp
index c66f6b6ae1..99b33bae2a 100644
--- a/Userland/Libraries/LibGfx/WebPLoader.cpp
+++ b/Userland/Libraries/LibGfx/WebPLoader.cpp
@@ -87,7 +87,7 @@ struct WebPLoadingContext {
Error,
HeaderDecoded,
FirstChunkRead,
- SizeDecoded,
+ FirstChunkDecoded,
ChunksDecoded,
BitmapDecoded,
};
@@ -102,6 +102,11 @@ struct WebPLoadingContext {
// Either 'VP8 ' (simple lossy file), 'VP8L' (simple lossless file), or 'VP8X' (extended file).
Optional<Chunk> first_chunk;
+ union {
+ VP8Header vp8_header;
+ VP8LHeader vp8l_header;
+ VP8XHeader vp8x_header;
+ };
// If first_chunk is not a VP8X chunk, then only image_data_chunk is set and all the other Chunks are not set.
@@ -384,30 +389,30 @@ static ErrorOr<void> read_webp_first_chunk(WebPLoadingContext& context)
return {};
}
-static ErrorOr<void> decode_webp_size(WebPLoadingContext& context)
+static ErrorOr<void> decode_webp_first_chunk(WebPLoadingContext& context)
{
- if (context.state >= WebPLoadingContext::State::SizeDecoded)
+ if (context.state >= WebPLoadingContext::State::FirstChunkDecoded)
return {};
if (context.state < WebPLoadingContext::FirstChunkRead)
TRY(read_webp_first_chunk(context));
if (context.first_chunk->type == FourCC("VP8 ")) {
- auto header = TRY(decode_webp_chunk_VP8_header(context, context.first_chunk.value()));
- context.size = IntSize { header.width, header.height };
- context.state = WebPLoadingContext::State::SizeDecoded;
+ context.vp8_header = TRY(decode_webp_chunk_VP8_header(context, context.first_chunk.value()));
+ context.size = IntSize { context.vp8_header.width, context.vp8_header.height };
+ context.state = WebPLoadingContext::State::FirstChunkDecoded;
return {};
}
if (context.first_chunk->type == FourCC("VP8L")) {
- auto header = TRY(decode_webp_chunk_VP8L_header(context, context.first_chunk.value()));
- context.size = IntSize { header.width, header.height };
- context.state = WebPLoadingContext::State::SizeDecoded;
+ context.vp8l_header = TRY(decode_webp_chunk_VP8L_header(context, context.first_chunk.value()));
+ context.size = IntSize { context.vp8l_header.width, context.vp8l_header.height };
+ context.state = WebPLoadingContext::State::FirstChunkDecoded;
return {};
}
VERIFY(context.first_chunk->type == FourCC("VP8X"));
- auto header = TRY(decode_webp_chunk_VP8X(context, context.first_chunk.value()));
- context.size = IntSize { header.width, header.height };
- context.state = WebPLoadingContext::State::SizeDecoded;
+ context.vp8x_header = TRY(decode_webp_chunk_VP8X(context, context.first_chunk.value()));
+ context.size = IntSize { context.vp8x_header.width, context.vp8x_header.height };
+ context.state = WebPLoadingContext::State::FirstChunkDecoded;
return {};
}
@@ -416,8 +421,8 @@ static ErrorOr<void> decode_webp_chunks(WebPLoadingContext& context)
if (context.state >= WebPLoadingContext::State::ChunksDecoded)
return {};
- if (context.state < WebPLoadingContext::SizeDecoded)
- TRY(decode_webp_size(context));
+ if (context.state < WebPLoadingContext::FirstChunkDecoded)
+ TRY(decode_webp_first_chunk(context));
if (context.first_chunk->type == FourCC("VP8X"))
return decode_webp_extended(context, context.chunks_cursor);
@@ -439,8 +444,8 @@ IntSize WebPImageDecoderPlugin::size()
if (m_context->state == WebPLoadingContext::State::Error)
return {};
- if (m_context->state < WebPLoadingContext::State::SizeDecoded) {
- if (decode_webp_size(*m_context).is_error())
+ if (m_context->state < WebPLoadingContext::State::FirstChunkDecoded) {
+ if (decode_webp_first_chunk(*m_context).is_error())
return {};
}