Move presum_gaussian to render.c
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
a48e1f65a9
commit
404a6b47ad
|
@ -403,54 +403,6 @@ run_fade(session_t *ps, win *w, unsigned steps) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// === Shadows ===
|
|
||||||
|
|
||||||
/* precompute shadow corners and sides
|
|
||||||
to save time for large windows */
|
|
||||||
|
|
||||||
static void
|
|
||||||
presum_gaussian(session_t *ps, conv *map) {
|
|
||||||
int center = map->size / 2;
|
|
||||||
int opacity, x, y;
|
|
||||||
|
|
||||||
ps->cgsize = map->size;
|
|
||||||
|
|
||||||
if (ps->shadow_corner)
|
|
||||||
free(ps->shadow_corner);
|
|
||||||
if (ps->shadow_top)
|
|
||||||
free(ps->shadow_top);
|
|
||||||
|
|
||||||
ps->shadow_corner = cvalloc((ps->cgsize + 1) * (ps->cgsize + 1) * 26);
|
|
||||||
ps->shadow_top = cvalloc((ps->cgsize + 1) * 26);
|
|
||||||
|
|
||||||
for (x = 0; x <= ps->cgsize; x++) {
|
|
||||||
ps->shadow_top[25 * (ps->cgsize + 1) + x] = (unsigned char)
|
|
||||||
(sum_kernel(map, x - center, center, ps->cgsize * 2, ps->cgsize * 2) * 255.0);
|
|
||||||
|
|
||||||
for (opacity = 0; opacity < 25; opacity++) {
|
|
||||||
ps->shadow_top[opacity * (ps->cgsize + 1) + x] =
|
|
||||||
ps->shadow_top[25 * (ps->cgsize + 1) + x] * opacity / 25;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (y = 0; y <= x; y++) {
|
|
||||||
ps->shadow_corner[25 * (ps->cgsize + 1) * (ps->cgsize + 1) + y * (ps->cgsize + 1) + x]
|
|
||||||
= (unsigned char)
|
|
||||||
(sum_kernel(map, x - center, y - center, ps->cgsize * 2, ps->cgsize * 2) * 255.0);
|
|
||||||
ps->shadow_corner[25 * (ps->cgsize + 1) * (ps->cgsize + 1) + x * (ps->cgsize + 1) + y]
|
|
||||||
= ps->shadow_corner[25 * (ps->cgsize + 1) * (ps->cgsize + 1) + y * (ps->cgsize + 1) + x];
|
|
||||||
|
|
||||||
for (opacity = 0; opacity < 25; opacity++) {
|
|
||||||
ps->shadow_corner[opacity * (ps->cgsize + 1) * (ps->cgsize + 1)
|
|
||||||
+ y * (ps->cgsize + 1) + x]
|
|
||||||
= ps->shadow_corner[opacity * (ps->cgsize + 1) * (ps->cgsize + 1)
|
|
||||||
+ x * (ps->cgsize + 1) + y]
|
|
||||||
= ps->shadow_corner[25 * (ps->cgsize + 1) * (ps->cgsize + 1)
|
|
||||||
+ y * (ps->cgsize + 1) + x] * opacity / 25;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Error handling ===
|
// === Error handling ===
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -3851,9 +3803,6 @@ session_init(session_t *ps_old, int argc, char **argv) {
|
||||||
|
|
||||||
init_atoms(ps);
|
init_atoms(ps);
|
||||||
|
|
||||||
ps->gaussian_map = gaussian_kernel(ps->o.shadow_radius);
|
|
||||||
presum_gaussian(ps, ps->gaussian_map);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
xcb_render_create_picture_value_list_t pa = {
|
xcb_render_create_picture_value_list_t pa = {
|
||||||
.subwindowmode = IncludeInferiors,
|
.subwindowmode = IncludeInferiors,
|
||||||
|
|
47
src/render.c
47
src/render.c
|
@ -1183,6 +1183,50 @@ static bool init_alpha_picts(session_t *ps) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// precompute shadow corners and sides to save time for large windows
|
||||||
|
static void presum_gaussian(session_t *ps, conv *map) {
|
||||||
|
ps->cgsize = map->size;
|
||||||
|
|
||||||
|
const int center = map->size / 2;
|
||||||
|
const int r = ps->cgsize + 1; // radius of the kernel
|
||||||
|
const int width = ps->cgsize * 2, height = ps->cgsize * 2;
|
||||||
|
|
||||||
|
|
||||||
|
if (ps->shadow_corner)
|
||||||
|
free(ps->shadow_corner);
|
||||||
|
if (ps->shadow_top)
|
||||||
|
free(ps->shadow_top);
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
ps->shadow_corner = cvalloc(r*r*26);
|
||||||
|
ps->shadow_top = cvalloc(r*26);
|
||||||
|
|
||||||
|
for (int x = 0; x < r; x++) {
|
||||||
|
double sum = sum_kernel(map, x-center, center, width, height);
|
||||||
|
int tmp = ps->shadow_top[25*r+x] = (unsigned char)(sum*255.0);
|
||||||
|
|
||||||
|
for (int opacity = 0; opacity < 25; opacity++) {
|
||||||
|
ps->shadow_top[opacity*r+x] = tmp*opacity/25;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int x = 0; x < r; x++) {
|
||||||
|
for (int y = 0; y <= x; y++) {
|
||||||
|
double sum =
|
||||||
|
sum_kernel(map, x-center, y-center, width, height);
|
||||||
|
ps->shadow_corner[25*r*r+y*r+x] = (unsigned char)(sum*255.0);
|
||||||
|
ps->shadow_corner[25*r*r+x*r+y] = ps->shadow_corner[25*r*r+y*r+x];
|
||||||
|
|
||||||
|
for (int opacity = 0; opacity < 25; opacity++) {
|
||||||
|
ps->shadow_corner[opacity*r*r+y*r+x] =
|
||||||
|
ps->shadow_corner[opacity*r*r+x*r+y] =
|
||||||
|
ps->shadow_corner[25*r*r+y*r+x]*opacity/25;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// clang-format on
|
||||||
|
}
|
||||||
|
|
||||||
bool init_render(session_t *ps) {
|
bool init_render(session_t *ps) {
|
||||||
// Initialize OpenGL as early as possible
|
// Initialize OpenGL as early as possible
|
||||||
if (bkend_use_glx(ps)) {
|
if (bkend_use_glx(ps)) {
|
||||||
|
@ -1232,6 +1276,9 @@ bool init_render(session_t *ps) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ps->gaussian_map = gaussian_kernel(ps->o.shadow_radius);
|
||||||
|
presum_gaussian(ps, ps->gaussian_map);
|
||||||
|
|
||||||
ps->black_picture = solid_picture(ps, true, 1, 0, 0, 0);
|
ps->black_picture = solid_picture(ps, true, 1, 0, 0, 0);
|
||||||
ps->white_picture = solid_picture(ps, true, 1, 1, 1, 1);
|
ps->white_picture = solid_picture(ps, true, 1, 1, 1, 1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue