mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-06-25 11:14:42 -04:00
Update gdgifexporter (#299)
This commit is contained in:
parent
da656df5b7
commit
e171e2ee65
5 changed files with 55 additions and 24 deletions
|
@ -3,29 +3,22 @@ extends Node
|
|||
|
||||
class LSB_LZWBitPacker:
|
||||
var bit_index: int = 0
|
||||
var byte: int = 0
|
||||
var stream: int = 0
|
||||
|
||||
var chunks: PoolByteArray = PoolByteArray([])
|
||||
|
||||
func get_bit(value: int, index: int) -> int:
|
||||
return (value >> index) & 1
|
||||
|
||||
func set_bit(value: int, index: int) -> int:
|
||||
return value | (1 << index)
|
||||
|
||||
func put_byte():
|
||||
chunks.append(byte)
|
||||
bit_index = 0
|
||||
byte = 0
|
||||
chunks.append(stream & 0xff)
|
||||
bit_index -= 8
|
||||
stream >>= 8
|
||||
|
||||
func write_bits(value: int, bits_count: int) -> void:
|
||||
for i in range(bits_count):
|
||||
if self.get_bit(value, i) == 1:
|
||||
byte = self.set_bit(byte, bit_index)
|
||||
|
||||
bit_index += 1
|
||||
if bit_index == 8:
|
||||
self.put_byte()
|
||||
value &= (1 << bits_count) - 1
|
||||
value <<= bit_index
|
||||
stream |= value
|
||||
bit_index += bits_count
|
||||
while bit_index >= 8:
|
||||
self.put_byte()
|
||||
|
||||
func pack() -> PoolByteArray:
|
||||
if bit_index != 0:
|
||||
|
@ -34,5 +27,5 @@ class LSB_LZWBitPacker:
|
|||
|
||||
func reset() -> void:
|
||||
bit_index = 0
|
||||
byte = 0
|
||||
stream = 0
|
||||
chunks = PoolByteArray([])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue