Class: PNG

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

Overview

need to add a new method to PNG to get at the raw bytes as the png library only writes to disk

Instance Method Summary collapse

Instance Method Details

#raw_bytesObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/HGR.rb', line 9

def raw_bytes
	bytes=""
	bytes<< [137, 80, 78, 71, 13, 10, 26, 10].pack("C*") # PNG signature
	bytes<< PNG.chunk('IHDR',
		[ @height, @width, @bits, 6, 0, 0, 0 ].pack("N2C5"))
	# 0 == filter type code "none"
	data = @data.map { |row| [0] + row.map { |p| p.values } }.flatten
	bytes<< PNG.chunk('IDAT', Zlib::Deflate.deflate(data.pack("C*"), 9))
	bytes<< PNG.chunk('IEND', '')
	bytes
end