summaryrefslogtreecommitdiffstats
path: root/sixel.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2026-05-28 20:16:10 -0700
committerRose Hogenson <rosehogenson@posteo.net>2026-05-28 20:16:10 -0700
commitdcae1c9d14004f364e476b82a4e66d015b2b04ef (patch)
tree934bdea82d5dcd8aca208b6951a6f0882aba0384 /sixel.go
parent3ddc4fd119a9812ad61a1bfed15162fd5821afbd (diff)
downloadsixel-dcae1c9d14004f364e476b82a4e66d015b2b04ef.tar.zst
Exclude transparent colors from median cut
Diffstat (limited to 'sixel.go')
-rw-r--r--sixel.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/sixel.go b/sixel.go
index 6873491..a744d35 100644
--- a/sixel.go
+++ b/sixel.go
@@ -81,14 +81,16 @@ func avgPaletteRGB(buckets [][]color.RGBA) []sixelRGB {
}
func medianCut(img image.Image) color.Palette {
- colors := make([]color.RGBA, 0, img.Bounds().Dx()*img.Bounds().Dy())
+ var colors []color.RGBA
for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ {
for x := img.Bounds().Min.X; x < img.Bounds().Max.X; x++ {
r, g, b, a := img.At(x, y).RGBA()
- colors = append(colors, color.RGBA{R: uint8(r >> 8), G: uint8(g >> 8), B: uint8(b >> 8), A: uint8(a >> 8)})
+ if a > 0 {
+ colors = append(colors, color.RGBA{R: uint8(r >> 8), G: uint8(g >> 8), B: uint8(b >> 8), A: 0xff})
+ }
}
}
- buckets := slices.DeleteFunc(cutDepth(colors, 0), func(c []color.RGBA) bool { return len(c) == 0 })
+ buckets := slices.DeleteFunc(cutDepth(colors, 0), func(b []color.RGBA) bool { return len(b) == 0 })
paletteRGB := avgPaletteRGB(buckets)
if len(paletteRGB) == 256 {
lastBucket := buckets[len(buckets)-1]