mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 05:17:34 +00:00
LibCompress/LZW: Support BigEndianInputBitStream
Let's templatize the LZWDecoder, so it can take both BigEndian and LittleEndian variant.
This commit is contained in:
parent
6f059c9d60
commit
0c0d7e8fd3
1 changed files with 5 additions and 3 deletions
|
@ -8,6 +8,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/BitStream.h>
|
||||
#include <AK/Concepts.h>
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/IntegralMath.h>
|
||||
|
@ -15,12 +16,13 @@
|
|||
|
||||
namespace Compress {
|
||||
|
||||
template<InputBitStream InputStream>
|
||||
class LZWDecoder {
|
||||
private:
|
||||
static constexpr int max_code_size = 12;
|
||||
|
||||
public:
|
||||
explicit LZWDecoder(MaybeOwned<LittleEndianInputBitStream> lzw_stream, u8 min_code_size)
|
||||
explicit LZWDecoder(MaybeOwned<InputStream> lzw_stream, u8 min_code_size)
|
||||
: m_bit_stream(move(lzw_stream))
|
||||
, m_code_size(min_code_size)
|
||||
, m_original_code_size(min_code_size)
|
||||
|
@ -53,7 +55,7 @@ public:
|
|||
|
||||
ErrorOr<u16> next_code()
|
||||
{
|
||||
m_current_code = TRY(m_bit_stream->read_bits<u16>(m_code_size));
|
||||
m_current_code = TRY(m_bit_stream->template read_bits<u16>(m_code_size));
|
||||
|
||||
if (m_current_code > m_code_table.size()) {
|
||||
dbgln_if(GIF_DEBUG, "Corrupted LZW stream, invalid code: {}, code table size: {}",
|
||||
|
@ -107,7 +109,7 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
MaybeOwned<LittleEndianInputBitStream> m_bit_stream;
|
||||
MaybeOwned<InputStream> m_bit_stream;
|
||||
|
||||
Vector<Vector<u8>> m_code_table {};
|
||||
Vector<Vector<u8>> m_original_code_table {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue