Class: Vissen::Output::Filter::Quantizer
- Inherits:
-
Object
- Object
- Vissen::Output::Filter::Quantizer
- Includes:
- Vissen::Output::Filter
- Defined in:
- lib/vissen/output/filter/quantizer.rb
Overview
Scales and rounds the color components to only take discrete values.
Instance Attribute Summary
Attributes included from Vissen::Output::Filter
Instance Method Summary collapse
-
#apply(pixel_buffer) ⇒ Object
Applies the filter to the given pixel cloud.
-
#initialize(*args, steps: 256, range: 0...steps) ⇒ Quantizer
constructor
A new instance of Quantizer.
Constructor Details
#initialize(*args, steps: 256, range: 0...steps) ⇒ Quantizer
Returns a new instance of Quantizer.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vissen/output/filter/quantizer.rb', line 18 def initialize(*args, steps: 256, range: 0...steps) super(*args) raise RangeError if steps < 2 from = range.begin to = if range.exclude_end? raise ArgumentError if range.end.is_a?(Float) range.end - 1 else range.end end design_function from, to, steps freeze end |
Instance Method Details
#apply(pixel_buffer) ⇒ Object
Applies the filter to the given pixel cloud.
40 41 42 43 44 45 46 |
# File 'lib/vissen/output/filter/quantizer.rb', line 40 def apply(pixel_buffer) pixel_buffer.each do |pixel| pixel.r = @fn.call pixel.r pixel.g = @fn.call pixel.g pixel.b = @fn.call pixel.b end end |