From 465aa7a7c58d58904196b4c436bdd69b8eea881e Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Wed, 17 Aug 2005 15:38:43 +0000 Subject: [PATCH] fixed initialization of row array. 2005-08-17 Sven Neumann * app/paint-funcs/paint-funcs.c (smooth_region): fixed initialization of row array. * app/base/siox.c: minor cleanups. --- ChangeLog | 7 ++ app/base/siox.c | 120 ++++++++++++++++------------------ app/paint-funcs/paint-funcs.c | 2 +- 3 files changed, 63 insertions(+), 66 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9fbcfef6f2..f65bdbc174 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-08-17 Sven Neumann + + * app/paint-funcs/paint-funcs.c (smooth_region): fixed + initialization of row array. + + * app/base/siox.c: minor cleanups. + 2005-08-17 Tor Lillqvist * plug-ins/winsnap/Makefile.am (LDADD): Use $(WINDRES) to handle diff --git a/app/base/siox.c b/app/base/siox.c index c5197d8755..7c4c9d87b0 100644 --- a/app/base/siox.c +++ b/app/base/siox.c @@ -638,21 +638,21 @@ set_mask (TileManager *mask, * are passed from above. */ static void -process_neighbours (gint pos_x, +process_neighbours (GQueue *q, + gint pos_x, gint pos_y, + TileManager *mask, + guchar maskval, gint x, gint y, gint width, - gint height, - GQueue *q, - TileManager *mask, - guchar maskval) + gint height) { guchar val; - if (pos_x + 1 < width) + if (pos_x + 1 < x + width) { - read_pixel_data_1 (mask, x + pos_x + 1, y + pos_y, &val); + read_pixel_data_1 (mask, pos_x + 1, pos_y, &val); if (!(val & maskval)) { @@ -661,9 +661,9 @@ process_neighbours (gint pos_x, } } - if (pos_x > 0) + if (pos_x > x) { - read_pixel_data_1 (mask, x + pos_x - 1, y + pos_y, &val); + read_pixel_data_1 (mask, pos_x - 1, pos_y, &val); if (!(val & maskval)) { @@ -672,9 +672,9 @@ process_neighbours (gint pos_x, } } - if (pos_y + 1 < height) + if (pos_y + 1 < y + height) { - read_pixel_data_1 (mask, x + pos_x, y + pos_y + 1, &val); + read_pixel_data_1 (mask, pos_x, pos_y + 1, &val); if (!(val & maskval)) { @@ -683,13 +683,13 @@ process_neighbours (gint pos_x, } } - if (pos_y > 0) + if (pos_y > y) { - read_pixel_data_1 (mask, x + pos_x , y + pos_y - 1, &val); + read_pixel_data_1 (mask, pos_x , pos_y - 1, &val); if (!(val & maskval)) { - g_queue_push_tail (q, GINT_TO_POINTER (pos_x )); + g_queue_push_tail (q, GINT_TO_POINTER (pos_x)); g_queue_push_tail (q, GINT_TO_POINTER (pos_y - 1)); } } @@ -699,14 +699,14 @@ process_neighbours (gint pos_x, /* This method processes every position in the queue, it finishes when * the queeue is empty and no further pixels kann be visited. */ -static int +static gint process_queue (GQueue *q, + TileManager *mask, + guchar maskval, gint x, gint y, gint width, - gint height, - TileManager *mask, - guchar maskval) + gint height) { gint regioncount = 0; @@ -716,22 +716,21 @@ process_queue (GQueue *q, gint pos_y = GPOINTER_TO_INT (g_queue_pop_head (q)); guchar val; - read_pixel_data_1 (mask, x + pos_x, y + pos_y, &val); + read_pixel_data_1 (mask, pos_x, pos_y, &val); if (val & maskval) continue; - val |= maskval; - /* pixel is set in original selection */ if (val & 0x1) { - write_pixel_data_1 (mask, x + pos_x, y + pos_y, &val); + val |= maskval; + write_pixel_data_1 (mask, pos_x, pos_y, &val); regioncount++; - process_neighbours (pos_x, pos_y, - x, y, width, height, q, mask, maskval); + process_neighbours (q, pos_x, pos_y, + mask, maskval, x, y, width, height); } } @@ -744,11 +743,11 @@ process_queue (GQueue *q, * should be considererd set in incoming mask, must fullfil (pixel & * 0x1) the method uses no further memory, except a queue, it finds * the biggest component by a 2 phase algorithm 1. in the first phase - * the koordinates of an element of the biggest component are - * identified, during set phase all pixels are visited 2. in the - * second phase first visitation flags are reseted, and afterwards a + * the coordinates of an element of the biggest component are + * identified, during this phase all pixels are visited. In the + * second phase first visitation flags are reset, and afterwards a * connected component starting at the found coordinates is - * determined, this is the biggest component, the result is written + * determined. This is the biggest component, the result is written * into mask, all pixels that belong to the biggest component, are set * to 255 any other to 0. */ @@ -763,11 +762,9 @@ find_max_blob (TileManager *mask, PixelRegion region; gpointer pr; gint row, col; - gint maxblobx = 0; - gint maxbloby = 0; + gint maxblob_x = 0; + gint maxblob_y = 0; gint maxregion = 0; - gint pos_x; - gint pos_y; guchar val; /* this mask is used to check if a pixel has been visited */ @@ -777,66 +774,61 @@ find_max_blob (TileManager *mask, threshold_mask (mask, 0x80, 0x1, x, y, width, height); + /* mark every pixel in the mask as unvisited */ + set_mask (mask, unvisited, x, y, width, height); + q = g_queue_new (); pixel_region_init (®ion, mask, x, y, width, height, TRUE); - /* mark every pixel in the mask as unvisited */ - set_mask (mask, unvisited, x, y, width, height); - for (pr = pixel_regions_register (1, ®ion); pr != NULL; pr = pixel_regions_process (pr)) { const guchar *data = region.data; - gint index = (region.x - x) + (region.y - y) * width; + gint pos_y = region.y; - for (row = 0; row < region.h; row++) + for (row = 0; row < region.h; row++, pos_y++) { - const guchar *d = data; - gint i = index; + gint pos_x = region.x; + const guchar *d = data; - for (col = 0; col < region.w; col++, d++, i++) + for (col = 0; col < region.w; col++, d++, pos_x++) { gint regioncount; - pos_x = i % width; - pos_y = i / width; - - read_pixel_data_1 (mask, x + pos_x, y + pos_y, &val); + read_pixel_data_1 (mask, pos_x, pos_y, &val); if (val & visited) continue; /* mark current pixel as visited */ val |= visited; - write_pixel_data_1 (mask, x + pos_x, y + pos_y, &val); + write_pixel_data_1 (mask, pos_x, pos_y, &val); - /* if this pixel is not marked as selection in original, - * image skip it + /* if this pixel is not marked as selection in original image, + * skip it */ if (!(val & 0x1)) continue; - /* check out neighbourhood*/ - process_neighbours (pos_x, pos_y, - x, y, width, height, q, mask, visited); + /* check out neighbourhood */ + process_neighbours (q, pos_x, pos_y, + mask, visited, x, y, width, height); - regioncount = 1 + process_queue (q, - x, y, width, height, mask, - visited); + regioncount = 1 + process_queue (q, mask, visited, + x, y, width, height); - /* remember bigest regions size and coords of an element*/ + /* remember bigest regions size and coords of an element */ if (regioncount > maxregion) { maxregion = regioncount; - maxblobx = pos_x; - maxbloby = pos_y; + maxblob_x = pos_x; + maxblob_y = pos_y; } } data += region.rowstride; - index += width; } } @@ -847,16 +839,14 @@ find_max_blob (TileManager *mask, * that it can be set as resulting mask */ - /* mark startpixel als visited */ - read_pixel_data_1 (mask, x + maxblobx, y + maxbloby, &val); - - /* mark as visited */ + /* mark startpixel as visited */ + read_pixel_data_1 (mask, maxblob_x, maxblob_y, &val); val |= visited; - write_pixel_data_1 (mask, x + maxblobx, y + maxbloby, &val); + write_pixel_data_1 (mask, maxblob_x, maxblob_y, &val); - process_neighbours (maxblobx, maxbloby, - x, y, width, height, q, mask, visited); - maxregion = process_queue (q, x, y, width, height, mask, visited); + process_neighbours (q, maxblob_x, maxblob_y, + mask, visited, x, y, width, height); + maxregion = process_queue (q, mask, visited, x, y, width, height); g_queue_free (q); diff --git a/app/paint-funcs/paint-funcs.c b/app/paint-funcs/paint-funcs.c index 932668d2b4..cf28890df1 100644 --- a/app/paint-funcs/paint-funcs.c +++ b/app/paint-funcs/paint-funcs.c @@ -3335,7 +3335,7 @@ smooth_region (PixelRegion *region) buf[0][0] = buf[0][1]; buf[0][width + 1] = buf[0][width]; - memcpy (buf[1], buf[2], width + 2); + memcpy (buf[1], buf[0], width + 2); for (y = 0; y < region->h; y++) {