Sha256: 57a5fac909a5867a5f21c73232212f4d2724c5dae12a03f4bf1eba6b413f9761

Contents?: true

Size: 1.45 KB

Versions: 30

Compression:

Stored size: 1.45 KB

Contents

module ChunkyPNG
  class Canvas

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

      # 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.
      #
      # @return [String] The RGBA-formatted pixel data.
      def to_rgba_stream
        pixels.pack('N*')
      end

      # 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.
      #
      # @return [String] The RGB-formatted pixel data.
      def to_rgb_stream
        pixels.pack('NX' * (width * height))
      end

      # 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.
      #
      # @return [String] The RGBA-formatted pixel data.
      def to_abgr_stream
        pixels.pack('V*')
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
chunky_png-1.1.0 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-1.0.1 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-1.0.0 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-1.0.0.rc2 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-1.0.0.rc1 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-1.0.0.beta2 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-1.0.0.beta1 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-0.12.0 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-0.11.1 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-0.11.0 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-0.10.5 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-0.10.4 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-0.10.3 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-0.10.2 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-0.10.1 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-0.10.0 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-0.9.2 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-0.9.1 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-0.9.0 lib/chunky_png/canvas/stream_exporting.rb
chunky_png-0.8.0 lib/chunky_png/canvas/stream_exporting.rb