From bcf3ff77ff1575991d34e54c78144232a8b08c24 Mon Sep 17 00:00:00 2001 From: Pierre Curto Date: Wed, 10 Nov 2021 15:49:14 +0100 Subject: [PATCH] op/paint: remove unnecessary check in ImageOp Signed-off-by: Pierre Curto --- gpu/internal/driver/driver.go | 5 ++-- .../rendertest/refs/TestImageRGBA.png | Bin 0 -> 394 bytes gpu/internal/rendertest/render_test.go | 23 ++++++++++++++++++ gpu/internal/rendertest/util_test.go | 4 +++ op/paint/paint.go | 9 +++---- 5 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 gpu/internal/rendertest/refs/TestImageRGBA.png diff --git a/gpu/internal/driver/driver.go b/gpu/internal/driver/driver.go index 2f8ba7f9..69791443 100644 --- a/gpu/internal/driver/driver.go +++ b/gpu/internal/driver/driver.go @@ -229,8 +229,9 @@ func flipImageY(stride, height int, pixels []byte) { func UploadImage(t Texture, offset image.Point, img *image.RGBA) { var pixels []byte size := img.Bounds().Size() - start := img.PixOffset(0, 0) - end := img.PixOffset(size.X, size.Y-1) + min := img.Rect.Min + start := img.PixOffset(min.X, min.Y) + end := img.PixOffset(min.X+size.X, min.Y+size.Y-1) pixels = img.Pix[start:end] t.Upload(offset, size, pixels, img.Stride) } diff --git a/gpu/internal/rendertest/refs/TestImageRGBA.png b/gpu/internal/rendertest/refs/TestImageRGBA.png new file mode 100644 index 0000000000000000000000000000000000000000..0c78d3ba724acbaeea1bb32b6f22a6b4ce072cbc GIT binary patch literal 394 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7xzrU<~whaSW-L^X7^pFM|RPi(^y$ z`45?)Z+wdQ%*y#Qr4P&&e9XAu4D%6A1wV#DrVe3;ISh|j1k@WW7)OQBL*h3h1H=FS Yae+*KOB0?=1cot#r>mdKI;Vst0LTk$CIA2c literal 0 HcmV?d00001 diff --git a/gpu/internal/rendertest/render_test.go b/gpu/internal/rendertest/render_test.go index a8bc8367..b5bea43a 100644 --- a/gpu/internal/rendertest/render_test.go +++ b/gpu/internal/rendertest/render_test.go @@ -334,6 +334,29 @@ func TestZeroImage(t *testing.T) { } } +func TestImageRGBA(t *testing.T) { + run(t, func(o *op.Ops) { + w := newWindow(t, 10, 10) + + im := image.NewRGBA(image.Rect(0, 0, 5, 5)) + im.Set(3, 3, colornames.Black) + im.Set(4, 3, colornames.Black) + im.Set(3, 4, colornames.Black) + im.Set(4, 4, colornames.Black) + im = im.SubImage(image.Rect(2, 2, 5, 5)).(*image.RGBA) + paint.NewImageOp(im).Add(o) + paint.PaintOp{}.Add(o) + if err := w.Frame(o); err != nil { + t.Error(err) + } + }, func(r result) { + r.expect(1, 1, colornames.Black) + r.expect(2, 1, colornames.Black) + r.expect(1, 2, colornames.Black) + r.expect(2, 2, colornames.Black) + }) +} + // lerp calculates linear interpolation with color b and p. func lerp(a, b f32color.RGBA, p float32) f32color.RGBA { return f32color.RGBA{ diff --git a/gpu/internal/rendertest/util_test.go b/gpu/internal/rendertest/util_test.go index df8cfec3..b56188de 100644 --- a/gpu/internal/rendertest/util_test.go +++ b/gpu/internal/rendertest/util_test.go @@ -145,6 +145,10 @@ func verifyRef(t *testing.T, img *image.RGBA, frame int) (ok bool) { if frame != 0 { path = filepath.Join("refs", t.Name()+"_"+strconv.Itoa(frame)+".png") } + if *dumpImages { + saveImage(t, path, img) + return true + } b, err := ioutil.ReadFile(path) if err != nil { t.Error("could not open ref:", err) diff --git a/op/paint/paint.go b/op/paint/paint.go index 17145f54..1c992973 100644 --- a/op/paint/paint.go +++ b/op/paint/paint.go @@ -59,12 +59,9 @@ func NewImageOp(src image.Image) ImageOp { color: col, } case *image.RGBA: - bounds := src.Bounds() - if bounds.Min == (image.Point{}) && src.Stride == bounds.Dx()*4 { - return ImageOp{ - src: src, - handle: new(int), - } + return ImageOp{ + src: src, + handle: new(int), } }