diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-03-14 20:14:42 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-03-14 20:14:42 +0100 |
commit | 512daa03c2e79352c2a40e6eb61b9604d7eb1f7a (patch) | |
tree | 955991989b4ad7baa130fcf4151835d48cf35a39 | |
parent | fac005a978b5ff84960c589e3f36ba7a0ba7abae (diff) | |
download | cv-512daa03c2e79352c2a40e6eb61b9604d7eb1f7a.tar.gz cv-512daa03c2e79352c2a40e6eb61b9604d7eb1f7a.tar.bz2 cv-512daa03c2e79352c2a40e6eb61b9604d7eb1f7a.zip |
wimmel: Dont use get_pixel for permormance reasons
-rw-r--r-- | wimmel.c | 41 |
1 files changed, 18 insertions, 23 deletions
@@ -23,39 +23,34 @@ find_image_in_wimmel(GdkPixbuf *wimmel, GdkPixbuf *match, GdkPixbuf *output) barrier = width * height / 2; - for (j = 0; j < wimmel_height - height; ++j) { - for (i = 0; i < wimmel_width - width; ++i) { + int stride = gdk_pixbuf_get_rowstride(wimmel); + int nch = gdk_pixbuf_get_n_channels(wimmel); + guchar *row = gdk_pixbuf_get_pixels(wimmel); + guchar *pix, *pix_m; + + int stride_m = gdk_pixbuf_get_rowstride(match); + + for (j = 0; j < wimmel_height - height; ++j, row += stride) { + for (i = 0, pix = row; i < wimmel_width - width; ++i, pix += nch) { difference = 0; - for (n = 0; n < height; ++n) { - for (k = 0; k < width; ++k) { - color_t color = get_pixel(wimmel, POINT(i + k, j + n)); - color_t color_orig = get_pixel(match, POINT(k, n)); - -#if 1 - if (abs(color.r - color_orig.r) > 50 || - abs(color.g - color_orig.g) > 50 || - abs(color.b - color_orig.b) > 50) { + guchar *row_m = gdk_pixbuf_get_pixels(match); + for (n = 0; n < height; ++n, row_m += stride_m) { + for (k = 0, pix_m = row_m; k < width; ++k, pix_m += nch) { + + pix = row + n * stride + (i + k) * nch; + + if (abs((int)pix[0] - (int)pix_m[0]) > 50 || + abs((int)pix[1] - (int)pix_m[1]) > 50 || + abs((int)pix[2] - (int)pix_m[2]) > 50) { difference++; if (difference > barrier) break; } -#else - difference += - abs(color.r - color_orig.r) + - abs(color.g - color_orig.g) + - abs(color.b - color_orig.b); - if (difference > barrier * 300) - break; -#endif } } -#if 0 - if (difference < barrier * 300) { -#else if (difference < barrier) { -#endif g_print("kleeblatt @ %d, %d; difference: %d\n", i, j, difference); color_t color = COLOR(255, 0, 0, 0); for (k = i; k < i+width; k++) { |