Skip to content

Commit d774cf3

Browse files
committed
Add parameters for DZI output
1 parent 9da52a3 commit d774cf3

File tree

4 files changed

+69
-10
lines changed

4 files changed

+69
-10
lines changed

bin/stitch/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ example list of files:
4444
- `output string`
4545
The path and filename of the resulting stitched image. Defaults to "output.png".
4646
Supported formats/file extensions: `.png`, `.jpg`, `.dzi`.
47+
- `dzi-tile-size`
48+
The size of the resulting deep zoom image (DZI) tiles in pixels. Defaults to 512.
49+
- `dzi-tile-overlap`
50+
TThe number of additional pixels around every deep zoom image (DZI) tile in pixels. Defaults to 2.
4751
- `xmax int`
4852
Right bound of the output rectangle. This coordinate is not included in the output.
4953
- `xmin int`

bin/stitch/dzi.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ import (
1717
"time"
1818
)
1919

20-
const (
21-
dziTileSize = 512 // The (maximum) width and height of a tile in pixels, not including the overlap.
22-
dziOverlap = 2 // The amount of additional pixels on every side of every tile. The real (max) width/height of an image is `2*overlap + tileSize`.
23-
)
24-
2520
type DZI struct {
2621
stitchedImage *StitchedImage
2722

@@ -33,7 +28,10 @@ type DZI struct {
3328
maxZoomLevel int // The maximum zoom level that is needed.
3429
}
3530

36-
func NewDZI(stitchedImage *StitchedImage) DZI {
31+
// NewDZI creates a new DZI from the given StitchedImages.
32+
//
33+
// dziTileSize and dziOverlap define the size and overlap of the resulting DZI tiles.
34+
func NewDZI(stitchedImage *StitchedImage, dziTileSize, dziOverlap int) DZI {
3735
dzi := DZI{
3836
stitchedImage: stitchedImage,
3937

bin/stitch/export-dzi.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import (
1212
"strings"
1313
)
1414

15-
func exportDZI(stitchedImage *StitchedImage, outputPath string) error {
15+
func exportDZI(stitchedImage *StitchedImage, outputPath string, dziTileSize, dziOverlap int) error {
1616
descriptorPath := outputPath
1717
extension := filepath.Ext(outputPath)
1818
outputTilesPath := strings.TrimSuffix(outputPath, extension) + "_files"
1919

20-
dzi := NewDZI(stitchedImage)
20+
dzi := NewDZI(stitchedImage, dziTileSize, dziOverlap)
2121

2222
// Create base directory of all DZI files.
2323
if err := os.MkdirAll(outputTilesPath, 0755); err != nil {

bin/stitch/main.go

+59-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var flagPlayerPathInputPath = flag.String("player-path", filepath.Join(".", ".."
2525
var flagOutputPath = flag.String("output", filepath.Join(".", "output.png"), "The path and filename of the resulting stitched image. Supported formats/file extensions: `.png`, `.jpg`, `.dzi`.")
2626
var flagScaleDivider = flag.Int("divide", 1, "A downscaling factor. 2 will produce an image with half the side lengths.")
2727
var flagBlendTileLimit = flag.Int("blend-tile-limit", 9, "Limits median blending to the n newest tiles by file modification time. If set to 0, all available tiles will be median blended.")
28+
var flagDZITileSize = flag.Int("dzi-tile-size", 512, "The size of the resulting deep zoom image (DZI) tiles in pixels.")
29+
var flagDZIOverlap = flag.Int("dzi-tile-overlap", 2, "The number of additional pixels around every deep zoom image (DZI) tile in pixels.")
2830
var flagXMin = flag.Int("xmin", 0, "Left bound of the output rectangle. This coordinate is included in the output.")
2931
var flagYMin = flag.Int("ymin", 0, "Upper bound of the output rectangle. This coordinate is included in the output.")
3032
var flagXMax = flag.Int("xmax", 0, "Right bound of the output rectangle. This coordinate is not included in the output.")
@@ -229,6 +231,62 @@ func main() {
229231
*flagOutputPath = result
230232
}
231233

234+
fileExtension := strings.ToLower(filepath.Ext(*flagOutputPath))
235+
236+
// Query the user, if there were no cmd arguments given.
237+
if flag.NFlag() == 0 && fileExtension == ".dzi" {
238+
prompt := promptui.Prompt{
239+
Label: "Enter DZI tile size:",
240+
Default: fmt.Sprint(*flagDZITileSize),
241+
AllowEdit: true,
242+
Validate: func(s string) error {
243+
var num int
244+
_, err := fmt.Sscanf(s, "%d", &num)
245+
if err != nil {
246+
return err
247+
}
248+
if int(num) < 1 {
249+
return fmt.Errorf("number must be at least 1")
250+
}
251+
252+
return nil
253+
},
254+
}
255+
256+
result, err := prompt.Run()
257+
if err != nil {
258+
log.Panicf("Error while getting user input: %v.", err)
259+
}
260+
fmt.Sscanf(result, "%d", flagDZITileSize)
261+
}
262+
263+
// Query the user, if there were no cmd arguments given.
264+
if flag.NFlag() == 0 && fileExtension == ".dzi" {
265+
prompt := promptui.Prompt{
266+
Label: "Enter DZI tile overlap:",
267+
Default: fmt.Sprint(*flagDZIOverlap),
268+
AllowEdit: true,
269+
Validate: func(s string) error {
270+
var num int
271+
_, err := fmt.Sscanf(s, "%d", &num)
272+
if err != nil {
273+
return err
274+
}
275+
if int(num) < 0 {
276+
return fmt.Errorf("number must be at least 0")
277+
}
278+
279+
return nil
280+
},
281+
}
282+
283+
result, err := prompt.Run()
284+
if err != nil {
285+
log.Panicf("Error while getting user input: %v.", err)
286+
}
287+
fmt.Sscanf(result, "%d", flagDZIOverlap)
288+
}
289+
232290
startTime := time.Now()
233291

234292
bar := pb.Full.New(0)
@@ -266,7 +324,6 @@ func main() {
266324
}
267325
}()
268326

269-
fileExtension := strings.ToLower(filepath.Ext(*flagOutputPath))
270327
switch fileExtension {
271328
case ".png":
272329
if err := exportPNG(stitchedImage, *flagOutputPath); err != nil {
@@ -277,7 +334,7 @@ func main() {
277334
log.Panicf("Export of JPEG file failed: %v", err)
278335
}
279336
case ".dzi":
280-
if err := exportDZI(stitchedImage, *flagOutputPath); err != nil {
337+
if err := exportDZI(stitchedImage, *flagOutputPath, *flagDZITileSize, *flagDZIOverlap); err != nil {
281338
log.Panicf("Export of DZI file failed: %v", err)
282339
}
283340
default:

0 commit comments

Comments
 (0)