示例#1
0
文件: average.go 项目: buth/imageutil
func AverageNRGBA64(rect image.Rectangle, img *image.NRGBA64) color.NRGBA64 {

	// Only use the area of the rectangle that overlaps with the image bounds.
	rect = rect.Intersect(img.Bounds())

	// Determine whether or not there's any area over which to determine an
	// average.
	d := uint64(rect.Dx() * rect.Dy())
	if d == 0 {
		return color.NRGBA64{}
	}

	var r, g, b, a uint64
	AllPointsRP(
		func(pt image.Point) {
			c := img.NRGBA64At(pt.X, pt.Y)
			r += uint64(c.R)
			g += uint64(c.G)
			b += uint64(c.B)
			a += uint64(c.A)
		},
	)(rect)

	return color.NRGBA64{
		R: uint16(r / d),
		G: uint16(g / d),
		B: uint16(b / d),
		A: uint16(a / d),
	}
}
示例#2
0
文件: channel.go 项目: buth/imageutil
// Channels decomposes a given NRGBA64 into red, green, blue, and alpha Channels.
func NRGBA64ToChannels(img *image.NRGBA64) (r, g, b, a Channel) {
	r = channel{
		bounds: img.Bounds,
		gray16At: func(x, y int) color.Gray16 {
			return color.Gray16{
				Y: img.NRGBA64At(x, y).R,
			}
		},
	}

	g = channel{
		bounds: img.Bounds,
		gray16At: func(x, y int) color.Gray16 {
			return color.Gray16{
				Y: img.NRGBA64At(x, y).G,
			}
		},
	}

	b = channel{
		bounds: img.Bounds,
		gray16At: func(x, y int) color.Gray16 {
			return color.Gray16{
				Y: img.NRGBA64At(x, y).B,
			}
		},
	}

	a = channel{
		bounds: img.Bounds,
		gray16At: func(x, y int) color.Gray16 {
			return color.Gray16{
				Y: img.NRGBA64At(x, y).A,
			}
		},
	}

	return
}