class PNGlitch::Filter
Filter
represents the filtering functions that is defined in PNG spec.
Constants
- AVERAGE
- NONE
- PAETH
- SUB
- UP
Attributes
decoder[RW]
encoder[RW]
filter_type[R]
Public Class Methods
guess(filter_type)
click to toggle source
Guesses and retuens the filter type as a number.
# File lib/pnglitch/filter.rb, line 18 def self.guess filter_type type = nil if filter_type.is_a?(Numeric) && filter_type.between?(NONE, PAETH) type = filter_type.to_i elsif filter_type.is_a?(String) && filter_type =~ /^[0-4]$/ type = filter_type.to_i else type = @@types.collect{|c| c.to_s[0] }.index(filter_type.to_s[0].downcase) end type end
new(filter_type, sample_size)
click to toggle source
# File lib/pnglitch/filter.rb, line 33 def initialize filter_type, sample_size @filter_type = Filter.guess(filter_type) || 0 @filter_type_name = @@types[@filter_type] @sample_size = sample_size @encoder = self.method ('encode_%s' % @filter_type_name.to_s).to_sym @decoder = self.method ('decode_%s' % @filter_type_name.to_s).to_sym end
Public Instance Methods
decode(data, prev_data = nil)
click to toggle source
Reconstruct with a specified filter type.
# File lib/pnglitch/filter.rb, line 51 def decode data, prev_data = nil @decoder.call data.dup, prev_data end
encode(data, prev_data = nil)
click to toggle source
Filter
with a specified filter type.
# File lib/pnglitch/filter.rb, line 44 def encode data, prev_data = nil @encoder.call data.dup, prev_data end