summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--harris.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/harris.c b/harris.c
index 502e976..1099f61 100644
--- a/harris.c
+++ b/harris.c
@@ -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;