Class: Btape::Palette::Fixed

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

Overview

Three bits of red, three of green, two of blue. Cheap, and independent of the image, but only eight distinct levels of red to spend on a gradient that may need far more.

Instance Method Summary collapse

Instance Method Details

#index_for(pixel) ⇒ Object



48
49
50
51
52
# File 'lib/btape/palette.rb', line 48

def index_for(pixel)
  (ChunkyPNG::Color.r(pixel) & 0xe0) |
    ((ChunkyPNG::Color.g(pixel) & 0xe0) >> 3) |
    (ChunkyPNG::Color.b(pixel) >> 6)
end

#to_gctObject



54
55
56
57
58
# File 'lib/btape/palette.rb', line 54

def to_gct
  Palette.colour_table(
    (0...SIZE).map { |i| [((i >> 5) & 7) * 255 / 7, ((i >> 2) & 7) * 255 / 7, (i & 3) * 255 / 3] }
  )
end