Class: PNG::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/PatchedPNG.rb

Overview

RGBA colors

Constant Summary collapse

Background =

Transparent white

Color.new 0xFF, 0xFF, 0xFF, 0x00
White =
Color.new 0xFF, 0xFF, 0xFF, 0xFF
Black =
Color.new 0x00, 0x00, 0x00, 0xFF
Gray =
Color.new 0x7F, 0x7F, 0x7F, 0xFF
Red =
Color.new 0xFF, 0x00, 0x00, 0xFF
Orange =
Color.new 0xFF, 0xA5, 0x00, 0xFF
Yellow =
Color.new 0xFF, 0xFF, 0x00, 0xFF
Green =
Color.new 0x00, 0xFF, 0x00, 0xFF
Blue =
Color.new 0x00, 0x00, 0xFF, 0xFF
Purple =
Color.new 0XFF, 0x00, 0xFF, 0xFF

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(red, green, blue, alpha) ⇒ Color

Creates a new color with values red, green, blue, and alpha.



111
112
113
# File 'lib/PatchedPNG.rb', line 111

def initialize(red, green, blue, alpha)
  @values = [red, green, blue, alpha]
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



106
107
108
# File 'lib/PatchedPNG.rb', line 106

def values
  @values
end

Instance Method Details

#aObject

Alpha transparency component



149
# File 'lib/PatchedPNG.rb', line 149

def a; @values[3]; end

#bObject

Blue component



144
# File 'lib/PatchedPNG.rb', line 144

def b; @values[2]; end

#blend(color) ⇒ Object

Blends color into this color returning a new blended color.



154
155
156
157
158
159
# File 'lib/PatchedPNG.rb', line 154

def blend(color)
  return Color.new((r * (0xFF - color.a) + color.r * color.a) >> 8,
                   (g * (0xFF - color.a) + color.g * color.a) >> 8,
                   (b * (0xFF - color.a) + color.b * color.a) >> 8,
                   (a * (0xFF - color.a) + color.a * color.a) >> 8)
end

#gObject

Green component



139
# File 'lib/PatchedPNG.rb', line 139

def g; @values[1]; end

#inspectObject

:nodoc:



168
169
170
# File 'lib/PatchedPNG.rb', line 168

def inspect # :nodoc:
  "#<%s %02x %02x %02x %02x>" % [self.class, *@values]
end

#intensity(i) ⇒ Object

Returns a new color with an alpha value adjusted by i.



164
165
166
# File 'lib/PatchedPNG.rb', line 164

def intensity(i)
  return Color.new(r,b,g,(a*i) >> 8)
end

#rObject

Red component



134
# File 'lib/PatchedPNG.rb', line 134

def r; @values[0]; end