summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8994934)
raw | patch | inline | side by side (parent: 8994934)
author | johncoswell <johncoswell@users.sourceforge.net> | |
Tue, 27 Feb 2007 23:28:03 +0000 (23:28 +0000) | ||
committer | johncoswell <johncoswell@users.sourceforge.net> | |
Tue, 27 Feb 2007 23:28:03 +0000 (23:28 +0000) |
src/flood-context.cpp | patch | blob | history | |
src/widgets/toolbox.cpp | patch | blob | history |
diff --git a/src/flood-context.cpp b/src/flood-context.cpp
index fa547a6b901c3f1e18508d5604d210b20b8a0cf5..e737b90f92adf825299dc55a41a3a7aaad984590 100644 (file)
--- a/src/flood-context.cpp
+++ b/src/flood-context.cpp
return px + (x + y * width) * 4;
}
-static bool compare_pixels(unsigned char *a, unsigned char *b, int fuzziness) {
+static bool compare_pixels(unsigned char *a, unsigned char *b, int tolerance) {
for (int i = 0; i < 4; i++) {
- if (a[i] != b[i]) {
+ if (abs(a[i] - b[i]) > tolerance) {
return false;
}
}
return true;
}
-static void try_add_to_queue(std::queue<NR::Point> *fill_queue, guchar *px, unsigned char *orig, int x, int y, int width) {
+static void try_add_to_queue(std::queue<NR::Point> *fill_queue, guchar *px, unsigned char *orig, int x, int y, int width, int tolerance) {
unsigned char *t = get_pixel(px, x, y, width);
- if (compare_pixels(t, orig, 0)) {
+ if (compare_pixels(t, orig, tolerance)) {
fill_queue->push(NR::Point(x, y));
}
}
@@ -413,7 +413,6 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even
nr_arena_item_unref(root);
nr_object_unref((NRObject *) arena);
-
NR::Point pw = NR::Point(event->button.x / zoom_scale, sp_document_height(document) + (event->button.y / zoom_scale)) * affine;
pw[NR::X] = (int)MIN(width - 1, MAX(0, pw[NR::X]));
@@ -432,25 +431,27 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even
unsigned char *orig_px = get_pixel(px, (int)pw[NR::X], (int)pw[NR::Y], width);
for (int i = 0; i < 4; i++) { orig_color[i] = orig_px[i]; }
+ int tolerance = prefs_get_int_attribute_limited("tools.paintbucket", "tolerance", 1, 0, 255);
+
while (!fill_queue.empty() && !aborted) {
NR::Point cp = fill_queue.front();
fill_queue.pop();
unsigned char *s = get_pixel(px, (int)cp[NR::X], (int)cp[NR::Y], width);
// same color at this point
- if (compare_pixels(s, orig_color, 0)) {
+ if (compare_pixels(s, orig_color, tolerance)) {
int left = (int)cp[NR::X];
int right = (int)cp[NR::X] + 1;
int x = (int)cp[NR::X];
int y = (int)cp[NR::Y];
if (y > 0) {
- try_add_to_queue(&fill_queue, px, orig_color, x, y - 1, width);
+ try_add_to_queue(&fill_queue, px, orig_color, x, y - 1, width, tolerance);
} else {
aborted = true; break;
}
if (y < y_limit) {
- try_add_to_queue(&fill_queue, px, orig_color, x, y + 1, width);
+ try_add_to_queue(&fill_queue, px, orig_color, x, y + 1, width, tolerance);
} else {
aborted = true; break;
}
@@ -463,12 +464,12 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even
// go left
if (left >= 0) {
t = get_pixel(px, left, y, width);
- if (compare_pixels(t, orig_color, 0)) {
+ if (compare_pixels(t, orig_color, tolerance)) {
for (int i = 0; i < 4; i++) { t[i] = 255 - t[i]; }
trace_t = get_pixel(trace_px, left, y, width);
trace_t[3] = 255;
- if (y > 0) { try_add_to_queue(&fill_queue, px, orig_color, left, y - 1, width); }
- if (y < y_limit) { try_add_to_queue(&fill_queue, px, orig_color, left, y + 1, width); }
+ if (y > 0) { try_add_to_queue(&fill_queue, px, orig_color, left, y - 1, width, tolerance); }
+ if (y < y_limit) { try_add_to_queue(&fill_queue, px, orig_color, left, y + 1, width, tolerance); }
left--; ok = true;
}
} else {
@@ -478,15 +479,15 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even
do {
ok = false;
- // go left
+ // go right
if (right < width) {
t = get_pixel(px, right, y, width);
- if (compare_pixels(t, orig_color, 0)) {
+ if (compare_pixels(t, orig_color, tolerance)) {
for (int i = 0; i < 4; i++) { t[i] = 255 - t[i]; }
trace_t = get_pixel(trace_px, right, y, width);
trace_t[3] = 255;
- if (y > 0) { try_add_to_queue(&fill_queue, px, orig_color, right, y - 1, width); }
- if (y < y_limit) { try_add_to_queue(&fill_queue, px, orig_color, right, y + 1, width); }
+ if (y > 0) { try_add_to_queue(&fill_queue, px, orig_color, right, y - 1, width, tolerance); }
+ if (y < y_limit) { try_add_to_queue(&fill_queue, px, orig_color, right, y + 1, width, tolerance); }
right++; ok = true;
}
} else {
index 43ebb6b5d7acab1f23a82d26b877b6462ac547f5..788176d9ca43278353a44438e0dc18e18373920f 100644 (file)
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
} // end of sp_connector_toolbox_new()
+static void paintbucket_tolerance_changed(GtkAdjustment *adj, GtkWidget *tbl)
+{
+ prefs_set_int_attribute("tools.paintbucket", "tolerance", (gint)adj->value);
+ spinbutton_defocus(GTK_OBJECT(tbl));
+}
+
static GtkWidget *
sp_paintbucket_toolbox_new(SPDesktop *desktop)
{
GtkWidget *tbl = gtk_hbox_new(FALSE, 0);
+ // Spacing spinbox
+ {
+ GtkWidget *tolerance = sp_tb_spinbutton(_("Tolerance:"),
+ _("The maximum allowed difference between the clicked pixel and the neighboring pixels to be counted in the fill"),
+ "tools.paintbucket", "tolerance", 8, NULL, tbl, TRUE,
+ "inkscape:paintbucket-tolerance", 0, 255, 1.0, 10.0,
+ paintbucket_tolerance_changed, 1, 0);
+
+ gtk_box_pack_start(GTK_BOX(tbl), tolerance, FALSE, FALSE,
+ AUX_SPACING);
+ }
+
Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL, _("Style of Paint Bucket fill objects"));
swatch->setDesktop (desktop);
swatch->setClickVerb (SP_VERB_CONTEXT_PAINTBUCKET_PREFS);