Skip to content

Instantly share code, notes, and snippets.

@skoji
Created September 13, 2011 03:38
Show Gist options
  • Save skoji/1213072 to your computer and use it in GitHub Desktop.
Save skoji/1213072 to your computer and use it in GitHub Desktop.
GDD2011JP DevQuiz Go!
package main
import (
"fmt"
"io"
"strings"
"image/png"
)
func CountColor(pngdata io.Reader) int {
colors := make(map[string] bool)
img,_:= png.Decode(pngdata)
x, y := img.Bounds().Max.X, img.Bounds().Max.Y
for i := 0; i < x; i++ {
for j:= 0; j < y; j++ {
r,g,b,_ := img.At(i,j).RGBA()
index := fmt.Sprintf("%x%x%x",r,g,b)
colors[index] = true
}
}
return len(colors)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment