#pragma once #include "StarRect.hpp" #include "StarMap.hpp" #include "StarString.hpp" #include "StarThread.hpp" #include "StarAssetPath.hpp" namespace Star { STAR_CLASS(ImageMetadataDatabase); // Caches image size, image spaces, and nonEmptyRegion completely until a // reload, does not expire cached values in a TTL based way like Assets, // because they are expensive to compute and cheap to keep around. class ImageMetadataDatabase { public: Vec2U imageSize(AssetPath const& path) const; List imageSpaces(AssetPath const& path, Vec2F position, float fillLimit, bool flip) const; RectU nonEmptyRegion(AssetPath const& path) const; private: // Removes image processing directives that don't affect image spaces / // non-empty regions. static AssetPath filterProcessing(AssetPath const& path); Vec2U calculateImageSize(AssetPath const& path) const; // Path, position, fillLimit, and flip typedef tuple SpacesEntry; mutable Mutex m_mutex; mutable HashMap m_sizeCache; mutable HashMap> m_spacesCache; mutable HashMap m_regionCache; }; }