jjCOLORMAP class JJ2+

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.

Constructors

jjCOLORMAP(uint16 tileID = 0, const jjPAL&in palette = jjPalette)
Creates a 32×32 color map from the image of a tile
jjCOLORMAP(uint width, uint height)
Creates a fully transparent color map of the given size in pixels
jjCOLORMAP(const jjPIXELMAP&in pixelMap, const jjPAL&in palette = jjPalette) C++
Creates a color map from a pixel map in the colors of a palette
jjCOLORMAP(const jjCOLORMAP&in other) C++
Creates a copy of another color map
jjCOLORMAP(const jjANIMFRAME@ animFrame, const jjPAL&in palette = jjPalette)
Creates a color map with the size and the image of an animation frame
jjCOLORMAP(uint left, uint top, uint width, uint height, uint layer = 4, const jjPAL&in palette = jjPalette)
Creates a color map from an area of one of the original layers
jjCOLORMAP(uint left, uint top, uint width, uint height, const jjLAYER&in layer, const jjPAL&in palette = jjPalette)
Creates a color map from an area of a layer
jjCOLORMAP(TEXTURE::Texture texture, const jjPAL&in palette = jjPalette) partially supported
Creates a 256×256 color map from a texture
jjCOLORMAP(const string&in filename)
Creates a color map from an image file

Functions

jjCOLORMAP& addBorders(int left, int top, int right, int bottom, jjPALCOLOR borderColor = jjPALCOLOR())
Adds or removes a border on each edge
jjCOLORMAP& crop(uint left, uint top, uint width, uint height)
Crops the image to a rectangle
jjCOLORMAP& flip(SPRITE::Direction directions)
Flips the image across one or both axes
jjCOLORMAP& resize(uint width, uint height)
Scales the image to a new size by nearest-neighbor sampling
jjCOLORMAP& rotate()
Rotates the image by 90 degrees clockwise
bool save(uint16 tileID, bool hFlip = false) const partially supported
Saves the image into a tile
bool save(jjANIMFRAME@ frame) const
Replaces the image of an animation frame
bool save(const string&in filename, bool allowCompression = false) const partially supported
Saves the image to a PNG file
jjCOLORMAP& swizzle(COLOR::Component red, COLOR::Component green, COLOR::Component blue, COLOR::Component alpha = COLOR::ALPHA)
Rearranges the components of every color
jjCOLORMAP& trim(uint&out left, uint&out top, uint&out right, uint&out bottom, uint8 trimAlpha = 0)
Removes the nearly transparent rows and columns from the edges, telling how many were removed
jjCOLORMAP& trim(uint8 trimAlpha = 0)
Removes the nearly transparent rows and columns from the edges

Operators

jjPALCOLOR& opIndex(uint x, uint y) []
Returns the color at the given position
const jjPALCOLOR& opIndex(uint x, uint y) const []
Returns the color at the given position

Properties

const uint height
Height of the image in pixels
const uint width
Width of the image in pixels

Constructor documentation

jjCOLORMAP::jjCOLORMAP(uint16 tileID = 0, const jjPAL&in palette = jjPalette)

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.

jjCOLORMAP::jjCOLORMAP(uint width, uint 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.

jjCOLORMAP::jjCOLORMAP(const jjANIMFRAME@ animFrame, const jjPAL&in palette = jjPalette)

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

A 32-bit frame keeps its own colors.

jjCOLORMAP::jjCOLORMAP(uint left, uint top, uint width, uint height, uint layer = 4, const jjPAL&in palette = jjPalette)

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.

jjCOLORMAP::jjCOLORMAP(uint left, uint top, uint width, uint height, const jjLAYER&in layer, const jjPAL&in palette = jjPalette)

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.

jjCOLORMAP::jjCOLORMAP(TEXTURE::Texture texture, const jjPAL&in palette = jjPalette)

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.

jjCOLORMAP::jjCOLORMAP(const string&in 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.

Function documentation

jjCOLORMAP& jjCOLORMAP::addBorders(int left, int top, int right, int bottom, jjPALCOLOR borderColor = jjPALCOLOR())

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& jjCOLORMAP::crop(uint left, uint top, uint width, uint 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& jjCOLORMAP::flip(SPRITE::Direction directions)

Flips the image across one or both axes

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

jjCOLORMAP& jjCOLORMAP::resize(uint width, uint 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& jjCOLORMAP::rotate()

Rotates the image by 90 degrees clockwise

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

bool jjCOLORMAP::save(uint16 tileID, bool hFlip = false) 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 jjCOLORMAP::save(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 jjCOLORMAP::save(const string&in filename, bool allowCompression = false) const

Saves the image to a PNG file

jjCOLORMAP& jjCOLORMAP::swizzle(COLOR::Component red, COLOR::Component green, COLOR::Component blue, COLOR::Component alpha = COLOR::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& jjCOLORMAP::trim(uint&out left, uint&out top, uint&out right, uint&out bottom, uint8 trimAlpha = 0)

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& jjCOLORMAP::trim(uint8 trimAlpha = 0)

Removes the nearly transparent rows and columns from the edges

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

Operator documentation

jjPALCOLOR& jjCOLORMAP::opIndex(uint x, uint 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.

const jjPALCOLOR& jjCOLORMAP::opIndex(uint x, uint y) const []

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.

Property documentation

const uint jjCOLORMAP::height

Height of the image in pixels

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

const uint jjCOLORMAP::width

Width of the image in pixels

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