Class: Vissen::Output::PixelBuffer
- Inherits:
-
Object
- Object
- Vissen::Output::PixelBuffer
- Includes:
- Buffer
- Defined in:
- lib/vissen/output/pixel_buffer.rb
Overview
The pixel buffer is an implementation of the general ‘Buffer` module that places `Pixel` objects in each buffer element.
Instance Attribute Summary
Attributes included from Buffer
Instance Method Summary collapse
-
#clear! ⇒ Object
Zeros the RGB components of each pixel in the buffer.
-
#copy!(other) ⇒ Object
Replaces the pixel values of this buffer with those of the given object.
-
#finalize! ⇒ self
Signals to the ‘PixelBuffer` that the user is done updating the color values and that the buffer should perform any post processing that is needed.
-
#freeze ⇒ self
Prevent any more filters from being added.
-
#initialize(context, filters = []) ⇒ PixelBuffer
constructor
A new instance of PixelBuffer.
Methods included from Buffer
#[], #each_with_position, #share_context?
Constructor Details
#initialize(context, filters = []) ⇒ PixelBuffer
Returns a new instance of PixelBuffer.
20 21 22 23 24 25 26 27 28 |
# File 'lib/vissen/output/pixel_buffer.rb', line 20 def initialize(context, filters = []) super context, Pixel # Verify that all filters share the same context # before adding them. filters.each { |f| raise ContextError unless share_context? f } @filters = filters freeze end |
Instance Method Details
#clear! ⇒ Object
Zeros the RGB components of each pixel in the buffer.
39 40 41 |
# File 'lib/vissen/output/pixel_buffer.rb', line 39 def clear! pixels.each(&:clear!) end |
#copy!(other) ⇒ Object
Replaces the pixel values of this buffer with those of the given object.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vissen/output/pixel_buffer.rb', line 48 def copy!(other) raise TypeError unless other.is_a? self.class other.each_with_index do |src_pixel, index| dst_pixel = pixels[index] dst_pixel.r = src_pixel.r dst_pixel.g = src_pixel.g dst_pixel.b = src_pixel.b end end |
#finalize! ⇒ self
Signals to the ‘PixelBuffer` that the user is done updating the color values and that the buffer should perform any post processing that is needed.
65 66 67 68 |
# File 'lib/vissen/output/pixel_buffer.rb', line 65 def finalize! @filters.each { |filter| filter.apply self } self end |
#freeze ⇒ self
Prevent any more filters from being added.
33 34 35 36 |
# File 'lib/vissen/output/pixel_buffer.rb', line 33 def freeze @filters.freeze super end |