lib/chunky_png/canvas/png_decoding.rb
# Decodes the Canvas from a PNG datastream instance.
# @param [ChunkyPNG::Datastream] ds The datastream to decode.
# @return [ChunkyPNG::Canvas] The canvas decoded from the PNG datastream.
Decodes the Canvas from a PNG datastream instance.
Decodes the Canvas from a PNG datastream instance .
def from_datastream(ds)
        width      = ds.header_chunk.width
        height     = ds.header_chunk.height
        color_mode = ds.header_chunk.color
        interlace  = ds.header_chunk.interlace
        depth      = ds.header_chunk.depth
        if width == 0 || height == 0
          raise ExpectationFailed, "Invalid image size, width: #{width}, height: #{height}"
        end
        decoding_palette, transparent_color = nil, nil
        case color_mode
          when ChunkyPNG::COLOR_INDEXED
            decoding_palette = ChunkyPNG::Palette.from_chunks(ds.palette_chunk, ds.transparency_chunk)
          when ChunkyPNG::COLOR_TRUECOLOR
            transparent_color = ds.transparency_chunk.truecolor_entry(depth) if ds.transparency_chunk
          when ChunkyPNG::COLOR_GRAYSCALE
            transparent_color = ds.transparency_chunk.grayscale_entry(depth) if ds.transparency_chunk
        end
        decode_png_pixelstream(ds.imagedata, width, height, color_mode, depth, interlace, decoding_palette, transparent_color)
      end
def from_datastream ( ds ) width = ds . header_chunk . width height = ds . header_chunk . height color_mode = ds . header_chunk . color interlace = ds . header_chunk . interlace depth = ds . header_chunk . depth if width == 0 || height == 0 raise ExpectationFailed , "Invalid image size, width: #{width}, height: #{height}" end decoding_palette , transparent_color = nil , nil case color_mode when ChunkyPNG :: COLOR_INDEXED decoding_palette = ChunkyPNG :: Palette . from_chunks ( ds . palette_chunk , ds . transparency_chunk ) when ChunkyPNG :: COLOR_TRUECOLOR transparent_color = ds . transparency_chunk . truecolor_entry ( depth ) if ds . transparency_chunk when ChunkyPNG :: COLOR_GRAYSCALE transparent_color = ds . transparency_chunk . grayscale_entry ( depth ) if ds . transparency_chunk end decode_png_pixelstream ( ds . imagedata , width , height , color_mode , depth , interlace , decoding_palette , transparent_color ) end
Decodes the Canvas from a PNG datastream instance.
Decodes the Canvas from a PNG datastream instance .
The canvas decoded from the PNG datastream.
The canvas decoded from the PNG datastream .
ChunkyPNG::Canvas
ds
<not_specific>
<not_specific>
ds The datastream to decode.
ds The datastream to decode .