2024-02-07 23:50:11 +00:00
|
|
|
// Copyright (c) 2023-2024 David Vogel
|
2023-12-23 00:17:20 +00:00
|
|
|
//
|
|
|
|
// This software is released under the MIT License.
|
|
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2024-02-07 23:50:11 +00:00
|
|
|
|
|
|
|
"github.com/cheggaaa/pb/v3"
|
2023-12-23 00:17:20 +00:00
|
|
|
)
|
|
|
|
|
2024-02-07 23:50:11 +00:00
|
|
|
func exportDZIStitchedImage(stitchedImage *StitchedImage, outputPath string, bar *pb.ProgressBar, dziTileSize, dziOverlap int, webPLevel int) error {
|
2023-12-23 00:17:20 +00:00
|
|
|
descriptorPath := outputPath
|
|
|
|
extension := filepath.Ext(outputPath)
|
|
|
|
outputTilesPath := strings.TrimSuffix(outputPath, extension) + "_files"
|
|
|
|
|
2023-12-31 16:44:07 +00:00
|
|
|
dzi := NewDZI(stitchedImage, dziTileSize, dziOverlap)
|
2023-12-23 00:17:20 +00:00
|
|
|
|
|
|
|
// Create base directory of all DZI files.
|
|
|
|
if err := os.MkdirAll(outputTilesPath, 0755); err != nil {
|
|
|
|
return fmt.Errorf("failed to create output directory: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Export DZI descriptor.
|
|
|
|
if err := dzi.ExportDZIDescriptor(descriptorPath); err != nil {
|
|
|
|
return fmt.Errorf("failed to export DZI descriptor: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Export DZI tiles.
|
2024-02-07 23:50:11 +00:00
|
|
|
if err := dzi.ExportDZITiles(outputTilesPath, bar, webPLevel); err != nil {
|
2023-12-23 00:17:20 +00:00
|
|
|
return fmt.Errorf("failed to export DZI tiles: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|