summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2013-02-01 13:23:34 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2013-02-01 15:06:59 +0100
commit04f2f3d766d6ceb2b5f4120be28cab04816e048b (patch)
tree12117cd7df8aaa860963702b3da520be908d4f01 /src
parentc050f52cba0b72fb5759e88b41db8bd700cd9bc3 (diff)
downloadadvtime-04f2f3d766d6ceb2b5f4120be28cab04816e048b.tar.gz
advtime-04f2f3d766d6ceb2b5f4120be28cab04816e048b.tar.bz2
advtime-04f2f3d766d6ceb2b5f4120be28cab04816e048b.zip
util: Add sobel operator
Diffstat (limited to 'src')
-rw-r--r--src/util.c42
-rw-r--r--src/util.h3
2 files changed, 45 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index ddd46d3..ddb3ce9 100644
--- a/src/util.c
+++ b/src/util.c
@@ -136,3 +136,45 @@ print_time(int64_t msec) {
printf("%02d:%02d:%02d.%03jd", hh, mm, ss, msec);
}
+
+int
+sobel(struct video_frame *frame, unsigned char **d)
+{
+ unsigned char *data;
+ unsigned char *p = frame->data;
+ int x,y;
+ int Yx, Yy, Y;
+
+ data = malloc(frame->width * frame->height);
+ if (data == NULL)
+ return -1;
+
+ for (y = 1; y < frame->height-1; ++y) {
+ for (x = 1; x < frame->width-1; ++x) {
+ Yx = (+1 * p[(y-1) * frame->stride + (x-1)]
+ -1 * p[(y-1) * frame->stride + (x+1)]
+ +2 * p[(y ) * frame->stride + (x-1)]
+ -2 * p[(y ) * frame->stride + (x+1)]
+ +1 * p[(y+1) * frame->stride + (x-1)]
+ -1 * p[(y+1) * frame->stride + (x+1)]);
+ Yx = abs(Yx);
+
+ Yy = (+1 * p[(y-1) * frame->stride + (x-1)]
+ +2 * p[(y-1) * frame->stride + (x )]
+ +1 * p[(y-1) * frame->stride + (x+1)]
+ -1 * p[(y+1) * frame->stride + (x-1)]
+ -2 * p[(y+1) * frame->stride + (x )]
+ -1 * p[(y+1) * frame->stride + (x+1)]);
+ Yy = abs(Yy);
+
+ Y = (Yx > Yy ? Yx : Yy) / 4;
+ if (Y > 255) Y = 255;
+
+ data[y * frame->width + x] = Y;
+ }
+ }
+
+ *d = data;
+
+ return 0;
+}
diff --git a/src/util.h b/src/util.h
index 4666b06..22d5587 100644
--- a/src/util.h
+++ b/src/util.h
@@ -32,4 +32,7 @@ frame_average(struct video_frame *frame);
void
print_time(int64_t msec);
+int
+sobel(struct video_frame *frame, unsigned char **d);
+
#endif /* _UTIL_H_ */