Skip to content

Commit

Permalink
correctly estimate symbol bit width for cases with 2,4,8,16... unique…
Browse files Browse the repository at this point in the history
… symbols
  • Loading branch information
JIy3AHKO committed Jun 4, 2024
1 parent 7c8a918 commit a7899b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ std::vector<uint32_t> get_unique_symbols(const std::vector<BaseRLELine*>& rle_li
}

uint8_t estimate_symbol_bit_width(const std::vector<uint32_t>& unique_symbols) {
return get_bit_width(unique_symbols.size());
return get_bit_width(unique_symbols.size() - 1);
}


Expand Down
16 changes: 16 additions & 0 deletions tests/test_fastmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,19 @@ def test_info_on_small_file_produces_error(self):

with self.assertRaises(ValueError):
pf.info(f.name)


class TestSymbolBitWidth(unittest.TestCase):
def test_info_for_binary_image_returns_1bits_symbol_bit_width(self):
mask = np.array([[0, 1], [1, 0]], dtype=np.uint8)
with TempFile() as f:
pf.write(f, mask)
info = pf.info(f)
self.assertEqual(info['symbol_bit_width'], 1)

def test_info_for_256color_image_returns_8bits_symbol_bit_width(self):
mask = np.arange(256, dtype=np.uint8).reshape(16, 16)
with TempFile() as f:
pf.write(f, mask)
info = pf.info(f)
self.assertEqual(info['symbol_bit_width'], 8)

0 comments on commit a7899b6

Please sign in to comment.