Exemple #1
0
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)
}
Exemple #2
0
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}
}
Exemple #3
0
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))))
}
Exemple #4
0
//
// 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
}
Exemple #5
0
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
}
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)}
}
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
}
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
}
Exemple #9
0
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)

}
Exemple #10
0
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)
}
Exemple #11
0
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
}
Exemple #12
0
func toColor(color image.Color) image.Color {
	if c, ok := color.(Color32); ok {
		return c
	}
	return makeColor(color.RGBA());
}
Exemple #13
0
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())
}
Exemple #14
-1
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}
}