Skip to content

Commit

Permalink
add InsertPictureData & InsertPictureDataV to (packer *Packer)
Browse files Browse the repository at this point in the history
  • Loading branch information
cebarks committed Mar 26, 2021
1 parent fd9cf01 commit 725dc8c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packer/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,20 @@ func (packer *Packer) Insert(id int, image *pixel.Sprite) (err error) {

// Inserts the image with the given id and additional insertion flags.
func (packer *Packer) InsertV(id int, image *pixel.Sprite, flags uint8) (err error) {
bounds := image.Picture().Bounds()
pic := image.Picture().(*pixel.PictureData)

return packer.InsertPictureDataV(id, pic, flags)
}

// Inserts the PictureData with the given id into the texture space; default values.
func (packer *Packer) InsertPictureData(id int, pic *pixel.PictureData) (err error) {
return packer.InsertPictureDataV(id, pic, 0)
}

// Inserts the picturedata with the given id and additional insertion flags.
func (packer *Packer) InsertPictureDataV(id int, pic *pixel.PictureData, flags uint8) (err error) {
bounds := pic.Bounds()

if flags&OptimizeOnInsert != 0 {
packer.Optimize()
}
Expand All @@ -227,12 +238,12 @@ func (packer *Packer) InsertV(id int, image *pixel.Sprite, flags uint8) (err err
return err
}

for y := 0; y < int(pic.Bounds().H()); y++ {
for x := 0; x < int(pic.Bounds().W()); x++ {
for y := 0; y < int(bounds.H()); y++ {
for x := 0; x < int(bounds.W()); x++ {
i := packer.pic.Index(pixel.V(space.Min.X+float64(x), space.Min.Y+float64(y)))
var ii int
if flags&InsertFlipped != 0 {
ii = pic.Index(pixel.V(float64(x), (pic.Bounds().H()-1)-float64(y)))
ii = pic.Index(pixel.V(float64(x), (bounds.H()-1)-float64(y)))
} else {
ii = pic.Index(pixel.V(float64(x), float64(y)))
}
Expand Down

0 comments on commit 725dc8c

Please sign in to comment.