Jazz2::Scripting::Legacy::jjPAL class

A palette of 256 colors.

Colors are edited through color or the fill, gradient and copy methods; nothing changes on screen until apply() puts the palette into use. jjPalette holds the palette in use, jjBackupPalette the original one of the level. A new palette is all black.

Public static functions

static auto Create() -> jjPAL*
Creates a palette with all colors black.

Constructors, destructors, conversion operators

jjPAL()
Creates a new instance.
~jjPAL()

Public functions

void AddRef()
Increments the reference count.
void Release()
Decrements the reference count.
auto operator=(const jjPAL& o) -> jjPAL&
Copies all colors of another palette.
auto operator==(const jjPAL& o) -> bool
Returns whether both refer to the same palette object, the colors aren't compared.
auto getColor(std::uint8_t idx) -> jjPALCOLOR&
Returns the color at a palette index.
auto getConstColor(std::uint8_t idx) const -> const jjPALCOLOR&
Returns the color at a palette index, read-only.
auto setColorEntry(std::uint8_t idx, jjPALCOLOR& value) -> jjPALCOLOR&
Sets the color at a palette index.
void reset()
Restores the original colors of the level, the same as assigning jjBackupPalette.
void apply()
Makes this palette the one the game draws with.
auto load(const String& filename) -> bool
Loads the palette from a file and returns whether it succeeded.
void fill(std::uint8_t red, std::uint8_t green, std::uint8_t blue, float opacity)
Fills the whole palette with a color.
void fillTint(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t start, std::uint8_t length, float opacity)
Fills a range of the palette with a color.
void fillFromColor(jjPALCOLOR color, float opacity)
Fills the whole palette with a color, see the overload taking components.
void fillTintFromColor(jjPALCOLOR color, std::uint8_t start, std::uint8_t length, float opacity)
Fills a range of the palette with a color, see the overload taking components.
void gradient(std::uint8_t red1, std::uint8_t green1, std::uint8_t blue1, std::uint8_t red2, std::uint8_t green2, std::uint8_t blue2, std::uint8_t start, std::uint8_t length, float opacity, bool inclusive)
Writes a gradient between two colors into a range of the palette.
void gradientFromColor(jjPALCOLOR color1, jjPALCOLOR color2, std::uint8_t start, std::uint8_t length, float opacity, bool inclusive)
Writes a gradient between two colors into a range of the palette, see the overload taking components.
void copyFrom(std::uint8_t start, std::uint8_t length, std::uint8_t start2, const jjPAL& source, float opacity)
Copies a range of colors from another palette.
auto findNearestColor(jjPALCOLOR color) -> std::uint8_t
Returns the index of the palette entry closest to a color, any of the 256 entries can be returned.
auto FindNearestOpaqueColor(const jjPALCOLOR& color) const -> std::uint8_t
Returns the palette index closest to the given color but the transparent one, index 0.

Function documentation

jjPALCOLOR& Jazz2::Scripting::Legacy::jjPAL::getColor(std::uint8_t idx)

Returns the color at a palette index.

Changes made to the returned color edit the palette directly; they show on screen once the palette is applied with apply().

void Jazz2::Scripting::Legacy::jjPAL::apply()

Makes this palette the one the game draws with.

Also copies the colors into jjPalette. Call it after every change, including changes made to jjPalette itself. Index 0 is always transparent.

bool Jazz2::Scripting::Legacy::jjPAL::load(const String& filename)

Loads the palette from a file and returns whether it succeeded.

Accepts the palette of a tile set (.j2t), a Windows palette file (plain or in a RIFF container), or otherwise raw red, green and blue bytes for each entry. Entries the file doesn't contain keep their colors. Returns false only if the file can't be opened or read.

void Jazz2::Scripting::Legacy::jjPAL::fill(std::uint8_t red, std::uint8_t green, std::uint8_t blue, float opacity)

Fills the whole palette with a color.

With opacity below 1.0, the color is only mixed into the existing colors, tinting them.

void Jazz2::Scripting::Legacy::jjPAL::fillTint(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t start, std::uint8_t length, float opacity)

Fills a range of the palette with a color.

Replaces length entries from start, by default all but the first and the last one. With opacity below 1.0, the color is only mixed into the existing colors, tinting them.

void Jazz2::Scripting::Legacy::jjPAL::gradient(std::uint8_t red1, std::uint8_t green1, std::uint8_t blue1, std::uint8_t red2, std::uint8_t green2, std::uint8_t blue2, std::uint8_t start, std::uint8_t length, float opacity, bool inclusive)

Writes a gradient between two colors into a range of the palette.

Replaces length entries from start; the defaults cover the entries used by water and most textured backgrounds. When inclusive is false, the gradient stops one step short of the second color, otherwise the last entry is exactly the second color. With opacity below 1.0, the gradient is only mixed into the existing colors.

void Jazz2::Scripting::Legacy::jjPAL::copyFrom(std::uint8_t start, std::uint8_t length, std::uint8_t start2, const jjPAL& source, float opacity)

Copies a range of colors from another palette.

Copies length colors of source from index start2 to this palette from index start. With opacity below 1.0, they are only mixed into the existing colors.