浏览代码

Invert hue adjustment direction

Inverts the direction in which the hue is rotated to bring the function in line with the HSL filters in GIMP, Krita and Blender.
StruffelProductions 4 年之前
父节点
当前提交
0d8eac9584
共有 6 个文件被更改,包括 9 次插入9 次删除
  1. 1 1
      adjust.go
  2. 8 8
      adjust_test.go
  3. 二进制
      testdata/out_hue_m120.png
  4. 二进制
      testdata/out_hue_m60.png
  5. 二进制
      testdata/out_hue_p120.png
  6. 二进制
      testdata/out_hue_p60.png

+ 1 - 1
adjust.go

@@ -95,7 +95,7 @@ func AdjustHue(img image.Image, shift float64) *image.NRGBA {
 	}
 
 	shift = math.Min(math.Max(shift, -180), 180)
-	summand := shift / -360
+	summand := shift / 360
 
 	return AdjustFunc(img, func(c color.NRGBA) color.NRGBA {
 		h, s, l := rgbToHSL(c.R, c.G, c.B)

+ 8 - 8
adjust_test.go

@@ -255,7 +255,7 @@ func TestAdjustHue(t *testing.T) {
 		want *image.NRGBA
 	}{
 		{
-			"AdjustHue 3x3 10",
+			"AdjustHue 3x3 -10",
 			&image.NRGBA{
 				Rect:   image.Rect(-1, -1, 2, 2),
 				Stride: 3 * 4,
@@ -265,7 +265,7 @@ func TestAdjustHue(t *testing.T) {
 					0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
 				},
 			},
-			10,
+			-10,
 			&image.NRGBA{
 				Rect:   image.Rect(0, 0, 3, 3),
 				Stride: 3 * 4,
@@ -277,7 +277,7 @@ func TestAdjustHue(t *testing.T) {
 			},
 		},
 		{
-			"AdjustHue 3x3 180",
+			"AdjustHue 3x3 -180",
 			&image.NRGBA{
 				Rect:   image.Rect(-1, -1, 2, 2),
 				Stride: 3 * 4,
@@ -287,7 +287,7 @@ func TestAdjustHue(t *testing.T) {
 					0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
 				},
 			},
-			180,
+			-180,
 			&image.NRGBA{
 				Rect:   image.Rect(0, 0, 3, 3),
 				Stride: 3 * 4,
@@ -299,7 +299,7 @@ func TestAdjustHue(t *testing.T) {
 			},
 		},
 		{
-			"AdjustHue 3x3 -10",
+			"AdjustHue 3x3 10",
 			&image.NRGBA{
 				Rect:   image.Rect(-1, -1, 2, 2),
 				Stride: 3 * 4,
@@ -309,7 +309,7 @@ func TestAdjustHue(t *testing.T) {
 					0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
 				},
 			},
-			-10,
+			10,
 			&image.NRGBA{
 				Rect:   image.Rect(0, 0, 3, 3),
 				Stride: 3 * 4,
@@ -321,7 +321,7 @@ func TestAdjustHue(t *testing.T) {
 			},
 		},
 		{
-			"AdjustHue 3x3 -180",
+			"AdjustHue 3x3 180",
 			&image.NRGBA{
 				Rect:   image.Rect(-1, -1, 2, 2),
 				Stride: 3 * 4,
@@ -331,7 +331,7 @@ func TestAdjustHue(t *testing.T) {
 					0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
 				},
 			},
-			-180,
+			180,
 			&image.NRGBA{
 				Rect:   image.Rect(0, 0, 3, 3),
 				Stride: 3 * 4,

二进制
testdata/out_hue_m120.png


二进制
testdata/out_hue_m60.png


二进制
testdata/out_hue_p120.png


二进制
testdata/out_hue_p60.png