class Branding::Pixel

Attributes

uint32[RW]

Public Class Methods

load_strategy(pixels, height: 0, width: 0) { |self| ... } click to toggle source
# File lib/branding/pixel.rb, line 9
def self.load_strategy(pixels, height: 0, width: 0)
  pixels.each do |pixel_value|
    yield self.new(pixel_value)
  end
end
new(*opts) click to toggle source

basic 2-space with background color per pixel

# File lib/branding/pixel.rb, line 23
def initialize(*opts)
  opts = opts.first if opts.size == 1

  case opts
  when self.class
    @uint32 = opts.uint32
  when Fixnum
    @uint32 = opts
  when Array
    r,g,b,a = opts
    a ||= 0xff # alpha is optional. If it is not supplied, assume full-alpha.
    @uint32 = (r << 24) | (g << 16) | b << 8 | a
  when Hash
    #(r << 24) | (g << 16) | b << 8)
  else
    raise "Cannot initialize Pixel with #{opts.inspect}."
  end
end
rgb(r,g,b) click to toggle source
# File lib/branding/pixel.rb, line 15
def self.rgb(r,g,b)
  self.new((r << 24) | (g << 16) | b << 8)
end

Public Instance Methods

==(value) click to toggle source
# File lib/branding/pixel.rb, line 46
def ==(value)
  case value
  when self.class
    @uint32 == value.uint32
  when Fixnum
    @uint32 == value
  else
    @uint32 == value
  end
end
a() click to toggle source
# File lib/branding/pixel.rb, line 73
def a
  @uint32 & 0x000000ff
end
b() click to toggle source
# File lib/branding/pixel.rb, line 69
def b
  @uint32 & 0x0000ff00
end
g() click to toggle source
# File lib/branding/pixel.rb, line 65
def g
  @uint32 & 0x00ff0000
end
inspect() click to toggle source
# File lib/branding/pixel.rb, line 42
def inspect
  "0x%0.8x" % @uint32
end
r() click to toggle source
# File lib/branding/pixel.rb, line 61
def r
  @uint32 & 0xff000000
end
to_i() click to toggle source
# File lib/branding/pixel.rb, line 57
def to_i
  uint32
end
to_rgb() click to toggle source
# File lib/branding/pixel.rb, line 77
def to_rgb
  {r: r, g: g, b: b}
end
to_rgba() click to toggle source
# File lib/branding/pixel.rb, line 81
def to_rgba
  {r: r, g: g, b: b, a: a}
end
to_s() click to toggle source
# File lib/branding/pixel.rb, line 85
def to_s
  "#{ANSI.bg(*ANSI.uint32_to_rgb(@uint32))}  "
end
width() click to toggle source
# File lib/branding/pixel.rb, line 89
def width
  2
end