Jazz2::Scripting::Legacy::jjCOLORMAP class

Editable 32-bit image with alpha.

The true color counterpart of jjPIXELMAP, each pixel is a jjPALCOLOR with its own alpha. An 8-bit source is converted through the palette given to the constructor, by default jjPalette: index 0 becomes fully transparent, any other index the color of that palette entry, fully opaque. A 32-bit source keeps its colors.

Saved into a tile of a palette-indexed tile set, the colors are reduced to the nearest entries of jjPalette.

Public static functions

static auto CreateFromSize(std::uint32_t width, std::uint32_t height) -> jjCOLORMAP*
Creates a fully transparent color map of the given size in pixels.
static auto CreateFromPixelMap(const jjPIXELMAP& other, const jjPAL& palette) -> jjCOLORMAP*
Creates a color map from a pixel map in the colors of a palette.
static auto CreateFromOther(const jjCOLORMAP& other) -> jjCOLORMAP*
Creates a copy of another color map.
static auto CreateFromFrame(const jjANIMFRAME* animFrame, const jjPAL& palette) -> jjCOLORMAP*
Creates a color map with the size and the image of an animation frame.
static auto CreateFromTexture(std::uint32_t texture, const jjPAL& palette) -> jjCOLORMAP* partially supported
Creates a 256×256 color map from a texture.
static auto CreateFromTile(std::uint16_t tileID, const jjPAL& palette) -> jjCOLORMAP*
Creates a 32×32 color map from the image of a tile.
static auto CreateFromLayer(std::uint32_t left, std::uint32_t top, std::uint32_t width, std::uint32_t height, std::uint32_t layer, const jjPAL& palette) -> jjCOLORMAP*
Creates a color map from an area of one of the original layers.
static auto CreateFromLayerObject(std::uint32_t left, std::uint32_t top, std::uint32_t width, std::uint32_t height, const jjLAYER& layer, const jjPAL& palette) -> jjCOLORMAP*
Creates a color map from an area of a layer.
static auto CreateFromFilename(const String& filename) -> jjCOLORMAP*
Creates a color map from an image file.

Constructors, destructors, conversion operators

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

Public functions

void AddRef()
Increments the reference count.
void Release()
Decrements the reference count.
auto operator=(const jjCOLORMAP& o) -> jjCOLORMAP&
auto GetPixel(std::uint32_t x, std::uint32_t y) -> jjPALCOLOR*
Returns the color at the given position.
auto saveToTile(std::uint16_t tileID, bool hFlip) const -> bool partially supported
Saves the image into a tile.
auto saveToFrame(jjANIMFRAME* frame) const -> bool
Replaces the image of an animation frame.
auto saveToFile(const String& filename, bool allowCompression) const -> bool partially supported
Saves the image to a PNG file.
auto addBorders(std::int32_t left, std::int32_t top, std::int32_t right, std::int32_t bottom, jjPALCOLOR borderColor) -> jjCOLORMAP&
Adds or removes a border on each edge.
auto crop(std::uint32_t left, std::uint32_t top, std::uint32_t width, std::uint32_t height) -> jjCOLORMAP&
Crops the image to a rectangle.
auto flip(std::int32_t directions) -> jjCOLORMAP&
Flips the image across one or both axes.
auto resize(std::uint32_t width, std::uint32_t height) -> jjCOLORMAP&
Scales the image to a new size by nearest-neighbor sampling.
auto rotate() -> jjCOLORMAP&
Rotates the image by 90 degrees clockwise.
auto swizzle(std::uint32_t red, std::uint32_t green, std::uint32_t blue, std::uint32_t alpha) -> jjCOLORMAP&
Rearranges the components of every color.
auto trim(std::uint32_t& left, std::uint32_t& top, std::uint32_t& right, std::uint32_t& bottom, std::uint8_t trimAlpha) -> jjCOLORMAP&
Removes the nearly transparent rows and columns from the edges, telling how many were removed.
auto trimBasic(std::uint8_t trimAlpha) -> jjCOLORMAP&
Removes the nearly transparent rows and columns from the edges.
auto ToIndices(const jjPAL& palette) const -> std::unique_ptr<std::uint8_t[]>
Returns the palette indices of the image, the nearest colors of a palette, 0 where there's no alpha.

Public variables

std::uint32_t width
Width of the image in pixels.
std::uint32_t height
Height of the image in pixels.

Function documentation

static jjCOLORMAP* Jazz2::Scripting::Legacy::jjCOLORMAP::CreateFromSize(std::uint32_t width, std::uint32_t height)

Creates a fully transparent color map of the given size in pixels.

A map of more than 8192×8192 pixels in total can't be created and raises a script exception.

static jjCOLORMAP* Jazz2::Scripting::Legacy::jjCOLORMAP::CreateFromFrame(const jjANIMFRAME* animFrame, const jjPAL& palette)

Creates a color map with the size and the image of an animation frame.

A 32-bit frame keeps its own colors.

static jjCOLORMAP* Jazz2::Scripting::Legacy::jjCOLORMAP::CreateFromTexture(std::uint32_t texture, const jjPAL& palette)

Creates a 256×256 color map from a texture.

TEXTURE::FROMTILES takes the 8×8 tiles at the top left corner of jjLayers[8], see the same constructor of jjPIXELMAP.

static jjCOLORMAP* Jazz2::Scripting::Legacy::jjCOLORMAP::CreateFromTile(std::uint16_t tileID, const jjPAL& palette)

Creates a 32×32 color map from the image of a tile.

A true color tile keeps its own colors. Flips and animated tiles are handled as by the same constructor of jjPIXELMAP.

static jjCOLORMAP* Jazz2::Scripting::Legacy::jjCOLORMAP::CreateFromLayer(std::uint32_t left, std::uint32_t top, std::uint32_t width, std::uint32_t height, std::uint32_t layer, const jjPAL& palette)

Creates a color map from an area of one of the original layers.

left, top, width and height are in pixels, layer is a number from 1 to 8, as in jjLayers. True color tiles keep their own colors, the others take those of palette. The part out of the layer is transparent.

static jjCOLORMAP* Jazz2::Scripting::Legacy::jjCOLORMAP::CreateFromLayerObject(std::uint32_t left, std::uint32_t top, std::uint32_t width, std::uint32_t height, const jjLAYER& layer, const jjPAL& palette)

Creates a color map from an area of a layer.

The same as the constructor taking a layer number. A layer that isn't part of the level gives a transparent map.

static jjCOLORMAP* Jazz2::Scripting::Legacy::jjCOLORMAP::CreateFromFilename(const String& filename)

Creates a color map from an image file.

Takes the actual colors and alpha of the image, whatever its format is. A file that can't be read gives a 1×1 map.

jjPALCOLOR* Jazz2::Scripting::Legacy::jjCOLORMAP::GetPixel(std::uint32_t x, std::uint32_t y)

Returns the color at the given position.

Pixels are stored row by row, so an x past width continues on the following rows. A position past the end of the map reads as transparent black, and what's written there is lost.

bool Jazz2::Scripting::Legacy::jjCOLORMAP::saveToTile(std::uint16_t tileID, bool hFlip) const

Saves the image into a tile.

If the tile set is drawn palette-indexed, the colors become the nearest entries of jjPalette and any pixel with non-zero alpha is opaque, so the tile follows later palette changes.

bool Jazz2::Scripting::Legacy::jjCOLORMAP::saveToFrame(jjANIMFRAME* frame) const

Replaces the image of an animation frame.

The frame becomes a 32-bit one with the size of the map, its hotspot and other spots stay as they were. Returns false if frame is null or the map is larger than 65535 pixels on either axis.

bool Jazz2::Scripting::Legacy::jjCOLORMAP::saveToFile(const String& filename, bool allowCompression) const

Saves the image to a PNG file.

jjCOLORMAP& Jazz2::Scripting::Legacy::jjCOLORMAP::addBorders(std::int32_t left, std::int32_t top, std::int32_t right, std::int32_t bottom, jjPALCOLOR borderColor)

Adds or removes a border on each edge.

A positive number of pixels extends the image on that edge, filling the new space with borderColor (transparent by default), a negative one crops it. Nothing changes if the result would be empty or more would be cropped than the image has. Returns the map itself.

jjCOLORMAP& Jazz2::Scripting::Legacy::jjCOLORMAP::crop(std::uint32_t left, std::uint32_t top, std::uint32_t width, std::uint32_t height)

Crops the image to a rectangle.

Nothing changes if the rectangle is empty or reaches out of the image. Returns the map itself.

jjCOLORMAP& Jazz2::Scripting::Legacy::jjCOLORMAP::flip(std::int32_t directions)

Flips the image across one or both axes.

Takes SPRITE::FLIPH, SPRITE::FLIPV or SPRITE::FLIPHV. Returns the map itself.

jjCOLORMAP& Jazz2::Scripting::Legacy::jjCOLORMAP::resize(std::uint32_t width, std::uint32_t height)

Scales the image to a new size by nearest-neighbor sampling.

Nothing changes if the old or the new size is 0 on either axis. Returns the map itself.

jjCOLORMAP& Jazz2::Scripting::Legacy::jjCOLORMAP::rotate()

Rotates the image by 90 degrees clockwise.

The width and the height swap. Returns the map itself.

jjCOLORMAP& Jazz2::Scripting::Legacy::jjCOLORMAP::swizzle(std::uint32_t red, std::uint32_t green, std::uint32_t blue, std::uint32_t alpha)

Rearranges the components of every color.

Each argument names the component the new one is taken from, as jjPALCOLOR::swizzle() does for a single color. Returns the map itself.

jjCOLORMAP& Jazz2::Scripting::Legacy::jjCOLORMAP::trim(std::uint32_t& left, std::uint32_t& top, std::uint32_t& right, std::uint32_t& bottom, std::uint8_t trimAlpha)

Removes the nearly transparent rows and columns from the edges, telling how many were removed.

Every outer row and column with no alpha greater than trimAlpha (by default fully transparent) is removed. The output arguments receive how many were removed from each edge. If nothing in the image is more opaque, it's cropped to 1×1, and left and right receive the former width, top and bottom the former height. Returns the map itself.

jjCOLORMAP& Jazz2::Scripting::Legacy::jjCOLORMAP::trimBasic(std::uint8_t trimAlpha)

Removes the nearly transparent rows and columns from the edges.

See the overload with output arguments. Returns the map itself.

Variable documentation

std::uint32_t Jazz2::Scripting::Legacy::jjCOLORMAP::width

Width of the image in pixels.

Read-only, changed by addBorders(), crop(), resize(), rotate() and trim().

std::uint32_t Jazz2::Scripting::Legacy::jjCOLORMAP::height

Height of the image in pixels.

Read-only, changed by addBorders(), crop(), resize(), rotate() and trim().