Skip to content

Commit b187bdc

Browse files
committed
use gausswin
1 parent 9405ad4 commit b187bdc

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/artist.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,9 @@ end
334334
function array_max!(a, b)
335335
a .= max.(a, b)
336336
end
337-
function window(k, h=1)
338-
r = k ÷ 2
339-
w = collect(-(k - 1 - r):1.0:r)
340-
w .= h .* (1 .- (abs.(w) ./ r) .^ 2)
337+
function gausswin(n, h=1)
338+
g(x, σ) = exp(-0.5 * (x / σ)^2)
339+
h * g.(range(-0.5, 0.5, n), 0.5 / 2.5)
341340
end
342341
function randommaskcolor(colors)
343342
colors = ascolor.(unique(colors))
@@ -349,9 +348,9 @@ function randommaskcolor(colors)
349348
rh = 30
350349
h_slots = zeros(360) .+ 0.05
351350
s2max = 0.6
352-
win_l = window(2rl + 1)
353-
win_l2 = window(2rl2 + 1)
354-
win_h = window(2rh + 1)
351+
win_l = gausswin(2rl + 1)
352+
win_l2 = gausswin(2rl2 + 1)
353+
win_h = gausswin(2rh + 1)
355354
for c in colors
356355
li = clamp(round(Int, c[3] * 255), 0, 255) + 1
357356
array_max!(@view(l_slots[li-rl+rl2:li+rl+rl2]), win_l) # 明度避让以保证对比度
@@ -387,7 +386,7 @@ function randommaskcolor(colors)
387386
end
388387
l_slots = l_slots[1+rl2:256+rl2]
389388
w = ones(length(l_slots))
390-
w[51:end-51] .+= window(256 - 101, 7) # 中间调回避
389+
w[51:end-51] .+= gausswin(256 - 101, 7) # 中间调回避
391390
array_max!(@view(w[1:end÷2]), 3) # 高亮偏好
392391
l_slots .*= w
393392
l2 = rand_argmin(l_slots) / 255

0 commit comments

Comments
 (0)