MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / nonEmptyRegion

Method nonEmptyRegion

source/game/StarImageMetadataDatabase.cpp:99–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99RectU ImageMetadataDatabase::nonEmptyRegion(AssetPath const& path) const {
100 MutexLocker locker(m_mutex);
101
102 if (auto cached = m_regionCache.ptr(path)) {
103 return *cached;
104 }
105
106 auto filteredPath = filterProcessing(path);
107 if (auto cached = m_regionCache.ptr(filteredPath)) {
108 m_regionCache.set(path, *cached);
109 return *cached;
110 }
111
112 locker.unlock();
113 auto image = Root::singleton().assets()->image(filteredPath);
114 RectU region = RectU::null();
115 image->forEachPixel([&region](unsigned x, unsigned y, Vec4B const& pixel) {
116 if (pixel[3] > 0)
117 region.combine(RectU::withSize({x, y}, {1, 1}));
118 });
119
120 locker.lock();
121 m_regionCache.set(path, region);
122 m_regionCache.set(filteredPath, region);
123
124 return region;
125}
126
127void ImageMetadataDatabase::cleanup() const {
128 MutexLocker locker(m_mutex);

Callers 1

boundBoxMethod · 0.45

Calls 9

singletonClass · 0.85
assetsMethod · 0.80
forEachPixelMethod · 0.80
ptrMethod · 0.45
setMethod · 0.45
unlockMethod · 0.45
imageMethod · 0.45
combineMethod · 0.45
lockMethod · 0.45

Tested by

no test coverage detected