Parcourir la source

* convolution.c: generic convolution method. Does not take advantage of

separable kernels yet.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2658 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam il y a 16 ans
Parent
révision
89f35cb8fd
3 fichiers modifiés avec 114 ajouts et 0 suppressions
  1. +1
    -0
      pipi/Makefile.am
  2. +112
    -0
      pipi/filter/convolution.c
  3. +1
    -0
      pipi/pipi.h

+ 1
- 0
pipi/Makefile.am Voir le fichier

@@ -29,6 +29,7 @@ libpipi_la_SOURCES = \
test.c \
$(codec_sources) \
filter/blur.c \
filter/convolution.c \
dither/floydsteinberg.c \
dither/ostromoukhov.c \
dither/dbs.c \


+ 112
- 0
pipi/filter/convolution.c Voir le fichier

@@ -0,0 +1,112 @@
/*
* 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.
*/

/*
* convolution.c: generic convolution 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_convolution(pipi_image_t *src, int m, int n, double mat[])
{
pipi_image_t *dst;
pipi_pixels_t *srcp, *dstp;
float *srcdata, *dstdata;
int x, y, i, j, w, h, gray;

w = src->w;
h = src->h;

gray = (src->last_modified == PIPI_PIXELS_Y_F);

srcp = gray ? pipi_getpixels(src, PIPI_PIXELS_Y_F)
: pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
srcdata = (float *)srcp->pixels;

dst = pipi_new(w, h);
dstp = gray ? pipi_getpixels(dst, PIPI_PIXELS_Y_F)
: pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
dstdata = (float *)dstp->pixels;

for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
if(gray)
{
double Y = 0.;
int x2, y2;

for(j = 0; j < n; j++)
{
y2 = y + j - n / 2;
if(y2 < 0) y2 = 0;
else if(y2 >= h) y2 = h - 1;

for(i = 0; i < m; i++)
{
x2 = x + i;
if(x2 < 0) x2 = 0;
else if(x2 >= w) x2 = w - 1;

Y += mat[j * m + i] * srcdata[y * w + x2];
}
}

dstdata[y * w + x] = Y;
}
else
{
double R = 0., G = 0., B = 0.;
int x2, y2, off = 4 * (y * w + x);

for(j = 0; j < n; j++)
{
y2 = y + j - n / 2;
if(y2 < 0) y2 = 0;
else if(y2 >= h) y2 = h - 1;

for(i = 0; i < m; i++)
{
double f = mat[j * m + i];

x2 = x + i;
if(x2 < 0) x2 = 0;
else if(x2 >= w) x2 = w - 1;

R += f * srcdata[(y * w + x2) * 4];
G += f * srcdata[(y * w + x2) * 4 + 1];
B += f * srcdata[(y * w + x2) * 4 + 2];
}
}

dstdata[off] = R;
dstdata[off + 1] = G;
dstdata[off + 2] = B;
}
}
}

return dst;
}


+ 1
- 0
pipi/pipi.h Voir le fichier

@@ -73,6 +73,7 @@ extern double pipi_measure_rmsd(pipi_image_t *, pipi_image_t *);

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

extern pipi_image_t *pipi_convolution(pipi_image_t *, int, int, double[]);
extern pipi_image_t *pipi_gaussian_blur(pipi_image_t *, float);
extern pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *,
float, float, float, float);


Chargement…
Annuler
Enregistrer