+
+void ObjectRenderer::FloodFillOnCPU(int64_t x, int64_t y, const PixelBounds & bounds, const CPURenderTarget & target, const Colour & fill, const Colour & stroke)
+{
+ // HACK to prevent overflooding (when the fill points for a path round to the pixel outside the boundary)
+ // (I totally just made that term up...)
+ Colour c = GetColour(target, x+1, y);
+ if (c == fill || c == stroke)
+ return;
+ c = GetColour(target, x-1, y);
+ if (c == fill || c == stroke)
+ return;
+ c = GetColour(target, x, y+1);
+ if (c == fill || c == stroke)
+ return;
+ c = GetColour(target, x, y-1);
+ if (c == fill || c == stroke)
+ return;
+
+ // The hack works but now we get underflooding, or, "droughts".
+
+
+ queue<PixelPoint > traverse;
+ traverse.push(PixelPoint(x,y));
+ // now with 100% less stack overflows!
+ while (traverse.size() > 0)
+ {
+ PixelPoint cur(traverse.front());
+ traverse.pop();
+ if (cur.first < 0 || cur.first < bounds.x || cur.first >= bounds.x+bounds.w || cur.first >= target.w ||
+ cur.second < 0 || cur.second < bounds.y || cur.second >= bounds.y+bounds.h || cur.second >= target.h)
+ continue;
+ c = GetColour(target, cur.first, cur.second);
+ if (c == fill || c == stroke)
+ continue;
+
+ SetColour(target, cur.first, cur.second, fill);
+
+ //Debug("c is {%u,%u,%u,%u} fill is {%u,%u,%u,%u}, stroke is {%u,%u,%u,%u}",
+ // c.r,c.g,c.b,c.a, fill.r,fill.g,fill.b,fill.a, stroke.r,stroke.g,stroke.b,stroke.a);
+
+ traverse.push(PixelPoint(cur.first+1, cur.second));
+ traverse.push(PixelPoint(cur.first-1, cur.second));
+ traverse.push(PixelPoint(cur.first, cur.second-1));
+ traverse.push(PixelPoint(cur.first, cur.second+1));
+ }
+}
+