img2gif
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package util
|
||||
|
||||
type Set map[color.Color]struct{}
|
||||
|
||||
func PaletteFromImage(img image.Image) color.Palette {
|
||||
m := Set{}
|
||||
for y := 0; y < img.Bounds().Dy(); y++ {
|
||||
for x := 0; x < img.Bounds().Dx(); x++ {
|
||||
m[img.At] = struct{}{}
|
||||
}
|
||||
}
|
||||
return func(m Set)(p color.Palette){
|
||||
for k := range m {
|
||||
p = append(p, k)
|
||||
}
|
||||
}(m)
|
||||
}
|
||||
|
||||
func ImageToPaletted(img image.Image) (image.Paletted) {
|
||||
p := image.NewPaletted(img.Bounds(), PaletteFromImage(img))
|
||||
|
||||
for y := 0; y < img.Bounds().Dy(); y++ {
|
||||
for x := 0; x < img.Bounds().Dx(); x++ {
|
||||
p.Set(x, y, img.At(x,y))
|
||||
}
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user