From ce60f44490c0c8e06c756f9ef07aba86ce7d8020 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 25 Oct 2018 02:11:54 +0900 Subject: [PATCH] graphics: Add (*mipmap).original() --- graphicscontext.go | 2 +- image.go | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/graphicscontext.go b/graphicscontext.go index 802a2896d..18a12d1a3 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -152,7 +152,7 @@ func (c *graphicsContext) needsRestoring() (bool, error) { if web.IsBrowser() { return c.invalidated, nil } - return c.offscreen.mipmap.level(0).IsInvalidated() + return c.offscreen.mipmap.original().IsInvalidated() } func (c *graphicsContext) restoreIfNeeded() error { diff --git a/image.go b/image.go index b1e6bfdb3..ee87236fb 100644 --- a/image.go +++ b/image.go @@ -45,6 +45,10 @@ func newMipmap(s *shareable.Image) *mipmap { } } +func (m *mipmap) original() *shareable.Image { + return m.imgs[0] +} + func (m *mipmap) level(i int) *shareable.Image { w, h := m.imgs[len(m.imgs) - 1].Size() for len(m.imgs) < i+1 { @@ -117,7 +121,7 @@ func (i *Image) copyCheck() { // Size returns the size of the image. func (i *Image) Size() (width, height int) { - return i.mipmap.level(0).Size() + return i.mipmap.original().Size() } func (i *Image) isDisposed() bool { @@ -155,7 +159,7 @@ func (i *Image) Fill(clr color.Color) error { func (i *Image) fill(r, g, b, a uint8) { if r == 0 && g == 0 && b == 0 && a == 0 { - i.mipmap.level(0).ReplacePixels(nil) + i.mipmap.original().ReplacePixels(nil) i.disposeMipmaps() return } @@ -363,7 +367,7 @@ func (i *Image) drawImage(img *Image, options *DrawImageOptions) { if colorm.ScaleOnly() { colorm = nil } - i.mipmap.level(0).DrawImage(src, vs, is, colorm, mode, filter) + i.mipmap.original().DrawImage(src, vs, is, colorm, mode, filter) } i.disposeMipmaps() } @@ -439,11 +443,11 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o } vs := []float32{} - src := img.mipmap.level(0) + src := img.mipmap.original() for _, v := range vertices { vs = append(vs, src.Vertex(float32(v.DstX), float32(v.DstY), v.SrcX, v.SrcY, v.ColorR, v.ColorG, v.ColorB, v.ColorA)...) } - i.mipmap.level(0).DrawImage(img.mipmap.level(0), vs, indices, options.ColorM.impl, mode, filter) + i.mipmap.original().DrawImage(img.mipmap.original(), vs, indices, options.ColorM.impl, mode, filter) } // Bounds returns the bounds of the image. @@ -471,7 +475,7 @@ func (i *Image) At(x, y int) color.Color { if i.isDisposed() { return color.RGBA{} } - return i.mipmap.level(0).At(x, y) + return i.mipmap.original().At(x, y) } // Dispose disposes the image data. After disposing, most of image functions do nothing and returns meaningless values. @@ -507,7 +511,7 @@ func (i *Image) ReplacePixels(p []byte) error { if i.isDisposed() { return nil } - i.mipmap.level(0).ReplacePixels(p) + i.mipmap.original().ReplacePixels(p) i.disposeMipmaps() return nil }