修改色域画图及重绘方式

This commit is contained in:
xinzhu.yin
2026-05-18 15:57:11 +08:00
parent 9371defb6e
commit d7495734a5
9 changed files with 900 additions and 540 deletions

View File

@@ -15,6 +15,24 @@ def init_gamut_chart(self):
container = ttk.Frame(self.gamut_chart_frame)
container.pack(expand=True, fill=tk.BOTH)
# ---- 参考色域切换工具栏 ----
toolbar = ttk.Frame(container)
toolbar.pack(fill=tk.X, padx=8, pady=(4, 2))
ttk.Label(toolbar, text="参考色域标准:").pack(side=tk.LEFT, padx=(0, 8))
self._gamut_ref_toolbar_var = tk.StringVar(value="DCI-P3")
for std in ["BT.709", "DCI-P3", "BT.2020", "BT.601"]:
rb = ttk.Radiobutton(
toolbar, text=std,
variable=self._gamut_ref_toolbar_var,
value=std,
bootstyle="toolbutton",
command=lambda s=std: self._on_gamut_toolbar_changed(s),
)
rb.pack(side=tk.LEFT, padx=2)
# ---- matplotlib 图表 ----
self.gamut_fig = plt.Figure(figsize=(14, 6), dpi=100)
self.gamut_canvas = FigureCanvasTkAgg(self.gamut_fig, master=container)
@@ -29,16 +47,16 @@ def init_gamut_chart(self):
[0.52, 0.08, 0.46, 0.84]
) # ← 改回 0.84
# 初始化XY
self.gamut_ax_xy.set_xlim(0, 600)
self.gamut_ax_xy.set_ylim(600, 0)
self.gamut_ax_xy.axis("off")
# 初始化 XY 图(占位坐标系,真实绘制时由 plot_gamut 设置 CIE 1931 范围)
self.gamut_ax_xy.set_xlim(0.0, 0.8)
self.gamut_ax_xy.set_ylim(0.0, 0.9)
self.gamut_ax_xy.set_aspect("equal", adjustable="datalim")
self.gamut_ax_xy.set_clip_on(False)
# 初始化UV
self.gamut_ax_uv.set_xlim(0, 600)
self.gamut_ax_uv.set_ylim(600, 0)
self.gamut_ax_uv.axis("off")
# 初始化 UV 图(占位坐标系,真实绘制时由 plot_gamut 设置 CIE 1976 范围)
self.gamut_ax_uv.set_xlim(0.0, 0.65)
self.gamut_ax_uv.set_ylim(0.0, 0.6)
self.gamut_ax_uv.set_aspect("equal", adjustable="datalim")
self.gamut_ax_uv.set_clip_on(False)
# 调整标题位置y=0.98
@@ -46,6 +64,47 @@ def init_gamut_chart(self):
self.gamut_canvas.draw()
def sync_gamut_toolbar(self):
"""将工具栏参考标准按钮同步为当前测试类型的 ref var 值。"""
if not hasattr(self, "_gamut_ref_toolbar_var"):
return
test_type = getattr(self.config, "current_test_type", "screen_module")
var_map = {
"screen_module": "screen_gamut_ref_var",
"sdr_movie": "sdr_gamut_ref_var",
"hdr_movie": "hdr_gamut_ref_var",
}
attr = var_map.get(test_type)
if attr and hasattr(self, attr):
self._gamut_ref_toolbar_var.set(getattr(self, attr).get())
def _on_gamut_toolbar_changed(self, std):
"""用户点击工具栏参考标准按钮时:更新 var → 保存配置 → 重绘(有数据时)。"""
test_type = self.config.current_test_type
var_map = {
"screen_module": "screen_gamut_ref_var",
"sdr_movie": "sdr_gamut_ref_var",
"hdr_movie": "hdr_gamut_ref_var",
}
attr = var_map.get(test_type)
if attr and hasattr(self, attr):
getattr(self, attr).set(std)
# 保存到配置
if test_type not in self.config.current_test_types:
self.config.current_test_types[test_type] = {}
self.config.current_test_types[test_type]["gamut_reference"] = std
self.save_pq_config()
# 仅在有色域数据时才重新绘制,避免无数据时弹出警告框
if hasattr(self, "results") and self.results:
rgb_data = self.results.get_intermediate_data("gamut", "rgb")
if rgb_data and len(rgb_data) >= 3:
self.recalculate_gamut()
def init_gamma_chart(self):
"""初始化Gamma曲线图表 - 左侧曲线 + 右侧表格4列 + 通用说明)"""
container = ttk.Frame(self.gamma_chart_frame)