Skip to content

Commit

Permalink
add: add zigzag export in sprite board tab, and fix background color …
Browse files Browse the repository at this point in the history
…in palette
  • Loading branch information
Jerome Le Saux committed May 6, 2024
1 parent d8fbffb commit 8082915
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion convert/image/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func downgradeWithPalette(in *image.NRGBA, p color.Palette) *image.NRGBA {
if r == 0 && g == 0 && b == 0 && a == 0 {
cPalette = p[0]
} else {
cPalette = p.Convert(c)
cPalette = p[1:].Convert(c)
}
in.Set(x, y, cPalette)
cache[c] = cPalette
Expand Down
13 changes: 13 additions & 0 deletions convert/sprite/sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ import (
"github.com/jeromelesaux/martine/log"
)

func ToImg(d [][]byte, p color.Palette) *image.NRGBA {
o := image.NewNRGBA(image.Rectangle{
Min: image.Point{X: 0, Y: 0},
Max: image.Point{X: len(d[0]), Y: len(d)}})

for y := 0; y < len(d); y++ {
for x := 0; x < len(d[0]); x++ {
o.Set(x, y, p[d[y][x]])
}
}
return o
}

// nolint:funlen
func RawSpriteToImg(data []byte, height, width, mode uint8, p color.Palette) *image.NRGBA {
var out *image.NRGBA
Expand Down
25 changes: 24 additions & 1 deletion ui/martine-ui/export_sprite_board.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
wgt "github.com/jeromelesaux/fyne-io/widget"
"github.com/jeromelesaux/martine/config"
"github.com/jeromelesaux/martine/constants"
"github.com/jeromelesaux/martine/convert/sprite"
"github.com/jeromelesaux/martine/export"
"github.com/jeromelesaux/martine/export/amsdos"
"github.com/jeromelesaux/martine/export/ascii"
Expand All @@ -25,6 +26,7 @@ import (
"github.com/jeromelesaux/martine/export/ocpartstudio/window"
"github.com/jeromelesaux/martine/export/spritehard"
"github.com/jeromelesaux/martine/gfx/animate"
"github.com/jeromelesaux/martine/gfx/transformation"
"github.com/jeromelesaux/martine/log"
"github.com/jeromelesaux/martine/ui/martine-ui/directory"
"github.com/jeromelesaux/martine/ui/martine-ui/menu"
Expand Down Expand Up @@ -182,6 +184,16 @@ func (m *MartineUI) ExportSpriteBoard(s *menu.SpriteMenu) {
case export.SpriteFlatExport:
buf := make([]byte, 0)
for _, v := range s.SpritesData {
if s.ExportZigzag {
im := sprite.ToImg(v, s.Palette())
z := transformation.Zigzag(im)
for y := 0; y < z.Bounds().Max.Y; y++ {
for x := 0; x < z.Bounds().Max.X; x++ {
c := s.Palette().Index(z.At(x, y))
v[y][x] = byte(c)
}
}
}
for _, v0 := range v {
buf = append(buf, v0...)
}
Expand Down Expand Up @@ -275,7 +287,18 @@ func (m *MartineUI) ExportSpriteBoard(s *menu.SpriteMenu) {
if s.ExportText {
data := make([][]byte, 0)
for _, v := range s.SpritesData {
data = append(data, v...)
if s.ExportZigzag {
im := sprite.ToImg(v, s.Palette())
z := transformation.Zigzag(im)
for y := 0; y < z.Bounds().Max.Y; y++ {
for x := 0; x < z.Bounds().Max.X; x++ {
c := s.Palette().Index(z.At(x, y))
v[y][x] = byte(c)
}
}
} else {
data = append(data, v...)
}
}
kitPalette := palette.KitPalette{}
for i := 0; i < len(s.Palette()); i++ {
Expand Down

0 comments on commit 8082915

Please sign in to comment.