diff options
-rw-r--r-- | harris.c | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -50,8 +50,8 @@ grey_scale(GdkPixbuf *image) int * conv(GdkPixbuf *pixbuf, gint *operator, gint block_size) { - gint Y, i, j, x, y, width, height, nch, stride; - guchar *p, *row, *v; + gint Y, i, j, ci, cj, x, y, width, height, nch, stride; + guchar *p, *row, v; int *out; pixbuf_get(pixbuf, &row, &width, &height, &nch, &stride); @@ -62,12 +62,13 @@ conv(GdkPixbuf *pixbuf, gint *operator, gint block_size) for (y = 0; y < height; ++y, row += stride) { for (x = 0, p = row; x < width; ++x, p += nch) { Y = 0; - for (i = 0; i < block_size; ++i) { - for (j = 0; j < block_size; ++j) { - /* TODO: fix clamping */ - v = p + (CLAMP((j-block_size/2), 0, width-1) * stride + - CLAMP((i-block_size/2), 0, height-1) * nch); - Y += v[0] * operator[j*block_size + i]; + for (j = 0; j < block_size; ++j) { + cj = CLAMP(j - block_size/2, -y, height-1-y); + for (i = 0; i < block_size; ++i) { + ci = CLAMP(i - block_size/2, -x, width-1-x); + + v = p[cj * stride + ci * nch + 0]; + Y += v * operator[j*block_size + i]; } } out[y * width + x] = Y/4; |