Jazz2::Scripting::Legacy::jjPIXELMAP class

Editable 8-bit image.

A rectangular array of palette indices, where 0 is transparent. A pixel map can be created from a tile, an animation frame, a texture, an area of a layer, an image file, a color map or just a size, edited pixel by pixel or by its transforming methods, and then saved into a tile or an animation frame, or used as the texture of a layer. Only the size of the image matters when saving, not where it came from.

Where a source has 32-bit colors, such as a true color tile or an image file, the optional palette of the constructor maps them to its nearest entries. It defaults to jjPalette.

Public static functions

static auto CreateFromTile(std::uint16_t tileID, const jjPAL* palette) -> jjPIXELMAP*
Creates a 32×32 pixel map from the image of a tile.
static auto CreateFromSize(std::uint32_t width, std::uint32_t height) -> jjPIXELMAP*
Creates a transparent pixel map of the given size in pixels.
static auto CreateFromOther(const jjPIXELMAP& other) -> jjPIXELMAP*
Creates a copy of another pixel map.
static auto CreateFromFrame(const jjANIMFRAME* animFrame, const jjPAL* palette) -> jjPIXELMAP* partially supported
Creates a pixel map with the size and the image of an animation frame.
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) -> jjPIXELMAP*
Creates a pixel 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) -> jjPIXELMAP*
Creates a pixel map from an area of a layer.
static auto CreateFromTexture(std::uint32_t texture, const jjPAL* palette) -> jjPIXELMAP*
Creates a 256×256 pixel map from a texture.
static auto CreateFromFilename(const String& filename, const jjPAL* palette, std::uint8_t threshold) -> jjPIXELMAP*
Creates a pixel map from an image file.
static auto CreateFromColorMap(const jjCOLORMAP& other, const jjPAL* palette) -> jjPIXELMAP*
Creates a pixel map from a color map.

Constructors, destructors, conversion operators

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

Public functions

void AddRef()
Increments the reference count.
void Release()
Decrements the reference count.
auto operator=(const jjPIXELMAP& o) -> jjPIXELMAP&
auto GetPixel(std::uint32_t x, std::uint32_t y) -> std::uint8_t*
Returns the pixel 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, const jjPAL& palette) const -> bool partially supported
Saves the image to a PNG file.
auto makeTexture(jjLAYER* layer) const -> bool
Makes the image the texture of a layer.
auto addBorders(std::int32_t left, std::int32_t top, std::int32_t right, std::int32_t bottom, std::uint8_t borderColor) -> jjPIXELMAP&
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) -> jjPIXELMAP&
Crops the image to a rectangle.
auto flip(std::int32_t directions) -> jjPIXELMAP&
Flips the image across one or both axes.
auto recolor(const CScriptArray& colorMapping) -> jjPIXELMAP&
Recolors the image through a color mapping.
auto resize(std::uint32_t width, std::uint32_t height) -> jjPIXELMAP&
Scales the image to a new size by nearest-neighbor sampling.
auto rotate() -> jjPIXELMAP&
Rotates the image by 90 degrees clockwise.
auto trim(std::uint32_t& left, std::uint32_t& top, std::uint32_t& right, std::uint32_t& bottom, std::uint8_t trimColor) -> jjPIXELMAP&
Removes the rows and columns of a single color from the edges, telling how many were removed.
auto trimBasic(std::uint8_t trimColor) -> jjPIXELMAP&
Removes the rows and columns of a single color from the edges.

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 jjPIXELMAP* Jazz2::Scripting::Legacy::jjPIXELMAP::CreateFromTile(std::uint16_t tileID, const jjPAL* palette)

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

TILE::HFLIPPED and TILE::VFLIPPED in tileID flip the image, an animated tile gives the frame it shows now. A tile the level doesn't have gives a transparent map.

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

Creates a transparent pixel 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 jjPIXELMAP* Jazz2::Scripting::Legacy::jjPIXELMAP::CreateFromFrame(const jjANIMFRAME* animFrame, const jjPAL* palette)

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

static jjPIXELMAP* Jazz2::Scripting::Legacy::jjPIXELMAP::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 pixel 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. Makes it easy to compose an image from several tiles placed next to each other. The part out of the layer is transparent.

static jjPIXELMAP* Jazz2::Scripting::Legacy::jjPIXELMAP::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 pixel 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 jjPIXELMAP* Jazz2::Scripting::Legacy::jjPIXELMAP::CreateFromTexture(std::uint32_t texture, const jjPAL* palette)

Creates a 256×256 pixel map from a texture.

TEXTURE::FROMTILES takes the 8×8 tiles at the top left corner of jjLayers[8]. The other textures are read from a data file in the game's Source directory, if it's missing, the map stays transparent.

static jjPIXELMAP* Jazz2::Scripting::Legacy::jjPIXELMAP::CreateFromFilename(const String& filename, const jjPAL* palette, std::uint8_t threshold)

Creates a pixel map from an image file.

The palette indices of an image with a palette are taken as they are, regardless of its colors, so the image should use a palette that matches the level's. The colors of any other image are mapped to the nearest entries of palette, a pixel with alpha lower than threshold (or no alpha at all) stays transparent. A file that can't be read gives a 1×1 map.

static jjPIXELMAP* Jazz2::Scripting::Legacy::jjPIXELMAP::CreateFromColorMap(const jjCOLORMAP& other, const jjPAL* palette)

Creates a pixel map from a color map.

Each color becomes the nearest entry of palette, a pixel with no alpha becomes transparent and any other pixel is opaque.

std::uint8_t* Jazz2::Scripting::Legacy::jjPIXELMAP::GetPixel(std::uint32_t x, std::uint32_t y)

Returns the pixel at the given position.

A palette index, 0 is transparent. 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 0, and what's written there is lost.

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

Saves the image into a tile.

The map has to be exactly 32×32 pixels. TILE::HFLIPPED and TILE::VFLIPPED in tileID flip the image, so the tile shows the map when it's drawn flipped that way. Returns false if the size is wrong or tileID is an animated tile.

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

Replaces the image of an animation frame.

The frame takes 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::jjPIXELMAP::saveToFile(const String& filename, const jjPAL& palette) const

Saves the image to a PNG file.

bool Jazz2::Scripting::Legacy::jjPIXELMAP::makeTexture(jjLAYER* layer) const

Makes the image the texture of a layer.

The map has to be exactly 256×256 pixels. Without a layer, jjLayers[8] is used. The layer's texture then reads as TEXTURE::CUSTOM. Returns false if the size is wrong or the layer isn't part of the level.

jjPIXELMAP& Jazz2::Scripting::Legacy::jjPIXELMAP::addBorders(std::int32_t left, std::int32_t top, std::int32_t right, std::int32_t bottom, std::uint8_t 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, 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.

jjPIXELMAP& Jazz2::Scripting::Legacy::jjPIXELMAP::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.

jjPIXELMAP& Jazz2::Scripting::Legacy::jjPIXELMAP::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.

jjPIXELMAP& Jazz2::Scripting::Legacy::jjPIXELMAP::recolor(const CScriptArray& colorMapping)

Recolors the image through a color mapping.

Every pixel is replaced by the entry of colorMapping at its palette index, e.g. pixels of index 10 become colorMapping[10]. Nothing changes if the mapping has fewer than 256 entries. Returns the map itself.

jjPIXELMAP& Jazz2::Scripting::Legacy::jjPIXELMAP::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.

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

Rotates the image by 90 degrees clockwise.

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

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

Removes the rows and columns of a single color from the edges, telling how many were removed.

Every outer row and column made only of trimColor (by default transparent) is removed. The output arguments receive how many were removed from each edge. If the whole image is trimColor, it's cropped to 1×1, and left and right receive the former width, top and bottom the former height. Returns the map itself.

jjPIXELMAP& Jazz2::Scripting::Legacy::jjPIXELMAP::trimBasic(std::uint8_t trimColor)

Removes the rows and columns of a single color from the edges.

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

Variable documentation

std::uint32_t Jazz2::Scripting::Legacy::jjPIXELMAP::width

Width of the image in pixels.

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

std::uint32_t Jazz2::Scripting::Legacy::jjPIXELMAP::height

Height of the image in pixels.

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