2018-12-15 21:11:41 +00:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
// Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
|
|
|
|
|
|
|
|
#pragma once
|
2019-01-01 11:35:59 +00:00
|
|
|
#include <stdlib.h>
|
2018-12-19 20:50:02 +00:00
|
|
|
#include "compiler.h"
|
2018-12-15 21:11:41 +00:00
|
|
|
|
|
|
|
/// Code for generating convolution kernels
|
|
|
|
|
|
|
|
typedef struct conv {
|
2018-12-19 20:50:02 +00:00
|
|
|
int size;
|
2019-01-01 11:35:59 +00:00
|
|
|
double *rsum;
|
2018-12-19 20:50:02 +00:00
|
|
|
double data[];
|
2018-12-15 21:11:41 +00:00
|
|
|
} conv;
|
|
|
|
|
|
|
|
/// Calculate the sum of a rectangle part of the convolution kernel
|
|
|
|
/// the rectangle is defined by top left (x, y), and a size (width x height)
|
2018-12-19 23:41:58 +00:00
|
|
|
double attr_const sum_kernel(const conv *map, int x, int y, int width, int height);
|
2019-01-01 00:15:51 +00:00
|
|
|
double attr_const sum_kernel_normalized(const conv *map, int x, int y, int width, int height);
|
2018-12-15 21:11:41 +00:00
|
|
|
|
|
|
|
/// Create a kernel with gaussian distribution of radius r
|
|
|
|
conv *gaussian_kernel(double r);
|
2019-01-01 00:15:51 +00:00
|
|
|
|
|
|
|
/// preprocess kernels to make shadow generation faster
|
|
|
|
/// shadow_sum[x*d+y] is the sum of the kernel from (0, 0) to (x, y), inclusive
|
2019-01-01 11:35:59 +00:00
|
|
|
void shadow_preprocess(conv *map);
|
|
|
|
|
|
|
|
static inline void free_conv(conv *k) {
|
|
|
|
free(k->rsum);
|
|
|
|
free(k);
|
|
|
|
}
|