Ebiten: Size is invalid on SubImage

Created on 7 Nov 2018  路  4Comments  路  Source: hajimehoshi/ebiten

It might be expected that Image.Size is the size of Image.Bounds but this is not the case with SubImage created images which is causing me some math headaches. Take the following code:

package main

import (
    "fmt"
    "image"

    "github.com/hajimehoshi/ebiten"
)

func main() {
    img, _ := ebiten.NewImage(100, 100, ebiten.FilterDefault)
    w, h := img.Size()
    fmt.Printf("Bounds: %v, Size: %v - %v\n", img.Bounds(), w, h)

    subImg := img.SubImage(image.Rect(20, 20, 40, 40)).(*ebiten.Image)
    subW, subH := subImg.Size()
    fmt.Printf("Bounds: %v, Size: %v - %v\n", subImg.Bounds(), subW, subH)
}

This outputs:

Bounds: (0,0)-(100,100), Size: 100 - 100
Bounds: (20,20)-(40,40), Size: 100 - 100

But you would expect:

Bounds: (0,0)-(100,100), Size: 100 - 100
Bounds: (20,20)-(40,40), Size: 20 - 20

If this is by intention, I cannot see it documented anywhere.

bug

All 4 comments

Nice catch, thanks!

@hajimehoshi - This change may have made other things break. I am still investigating...

@hajimehoshi - yeah, this broke many DrawImage calls which leverages Size. Can you confirm w/ a go build -a on any of your examples while having this commit checked out?

Oops, I'll revert this asap, and fix this again. Sorry.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

QiProject picture QiProject  路  4Comments

hajimehoshi picture hajimehoshi  路  7Comments

ilyar picture ilyar  路  3Comments

hajimehoshi picture hajimehoshi  路  6Comments

nanoslayer picture nanoslayer  路  7Comments