module ChunkyPNG::Canvas::PNGEncoding
def to_datastream(constraints = {})
- See: ChunkyPNG::Canvas::PNGEncoding#determine_png_encoding -
Returns:
-
(ChunkyPNG::Datastream)
- The PNG datastream containing the encoded canvas.
Options Hash:
(**constraints)
-
:bit_depth
(Fixnum
) -- The bit depth to use. This option is only used -
:compression
(Fixnum
) -- The compression level for Zlib. This can be a -
:interlace
(true, false
) -- Whether to use interlacing. -
:color_mode
(Fixnum
) -- The color mode to use. Use one of the
Parameters:
-
constraints
(Hash, Symbol
) -- The constraints to use when encoding the canvas.
def to_datastream(constraints = {}) encoding = determine_png_encoding(constraints) ds = Datastream.new ds.header_chunk = Chunk::Header.new(:width => width, :height => height, :color => encoding[:color_mode], :depth => encoding[:bit_depth], :interlace => encoding[:interlace]) if encoding[:color_mode] == ChunkyPNG::COLOR_INDEXED ds.palette_chunk = encoding_palette.to_plte_chunk ds.transparency_chunk = encoding_palette.to_trns_chunk unless encoding_palette.opaque? end data = encode_png_pixelstream(encoding[:color_mode], encoding[:bit_depth], encoding[:interlace], encoding[:filtering]) ds.data_chunks = Chunk::ImageData.split_in_chunks(data, encoding[:compression]) ds.end_chunk = Chunk::End.new return ds end