class FreeImage::Palette

  1. lib/free-image/palette.rb
Superclass: Object

Represents a bitmaps palette. If the bitmap doesn’t have a palette (i.e. when its pixel bit depth is greater than 8), this function returns nil.

Methods

Public Class

  1. new

Public Instance

  1. []
  2. each
  3. size

Included modules

  1. Enumerable

Public Instance Aliases

colors_used -> size

Public Class methods

new (bitmap)
[show source]
# File lib/free-image/palette.rb, line 13
def initialize(bitmap)
  # Keep reference to bitmap so its not gc'ed
  @bitmap = bitmap
end

Public Instance methods

[] (index)

Returns the index color as an instance of FreeImage::RGBQuad

[show source]
# File lib/free-image/palette.rb, line 27
def [](index)
  unless (0..self.size).include?(index)
    raise(RangeError, "Value is out of range 0..#{self.size}. Value: #{index}")
  end

  ptr = FreeImage.FreeImage_GetPalette(@bitmap)
  FreeImage.check_last_error
  RGBQuad.new(ptr[index])
end
each ()
[show source]
# File lib/free-image/palette.rb, line 37
def each
  size.times do |i|
    yield (self[i])
  end
end
size ()

Returns the palette-size for palletised bitmaps, and 0 for high-colour bitmaps.

[show source]
# File lib/free-image/palette.rb, line 19
def size
  result = FreeImage.FreeImage_GetColorsUsed(@bitmap)
  FreeImage.check_last_error
  result
end