Class: Btape::GifEncoder::LzwCompressor

Inherits:
Object
  • Object
show all
Defined in:
lib/btape/lzw_compressor.rb

Overview

Variable-width LZW compression of a flat array of palette indices, producing (code, width) pairs ready for bit-packing into a GIF stream.

Defined Under Namespace

Classes: State

Constant Summary collapse

CLEAR_CODE =
256
FINISH_CODE =
257
MAX_CODE_WIDTH =
12
MAX_DICTIONARY_SIZE =
1 << MAX_CODE_WIDTH

Instance Method Summary collapse

Instance Method Details

#call(pixels, &emit) ⇒ Object



18
19
20
21
22
23
# File 'lib/btape/lzw_compressor.rb', line 18

def call(pixels, &emit)
  emit.call(CLEAR_CODE, 9)
  return emit.call(FINISH_CODE, 9) if pixels.empty?

  compress(pixels, emit)
end