Class: FreeImage::Palette
- Inherits:
-
Object
- Object
- FreeImage::Palette
- Includes:
- Enumerable
- Defined in:
- lib/free-image/palette.rb
Overview
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.
Instance Method Summary collapse
-
#[](index) ⇒ Object
Returns the index color as an instance of FreeImage::RGBQuad.
- #each ⇒ Object
-
#initialize(bitmap) ⇒ Palette
constructor
A new instance of Palette.
-
#size ⇒ Object
(also: #colors_used)
Returns the palette-size for palletised bitmaps, and 0 for high-colour bitmaps.
Constructor Details
#initialize(bitmap) ⇒ Palette
Returns a new instance of Palette.
14 15 16 17 |
# File 'lib/free-image/palette.rb', line 14 def initialize(bitmap) # Keep reference to bitmap so its not gc'ed @bitmap = bitmap end |
Instance Method Details
#[](index) ⇒ Object
Returns the index color as an instance of FreeImage::RGBQuad
28 29 30 31 32 33 34 35 36 |
# File 'lib/free-image/palette.rb', line 28 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 ⇒ Object
38 39 40 41 42 |
# File 'lib/free-image/palette.rb', line 38 def each size.times do |i| yield (self[i]) end end |
#size ⇒ Object Also known as: colors_used
Returns the palette-size for palletised bitmaps, and 0 for high-colour bitmaps.
20 21 22 23 24 |
# File 'lib/free-image/palette.rb', line 20 def size result = FreeImage.FreeImage_GetColorsUsed(@bitmap) FreeImage.check_last_error result end |