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) }) }
// 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) }
// 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)) }
// 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)) }
func SetWhite(img image.Image, ch Channel, lightest float64) image.Image { return utils.MapColor(img, SetWhiteC(ch, lightest)) }
func SetBlack(img image.Image, ch Channel, darkest float64) image.Image { return utils.MapColor(img, SetBlackC(ch, darkest)) }
func SetCurve(img image.Image, ch Channel, curve *Curve) image.Image { return utils.MapColor(img, SetCurveC(ch, curve)) }