Esempio n. 1
0
func runPxl(cmd *Command, args []string) {
	i := utils.ReadStdin()

	triangle := pixelate.BOTH
	if pxlLeft {
		triangle = pixelate.LEFT
	}
	if pxlRight {
		triangle = pixelate.RIGHT
	}

	if pxlRows > 0 && pxlCols > 0 {
		pxlSize = utils.SizeForRowsAndCols(i, pxlRows, pxlCols)
	} else if pxlRows > 0 {
		pxlSize = utils.SizeForRows(i, pxlRows)
	} else if pxlCols > 0 {
		pxlSize = utils.SizeForCols(i, pxlCols)
	}

	if pxlAlias {
		i = pixelate.AliasedPxl(i, pxlSize, triangle)
	} else {
		i = pixelate.Pxl(i, pxlSize, triangle)
	}

	utils.WriteStdout(i)
}
Esempio n. 2
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)
}
Esempio n. 3
0
func runVxl(cmd *Command, args []string) {
	i := utils.ReadStdin()

	if vxlRows > 0 {
		vxlHeight = utils.SizeForRows(i, vxlRows).H
	}

	i = pixelate.Vxl(i, vxlHeight, vxlFlip, vxlTop, vxlLeft, vxlRight)
	utils.WriteStdout(i)
}
Esempio n. 4
0
func runHxl(cmd *Command, args []string) {
	i := utils.ReadStdin()

	if hxlCols > 0 {
		hxlWidth = utils.SizeForCols(i, hxlCols).W
	}

	i = pixelate.Hxl(i, hxlWidth)
	utils.WriteStdout(i)
}
Esempio n. 5
0
func runGamma(cmd *Command, args []string) {
	i := utils.ReadStdin()

	if gammaAuto {
		i = gamma.Auto(i)
	} else {
		i = gamma.Adjust(i, gammaBy)
	}
	utils.WriteStdout(i)
}
Esempio n. 6
0
func runSharpen(cmd *Command, args []string) {
	i := utils.ReadStdin()

	if sharpenUnsharp {
		i = sharpen.UnsharpMask(i, sharpenRadius, sharpenSigma, sharpenAmount, sharpenThreshold)
	} else {
		i = sharpen.Sharpen(i, sharpenRadius, sharpenSigma)
	}

	utils.WriteStdout(i)
}
Esempio n. 7
0
func runContrast(cmd *Command, args []string) {
	i := utils.ReadStdin()

	if contrastLinear {
		i = contrast.Adjust(i, contrastRatio)
	} else {
		i = contrast.Sigmoidal(i, contrastRatio, contrastSigmoidal)
	}

	utils.WriteStdout(i)
}
Esempio n. 8
0
func runTint(cmd *Command, args []string) {
	i := utils.ReadStdin()

	tintColor := color.NRGBA{
		uint8(tintWith.R),
		uint8(tintWith.G),
		uint8(tintWith.B),
		uint8(tintWith.A),
	}
	i = tint.Tint(i, tintColor)

	utils.WriteStdout(i)
}
Esempio n. 9
0
func runShuffle(cmd *Command, args []string) {
	i := utils.ReadStdin()

	if shuffleVertical && !shuffleHorizontal {
		i = shuffle.Vertically(i)
	} else if shuffleHorizontal && !shuffleVertical {
		i = shuffle.Horizontally(i)
	} else {
		i = shuffle.Shuffle(i)
	}

	utils.WriteStdout(i)
}
Esempio n. 10
0
func runPixelate(cmd *Command, args []string) {
	i := utils.ReadStdin()

	if pixelateRows > 0 && pixelateCols > 0 {
		pixelateSize = utils.SizeForRowsAndCols(i, pixelateRows, pixelateCols)
	} else if pixelateRows > 0 {
		pixelateSize = utils.SizeForRows(i, pixelateRows)
	} else if pixelateCols > 0 {
		pixelateSize = utils.SizeForCols(i, pixelateCols)
	}

	i = pixelate.Pixelate(i, pixelateSize)
	utils.WriteStdout(i)
}
Esempio n. 11
0
func runChannel(cmd *Command, args []string) {
	i := utils.ReadStdin()
	var adj utils.Adjuster

	if utils.FlagVisited("by", cmd.Flag) {
		adj = utils.Adder(channelBy)
	} else {
		adj = utils.Multiplier(channelRatio)
	}

	if !(channelRed || channelGreen || channelBlue || channelHue ||
		channelSaturation || channelLightness || channelBrightness || channelAlpha) {
		channelRed = true
		channelGreen = true
		channelBlue = true
	}

	if channelRed {
		i = channel.Red(i, adj)
	}
	if channelGreen {
		i = channel.Green(i, adj)
	}
	if channelBlue {
		i = channel.Blue(i, adj)
	}

	if channelHue {
		i = channel.Hue(i, adj)
	}
	if channelSaturation {
		i = channel.Saturation(i, adj)
	}
	if channelLightness {
		i = channel.Lightness(i, adj)
	}
	if channelBrightness {
		i = channel.Brightness(i, adj)
	}

	if channelAlpha {
		i = channel.Alpha(i, adj)
	}

	utils.WriteStdout(i)
}
Esempio n. 12
0
func runBlur(cmd *Command, args []string) {
	if _, ok := styleNames[blurStyle]; !ok {
		utils.Warn("--style must be one of 'clamp', 'ignore' or 'wrap'")
		os.Exit(2)
	}

	style, _ := styleNames[blurStyle]

	i := utils.ReadStdin()

	if blurBox {
		i = blur.Box(i, blurRadius, style)
	} else {
		i = blur.Gaussian(i, blurRadius, blurGaussian, style)
	}

	utils.WriteStdout(i)
}
Esempio n. 13
0
func runLevels(cmd *Command, args []string) {
	i := utils.ReadStdin()

	if !levelsRed && !levelsGreen && !levelsBlue {
		levelsRed = true
		levelsGreen = true
		levelsBlue = true
	}

	if levelsRed {
		i = runLevelsOnChannel(cmd, args, i, levels.RedChannel)
	}

	if levelsGreen {
		i = runLevelsOnChannel(cmd, args, i, levels.GreenChannel)
	}

	if levelsBlue {
		i = runLevelsOnChannel(cmd, args, i, levels.BlueChannel)
	}

	utils.WriteStdout(i)
}
Esempio n. 14
0
func runBlend(cmd *Command, args []string) {
	if blendModes {
		printModes()
	}

	a := utils.ReadStdin()

	path := args[0]
	file, _ := os.Open(path)
	defer file.Close()
	b, _, _ := image.Decode(file)
	var f (func(a, b image.Image) image.Image)

	b = blend.Fade(b, blendOpacity)

	if blendFit {
		ab := a.Bounds()
		bb := b.Bounds()

		// Need to work this out better, see
		// http://www.codinghorror.com/blog/2007/07/better-image-resizing.html
		if bb.Dx() < ab.Dx() || bb.Dy() < ab.Dy() {
			// b is going to get BIGGER
			b = resize.Resize(uint(ab.Dx()), uint(ab.Dy()), b, resize.Bilinear)
		} else {
			// b is going to get SMALLER
			b = resize.Resize(uint(ab.Dx()), uint(ab.Dy()), b, resize.Bicubic)
		}
	}

	if blendNormal {
		f = blend.Normal
	} else if blendDissolve {
		f = blend.Dissolve

	} else if blendDarken {
		f = blend.Darken
	} else if blendMultiply {
		f = blend.Multiply
	} else if blendBurn {
		f = blend.Burn
	} else if blendLinearBurn {
		f = blend.LinearBurn
	} else if blendDarker {
		f = blend.Darker

	} else if blendLighten {
		f = blend.Lighten
	} else if blendScreen {
		f = blend.Screen
	} else if blendDodge {
		f = blend.Dodge
	} else if blendLinearDodge {
		f = blend.LinearDodge
	} else if blendLighter {
		f = blend.Lighter

	} else if blendOverlay {
		f = blend.Overlay
	} else if blendSoftLight {
		f = blend.SoftLight
	} else if blendHardLight {
		f = blend.HardLight
	} else if blendVividLight {
		f = blend.VividLight
	} else if blendLinearLight {
		f = blend.LinearLight
	} else if blendPinLight {
		f = blend.PinLight
	} else if blendHardMix {
		f = blend.HardMix

	} else if blendDifference {
		f = blend.Difference
	} else if blendExclusion {
		f = blend.Exclusion
	} else if blendAddition {
		f = blend.Addition
	} else if blendSubtraction {
		f = blend.Subtraction

	} else if blendHue {
		f = blend.Hue
	} else if blendSaturation {
		f = blend.Saturation
	} else if blendColor {
		f = blend.Color
	} else if blendLuminosity {
		f = blend.Luminosity

	} else {
		f = blend.Normal
	}

	utils.WriteStdout(f(a, b))
}