summaryrefslogtreecommitdiff
path: root/wimmel.c
diff options
context:
space:
mode:
Diffstat (limited to 'wimmel.c')
-rw-r--r--wimmel.c54
1 files changed, 25 insertions, 29 deletions
diff --git a/wimmel.c b/wimmel.c
index 712dacb..0a35ec2 100644
--- a/wimmel.c
+++ b/wimmel.c
@@ -4,6 +4,10 @@
#include "util.h"
+#ifndef N_THREADS
+#define N_THREADS 4
+#endif
+
static void
find_image_in_wimmel(GdkPixbuf *wimmel, GdkPixbuf *match, GdkPixbuf *output)
{
@@ -93,11 +97,9 @@ main(int argc, char *argv[])
char *file;
GdkPixbuf *wimmel, *output;
GdkPixbuf *match_tmp, *match;
- int i, j;
+ int i;
int x1, y1, mwidth, mheight, width, height;
-#define N 4
-#define K 4
- GThread *thread[N][K];
+ GThread *thread[N_THREADS];
g_type_init();
@@ -123,33 +125,27 @@ main(int argc, char *argv[])
width = gdk_pixbuf_get_width(wimmel);
height = gdk_pixbuf_get_height(wimmel);
- int step_x = width / N, step_y = height / K;
- int x, y;
- for (i = 0, x = 0; i < N; ++i, x += step_x) {
- for (j = 0, y = 0; j < K; ++j, y += step_y) {
- struct find_params *params = malloc(sizeof (struct find_params));;
- if (!params)
- exit(EXIT_FAILURE);
-
- int w = step_x + mwidth;
- int h = step_y + mheight;
-
- if (x + w > width)
- w = width - x;
- if (y + h > height)
- h = height - y;
-
- params->wimmel = gdk_pixbuf_new_subpixbuf(wimmel, x, y, w, h);
- params->output = gdk_pixbuf_new_subpixbuf(output, x, y, w, h);
- params->match = g_object_ref(match);
-
- thread[i][j] = g_thread_create(find_thread, params, TRUE, NULL);
- }
+ int step_y = height / N_THREADS;
+ int y;
+ for (i = 0, y = 0; i < N_THREADS; ++i, y += step_y) {
+ struct find_params *params = malloc(sizeof (struct find_params));;
+ if (!params)
+ exit(EXIT_FAILURE);
+
+ int h = step_y + mheight;
+
+ if (y + h > height)
+ h = height - y;
+
+ params->wimmel = gdk_pixbuf_new_subpixbuf(wimmel, 0, y, width, h);
+ params->output = gdk_pixbuf_new_subpixbuf(output, 0, y, width, h);
+ params->match = g_object_ref(match);
+
+ thread[i] = g_thread_create(find_thread, params, TRUE, NULL);
}
- for (i = 0; i < N; ++i)
- for (j = 0; j < K; ++j)
- g_thread_join(thread[i][j]);
+ for (i = 0; i < N_THREADS; ++i)
+ g_thread_join(thread[i]);
gdk_pixbuf_save(output, "output.png", "png", NULL, NULL);
g_object_unref(wimmel);