Example #1
0
// Darken selects the darkest value for each pixels' colour channels.
func Darken(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.RatioRGBA(c)
		m, n, o, p := utils.RatioRGBA(d)

		r := utils.Minf(i, m)
		g := utils.Minf(j, n)
		b := utils.Minf(k, o)
		a := utils.Minf(l, p)

		return ratioNRGBA(r, g, b, a)
	})
}
Example #2
0
func hsiaModel(c color.Color) color.Color {
	if _, ok := c.(HSIA); ok {
		return c
	}

	r, g, b, a := utils.RatioRGBA(c)

	maxi := utils.Maxf(r, g, b)
	mini := utils.Minf(r, g, b)
	chroma := maxi - mini

	// Work out hue
	hdash := 0.0
	if chroma == 0 {
		hdash = 0
	} else if maxi == r {
		hdash = math.Mod((g-b)/chroma, 6)
	} else if maxi == g {
		hdash = (b-r)/chroma + 2.0
	} else if maxi == b {
		hdash = (r-g)/chroma + 4.0
	}

	hue := hdash * 60

	if chroma == 0 {
		hue = 0
	}

	// Work out intensity
	intensity := (r + g + b) / 3

	// Work out saturation
	saturation := 0.0
	if chroma != 0 {
		saturation = 1 - mini/intensity
	}

	// prefer positive hues
	if hue < 0 {
		hue += 360
	}

	return HSIA{hue, saturation, intensity, a}
}
Example #3
0
func hslaModel(c color.Color) color.Color {
	if _, ok := c.(HSLA); ok {
		return c
	}

	r, g, b, a := utils.RatioRGBA(c)

	maxi := utils.Maxf(r, g, b)
	mini := utils.Minf(r, g, b)
	chroma := maxi - mini

	// Work out hue
	hdash := 0.0
	if chroma == 0 {
		hdash = 0
	} else if maxi == r {
		hdash = math.Mod((g-b)/chroma, 6)
	} else if maxi == g {
		hdash = (b-r)/chroma + 2.0
	} else if maxi == b {
		hdash = (r-g)/chroma + 4.0
	}

	hue := hdash * 60

	if chroma == 0 {
		hue = 0
	}

	// Work out lightness
	lightness := 0.5 * (maxi + mini)

	// Work out saturation
	saturation := 0.0
	if chroma != 0 {
		saturation = chroma / (1 - math.Abs(2*lightness-1))
	}

	return HSLA{hue, saturation, lightness, a}
}
Example #4
0
func hsvaModel(c color.Color) color.Color {
	if _, ok := c.(HSVA); ok {
		return c
	}

	r, g, b, a := utils.RatioRGBA(c)

	maxi := utils.Maxf(r, g, b)
	mini := utils.Minf(r, g, b)
	chroma := maxi - mini

	// Work out hue
	hdash := 0.0
	if chroma == 0 {
		hdash = 0
	} else if maxi == r {
		hdash = math.Mod((g-b)/chroma, 6)
	} else if maxi == g {
		hdash = (b-r)/chroma + 2.0
	} else if maxi == b {
		hdash = (r-g)/chroma + 4.0
	}

	hue := hdash * 60

	if chroma == 0 {
		hue = 0
	}

	// Work out value
	value := maxi

	// Work out saturation
	saturation := 0.0
	if chroma != 0 {
		saturation = chroma / value
	}

	return HSVA{hue, saturation, value, a}
}