-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadStitchContextMenu.py
More file actions
72 lines (59 loc) · 2.09 KB
/
ReadStitchContextMenu.py
File metadata and controls
72 lines (59 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import argparse
import multiprocessing
import os
from core.services import SettingsHandler
from core.utils.constants import OUTPUT_SUFFIX
from gui.process import GuiStitchProcess
def _apply_preset(settings: SettingsHandler, preset: str) -> None:
preset = (preset or "").strip().lower()
if preset not in {"type", "redraw"}:
raise ValueError("preset must be 'type' or 'redraw'")
# Shared settings
settings.save("lossy_quality", 100)
settings.save("enforce_type", 2)
settings.save("enforce_width", 800)
if preset == "type":
settings.save("output_type", ".webp")
settings.save("split_height", 5000)
settings.save("detector_type", 0)
settings.save("postprocess_args", "-i [stitched] -o [processed] -n 3 -s 1 -f webp")
else:
settings.save("output_type", ".jpg")
settings.save("split_height", 15000)
settings.save("detector_type", 1)
settings.save("sensitivity", 100)
settings.save("scan_step", 10)
settings.save("ignorable_pixels", 0)
settings.save("postprocess_args", "-i [stitched] -o [processed] -n 3 -s 1 -f jpg")
def launch() -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
"--preset",
required=True,
choices=["type", "redraw"],
help="Which preset to use",
)
parser.add_argument(
"--input",
required=True,
dest="input_path",
help="Folder path to process",
)
args = parser.parse_args()
input_path = os.path.abspath(args.input_path)
if not os.path.isdir(input_path):
raise FileNotFoundError(f"Input folder not found: {input_path}")
settings = SettingsHandler()
_apply_preset(settings, args.preset)
output_path = input_path + OUTPUT_SUFFIX
process = GuiStitchProcess()
process.run_with_error_msgs(
input_path=input_path,
output_path=output_path,
status_func=lambda pct, msg: print(f"[{pct}%] {msg}"),
console_func=print,
)
return 0
if __name__ == "__main__":
multiprocessing.freeze_support()
raise SystemExit(launch())