Class: GD2::Palette::IndexedColor
- Inherits:
-
GD2::Palette
- Object
- GD2::Palette
- GD2::Palette::IndexedColor
- Includes:
- Enumerable
- Defined in:
- lib/gd2/palette.rb
Instance Attribute Summary
Attributes inherited from GD2::Palette
Instance Method Summary collapse
-
#deallocate_unused ⇒ Object
:nodoc:.
-
#each ⇒ Object
Iterate through every color allocated in this palette.
-
#inspect ⇒ Object
:nodoc:.
Methods inherited from GD2::Palette
#<<, #[], #[]=, #allocate, #available, #closest, #closest_hwb, #deallocate, #exact, #exact!, #initialize, #resolve, #size, #used
Constructor Details
This class inherits a constructor from GD2::Palette
Instance Method Details
#deallocate_unused ⇒ Object
:nodoc:
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/gd2/palette.rb', line 206 def deallocate_unused #:nodoc: used = @image.collect.flatten.uniq.inject(Array.new(MAX_COLORS)) do |ary, c| ary[c] = true ary end count = 0 each do |color| unless used.at(color.index) self[color.index] = nil count += 1 end end count.zero? ? nil : count end |
#each ⇒ Object
Iterate through every color allocated in this palette.
198 199 200 201 202 203 204 |
# File 'lib/gd2/palette.rb', line 198 def each #:yields: color (0...MAX_COLORS).each do |i| color = self[i] yield color unless color.nil? end self end |
#inspect ⇒ Object
:nodoc:
182 183 184 |
# File 'lib/gd2/palette.rb', line 182 def inspect #:nodoc: "#<#{self.class} [#{used}]>" end |