Beispiel #1
0
// HardLight multiplies or screens the colours, depending on the blend
// colour. The effect is similar to shining a harsh spotlight on the image.
func HardLight(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.NormalisedRGBAf(c)
		m, n, o, p := utils.NormalisedRGBAf(d)

		f := func(i, j float64) float64 {
			if j > 128 {
				return 255 - ((255-2*(j-128))*(255-i))/256
			}
			return (2 * j * i) / 256
		}

		r := f(i, m)
		g := f(j, n)
		b := f(k, o)
		a := p + l*(1-p)

		return color.NRGBA{
			uint8(utils.Truncatef(r)),
			uint8(utils.Truncatef(g)),
			uint8(utils.Truncatef(b)),
			uint8(utils.Truncatef(a * 255)),
		}
	})
}
Beispiel #2
0
// Overlay multiplies or screens the colours, depending on the base colour.
func Overlay(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.NormalisedRGBAf(c)
		m, n, o, p := utils.NormalisedRGBAf(d)

		r := (i / 255) * (i + ((2*m)/255)*(255-i))
		g := (j / 255) * (j + ((2*n)/255)*(255-j))
		b := (k / 255) * (k + ((2*o)/255)*(255-k))
		a := p + l*(1-p)

		return color.NRGBA{
			uint8(utils.Truncatef(r)),
			uint8(utils.Truncatef(g)),
			uint8(utils.Truncatef(b)),
			uint8(utils.Truncatef(a * 255)),
		}
	})
}