Class GD2::Palette
In: lib/gd2/palette.rb
Parent: Object

Description

Palette objects are associated with an Image and hold the selection of pixel colors available to the Image. This is primarily a concern for Image::IndexedColor images, but their use with Image::TrueColor images is supported for consistency.

Obtaining

Obtain a Palette object from the associated Image:

  palette = image.palette

Methods

<<   []   []=   allocate   available   closest   closest_hwb   deallocate   deallocate_unused   exact   exact!   length   resolve   size   used  

Classes and Modules

Class GD2::Palette::ColorNotFoundError
Class GD2::Palette::IndexedColor
Class GD2::Palette::PaletteFullError
Class GD2::Palette::TrueColor

Attributes

image  [R]  The Image associated with this Palette

Public Instance methods

Ensure the given color is present in this palette, allocating it if necessary. Returns the palette so calls may be stacked.

Return the color allocated to the specified index, or nil if the entry is unallocated.

Assign (allocate) the given color to the palette entry identified by index. If the entry was previously allocated to a different color, every pixel in the image having the given color index will effectively be changed to the new color. This method cannot be used with Image::TrueColor palettes.

Assign the given color to an unoccupied entry in this palette and return it. Does not check whether the color is already allocated, and raises an error for Image::IndexedColor palettes if the palette is full.

Return the number of palette entries available to be allocated for new colors.

Return the color in this palette that is closest to the given color according to Euclidian distance.

Return the color in this palette that is closest to the given color according to hue, whiteness, and blackness.

Remove the given color from this palette.

Remove all colors from this palette that are not currently in use by the associated Image. This is an expensive operation. Returns the number of palette entries deallocated.

Locate the given color in this palette and return it. Returns nil if the color is not presently in the palette.

Like Palette#exact except an error is raised if the color is not presently in the palette.

length()

Alias for size

Locate the given color in this palette and return it if found; otherwise try to allocate the color, or if the palette is full, return a color from the palette that is closest to it.

Return the maximum number of colors this palette can hold.

Return the number of colors presently allocated in this palette.

[Validate]