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 272 def self.combine_chunks(data_chunks) 273 zstream = Zlib::Inflate.new 274 data_chunks.each { |c| zstream << c.content } 275 inflated = zstream.finish 276 zstream.close 277 inflated 278 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 286 def self.split_in_chunks(data, level = Zlib::DEFAULT_COMPRESSION, chunk_size = 2147483647) 287 streamdata = Zlib::Deflate.deflate(data, level) 288 # TODO: Split long streamdata over multiple chunks 289 [ChunkyPNG::Chunk::ImageData.new("IDAT", streamdata)] 290 end