module ChunkyPNG::Canvas::StreamImporting

def from_bgr_stream(width, height, stream)

Returns:
  • (ChunkyPNG::Canvas) - The newly constructed canvas instance.

Parameters:
  • stream (#read, String) -- The stream to read the pixel data from.
  • height (Integer) -- The height of the new canvas.
  • width (Integer) -- The width of the new canvas.
def from_bgr_stream(width, height, stream)
  string = ChunkyPNG::EXTRA_BYTE.dup # Add a first byte to the first BGR triple.
  string << (stream.respond_to?(:read) ? stream.read(3 * width * height) : stream.to_s[0, 3 * width * height])
  pixels = string.unpack("@1" << ('XV' * (width * height))).map { |color| color | 0x000000ff }
  self.new(width, height, pixels)
end