2 #include "IConvolution.h"
21 template <
int radius, ConvolutionEdgeBehavior behavior>
24 static const int kernel_width = 2 * radius + 1;
25 float _kernel[kernel_width][kernel_width];
28 Convolution(
float kernel[kernel_width][kernel_width])
30 for (
int i = 0; i < kernel_width; i++)
32 for (
int j = 0; j < kernel_width; j++)
34 _kernel[i][j] = kernel[i][j];
43 inline void Convolve(
float* in,
float* out,
int rows,
int cols)
const
45 for (
int i = 0; i < rows; i++) {
46 for (
int j = 0; j < cols; j++) {
47 int vtx = i * cols + j;
50 for (
int kern_x = -radius; kern_x <= radius; kern_x++) {
51 for (
int kern_y = -radius; kern_y <= radius; kern_y++) {
56 other_vtx_x = min(max(i + kern_x, 0), rows - 1);
57 other_vtx_y = min(max(j + kern_y, 0), cols - 1);
61 other_vtx_x = (((i + kern_x) % rows) + rows) % rows;
62 other_vtx_y = (((j + kern_y) % rows) + rows) % rows;
67 other_vtx_x = abs(i + kern_x);
68 other_vtx_y = abs(j + kern_y);
71 int diff_x = abs(other_vtx_x - (rows - 1));
72 other_vtx_x = (rows - 1) - diff_x;
74 int diff_y = abs(other_vtx_y - (cols - 1));
75 other_vtx_y = (cols - 1) - diff_y;
78 int other_vtx = other_vtx_x * cols + other_vtx_y;
79 val += _kernel[kern_x + radius][kern_y + radius] * in[other_vtx];
Definition: IConvolution.h:5
Definition: Convolution.h:22
Definition: Convolution.h:13
Definition: Convolution.h:9
ConvolutionEdgeBehavior
Definition: Convolution.h:6
Definition: Convolution.h:11
void Convolve(float *in, float *out, int rows, int cols) const
Definition: Convolution.h:43