jjPIXELMAP class JJ2+
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.
Constructors
- jjPIXELMAP(uint16 tileID = 0, const jjPAL&in palette = jjPalette)
- Creates a 32×32 pixel map from the image of a tile
- jjPIXELMAP(uint width, uint height)
- Creates a transparent pixel map of the given size in pixels
- jjPIXELMAP(const jjPIXELMAP&in other) C++
- Creates a copy of another pixel map
- jjPIXELMAP(const jjANIMFRAME@ animFrame, const jjPAL&in palette = jjPalette) partially supported
- Creates a pixel map with the size and the image of an animation frame
- jjPIXELMAP(uint left, uint top, uint width, uint height, uint layer = 4, const jjPAL&in palette = jjPalette)
- Creates a pixel map from an area of one of the original layers
- jjPIXELMAP(uint left, uint top, uint width, uint height, const jjLAYER&in layer, const jjPAL&in palette = jjPalette)
- Creates a pixel map from an area of a layer
- jjPIXELMAP(TEXTURE::Texture texture, const jjPAL&in palette = jjPalette)
- Creates a 256×256 pixel map from a texture
- jjPIXELMAP(const string&in filename, const jjPAL&in palette = jjPalette, uint8 threshold = 1)
- Creates a pixel map from an image file
- jjPIXELMAP(const jjCOLORMAP&in colorMap, const jjPAL&in palette = jjPalette)
- Creates a pixel map from a color map
Functions
- jjPIXELMAP& addBorders(int left, int top, int right, int bottom, uint8 borderColor = 0)
- Adds or removes a border on each edge
- jjPIXELMAP& crop(uint left, uint top, uint width, uint height)
- Crops the image to a rectangle
- jjPIXELMAP& flip(SPRITE::Direction directions)
- Flips the image across one or both axes
- bool makeTexture(jjLAYER@ layer = null) const
- Makes the image the texture of a layer
- jjPIXELMAP& recolor(const array<uint8>&in colorMapping)
- Recolors the image through a color mapping
- jjPIXELMAP& resize(uint width, uint height)
- Scales the image to a new size by nearest-neighbor sampling
- jjPIXELMAP& 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, const jjPAL&in palette = jjPalette) const partially supported
- Saves the image to a PNG file
- jjPIXELMAP& trim(uint&out left, uint&out top, uint&out right, uint&out bottom, uint8 trimColor = 0)
- Removes the rows and columns of a single color from the edges, telling how many were removed
- jjPIXELMAP& trim(uint8 trimColor = 0)
- Removes the rows and columns of a single color from the edges
Operators
Properties
Constructor documentation
jjPIXELMAP:: jjPIXELMAP(uint16 tileID = 0,
const jjPAL&in palette = jjPalette)
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.
jjPIXELMAP:: jjPIXELMAP(uint width,
uint 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.
jjPIXELMAP:: jjPIXELMAP(const jjANIMFRAME@ animFrame,
const jjPAL&in palette = jjPalette)
Creates a pixel map with the size and the image of an animation frame
jjPIXELMAP:: jjPIXELMAP(uint left,
uint top,
uint width,
uint height,
uint layer = 4,
const jjPAL&in palette = jjPalette)
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.
jjPIXELMAP:: jjPIXELMAP(TEXTURE::Texture texture,
const jjPAL&in palette = jjPalette)
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.
jjPIXELMAP:: jjPIXELMAP(const string&in filename,
const jjPAL&in palette = jjPalette,
uint8 threshold = 1)
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.
jjPIXELMAP:: jjPIXELMAP(const jjCOLORMAP&in colorMap,
const jjPAL&in palette = jjPalette)
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.
Function documentation
jjPIXELMAP& jjPIXELMAP:: addBorders(int left,
int top,
int right,
int bottom,
uint8 borderColor = 0)
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& jjPIXELMAP:: flip(SPRITE::Direction directions)
Flips the image across one or both axes
Takes SPRITE::FLIPH, SPRITE::FLIPV or SPRITE::FLIPHV. Returns the map itself.
bool jjPIXELMAP:: makeTexture(jjLAYER@ layer = null) 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& jjPIXELMAP:: recolor(const array<uint8>&in 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& jjPIXELMAP:: 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.
jjPIXELMAP& jjPIXELMAP:: rotate()
Rotates the image by 90 degrees clockwise
The width and the height swap. Returns the map itself.
bool jjPIXELMAP:: save(uint16 tileID,
bool hFlip = false) 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 jjPIXELMAP:: save(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.
jjPIXELMAP& jjPIXELMAP:: trim(uint&out left,
uint&out top,
uint&out right,
uint&out bottom,
uint8 trimColor = 0)
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& jjPIXELMAP:: trim(uint8 trimColor = 0)
Removes the rows and columns of a single color from the edges
See the overload with output arguments. Returns the map itself.