Class: Ashton::ImageStub

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Parameters:

  • blob_data (String)

    Raw data string to import. Must be RGBA ordered, (4 * width * height) bytes in length.

  • width (Integer)

    Number of pixels wide.

  • height (Integer)

    Number of pixels high.

Raises:

  • (ArgumentError)


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

#columnsInteger (readonly)

Returns:

  • (Integer)


10
11
12
# File 'lib/ashton/image_stub.rb', line 10

def columns
  @columns
end

#rowsInteger (readonly)

Returns:

  • (Integer)


8
9
10
# File 'lib/ashton/image_stub.rb', line 8

def rows
  @rows
end

Instance Method Details

#to_blobString

Returns:

  • (String)


29
30
31
# File 'lib/ashton/image_stub.rb', line 29

def to_blob
  @data
end