Module: ChunkyPNG::Canvas::StreamExporting

Included in:
ChunkyPNG::Canvas
Defined in:
lib/chunky_png/canvas/stream_exporting.rb

Overview

Methods to save load a canvas from to stream, encoded in RGB, RGBA, BGR or ABGR format.

Instance Method Summary (collapse)

Instance Method Details

- (String) to_abgr_stream

Creates an ABGR-formatted pixelstream with the pixel data from this canvas.

Note that this format is fast but bloated, because no compression is used and the internal representation is left intact. To reconstruct the canvas, the width and height should be known.



53
54
55
# File 'lib/chunky_png/canvas/stream_exporting.rb', line 53

def to_abgr_stream
  pixels.pack('V*')
end

- (String) to_alpha_channel_stream

Creates a stream of the alpha channel of this canvas.



32
33
34
# File 'lib/chunky_png/canvas/stream_exporting.rb', line 32

def to_alpha_channel_stream
  pixels.pack('C*')
end

- (String) to_grayscale_stream

Creates a grayscale stream of this canvas.

This method assume sthat this image is fully grayscale, i.e. R = G = B for every pixel. The alpha channel will not be included in the stream.



42
43
44
# File 'lib/chunky_png/canvas/stream_exporting.rb', line 42

def to_grayscale_stream
  pixels.pack('nX' * pixels.length)
end

- (String) to_rgb_stream

Creates an RGB-formatted pixelstream with the pixel data from this canvas.

Note that this format is fast but bloated, because no compression is used and the internal representation is almost left intact. To reconstruct the canvas, the width and height should be known.



25
26
27
# File 'lib/chunky_png/canvas/stream_exporting.rb', line 25

def to_rgb_stream
  pixels.pack('NX' * pixels.length)
end

- (String) to_rgba_stream

Creates an RGB-formatted pixelstream with the pixel data from this canvas.

Note that this format is fast but bloated, because no compression is used and the internal representation is left intact. To reconstruct the canvas, the width and height should be known.



14
15
16
# File 'lib/chunky_png/canvas/stream_exporting.rb', line 14

def to_rgba_stream
  pixels.pack('N*')
end