Skip to content

Palette

Type

Palette

A palette containing (up to) 256 Colours

Constants

Name Value
FORMAT_RAW 0
FORMAT_IMAGE 1
FORMAT_CSV 2
FORMAT_JASC 3
FORMAT_GIMP 4
MATCH_DEFAULT 0
MATCH_OLD 1
MATCH_RGB 2
MATCH_HSL 3
MATCH_C76 4
MATCH_C94 5
MATCH_C2K 6

Properties

Property Type Description
colourCount integer The number of colours in the palette

Constructors

Palette.new()

Creates a new palette with 256 colours in a greyscale gradient (from black to white).


Palette.new(count)

Creates a new palette with count colours in a greyscale gradient.

Parameters

  • count (integer): The number of colours in the palette

Functions

Overview

General

Colour(index) -> Colour CopyColours(other) CountUniqueColours() -> integer FindColour(colour) -> integer NearestColour(colour, [matchMode]) -> integer

Load/Save

LoadData(data, [format]) -> boolean LoadFile(path, [format]) -> boolean SaveFile(path, [format])

Colour Modification

SetColour(index, colour) SetColourR(index, r) SetColourG(index, g) SetColourB(index, b) SetColourA(index, a)

Colour Range Modification

ApplyTranslation(translation) Colourise(colour, firstIndex, lastIndex) Tint(colour, amount, firstIndex, lastIndex) Saturate(amount, firstIndex, lastIndex) Illuminate(amount, firstIndex, lastIndex) Shift(amount, firstIndex, lastIndex) Invert(firstIndex, lastIndex) Gradient(startColour, endColour, firstIndex, lastIndex)


Colour

Gets the colour at the given index in the palette.

Parameters

  • index (integer): The index of the colour to get

Returns

  • Colour: The colour at the given index

CopyColours

Copies all colours from another palette.

Parameters

  • other (Palette): The palette to copy from

Notes

This will not change the colourCount of the palette. If the other palette has less colours than this, the remaining colours in this palette will be left the same.


CountUniqueColours

Counts the number of unique colours in the palette.

Returns

  • integer: The number of unique colours present in the palette

FindColour

Finds the index of the first colour in the palette that exactly matches the given colour.

Parameters

  • colour (Colour): The colour to find in the palette

Returns

  • integer: The index of the first matching colour in the palette, or -1 if no match was found

NearestColour

Finds the index of the colour in the palette that most closely matches the given colour.

Parameters

  • colour (Colour): The colour to find in the palette
  • [matchMode] (integer): The colour matching algorithm to use (see MATCH_ constants). Default is MATCH_DEFAULT, which means the colour matching algorithm currently selected in the SLADE preferences will be used

Returns

  • integer: The index of the closest matching colour

LoadData

Loads the given data into the palette.

Parameters

  • data (string): The binary data to load
  • [format] (integer): The format of the data. See FORMAT_ constants. Default is FORMAT_RAW

Returns

  • boolean: true on success

LoadFile

Loads the file at path on disk into the palette.

Parameters

  • path (string): The full path to the file to load
  • [format] (integer): The format of the file. See FORMAT_ constants. Default is FORMAT_RAW

Returns

  • boolean: true on success

SaveFile

Saves the palette to a file at path on disk in the specified format.

Parameters

  • path (string): The full path to the file
  • [format] (integer): The format of the file. See FORMAT_ constants. Default is FORMAT_RAW

Returns

  • boolean: true on success

SetColour

Sets the colour at index in the palette.

Parameters

  • index (integer): The index of the colour to set
  • colour (Colour): The colour to set it to

SetColourR

Sets red component of the colour at index in the palette.

Parameters

  • index (integer): The index of the colour in the palette
  • r (integer): The new red component value

SetColourG

Sets green component of the colour at index in the palette.

Parameters

  • index (integer): The index of the colour in the palette
  • g (integer): The new green component value

SetColourB

Sets blue component of the colour at index in the palette.

Parameters

  • index (integer): The index of the colour in the palette
  • b (integer): The new blue component value

SetColourA

Sets alpha component of the colour at index in the palette.

Parameters

  • index (integer): The index of the colour in the palette
  • a (integer): The new alpha component value

ApplyTranslation

Applies a Translation to the palette.

Parameters


Colourise

Colourises a range of colours in the palette.

Parameters

  • colour (Colour): The colour to use
  • firstIndex (integer): The index of the first colour to apply to
  • lastIndex (integer): The index of the last colour to apply to

Tint

Tints a range of colours in the palette.

Parameters

  • colour (Colour): The colour to use
  • amount (float): The amount to tint (0.0 - 1.0)
  • firstIndex (integer): The index of the first colour to apply to
  • lastIndex (integer): The index of the last colour to apply to

Saturate

Adjusts the saturation on a range of colours in the palette.

Parameters

  • amount (float): The amount to adjust by (0.0 - 2.0)
  • firstIndex (integer): The index of the first colour to apply to
  • lastIndex (integer): The index of the last colour to apply to

Illuminate

Adjusts the brightness on a range of colours in the palette.

Parameters

  • amount (float): The amount to adjust by (0.0 - 2.0)
  • firstIndex (integer): The index of the first colour to apply to
  • lastIndex (integer): The index of the last colour to apply to

Shift

Shifts the hue on a range of colours in the palette.

Parameters

  • amount (float): The amount to shift by (0.0 - 1.0)
  • firstIndex (integer): The index of the first colour to apply to
  • lastIndex (integer): The index of the last colour to apply to

Invert

Inverts a range of colours in the palette.

Parameters

  • firstIndex (integer): The index of the first colour to apply to
  • lastIndex (integer): The index of the last colour to apply to

Gradient

Converts a range of colours in the palette to a colour gradient from startColour to endColour.

Parameters

  • startColour (Colour): The starting colour of the gradient
  • endColour (Colour): The ending colour of the gradient
  • firstIndex (integer): The index of the first colour to apply to
  • lastIndex (integer): The index of the last colour to apply to