---
name: "SDL::Palette"
section: "3pm"
platform: "linux"
package: "libsdl-perl"
version: "2.548-5+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/SDL::Palette"
---

# SDL::Palette(3pm)

## NAME

SDL::Palette -- Color palette for 8-bit pixel formats

## CATEGORY

Core, Video, Structure

## DESCRIPTION

Each pixel in an 8-bit surface is an index into the colors field of the `"SDL::Palette"` object stored in its `"SDL::PixelFormat"`. A `"SDL::Palette"` is created automatically when SDL allocates a `"SDL::PixelFormat"` for a surface. This class has methods for returning the colors in a palette object. The colors can be set with SDL::Video::set\_colors and SDL::Video::set\_palette.

## METHODS

### ncolors

```
  $ncolors = $palette->ncolors();
```

Returns the number of colors in palette.

### colors

```
  @colors = @{ $palette->colors() };
```

Returns an array, `"ncolors"` in length, of the SDL::Colors in the palette.

### color\_index

```
  $color = $palette->color_index( $index );
```

Returns the SDL::Color at the provided index of the palette.

## SEE ALSO

SDL::Video SDL::PixelFormat SDL::Color SDL::Surface

## AUTHORS

See "AUTHORS" in SDL.
