class Vissen::Output::PixelBuffer

The pixel buffer is an implementation of the general `Buffer` module that places `Pixel` objects in each buffer element.

Public Class Methods

new(context, filters = []) click to toggle source

@raise [ContextError] if any of the filters does not share the same

context.

@param context [Context] the context in which the pixel buffer exists. @param filters [Array<Filter>] the output filters to apply when

finalizing the buffer.
Calls superclass method Vissen::Output::Buffer::new
# 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

Public Instance Methods

clear!() click to toggle source

Zeros the RGB components of each pixel in the buffer.

# File lib/vissen/output/pixel_buffer.rb, line 39
def clear!
  pixels.each(&:clear!)
end
copy!(other) click to toggle source

Replaces the pixel values of this buffer with those of the given object.

@raise [TypeError] if the other object is not a PixelBuffer.

@param other [PixelBuffer] the pixel buffer to copy values from.

# 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!() click to toggle source

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.

@return [self]

# File lib/vissen/output/pixel_buffer.rb, line 65
def finalize!
  @filters.each { |filter| filter.apply self }
  self
end
freeze() click to toggle source

Prevent any more filters from being added.

@return [self]

Calls superclass method Vissen::Output::Buffer#freeze
# File lib/vissen/output/pixel_buffer.rb, line 33
def freeze
  @filters.freeze
  super
end