本文整理匯總了Golang中image.Color類的典型用法代碼示例。如果您正苦於以下問題:Golang Color類的具體用法?Golang Color怎麽用?Golang Color使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Color類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: toColor
func toColor(color image.Color) image.Color {
if c, ok := color.(Color); ok {
return c
}
r, g, b, a := color.RGBA()
return Color(r>>24<<24 | g>>24<<16 | b>>24<<8 | a>>24)
}
示例2: toFloatGrayColor
func toFloatGrayColor(c image.Color) image.Color {
if _, ok := c.(FloatGrayColor); ok {
return c
}
r, g, b, _ := c.RGBA()
y := (0.3*float(r) + 0.59*float(g) + 0.11*float(b)) / float(0xffff)
return FloatGrayColor{y}
}
示例3: Set
func (img *surfimg) Set(x, y int, c image.Color) {
img.Lock()
defer img.Unlock()
r, g, b, a := c.RGBA()
pix := img.pixPtr(x, y)
pix.SetUint(uint64(sdl.MapRGBA(img.Format, uint8(r), uint8(g), uint8(b), uint8(a))))
}
示例4: PixelSimilarity
//
// Compare two pixels
// Return their similarity over the interval [0.0, 1.0]
//
func PixelSimilarity(pixel1, pixel2 image.Color) float64 {
p1r, p1g, p1b, _ := pixel1.RGBA()
p2r, p2g, p2b, _ := pixel2.RGBA()
similarity := 0.0
similarity += (PixelChannelSimilarity(p1r, p2r) / 3.0)
similarity += (PixelChannelSimilarity(p1g, p2g) / 3.0)
similarity += (PixelChannelSimilarity(p1b, p2b) / 3.0)
return similarity
}
示例5: withinTolerance
func withinTolerance(c0, c1 image.Color, tolerance int) bool {
r0, g0, b0, a0 := c0.RGBA()
r1, g1, b1, a1 := c1.RGBA()
r := delta(r0, r1)
g := delta(g0, g1)
b := delta(b0, b1)
a := delta(a0, a1)
return r <= tolerance && g <= tolerance && b <= tolerance && a <= tolerance
}
示例6: Mix
func Mix(x, y image.Color, theta float64) image.Color {
rx, gx, bx, ax := x.RGBA()
ry, gy, by, ay := y.RGBA()
r := (1-theta)*float64(rx) + theta*float64(ry)
g := (1-theta)*float64(gx) + theta*float64(gy)
b := (1-theta)*float64(bx) + theta*float64(by)
a := (1-theta)*float64(ax) + theta*float64(ay)
return &image.RGBA64Color{uint16(r), uint16(g), uint16(b), uint16(a)}
}
示例7: CountColor
func CountColor(png io.Reader) int {
var pic image.Image
var color image.Color
pic, e := p.Decode(png)
if e != nil {
fmt.Printf("Error %v\n", e)
return 0
}
cnt := 0
colormap := make(map[string]int)
for y := 0; y < pic.Bounds().Size().Y; y++ {
for x := 0; x < pic.Bounds().Size().X; x++ {
color = pic.At(x, y)
r, g, b, _ := color.RGBA()
key := ""
if uint8(r) < 10 {
key += "00" + strconv.Uitoa(uint(uint8(r)))
} else if uint8(r) < 100 {
key += "0" + strconv.Uitoa(uint(uint8(r)))
} else {
key += strconv.Uitoa(uint(uint8(r)))
}
if uint8(g) < 10 {
key += "00" + strconv.Uitoa(uint(uint8(g)))
} else if uint8(g) < 100 {
key += "0" + strconv.Uitoa(uint(uint8(g)))
} else {
key += strconv.Uitoa(uint(uint8(g)))
}
if uint8(b) < 10 {
key += "00" + strconv.Uitoa(uint(uint8(b)))
} else if uint8(b) < 100 {
key += "0" + strconv.Uitoa(uint(uint8(b)))
} else {
key += strconv.Uitoa(uint(uint8(b)))
}
if val, exist := colormap[key]; exist {
colormap[key] = val + 1
} else {
colormap[key] = 1
cnt++
}
}
}
return cnt
}
示例8: Check
func (this *HashSet) Check(color image.Color) bool {
for i := 0; i < len(this.colors); i++ {
buf := this.colors[i]
r1, g1, b1, _ := buf.RGBA()
r2, g2, b2, _ := color.RGBA()
if r1 == r2 && g1 == g2 && b1 == b2 {
return false
}
}
return true
}
示例9: Set
func (surface *Surface) Set(x, y int, c image.Color) {
//TODO endianess, bpp, alpha, etc
var bpp = int(surface.Format.BytesPerPixel)
var pixel = uintptr(unsafe.Pointer(surface.Pixels))
pixel += uintptr(y*int(surface.Pitch) + x*bpp)
var p = (*image.RGBAColor)(unsafe.Pointer(pixel))
var r, g, b, a = c.RGBA()
p.R = uint8(r)
p.G = uint8(g)
p.R = uint8(b)
p.A = uint8(255 - a)
}
示例10: CountColor
func CountColor(reader io.Reader) int {
var count = map[string]int{}
decodedPng, error := png.Decode(reader)
if error == nil {
var rect image.Rectangle = decodedPng.Bounds()
for i := 0; i < rect.Size().X; i++ {
for j := 0; j < rect.Size().Y; j++ {
var pixel image.Color = decodedPng.At(i, j)
var r, g, b, _ uint32 = pixel.RGBA()
var key uint = (uint)((r << 16) + (g << 8) + (b))
if _, ok := count[strconv.Uitoa(key)]; ok {
count[strconv.Uitoa(key)]++
} else {
count[strconv.Uitoa(key)] = 1
}
}
}
}
return len(count)
}
示例11: eq
func eq(c0, c1 image.Color) bool {
r0, g0, b0, a0 := c0.RGBA()
r1, g1, b1, a1 := c1.RGBA()
return r0 == r1 && g0 == g1 && b0 == b1 && a0 == a1
}
示例12: toColor
func toColor(color image.Color) image.Color {
if c, ok := color.(Color32); ok {
return c
}
return makeColor(color.RGBA());
}
示例13: Set
func (m *Image) Set(x, y int, color image.Color) {
if c, ok := color.(Color); ok {
m.Pixel[y][x] = c
}
m.Pixel[y][x] = makeColor(color.RGBA())
}
示例14: toYCbCrColor
func toYCbCrColor(c image.Color) image.Color {
if _, ok := c.(YCbCrColor); ok {
return c
}
r, g, b, _ := c.RGBA()
y, u, v := RGBToYCbCr(uint8(r>>8), uint8(g>>8), uint8(b>>8))
return YCbCrColor{y, u, v}
}