sistemata la gestione delle dimensione e delle equalizzazione delle immagini sar
This commit is contained in:
parent
726a3b5852
commit
4c34f47789
@ -92,17 +92,21 @@ def run_orchestrator():
|
|||||||
rec_status_label = ttk.Label(controls_inner, textvariable=rec_status_var, foreground="gray")
|
rec_status_label = ttk.Label(controls_inner, textvariable=rec_status_var, foreground="gray")
|
||||||
rec_status_label.grid(row=0, column=3, padx=10)
|
rec_status_label.grid(row=0, column=3, padx=10)
|
||||||
|
|
||||||
# Size controls for display (MFD and SAR)
|
# Size controls for display (square pixels)
|
||||||
ttk.Label(controls_inner, text="MFD Size:").grid(row=1, column=0, sticky="w", padx=5)
|
ttk.Label(controls_inner, text="MFD Size (pixels, square):").grid(row=1, column=0, sticky="w", padx=5)
|
||||||
mfd_size_var = tk.IntVar(value=484)
|
mfd_size_var = tk.IntVar(value=484)
|
||||||
mfd_spin = tk.Spinbox(controls_inner, from_=32, to=2048, increment=1, textvariable=mfd_size_var, width=6)
|
mfd_spin = tk.Spinbox(controls_inner, from_=50, to=1024, increment=1, textvariable=mfd_size_var, width=6)
|
||||||
mfd_spin.grid(row=1, column=1, padx=5, pady=2, sticky='w')
|
mfd_spin.grid(row=1, column=1, padx=5, pady=2, sticky='w')
|
||||||
|
|
||||||
ttk.Label(controls_inner, text="SAR Size:").grid(row=1, column=2, sticky="w", padx=5)
|
ttk.Label(controls_inner, text="SAR Size (pixels, square):").grid(row=1, column=2, sticky="w", padx=5)
|
||||||
sar_size_var = tk.IntVar(value=484)
|
sar_size_var = tk.IntVar(value=484)
|
||||||
sar_spin = tk.Spinbox(controls_inner, from_=32, to=2048, increment=1, textvariable=sar_size_var, width=6)
|
sar_spin = tk.Spinbox(controls_inner, from_=100, to=2048, increment=1, textvariable=sar_size_var, width=6)
|
||||||
sar_spin.grid(row=1, column=3, padx=5, pady=2, sticky='w')
|
sar_spin.grid(row=1, column=3, padx=5, pady=2, sticky='w')
|
||||||
|
|
||||||
|
# Apply button (apply sizes to viewer windows when pressed)
|
||||||
|
apply_btn = ttk.Button(controls_inner, text="Apply Size")
|
||||||
|
apply_btn.grid(row=1, column=4, padx=8, pady=2)
|
||||||
|
|
||||||
# --- Row 1: Viewers ---
|
# --- Row 1: Viewers ---
|
||||||
# Set padding to 0 for Labelframes to remove gray areas around images
|
# Set padding to 0 for Labelframes to remove gray areas around images
|
||||||
left_box = ttk.Labelframe(main_frame, text="MFD Viewer", padding=0)
|
left_box = ttk.Labelframe(main_frame, text="MFD Viewer", padding=0)
|
||||||
@ -158,7 +162,7 @@ def run_orchestrator():
|
|||||||
master=right_box
|
master=right_box
|
||||||
)
|
)
|
||||||
|
|
||||||
# Apply initial display sizes and wire spinboxes to viewer setters
|
# Apply initial sizes once and wire the Apply button to apply later
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
viewer.set_mfd_display_size(int(mfd_size_var.get()))
|
viewer.set_mfd_display_size(int(mfd_size_var.get()))
|
||||||
@ -170,34 +174,31 @@ def run_orchestrator():
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _mfd_size_changed(*_args):
|
def _apply_sizes():
|
||||||
|
# Enforce limits and apply sizes to viewers
|
||||||
try:
|
try:
|
||||||
viewer.set_mfd_display_size(int(mfd_size_var.get()))
|
mfd_val = int(mfd_size_var.get())
|
||||||
|
except Exception:
|
||||||
|
mfd_val = 484
|
||||||
|
try:
|
||||||
|
sar_val = int(sar_size_var.get())
|
||||||
|
except Exception:
|
||||||
|
sar_val = 484
|
||||||
|
|
||||||
|
# Clamp to allowed ranges
|
||||||
|
mfd_val = max(50, min(1024, mfd_val))
|
||||||
|
sar_val = max(100, min(2048, sar_val))
|
||||||
|
|
||||||
|
try:
|
||||||
|
viewer.set_mfd_display_size(mfd_val)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
sar_viewer.set_display_size(sar_val)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _sar_size_changed(*_args):
|
apply_btn.config(command=_apply_sizes)
|
||||||
try:
|
|
||||||
sar_viewer.set_display_size(int(sar_size_var.get()))
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# trace_add for modern Tk; fallback to trace
|
|
||||||
try:
|
|
||||||
mfd_size_var.trace_add('write', lambda *a: _mfd_size_changed())
|
|
||||||
except Exception:
|
|
||||||
try:
|
|
||||||
mfd_size_var.trace('w', lambda *a: _mfd_size_changed())
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
sar_size_var.trace_add('write', lambda *a: _sar_size_changed())
|
|
||||||
except Exception:
|
|
||||||
try:
|
|
||||||
sar_size_var.trace('w', lambda *a: _sar_size_changed())
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@ -226,7 +226,7 @@ class SfpSarViewer:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _apply_brightness_contrast(self, img: 'Image.Image') -> 'Image.Image':
|
def _apply_brightness_contrast(self, img):
|
||||||
if Image is None or ImageEnhance is None:
|
if Image is None or ImageEnhance is None:
|
||||||
return img
|
return img
|
||||||
try:
|
try:
|
||||||
@ -287,7 +287,7 @@ class SfpSarViewer:
|
|||||||
logging.exception("SfpSarViewer: failed to build tk image")
|
logging.exception("SfpSarViewer: failed to build tk image")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _draw_image_on_canvas(self, photo_image: ImageTk.PhotoImage) -> None:
|
def _draw_image_on_canvas(self, photo_image) -> None:
|
||||||
"""Draw image on canvas and adjust canvas size to match image resolution."""
|
"""Draw image on canvas and adjust canvas size to match image resolution."""
|
||||||
try:
|
try:
|
||||||
self._last_photoimage = photo_image
|
self._last_photoimage = photo_image
|
||||||
@ -355,10 +355,27 @@ class SfpSarViewer:
|
|||||||
raw = self._current_pil_image_raw.copy() if self._current_pil_image_raw is not None else None
|
raw = self._current_pil_image_raw.copy() if self._current_pil_image_raw is not None else None
|
||||||
if raw is None:
|
if raw is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
pil = self._apply_brightness_contrast(raw.copy())
|
pil = self._apply_brightness_contrast(raw.copy())
|
||||||
tkimg = ImageTk.PhotoImage(pil, master=self._root)
|
|
||||||
|
# Resize a display copy so the shown image respects _display_size
|
||||||
|
display_copy = pil.copy()
|
||||||
|
try:
|
||||||
|
max_side = int(self._display_size) if self._display_size else None
|
||||||
|
except Exception:
|
||||||
|
max_side = None
|
||||||
|
|
||||||
|
if max_side and (display_copy.width > max_side or display_copy.height > max_side):
|
||||||
|
try:
|
||||||
|
resample = getattr(Image, 'LANCZOS', 1)
|
||||||
|
display_copy.thumbnail((max_side, max_side), resample)
|
||||||
|
except Exception:
|
||||||
|
try:
|
||||||
|
display_copy.thumbnail((max_side, max_side))
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
tkimg = ImageTk.PhotoImage(display_copy, master=self._root)
|
||||||
|
|
||||||
with self._lock:
|
with self._lock:
|
||||||
self._photo = tkimg
|
self._photo = tkimg
|
||||||
self._draw_image_on_canvas(self._photo)
|
self._draw_image_on_canvas(self._photo)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user