Test rework, bugfixes and more tests

This commit is contained in:
nxshock 2017-06-26 23:12:48 +05:00
parent 1cf1415b29
commit 28d09be6b5
22 changed files with 240 additions and 45 deletions

View file

@ -10,6 +10,7 @@ import (
type comparator func(color.Color, color.Color) float64
// CmpEuclidean returns Euclidean difference of two colors.
//
// https://en.wikipedia.org/wiki/Color_difference#Euclidean
func CmpEuclidean(color1 color.Color, color2 color.Color) float64 {
const maxDiff = 113509.94967402637 // Difference between black and white colors
@ -29,8 +30,8 @@ func CmpRGBComponents(color1 color.Color, color2 color.Color) float64 {
r1, g1, b1, _ := color1.RGBA()
r2, g2, b2, _ := color2.RGBA()
r1, g1, b1 = r1/256, g1/256, b1/256
r2, g2, b2 = r2/256, g2/256, b2/256
r1, g1, b1 = r1>>8, g1>>8, b1>>8
r2, g2, b2 = r2>>8, g2>>8, b2>>8
return float64((max(r1, r2)-min(r1, r2))+
(max(g1, g2)-min(g1, g2))+
@ -38,15 +39,13 @@ func CmpRGBComponents(color1 color.Color, color2 color.Color) float64 {
}
// CmpCIE76 returns difference of two colors defined in CIE76 standart.
//
// https://en.wikipedia.org/wiki/Color_difference#CIE76
func CmpCIE76(color1 color.Color, color2 color.Color) float64 {
const maxDiff = 149.95514755026548 // Difference between blue and white colors
const maxDiff = 149.95514755 // Difference between blue and white colors
r1, g1, b1, _ := color1.RGBA()
r2, g2, b2, _ := color2.RGBA()
cl1, ca1, cb1 := xyztoLAB(rgbtoXYZ(r1/256, g1/256, b1/256))
cl2, ca2, cb2 := xyztoLAB(rgbtoXYZ(r2/256, g2/256, b2/256))
cl1, ca1, cb1 := colorToLAB(color1)
cl2, ca2, cb2 := colorToLAB(color2)
return math.Sqrt(distance(cl2, cl1)+distance(ca2, ca1)+distance(cb2, cb1)) / maxDiff
}
@ -55,6 +54,7 @@ func distance(x, y float64) float64 {
return (x - y) * (x - y)
}
// min is minimum of two uint32
func min(a, b uint32) uint32 {
if a < b {
return a
@ -62,6 +62,7 @@ func min(a, b uint32) uint32 {
return b
}
// max is maximum of two uint32
func max(a, b uint32) uint32 {
if a > b {
return a