|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | #include "Common/Cpp/PrettyPrint.h" |
| 8 | +#include "Common/Cpp/Concurrency/SpinLock.h" |
8 | 9 | #include "Kernels/Waterfill/Kernels_Waterfill_Session.h" |
| 10 | +#include "CommonFramework/Tools/GlobalThreadPools.h" |
9 | 11 | #include "CommonTools/Images/BinaryImage_FilterRgb32.h" |
10 | 12 | #include "PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_SparkleDetectorRadial.h" |
11 | 13 | #include "PokemonBDSP_ShinySparkleSet.h" |
@@ -116,19 +118,25 @@ void ShinySparkleSetBDSP::read_from_image(size_t screen_area, const ImageViewRGB |
116 | 118 | {0xff909000, 0xffffffff}, |
117 | 119 | } |
118 | 120 | ); |
119 | | - auto session = make_WaterfillSession(); |
120 | 121 |
|
| 122 | + SpinLock lock; |
121 | 123 | double best_alpha = 0; |
122 | | - for (PackedBinaryMatrix& matrix : matrices){ |
123 | | - session->set_source(matrix); |
124 | | - ShinySparkleSetBDSP sparkles = find_sparkles(screen_area, *session); |
125 | | - sparkles.update_alphas(); |
126 | | - double alpha = sparkles.alpha_overall(); |
127 | | - if (best_alpha < alpha){ |
128 | | - best_alpha = alpha; |
129 | | - *this = std::move(sparkles); |
130 | | - } |
131 | | - } |
| 124 | + GlobalThreadPools::realtime_inference().run_in_parallel( |
| 125 | + [&](size_t index){ |
| 126 | + auto session = make_WaterfillSession(); |
| 127 | + session->set_source(matrices[index]); |
| 128 | + ShinySparkleSetBDSP sparkles = find_sparkles(screen_area, *session); |
| 129 | + sparkles.update_alphas(); |
| 130 | + double alpha = sparkles.alpha_overall(); |
| 131 | + |
| 132 | + WriteSpinLock lg(lock); |
| 133 | + if (best_alpha < alpha){ |
| 134 | + best_alpha = alpha; |
| 135 | + *this = std::move(sparkles); |
| 136 | + } |
| 137 | + }, |
| 138 | + 0, matrices.size(), 1 |
| 139 | + ); |
132 | 140 | } |
133 | 141 |
|
134 | 142 |
|
|
0 commit comments