class ChunkyPNG::Chunk::ImageData
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.
Public Class Methods
Combines the list of IDAT chunks and inflates their contents to produce the pixeldata stream for the image.
@return [String] The combined, inflated pixeldata as binary string
# File lib/chunky_png/chunk.rb, line 271 def self.combine_chunks(data_chunks) zstream = Zlib::Inflate.new data_chunks.each { |c| zstream << c.content } inflated = zstream.finish zstream.close inflated end
Splits and compresses a pixeldata stream into a list of IDAT chunks.
@param data [String] The binary string of pixeldata @param level [Integer] The compression level to use. @param chunk_size [Integer] The maximum size of a chunk. @return Array<ChunkyPNG::Chunk::ImageData> The list of IDAT chunks.
# File lib/chunky_png/chunk.rb, line 285 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