MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / flooder

Function flooder

src/doc/algorithm/floodfill.cpp:133–272  ·  view source on GitHub ↗

flooder: * Fills a horizontal line around the specified position, and adds it * to the list of drawn segments. Returns the first x coordinate after * the part of the line which it has dealt with. */

Source from the content-addressed store, hash-verified

131 * the part of the line which it has dealt with.
132 */
133static int flooder(const Image* image,
134 const Mask* mask,
135 int x, int y,
136 const gfx::Rect& bounds,
137 color_t src_color, int tolerance, void *data, AlgoHLine proc)
138{
139#define MASKED(u, v) \
140 (mask && \
141 (!mask->bounds().contains(u, v) || \
142 (mask->bitmap() && \
143 !get_pixel_fast<BitmapTraits>(mask->bitmap(), \
144 (u)-mask->bounds().x, \
145 (v)-mask->bounds().y))))
146
147 FLOODED_LINE *p;
148 int left = 0, right = 0;
149 int c;
150
151 switch (image->pixelFormat()) {
152
153 case IMAGE_RGB:
154 {
155 uint32_t* address = reinterpret_cast<uint32_t*>(image->getPixelAddress(0, y));
156
157 // Check start pixel
158 if (!color_equal_32((int)*(address+x), src_color, tolerance) || MASKED(x, y))
159 return x+1;
160
161 // Work left from starting point
162 for (left=x-1; left>=bounds.x; left--) {
163 if (!color_equal_32((int)*(address+left), src_color, tolerance) || MASKED(left, y))
164 break;
165 }
166
167 // Work right from starting point
168 for (right=x+1; right<bounds.x2(); right++) {
169 if (!color_equal_32((int)*(address+right), src_color, tolerance) || MASKED(right, y))
170 break;
171 }
172 }
173 break;
174
175 case IMAGE_GRAYSCALE:
176 {
177 uint16_t* address = reinterpret_cast<uint16_t*>(image->getPixelAddress(0, y));
178
179 // Check start pixel
180 if (!color_equal_16((int)*(address+x), src_color, tolerance) || MASKED(x, y))
181 return x+1;
182
183 // Work left from starting point
184 for (left=x-1; left>=bounds.x; left--) {
185 if (!color_equal_16((int)*(address+left), src_color, tolerance) || MASKED(left, y))
186 break;
187 }
188
189 // Work right from starting point
190 for (right=x+1; right<bounds.x2(); right++) {

Callers 2

check_flood_lineFunction · 0.85
floodfillFunction · 0.85

Calls 9

color_equal_32Function · 0.85
color_equal_16Function · 0.85
color_equal_8Function · 0.85
get_pixelFunction · 0.85
getPixelAddressMethod · 0.80
x2Method · 0.80
y2Method · 0.80
pixelFormatMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected