Skip to content

Commit

Permalink
Fix LZW table entries on 32-bit systems
Browse files Browse the repository at this point in the history
  • Loading branch information
kimikage committed May 31, 2024
1 parent 377bda2 commit f3fa61a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TiffImages"
uuid = "731e570b-9d59-4bfa-96dc-6df516fadf69"
authors = ["Tamas Nagy <[email protected]>"]
version = "0.10.0"
version = "0.10.1"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand Down
7 changes: 4 additions & 3 deletions src/compression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function lzw_decode!(io, arr)
CLEAR_CODE::Int = 256 + 1
EOI_CODE::Int = 257 + 1
TABLE_ENTRY_LENGTH_BITS::Int = 16
TABLE_ENTRY_OFFSET_BITS::Int = 8 * sizeof(Int) - TABLE_ENTRY_LENGTH_BITS

output_size = length(arr)

Expand All @@ -54,9 +55,9 @@ function lzw_decode!(io, arr)
table_pointer::Ptr{UInt8} = reinterpret(Ptr{UInt8}, Libc.malloc(table_size)) # table of strings
table_offsets_pointer::Ptr{Int} = reinterpret(Ptr{Int}, Libc.malloc(sizeof(Int) * 4097)) # offsets into table

@inline create_table_entry(length, offset) = Base.shl_int(length, (64 - TABLE_ENTRY_LENGTH_BITS)) | offset
@inline table_entry_length(table_entry) = Base.lshr_int(table_entry, 64 - TABLE_ENTRY_LENGTH_BITS)
@inline table_entry_offset(table_entry) = table_entry & (Base.shl_int(1, 64 - TABLE_ENTRY_LENGTH_BITS) - 1)
@inline create_table_entry(length, offset) = Base.shl_int(length, TABLE_ENTRY_OFFSET_BITS) | offset
@inline table_entry_length(table_entry) = Base.lshr_int(table_entry, TABLE_ENTRY_OFFSET_BITS)
@inline table_entry_offset(table_entry) = table_entry & (Base.shl_int(1, TABLE_ENTRY_OFFSET_BITS) - 1)

try
# InitializeTable();
Expand Down

0 comments on commit f3fa61a

Please sign in to comment.