Class Method Details

.decode(data) ⇒ Object

# File 'lib/pdf/reader/lzw.rb', line 83defself.decode(data)stream=BitStream.newdata.to_s,9# size of codes between 9 and 12 bits
result=''until(code=stream.read)==CODE_EODifcode==CODE_CLEAR_TABLEstream.set_bits_in_chunk(9)string_table=StringTable.newcode=stream.readbreakifcode==CODE_EODresult<<string_table[code]old_code=codeelsestring=string_table[code]ifstringresult<<stringstring_table.addcreate_new_string(string_table,old_code,code)old_code=codeelsenew_string=create_new_string(string_table,old_code,old_code)result<<new_stringstring_table.addnew_stringold_code=codeend#increase de size of the codes when limit reached
ifstring_table.string_table_pos==511stream.set_bits_in_chunk(10)elsifstring_table.string_table_pos==1023stream.set_bits_in_chunk(11)elsifstring_table.string_table_pos==2047stream.set_bits_in_chunk(12)endendendresultend