Coverage Report

Created: 2025-06-16 07:00

/src/libjxl/lib/jxl/dec_bit_reader.cc
Line
Count
Source
1
// Copyright (c) the JPEG XL Project Authors. All rights reserved.
2
//
3
// Use of this source code is governed by a BSD-style
4
// license that can be found in the LICENSE file.
5
6
#include "lib/jxl/dec_bit_reader.h"
7
8
#include <cstddef>
9
#include <cstdint>
10
11
#include "lib/jxl/base/common.h"
12
#include "lib/jxl/base/status.h"
13
14
namespace jxl {
15
16
70.3M
void BitReader::BoundsCheckedRefill() {
17
70.3M
  const uint8_t* end = end_minus_8_ + 8;
18
19
  // Read whole bytes until we have [56, 64) bits (same as LoadLE64)
20
70.5M
  for (; bits_in_buf_ < 64 - kBitsPerByte; bits_in_buf_ += kBitsPerByte) {
21
7.57M
    if (next_byte_ >= end) break;
22
176k
    buf_ |= static_cast<uint64_t>(*next_byte_++) << bits_in_buf_;
23
176k
  }
24
70.3M
  JXL_DASSERT(bits_in_buf_ < 64);
25
26
  // Add extra bytes as 0 at the end of the stream in the bit_buffer_. If
27
  // these bits are read, Close() will return a failure.
28
70.3M
  size_t extra_bytes = (63 - bits_in_buf_) / kBitsPerByte;
29
70.3M
  overread_bytes_ += extra_bytes;
30
70.3M
  bits_in_buf_ += extra_bytes * kBitsPerByte;
31
32
70.3M
  JXL_DASSERT(bits_in_buf_ < 64);
33
70.3M
  JXL_DASSERT(bits_in_buf_ >= 56);
34
70.3M
}
35
36
}  // namespace jxl