diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /third_party/jpeg-xl/lib/jxl/dec_huffman.cc | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/jpeg-xl/lib/jxl/dec_huffman.cc')
-rw-r--r-- | third_party/jpeg-xl/lib/jxl/dec_huffman.cc | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/third_party/jpeg-xl/lib/jxl/dec_huffman.cc b/third_party/jpeg-xl/lib/jxl/dec_huffman.cc index 05b275773a..849b1a5f64 100644 --- a/third_party/jpeg-xl/lib/jxl/dec_huffman.cc +++ b/third_party/jpeg-xl/lib/jxl/dec_huffman.cc @@ -5,6 +5,7 @@ #include "lib/jxl/dec_huffman.h" +#include <jxl/types.h> #include <string.h> /* for memset */ #include <vector> @@ -22,9 +23,9 @@ static const uint8_t kCodeLengthCodeOrder[kCodeLengthCodes] = { static const uint8_t kDefaultCodeLength = 8; static const uint8_t kCodeLengthRepeatCode = 16; -int ReadHuffmanCodeLengths(const uint8_t* code_length_code_lengths, - int num_symbols, uint8_t* code_lengths, - BitReader* br) { +JXL_BOOL ReadHuffmanCodeLengths(const uint8_t* code_length_code_lengths, + int num_symbols, uint8_t* code_lengths, + BitReader* br) { int symbol = 0; uint8_t prev_code_len = kDefaultCodeLength; int repeat = 0; @@ -38,7 +39,7 @@ int ReadHuffmanCodeLengths(const uint8_t* code_length_code_lengths, } if (!BuildHuffmanTable(table, 5, code_length_code_lengths, kCodeLengthCodes, &counts[0])) { - return 0; + return JXL_FALSE; } while (symbol < num_symbols && space > 0) { @@ -47,7 +48,7 @@ int ReadHuffmanCodeLengths(const uint8_t* code_length_code_lengths, br->Refill(); p += br->PeekFixedBits<5>(); br->Consume(p->bits); - code_len = (uint8_t)p->value; + code_len = static_cast<uint8_t>(p->value); if (code_len < kCodeLengthRepeatCode) { repeat = 0; code_lengths[symbol++] = code_len; @@ -72,12 +73,13 @@ int ReadHuffmanCodeLengths(const uint8_t* code_length_code_lengths, repeat -= 2; repeat <<= extra_bits; } - repeat += (int)br->ReadBits(extra_bits) + 3; + repeat += static_cast<int>(br->ReadBits(extra_bits) + 3); repeat_delta = repeat - old_repeat; if (symbol + repeat_delta > num_symbols) { return 0; } - memset(&code_lengths[symbol], repeat_code_len, (size_t)repeat_delta); + memset(&code_lengths[symbol], repeat_code_len, + static_cast<size_t>(repeat_delta)); symbol += repeat_delta; if (repeat_code_len != 0) { space -= repeat_delta << (15 - repeat_code_len); @@ -85,10 +87,10 @@ int ReadHuffmanCodeLengths(const uint8_t* code_length_code_lengths, } } if (space != 0) { - return 0; + return JXL_FALSE; } - memset(&code_lengths[symbol], 0, (size_t)(num_symbols - symbol)); - return true; + memset(&code_lengths[symbol], 0, static_cast<size_t>(num_symbols - symbol)); + return JXL_TRUE; } static JXL_INLINE bool ReadSimpleCode(size_t alphabet_size, BitReader* br, @@ -176,7 +178,7 @@ static JXL_INLINE bool ReadSimpleCode(size_t alphabet_size, BitReader* br, const uint32_t goal_size = 1u << kHuffmanTableBits; while (table_size != goal_size) { memcpy(&table[table_size], &table[0], - (size_t)table_size * sizeof(table[0])); + static_cast<size_t>(table_size) * sizeof(table[0])); table_size <<= 1; } @@ -212,16 +214,17 @@ bool HuffmanDecodingData::ReadFromBitStream(size_t alphabet_size, br->Refill(); p += br->PeekFixedBits<4>(); br->Consume(p->bits); - v = (uint8_t)p->value; + v = static_cast<uint8_t>(p->value); code_length_code_lengths[code_len_idx] = v; if (v != 0) { space -= (32u >> v); ++num_codes; } } - bool ok = (num_codes == 1 || space == 0) && - ReadHuffmanCodeLengths(code_length_code_lengths, alphabet_size, - &code_lengths[0], br); + bool ok = + (num_codes == 1 || space == 0) && + FROM_JXL_BOOL(ReadHuffmanCodeLengths( + code_length_code_lengths, alphabet_size, code_lengths.data(), br)); if (!ok) return false; uint16_t counts[16] = {0}; @@ -230,7 +233,7 @@ bool HuffmanDecodingData::ReadFromBitStream(size_t alphabet_size, } table_.resize(alphabet_size + 376); uint32_t table_size = - BuildHuffmanTable(table_.data(), kHuffmanTableBits, &code_lengths[0], + BuildHuffmanTable(table_.data(), kHuffmanTableBits, code_lengths.data(), alphabet_size, &counts[0]); table_.resize(table_size); return (table_size > 0); |