// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
for (size_t n_bytes = 0; n_bytes < size; n_bytes++) {
BitReader br(Bytes(data.data(), n_bytes)); // Read all the bits for (size_t i = 0; i < n_bytes * kBitsPerByte; i++) {
ASSERT_EQ(br.ReadBits(1), 1u) << "n_bytes=" << n_bytes << " i=" << i;
}
// PEEK more than the declared size - all will be zero. Cannot consume. for (size_t i = 0; i < BitReader::kMaxBitsPerCall; i++) {
ASSERT_EQ(br.PeekBits(i), 0u)
<< "size=" << size << "n_bytes=" << n_bytes << " i=" << i;
}
EXPECT_TRUE(br.Close());
}
}
}
struct Symbol {
uint32_t num_bits;
uint32_t value;
};
// Verifies byte order and different groupings of bits.
TEST(BitReaderTest, TestOrder) {
JxlMemoryManager* memory_manager = jxl::test::MemoryManager();
constexpr size_t kMaxBits = 16;
// u(1) - bits written into LSBs of first byte
{
BitWriter writer{memory_manager};
ASSERT_TRUE(writer.WithMaxBits(kMaxBits, LayerType::Header, nullptr, [&] { for (size_t i = 0; i < 5; ++i) {
writer.Write(1, 1);
} for (size_t i = 0; i < 5; ++i) {
writer.Write(1, 0);
} for (size_t i = 0; i < 6; ++i) {
writer.Write(1, 1);
}
// u(8) - get bytes in the same order
{
BitWriter writer{memory_manager};
ASSERT_TRUE(writer.WithMaxBits(kMaxBits, LayerType::Header, nullptr, [&] {
writer.Write(8, 0xF8);
writer.Write(8, 0x3F);
reader2 = std::move(reader1); // From this point reader1 is invalid, but can continue to access reader2 // and we don't need to call Close() on reader1.
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.