summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-04-17 20:37:28 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-04-17 21:32:04 +0200
commit6def6d1568a9d710fe0f2f05b96a014ae180a506 (patch)
treee6e0ce8b2cfb57efdfd648e95fd9697eb59494cf
parentcae4b8ed522c0302dd4db994ffcf509f0a245535 (diff)
downloadcv-6def6d1568a9d710fe0f2f05b96a014ae180a506.zip
cv-6def6d1568a9d710fe0f2f05b96a014ae180a506.tar.gz
cv-6def6d1568a9d710fe0f2f05b96a014ae180a506.tar.bz2
Add a very simple vignetting-reduction program
Its called unvignette.c. Has no dynamic adjustment yet, and operatoes only in x-direction.
-rw-r--r--Makefile6
-rw-r--r--unvignette.c45
2 files changed, 50 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 30f407f..afdc528 100644
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,10 @@ roi_LIBS=$(shell pkg-config --libs gtk+-3.0 gdk-pixbuf-2.0 glib-2.0)
capture_CFLAGS=$(shell pkg-config --cflags gtk+-3.0 opencv glib-2.0)
capture_LIBS=$(shell pkg-config --libs gtk+-3.0 opencv glib-2.0)
-PROGS = wimmel wimmel_gl roi capture
+unvignette_CFLAGS=$(shell pkg-config --cflags cairo)
+unvignette_LIBS=$(shell pkg-config --libs cairo) -lm
+
+PROGS = wimmel wimmel_gl roi capture unvignette
OBJS = $(PROGS:=.o) util.o
all: $(PROGS)
@@ -25,6 +28,7 @@ wimmel: wimmel.o util.o
wimmel_gl: wimmel_gl.o util.o
roi: roi.o
capture: capture.o
+unvignette: unvignette.o
.PHONY: clean all
diff --git a/unvignette.c b/unvignette.c
new file mode 100644
index 0000000..36e30e7
--- /dev/null
+++ b/unvignette.c
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <cairo.h>
+
+#define CLAMP(x, l, h) (((x) > (h)) ? (h) : (((x) < (l)) ? (l) : (x)))
+
+static inline double
+cos4(double x)
+{
+ return CLAMP(pow(cos(x), 4.0), 0.001, 1.0);
+}
+
+int
+main(int argc, char *argv[])
+{
+ cairo_surface_t *s;
+ unsigned char *row, *p;
+ int x, y, i, width, height, stride;
+
+ if (argc < 2)
+ exit(EXIT_FAILURE);
+
+ s = cairo_image_surface_create_from_png(argv[1]);
+ if (!s || cairo_surface_status(s) != CAIRO_STATUS_SUCCESS)
+ exit(EXIT_FAILURE);
+
+ row = cairo_image_surface_get_data(s);
+ width = cairo_image_surface_get_width(s);
+ height = cairo_image_surface_get_height(s);
+ stride = cairo_image_surface_get_stride(s);
+
+ for (y = 0; y < height; ++y, row += stride) {
+ for (x = 0, p = row; x < width; ++x, p += 4) {
+ double c = 1.0 / cos4(1.2 * (x - width / 2) / width);
+ for (i = 0; i < 3; ++i)
+ p[i] = CLAMP(c * p[i], 0, 255);
+ }
+ }
+
+ cairo_surface_write_to_png(s, argc > 2 ? argv[2] : "unvignetted.png");
+ cairo_surface_destroy(s);
+
+ return 0;
+}