Jazz2/Editor/Imaging/TileImages.h file

Namespaces

namespace Jazz2
Root namespace of Jazz² Resurrection.
namespace Jazz2::Editor

Classes

struct Jazz2::Editor::TileImportOptions
How an image is made into a tile set, see SliceTileSet().
struct Jazz2::Editor::TileImportResult
What SliceTileSet() did.

Enums

enum class TileImportColors : std::uint8_t { OwnPalette, TrueColor, MatchPalette, Reduce }
What the colors of the tiles of an image become, see SliceTileSet().
enum class TileImportError : std::uint8_t { None, TooSmall, TooManyTiles, Cancelled }
Why SliceTileSet() couldn't make a tile set.

Functions

auto MakeTileSetSheet(const Formats::TileSetData& tileSet, const std::uint32_t* palette, std::int32_t columns) -> PngImage
Puts the tiles of a tile set side by side into an image, rows of columns of them.
auto MakeTileSetMaskSheet(const Formats::TileSetData& tileSet, std::int32_t columns) -> PngImage
Puts the collision masks of the tiles of a tile set side by side, solid pixels black, the others transparent.
auto MakeTileImage(const std::uint8_t* indices, const std::uint32_t* palette) -> PngImage
Makes an image of a tile, 32 × 32 palette indices with the colors of palette, entry 0 transparent.
auto HashTileOf(const Formats::TileSetData& data, std::int32_t tile) -> std::uint64_t
Returns a hash of a tile of a tile set, by which the same tiles are found.
auto ReadTileFromImage(const PngImage& image, std::int32_t x, std::int32_t y, const std::uint32_t* palette, std::uint8_t* indices) -> bool
Reads 32 × 32 pixels of an image from a position as palette indices.
auto MakeTextureImage(const std::uint8_t* indices, std::int32_t size, const std::uint32_t* palette) -> PngImage
Makes an indexed image of size × size palette indices with the colors of palette, entry 0 transparent.
auto ReadTextureFromImage(const PngImage& image, std::int32_t size, const std::uint32_t* palette, std::uint8_t* indices) -> bool
Reads an image of size × size pixels as palette indices, as ReadTileFromImage() reads a tile.
auto GetTileGrid(const PngImage& image, const TileImportOptions& options) -> nCine::Vector2i
Number of columns and rows of tiles in an image with the layout of options, see SliceTileSet().
auto SliceTileSet(const PngImage& image, const TileImportOptions& options, Formats::TileSetData& tileSet, TileImportResult& result) -> bool
Makes a tile set of an image, tiles of 32 × 32 pixels row by row.

Variables

std::int32_t MaxImportedTiles constexpr
Most tiles a tile set can have, as its file stores the number of them in 16 bits.

Enum documentation

enum class TileImportColors : std::uint8_t

What the colors of the tiles of an image become, see SliceTileSet().

Enumerators
OwnPalette

The indices of an indexed image, with its palette as the palette of the tile set

TrueColor

The colors as they are, true color tiles

MatchPalette

The closest colors of a palette, the palette of the tile set

Reduce

The colors reduced to a palette made for them, with the locked entries of a palette kept, see BuildPalette()

enum class TileImportError : std::uint8_t

Why SliceTileSet() couldn't make a tile set.

Enumerators
None

It could

TooSmall

The image is smaller than a tile

TooManyTiles

The tile set would have more tiles than MaxImportedTiles

Cancelled

TileImportOptions::Progress stopped it

Function documentation

PngImage MakeTileSetSheet(const Formats::TileSetData& tileSet, const std::uint32_t* palette, std::int32_t columns)

Puts the tiles of a tile set side by side into an image, rows of columns of them.

The image is indexed with the palette of the tile set if all of its tiles are 8-bit ones, entry 0 transparent, so it can be edited and read back without losing anything. It's RGBA otherwise, the 8-bit tiles in the colors of palette.

std::uint64_t HashTileOf(const Formats::TileSetData& data, std::int32_t tile)

Returns a hash of a tile of a tile set, by which the same tiles are found.

Of the pixels (a byte each of an 8-bit tile, 4 of a true color one), the mask and whether it's a true color tile. Equal tiles have equal hashes, the tiles of equal hashes still have to be compared.

bool ReadTileFromImage(const PngImage& image, std::int32_t x, std::int32_t y, const std::uint32_t* palette, std::uint8_t* indices)

Reads 32 × 32 pixels of an image from a position as palette indices.

Pixels that are more transparent than opaque are index 0. An indexed image that has the same colors as palette keeps its indices, other colors are the closest entry of palette, as they look. Pixels outside of the image are transparent. Returns true if any color was changed to a close one.

PngImage MakeTextureImage(const std::uint8_t* indices, std::int32_t size, const std::uint32_t* palette)

Makes an indexed image of size × size palette indices with the colors of palette, entry 0 transparent.

As a texture of its own of a layer is stored (see Formats::LayerPropertiesChunk), so it can be edited and read back by ReadTextureFromImage() without losing anything.

bool ReadTextureFromImage(const PngImage& image, std::int32_t size, const std::uint32_t* palette, std::uint8_t* indices)

Reads an image of size × size pixels as palette indices, as ReadTileFromImage() reads a tile.

Returns true if any color was changed to a close one.

bool SliceTileSet(const PngImage& image, const TileImportOptions& options, Formats::TileSetData& tileSet, TileImportResult& result)

Makes a tile set of an image, tiles of 32 × 32 pixels row by row.

The first tile of a tile set is the empty one, an empty one is put first if the image doesn't start with one. Empty tiles at the end of the image are left out. A tile is empty if none of its pixels can be seen and its mask is empty. Returns false and why in TileImportResult::Error if the image has no tile in it, or more than MaxImportedTiles of them would be left — that's found as soon as there are, before the rest is sliced.