1 /*****************************************************************************
2 * This file is part of gfxprim library. *
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. *
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. *
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 *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
25 Linear Convolution _Raw filters.
29 #ifndef FILTERS_GP_LINEAR_H
30 #define FILTERS_GP_LINEAR_H
32 #include "GP_Filter.h"
37 * The kernel is array of kw * kh floats and is indexed as two directional
40 * The src coordinates and size defines rectangle in the source on which the
43 * The dst coodinates defines start pixel of in the destination pixmap.
45 * To define 3x3 average filter
57 int GP_FilterLinearConvolution_Raw(const GP_Pixmap
*src
,
58 GP_Coord x_src
, GP_Coord y_src
,
59 GP_Size w_src
, GP_Size h_src
,
61 GP_Coord x_dst
, GP_Coord y_dst
,
62 float kernel
[], uint32_t kw
, uint32_t kh
,
63 float kern_div
, GP_ProgressCallback
*callback
);
66 * Special cases for convolution only in horizontal/vertical direction.
68 * These are about 10-30% faster than the generic implementation (depending on
69 * the kernel size, bigger kernel == more savings).
71 * These are two are a base for bilinear filters.
73 * Both works also in-place.
75 int GP_FilterHLinearConvolution_Raw(const GP_Pixmap
*src
,
76 GP_Coord x_src
, GP_Coord y_src
,
77 GP_Size w_src
, GP_Size h_src
,
79 GP_Coord x_dst
, GP_Coord y_dst
,
80 float kernel
[], uint32_t kw
, float kern_div
,
81 GP_ProgressCallback
*callback
);
83 int GP_FilterVLinearConvolution_Raw(const GP_Pixmap
*src
,
84 GP_Coord x_src
, GP_Coord y_src
,
85 GP_Size w_src
, GP_Size h_src
,
87 GP_Coord x_dst
, GP_Coord y_dst
,
88 float kernel
[], uint32_t kh
, float kern_div
,
89 GP_ProgressCallback
*callback
);
92 * Applies both horizontal and vertical convolution and takes care of the
93 * correct progress callback (both horizontal and vertical kernels are expected
94 * to be similar in size).
96 int GP_FilterVHLinearConvolution_Raw(const GP_Pixmap
*src
,
97 GP_Coord x_src
, GP_Coord y_src
,
98 GP_Size w_src
, GP_Size h_src
,
100 GP_Coord x_dst
, GP_Coord y_dst
,
101 float hkernel
[], uint32_t kw
, float hkern_div
,
102 float vkernel
[], uint32_t kh
, float vkern_div
,
103 GP_ProgressCallback
*callback
);
106 * Prints a kernel into the stdout.
108 void GP_FilterKernelPrint_Raw(float kernel
[], int kw
, int kh
, float kern_div
);
112 typedef struct GP_ConvolutionParams
{
113 const GP_Pixmap
*src
;
128 GP_ProgressCallback
*callback
;
129 } GP_ConvolutionParams
;
131 static inline int GP_FilterConvolution_Raw(const struct GP_ConvolutionParams
*params
)
133 return GP_FilterLinearConvolution_Raw(params
->src
, params
->x_src
,
134 params
->y_src
, params
->w_src
,
135 params
->h_src
, params
->dst
,
136 params
->x_dst
, params
->y_dst
,
137 params
->kernel
, params
->kw
,
138 params
->kh
, params
->kern_div
,
142 static inline int GP_FilterVConvolution_Raw(const struct GP_ConvolutionParams
*params
)
145 return GP_FilterVLinearConvolution_Raw(params
->src
, params
->x_src
,
146 params
->y_src
, params
->w_src
,
147 params
->h_src
, params
->dst
,
148 params
->x_dst
, params
->y_dst
,
149 params
->kernel
, params
->kh
,
154 static inline int GP_FilterHConvolution_Raw(const struct GP_ConvolutionParams
*params
)
156 return GP_FilterHLinearConvolution_Raw(params
->src
, params
->x_src
,
157 params
->y_src
, params
->w_src
,
158 params
->h_src
, params
->dst
,
159 params
->x_dst
, params
->y_dst
,
160 params
->kernel
, params
->kw
,
165 #endif /* FILTERS_GP_LINEAR_H */