MCPcopy Create free account
hub / github.com/OpenSN-Library/OpenSN-Library / getPalette

Function getPalette

tools/PacketCapture/main.go:54–76  ·  view source on GitHub ↗
(m image.Image)

Source from the content-addressed store, hash-verified

52}
53
54func getPalette(m image.Image) color.Palette {
55 p := color.Palette{color.RGBA{0x00, 0x00, 0x00, 0x00}}
56 p9 := color.Palette(palette.Plan9)
57 b := m.Bounds()
58 black := false
59 for y := b.Min.Y; y < b.Max.Y; y++ {
60 for x := b.Min.X; x < b.Max.X; x++ {
61 c := m.At(x, y)
62 cc := p9.Convert(c)
63 if cc == p9[0] {
64 black = true
65 }
66 if isInPalette(p, cc) == -1 {
67 p = append(p, cc)
68 }
69 }
70 }
71 if len(p) < 256 && black == true {
72 p[0] = color.RGBA{0x00, 0x00, 0x00, 0x00} // transparent
73 p = append(p, p9[0])
74 }
75 return p
76}
77
78func main() {
79 config.InitConfig("../../daemon/opensn-daemon/config/config.json")

Callers 1

mainFunction · 0.85

Calls 1

isInPaletteFunction · 0.85

Tested by

no test coverage detected