Skip to content

Commit

Permalink
helpers tests
Browse files Browse the repository at this point in the history
  • Loading branch information
disintegration committed Dec 6, 2014
1 parent 56d1f5a commit 9f29595
Show file tree
Hide file tree
Showing 14 changed files with 890 additions and 733 deletions.
30 changes: 23 additions & 7 deletions adjust.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@ import (
"math"
)

func applyColorMapping(img image.Image, fn func(c color.NRGBA) color.NRGBA) *image.NRGBA {
// AdjustFunc applies the fn function to each pixel of the img image and returns the adjusted image.
//
// Example:
//
// dstImage = imaging.AdjustFunc(
// srcImage,
// func(c color.NRGBA) color.NRGBA {
// // shift the red channel by 16
// r := int(c.R) + 16
// if r > 255 {
// r = 255
// }
// return color.NRGBA{uint8(r), c.G, c.B, c.A}
// }
// )
//
func AdjustFunc(img image.Image, fn func(c color.NRGBA) color.NRGBA) *image.NRGBA {
src := toNRGBA(img)
width := src.Bounds().Max.X
height := src.Bounds().Max.Y
Expand Down Expand Up @@ -56,7 +72,7 @@ func AdjustGamma(img image.Image, gamma float64) *image.NRGBA {
return color.NRGBA{lut[c.R], lut[c.G], lut[c.B], c.A}
}

return applyColorMapping(img, fn)
return AdjustFunc(img, fn)
}

func sigmoid(a, b, x float64) float64 {
Expand Down Expand Up @@ -106,7 +122,7 @@ func AdjustSigmoid(img image.Image, midpoint, factor float64) *image.NRGBA {
return color.NRGBA{lut[c.R], lut[c.G], lut[c.B], c.A}
}

return applyColorMapping(img, fn)
return AdjustFunc(img, fn)
}

// AdjustContrast changes the contrast of the image using the percentage parameter and returns the adjusted image.
Expand Down Expand Up @@ -137,7 +153,7 @@ func AdjustContrast(img image.Image, percentage float64) *image.NRGBA {
return color.NRGBA{lut[c.R], lut[c.G], lut[c.B], c.A}
}

return applyColorMapping(img, fn)
return AdjustFunc(img, fn)
}

// AdjustBrightness changes the brightness of the image using the percentage parameter and returns the adjusted image.
Expand All @@ -162,7 +178,7 @@ func AdjustBrightness(img image.Image, percentage float64) *image.NRGBA {
return color.NRGBA{lut[c.R], lut[c.G], lut[c.B], c.A}
}

return applyColorMapping(img, fn)
return AdjustFunc(img, fn)
}

// Grayscale produces grayscale version of the image.
Expand All @@ -172,13 +188,13 @@ func Grayscale(img image.Image) *image.NRGBA {
y := uint8(f + 0.5)
return color.NRGBA{y, y, y, c.A}
}
return applyColorMapping(img, fn)
return AdjustFunc(img, fn)
}

// Invert produces inverted (negated) version of the image.
func Invert(img image.Image) *image.NRGBA {
fn := func(c color.NRGBA) color.NRGBA {
return color.NRGBA{255 - c.R, 255 - c.G, 255 - c.B, c.A}
}
return applyColorMapping(img, fn)
return AdjustFunc(img, fn)
}
194 changes: 0 additions & 194 deletions clone.go

This file was deleted.

36 changes: 0 additions & 36 deletions crop.go

This file was deleted.

60 changes: 0 additions & 60 deletions doc.go

This file was deleted.

Loading

0 comments on commit 9f29595

Please sign in to comment.