diff options
Diffstat (limited to 'src/image/color/ycbcr_test.go')
-rw-r--r-- | src/image/color/ycbcr_test.go | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/image/color/ycbcr_test.go b/src/image/color/ycbcr_test.go index 92a0e6ff1e..94c23dd9ea 100644 --- a/src/image/color/ycbcr_test.go +++ b/src/image/color/ycbcr_test.go @@ -15,9 +15,9 @@ func delta(x, y uint8) uint8 { return y - x } -// Test that a subset of RGB space can be converted to YCbCr and back to within -// 1/256 tolerance. -func TestRoundtrip(t *testing.T) { +// TestYCbCrRoundtrip tests that a subset of RGB space can be converted to YCbCr +// and back to within 1/256 tolerance. +func TestYCbCrRoundtrip(t *testing.T) { for r := 0; r < 255; r += 7 { for g := 0; g < 255; g += 5 { for b := 0; b < 255; b += 3 { @@ -31,3 +31,20 @@ func TestRoundtrip(t *testing.T) { } } } + +// TestCMYKRoundtrip tests that a subset of RGB space can be converted to CMYK +// and back to within 1/256 tolerance. +func TestCMYKRoundtrip(t *testing.T) { + for r := 0; r < 255; r += 7 { + for g := 0; g < 255; g += 5 { + for b := 0; b < 255; b += 3 { + r0, g0, b0 := uint8(r), uint8(g), uint8(b) + c, m, y, k := RGBToCMYK(r0, g0, b0) + r1, g1, b1 := CMYKToRGB(c, m, y, k) + if delta(r0, r1) > 1 || delta(g0, g1) > 1 || delta(b0, b1) > 1 { + t.Fatalf("r0, g0, b0 = %d, %d, %d r1, g1, b1 = %d, %d, %d", r0, g0, b0, r1, g1, b1) + } + } + } + } +} |