@@ -287,94 +287,4 @@ template usize FloodFill::processRowSIMD<f32>(f32*, i32, i32, f32, f32);
287287template usize FloodFill::processRowSIMD<u8 >(u8 *, i32 , i32 , u8 , u8 );
288288#endif
289289
290- <<<<<<< HEAD
291290} // namespace atom::algorithm
292- =======
293- // Implementation of block processing template function
294- template <Grid GridType>
295- usize FloodFill::processBlock (
296- GridType& grid, i32 blockX, i32 blockY, i32 blockSize,
297- typename GridType::value_type::value_type target_color,
298- typename GridType::value_type::value_type fill_color, Connectivity conn,
299- std::queue<std::pair<i32 , i32 >>& borderQueue) {
300- usize filled_count = 0 ;
301- i32 rows = static_cast <i32 >(grid.size ());
302- i32 cols = static_cast <i32 >(grid[0 ].size ());
303-
304- // Calculate block boundaries
305- i32 endX = std::min (blockX + blockSize, rows);
306- i32 endY = std::min (blockY + blockSize, cols);
307-
308- // Use BFS to process the block
309- std::queue<std::pair<i32 , i32 >> localQueue;
310- std::vector<std::vector<bool >> localVisited (
311- static_cast <usize>(blockSize),
312- std::vector<bool >(static_cast <usize>(blockSize), false ));
313-
314- // Find any already filled pixel in the block to use as starting point
315- bool found_start = false ;
316- for (i32 x = blockX; x < endX && !found_start; ++x) {
317- for (i32 y = blockY; y < endY && !found_start; ++y) {
318- if (grid[static_cast <usize>(x)][static_cast <usize>(y)] ==
319- fill_color) {
320- // Check neighbors for target color pixels
321- auto directions = getDirections (conn);
322- for (auto [dx, dy] : directions) {
323- i32 nx = x + dx;
324- i32 ny = y + dy;
325-
326- if (isInBounds (nx, ny, rows, cols) &&
327- grid[static_cast <usize>(nx)][static_cast <usize>(ny)] ==
328- target_color &&
329- nx >= blockX && nx < endX && ny >= blockY &&
330- ny < endY) {
331- localQueue.emplace (nx, ny);
332- localVisited[static_cast <usize>(nx - blockX)]
333- [static_cast <usize>(ny - blockY)] = true ;
334- grid[static_cast <usize>(nx)][static_cast <usize>(ny)] =
335- fill_color;
336- filled_count++;
337- found_start = true ;
338- }
339- }
340- }
341- }
342- }
343-
344- // Perform BFS within the block
345- auto directions = getDirections (conn);
346- while (!localQueue.empty ()) {
347- auto [x, y] = localQueue.front ();
348- localQueue.pop ();
349-
350- for (auto [dx, dy] : directions) {
351- i32 nx = x + dx;
352- i32 ny = y + dy;
353-
354- if (isInBounds (nx, ny, rows, cols) &&
355- grid[static_cast <usize>(nx)][static_cast <usize>(ny)] ==
356- target_color) {
357- // Check if the pixel is within the current block
358- if (nx >= blockX && nx < endX && ny >= blockY && ny < endY) {
359- if (!localVisited[static_cast <usize>(nx - blockX)]
360- [static_cast <usize>(ny - blockY)]) {
361- grid[static_cast <usize>(nx)][static_cast <usize>(ny)] =
362- fill_color;
363- localQueue.emplace (nx, ny);
364- localVisited[static_cast <usize>(nx - blockX)]
365- [static_cast <usize>(ny - blockY)] = true ;
366- filled_count++;
367- }
368- } else {
369- // Pixel is outside the block, add to border queue
370- borderQueue.emplace (x, y);
371- }
372- }
373- }
374- }
375-
376- return filled_count;
377- }
378-
379- } // namespace atom::algorithm
380- >>>>>>> 7ca9448dadcbc6c2bb1a7286a72a7abccac61dea
0 commit comments