summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3a5736c)
raw | patch | inline | side by side (parent: 3a5736c)
author | johncoswell <johncoswell@users.sourceforge.net> | |
Thu, 1 Mar 2007 03:58:45 +0000 (03:58 +0000) | ||
committer | johncoswell <johncoswell@users.sourceforge.net> | |
Thu, 1 Mar 2007 03:58:45 +0000 (03:58 +0000) |
src/flood-context.cpp | patch | blob | history |
diff --git a/src/flood-context.cpp b/src/flood-context.cpp
index 611c46646e8659ac7ccdb83e23bdb515259cb436..da8f22513c29f03f8b3c183924efcef9f3249017 100644 (file)
--- a/src/flood-context.cpp
+++ b/src/flood-context.cpp
}
static bool compare_pixels(unsigned char *a, unsigned char *b, int tolerance) {
+ int diff = 0;
for (int i = 0; i < 4; i++) {
- if (abs(a[i] - b[i]) > tolerance) {
- return false;
- }
+ diff += (int)abs(a[i] - b[i]);
}
- return true;
+ return ((diff / 4) <= tolerance);
}
-static bool try_add_to_queue(std::queue<NR::Point> *fill_queue, guchar *px, unsigned char *orig, int x, int y, int width, int tolerance, bool fill_switch) {
+static bool try_add_to_queue(std::queue<NR::Point> *fill_queue, guchar *px, guchar *trace_px, unsigned char *orig, int x, int y, int width, int tolerance, bool fill_switch) {
unsigned char *t = get_pixel(px, x, y, width);
if (compare_pixels(t, orig, tolerance)) {
- if (fill_switch) {
- fill_queue->push(NR::Point(x, y));
- return false;
+ unsigned char *trace_t = get_pixel(trace_px, x, y, width);
+ if (trace_t[3] != 255) {
+ if (fill_switch) {
+ fill_queue->push(NR::Point(x, y));
+ }
}
+ return false;
}
return true;
}
@@ -468,12 +470,12 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even
bool bottom_fill = true;
if (y > 0) {
- top_fill = try_add_to_queue(&fill_queue, px, orig_color, x, y - 1, width, tolerance, top_fill);
+ top_fill = try_add_to_queue(&fill_queue, px, trace_px, orig_color, x, y - 1, width, tolerance, top_fill);
} else {
aborted = true; break;
}
if (y < y_limit) {
- bottom_fill = try_add_to_queue(&fill_queue, px, orig_color, x, y + 1, width, tolerance, bottom_fill);
+ bottom_fill = try_add_to_queue(&fill_queue, px, trace_px, orig_color, x, y + 1, width, tolerance, bottom_fill);
} else {
aborted = true; break;
}
@@ -484,8 +486,6 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even
unsigned char *t, *trace_t;
bool ok = false;
- trace_t = get_pixel(trace_px, left, y, width);
-
do {
ok = false;
// go left
@@ -493,9 +493,10 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even
t = get_pixel(px, left, y, width);
if (compare_pixels(t, orig_color, tolerance)) {
for (int i = 0; i < 4; i++) { t[i] = 255 - t[i]; }
- trace_t[3] = 255; trace_t -= 4;
- if (y > 0) { top_fill = try_add_to_queue(&fill_queue, px, orig_color, left, y - 1, width, tolerance, top_fill); }
- if (y < y_limit) { bottom_fill = try_add_to_queue(&fill_queue, px, orig_color, left, y + 1, width, tolerance, bottom_fill); }
+ trace_t = get_pixel(trace_px, left, y, width);
+ trace_t[3] = 255;
+ if (y > 0) { top_fill = try_add_to_queue(&fill_queue, px, trace_px, orig_color, left, y - 1, width, tolerance, top_fill); }
+ if (y < y_limit) { bottom_fill = try_add_to_queue(&fill_queue, px, trace_px, orig_color, left, y + 1, width, tolerance, bottom_fill); }
left--; ok = true;
}
} else {
@@ -505,7 +506,6 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even
top_fill = default_top_fill;
bottom_fill = default_bottom_fill;
- trace_t = get_pixel(trace_px, right, y, width);
do {
ok = false;
@@ -514,9 +514,10 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even
t = get_pixel(px, right, y, width);
if (compare_pixels(t, orig_color, tolerance)) {
for (int i = 0; i < 4; i++) { t[i] = 255 - t[i]; }
- trace_t[3] = 255; trace_t += 4;
- if (y > 0) { top_fill = try_add_to_queue(&fill_queue, px, orig_color, right, y - 1, width, tolerance, top_fill); }
- if (y < y_limit) { bottom_fill = try_add_to_queue(&fill_queue, px, orig_color, right, y + 1, width, tolerance, bottom_fill); }
+ trace_t = get_pixel(trace_px, right, y, width);
+ trace_t[3] = 255;
+ if (y > 0) { top_fill = try_add_to_queue(&fill_queue, px, trace_px, orig_color, right, y - 1, width, tolerance, top_fill); }
+ if (y < y_limit) { bottom_fill = try_add_to_queue(&fill_queue, px, trace_px, orig_color, right, y + 1, width, tolerance, bottom_fill); }
right++; ok = true;
}
} else {