Rename GP_Context -> GP_Pixmap
[gfxprim.git] / include / filters / GP_Convolution.h
blob79551da0d10bf44c27a5ec000b0e2769c39fe9a3
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
25 Convolution filters.
29 #ifndef FILTERS_GP_CONVOLUTION_H
30 #define FILTERS_GP_CONVOLUTION_H
32 #include "GP_Filter.h"
33 #include "GP_Linear.h"
36 * 2D convolution kernel.
38 * The kernel array size must be w * h.
40 * The div is used to divide the resulting value which is commonly used for
41 * normalization.
43 * Example box smoothing filter kernel initialization:
45 * float box_filter[] = {
46 * 1, 1, 1,
47 * 1, 1, 1,
48 * 1, 1, 1,
49 * };
51 * GP_FilterKernel2D box_kernel = {
52 * .w = 3,
53 * .h = 3,
54 * .div = 9,
55 * .kernel = box_filter,
56 * };
58 typedef struct GP_FilterKernel2D {
59 unsigned int w;
60 unsigned int h;
61 float div;
62 float *kernel;
63 } GP_FilterKernel2D;
66 * Extended convolution filter.
68 * Works on rectangle in src defined by x_src, y_src, w_src and h_src.
70 * The result is stored into dst strating from x_dst and y_dst.
73 int GP_FilterConvolutionEx(const GP_Pixmap *src,
74 GP_Coord x_src, GP_Coord y_src,
75 GP_Size w_src, GP_Coord h_src,
76 GP_Pixmap *dst,
77 GP_Coord x_dst, GP_Coord y_dst,
78 const GP_FilterKernel2D *kernel,
79 GP_ProgressCallback *callback);
82 * Extended convolution filter.
84 * Works on rectangle in src defined by x_src, y_src, w_src and h_src.
86 * Allocates pixmap of a w_src x h_src.
88 GP_Pixmap *GP_FilterConvolutionExAlloc(const GP_Pixmap *src,
89 GP_Coord x_src, GP_Coord y_src,
90 GP_Size w_src, GP_Size h_src,
91 const GP_FilterKernel2D *kernel,
92 GP_ProgressCallback *callback);
95 static inline int GP_FilterConvolution(const GP_Pixmap *src, GP_Pixmap *dst,
96 const GP_FilterKernel2D *kernel,
97 GP_ProgressCallback *callback)
99 return GP_FilterConvolutionEx(src, 0, 0, dst->w, dst->h, dst, 0, 0,
100 kernel, callback);
103 static inline GP_Pixmap *GP_FilterConvolutionAlloc(const GP_Pixmap *src,
104 const GP_FilterKernel2D *kernel,
105 GP_ProgressCallback *callback)
107 return GP_FilterConvolutionExAlloc(src, 0, 0, src->w, src->h,
108 kernel, callback);
112 * Prints a kernel into the stdout.
114 static inline void GP_FilterKernel2DPrint(const GP_FilterKernel2D *kernel)
116 GP_FilterKernelPrint_Raw(kernel->kernel, kernel->w, kernel->h,
117 kernel->div);
120 #endif /* FILTERS_GP_CONVOLUTION_H */