Files
openchamber-android-native/third_party/mygo/internal/text/shadow.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
2026-11-18 13:22:59 +08:00

67 lines
1.7 KiB
Go

package text
import "math"
// blurBitmap returns the coverage of b blurred by a Gaussian of standard
// deviation sigma pixels, as a mask reaching three of them past b on each
// side: a glyph's shadow. Color glyphs blur their alpha, subpixel ones
// their most covered channel; a sigma of 0 leaves the coverage sharp.
func blurBitmap(b bitmap, sigma float32) bitmap {
pad := 0
if sigma > 0 {
pad = int(math.Ceil(float64(3*sigma))) + 1
}
w, h := b.w+2*pad, b.h+2*pad
cov := make([]float32, w*h)
for y := range b.h {
for x := range b.w {
i := y*b.w + x
var c byte
switch {
case b.color:
c = b.pix[4*i+3]
case b.subpixel:
p := b.pix[4*i:]
c = max(p[0], p[1], p[2])
default:
c = b.pix[i]
}
cov[(y+pad)*w+x+pad] = float32(c) / 255
}
}
if pad > 0 {
// The kernel, normalized, and the blur in rows, then in columns.
kernel := make([]float32, 2*pad+1)
var sum float32
for i := range kernel {
d := float64(i - pad)
kernel[i] = float32(math.Exp(-d * d / (2 * float64(sigma) * float64(sigma))))
sum += kernel[i]
}
for i := range kernel {
kernel[i] /= sum
}
tmp := make([]float32, w*h)
blur := func(dst, src []float32, n, step, lines, across int) {
for l := range lines {
for i := range n {
var v float32
for k, kv := range kernel {
if j := i + k - pad; j >= 0 && j < n {
v += src[l*across+j*step] * kv
}
}
dst[l*across+i*step] = v
}
}
}
blur(tmp, cov, w, 1, h, w) // rows
blur(cov, tmp, h, w, w, 1) // columns
}
pix := make([]byte, w*h)
for i, c := range cov {
pix[i] = uint8(min(max(c, 0), 1)*255 + 0.5)
}
return bitmap{left: b.left - pad, top: b.top - pad, w: w, h: h, pix: pix}
}