GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_convolution.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz>
4 */
5
6/*
7
8 Convolution filters.
9
10 */
11
12#ifndef FILTERS_GP_CONVOLUTION_H
13#define FILTERS_GP_CONVOLUTION_H
14
15#include <filters/gp_filter.h>
16#include <filters/gp_linear.h>
17
18/*
19 * 2D convolution kernel.
20 *
21 * The kernel array size must be w * h.
22 *
23 * The div is used to divide the resulting value which is commonly used for
24 * normalization.
25 *
26 * _example box smoothing filter kernel initialization:
27 *
28 * float box_filter[] = {
29 * 1, 1, 1,
30 * 1, 1, 1,
31 * 1, 1, 1,
32 * };
33 *
34 * gp_filter_kernel_2d box_kernel = {
35 * .w = 3,
36 * .h = 3,
37 * .div = 9,
38 * .kernel = box_filter,
39 * };
40 */
41typedef struct gp_filter_kernel_2d {
42 unsigned int w;
43 unsigned int h;
44 float div;
45 float *kernel;
46} gp_filter_kernel_2d;
47
48/*
49 * _extended convolution filter.
50 *
51 * Works on rectangle in src defined by x_src, y_src, w_src and h_src.
52 *
53 * The result is stored into dst strating from x_dst and y_dst.
54 *
55 */
56int gp_filter_convolution_ex(const gp_pixmap *src,
57 gp_coord x_src, gp_coord y_src,
58 gp_size w_src, gp_coord h_src,
59 gp_pixmap *dst,
60 gp_coord x_dst, gp_coord y_dst,
61 const gp_filter_kernel_2d *kernel,
62 gp_progress_cb *callback);
63
64/*
65 * _extended convolution filter.
66 *
67 * Works on rectangle in src defined by x_src, y_src, w_src and h_src.
68 *
69 * _allocates pixmap of a w_src x h_src.
70 */
71gp_pixmap *gp_filter_convolution_ex_alloc(const gp_pixmap *src,
72 gp_coord x_src, gp_coord y_src,
73 gp_size w_src, gp_size h_src,
74 const gp_filter_kernel_2d *kernel,
75 gp_progress_cb *callback);
76
77
78static inline int gp_filter_convolution(const gp_pixmap *src, gp_pixmap *dst,
79 const gp_filter_kernel_2d *kernel,
80 gp_progress_cb *callback)
81{
82 return gp_filter_convolution_ex(src, 0, 0, dst->w, dst->h, dst, 0, 0,
83 kernel, callback);
84}
85
86static inline gp_pixmap *gp_filter_convolution_alloc(const gp_pixmap *src,
87 const gp_filter_kernel_2d *kernel,
88 gp_progress_cb *callback)
89{
90 return gp_filter_convolution_ex_alloc(src, 0, 0, src->w, src->h,
91 kernel, callback);
92}
93
94/*
95 * Prints a kernel into the stdout.
96 */
97static inline void gp_filter_kernel_2d_print(const gp_filter_kernel_2d *kernel)
98{
99 gp_filter_kernel_print_raw(kernel->kernel, kernel->w, kernel->h,
100 kernel->div);
101}
102
103#endif /* FILTERS_GP_CONVOLUTION_H */
int gp_coord
Integer type for coordinates i.e. x, y, ...
Definition gp_types.h:19
unsigned int gp_size
Integer type for sizes i.e. w, h, ...
Definition gp_types.h:24
Common filter includes.
A pixmap buffer.
Definition gp_pixmap.h:33
uint32_t h
Pixmap height in pixels.
Definition gp_pixmap.h:46
uint32_t w
Pixmap width in pixels.
Definition gp_pixmap.h:44
Progress callback.