Skip to content

Commit

Permalink
Resized frames now have original name of the image; made commands les…
Browse files Browse the repository at this point in the history
…s verbose now.
  • Loading branch information
LeeWannacott committed Mar 16, 2024
1 parent bb9346d commit 8346f4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func main() {
os.Exit(1)
}
sprite_source_folder := flag.String("f", "", "Folder name that contains sprites.")
hframes := flag.Int("hframes", 8, "Amount of horizontal sprites you want in your spritesheet: default 8.")
sprite_resize_px := flag.Int("sprite_resize", 0, "Resize each tile/sprite in spritesheet to the pixel value provided.")
single_sprites := flag.Bool("single_sprites", false, "Instead of spritesheet outputs single sprites into a folder used with -sprite_resize flag")
parent_folder_path := flag.String("mf", "", "multiple folders: path should be parent folder containing sub folders that contain folders with sprites/images in them. Refer to test_multi for example structure.")
hframes := flag.Int("hf", 8, "Horizontal Frames: Amount of horizontal frames you want in your spritesheet: default 8.")
sprite_resize_px := flag.Int("sr", 0, "Sprite Resize: Resize each sprite to the pixel value provided.")
single_sprites := flag.Bool("ss", false, "Single Sprites: Output sprites rather than spritesheet use with -sr flag")
parent_folder_path := flag.String("mf", "", "Multiple Folders: path should be parent folder containing sub folders that contain folders with sprites/images in them. Refer to test_multi for example structure.")
useMontage := flag.Bool("montage", false, "Use montage with -mf instead of gontage (if installed)")
help := flag.Bool("h", false, "Display help")
flag.Parse()
Expand Down
12 changes: 8 additions & 4 deletions src/gontage.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func Gontage(sprite_source_folder string, hframes *int, sprite_resize_px int, si

var chunk_images_waitgroup sync.WaitGroup
all_decoded_images := make([]image.Image, len(sprites_folder))
all_decoded_images_names := make([]string, len(sprites_folder))
for i := 0; i < len(sprites_folder); i += chunkSize {
start := i
end := start + chunkSize
Expand All @@ -65,9 +66,10 @@ func Gontage(sprite_source_folder string, hframes *int, sprite_resize_px int, si
chunk_images_waitgroup.Add(1)
go func(start int, end int) {
// Ideally decodeImages would write into all_decoded_images directly.
one_chunk_of_decoded_images := decodeImages(sprites_folder[start:end], sprite_source_folder, pwd, &chunk_images_waitgroup)
one_chunk_of_decoded_images, decoded_image_names := decodeImages(sprites_folder[start:end], sprite_source_folder, pwd, &chunk_images_waitgroup)
for j, decoded_image := range one_chunk_of_decoded_images {
all_decoded_images[start+j] = decoded_image
all_decoded_images_names[start+j] = decoded_image_names[j]
}
}(start, end)
}
Expand All @@ -79,7 +81,7 @@ func Gontage(sprite_source_folder string, hframes *int, sprite_resize_px int, si
os.Mkdir(sprite_source_folder_resized_name, 0755)
encoder := png.Encoder{CompressionLevel: png.BestSpeed}
for i, decoded_image := range all_decoded_images {
resized_sprite_name := fmt.Sprintf("/%v_%v.png", i, "resized")
resized_sprite_name := fmt.Sprintf("/%v", all_decoded_images_names[i])
f, err := os.Create(sprite_source_folder_resized_name + resized_sprite_name)
if err != nil {
panic(err)
Expand Down Expand Up @@ -137,20 +139,22 @@ func Gontage(sprite_source_folder string, hframes *int, sprite_resize_px int, si
}
}

func decodeImages(sprites_folder []fs.DirEntry, targetFolder string, pwd string, wg *sync.WaitGroup) []image.Image {
func decodeImages(sprites_folder []fs.DirEntry, targetFolder string, pwd string, wg *sync.WaitGroup) ([]image.Image, []string) {
defer wg.Done()
var sprites_array []image.Image
var sprites_names []string
for _, sprite := range sprites_folder {
if reader, err := os.Open(filepath.Join(pwd, targetFolder, sprite.Name())); err == nil {
m, _, err := image.Decode(reader)
if err != nil {
log.Fatal(err)
}
sprites_array = append(sprites_array, m)
sprites_names = append(sprites_names, sprite.Name())
reader.Close()
}
}
return sprites_array
return sprites_array, sprites_names
}

func drawSpritesheet(drawing drawingInfo) {
Expand Down

0 comments on commit 8346f4d

Please sign in to comment.