mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:17:35 +00:00
LibGfx: In WebP, rename decode_webp_size to decode_webp_first_chunk
...and make it store the decoded details in the context.
This commit is contained in:
parent
15d2e8ca2b
commit
9864963a08
1 changed files with 21 additions and 16 deletions
|
@ -87,7 +87,7 @@ struct WebPLoadingContext {
|
||||||
Error,
|
Error,
|
||||||
HeaderDecoded,
|
HeaderDecoded,
|
||||||
FirstChunkRead,
|
FirstChunkRead,
|
||||||
SizeDecoded,
|
FirstChunkDecoded,
|
||||||
ChunksDecoded,
|
ChunksDecoded,
|
||||||
BitmapDecoded,
|
BitmapDecoded,
|
||||||
};
|
};
|
||||||
|
@ -102,6 +102,11 @@ struct WebPLoadingContext {
|
||||||
|
|
||||||
// Either 'VP8 ' (simple lossy file), 'VP8L' (simple lossless file), or 'VP8X' (extended file).
|
// Either 'VP8 ' (simple lossy file), 'VP8L' (simple lossless file), or 'VP8X' (extended file).
|
||||||
Optional<Chunk> first_chunk;
|
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.
|
// 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 {};
|
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 {};
|
return {};
|
||||||
|
|
||||||
if (context.state < WebPLoadingContext::FirstChunkRead)
|
if (context.state < WebPLoadingContext::FirstChunkRead)
|
||||||
TRY(read_webp_first_chunk(context));
|
TRY(read_webp_first_chunk(context));
|
||||||
|
|
||||||
if (context.first_chunk->type == FourCC("VP8 ")) {
|
if (context.first_chunk->type == FourCC("VP8 ")) {
|
||||||
auto header = TRY(decode_webp_chunk_VP8_header(context, context.first_chunk.value()));
|
context.vp8_header = TRY(decode_webp_chunk_VP8_header(context, context.first_chunk.value()));
|
||||||
context.size = IntSize { header.width, header.height };
|
context.size = IntSize { context.vp8_header.width, context.vp8_header.height };
|
||||||
context.state = WebPLoadingContext::State::SizeDecoded;
|
context.state = WebPLoadingContext::State::FirstChunkDecoded;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (context.first_chunk->type == FourCC("VP8L")) {
|
if (context.first_chunk->type == FourCC("VP8L")) {
|
||||||
auto header = TRY(decode_webp_chunk_VP8L_header(context, context.first_chunk.value()));
|
context.vp8l_header = TRY(decode_webp_chunk_VP8L_header(context, context.first_chunk.value()));
|
||||||
context.size = IntSize { header.width, header.height };
|
context.size = IntSize { context.vp8l_header.width, context.vp8l_header.height };
|
||||||
context.state = WebPLoadingContext::State::SizeDecoded;
|
context.state = WebPLoadingContext::State::FirstChunkDecoded;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
VERIFY(context.first_chunk->type == FourCC("VP8X"));
|
VERIFY(context.first_chunk->type == FourCC("VP8X"));
|
||||||
auto header = TRY(decode_webp_chunk_VP8X(context, context.first_chunk.value()));
|
context.vp8x_header = TRY(decode_webp_chunk_VP8X(context, context.first_chunk.value()));
|
||||||
context.size = IntSize { header.width, header.height };
|
context.size = IntSize { context.vp8x_header.width, context.vp8x_header.height };
|
||||||
context.state = WebPLoadingContext::State::SizeDecoded;
|
context.state = WebPLoadingContext::State::FirstChunkDecoded;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,8 +421,8 @@ static ErrorOr<void> decode_webp_chunks(WebPLoadingContext& context)
|
||||||
if (context.state >= WebPLoadingContext::State::ChunksDecoded)
|
if (context.state >= WebPLoadingContext::State::ChunksDecoded)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (context.state < WebPLoadingContext::SizeDecoded)
|
if (context.state < WebPLoadingContext::FirstChunkDecoded)
|
||||||
TRY(decode_webp_size(context));
|
TRY(decode_webp_first_chunk(context));
|
||||||
|
|
||||||
if (context.first_chunk->type == FourCC("VP8X"))
|
if (context.first_chunk->type == FourCC("VP8X"))
|
||||||
return decode_webp_extended(context, context.chunks_cursor);
|
return decode_webp_extended(context, context.chunks_cursor);
|
||||||
|
@ -439,8 +444,8 @@ IntSize WebPImageDecoderPlugin::size()
|
||||||
if (m_context->state == WebPLoadingContext::State::Error)
|
if (m_context->state == WebPLoadingContext::State::Error)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (m_context->state < WebPLoadingContext::State::SizeDecoded) {
|
if (m_context->state < WebPLoadingContext::State::FirstChunkDecoded) {
|
||||||
if (decode_webp_size(*m_context).is_error())
|
if (decode_webp_first_chunk(*m_context).is_error())
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue