Cleanups.

This commit is contained in:
Relintai 2022-12-10 17:01:11 +01:00
parent 38ac3c7b7d
commit ec7686a450

View File

@ -183,6 +183,7 @@ func decompress_lzw(code_stream_data: PoolByteArray, min_code_size: int, colors:
prevcode = code
elif code == clear_code_index + 1: # Stop when detected EOI Code.
break
# is CODE in the code table?
var code_entry: CodeEntry = code_table.get(code)
if code_entry != null: # if YES
@ -193,35 +194,20 @@ func decompress_lzw(code_stream_data: PoolByteArray, min_code_size: int, colors:
# warning-ignore:return_value_discarded
# add {PREVCODE} + k to the code table
var prev_code_entry: CodeEntry = code_table.get(prevcode)
if prev_code_entry:
code_table.add(prev_code_entry.add(k))
else:
code_table.add(k)
# set PREVCODE = CODE
prevcode = code
else: # if NO
# let k be the first index of {PREVCODE}
var prevcode_entry: CodeEntry = code_table.get(prevcode)
var k: CodeEntry
if prevcode_entry:
k = CodeEntry.new([prevcode_entry.sequence[0]])
else:
k = CodeEntry.new([ code ])
var k: CodeEntry = CodeEntry.new([prevcode_entry.sequence[0]])
# output {PREVCODE} + k to index stream
index_stream.append_array(prevcode_entry.add(k).sequence)
# output {PREVCODE} + k to index stream
if prevcode_entry:
index_stream.append_array(prevcode_entry.add(k).sequence)
else:
index_stream.append_array(k.sequence)
# add {PREVCODE} + k to code table
# warning-ignore:return_value_discarded
if prevcode_entry:
code_table.add(prevcode_entry.add(k))
else:
code_table.add(k)
# set PREVCODE = CODE
prevcode = code