Class | GD2::Palette |
In: |
lib/gd2/palette.rb
|
Parent: | Object |
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.
Obtain a Palette object from the associated Image:
palette = image.palette
Ensure the given color is present in this palette, allocating it if necessary. Returns the palette so calls may be stacked.
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 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 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.