Example #1
0
func colorAlterer(f pixelAlterer) utils.Composable {
	return func(c color.Color) color.Color {
		r, g, b, a := utils.NormalisedRGBA(c)
		grey := uint8(f(r, g, b))

		return color.NRGBA{grey, grey, grey, uint8(a)}
	}
}
Example #2
0
File: crop.go Project: hawx/img
func cropToValue(img image.Image, in func(x, y int) float64) image.Image {
	b := img.Bounds()
	o := image.NewRGBA(b)

	leastX := b.Max.X
	leastY := b.Max.Y
	mostX := 0
	mostY := 0

	for y := b.Min.Y; y <= b.Max.Y; y++ {
		for x := b.Min.X; x <= b.Max.X; x++ {
			if in(x, y) > 0 {
				if x < leastX {
					leastX = x
				}
				if y < leastY {
					leastY = y
				}
				if x > mostX {
					mostX = x
				}
				if y > mostY {
					mostY = y
				}

				r, g, b, a := utils.NormalisedRGBA(img.At(x, y))
				o.Set(x, y, color.NRGBA{
					uint8(r),
					uint8(g),
					uint8(b),
					uint8(float64(a) * in(x, y)),
				})
			}
		}
	}

	return o.SubImage(image.Rect(leastX, leastY, mostX, mostY))
}
Example #3
0
File: channel.go Project: hawx/img
func (_ blueCh) Set(c color.Color, v float64) color.Color {
	r, g, _, a := utils.NormalisedRGBA(c)
	v = utils.Truncatef(255 * v)

	return color.NRGBA{uint8(r), uint8(g), uint8(v), uint8(a)}
}
Example #4
0
File: channel.go Project: hawx/img
func (_ redCh) Set(c color.Color, v float64) color.Color {
	_, g, b, a := utils.NormalisedRGBA(c)
	v = utils.Truncatef(255 * v)

	return color.NRGBA{uint8(v), uint8(g), uint8(b), uint8(a)}
}
Example #5
0
File: channel.go Project: hawx/img
func (_ alphaCh) Set(c color.Color, v float64) color.Color {
	r, g, b, _ := utils.NormalisedRGBA(c)
	v = utils.Truncatef(255 * v)

	return color.NRGBA{uint8(r), uint8(g), uint8(b), uint8(v)}
}