Skip to content

Commit

Permalink
fix: crack_codes was still incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Jul 20, 2024
1 parent 221754f commit 38ef0f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions automated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,18 @@ def test_zstack_ones():
binary2 = crackle.compress(np.ones([512,512,sz], dtype=np.uint32))
assert binary == binary2

sz = 10

image = np.random.randint(0,255, size=(64, 64, sz), dtype=np.uint8)
binary = crackle.zstack([
image[:,:,2*z:2*z+2]
for z in range(sz // 2)
])

recovered = crackle.decompress(binary)
assert np.all(image == recovered)





Expand Down
4 changes: 2 additions & 2 deletions crackle/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,13 @@ def crack_codes(binary:bytes) -> np.ndarray:
header = CrackleHeader.frombytes(binary)
comps = components(binary)
z_index = np.frombuffer(comps["z_index"], dtype=np.uint32)
z_index = np.cumsum(z_index) - z_index[0]
z_index = np.concatenate([ [0], z_index ])
z_index = np.cumsum(z_index)
z_index += (
len(header.tobytes())
+ header.num_label_bytes
+ header.sz * header.z_index_width()
)
z_index = np.concatenate((z_index, [ len(binary) ]))
z_index = z_index.astype(np.uint64)

codes = []
Expand Down

0 comments on commit 38ef0f0

Please sign in to comment.