Example #1
0
func runGreyscale(cmd *Command, args []string) {
	i := utils.ReadStdin()

	if greyscaleAverage {
		i = greyscale.Average(i)
	} else if greyscaleLightness {
		i = greyscale.Lightness(i)
	} else if greyscaleLuminosity {
		i = greyscale.Luminosity(i)
	} else if greyscaleMaximal {
		i = greyscale.Maximal(i)
	} else if greyscaleMinimal {
		i = greyscale.Minimal(i)
	} else if greyscaleRed {
		i = greyscale.Red(i)
	} else if greyscaleGreen {
		i = greyscale.Green(i)
	} else if greyscaleBlue {
		i = greyscale.Blue(i)
	} else {
		i = greyscale.Photoshop(i)
	}

	utils.WriteStdout(i)
}
Example #2
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)
}