MCPcopy
hub / github.com/anthonynsimon/bild / RGBAImageApproxEqual

Function RGBAImageApproxEqual

util/util.go:107–124  ·  view source on GitHub ↗

RGBAImageApproxEqual returns true if all pixel channel values in images a and b differ by at most the given tolerance, or false otherwise.

(a, b *image.RGBA, tolerance int)

Source from the content-addressed store, hash-verified

105// RGBAImageApproxEqual returns true if all pixel channel values in images a and b
106// differ by at most the given tolerance, or false otherwise.
107func RGBAImageApproxEqual(a, b *image.RGBA, tolerance int) bool {
108 if !a.Rect.Eq(b.Rect) {
109 return false
110 }
111
112 for y := 0; y < a.Bounds().Dy(); y++ {
113 for x := 0; x < a.Bounds().Dx(); x++ {
114 pos := y*a.Stride + x*4
115 for c := 0; c < 4; c++ {
116 d := int(a.Pix[pos+c]) - int(b.Pix[pos+c])
117 if d < -tolerance || d > tolerance {
118 return false
119 }
120 }
121 }
122 }
123 return true
124}

Callers 4

TestUnsharpMaskFunction · 0.92
TestGaussianBlurFunction · 0.92
TestRotateFunction · 0.92
RGBAImageEqualFunction · 0.85

Calls

no outgoing calls

Tested by 3

TestUnsharpMaskFunction · 0.74
TestGaussianBlurFunction · 0.74
TestRotateFunction · 0.74