noita-mapcap/bin/stitch/image-tiles.go
David Vogel 65f7cb4e60 Improve stitching speed and resource usage
- Use QuickSelect algorithm for median filtering
- Use lists of uint8 instead of int for median filtering
- Fix GridifyRectangle
- Remove HilbertifyRectangle
- Add profiling.go
- Remove Profile.bat
- Add median blend tile-limit flag
- Print stitch duration
- Reduce StitchedImage cache image height
- Reduce StitchedImageCacheGridSize
- Improve StitchedImage caching
- Improve ImageTile caching
- Separate entity and entities
- Update stitcher README.md
- Add comments
2022-08-12 01:06:22 +02:00

48 lines
1016 B
Go

// Copyright (c) 2019-2022 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package main
import (
"fmt"
"path/filepath"
)
type ImageTiles []ImageTile
// LoadImageTiles "loads" all images in the directory at the given path.
func LoadImageTiles(path string, scaleDivider int) (ImageTiles, error) {
if scaleDivider < 1 {
return nil, fmt.Errorf("invalid scale of %v", scaleDivider)
}
var imageTiles ImageTiles
files, err := filepath.Glob(filepath.Join(path, "*.png"))
if err != nil {
return nil, err
}
for _, file := range files {
imageTile, err := NewImageTile(file, scaleDivider)
if err != nil {
return nil, err
}
imageTiles = append(imageTiles, imageTile)
}
return imageTiles, nil
}
// InvalidateAboveY invalidates all cached images that have no pixel at the given y coordinate or below.
func (it ImageTiles) InvalidateAboveY(y int) {
for _, tile := range it {
if tile.Bounds().Max.Y <= y {
tile.Invalidate()
}
}
}