Class: ImageFilterDsl::Dsl::Kernel::FilterKernel
- Inherits:
-
Object
- Object
- ImageFilterDsl::Dsl::Kernel::FilterKernel
- Defined in:
- lib/image_filter_dsl/dsl/kernel.rb
Overview
IFD Filter Kernel class
Instance Attribute Summary collapse
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#instructions ⇒ Object
Returns the value of attribute instructions.
-
#outputs ⇒ Object
Returns the value of attribute outputs.
Instance Method Summary collapse
-
#initialize(inputs = [], outputs = []) ⇒ FilterKernel
constructor
Kernel constructor.
-
#process(initial_values) ⇒ Hash
Process filter kernel and produce output hash.
-
#store_instruction(instruction) ⇒ Integer
Store instruction in kernel.
Constructor Details
#initialize(inputs = [], outputs = []) ⇒ FilterKernel
Kernel constructor
22 23 24 25 26 |
# File 'lib/image_filter_dsl/dsl/kernel.rb', line 22 def initialize(inputs=[],outputs=[]) @inputs = inputs @outputs = outputs @instructions = [] end |
Instance Attribute Details
#inputs ⇒ Object
Returns the value of attribute inputs.
15 16 17 |
# File 'lib/image_filter_dsl/dsl/kernel.rb', line 15 def inputs @inputs end |
#instructions ⇒ Object
Returns the value of attribute instructions.
14 15 16 |
# File 'lib/image_filter_dsl/dsl/kernel.rb', line 14 def instructions @instructions end |
#outputs ⇒ Object
Returns the value of attribute outputs.
16 17 18 |
# File 'lib/image_filter_dsl/dsl/kernel.rb', line 16 def outputs @outputs end |
Instance Method Details
#process(initial_values) ⇒ Hash
Process filter kernel and produce output hash
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/image_filter_dsl/dsl/kernel.rb', line 41 def process(initial_values) outs = Hash[* @outputs.map{|o| [o,nil] }.flatten] @instructions.each do |i| v = i.calculate(initial_values) if @outputs.include?(i.out) outs[i.out] = v else initial_values[i.out] = v end end outs end |
#store_instruction(instruction) ⇒ Integer
Store instruction in kernel
32 33 34 35 |
# File 'lib/image_filter_dsl/dsl/kernel.rb', line 32 def store_instruction(instruction) @instructions.append(instruction) @instructions.length end |