Example #1
0
// Addition adds the blend colour to the base colour. (aka. Linear Dodge)
func Addition(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.NormalisedRGBA(c)
		m, n, o, p := utils.NormalisedRGBA(d)

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

		return color.NRGBA{uint8(r), uint8(g), uint8(b), uint8(a)}
	})
}
Example #2
0
func colorAlterer(f pixelAlterer) utils.Composable {
	return func(c color.Color) color.Color {
		r, g, b, a := utils.NormalisedRGBA(c)
		grey := uint8(f(r, g, b))

		return color.NRGBA{grey, grey, grey, uint8(a)}
	}
}
Example #3
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)
}
Example #4
0
// Subtraction subtracts the blend colour from the base colour.
func Subtraction(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.NormalisedRGBA(c)
		m, n, o, p := utils.NormalisedRGBA(d)

		r := utils.Truncate(i - m)
		g := utils.Truncate(j - n)
		b := utils.Truncate(k - o)

		if m > i {
			r = 0
		}
		if n > j {
			g = 0
		}
		if o > k {
			b = 0
		}

		a := p + l*(1-p)

		return color.NRGBA{uint8(r), uint8(g), uint8(b), uint8(a)}
	})
}
Example #5
0
// Auto calculates the mean values of an image, then applies a gamma adjustment
// so that the mean colour in the image has a value of half.
func Auto(img image.Image) image.Image {
	luma := greyscale.Luminosity(img)
	greys := []uint32{}

	b := luma.Bounds()
	for y := b.Min.Y; y < b.Max.Y; y++ {
		for x := b.Min.X; x < b.Max.X; x++ {
			g, _, _, _ := utils.NormalisedRGBA(luma.At(x, y))
			greys = append(greys, g)
		}
	}

	var averageGrey uint32 = 0
	for i := 0; i < len(greys); i++ {
		averageGrey += greys[i]
	}
	averageGrey /= uint32(len(greys))

	newGamma := 127.5 / float64(averageGrey)

	return Adjust(img, newGamma)
}
Example #6
0
func setAlpha(c color.Color, v float64) color.Color {
	r, g, b, _ := utils.NormalisedRGBA(c)
	v = utils.Truncatef(255 * v)

	return color.NRGBA{uint8(r), uint8(g), uint8(b), uint8(v)}
}
Example #7
0
func setBlue(c color.Color, v float64) color.Color {
	r, g, _, a := utils.NormalisedRGBA(c)
	v = utils.Truncatef(255 * v)

	return color.NRGBA{uint8(r), uint8(g), uint8(v), uint8(a)}
}
Example #8
0
func setGreen(c color.Color, v float64) color.Color {
	r, _, b, a := utils.NormalisedRGBA(c)
	v = utils.Truncatef(255 * v)

	return color.NRGBA{uint8(r), uint8(v), uint8(b), uint8(a)}
}
Example #9
0
func setRed(c color.Color, v float64) color.Color {
	_, g, b, a := utils.NormalisedRGBA(c)
	v = utils.Truncatef(255 * v)

	return color.NRGBA{uint8(v), uint8(g), uint8(b), uint8(a)}
}