Exemple #1
0
func Auto(img image.Image, ch Channel) image.Image {
	var lightest, darkest float64
	lightest = 0.0
	darkest = 1.0

	utils.EachColor(img, func(c color.Color) {
		v := ch.Get(c)

		if v > lightest {
			lightest = v
		}
		if v < darkest {
			darkest = v
		}
	})

	// Use linear stretching algorithm
	//   v = (v - inLow) * ((outUp - outLow) / (inUp - inLow)) + outLow
	return utils.MapColor(img, func(c color.Color) color.Color {
		v := ch.Get(c)
		v = linearScale(v, darkest, lightest)

		return ch.Set(c, v)
	})
}
Exemple #2
0
// Fade changes the opacity of the Image given by the amount given. The
// resulting opacity is the product of the image's opacity and the amount, so a
// value of 1 has no effect whilst a value of 0 makes the image fully
// transparent.
func Fade(img image.Image, amount float64) image.Image {
	f := func(c color.Color) color.Color {
		r, g, b, a := utils.NormalisedRGBA(c)

		return color.NRGBA{
			uint8(float64(r)),
			uint8(float64(g)),
			uint8(float64(b)),
			uint8(float64(a) * amount),
		}
	}

	return utils.MapColor(img, f)
}
Exemple #3
0
// Adjusts the gamma of the Image by the given value. A value less than 1.0
// darkens the image, whilst a gamma of greater than 1.0 lightens an image.
func Adjust(img image.Image, value float64) image.Image {
	return utils.MapColor(img, AdjustC(value))
}
Exemple #4
0
// Sigmoidal adjusts the contrast in a non-linear way. Factor sets how much to
// increase the contrast, midpoint sets where midtones fall in the resultant
// image.
func Sigmoidal(img image.Image, factor, midpoint float64) image.Image {
	return utils.MapColor(img, SigmoidalC(factor, midpoint))
}
Exemple #5
0
func SetWhite(img image.Image, ch Channel, lightest float64) image.Image {
	return utils.MapColor(img, SetWhiteC(ch, lightest))
}
Exemple #6
0
func SetBlack(img image.Image, ch Channel, darkest float64) image.Image {
	return utils.MapColor(img, SetBlackC(ch, darkest))
}
Exemple #7
0
func SetCurve(img image.Image, ch Channel, curve *Curve) image.Image {
	return utils.MapColor(img, SetCurveC(ch, curve))
}