mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
graphics: Remove imageImpl.width/height
This commit is contained in:
parent
99b7e85d3d
commit
43e8349567
5
image.go
5
image.go
@ -144,7 +144,7 @@ type Image struct {
|
|||||||
//
|
//
|
||||||
// This function is concurrent-safe.
|
// This function is concurrent-safe.
|
||||||
func (i *Image) Size() (width, height int) {
|
func (i *Image) Size() (width, height int) {
|
||||||
return i.impl.width, i.impl.height
|
return i.impl.restorable.Size()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear resets the pixels of the image into 0.
|
// Clear resets the pixels of the image into 0.
|
||||||
@ -194,7 +194,8 @@ func (i *Image) DrawImage(image *Image, options *DrawImageOptions) error {
|
|||||||
//
|
//
|
||||||
// This function is concurrent-safe.
|
// This function is concurrent-safe.
|
||||||
func (i *Image) Bounds() image.Rectangle {
|
func (i *Image) Bounds() image.Rectangle {
|
||||||
return image.Rect(0, 0, i.impl.width, i.impl.height)
|
w, h := i.impl.restorable.Size()
|
||||||
|
return image.Rect(0, 0, w, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ColorModel returns the color model of the image.
|
// ColorModel returns the color model of the image.
|
||||||
|
20
imageimpl.go
20
imageimpl.go
@ -29,8 +29,6 @@ import (
|
|||||||
|
|
||||||
type imageImpl struct {
|
type imageImpl struct {
|
||||||
disposed bool
|
disposed bool
|
||||||
width int
|
|
||||||
height int
|
|
||||||
restorable *restorable.Image
|
restorable *restorable.Image
|
||||||
volatile bool
|
volatile bool
|
||||||
screen bool
|
screen bool
|
||||||
@ -43,8 +41,6 @@ func newImageImpl(width, height int, filter Filter, volatile bool) (*imageImpl,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
i := &imageImpl{
|
i := &imageImpl{
|
||||||
width: width,
|
|
||||||
height: height,
|
|
||||||
restorable: img,
|
restorable: img,
|
||||||
volatile: volatile,
|
volatile: volatile,
|
||||||
}
|
}
|
||||||
@ -74,8 +70,6 @@ func newImageImplFromImage(source image.Image, filter Filter) (*imageImpl, error
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
i := &imageImpl{
|
i := &imageImpl{
|
||||||
width: w,
|
|
||||||
height: h,
|
|
||||||
restorable: img,
|
restorable: img,
|
||||||
}
|
}
|
||||||
i.restorable.ReplacePixels(p)
|
i.restorable.ReplacePixels(p)
|
||||||
@ -89,8 +83,6 @@ func newScreenImageImpl(width, height int) (*imageImpl, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
i := &imageImpl{
|
i := &imageImpl{
|
||||||
width: width,
|
|
||||||
height: height,
|
|
||||||
restorable: img,
|
restorable: img,
|
||||||
volatile: true,
|
volatile: true,
|
||||||
screen: true,
|
screen: true,
|
||||||
@ -140,10 +132,12 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
|||||||
if dparts != nil {
|
if dparts != nil {
|
||||||
parts = imageParts(dparts)
|
parts = imageParts(dparts)
|
||||||
} else {
|
} else {
|
||||||
parts = &wholeImage{image.impl.width, image.impl.height}
|
w, h := image.impl.restorable.Size()
|
||||||
|
parts = &wholeImage{w, h}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
quads := &textureQuads{parts: parts, width: image.impl.width, height: image.impl.height}
|
w, h := image.impl.restorable.Size()
|
||||||
|
quads := &textureQuads{parts: parts, width: w, height: h}
|
||||||
// TODO: Reuse one vertices instead of making here, but this would need locking.
|
// TODO: Reuse one vertices instead of making here, but this would need locking.
|
||||||
vertices := make([]int16, parts.Len()*16)
|
vertices := make([]int16, parts.Len()*16)
|
||||||
n := quads.vertices(vertices)
|
n := quads.vertices(vertices)
|
||||||
@ -176,7 +170,8 @@ func (i *imageImpl) At(x, y int, context *opengl.Context) color.Color {
|
|||||||
if i.disposed {
|
if i.disposed {
|
||||||
return color.Transparent
|
return color.Transparent
|
||||||
}
|
}
|
||||||
idx := 4*x + 4*y*i.width
|
w, _ := i.restorable.Size()
|
||||||
|
idx := 4*x + 4*y*w
|
||||||
clr, err := i.restorable.At(idx, context)
|
clr, err := i.restorable.At(idx, context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -262,7 +257,8 @@ func (i *imageImpl) Dispose() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *imageImpl) ReplacePixels(p []uint8) error {
|
func (i *imageImpl) ReplacePixels(p []uint8) error {
|
||||||
if l := 4 * i.width * i.height; len(p) != l {
|
w, h := i.restorable.Size()
|
||||||
|
if l := 4 * w * h; len(p) != l {
|
||||||
return fmt.Errorf("ebiten: p's length must be %d", l)
|
return fmt.Errorf("ebiten: p's length must be %d", l)
|
||||||
}
|
}
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
|
@ -86,6 +86,10 @@ func NewScreenFramebufferImage(width, height int) (*Image, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Image) Size() (int, int) {
|
||||||
|
return p.width, p.height
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Image) makeStale() {
|
func (p *Image) makeStale() {
|
||||||
p.basePixels = nil
|
p.basePixels = nil
|
||||||
p.baseColor = color.RGBA{}
|
p.baseColor = color.RGBA{}
|
||||||
|
Loading…
Reference in New Issue
Block a user