| 97 | } |
| 98 | |
| 99 | RectU 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([®ion](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 | |
| 127 | void ImageMetadataDatabase::cleanup() const { |
| 128 | MutexLocker locker(m_mutex); |