GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_linear.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 Linear Convolution _raw filters.
9
10 */
11
12#ifndef FILTERS_GP_LINEAR_H
13#define FILTERS_GP_LINEAR_H
14
15#include <filters/gp_filter.h>
16
17/*
18 * Linear convolution.
19 *
20 * The kernel is array of kw * kh floats and is indexed as two directional
21 * array.
22 *
23 * The src coordinates and size defines rectangle in the source on which the
24 * filter operates.
25 *
26 * The dst coodinates defines start pixel of in the destination pixmap.
27 *
28 * To define 3x3 average filter
29 *
30 * kernel[] = {
31 * 1, 1, 1,
32 * 1, 1, 1,
33 * 1, 1, 1,
34 * };
35 *
36 * kw = kh = 3
37 *
38 * kern_div = 9
39 */
40int gp_filter_linear_convolution_raw(const gp_pixmap *src,
41 gp_coord x_src, gp_coord y_src,
42 gp_size w_src, gp_size h_src,
43 gp_pixmap *dst,
44 gp_coord x_dst, gp_coord y_dst,
45 float kernel[], uint32_t kw, uint32_t kh,
46 float kern_div, gp_progress_cb *callback);
47
48/*
49 * Special cases for convolution only in horizontal/vertical direction.
50 *
51 * These are about 10-30% faster than the generic implementation (depending on
52 * the kernel size, bigger kernel == more savings).
53 *
54 * These are two are a base for bilinear filters.
55 *
56 * Both works also in-place.
57 */
58int gp_filter_hlinear_convolution_raw(const gp_pixmap *src,
59 gp_coord x_src, gp_coord y_src,
60 gp_size w_src, gp_size h_src,
61 gp_pixmap *dst,
62 gp_coord x_dst, gp_coord y_dst,
63 float kernel[], uint32_t kw, float kern_div,
64 gp_progress_cb *callback);
65
66int gp_filter_vlinear_convolution_raw(const gp_pixmap *src,
67 gp_coord x_src, gp_coord y_src,
68 gp_size w_src, gp_size h_src,
69 gp_pixmap *dst,
70 gp_coord x_dst, gp_coord y_dst,
71 float kernel[], uint32_t kh, float kern_div,
72 gp_progress_cb *callback);
73
74/*
75 * Applies both horizontal and vertical convolution and takes care of the
76 * correct progress callback (both horizontal and vertical kernels are expected
77 * to be similar in size).
78 */
79int gp_filter_vhlinear_convolution_raw(const gp_pixmap *src,
80 gp_coord x_src, gp_coord y_src,
81 gp_size w_src, gp_size h_src,
82 gp_pixmap *dst,
83 gp_coord x_dst, gp_coord y_dst,
84 float hkernel[], uint32_t kw, float hkern_div,
85 float vkernel[], uint32_t kh, float vkern_div,
86 gp_progress_cb *callback);
87
88/*
89 * Prints a kernel into the stdout.
90 */
91void gp_filter_kernel_print_raw(float kernel[], int kw, int kh, float kern_div);
92
93typedef struct gp_convolution_params {
94 const gp_pixmap *src;
95 gp_coord x_src;
96 gp_coord y_src;
97 gp_size w_src;
98 gp_size h_src;
99
100 gp_pixmap *dst;
101 gp_coord x_dst;
102 gp_coord y_dst;
103
104 float *kernel;
105 unsigned int kw;
106 unsigned int kh;
107 float kern_div;
108
109 gp_progress_cb *callback;
110} gp_convolution_params;
111
112static inline int gp_filter_convolution_raw(const struct gp_convolution_params *params)
113{
114 return gp_filter_linear_convolution_raw(params->src, params->x_src,
115 params->y_src, params->w_src,
116 params->h_src, params->dst,
117 params->x_dst, params->y_dst,
118 params->kernel, params->kw,
119 params->kh, params->kern_div,
120 params->callback);
121}
122
123static inline int gp_filter_vconvolution_raw(const struct gp_convolution_params *params)
124{
125
126 return gp_filter_vlinear_convolution_raw(params->src, params->x_src,
127 params->y_src, params->w_src,
128 params->h_src, params->dst,
129 params->x_dst, params->y_dst,
130 params->kernel, params->kh,
131 params->kern_div,
132 params->callback);
133}
134
135static inline int gp_filter_hconvolution_raw(const struct gp_convolution_params *params)
136{
137 return gp_filter_hlinear_convolution_raw(params->src, params->x_src,
138 params->y_src, params->w_src,
139 params->h_src, params->dst,
140 params->x_dst, params->y_dst,
141 params->kernel, params->kw,
142 params->kern_div,
143 params->callback);
144}
145
146#endif /* FILTERS_GP_LINEAR_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
Progress callback.