Make zoom levels descend to zero - ie '0' is the most zoomed out, where a single tile encompasses the entire image
This commit is contained in:
parent
e2ee7ae4aa
commit
0548db24c7
39
main.go
39
main.go
@ -8,18 +8,25 @@ import "flag"
|
||||
import "fmt"
|
||||
import "os"
|
||||
|
||||
const currentVersion = "0.01"
|
||||
|
||||
func main() {
|
||||
|
||||
filenamePtr := flag.String("filename", "screenshot.png", "filename to open")
|
||||
tileSizePtr := flag.Int ("tile-size", 512, "tile size, in pixels")
|
||||
filenamePtr := flag.String("filename", "", "filename to open")
|
||||
tileSizePtr := flag.Int ("tile-size", 256, "tile size, in pixels")
|
||||
concurrencyPtr := flag.Int ("concurrency", 5, "how many tiles to generate concurrently (threads)")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if (*filenamePtr == "") {
|
||||
fmt.Println("Error: You must specify a filename with --filename");
|
||||
return;
|
||||
}
|
||||
|
||||
fmt.Println("opening file:", *filenamePtr)
|
||||
src, err := imaging.Open(*filenamePtr)
|
||||
if err != nil {
|
||||
fmt.Println("could not open file:", err)
|
||||
fmt.Println("Error: Could not open file:", err)
|
||||
return;
|
||||
}
|
||||
|
||||
@ -28,7 +35,20 @@ func main() {
|
||||
tile_size_x := *tileSizePtr
|
||||
tile_size_y := *tileSizePtr
|
||||
|
||||
z := 0
|
||||
// work out maximum zoom
|
||||
var max_zoom int
|
||||
zoom_test_size_x := size.X
|
||||
zoom_test_size_y := size.Y
|
||||
for max_zoom = 0 ; ; max_zoom++ {
|
||||
if zoom_test_size_x < tile_size_x && zoom_test_size_y < tile_size_y {
|
||||
break
|
||||
}
|
||||
zoom_test_size_x = zoom_test_size_x >> 1
|
||||
zoom_test_size_y = zoom_test_size_y >> 1
|
||||
}
|
||||
|
||||
z := max_zoom
|
||||
fmt.Println("maximum zoom level is", max_zoom)
|
||||
|
||||
concurrency := *concurrencyPtr
|
||||
sem := make(chan bool, concurrency)
|
||||
@ -37,7 +57,7 @@ func main() {
|
||||
|
||||
// outer loop for zoom
|
||||
for {
|
||||
if (z == 0) {
|
||||
if (z == max_zoom) {
|
||||
// do nothing
|
||||
} else {
|
||||
// halve image size
|
||||
@ -45,10 +65,6 @@ func main() {
|
||||
runtime.GC()
|
||||
// recalculate size
|
||||
size = src.Bounds().Max
|
||||
// we are done if we are now smaller then the tile
|
||||
if (size.X < tile_size_x || size.Y < tile_size_y) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Print(fmt.Sprintf("zoom level: %d (%d x %d)\n", z, size.X, size.Y))
|
||||
@ -61,7 +77,10 @@ func main() {
|
||||
|
||||
}
|
||||
|
||||
z++
|
||||
z--
|
||||
if (z < 0) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// drain at the end of each zoom level
|
||||
|
Loading…
x
Reference in New Issue
Block a user