Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function "AdjustHues" #130

Merged
merged 10 commits into from
Dec 18, 2020
Merged
Prev Previous commit
Next Next commit
Rename "AdjustHues" to "AdjustHue"
Renames the function "AdjustHues" to "AdjustHue" (along with the tests, documentation and sample files).
  • Loading branch information
struffel committed Nov 22, 2020
commit 84be08e61274361ee54f73dc1f36d4ce463ec49f
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ Original image | Saturation = 30
### Hue adjustment

```go
dstImage := imaging.AdjustHues(srcImage, 20)
dstImage := imaging.AdjustHue(srcImage, 20)
```

Original image | Hue = 60 | Hue = -60
-----------------------------------|----------------------------------------------|---------------------------------------------
![srcImage](testdata/flowers_small.png) | ![dstImage](testdata/out_hues_p60.png) | ![dstImage](testdata/out_hues_m60.png)
![srcImage](testdata/flowers_small.png) | ![dstImage](testdata/out_hue_p60.png) | ![dstImage](testdata/out_hue_m60.png)

## FAQ

Expand Down
8 changes: 4 additions & 4 deletions adjust.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ func AdjustSaturation(img image.Image, percentage float64) *image.NRGBA {
})
}

// AdjustHues changes the hue of the image using the shift parameter (measured in degrees) and returns the adjusted image.
// AdjustHue changes the hue of the image using the shift parameter (measured in degrees) and returns the adjusted image.
// The shift must be in the range (-180, 180).
// The shift = 0 gives the original image.
// The shift = 180 (or -180) corresponds to a 180° degree rotation of the color wheel and thus gives the image with its hue inverted for each pixel.
//
// Examples:
// dstImage = imaging.AdjustHues(srcImage, 90) // Shift Hue by 90°.
// dstImage = imaging.AdjustHues(srcImage, -30) // Shift Hue by -30°.
// dstImage = imaging.AdjustHue(srcImage, 90) // Shift Hue by 90°.
// dstImage = imaging.AdjustHue(srcImage, -30) // Shift Hue by -30°.
//
func AdjustHues(img image.Image, shift float64) *image.NRGBA {
func AdjustHue(img image.Image, shift float64) *image.NRGBA {
if shift == 0 {
return Clone(img)
}
Expand Down
30 changes: 15 additions & 15 deletions adjust_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ func BenchmarkAdjustSaturation(b *testing.B) {
}
}

func TestAdjustHues(t *testing.T) {
func TestAdjustHue(t *testing.T) {
testCases := []struct {
name string
src image.Image
p float64
want *image.NRGBA
}{
{
"AdjustHues 3x3 10",
"AdjustHue 3x3 10",
&image.NRGBA{
Rect: image.Rect(-1, -1, 2, 2),
Stride: 3 * 4,
Expand All @@ -277,7 +277,7 @@ func TestAdjustHues(t *testing.T) {
},
},
{
"AdjustHues 3x3 180",
"AdjustHue 3x3 180",
&image.NRGBA{
Rect: image.Rect(-1, -1, 2, 2),
Stride: 3 * 4,
Expand All @@ -299,7 +299,7 @@ func TestAdjustHues(t *testing.T) {
},
},
{
"AdjustHues 3x3 -10",
"AdjustHue 3x3 -10",
&image.NRGBA{
Rect: image.Rect(-1, -1, 2, 2),
Stride: 3 * 4,
Expand All @@ -321,7 +321,7 @@ func TestAdjustHues(t *testing.T) {
},
},
{
"AdjustHues 3x3 -180",
"AdjustHue 3x3 -180",
&image.NRGBA{
Rect: image.Rect(-1, -1, 2, 2),
Stride: 3 * 4,
Expand All @@ -343,7 +343,7 @@ func TestAdjustHues(t *testing.T) {
},
},
{
"AdjustHues 3x3 0",
"AdjustHue 3x3 0",
&image.NRGBA{
Rect: image.Rect(-1, -1, 2, 2),
Stride: 3 * 4,
Expand All @@ -367,22 +367,22 @@ func TestAdjustHues(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := AdjustHues(tc.src, tc.p)
got := AdjustHue(tc.src, tc.p)
if !compareNRGBA(got, tc.want, 0) {
t.Fatalf("got result %#v want %#v", got, tc.want)
}
})
}
}

func TestAdjustHuesGolden(t *testing.T) {
func TestAdjustHueGolden(t *testing.T) {
for name, p := range map[string]float64{
"out_hues_m120.png": -120,
"out_hues_m60.png": -60,
"out_hues_p60.png": 60,
"out_hues_p120.png": 120,
"out_hue_m120.png": -120,
"out_hue_m60.png": -60,
"out_hue_p60.png": 60,
"out_hue_p120.png": 120,
} {
got := AdjustHues(testdataFlowersSmallPNG, p)
got := AdjustHue(testdataFlowersSmallPNG, p)
want, err := Open("testdata/" + name)
if err != nil {
t.Fatalf("failed to open image: %v", err)
Expand All @@ -393,10 +393,10 @@ func TestAdjustHuesGolden(t *testing.T) {
}
}

func BenchmarkAdjustHues(b *testing.B) {
func BenchmarkAdjustHue(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AdjustHues(testdataBranchesJPG, 10)
AdjustHue(testdataBranchesJPG, 10)
}
}

Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes