From 6def6d1568a9d710fe0f2f05b96a014ae180a506 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 17 Apr 2012 20:37:28 +0200 Subject: Add a very simple vignetting-reduction program Its called unvignette.c. Has no dynamic adjustment yet, and operatoes only in x-direction. --- Makefile | 6 +++++- unvignette.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 unvignette.c 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 +#include +#include +#include + +#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; +} -- cgit