github.com/zach-klippenstein/go@v0.0.0-20150108044943-fcfbeb3adf58/src/image/color/ycbcr_test.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package color 6 7 import ( 8 "testing" 9 ) 10 11 func delta(x, y uint8) uint8 { 12 if x >= y { 13 return x - y 14 } 15 return y - x 16 } 17 18 // Test that a subset of RGB space can be converted to YCbCr and back to within 19 // 1/256 tolerance. 20 func TestRoundtrip(t *testing.T) { 21 for r := 0; r < 255; r += 7 { 22 for g := 0; g < 255; g += 5 { 23 for b := 0; b < 255; b += 3 { 24 r0, g0, b0 := uint8(r), uint8(g), uint8(b) 25 y, cb, cr := RGBToYCbCr(r0, g0, b0) 26 r1, g1, b1 := YCbCrToRGB(y, cb, cr) 27 if delta(r0, r1) > 1 || delta(g0, g1) > 1 || delta(b0, b1) > 1 { 28 t.Fatalf("r0, g0, b0 = %d, %d, %d r1, g1, b1 = %d, %d, %d", r0, g0, b0, r1, g1, b1) 29 } 30 } 31 } 32 } 33 }