From bf31390d1eca14bede1a590e8a718a3187018b94 Mon Sep 17 00:00:00 2001 From: sam Date: Sun, 3 Aug 2008 16:03:46 +0000 Subject: [PATCH] * sharpen.c: add a sharpen filter example, using our generic convolution routine. Note that it is not the "real" sharpen which should be built on top of a gaussian kernel. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2662 92316355-f0b4-4df1-b90c-862c8a59935f --- .gitignore | 1 + examples/Makefile.am | 5 ++++- examples/sharpen.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 examples/sharpen.c diff --git a/.gitignore b/.gitignore index b53545f..0b6dcd0 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ examples/blur examples/dither examples/edd examples/img2rubik +examples/sharpen test/u8tof32tou8 stamp-h1 .auto diff --git a/examples/Makefile.am b/examples/Makefile.am index 81d8799..ef5dcc8 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -2,7 +2,7 @@ AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/pipi -bin_PROGRAMS = blur dither edd img2rubik +bin_PROGRAMS = blur dither edd img2rubik sharpen blur_SOURCES = blur.c blur_LDADD = ../pipi/libpipi.la @@ -16,3 +16,6 @@ edd_LDADD = ../pipi/libpipi.la img2rubik_SOURCES = img2rubik.c img2rubik_LDADD = ../pipi/libpipi.la +sharpen_SOURCES = sharpen.c +sharpen_LDADD = ../pipi/libpipi.la + diff --git a/examples/sharpen.c b/examples/sharpen.c new file mode 100644 index 0000000..3218e3e --- /dev/null +++ b/examples/sharpen.c @@ -0,0 +1,43 @@ +#include "config.h" +#include "common.h" + +#include +#include +#include + +#include + +double kern[] = +{ + 0., -.0625, -.125, -.0625, 0., + -.0625, -.125, -.25, -.125, -.0625, + -.125, -.25, 3.5, -.25, -.125, + -.0625, -.125, -.25, -.125, -.0625, + 0., -.0625, -.125, -.0625, 0., +}; + +int main(int argc, char *argv[]) +{ + char *srcname = NULL, *dstname = NULL; + pipi_image_t *img, *newimg; + + if(argc < 3) + { + fprintf(stderr, "%s: too few arguments\n", argv[0]); + fprintf(stderr, "Usage: %s \n", argv[0]); + return EXIT_FAILURE; + } + + srcname = argv[1]; + dstname = argv[2]; + + img = pipi_load(srcname); + newimg = pipi_convolution(img, 5, 5, kern); + pipi_free(img); + + pipi_save(newimg, dstname); + pipi_free(newimg); + + return 0; +} +