| 52 | } |
| 53 | |
| 54 | func 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 | |
| 78 | func main() { |
| 79 | config.InitConfig("../../daemon/opensn-daemon/config/config.json") |