Class: RawImage::Color

Inherits:
Object
  • Object
show all
Includes:
Colors
Defined in:
lib/raw_image/color.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Colors

#black, #transparent, #white

Constructor Details

#initialize(r = 0, g = r, b = r, a = 1.0) ⇒ Color

0 <= values <= 1



10
11
12
# File 'lib/raw_image/color.rb', line 10

def initialize(r=0, g=r, b=r, a=1.0)
  @r = r; @g = g; @b = b; @a = a
end

Instance Attribute Details

#aObject

Returns the value of attribute a.



7
8
9
# File 'lib/raw_image/color.rb', line 7

def a
  @a
end

#bObject

Returns the value of attribute b.



7
8
9
# File 'lib/raw_image/color.rb', line 7

def b
  @b
end

#gObject

Returns the value of attribute g.



7
8
9
# File 'lib/raw_image/color.rb', line 7

def g
  @g
end

#rObject

Returns the value of attribute r.



7
8
9
# File 'lib/raw_image/color.rb', line 7

def r
  @r
end

Instance Method Details

#a8Object



35
# File 'lib/raw_image/color.rb', line 35

def a8; a * 255; end

#b8Object



34
# File 'lib/raw_image/color.rb', line 34

def b8; b * 255; end

#byte(int) ⇒ Object



20
21
22
# File 'lib/raw_image/color.rb', line 20

def byte(int)
  "%c"%int
end

#g8Object



33
# File 'lib/raw_image/color.rb', line 33

def g8; g * 255; end

#grayObject Also known as: grey



39
# File 'lib/raw_image/color.rb', line 39

def gray; (r+g+b)/3; end

#gray8Object Also known as: grey8



36
# File 'lib/raw_image/color.rb', line 36

def gray8; g * 255; end

#gray=(val) ⇒ Object Also known as: grey=

0 <= val <= 1



15
16
17
# File 'lib/raw_image/color.rb', line 15

def gray=(val)
  @r = @g = @b = g
end

#inspectObject



24
25
26
# File 'lib/raw_image/color.rb', line 24

def inspect
  "color(#{[r,g,b,a].join(', ')})"
end

#r8Object



32
# File 'lib/raw_image/color.rb', line 32

def r8; r * 255; end

#to_bytes(format) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/raw_image/color.rb', line 42

def to_bytes(format)
  case format
  when :g8    then [byte(g8)].join
  when :rgb8  then [byte(r8), byte(g8), byte(b8)].join
  when :rgba8 then [byte(r8), byte(g8), byte(b8), byte(a8)].join
  end
end

#to_sObject



28
29
30
# File 'lib/raw_image/color.rb', line 28

def to_s
  "#%02x%02x%02x%02x"%[r8,g8,b8,a8]
end