git.lucas.co / go_mono
git clone https://git.lucas.co/go_mono.git

commit261d2777537237975bcb057e6209a6109a002288
parent5d4df673f7
authorRuss Cox <rsc@golang.org>
date2025-09-29 09:50
draw: accept slightly different JPEG decodings

Go 1.26 changed the image/jpeg decoder.
Accept the new decoder's output as well as the old one.

Change-Id: I8d92508a4d1d6dc47849b293b538a10271d0ebbd
Reviewed-on: https://go-review.googlesource.com/c/image/+/707715
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

 draw/scale_test.go | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/draw/scale_test.go b/draw/scale_test.go
index bd6ff36..0c6ce94 100644
--- a/draw/scale_test.go
+++ b/draw/scale_test.go
@@ -13,7 +13,6 @@ import (
 	"image/png"
 	"math/rand"
 	"os"
-	"reflect"
 	"testing"
 
 	"golang.org/x/image/math/f64"
@@ -109,13 +108,29 @@ func testInterp(t *testing.T, w int, h int, direction, prefix, suffix string) {
 			Draw(want, b, wantRaw, b.Min, Src)
 		}
 
-		if !reflect.DeepEqual(got, want) {
+		// Use imageAlmostEqual so that we accept both
+		// the Go 1.26 image/jpeg decoder and the
+		// pre-Go1.26 image/jpeg decoder.
+		if !imageAlmostEqual(got, want) {
 			t.Errorf("%s: actual image differs from golden image", goldenFilename)
 			continue
 		}
 	}
 }
 
+func imageAlmostEqual(got, want *image.RGBA) bool {
+	if got.Stride != want.Stride || got.Rect != want.Rect || len(got.Pix) != len(want.Pix) {
+		return false
+	}
+	for i := range got.Pix {
+		d := int(got.Pix[i]) - int(want.Pix[i])
+		if d < -2 || 2 < d {
+			return false
+		}
+	}
+	return true
+}
+
 func TestScaleDown(t *testing.T) { testInterp(t, 100, 100, "down", "go-turns-two", "-280x360.jpeg") }
 func TestScaleUp(t *testing.T)   { testInterp(t, 75, 100, "up", "go-turns-two", "-14x18.png") }
 func TestTformSrc(t *testing.T)  { testInterp(t, 100, 100, "rotate", "go-turns-two", "-14x18.png") }