Class: Contrek::Bitmaps::RgbColor

Inherits:
Object
  • Object
show all
Defined in:
lib/contrek/bitmaps/rgb_color.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r:, g:, b:, a: 255) ⇒ RgbColor

Returns a new instance of RgbColor.



5
6
7
8
9
10
11
# File 'lib/contrek/bitmaps/rgb_color.rb', line 5

def initialize(r:, g:, b:, a: 255)
  @r = r
  @g = g
  @b = b
  @a = a
  @raw = (r << 24) + (g << 16) + (b << 8) + a
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



4
5
6
# File 'lib/contrek/bitmaps/rgb_color.rb', line 4

def raw
  @raw
end

Class Method Details

.reverse_raw(raw) ⇒ Object



17
18
19
20
21
22
# File 'lib/contrek/bitmaps/rgb_color.rb', line 17

def self.reverse_raw(raw)
  [:a, :b, :g, :r].each_with_object({}) do |c, h|
    h[c] = raw & 0xFF
    raw >>= 8
  end
end

Instance Method Details

#to_rgb_rawObject



13
14
15
# File 'lib/contrek/bitmaps/rgb_color.rb', line 13

def to_rgb_raw
  @raw >> 8
end