mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:47:45 +00:00
LibGfx/JPEGXL: Factorize the code to read symbols from distributions
This will soon be used by the LZ77 decoder, so let's avoid some duplication.
This commit is contained in:
parent
3fdc000b90
commit
80cb377990
1 changed files with 16 additions and 11 deletions
|
@ -1208,17 +1208,7 @@ public:
|
||||||
TODO();
|
TODO();
|
||||||
|
|
||||||
// Read symbol from entropy coded stream using D[clusters[ctx]]
|
// Read symbol from entropy coded stream using D[clusters[ctx]]
|
||||||
u32 token {};
|
auto const token = TRY(read_symbol(stream, context));
|
||||||
TRY(m_distributions.visit(
|
|
||||||
[&](Vector<BrotliCanonicalCode> const& distributions) -> ErrorOr<void> {
|
|
||||||
token = TRY(distributions[m_clusters[context]].read_symbol(stream));
|
|
||||||
return {};
|
|
||||||
},
|
|
||||||
[&](Vector<ANSHistogram> const& distributions) -> ErrorOr<void> {
|
|
||||||
token = TRY(distributions[m_clusters[context]].read_symbol(stream, m_state));
|
|
||||||
return {};
|
|
||||||
}));
|
|
||||||
|
|
||||||
auto r = TRY(read_uint(stream, m_configs[m_clusters[context]], token));
|
auto r = TRY(read_uint(stream, m_configs[m_clusters[context]], token));
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -1276,6 +1266,21 @@ private:
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<u32> read_symbol(LittleEndianInputBitStream& stream, u32 context)
|
||||||
|
{
|
||||||
|
u32 token {};
|
||||||
|
TRY(m_distributions.visit(
|
||||||
|
[&](Vector<BrotliCanonicalCode> const& distributions) -> ErrorOr<void> {
|
||||||
|
token = TRY(distributions[m_clusters[context]].read_symbol(stream));
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
[&](Vector<ANSHistogram> const& distributions) -> ErrorOr<void> {
|
||||||
|
token = TRY(distributions[m_clusters[context]].read_symbol(stream, m_state));
|
||||||
|
return {};
|
||||||
|
}));
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<void> read_pre_clustered_distributions(LittleEndianInputBitStream& stream, u32 num_distrib)
|
ErrorOr<void> read_pre_clustered_distributions(LittleEndianInputBitStream& stream, u32 num_distrib)
|
||||||
{
|
{
|
||||||
// C.2.2 Distribution clustering
|
// C.2.2 Distribution clustering
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue