Add parameters for DZI output

This commit is contained in:
David Vogel 2023-12-31 17:44:07 +01:00
parent 9da52a3f70
commit d774cf373d
4 changed files with 69 additions and 10 deletions

View File

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

View File

@ -17,11 +17,6 @@ import (
"time"
)
const (
dziTileSize = 512 // The (maximum) width and height of a tile in pixels, not including the overlap.
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`.
)
type DZI struct {
stitchedImage *StitchedImage
@ -33,7 +28,10 @@ type DZI struct {
maxZoomLevel int // The maximum zoom level that is needed.
}
func NewDZI(stitchedImage *StitchedImage) DZI {
// NewDZI creates a new DZI from the given StitchedImages.
//
// dziTileSize and dziOverlap define the size and overlap of the resulting DZI tiles.
func NewDZI(stitchedImage *StitchedImage, dziTileSize, dziOverlap int) DZI {
dzi := DZI{
stitchedImage: stitchedImage,

View File

@ -12,12 +12,12 @@ import (
"strings"
)
func exportDZI(stitchedImage *StitchedImage, outputPath string) error {
func exportDZI(stitchedImage *StitchedImage, outputPath string, dziTileSize, dziOverlap int) error {
descriptorPath := outputPath
extension := filepath.Ext(outputPath)
outputTilesPath := strings.TrimSuffix(outputPath, extension) + "_files"
dzi := NewDZI(stitchedImage)
dzi := NewDZI(stitchedImage, dziTileSize, dziOverlap)
// Create base directory of all DZI files.
if err := os.MkdirAll(outputTilesPath, 0755); err != nil {

View File

@ -25,6 +25,8 @@ var flagPlayerPathInputPath = flag.String("player-path", filepath.Join(".", ".."
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`.")
var flagScaleDivider = flag.Int("divide", 1, "A downscaling factor. 2 will produce an image with half the side lengths.")
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.")
var flagDZITileSize = flag.Int("dzi-tile-size", 512, "The size of the resulting deep zoom image (DZI) tiles in pixels.")
var flagDZIOverlap = flag.Int("dzi-tile-overlap", 2, "The number of additional pixels around every deep zoom image (DZI) tile in pixels.")
var flagXMin = flag.Int("xmin", 0, "Left bound of the output rectangle. This coordinate is included in the output.")
var flagYMin = flag.Int("ymin", 0, "Upper bound of the output rectangle. This coordinate is included in the output.")
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() {
*flagOutputPath = result
}
fileExtension := strings.ToLower(filepath.Ext(*flagOutputPath))
// Query the user, if there were no cmd arguments given.
if flag.NFlag() == 0 && fileExtension == ".dzi" {
prompt := promptui.Prompt{
Label: "Enter DZI tile size:",
Default: fmt.Sprint(*flagDZITileSize),
AllowEdit: true,
Validate: func(s string) error {
var num int
_, err := fmt.Sscanf(s, "%d", &num)
if err != nil {
return err
}
if int(num) < 1 {
return fmt.Errorf("number must be at least 1")
}
return nil
},
}
result, err := prompt.Run()
if err != nil {
log.Panicf("Error while getting user input: %v.", err)
}
fmt.Sscanf(result, "%d", flagDZITileSize)
}
// Query the user, if there were no cmd arguments given.
if flag.NFlag() == 0 && fileExtension == ".dzi" {
prompt := promptui.Prompt{
Label: "Enter DZI tile overlap:",
Default: fmt.Sprint(*flagDZIOverlap),
AllowEdit: true,
Validate: func(s string) error {
var num int
_, err := fmt.Sscanf(s, "%d", &num)
if err != nil {
return err
}
if int(num) < 0 {
return fmt.Errorf("number must be at least 0")
}
return nil
},
}
result, err := prompt.Run()
if err != nil {
log.Panicf("Error while getting user input: %v.", err)
}
fmt.Sscanf(result, "%d", flagDZIOverlap)
}
startTime := time.Now()
bar := pb.Full.New(0)
@ -266,7 +324,6 @@ func main() {
}
}()
fileExtension := strings.ToLower(filepath.Ext(*flagOutputPath))
switch fileExtension {
case ".png":
if err := exportPNG(stitchedImage, *flagOutputPath); err != nil {
@ -277,7 +334,7 @@ func main() {
log.Panicf("Export of JPEG file failed: %v", err)
}
case ".dzi":
if err := exportDZI(stitchedImage, *flagOutputPath); err != nil {
if err := exportDZI(stitchedImage, *flagOutputPath, *flagDZITileSize, *flagDZIOverlap); err != nil {
log.Panicf("Export of DZI file failed: %v", err)
}
default: