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)
| 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. |
| 107 | func 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 | } |
no outgoing calls