Parent

Included Modules

Class/Module Index [+]

Quicksearch

Origami::Filter::Flate

Class representing a Filter used to encode and decode data with zlib/Flate compression algorithm.

Public Class Methods

new(parameters = {}) click to toggle source

Create a new Flate Filter.

parameters

A hash of filter options (ignored).

# File lib/origami/filters/flate.rb, line 56
def initialize(parameters = {})
  super(DecodeParms.new(parameters))
end

Public Instance Methods

decode(stream) click to toggle source

Decodes data using zlib/Inflate decompression method.

stream

The data to decode.

# File lib/origami/filters/flate.rb, line 80
def decode(stream)
  
  zlib_stream = Zlib::Inflate.new
  begin
    uncompressed = zlib_stream.inflate(stream)
  rescue Zlib::DataError => zlib_except
    uncompressed = zlib_stream.flush_next_out

    unless Origami::OPTIONS[:ignore_zlib_errors]
      raise InvalidFlateDataError.new(zlib_except.message, uncompressed)
    end
  end

  if @params.Predictor.is_a?(Integer)
    colors  = @params.Colors.is_a?(Integer) ? @params.Colors.to_i : 1
    bpc     = @params.BitsPerComponent.is_a?(Integer) ? @params.BitsPerComponent.to_i : 8
    columns = @params.Columns.is_a?(Integer) ? @params.Columns.to_i : 1

    uncompressed = Predictor.do_post_prediction(uncompressed, @params.Predictor.to_i, colors, bpc, columns)
  end

  uncompressed
end
encode(stream) click to toggle source

Encodes data using zlib/Deflate compression method.

stream

The data to encode.

# File lib/origami/filters/flate.rb, line 64
def encode(stream)
  if @params.Predictor.is_a?(Integer)
    colors  = @params.Colors.is_a?(Integer) ? @params.Colors.to_i : 1
    bpc     = @params.BitsPerComponent.is_a?(Integer) ? @params.BitsPerComponent.to_i : 8
    columns = @params.Columns.is_a?(Integer) ? @params.Columns.to_i : 1

    stream = Predictor.do_pre_prediction(stream, @params.Predictor.to_i, colors, bpc, columns)
  end       
  
  Zlib::Deflate.deflate(stream, Zlib::BEST_COMPRESSION)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.