module ChunkyPNG::Canvas::StreamImporting
def from_abgr_stream(width, height, stream)
-
(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_abgr_stream(width, height, stream) string = stream.respond_to?(:read) ? stream.read(4 * width * height) : stream.to_s[0, 4 * width * height] new(width, height, string.unpack("V*")) end
def from_bgr_stream(width, height, stream)
-
(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 } new(width, height, pixels) end
def from_rgb_stream(width, height, stream)
-
(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_rgb_stream(width, height, stream) string = stream.respond_to?(:read) ? stream.read(3 * width * height) : stream.to_s[0, 3 * width * height] string << ChunkyPNG::EXTRA_BYTE # Add a fourth byte to the last RGB triple. unpacker = "NX" * (width * height) pixels = string.unpack(unpacker).map { |color| color | 0x000000ff } new(width, height, pixels) end
def from_rgba_stream(width, height, stream)
-
(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_rgba_stream(width, height, stream) string = stream.respond_to?(:read) ? stream.read(4 * width * height) : stream.to_s[0, 4 * width * height] new(width, height, string.unpack("N*")) end