2018-12-15 16:11:41 -05:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
// Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
|
|
|
|
|
|
|
|
#pragma once
|
2019-01-01 06:35:59 -05:00
|
|
|
#include <stdlib.h>
|
2018-12-19 15:50:02 -05:00
|
|
|
#include "compiler.h"
|
2018-12-15 16:11:41 -05:00
|
|
|
|
|
|
|
/// Code for generating convolution kernels
|
|
|
|
|
|
|
|
typedef struct conv {
|
2019-02-17 16:54:35 -05:00
|
|
|
int w, h;
|
2019-01-01 06:35:59 -05:00
|
|
|
double *rsum;
|
2018-12-19 15:50:02 -05:00
|
|
|
double data[];
|
2018-12-15 16:11:41 -05: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)
|
2019-02-21 09:08:08 -05:00
|
|
|
double attr_pure sum_kernel(const conv *map, int x, int y, int width, int height);
|
|
|
|
double attr_pure sum_kernel_normalized(const conv *map, int x, int y, int width, int height);
|
2018-12-15 16:11:41 -05:00
|
|
|
|
2019-04-18 19:11:54 -04:00
|
|
|
/// Create a kernel with gaussian distribution with standard deviation `r`, and size
|
|
|
|
/// `size`.
|
|
|
|
conv *gaussian_kernel(double r, int size);
|
|
|
|
|
2022-09-18 00:00:52 -04:00
|
|
|
/// Estimate the best standard deviation for a give kernel size.
|
|
|
|
double gaussian_kernel_std_for_size(double size, double row_limit);
|
|
|
|
|
2019-04-18 19:11:54 -04:00
|
|
|
/// Create a gaussian kernel with auto detected standard deviation. The choosen standard
|
|
|
|
/// deviation tries to make sure the outer most pixels of the shadow are completely
|
|
|
|
/// transparent.
|
|
|
|
///
|
|
|
|
/// @param[in] shadow_radius the radius of the shadow
|
2022-08-25 00:21:19 -04:00
|
|
|
conv *gaussian_kernel_autodetect_deviation(double shadow_radius);
|
2018-12-31 19:15:51 -05: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-02-17 16:54:35 -05:00
|
|
|
void sum_kernel_preprocess(conv *map);
|
2019-01-01 06:35:59 -05:00
|
|
|
|
|
|
|
static inline void free_conv(conv *k) {
|
|
|
|
free(k->rsum);
|
|
|
|
free(k);
|
|
|
|
}
|