mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-07 08:29:58 +00:00
LibGfx/JBIG2: Pass Context to get_next_bit() instead of to initialize()
The context can vary for every bit we read. This does not affect the one use in the test which reuses the same context for all bits, but it is necessary for future changes.
This commit is contained in:
parent
e0713376a0
commit
b8f80501ec
|
@ -368,13 +368,13 @@ TEST_CASE(test_jbig2_arithmetic_decoder)
|
|||
|
||||
// "For this entire test, a single value of CX is used. I(CX) is initially 0 and MPS(CX) is initially 0."
|
||||
Gfx::JBIG2::ArithmeticDecoder::Context context { 0, 0 };
|
||||
auto decoder = MUST(Gfx::JBIG2::ArithmeticDecoder::initialize(input, context));
|
||||
auto decoder = MUST(Gfx::JBIG2::ArithmeticDecoder::initialize(input));
|
||||
|
||||
for (auto expected : output) {
|
||||
u8 actual = 0;
|
||||
for (size_t i = 0; i < 8; ++i) {
|
||||
actual <<= 1;
|
||||
actual |= static_cast<u8>(decoder.get_next_bit());
|
||||
actual |= static_cast<u8>(decoder.get_next_bit(context));
|
||||
}
|
||||
EXPECT_EQ(actual, expected);
|
||||
}
|
||||
|
|
|
@ -77,16 +77,16 @@ constexpr auto qe_table = to_array<QeEntry>({
|
|||
{ 0x5601, 46, 46, 0 },
|
||||
});
|
||||
|
||||
ErrorOr<ArithmeticDecoder> ArithmeticDecoder::initialize(ReadonlyBytes data, Context context)
|
||||
ErrorOr<ArithmeticDecoder> ArithmeticDecoder::initialize(ReadonlyBytes data)
|
||||
{
|
||||
ArithmeticDecoder decoder { data };
|
||||
decoder.CX = context;
|
||||
decoder.INITDEC();
|
||||
return decoder;
|
||||
}
|
||||
|
||||
bool ArithmeticDecoder::get_next_bit()
|
||||
bool ArithmeticDecoder::get_next_bit(Context& context)
|
||||
{
|
||||
CX = &context;
|
||||
// Useful for comparing to Table H.1 – Encoder and decoder trace data.
|
||||
// dbg("I={} MPS={} A={:#x} C={:#x} CT={} B={:#x}", I(CX), MPS(CX), A, C, CT, B());
|
||||
u8 D = DECODE();
|
||||
|
|
|
@ -26,9 +26,9 @@ public:
|
|||
u8 is_mps; // "More probable symbol" (E.1.1). 0 or 1.
|
||||
};
|
||||
|
||||
static ErrorOr<ArithmeticDecoder> initialize(ReadonlyBytes data, Context context);
|
||||
static ErrorOr<ArithmeticDecoder> initialize(ReadonlyBytes data);
|
||||
|
||||
bool get_next_bit();
|
||||
bool get_next_bit(Context& context);
|
||||
|
||||
private:
|
||||
ArithmeticDecoder(ReadonlyBytes data)
|
||||
|
@ -63,9 +63,9 @@ private:
|
|||
|
||||
u8 CT; // Count of the number of bits in C.
|
||||
|
||||
Context CX;
|
||||
static u16& I(Context& cx) { return cx.I; }
|
||||
static u8& MPS(Context& cx) { return cx.is_mps; }
|
||||
Context* CX;
|
||||
static u16& I(Context* cx) { return cx->I; }
|
||||
static u8& MPS(Context* cx) { return cx->is_mps; }
|
||||
static u16 Qe(u16);
|
||||
static u8 NMPS(u16);
|
||||
static u8 NLPS(u16);
|
||||
|
|
Loading…
Reference in a new issue