filters: Cleanup and preparation for changes.
[gfxprim.git] / include / filters / GP_Linear.h
blobe6cf8854be0df55cafbac6c5126add02ca774786
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 Linear Convolution _Raw filters.
29 #ifndef FILTERS_GP_LINEAR_H
30 #define FILTERS_GP_LINEAR_H
32 #include "GP_Filter.h"
35 * Gaussian blur
37 * The sigma parameters defines the blur radii in horizontal and vertical
38 * direction.
40 * Internaly this is implemented as separable linear filter (calls vertical and
41 * horizontal convolution with generated gaussian kernel).
43 * This variant could work in-place so it's perectly okay to call
45 * GP_FilterGaussianBlur_Raw(context, context, ...);
47 int GP_FilterGaussianBlur_Raw(const GP_Context *src, GP_Context *dst,
48 float sigma_x, float sigma_y,
49 GP_ProgressCallback *callback);
51 * Gaussian blur.
53 * If dst is NULL, new bitmap is allocated.
55 * This variant could work in-place.
57 * Returns pointer to destination bitmap or NULL if allocation failed.
59 GP_Context *GP_FilterGaussianBlur(const GP_Context *src, GP_Context *dst,
60 float sigma_x, float sigma_y,
61 GP_ProgressCallback *callback);
64 * Linear convolution.
66 * The kernel is array of kw * kh floats and is indexed as two directional
67 * array.
69 * The src coordinates and size defines rectangle in the source on which the
70 * filter operates.
72 * The dst coodinates defines start pixel of in the destination context.
74 * To define 3x3 average filter
76 * kernel[] = {
77 * 1, 1, 1,
78 * 1, 1, 1,
79 * 1, 1, 1,
80 * };
82 * kw = kh = 3
84 * kern_div = 9
86 * This function works also in-place.
88 int GP_FilterLinearConvolution_Raw(const GP_Context *src,
89 GP_Coord x_src, GP_Coord y_src,
90 GP_Size w_src, GP_Size h_src,
91 GP_Context *dst,
92 GP_Coord x_dst, GP_Coord y_dst,
93 float kernel[], uint32_t kw, uint32_t kh,
94 float kern_div, GP_ProgressCallback *callback);
97 * Special cases for convolution only in horizontal/vertical direction.
99 * These are about 10-30% faster than the generic implementation (depending on
100 * the kernel size, bigger kernel == more savings).
102 * These are two are a base for bilinear filters.
104 * Both works also in-place.
106 int GP_FilterHLinearConvolution_Raw(const GP_Context *src,
107 GP_Coord x_src, GP_Coord y_src,
108 GP_Size w_src, GP_Size h_src,
109 GP_Context *dst,
110 GP_Coord x_dst, GP_Coord y_dst,
111 float kernel[], uint32_t kw, float kern_div,
112 GP_ProgressCallback *callback);
114 int GP_FilterVLinearConvolution_Raw(const GP_Context *src,
115 GP_Coord x_src, GP_Coord y_src,
116 GP_Size w_src, GP_Size h_src,
117 GP_Context *dst,
118 GP_Coord x_dst, GP_Coord y_dst,
119 float kernel[], uint32_t kh, float kern_div,
120 GP_ProgressCallback *callback);
123 * Applies both horizontal and vertical convolution and takes care of the
124 * correct progress callback (both horizontal and vertical kernels are expected
125 * to be similar in size).
127 int GP_FilterVHLinearConvolution_Raw(const GP_Context *src,
128 GP_Coord x_src, GP_Coord y_src,
129 GP_Size w_src, GP_Size h_src,
130 GP_Context *dst,
131 GP_Coord x_dst, GP_Coord y_dst,
132 float hkernel[], uint32_t kw, float hkern_div,
133 float vkernel[], uint32_t kh, float vkern_div,
134 GP_ProgressCallback *callback);
137 * Prints a kernel into the stdout.
139 void GP_FilterKernelPrint_Raw(float kernel[], int kw, int kh, float kern_div);
141 #endif /* FILTERS_GP_LINEAR_H */