lib/chunky_png/datastream.rb in chunky_png-0.0.1 vs lib/chunky_png/datastream.rb in chunky_png-0.0.2
- old
+ new
@@ -5,24 +5,26 @@
SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10].pack('C8')
attr_accessor :header_chunk
attr_accessor :other_chunks
attr_accessor :palette_chunk
+ attr_accessor :transparency_chunk
attr_accessor :data_chunks
attr_accessor :end_chunk
def self.read(io)
verify_signature!(io)
ds = self.new
until io.eof?
chunk = ChunkyPNG::Chunk.read(io)
case chunk
- when ChunkyPNG::Chunk::Header then ds.header_chunk = chunk
- when ChunkyPNG::Chunk::Palette then ds.palette_chunk = chunk
- when ChunkyPNG::Chunk::ImageData then ds.data_chunks << chunk
- when ChunkyPNG::Chunk::End then ds.end_chunk = chunk
+ when ChunkyPNG::Chunk::Header then ds.header_chunk = chunk
+ when ChunkyPNG::Chunk::Palette then ds.palette_chunk = chunk
+ when ChunkyPNG::Chunk::Transparency then ds.transparency_chunk = chunk
+ when ChunkyPNG::Chunk::ImageData then ds.data_chunks << chunk
+ when ChunkyPNG::Chunk::End then ds.end_chunk = chunk
else ds.other_chunks << chunk
end
end
return ds
end
@@ -33,11 +35,12 @@
end
def chunks
cs = [header_chunk]
cs += other_chunks
- cs << palette_chunk if palette_chunk
+ cs << palette_chunk if palette_chunk
+ cs << transparency_chunk if transparency_chunk
cs += data_chunks
cs << end_chunk
return cs
end
@@ -60,13 +63,9 @@
def pixel_matrix=(pixel_matrix)
@pixel_matrix = pixel_matrix
end
def pixel_matrix
- @pixel_matrix ||= begin
- data = data_chunks.map(&:content).join('')
- streamdata = Zlib::Inflate.inflate(data)
- matrix = ChunkyPNG::PixelMatrix.load(header, streamdata)
- end
+ @pixel_matrix ||= ChunkyPNG::PixelMatrix.decode(self)
end
end
end