DEKI/ENGINE docs
Deki 0.19.0
Modular C++ 2D engine for embedded displays and desktop
Loading...
Searching...
No Matches
DekiEditor::TextureImporter Class Reference

#include <C:/Users/kirby/Documents/Github/deki/deki-editor/deki-editor/include/deki-editor/TextureImporter.h>

Inherits DekiEditor::IAssetImporter.

Public Member Functions

std::vector< std::string > GetSupportedExtensions () const override
 The extensions it handles, e.g. {".png", ".jpg", ".bmp"}.
std::string GetImporterName () const override
 A name for logs.
ImportResult Import (const std::string &sourcePath, const std::string &cachePath) override
 Imports the source file into the cache.
ImportResult ImportWithFormat (const std::string &sourcePath, const std::string &cachePath, TextureFormat format)
 Imports with the given stored format.
Public Member Functions inherited from DekiEditor::IAssetImporter
virtual ~IAssetImporter ()=default
virtual bool NeedsReimport (const std::string &sourcePath, const std::string &cachePath) const
 Whether the asset needs importing again.

Static Public Member Functions

static bool WriteTexFile (const std::string &path, const uint8_t *rgbaData, uint32_t width, uint32_t height, TextureFormat format=TextureFormat::RGB565A8, const SpriteSettings *spriteSettings=nullptr, const std::vector< SubAssetInfo > *frameSubAssets=nullptr, const ChromaKeySettings *chromaKey=nullptr, uint32_t sourceWidth=0, uint32_t sourceHeight=0)
static bool ReadTexFile (const std::string &path, TexData &outData)
static bool ReadSourceSize (const std::string &texPath, int &outWidth, int &outHeight)
 The size of the image a compiled texture was made from.
static std::vector< uint8_t > ConvertToRGBA (const TexData &data)
static bool HasAlphaChannel (const uint8_t *rgbaData, size_t pixelCount)
 True if any pixel in the RGBA buffer has alpha < 255.
static std::vector< AtlasFrame > AutoDetectFrames (const uint8_t *rgbaData, uint32_t width, uint32_t height, uint8_t alphaThreshold=10, int minWidth=1, int minHeight=1)
 Finds sprite frames in an RGBA image by looking for regions separated by transparent pixels.
static void CarryFrameIds (const std::vector< AtlasFrame > &previous, std::vector< AtlasFrame > &frames, int32_t &nextId)
 Gives re-sliced frames the ids of the frames they replace, so references to a frame survive a new grid size or a fresh auto-detect.
static std::vector< SubAssetInfo > GenerateFrameSubAssets (const std::string &parentGuid, int texWidth, int texHeight, const SpriteSettings &settings)
 One sub-asset per sprite frame that settings slices from the texture parentGuid.
static const SpriteFrameData * GetFrameData (const std::string &frameGuid)
 The frame registered as frameGuid, or nullptr.
static void RegisterFrameData (const std::string &frameGuid, const SpriteFrameData &data)
static void ClearFrameData ()
 Clears all registered frames. Called when the asset cache is rebuilt.
static void SetFrameNineSlice (const std::string &frameGuid, bool has, uint16_t left, uint16_t right, uint16_t top, uint16_t bottom)
 Sets a frame's own 9-slice borders, measured inside the frame in the image's pixels.
static bool HasFrameListChunk (const std::string &texPath)
 True if the .tex file at texPath has a FrameList metadata chunk.

Member Function Documentation

◆ GetSupportedExtensions()

std::vector< std::string > DekiEditor::TextureImporter::GetSupportedExtensions ( ) const
inlineoverridevirtual

The extensions it handles, e.g. {".png", ".jpg", ".bmp"}.

Implements DekiEditor::IAssetImporter.

◆ GetImporterName()

std::string DekiEditor::TextureImporter::GetImporterName ( ) const
inlineoverridevirtual

A name for logs.

Implements DekiEditor::IAssetImporter.

◆ Import()

ImportResult DekiEditor::TextureImporter::Import ( const std::string & sourcePath,
const std::string & cachePath )
overridevirtual

Imports the source file into the cache.

Implements DekiEditor::IAssetImporter.

◆ ImportWithFormat()

ImportResult DekiEditor::TextureImporter::ImportWithFormat ( const std::string & sourcePath,
const std::string & cachePath,
TextureFormat format )

Imports with the given stored format.

◆ WriteTexFile()

bool DekiEditor::TextureImporter::WriteTexFile ( const std::string & path,
const uint8_t * rgbaData,
uint32_t width,
uint32_t height,
TextureFormat format = TextureFormat::RGB565A8,
const SpriteSettings * spriteSettings = nullptr,
const std::vector< SubAssetInfo > * frameSubAssets = nullptr,
const ChromaKeySettings * chromaKey = nullptr,
uint32_t sourceWidth = 0,
uint32_t sourceHeight = 0 )
static

◆ ReadTexFile()

bool DekiEditor::TextureImporter::ReadTexFile ( const std::string & path,
TexData & outData )
static

◆ ReadSourceSize()

bool DekiEditor::TextureImporter::ReadSourceSize ( const std::string & texPath,
int & outWidth,
int & outHeight )
static

The size of the image a compiled texture was made from.

A texture stored smaller than its image (Max Size) records the image's size; frames, nine-slice borders and tilesets are in those pixels. For any other texture it is the stored size. False when the file cannot be read.

◆ ConvertToRGBA()

std::vector< uint8_t > DekiEditor::TextureImporter::ConvertToRGBA ( const TexData & data)
static

◆ HasAlphaChannel()

bool DekiEditor::TextureImporter::HasAlphaChannel ( const uint8_t * rgbaData,
size_t pixelCount )
static

True if any pixel in the RGBA buffer has alpha < 255.

◆ AutoDetectFrames()

std::vector< AtlasFrame > DekiEditor::TextureImporter::AutoDetectFrames ( const uint8_t * rgbaData,
uint32_t width,
uint32_t height,
uint8_t alphaThreshold = 10,
int minWidth = 1,
int minHeight = 1 )
static

Finds sprite frames in an RGBA image by looking for regions separated by transparent pixels.

Pixels with alpha below alphaThreshold count as transparent. Regions smaller than minWidth x minHeight are ignored.

◆ CarryFrameIds()

void DekiEditor::TextureImporter::CarryFrameIds ( const std::vector< AtlasFrame > & previous,
std::vector< AtlasFrame > & frames,
int32_t & nextId )
static

Gives re-sliced frames the ids of the frames they replace, so references to a frame survive a new grid size or a fresh auto-detect.

A frame with exactly the rect of an earlier one takes its id; next, one that overlaps an earlier one by at least half of their union does. The rest get new ids from nextId, which never hands out an id twice, so a reference to a deleted frame never lands on a new one. A previous id of -1 means the frame's position.

◆ GenerateFrameSubAssets()

std::vector< SubAssetInfo > DekiEditor::TextureImporter::GenerateFrameSubAssets ( const std::string & parentGuid,
int texWidth,
int texHeight,
const SpriteSettings & settings )
static

One sub-asset per sprite frame that settings slices from the texture parentGuid.

Empty when there are no frames.

◆ GetFrameData()

const SpriteFrameData * DekiEditor::TextureImporter::GetFrameData ( const std::string & frameGuid)
static

The frame registered as frameGuid, or nullptr.

◆ RegisterFrameData()

void DekiEditor::TextureImporter::RegisterFrameData ( const std::string & frameGuid,
const SpriteFrameData & data )
static

◆ ClearFrameData()

void DekiEditor::TextureImporter::ClearFrameData ( )
static

Clears all registered frames. Called when the asset cache is rebuilt.

◆ SetFrameNineSlice()

void DekiEditor::TextureImporter::SetFrameNineSlice ( const std::string & frameGuid,
bool has,
uint16_t left,
uint16_t right,
uint16_t top,
uint16_t bottom )
static

Sets a frame's own 9-slice borders, measured inside the frame in the image's pixels.

WriteTexFile stores them after the frame list. has false removes them. ClearFrameData clears them too.

◆ HasFrameListChunk()

bool DekiEditor::TextureImporter::HasFrameListChunk ( const std::string & texPath)
static

True if the .tex file at texPath has a FrameList metadata chunk.


The documentation for this class was generated from the following file: