83 lines
2.3 KiB
Python
83 lines
2.3 KiB
Python
|
|
import json
|
|
import sys
|
|
|
|
from cli.parse_args import parse_args
|
|
|
|
|
|
def _normalize_channel(ch: str) -> str:
|
|
"""Y/Cb/Cr в канонический вид."""
|
|
m = {"y": "Y", "cb": "Cb", "cr": "Cr"}
|
|
s = (ch or "").strip().lower()
|
|
return m.get(s, ch)
|
|
|
|
|
|
def _print_result(result):
|
|
if result is None:
|
|
return
|
|
if isinstance(result, (dict, list)):
|
|
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
else:
|
|
print(result)
|
|
|
|
|
|
def main() -> int:
|
|
args = parse_args()
|
|
try:
|
|
if args.cmd == "embed":
|
|
from modes.embed_mode import EmbedMode
|
|
runner = EmbedMode()
|
|
result = runner.run(
|
|
input_path=args.input,
|
|
label_path=args.label,
|
|
output_path=args.output,
|
|
channel=_normalize_channel(args.channel),
|
|
seq0=args.seq0,
|
|
)
|
|
|
|
elif args.cmd == "extract":
|
|
from modes.extract_mode import ExtractMode
|
|
runner = ExtractMode()
|
|
result = runner.run(
|
|
input_path=args.input,
|
|
output_path=args.output,
|
|
channel=_normalize_channel(args.channel),
|
|
seq0=args.seq0
|
|
)
|
|
|
|
elif args.cmd == "analyze":
|
|
from modes.analyze_quality import AnalyzeQuality
|
|
runner = AnalyzeQuality()
|
|
result = runner.run(
|
|
original_path=args.original,
|
|
stego_path=args.stego,
|
|
space=args.space,
|
|
metrics=args.metrics,
|
|
)
|
|
|
|
elif args.cmd == "generate":
|
|
from modes.generate_mode import GenerateMode
|
|
runner = GenerateMode()
|
|
# Ветка generate имеет вложенные подкоманды: args.gen in {"gradient","chess"}
|
|
result = runner.run(
|
|
kind=args.gen,
|
|
size=args.size,
|
|
channels=args.channels,
|
|
output_path=args.output,
|
|
tile=getattr(args, "tile", None),
|
|
)
|
|
|
|
else:
|
|
raise RuntimeError(f"Неизвестная команда: {args.cmd}")
|
|
|
|
_print_result(result)
|
|
return 0
|
|
|
|
except Exception as exc:
|
|
print(f"Ошибка: {exc}", file=sys.stderr)
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|