Class: Ashton::ImageStub
- Inherits:
-
Object
- Object
- Ashton::ImageStub
- Defined in:
- lib/ashton/image_stub.rb
Overview
Used internally to create images from raw binary (blob) data.
This object duck-types an RMagick image (#rows, #columns, #to_blob), so that Gosu will import it.
Instance Attribute Summary collapse
- #columns ⇒ Integer readonly
- #rows ⇒ Integer readonly
Instance Method Summary collapse
-
#initialize(blob_data, width, height) ⇒ ImageStub
constructor
The first pixel in the blob will be at the top left hand corner of the created image, since that is the orientation of Gosu images.
- #to_blob ⇒ String
Constructor Details
#initialize(blob_data, width, height) ⇒ ImageStub
The first pixel in the blob will be at the top left hand corner of the created image, since that is the orientation of Gosu images.
18 19 20 21 22 23 24 25 26 |
# File 'lib/ashton/image_stub.rb', line 18 def initialize(blob_data, width, height) raise ArgumentError, "Width must be >= 1 pixel" unless width > 0 raise ArgumentError, "Height must be >= 1 pixel" unless height > 0 expected_size = width * height * 4 raise ArgumentError, "Expected blob to be #{expected_size} bytes" unless blob_data.size == expected_size @data, @columns, @rows = blob_data, width, height end |
Instance Attribute Details
#columns ⇒ Integer (readonly)
10 11 12 |
# File 'lib/ashton/image_stub.rb', line 10 def columns @columns end |
#rows ⇒ Integer (readonly)
8 9 10 |
# File 'lib/ashton/image_stub.rb', line 8 def rows @rows end |
Instance Method Details
#to_blob ⇒ String
29 30 31 |
# File 'lib/ashton/image_stub.rb', line 29 def to_blob @data end |