Ver código fonte

* Test implementation of Gaussian blurring. It's awfully slow and does not

use the separation property, but it's just for a test.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2603 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 16 anos atrás
pai
commit
7d147f3576
3 arquivos alterados com 83 adições e 0 exclusões
  1. +1
    -0
      pipi/Makefile.am
  2. +80
    -0
      pipi/filter/blur.c
  3. +2
    -0
      pipi/pipi.h

+ 1
- 0
pipi/Makefile.am Ver arquivo

@@ -27,6 +27,7 @@ libpipi_la_SOURCES = \
dither.c \
test.c \
$(codec_sources) \
filter/blur.c \
$(NULL)
libpipi_la_CFLAGS = $(codec_cflags)
libpipi_la_LDFLAGS = $(codec_libs) \


+ 80
- 0
pipi/filter/blur.c Ver arquivo

@@ -0,0 +1,80 @@
/*
* libpipi Proper image processing implementation library
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id$
*
* This library is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/

/*
* blur.c: blur functions
*/

#include "config.h"
#include "common.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include "pipi.h"
#include "pipi_internals.h"

pipi_image_t *pipi_gaussian_blur(pipi_image_t const *src, float radius)
{
pipi_image_t *dst;
double *kernel;
double K, L, t = 0.;
int x, y, i, j, w, h, kr, kw;

w = src->width;
h = src->height;

kr = (int)(3. * radius + 0.99999);
kw = 2 * kr + 1;
K = 1. / (2. * M_PI * radius * radius);
L = -1. / (2. * radius * radius);

kernel = malloc(kw * kw * sizeof(double));
for(j = -kr; j <= kr; j++)
for(i = -kr; i <= kr; i++)
t += kernel[(j + kr) * kw + (i + kr)]
= exp(L * (i * i + j * j)) * K;

for(j = -kr; j <= kr; j++)
for(i = -kr; i <= kr; i++)
kernel[(j + kr) * kw + (i + kr)] /= t;

dst = pipi_new(w, h);

for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
double R = 0., G = 0., B = 0.;

for(j = -kr; j <= kr; j++)
for(i = -kr; i <= kr; i++)
{
double r, g, b, f = kernel[(j + kr) * kw + (i + kr)];

pipi_getpixel(src, x + i, y + j, &r, &g, &b);
R += f * r;
G += f * g;
B += f * b;
}

pipi_setpixel(dst, x, y, R, G, B);
}
}

return dst;
}


+ 2
- 0
pipi/pipi.h Ver arquivo

@@ -40,6 +40,8 @@ extern int pipi_setpixel(pipi_image_t *img, int x, int y,

extern pipi_image_t *pipi_resize(pipi_image_t const *, int, int);

extern pipi_image_t *pipi_gaussian_blur(pipi_image_t const *, float);

extern void pipi_dither_24to16(pipi_image_t *img);

extern void pipi_test(pipi_image_t *);


Carregando…
Cancelar
Salvar