Class: ChunkyPNG::Chunk::ImageData
- Defined in:
- lib/chunky_png/chunk.rb
Overview
An image data (IDAT) chunk holds (part of) the compressed image pixel data.
The data of an image can be split over multiple chunks, which will have to be combined and inflated in order to decode an image. See {{.combine_chunks} to combine chunks to decode, and {{.split_in_chunks} for encoding a pixeldata stream into IDAT chunks.
Instance Attribute Summary
Attributes inherited from Generic
Attributes inherited from Base
Class Method Summary collapse
-
.combine_chunks(data_chunks) ⇒ String
Combines the list of IDAT chunks and inflates their contents to produce the pixeldata stream for the image.
-
.split_in_chunks(data, level = Zlib::DEFAULT_COMPRESSION, chunk_size = 2147483647) ⇒ Object
Splits and compresses a pixeldata stream into a list of IDAT chunks.
Methods inherited from Generic
Methods inherited from Base
#initialize, #write, #write_with_crc
Constructor Details
This class inherits a constructor from ChunkyPNG::Chunk::Generic
Class Method Details
.combine_chunks(data_chunks) ⇒ String
Combines the list of IDAT chunks and inflates their contents to produce the pixeldata stream for the image.
272 273 274 275 276 277 278 |
# File 'lib/chunky_png/chunk.rb', line 272 def self.combine_chunks(data_chunks) zstream = Zlib::Inflate.new data_chunks.each { |c| zstream << c.content } inflated = zstream.finish zstream.close inflated end |
.split_in_chunks(data, level = Zlib::DEFAULT_COMPRESSION, chunk_size = 2147483647) ⇒ Object
Splits and compresses a pixeldata stream into a list of IDAT chunks.
286 287 288 289 290 |
# File 'lib/chunky_png/chunk.rb', line 286 def self.split_in_chunks(data, level = Zlib::DEFAULT_COMPRESSION, chunk_size = 2147483647) streamdata = Zlib::Deflate.deflate(data, level) # TODO: Split long streamdata over multiple chunks [ChunkyPNG::Chunk::ImageData.new("IDAT", streamdata)] end |