示例#1
0
文件: levels.go 项目: surma-dump/img
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)
	})
}
示例#2
0
文件: blend.go 项目: surma-dump/img
// 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)
}
示例#3
0
文件: gamma.go 项目: surma-dump/img
// 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))
}
示例#4
0
文件: adjust.go 项目: surma-dump/img
// 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))
}
示例#5
0
文件: levels.go 项目: surma-dump/img
func SetWhite(img image.Image, ch Channel, lightest float64) image.Image {
	return utils.MapColor(img, SetWhiteC(ch, lightest))
}
示例#6
0
文件: levels.go 项目: surma-dump/img
func SetBlack(img image.Image, ch Channel, darkest float64) image.Image {
	return utils.MapColor(img, SetBlackC(ch, darkest))
}
示例#7
0
文件: levels.go 项目: surma-dump/img
func SetCurve(img image.Image, ch Channel, curve *Curve) image.Image {
	return utils.MapColor(img, SetCurveC(ch, curve))
}