| 1 |
"""GUI for creating and editing test charts with wxPython. |
| 2 |
|
| 3 |
It supports features such as patch customization, color space adjustments, file |
| 4 |
import/export, and 3D visualization. The editor allows users to generate test |
| 5 |
charts for color calibration and profiling tasks with various configuration |
| 6 |
options. |
| 7 |
""" |
| 8 |
|
| 9 |
import csv |
| 10 |
import math |
| 11 |
import os |
| 12 |
import re |
| 13 |
import shutil |
| 14 |
import sys |
| 15 |
import time |
| 16 |
|
| 17 |
from DisplayCAL.argyll import check_set_argyll_bin |
| 18 |
|
| 19 |
if sys.platform == "win32": |
| 20 |
from win32 import win32file |
| 21 |
|
| 22 |
from DisplayCAL import ( |
| 23 |
argyll_rgb2xyz, |
| 24 |
colormath, |
| 25 |
config, |
| 26 |
floatspin, |
| 27 |
imfile, |
| 28 |
) |
| 29 |
from DisplayCAL import localization as lang |
| 30 |
from DisplayCAL.argyll_cgats import ti3_to_ti1, verify_cgats |
| 31 |
from DisplayCAL.cgats import ( |
| 32 |
CGATS, |
| 33 |
CGATSError, |
| 34 |
CGATSKeyError, |
| 35 |
rpad, |
| 36 |
sort_by_rec709_luma, |
| 37 |
sort_by_rgb, |
| 38 |
sort_by_rgb_sum, |
| 39 |
stable_sort_by_l, |
| 40 |
) |
| 41 |
from DisplayCAL.config import ( |
| 42 |
DEFAULTS, |
| 43 |
get_bitmap, |
| 44 |
get_data_path, |
| 45 |
get_display_name, |
| 46 |
get_icon, |
| 47 |
get_total_patches, |
| 48 |
get_verified_path, |
| 49 |
getcfg, |
| 50 |
hascfg, |
| 51 |
setcfg, |
| 52 |
writecfg, |
| 53 |
) |
| 54 |
from DisplayCAL.debughelpers import handle_error |
| 55 |
from DisplayCAL.icc_profile import ( |
| 56 |
ICCProfile, |
| 57 |
ICCProfileInvalidError, |
| 58 |
NamedColor2Type, |
| 59 |
) |
| 60 |
from DisplayCAL.meta import NAME as APPNAME |
| 61 |
from DisplayCAL.options import DEBUG, TC_USE_ALTERNATE_PREVIEW, TEST, VERBOSE |
| 62 |
from DisplayCAL.util_dict import swap_dict_keys_values |
| 63 |
from DisplayCAL.util_os import is_superuser, launch_file, waccess |
| 64 |
from DisplayCAL.worker import ( |
| 65 |
Error, |
| 66 |
Worker, |
| 67 |
check_file_isfile, |
| 68 |
get_argyll_util, |
| 69 |
get_current_profile_path, |
| 70 |
show_result_dialog, |
| 71 |
) |
| 72 |
from DisplayCAL.wx_addons import CustomEvent, wx |
| 73 |
from DisplayCAL.wx_measure_frame import get_default_size |
| 74 |
from DisplayCAL.wx_windows import ( |
| 75 |
BaseApp, |
| 76 |
BaseFrame, |
| 77 |
ConfirmDialog, |
| 78 |
CustomGrid, |
| 79 |
FileBrowseBitmapButtonWithChoiceHistory, |
| 80 |
FileDrop, |
| 81 |
get_gradient_panel, |
| 82 |
) |
| 83 |
|
| 84 |
|
| 85 |
class TestchartEditor(BaseFrame): |
| 86 |
"""Testchart editor window. |
| 87 |
|
| 88 |
Args: |
| 89 |
parent (wx.Window, optional): Parent window. |
| 90 |
id (int, optional): Window identifier. Defaults to -1. |
| 91 |
path (str, optional): Path to a test chart file to load. If None, |
| 92 |
an empty test chart is created. |
| 93 |
cfg (str, optional): Configuration file name. Defaults to |
| 94 |
"testchart.file". |
| 95 |
parent_set_chart_methodname (str, optional): Method name in the parent |
| 96 |
to set the test chart. Defaults to "set_testchart". |
| 97 |
setup (bool, optional): Whether to set up the editor immediately. |
| 98 |
Defaults to True. |
| 99 |
""" |
| 100 |
|
| 101 |
def __init__( |
| 102 |
self, |
| 103 |
parent=None, |
| 104 |
id=-1, # noqa: A002 |
| 105 |
path=None, |
| 106 |
cfg="testchart.file", |
| 107 |
parent_set_chart_methodname="set_testchart", |
| 108 |
setup=True, |
| 109 |
): |
| 110 |
BaseFrame.__init__( |
| 111 |
self, parent, id, lang.getstr("testchart.edit"), name="tcgen" |
| 112 |
) |
| 113 |
self.SetIcons( |
| 114 |
config.get_icon_bundle([256, 48, 32, 16], f"{APPNAME}-testchart-editor") |
| 115 |
) |
| 116 |
self.Bind(wx.EVT_CLOSE, self.tc_close_handler) |
| 117 |
|
| 118 |
self.tc_algos_ab = { |
| 119 |
"": lang.getstr("tc.ofp"), |
| 120 |
"t": lang.getstr("tc.t"), |
| 121 |
"r": lang.getstr("tc.r"), |
| 122 |
"R": lang.getstr("tc.R"), |
| 123 |
"q": lang.getstr("tc.q"), |
| 124 |
"i": lang.getstr("tc.i"), |
| 125 |
"I": lang.getstr("tc.I"), |
| 126 |
} |
| 127 |
|
| 128 |
self.cfg = cfg |
| 129 |
self.parent_set_chart_methodname = parent_set_chart_methodname |
| 130 |
|
| 131 |
if setup: |
| 132 |
self.setup(path) |
| 133 |
|
| 134 |
def setup(self, path=None): |
| 135 |
"""Set up the testchart editor. |
| 136 |
|
| 137 |
Args: |
| 138 |
path (str, optional): Path to a test chart file to load. If None, |
| 139 |
an empty test chart is created. |
| 140 |
""" |
| 141 |
self.worker = Worker(self) |
| 142 |
self.worker.set_argyll_version("targen") |
| 143 |
|
| 144 |
if self.worker.argyll_version >= [1, 1, 0]: |
| 145 |
self.tc_algos_ab["Q"] = lang.getstr("tc.Q") |
| 146 |
|
| 147 |
self.tc_algos_ba = swap_dict_keys_values(self.tc_algos_ab) |
| 148 |
|
| 149 |
self.label_b2a = { |
| 150 |
"R %": "RGB_R", |
| 151 |
"G %": "RGB_G", |
| 152 |
"B %": "RGB_B", |
| 153 |
"X": "XYZ_X", |
| 154 |
"Y": "XYZ_Y", |
| 155 |
"Z": "XYZ_Z", |
| 156 |
} |
| 157 |
|
| 158 |
self.droptarget = FileDrop(self) |
| 159 |
self.droptarget.drophandlers = { |
| 160 |
".cgats": self.ti1_drop_handler, |
| 161 |
".cie": self.tc_drop_ti3_handler, |
| 162 |
".csv": self.csv_drop_handler, |
| 163 |
".gam": self.tc_drop_ti3_handler, |
| 164 |
".icc": self.ti1_drop_handler, |
| 165 |
".icm": self.ti1_drop_handler, |
| 166 |
".jpg": self.tc_drop_ti3_handler, |
| 167 |
".jpeg": self.tc_drop_ti3_handler, |
| 168 |
".png": self.tc_drop_ti3_handler, |
| 169 |
".tif": self.tc_drop_ti3_handler, |
| 170 |
".tiff": self.tc_drop_ti3_handler, |
| 171 |
".ti1": self.ti1_drop_handler, |
| 172 |
".ti3": self.ti1_drop_handler, |
| 173 |
".txt": self.ti1_drop_handler, |
| 174 |
} |
| 175 |
|
| 176 |
scale = getcfg("app.dpi") / config.get_default_dpi() |
| 177 |
scale = max(scale, 1) |
| 178 |
|
| 179 |
if TC_USE_ALTERNATE_PREVIEW: |
| 180 |
# splitter |
| 181 |
splitter = self.splitter = wx.SplitterWindow( |
| 182 |
self, -1, style=wx.SP_LIVE_UPDATE | wx.SP_3DSASH |
| 183 |
) |
| 184 |
if wx.VERSION < (2, 9): |
| 185 |
self.Bind( |
| 186 |
wx.EVT_SPLITTER_SASH_POS_CHANGED, self.tc_sash_handler, splitter |
| 187 |
) |
| 188 |
self.Bind( |
| 189 |
wx.EVT_SPLITTER_SASH_POS_CHANGING, self.tc_sash_handler, splitter |
| 190 |
) |
| 191 |
|
| 192 |
p1 = wx.Panel(splitter) |
| 193 |
p1.sizer = wx.BoxSizer(wx.VERTICAL) |
| 194 |
p1.SetSizer(p1.sizer) |
| 195 |
|
| 196 |
p2 = wx.Panel(splitter) |
| 197 |
# Setting a droptarget seems to cause crash when destroying |
| 198 |
# p2.SetDropTarget(self.droptarget) |
| 199 |
p2.sizer = wx.BoxSizer(wx.VERTICAL) |
| 200 |
p2.SetSizer(p2.sizer) |
| 201 |
|
| 202 |
splitter.SetMinimumPaneSize(23) |
| 203 |
# splitter end |
| 204 |
|
| 205 |
panel = self.panel = p1 |
| 206 |
else: |
| 207 |
panel = self.panel = wx.Panel(self) |
| 208 |
panel.SetDropTarget(self.droptarget) |
| 209 |
|
| 210 |
self.sizer = wx.BoxSizer(wx.VERTICAL) |
| 211 |
panel.SetSizer(self.sizer) |
| 212 |
|
| 213 |
border = 4 |
| 214 |
|
| 215 |
sizer = wx.FlexGridSizer(0, 4, 0, 0) |
| 216 |
self.sizer.Add(sizer, flag=(wx.ALL & ~wx.BOTTOM), border=12) |
| 217 |
|
| 218 |
# white patches |
| 219 |
sizer.Add( |
| 220 |
wx.StaticText(panel, -1, lang.getstr("tc.white")), |
| 221 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 222 |
border=border, |
| 223 |
) |
| 224 |
self.tc_white_patches = wx.SpinCtrl( |
| 225 |
panel, -1, size=(100 * scale, -1), min=0, name="tc_white_patches" |
| 226 |
) |
| 227 |
self.Bind( |
| 228 |
wx.EVT_TEXT, self.tc_white_patches_handler, id=self.tc_white_patches.GetId() |
| 229 |
) |
| 230 |
sizer.Add( |
| 231 |
self.tc_white_patches, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 232 |
) |
| 233 |
|
| 234 |
# single channel patches |
| 235 |
sizer.Add( |
| 236 |
wx.StaticText(panel, -1, lang.getstr("tc.single")), |
| 237 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, |
| 238 |
border=border, |
| 239 |
) |
| 240 |
self.tc_single_channel_patches = wx.SpinCtrl( |
| 241 |
panel, |
| 242 |
-1, |
| 243 |
size=(100 * scale, -1), |
| 244 |
min=0, |
| 245 |
max=256, |
| 246 |
name="tc_single_channel_patches", |
| 247 |
) |
| 248 |
self.tc_single_channel_patches.Bind( |
| 249 |
wx.EVT_KILL_FOCUS, self.tc_single_channel_patches_handler |
| 250 |
) |
| 251 |
self.Bind( |
| 252 |
wx.EVT_SPINCTRL, |
| 253 |
self.tc_single_channel_patches_handler, |
| 254 |
id=self.tc_single_channel_patches.GetId(), |
| 255 |
) |
| 256 |
hsizer = wx.BoxSizer(wx.HORIZONTAL) |
| 257 |
sizer.Add(hsizer) |
| 258 |
hsizer.Add( |
| 259 |
self.tc_single_channel_patches, |
| 260 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 261 |
border=border, |
| 262 |
) |
| 263 |
hsizer.Add( |
| 264 |
wx.StaticText(panel, -1, lang.getstr("tc.single.perchannel")), |
| 265 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 266 |
border=border, |
| 267 |
) |
| 268 |
|
| 269 |
# black patches |
| 270 |
if self.worker.argyll_version >= [1, 6]: |
| 271 |
hsizer.Add( |
| 272 |
wx.StaticText(panel, -1, lang.getstr("tc.black")), |
| 273 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 274 |
border=border, |
| 275 |
) |
| 276 |
self.tc_black_patches = wx.SpinCtrl( |
| 277 |
panel, -1, size=(100 * scale, -1), min=0, name="tc_black_patches" |
| 278 |
) |
| 279 |
self.Bind( |
| 280 |
wx.EVT_TEXT, |
| 281 |
self.tc_black_patches_handler, |
| 282 |
id=self.tc_black_patches.GetId(), |
| 283 |
) |
| 284 |
hsizer.Add( |
| 285 |
self.tc_black_patches, |
| 286 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 287 |
border=border, |
| 288 |
) |
| 289 |
|
| 290 |
# gray axis patches |
| 291 |
sizer.Add( |
| 292 |
wx.StaticText(panel, -1, lang.getstr("tc.gray")), |
| 293 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 294 |
border=border, |
| 295 |
) |
| 296 |
self.tc_gray_patches = wx.SpinCtrl( |
| 297 |
panel, -1, size=(100 * scale, -1), min=0, max=256, name="tc_gray_patches" |
| 298 |
) |
| 299 |
self.tc_gray_patches.Bind(wx.EVT_KILL_FOCUS, self.tc_gray_handler) |
| 300 |
self.Bind( |
| 301 |
wx.EVT_SPINCTRL, self.tc_gray_handler, id=self.tc_gray_patches.GetId() |
| 302 |
) |
| 303 |
sizer.Add( |
| 304 |
self.tc_gray_patches, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 305 |
) |
| 306 |
|
| 307 |
# multidim steps |
| 308 |
sizer.Add( |
| 309 |
wx.StaticText(panel, -1, lang.getstr("tc.multidim")), |
| 310 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, |
| 311 |
border=border, |
| 312 |
) |
| 313 |
hsizer = wx.BoxSizer(wx.HORIZONTAL) |
| 314 |
sizer.Add(hsizer) |
| 315 |
self.tc_multi_steps = wx.SpinCtrl( |
| 316 |
panel, -1, size=(100 * scale, -1), min=0, max=21, name="tc_multi_steps" |
| 317 |
) # 16 multi dim steps = 4096 patches |
| 318 |
self.tc_multi_steps.Bind(wx.EVT_KILL_FOCUS, self.tc_multi_steps_handler) |
| 319 |
self.Bind( |
| 320 |
wx.EVT_SPINCTRL, self.tc_multi_steps_handler, id=self.tc_multi_steps.GetId() |
| 321 |
) |
| 322 |
hsizer.Add( |
| 323 |
self.tc_multi_steps, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 324 |
) |
| 325 |
if self.worker.argyll_version >= [1, 6, 0]: |
| 326 |
self.tc_multi_bcc_cb = wx.CheckBox(panel, -1, lang.getstr("centered")) |
| 327 |
self.tc_multi_bcc_cb.Bind(wx.EVT_CHECKBOX, self.tc_multi_bcc_cb_handler) |
| 328 |
hsizer.Add( |
| 329 |
self.tc_multi_bcc_cb, |
| 330 |
flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, |
| 331 |
border=border, |
| 332 |
) |
| 333 |
self.tc_multi_patches = wx.StaticText(panel, -1, "", name="tc_multi_patches") |
| 334 |
hsizer.Add( |
| 335 |
self.tc_multi_patches, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 336 |
) |
| 337 |
|
| 338 |
# full spread patches |
| 339 |
sizer.Add( |
| 340 |
wx.StaticText(panel, -1, lang.getstr("tc.fullspread")), |
| 341 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 342 |
border=border, |
| 343 |
) |
| 344 |
self.tc_fullspread_patches = wx.SpinCtrl( |
| 345 |
panel, |
| 346 |
-1, |
| 347 |
size=(100 * scale, -1), |
| 348 |
min=0, |
| 349 |
max=9999, |
| 350 |
name="tc_fullspread_patches", |
| 351 |
) |
| 352 |
self.Bind( |
| 353 |
wx.EVT_TEXT, |
| 354 |
self.tc_fullspread_handler, |
| 355 |
id=self.tc_fullspread_patches.GetId(), |
| 356 |
) |
| 357 |
sizer.Add( |
| 358 |
self.tc_fullspread_patches, |
| 359 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 360 |
border=border, |
| 361 |
) |
| 362 |
|
| 363 |
# algo |
| 364 |
algos = list(self.tc_algos_ab.values()) |
| 365 |
algos.sort() |
| 366 |
sizer.Add( |
| 367 |
wx.StaticText(panel, -1, lang.getstr("tc.algo")), |
| 368 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, |
| 369 |
border=border, |
| 370 |
) |
| 371 |
self.tc_algo = wx.Choice(panel, -1, choices=algos, name="tc_algo") |
| 372 |
self.tc_algo.Disable() |
| 373 |
self.Bind(wx.EVT_CHOICE, self.tc_algo_handler, id=self.tc_algo.GetId()) |
| 374 |
sizer.Add(self.tc_algo, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border) |
| 375 |
|
| 376 |
# adaption |
| 377 |
hsizer = wx.BoxSizer(wx.HORIZONTAL) |
| 378 |
sizer.Add(hsizer, 1, flag=wx.EXPAND) |
| 379 |
hsizer.Add( |
| 380 |
wx.StaticText(panel, -1, lang.getstr("tc.adaption")), |
| 381 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 382 |
border=border, |
| 383 |
) |
| 384 |
self.tc_adaption_slider = wx.Slider( |
| 385 |
panel, -1, 0, 0, 100, size=(64 * scale, -1), name="tc_adaption_slider" |
| 386 |
) |
| 387 |
self.tc_adaption_slider.Disable() |
| 388 |
self.Bind( |
| 389 |
wx.EVT_SLIDER, self.tc_adaption_handler, id=self.tc_adaption_slider.GetId() |
| 390 |
) |
| 391 |
hsizer.Add(self.tc_adaption_slider, flag=wx.ALIGN_CENTER_VERTICAL) |
| 392 |
self.tc_adaption_intctrl = wx.SpinCtrl( |
| 393 |
panel, |
| 394 |
-1, |
| 395 |
size=(100 * scale, -1), |
| 396 |
min=0, |
| 397 |
max=100, |
| 398 |
name="tc_adaption_intctrl", |
| 399 |
) |
| 400 |
self.tc_adaption_intctrl.Disable() |
| 401 |
self.Bind( |
| 402 |
wx.EVT_TEXT, self.tc_adaption_handler, id=self.tc_adaption_intctrl.GetId() |
| 403 |
) |
| 404 |
sizer.Add( |
| 405 |
self.tc_adaption_intctrl, |
| 406 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 407 |
border=border, |
| 408 |
) |
| 409 |
|
| 410 |
hsizer = wx.GridSizer(0, 2, 0, 0) |
| 411 |
sizer.Add(hsizer, 1, flag=wx.EXPAND) |
| 412 |
hsizer.Add( |
| 413 |
wx.StaticText(panel, -1, "%"), |
| 414 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 415 |
border=border, |
| 416 |
) |
| 417 |
hsizer.Add( |
| 418 |
wx.StaticText(panel, -1, lang.getstr("tc.angle")), |
| 419 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, |
| 420 |
border=border, |
| 421 |
) |
| 422 |
|
| 423 |
# angle |
| 424 |
hsizer = wx.BoxSizer(wx.HORIZONTAL) |
| 425 |
sizer.Add(hsizer, 1, flag=wx.EXPAND) |
| 426 |
self.tc_angle_slider = wx.Slider( |
| 427 |
panel, -1, 0, 0, 5000, size=(128 * scale, -1), name="tc_angle_slider" |
| 428 |
) |
| 429 |
self.tc_angle_slider.Disable() |
| 430 |
self.Bind(wx.EVT_SLIDER, self.tc_angle_handler, id=self.tc_angle_slider.GetId()) |
| 431 |
hsizer.Add(self.tc_angle_slider, flag=wx.ALIGN_CENTER_VERTICAL) |
| 432 |
self.tc_angle_intctrl = wx.SpinCtrl( |
| 433 |
panel, -1, size=(110 * scale, -1), min=0, max=5000, name="tc_angle_intctrl" |
| 434 |
) |
| 435 |
self.tc_angle_intctrl.Disable() |
| 436 |
self.Bind(wx.EVT_TEXT, self.tc_angle_handler, id=self.tc_angle_intctrl.GetId()) |
| 437 |
hsizer.Add( |
| 438 |
self.tc_angle_intctrl, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 439 |
) |
| 440 |
|
| 441 |
# gamma |
| 442 |
if self.worker.argyll_version == [ |
| 443 |
1, |
| 444 |
1, |
| 445 |
"RC2", |
| 446 |
] or self.worker.argyll_version >= [1, 1]: |
| 447 |
sizer.Add( |
| 448 |
wx.StaticText(panel, -1, lang.getstr("trc.gamma")), |
| 449 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 450 |
border=border, |
| 451 |
) |
| 452 |
self.tc_gamma_floatctrl = floatspin.FloatSpin( |
| 453 |
panel, |
| 454 |
-1, |
| 455 |
size=(100 * scale, -1), |
| 456 |
min_val=0.0, |
| 457 |
max_val=9.9, |
| 458 |
increment=0.05, |
| 459 |
digits=2, |
| 460 |
name="tc_gamma_floatctrl", |
| 461 |
) |
| 462 |
self.Bind( |
| 463 |
floatspin.EVT_FLOATSPIN, |
| 464 |
self.tc_gamma_handler, |
| 465 |
id=self.tc_gamma_floatctrl.GetId(), |
| 466 |
) |
| 467 |
sizer.Add( |
| 468 |
self.tc_gamma_floatctrl, |
| 469 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 470 |
border=border, |
| 471 |
) |
| 472 |
|
| 473 |
# neutral axis emphasis |
| 474 |
if self.worker.argyll_version >= [1, 3, 3]: |
| 475 |
sizer.Add( |
| 476 |
wx.StaticText(panel, -1, lang.getstr("tc.neutral_axis_emphasis")), |
| 477 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, |
| 478 |
border=border, |
| 479 |
) |
| 480 |
hsizer = wx.BoxSizer(wx.HORIZONTAL) |
| 481 |
sizer.Add(hsizer, 1, flag=wx.EXPAND) |
| 482 |
self.tc_neutral_axis_emphasis_slider = wx.Slider( |
| 483 |
panel, |
| 484 |
-1, |
| 485 |
0, |
| 486 |
0, |
| 487 |
100, |
| 488 |
size=(64 * scale, -1), |
| 489 |
name="tc_neutral_axis_emphasis_slider", |
| 490 |
) |
| 491 |
self.tc_neutral_axis_emphasis_slider.Disable() |
| 492 |
self.Bind( |
| 493 |
wx.EVT_SLIDER, |
| 494 |
self.tc_neutral_axis_emphasis_handler, |
| 495 |
id=self.tc_neutral_axis_emphasis_slider.GetId(), |
| 496 |
) |
| 497 |
hsizer.Add( |
| 498 |
self.tc_neutral_axis_emphasis_slider, flag=wx.ALIGN_CENTER_VERTICAL |
| 499 |
) |
| 500 |
self.tc_neutral_axis_emphasis_intctrl = wx.SpinCtrl( |
| 501 |
panel, |
| 502 |
-1, |
| 503 |
size=(100 * scale, -1), |
| 504 |
min=0, |
| 505 |
max=100, |
| 506 |
name="tc_neutral_axis_emphasis_intctrl", |
| 507 |
) |
| 508 |
self.tc_neutral_axis_emphasis_intctrl.Disable() |
| 509 |
self.Bind( |
| 510 |
wx.EVT_TEXT, |
| 511 |
self.tc_neutral_axis_emphasis_handler, |
| 512 |
id=self.tc_neutral_axis_emphasis_intctrl.GetId(), |
| 513 |
) |
| 514 |
hsizer.Add( |
| 515 |
self.tc_neutral_axis_emphasis_intctrl, |
| 516 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 517 |
border=border, |
| 518 |
) |
| 519 |
hsizer.Add( |
| 520 |
wx.StaticText(panel, -1, "%"), |
| 521 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 522 |
border=border, |
| 523 |
) |
| 524 |
|
| 525 |
# dark patch emphasis |
| 526 |
if self.worker.argyll_version >= [1, 6, 2]: |
| 527 |
hsizer.Add( |
| 528 |
wx.StaticText(panel, -1, lang.getstr("tc.dark_emphasis")), |
| 529 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 530 |
border=border, |
| 531 |
) |
| 532 |
self.tc_dark_emphasis_slider = wx.Slider( |
| 533 |
panel, |
| 534 |
-1, |
| 535 |
0, |
| 536 |
0, |
| 537 |
100, |
| 538 |
size=(64 * scale, -1), |
| 539 |
name="tc_dark_emphasis_slider", |
| 540 |
) |
| 541 |
self.tc_dark_emphasis_slider.Disable() |
| 542 |
self.Bind( |
| 543 |
wx.EVT_SLIDER, |
| 544 |
self.tc_dark_emphasis_handler, |
| 545 |
id=self.tc_dark_emphasis_slider.GetId(), |
| 546 |
) |
| 547 |
hsizer.Add(self.tc_dark_emphasis_slider, flag=wx.ALIGN_CENTER_VERTICAL) |
| 548 |
self.tc_dark_emphasis_intctrl = wx.SpinCtrl( |
| 549 |
panel, |
| 550 |
-1, |
| 551 |
size=(100 * scale, -1), |
| 552 |
min=0, |
| 553 |
max=100, |
| 554 |
name="tc_dark_emphasis_intctrl", |
| 555 |
) |
| 556 |
self.tc_dark_emphasis_intctrl.Disable() |
| 557 |
self.Bind( |
| 558 |
wx.EVT_TEXT, |
| 559 |
self.tc_dark_emphasis_handler, |
| 560 |
id=self.tc_dark_emphasis_intctrl.GetId(), |
| 561 |
) |
| 562 |
hsizer.Add( |
| 563 |
self.tc_dark_emphasis_intctrl, |
| 564 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 565 |
border=border, |
| 566 |
) |
| 567 |
hsizer.Add( |
| 568 |
wx.StaticText(panel, -1, "%"), |
| 569 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 570 |
border=border, |
| 571 |
) |
| 572 |
|
| 573 |
# precond profile |
| 574 |
hsizer = wx.BoxSizer(wx.HORIZONTAL) |
| 575 |
self.sizer.Add( |
| 576 |
hsizer, flag=wx.ALL & ~(wx.BOTTOM | wx.TOP) | wx.EXPAND, border=12 |
| 577 |
) |
| 578 |
self.tc_precond = wx.CheckBox( |
| 579 |
panel, -1, lang.getstr("tc.precond"), name="tc_precond" |
| 580 |
) |
| 581 |
self.tc_precond.Disable() |
| 582 |
self.Bind(wx.EVT_CHECKBOX, self.tc_precond_handler, id=self.tc_precond.GetId()) |
| 583 |
hsizer.Add( |
| 584 |
self.tc_precond, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 585 |
) |
| 586 |
self.tc_precond_profile = FileBrowseBitmapButtonWithChoiceHistory( |
| 587 |
panel, |
| 588 |
-1, |
| 589 |
toolTip=lang.getstr("tc.precond"), |
| 590 |
dialogTitle=lang.getstr("tc.precond"), |
| 591 |
fileMask=lang.getstr("filetype.icc_mpp") + "|*.icc;*.icm;*.mpp", |
| 592 |
changeCallback=self.tc_precond_profile_handler, |
| 593 |
history=get_data_path("ref", r"\.(icm|icc)$"), |
| 594 |
) |
| 595 |
self.tc_precond_profile.SetMaxFontSize(11) |
| 596 |
hsizer.Add( |
| 597 |
self.tc_precond_profile, |
| 598 |
1, |
| 599 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 600 |
border=border, |
| 601 |
) |
| 602 |
|
| 603 |
self.tc_precond_profile_current_btn = wx.Button( |
| 604 |
panel, -1, lang.getstr("profile.current"), name="tc_precond_profile_current" |
| 605 |
) |
| 606 |
self.Bind( |
| 607 |
wx.EVT_BUTTON, |
| 608 |
self.tc_precond_profile_current_ctrl_handler, |
| 609 |
id=self.tc_precond_profile_current_btn.GetId(), |
| 610 |
) |
| 611 |
hsizer.Add( |
| 612 |
self.tc_precond_profile_current_btn, |
| 613 |
0, |
| 614 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 615 |
border=border, |
| 616 |
) |
| 617 |
self.precond_droptarget = FileDrop(self) |
| 618 |
self.precond_droptarget.drophandlers = { |
| 619 |
".icc": self.precond_profile_drop_handler, |
| 620 |
".icm": self.precond_profile_drop_handler, |
| 621 |
} |
| 622 |
self.tc_precond_profile.SetDropTarget(self.precond_droptarget) |
| 623 |
|
| 624 |
# limit samples to lab sphere |
| 625 |
hsizer = wx.BoxSizer(wx.HORIZONTAL) |
| 626 |
self.sizer.Add(hsizer, flag=wx.ALL & ~(wx.BOTTOM | wx.TOP), border=12) |
| 627 |
self.tc_filter = wx.CheckBox( |
| 628 |
panel, -1, lang.getstr("tc.limit.sphere"), name="tc_filter" |
| 629 |
) |
| 630 |
self.Bind(wx.EVT_CHECKBOX, self.tc_filter_handler, id=self.tc_filter.GetId()) |
| 631 |
hsizer.Add( |
| 632 |
self.tc_filter, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 633 |
) |
| 634 |
# L |
| 635 |
hsizer.Add( |
| 636 |
wx.StaticText(panel, -1, "L"), |
| 637 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 638 |
border=border, |
| 639 |
) |
| 640 |
self.tc_filter_L = wx.SpinCtrl( |
| 641 |
panel, |
| 642 |
-1, |
| 643 |
initial=50, |
| 644 |
size=(100 * scale, -1), |
| 645 |
min=0, |
| 646 |
max=100, |
| 647 |
name="tc_filter_L", |
| 648 |
) |
| 649 |
self.Bind(wx.EVT_TEXT, self.tc_filter_handler, id=self.tc_filter_L.GetId()) |
| 650 |
hsizer.Add( |
| 651 |
self.tc_filter_L, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 652 |
) |
| 653 |
# a |
| 654 |
hsizer.Add( |
| 655 |
wx.StaticText(panel, -1, "a"), |
| 656 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 657 |
border=border, |
| 658 |
) |
| 659 |
self.tc_filter_a = wx.SpinCtrl( |
| 660 |
panel, |
| 661 |
-1, |
| 662 |
initial=0, |
| 663 |
size=(100 * scale, -1), |
| 664 |
min=-128, |
| 665 |
max=127, |
| 666 |
name="tc_filter_a", |
| 667 |
) |
| 668 |
self.Bind(wx.EVT_TEXT, self.tc_filter_handler, id=self.tc_filter_a.GetId()) |
| 669 |
hsizer.Add( |
| 670 |
self.tc_filter_a, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 671 |
) |
| 672 |
# b |
| 673 |
hsizer.Add( |
| 674 |
wx.StaticText(panel, -1, "b"), |
| 675 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 676 |
border=border, |
| 677 |
) |
| 678 |
self.tc_filter_b = wx.SpinCtrl( |
| 679 |
panel, |
| 680 |
-1, |
| 681 |
initial=0, |
| 682 |
size=(100 * scale, -1), |
| 683 |
min=-128, |
| 684 |
max=127, |
| 685 |
name="tc_filter_b", |
| 686 |
) |
| 687 |
self.Bind(wx.EVT_TEXT, self.tc_filter_handler, id=self.tc_filter_b.GetId()) |
| 688 |
hsizer.Add( |
| 689 |
self.tc_filter_b, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 690 |
) |
| 691 |
# radius |
| 692 |
hsizer.Add( |
| 693 |
wx.StaticText(panel, -1, lang.getstr("tc.limit.sphere_radius")), |
| 694 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 695 |
border=border, |
| 696 |
) |
| 697 |
self.tc_filter_rad = wx.SpinCtrl( |
| 698 |
panel, |
| 699 |
-1, |
| 700 |
initial=255, |
| 701 |
size=(100 * scale, -1), |
| 702 |
min=1, |
| 703 |
max=255, |
| 704 |
name="tc_filter_rad", |
| 705 |
) |
| 706 |
self.Bind(wx.EVT_TEXT, self.tc_filter_handler, id=self.tc_filter_rad.GetId()) |
| 707 |
hsizer.Add( |
| 708 |
self.tc_filter_rad, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 709 |
) |
| 710 |
|
| 711 |
# diagnostic VRML files |
| 712 |
hsizer = wx.BoxSizer(wx.HORIZONTAL) |
| 713 |
self.sizer.Add(hsizer, flag=wx.ALL & ~(wx.BOTTOM | wx.TOP), border=12 + border) |
| 714 |
|
| 715 |
self.vrml_save_as_btn = wx.BitmapButton(panel, -1, get_icon(16, "3D")) |
| 716 |
if sys.platform == "darwin": |
| 717 |
# Work-around bitmap cutoff on left and right side |
| 718 |
w = self.vrml_save_as_btn.Size[0] + 4 |
| 719 |
else: |
| 720 |
w = -1 |
| 721 |
self.vrml_save_as_btn.MinSize = (w, -1) |
| 722 |
self.vrml_save_as_btn.SetToolTipString(lang.getstr("tc.3d")) |
| 723 |
self.vrml_save_as_btn.Disable() |
| 724 |
self.Bind(wx.EVT_BUTTON, self.tc_view_3d, id=self.vrml_save_as_btn.GetId()) |
| 725 |
self.vrml_save_as_btn.Bind(wx.EVT_CONTEXT_MENU, self.view_3d_format_popup) |
| 726 |
hsizer.Add( |
| 727 |
self.vrml_save_as_btn, |
| 728 |
flag=wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, |
| 729 |
border=border * 2, |
| 730 |
) |
| 731 |
hsizer.Add((1, 1)) |
| 732 |
self.view_3d_format_btn = wx.BitmapButton( |
| 733 |
panel, -1, get_bitmap("theme/dropdown-arrow") |
| 734 |
) |
| 735 |
if sys.platform == "darwin": |
| 736 |
# Work-around bitmap cutoff on left and right side |
| 737 |
w = self.view_3d_format_btn.Size[0] + 4 |
| 738 |
else: |
| 739 |
w = -1 |
| 740 |
self.view_3d_format_btn.MinSize = (w, self.vrml_save_as_btn.Size[1]) |
| 741 |
self.view_3d_format_btn.Bind(wx.EVT_BUTTON, self.view_3d_format_popup) |
| 742 |
self.view_3d_format_btn.Bind(wx.EVT_CONTEXT_MENU, self.view_3d_format_popup) |
| 743 |
self.view_3d_format_btn.SetToolTipString(lang.getstr("tc.3d")) |
| 744 |
self.view_3d_format_btn.Disable() |
| 745 |
hsizer.Add( |
| 746 |
self.view_3d_format_btn, |
| 747 |
flag=(wx.ALL & ~wx.LEFT) | wx.ALIGN_CENTER_VERTICAL, |
| 748 |
border=border * 2, |
| 749 |
) |
| 750 |
self.tc_vrml_cie = wx.CheckBox( |
| 751 |
panel, -1, "", name="tc_vrml_cie", style=wx.RB_GROUP |
| 752 |
) |
| 753 |
self.tc_vrml_cie.SetToolTipString(lang.getstr("tc.3d")) |
| 754 |
self.Bind(wx.EVT_CHECKBOX, self.tc_vrml_handler, id=self.tc_vrml_cie.GetId()) |
| 755 |
hsizer.Add( |
| 756 |
self.tc_vrml_cie, |
| 757 |
flag=(wx.ALL & ~wx.LEFT) | wx.ALIGN_CENTER_VERTICAL, |
| 758 |
border=border * 2, |
| 759 |
) |
| 760 |
self.tc_vrml_cie_colorspace_ctrl = wx.Choice( |
| 761 |
panel, -1, choices=config.VALID_VALUES["tc_vrml_cie_colorspace"] |
| 762 |
) |
| 763 |
self.tc_vrml_cie_colorspace_ctrl.SetToolTipString(lang.getstr("tc.3d")) |
| 764 |
self.Bind( |
| 765 |
wx.EVT_CHOICE, |
| 766 |
self.tc_vrml_handler, |
| 767 |
id=self.tc_vrml_cie_colorspace_ctrl.GetId(), |
| 768 |
) |
| 769 |
hsizer.Add( |
| 770 |
self.tc_vrml_cie_colorspace_ctrl, |
| 771 |
flag=(wx.ALL & ~wx.LEFT) | wx.ALIGN_CENTER_VERTICAL, |
| 772 |
border=border * 2, |
| 773 |
) |
| 774 |
self.tc_vrml_device = wx.CheckBox(panel, -1, "", name="tc_vrml_device") |
| 775 |
self.tc_vrml_device.SetToolTipString(lang.getstr("tc.3d")) |
| 776 |
self.Bind(wx.EVT_CHECKBOX, self.tc_vrml_handler, id=self.tc_vrml_device.GetId()) |
| 777 |
hsizer.Add( |
| 778 |
self.tc_vrml_device, |
| 779 |
flag=(wx.ALL & ~wx.LEFT) | wx.ALIGN_CENTER_VERTICAL, |
| 780 |
border=border * 2, |
| 781 |
) |
| 782 |
self.tc_vrml_device_colorspace_ctrl = wx.Choice( |
| 783 |
panel, -1, choices=config.VALID_VALUES["tc_vrml_device_colorspace"] |
| 784 |
) |
| 785 |
self.tc_vrml_device_colorspace_ctrl.SetToolTipString(lang.getstr("tc.3d")) |
| 786 |
self.Bind( |
| 787 |
wx.EVT_CHOICE, |
| 788 |
self.tc_vrml_handler, |
| 789 |
id=self.tc_vrml_device_colorspace_ctrl.GetId(), |
| 790 |
) |
| 791 |
hsizer.Add( |
| 792 |
self.tc_vrml_device_colorspace_ctrl, |
| 793 |
flag=(wx.ALL & ~wx.LEFT) | wx.ALIGN_CENTER_VERTICAL, |
| 794 |
border=border * 2, |
| 795 |
) |
| 796 |
|
| 797 |
hsizer.Add( |
| 798 |
wx.StaticText(panel, -1, lang.getstr("tc.vrml.black_offset")), |
| 799 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 800 |
border=border, |
| 801 |
) |
| 802 |
self.tc_vrml_black_offset_intctrl = wx.SpinCtrl( |
| 803 |
panel, |
| 804 |
-1, |
| 805 |
size=(90 * scale, -1), |
| 806 |
min=0, |
| 807 |
max=40, |
| 808 |
name="tc_vrml_black_offset_intctrl", |
| 809 |
) |
| 810 |
self.Bind( |
| 811 |
wx.EVT_TEXT, |
| 812 |
self.tc_vrml_black_offset_ctrl_handler, |
| 813 |
id=self.tc_vrml_black_offset_intctrl.GetId(), |
| 814 |
) |
| 815 |
hsizer.Add( |
| 816 |
self.tc_vrml_black_offset_intctrl, |
| 817 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 818 |
border=border, |
| 819 |
) |
| 820 |
self.tc_vrml_use_D50_cb = wx.CheckBox( |
| 821 |
panel, -1, lang.getstr("tc.vrml.use_D50"), name="tc_vrml_use_D50_cb" |
| 822 |
) |
| 823 |
self.Bind( |
| 824 |
wx.EVT_CHECKBOX, |
| 825 |
self.tc_vrml_use_D50_handler, |
| 826 |
id=self.tc_vrml_use_D50_cb.GetId(), |
| 827 |
) |
| 828 |
hsizer.Add( |
| 829 |
self.tc_vrml_use_D50_cb, |
| 830 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 831 |
border=border, |
| 832 |
) |
| 833 |
self.tc_vrml_compress_cb = wx.CheckBox( |
| 834 |
panel, -1, lang.getstr("compression.gzip"), name="tc_vrml_compress_cb" |
| 835 |
) |
| 836 |
self.Bind( |
| 837 |
wx.EVT_CHECKBOX, |
| 838 |
self.tc_vrml_compress_handler, |
| 839 |
id=self.tc_vrml_compress_cb.GetId(), |
| 840 |
) |
| 841 |
hsizer.Add( |
| 842 |
self.tc_vrml_compress_cb, |
| 843 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 844 |
border=border, |
| 845 |
) |
| 846 |
|
| 847 |
# buttons |
| 848 |
hsizer = wx.BoxSizer(wx.HORIZONTAL) |
| 849 |
self.sizer.Add(hsizer, flag=(wx.ALL & ~wx.BOTTOM) | wx.ALIGN_CENTER, border=12) |
| 850 |
|
| 851 |
self.preview_btn = wx.Button( |
| 852 |
panel, -1, lang.getstr("testchart.create"), name="tc_create" |
| 853 |
) |
| 854 |
self.Bind(wx.EVT_BUTTON, self.tc_preview_handler, id=self.preview_btn.GetId()) |
| 855 |
hsizer.Add( |
| 856 |
self.preview_btn, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 857 |
) |
| 858 |
|
| 859 |
self.save_btn = wx.Button(panel, -1, lang.getstr("save")) |
| 860 |
self.save_btn.Disable() |
| 861 |
self.Bind(wx.EVT_BUTTON, self.tc_save_handler, id=self.save_btn.GetId()) |
| 862 |
hsizer.Add(self.save_btn, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border) |
| 863 |
|
| 864 |
self.save_as_btn = wx.Button(panel, -1, lang.getstr("save_as")) |
| 865 |
self.save_as_btn.Disable() |
| 866 |
self.Bind(wx.EVT_BUTTON, self.tc_save_as_handler, id=self.save_as_btn.GetId()) |
| 867 |
hsizer.Add( |
| 868 |
self.save_as_btn, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 869 |
) |
| 870 |
|
| 871 |
self.export_btn = wx.Button(panel, -1, lang.getstr("export"), name="tc_export") |
| 872 |
self.export_btn.Disable() |
| 873 |
self.Bind(wx.EVT_BUTTON, self.tc_export_handler, id=self.export_btn.GetId()) |
| 874 |
hsizer.Add( |
| 875 |
self.export_btn, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 876 |
) |
| 877 |
|
| 878 |
self.clear_btn = wx.Button( |
| 879 |
panel, -1, lang.getstr("testchart.discard"), name="tc_clear" |
| 880 |
) |
| 881 |
self.clear_btn.Disable() |
| 882 |
self.Bind(wx.EVT_BUTTON, self.tc_clear_handler, id=self.clear_btn.GetId()) |
| 883 |
hsizer.Add( |
| 884 |
self.clear_btn, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 885 |
) |
| 886 |
|
| 887 |
# buttons row 2 |
| 888 |
hsizer = wx.BoxSizer(wx.HORIZONTAL) |
| 889 |
self.sizer.Add(hsizer, flag=wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT, border=12) |
| 890 |
|
| 891 |
hsizer.Add( |
| 892 |
wx.StaticText(panel, -1, lang.getstr("testchart.add_saturation_sweeps")), |
| 893 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 894 |
border=border, |
| 895 |
) |
| 896 |
self.saturation_sweeps_intctrl = wx.SpinCtrl( |
| 897 |
panel, |
| 898 |
-1, |
| 899 |
size=(95 * scale, -1), |
| 900 |
initial=getcfg("tc.saturation_sweeps"), |
| 901 |
min=2, |
| 902 |
max=255, |
| 903 |
) |
| 904 |
self.saturation_sweeps_intctrl.Disable() |
| 905 |
hsizer.Add( |
| 906 |
self.saturation_sweeps_intctrl, |
| 907 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 908 |
border=border, |
| 909 |
) |
| 910 |
|
| 911 |
for color in ("R", "G", "B", "C", "M", "Y"): |
| 912 |
name = f"saturation_sweeps_{color}_btn" |
| 913 |
setattr(self, name, wx.Button(panel, -1, color, size=(45 * scale, -1))) |
| 914 |
getattr(self, f"saturation_sweeps_{color}_btn").Disable() |
| 915 |
self.Bind( |
| 916 |
wx.EVT_BUTTON, |
| 917 |
self.tc_add_saturation_sweeps_handler, |
| 918 |
id=getattr(self, name).GetId(), |
| 919 |
) |
| 920 |
hsizer.Add( |
| 921 |
getattr(self, name), |
| 922 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 923 |
border=border, |
| 924 |
) |
| 925 |
|
| 926 |
self.saturation_sweeps_custom_btn = wx.Button( |
| 927 |
panel, -1, "=", size=(45 * scale, -1) |
| 928 |
) |
| 929 |
self.saturation_sweeps_custom_btn.Disable() |
| 930 |
self.Bind( |
| 931 |
wx.EVT_BUTTON, |
| 932 |
self.tc_add_saturation_sweeps_handler, |
| 933 |
id=self.saturation_sweeps_custom_btn.GetId(), |
| 934 |
) |
| 935 |
hsizer.Add( |
| 936 |
self.saturation_sweeps_custom_btn, |
| 937 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 938 |
border=border, |
| 939 |
) |
| 940 |
for component in ("R", "G", "B"): |
| 941 |
hsizer.Add( |
| 942 |
wx.StaticText(panel, -1, component), |
| 943 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 944 |
border=border, |
| 945 |
) |
| 946 |
name = f"saturation_sweeps_custom_{component}_ctrl" |
| 947 |
setattr( |
| 948 |
self, |
| 949 |
name, |
| 950 |
floatspin.FloatSpin( |
| 951 |
panel, |
| 952 |
-1, |
| 953 |
size=(100 * scale, -1), |
| 954 |
value=getcfg(f"tc.saturation_sweeps.custom.{component}"), |
| 955 |
min_val=0, |
| 956 |
max_val=100, |
| 957 |
increment=100.0 / 255, |
| 958 |
digits=2, |
| 959 |
), |
| 960 |
) |
| 961 |
getattr(self, f"saturation_sweeps_custom_{component}_ctrl").Disable() |
| 962 |
self.Bind( |
| 963 |
floatspin.EVT_FLOATSPIN, |
| 964 |
self.tc_algo_handler, |
| 965 |
id=getattr(self, name).GetId(), |
| 966 |
) |
| 967 |
hsizer.Add( |
| 968 |
getattr(self, name), |
| 969 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 970 |
border=border, |
| 971 |
) |
| 972 |
|
| 973 |
# buttons row 3 |
| 974 |
hsizer = wx.BoxSizer(wx.HORIZONTAL) |
| 975 |
self.sizer.Add(hsizer, flag=wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT, border=12) |
| 976 |
|
| 977 |
self.add_ti3_btn = wx.Button( |
| 978 |
panel, -1, lang.getstr("testchart.add_ti3_patches") |
| 979 |
) |
| 980 |
self.add_ti3_btn.Disable() |
| 981 |
self.Bind(wx.EVT_BUTTON, self.tc_add_ti3_handler, id=self.add_ti3_btn.GetId()) |
| 982 |
hsizer.Add( |
| 983 |
self.add_ti3_btn, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=border |
| 984 |
) |
| 985 |
self.add_ti3_relative_cb = wx.CheckBox( |
| 986 |
panel, -1, lang.getstr("whitepoint.simulate.relative") |
| 987 |
) |
| 988 |
self.add_ti3_relative_cb.Disable() |
| 989 |
self.Bind( |
| 990 |
wx.EVT_CHECKBOX, |
| 991 |
self.tc_add_ti3_relative_handler, |
| 992 |
id=self.add_ti3_relative_cb.GetId(), |
| 993 |
) |
| 994 |
hsizer.Add( |
| 995 |
self.add_ti3_relative_cb, |
| 996 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 997 |
border=border, |
| 998 |
) |
| 999 |
hsizer.Add((50, 1)) |
| 1000 |
|
| 1001 |
lstrs = ( |
| 1002 |
"testchart.sort_RGB_gray_to_top", |
| 1003 |
"testchart.sort_RGB_white_to_top", |
| 1004 |
"testchart.sort_RGB_red_to_top", |
| 1005 |
"testchart.sort_RGB_green_to_top", |
| 1006 |
"testchart.sort_RGB_blue_to_top", |
| 1007 |
"testchart.sort_RGB_cyan_to_top", |
| 1008 |
"testchart.sort_RGB_magenta_to_top", |
| 1009 |
"testchart.sort_RGB_yellow_to_top", |
| 1010 |
"testchart.sort_by_HSI", |
| 1011 |
"testchart.sort_by_HSL", |
| 1012 |
"testchart.sort_by_HSV", |
| 1013 |
"testchart.sort_by_L", |
| 1014 |
"testchart.sort_by_rec709_luma", |
| 1015 |
"testchart.sort_by_RGB", |
| 1016 |
"testchart.sort_by_RGB_sum", |
| 1017 |
"testchart.sort_by_BGR", |
| 1018 |
"testchart.optimize_display_response_delay", |
| 1019 |
"testchart.interleave", |
| 1020 |
"testchart.shift_interleave", |
| 1021 |
"testchart.maximize_lightness_difference", |
| 1022 |
"testchart.maximize_rec709_luma_difference", |
| 1023 |
"testchart.maximize_RGB_difference", |
| 1024 |
"testchart.vary_RGB_difference", |
| 1025 |
) |
| 1026 |
patch_order_choices = [lang.getstr(lstr) for lstr in lstrs] |
| 1027 |
self.change_patch_order_ctrl = wx.Choice(panel, -1, choices=patch_order_choices) |
| 1028 |
self.change_patch_order_ctrl.SetSelection(0) |
| 1029 |
self.change_patch_order_ctrl.SetToolTipString( |
| 1030 |
lang.getstr("testchart.change_patch_order") |
| 1031 |
) |
| 1032 |
hsizer.Add( |
| 1033 |
self.change_patch_order_ctrl, |
| 1034 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 1035 |
border=border, |
| 1036 |
) |
| 1037 |
|
| 1038 |
self.change_patch_order_btn = wx.Button(panel, -1, lang.getstr("apply")) |
| 1039 |
self.Bind( |
| 1040 |
wx.EVT_BUTTON, self.tc_sort_handler, id=self.change_patch_order_btn.GetId() |
| 1041 |
) |
| 1042 |
hsizer.Add( |
| 1043 |
self.change_patch_order_btn, |
| 1044 |
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, |
| 1045 |
border=border, |
| 1046 |
) |
| 1047 |
|
| 1048 |
# grid |
| 1049 |
self.sizer.Add((-1, 12)) |
| 1050 |
use_native_grid = sys.version_info >= (3, 10) |
| 1051 |
grid_cls = wx.grid.Grid if use_native_grid else CustomGrid |
| 1052 |
self.grid = grid_cls(panel, -1, size=(-1, 100)) |
| 1053 |
self.grid.DisableDragColSize() |
| 1054 |
self.grid.EnableGridLines(False) |
| 1055 |
self.grid.SetCellHighlightPenWidth(0) |
| 1056 |
self.grid.SetCellHighlightROPenWidth(0) |
| 1057 |
self.grid.SetColLabelSize(self.grid.GetDefaultRowSize()) |
| 1058 |
self.grid.SetDefaultCellAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER) |
| 1059 |
self.grid.SetRowLabelAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER) |
| 1060 |
self.grid.SetScrollRate(0, 5) |
| 1061 |
if hasattr(self.grid, "draw_horizontal_grid_lines"): |
| 1062 |
self.grid.draw_horizontal_grid_lines = False |
| 1063 |
if hasattr(self.grid, "draw_vertical_grid_lines"): |
| 1064 |
self.grid.draw_vertical_grid_lines = False |
| 1065 |
self.sizer.Add(self.grid, 1, flag=wx.EXPAND) |
| 1066 |
self.grid.CreateGrid(0, 0) |
| 1067 |
font = self.grid.GetDefaultCellFont() |
| 1068 |
if font.PointSize > 11: |
| 1069 |
font.PointSize = 11 |
| 1070 |
self.grid.SetDefaultCellFont(font) |
| 1071 |
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.tc_grid_cell_change_handler) |
| 1072 |
self.grid.Bind( |
| 1073 |
wx.grid.EVT_GRID_LABEL_LEFT_CLICK, self.tc_grid_label_left_click_handler |
| 1074 |
) |
| 1075 |
self.grid.Bind( |
| 1076 |
wx.grid.EVT_GRID_LABEL_LEFT_DCLICK, self.tc_grid_label_left_dclick_handler |
| 1077 |
) |
| 1078 |
self.grid.Bind(wx.grid.EVT_GRID_RANGE_SELECT, self.tc_grid_range_select_handler) |
| 1079 |
self.grid.DisableDragRowSize() |
| 1080 |
if TC_USE_ALTERNATE_PREVIEW: |
| 1081 |
separator_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DSHADOW) |
| 1082 |
separator = wx.Panel(panel, size=(-1, 1)) |
| 1083 |
separator.BackgroundColour = separator_color |
| 1084 |
self.sizer.Add(separator, flag=wx.EXPAND) |
| 1085 |
|
| 1086 |
# preview area |
| 1087 |
if TC_USE_ALTERNATE_PREVIEW: |
| 1088 |
self.sizer.SetSizeHints(self) |
| 1089 |
self.sizer.Layout() |
| 1090 |
self.sizer.SetMinSize((self.sizer.MinSize[0], self.sizer.MinSize[1] + 1)) |
| 1091 |
p1.SetMinSize(self.sizer.MinSize) |
| 1092 |
splitter.SplitHorizontally(p1, p2, self.sizer.GetMinSize()[1]) |
| 1093 |
hsizer = wx.BoxSizer(wx.VERTICAL) |
| 1094 |
gradientpanel = get_gradient_panel(p2, lang.getstr("preview")) |
| 1095 |
gradientpanel.MinSize = (-1, 23 * scale) |
| 1096 |
p2.sizer.Add(gradientpanel, flag=wx.EXPAND) |
| 1097 |
p2.sizer.Add(hsizer, 1, flag=wx.EXPAND) |
| 1098 |
p2.BackgroundColour = "#333333" |
| 1099 |
preview = grid_cls(p2, -1, size=(-1, 100)) |
| 1100 |
preview.DisableDragColSize() |
| 1101 |
preview.DisableDragRowSize() |
| 1102 |
preview.EnableEditing(False) |
| 1103 |
preview.EnableGridLines(False) |
| 1104 |
preview.SetCellHighlightPenWidth(0) |
| 1105 |
preview.SetCellHighlightROPenWidth(0) |
| 1106 |
preview.SetColLabelSize(self.grid.GetDefaultRowSize()) |
| 1107 |
preview.SetDefaultCellAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER) |
| 1108 |
preview.SetRowLabelAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER) |
| 1109 |
preview.SetLabelTextColour("#CCCCCC") |
| 1110 |
preview.SetScrollRate(0, 5) |
| 1111 |
if hasattr(preview, "_default_col_label_renderer"): |
| 1112 |
preview._default_col_label_renderer.bgcolor = "#333333" |
| 1113 |
if hasattr(preview, "_default_row_label_renderer"): |
| 1114 |
preview._default_row_label_renderer.bgcolor = "#333333" |
| 1115 |
preview.alternate_cell_background_color = False |
| 1116 |
preview.alternate_row_label_background_color = False |
| 1117 |
if hasattr(preview, "draw_horizontal_grid_lines"): |
| 1118 |
preview.draw_horizontal_grid_lines = False |
| 1119 |
if hasattr(preview, "draw_vertical_grid_lines"): |
| 1120 |
preview.draw_vertical_grid_lines = False |
| 1121 |
if hasattr(preview, "rendernative"): |
| 1122 |
preview.rendernative = False |
| 1123 |
if hasattr(preview, "style"): |
| 1124 |
preview.style = "" |
| 1125 |
preview.CreateGrid(0, 0) |
| 1126 |
font = preview.GetDefaultCellFont() |
| 1127 |
if font.PointSize > 11: |
| 1128 |
font.PointSize = 11 |
| 1129 |
preview.SetDefaultCellFont(font) |
| 1130 |
preview.SetLabelFont(font) |
| 1131 |
preview.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.tc_mouseclick_handler) |
| 1132 |
self.preview = preview |
| 1133 |
preview.SetDefaultCellBackgroundColour("#333333") |
| 1134 |
preview.SetLabelBackgroundColour("#333333") |
| 1135 |
hsizer.Add(preview, 1, wx.EXPAND) |
| 1136 |
|
| 1137 |
panel = p2 |
| 1138 |
|
| 1139 |
if sys.platform not in ("darwin", "win32"): |
| 1140 |
separator_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DSHADOW) |
| 1141 |
separator = wx.Panel(panel, size=(-1, 1)) |
| 1142 |
separator.BackgroundColour = separator_color |
| 1143 |
panel.Sizer.Add(separator, flag=wx.EXPAND) |
| 1144 |
|
| 1145 |
# status |
| 1146 |
status = wx.StatusBar(self, -1) |
| 1147 |
status.SetStatusStyles([wx.SB_FLAT]) |
| 1148 |
self.SetStatusBar(status) |
| 1149 |
|
| 1150 |
# layout |
| 1151 |
if TC_USE_ALTERNATE_PREVIEW: |
| 1152 |
self.SetMinSize( |
| 1153 |
( |
| 1154 |
self.GetMinSize()[0], |
| 1155 |
self.GetMinSize()[1] + splitter.SashSize + p2.sizer.MinSize[1], |
| 1156 |
) |
| 1157 |
) |
| 1158 |
else: |
| 1159 |
self.sizer.SetSizeHints(self) |
| 1160 |
self.sizer.Layout() |
| 1161 |
|
| 1162 |
DEFAULTS.update( |
| 1163 |
{ |
| 1164 |
"position.tcgen.x": self.GetDisplay().ClientArea[0] + 40, |
| 1165 |
"position.tcgen.y": self.GetDisplay().ClientArea[1] + 60, |
| 1166 |
"size.tcgen.w": self.ClientSize[0], |
| 1167 |
"size.tcgen.h": self.ClientSize[1], |
| 1168 |
} |
| 1169 |
) |
| 1170 |
|
| 1171 |
if ( |
| 1172 |
hascfg("position.tcgen.x") |
| 1173 |
and hascfg("position.tcgen.y") |
| 1174 |
and hascfg("size.tcgen.w") |
| 1175 |
and hascfg("size.tcgen.h") |
| 1176 |
): |
| 1177 |
self.SetSaneGeometry( |
| 1178 |
int(getcfg("position.tcgen.x")), |
| 1179 |
int(getcfg("position.tcgen.y")), |
| 1180 |
int(getcfg("size.tcgen.w")), |
| 1181 |
int(getcfg("size.tcgen.h")), |
| 1182 |
) |
| 1183 |
else: |
| 1184 |
self.Center() |
| 1185 |
|
| 1186 |
self.tc_size_handler() |
| 1187 |
|
| 1188 |
children = list(self.GetAllChildren()) |
| 1189 |
|
| 1190 |
for child in children: |
| 1191 |
if hasattr(child, "SetFont"): |
| 1192 |
child.SetMaxFontSize(11) |
| 1193 |
child.Bind(wx.EVT_KEY_DOWN, self.tc_key_handler) |
| 1194 |
if ( |
| 1195 |
sys.platform == "win32" |
| 1196 |
and sys.getwindowsversion() >= (6,) |
| 1197 |
and isinstance(child, wx.Panel) |
| 1198 |
): |
| 1199 |
# No need to enable double buffering under Linux and Mac OS X. |
| 1200 |
# Under Windows, enabling double buffering on the panel seems |
| 1201 |
# to work best to reduce flicker. |
| 1202 |
child.SetDoubleBuffered(True) |
| 1203 |
self.Bind(wx.EVT_MOVE, self.tc_move_handler) |
| 1204 |
self.Bind(wx.EVT_SIZE, self.tc_size_handler, self) |
| 1205 |
self.Bind(wx.EVT_MAXIMIZE, self.tc_size_handler, self) |
| 1206 |
|
| 1207 |
self.Children[0].Bind(wx.EVT_WINDOW_DESTROY, self.tc_destroy_handler) |
| 1208 |
|
| 1209 |
self.tc_update_controls() |
| 1210 |
self.tc_check() |
| 1211 |
if path is not False: |
| 1212 |
wx.CallAfter(self.tc_load_cfg_from_ti1, None, path) |
| 1213 |
|
| 1214 |
def csv_drop_handler(self, path): |
| 1215 |
"""Handle dropping a CSV file onto the test chart editor. |
| 1216 |
|
| 1217 |
Args: |
| 1218 |
path (str): The file path of the dropped CSV file. |
| 1219 |
""" |
| 1220 |
if self.worker.is_working(): |
| 1221 |
return |
| 1222 |
if not self.tc_check_save_ti1(): |
| 1223 |
return |
| 1224 |
self.worker.start( |
| 1225 |
self.csv_convert_finish, |
| 1226 |
self.csv_convert, |
| 1227 |
wargs=(path,), |
| 1228 |
progress_msg=lang.getstr("testchart.read"), |
| 1229 |
parent=self, |
| 1230 |
progress_start=500, |
| 1231 |
cancelable=False, |
| 1232 |
continue_next=True, |
| 1233 |
show_remaining_time=False, |
| 1234 |
fancy=False, |
| 1235 |
) |
| 1236 |
|
| 1237 |
def csv_convert(self, path): |
| 1238 |
"""Convert a CSV file to a temporary TI1 file. |
| 1239 |
|
| 1240 |
Args: |
| 1241 |
path (str): The file path of the CSV file to convert. |
| 1242 |
|
| 1243 |
Returns: |
| 1244 |
CGATS or Exception: The converted CGATS object or an exception if |
| 1245 |
an error occurred. |
| 1246 |
""" |
| 1247 |
# Read CSV file and get rows |
| 1248 |
rows = [] |
| 1249 |
maxval = 100.0 |
| 1250 |
try: |
| 1251 |
with open(path, "rb") as csvfile: |
| 1252 |
sniffer = csv.Sniffer() |
| 1253 |
rawcsv = csvfile.read() |
| 1254 |
dialect = sniffer.sniff(rawcsv, delimiters=",;\t") |
| 1255 |
has_header = sniffer.has_header(rawcsv) |
| 1256 |
csvfile.seek(0) |
| 1257 |
for i, row in enumerate(csv.reader(csvfile, dialect=dialect)): |
| 1258 |
if has_header: |
| 1259 |
continue |
| 1260 |
if len(row) == 3 or len(row) == 6: |
| 1261 |
# Add row number before first column |
| 1262 |
row.insert(0, i) |
| 1263 |
if len(row) not in (4, 7): |
| 1264 |
raise ValueError(lang.getstr("error.testchart.invalid", path)) |
| 1265 |
row = [int(row[0])] + [float(v) for v in row[1:]] |
| 1266 |
for v in row[1:]: |
| 1267 |
maxval = max(maxval, v) |
| 1268 |
rows.append(row) |
| 1269 |
except Exception as exception: |
| 1270 |
result = exception |
| 1271 |
else: |
| 1272 |
# Scale to 0..100 if actual value range is different |
| 1273 |
if maxval > 100: |
| 1274 |
for i, row in enumerate(rows): |
| 1275 |
rows[i][1:] = [v / maxval * 100 for v in row[1:]] |
| 1276 |
# Create temporary TI1 |
| 1277 |
ti1 = CGATS( |
| 1278 |
"""CTI1 |
| 1279 |
KEYWORD "COLOR_REP" |
| 1280 |
COLOR_REP "RGB" |
| 1281 |
NUMBER_OF_FIELDS 7 |
| 1282 |
BEGIN_DATA_FORMAT |
| 1283 |
SAMPLE_ID RGB_R RGB_G RGB_B XYZ_X XYZ_Y XYZ_Z |
| 1284 |
END_DATA_FORMAT |
| 1285 |
NUMBER_OF_SETS 4 |
| 1286 |
BEGIN_DATA |
| 1287 |
END_DATA""" |
| 1288 |
) |
| 1289 |
# Add rows to TI1 |
| 1290 |
data = ti1[0].DATA |
| 1291 |
for row in rows: |
| 1292 |
if len(row) < 7: |
| 1293 |
# Missing XYZ, add via simple sRGB-like model |
| 1294 |
row.extend( |
| 1295 |
v * 100 |
| 1296 |
for v in argyll_rgb2xyz.rgb2xyz(*[v / 100.0 for v in row[1:]]) |
| 1297 |
) |
| 1298 |
data.add_data(row) |
| 1299 |
# Create temp dir |
| 1300 |
result = tmp = self.worker.create_tempdir() |
| 1301 |
if not isinstance(result, Exception): |
| 1302 |
# Write out temporary TI1 |
| 1303 |
ti1.filename = os.path.join( |
| 1304 |
tmp, os.path.splitext(os.path.basename(path))[0] + ".ti1" |
| 1305 |
) |
| 1306 |
ti1.write() |
| 1307 |
result = ti1 |
| 1308 |
return result |
| 1309 |
|
| 1310 |
def csv_convert_finish(self, result): |
| 1311 |
"""Handle the completion of the CSV conversion. |
| 1312 |
|
| 1313 |
Args: |
| 1314 |
result (CGATS or Exception): The result of the conversion. |
| 1315 |
""" |
| 1316 |
if isinstance(result, Exception): |
| 1317 |
show_result_dialog(result, self) |
| 1318 |
else: |
| 1319 |
self.tc_load_cfg_from_ti1(None, result.filename, resume=True) |
| 1320 |
|
| 1321 |
def precond_profile_drop_handler(self, path): |
| 1322 |
"""Handle dropping a profile file onto the precondition profile control. |
| 1323 |
|
| 1324 |
Args: |
| 1325 |
path (str): The file path of the dropped profile. |
| 1326 |
""" |
| 1327 |
self.tc_precond_profile.SetPath(path) |
| 1328 |
self.tc_precond_profile_handler() |
| 1329 |
|
| 1330 |
def get_commands(self): |
| 1331 |
"""Get a list of commands for the test chart editor. |
| 1332 |
|
| 1333 |
Returns: |
| 1334 |
list: List of command strings. |
| 1335 |
""" |
| 1336 |
return [ |
| 1337 |
*self.get_common_commands(), |
| 1338 |
"testchart-editor [filename | create filename]", |
| 1339 |
"load <filename>", |
| 1340 |
] |
| 1341 |
|
| 1342 |
def process_data(self, data): |
| 1343 |
"""Process command line data for the test chart editor. |
| 1344 |
|
| 1345 |
Args: |
| 1346 |
data (list): List of command line arguments. |
| 1347 |
|
| 1348 |
Returns: |
| 1349 |
str: "ok" if the command was processed successfully, "fail" if it |
| 1350 |
failed, or "invalid" if the command was not recognized. |
| 1351 |
""" |
| 1352 |
if ( |
| 1353 |
data[0] == "testchart-editor" |
| 1354 |
and (len(data) < 3 or (len(data) == 3 and data[1] == "create")) |
| 1355 |
) or (data[0] == "load" and len(data) == 2): |
| 1356 |
if self.IsIconized(): |
| 1357 |
self.Restore() |
| 1358 |
self.Raise() |
| 1359 |
if len(data) == 2: |
| 1360 |
path = data[1] |
| 1361 |
if not os.path.isfile(path) and not os.path.isabs(path): |
| 1362 |
path = get_data_path(path) |
| 1363 |
if not path: |
| 1364 |
return "fail" |
| 1365 |
self.droptarget.OnDropFiles(0, 0, [path]) |
| 1366 |
elif len(data) == 3: |
| 1367 |
# Create testchart |
| 1368 |
wx.CallAfter(self.tc_preview_handler, path=data[2]) |
| 1369 |
return "ok" |
| 1370 |
return "invalid" |
| 1371 |
|
| 1372 |
def ti1_drop_handler(self, path): |
| 1373 |
"""Handle dropping a TI1 file onto the test chart editor.""" |
| 1374 |
self.tc_load_cfg_from_ti1(None, path) |
| 1375 |
|
| 1376 |
def resize_grid(self): |
| 1377 |
"""Resize the grid columns based on the current size of the grid.""" |
| 1378 |
num_cols = self.grid.GetNumberCols() |
| 1379 |
if not num_cols or num_cols == 1: |
| 1380 |
return |
| 1381 |
grid_w = ( |
| 1382 |
self.grid.GetSize()[0] |
| 1383 |
- self.grid.GetRowLabelSize() |
| 1384 |
- self.grid.GetDefaultRowSize() |
| 1385 |
) |
| 1386 |
col_w = round(grid_w / (num_cols - 1)) |
| 1387 |
last_col_w = grid_w - col_w * (num_cols - 2) |
| 1388 |
for i in range(num_cols): |
| 1389 |
if i == 3: |
| 1390 |
w = self.grid.GetDefaultRowSize() |
| 1391 |
elif i == num_cols - 2: |
| 1392 |
w = last_col_w - wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X) |
| 1393 |
else: |
| 1394 |
w = col_w |
| 1395 |
self.grid.SetColSize(i, w) |
| 1396 |
self.grid.SetMargins(0 - wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X), 0) |
| 1397 |
self.grid.ForceRefresh() |
| 1398 |
if hasattr(self, "preview"): |
| 1399 |
num_cols = self.preview.GetNumberCols() |
| 1400 |
if not num_cols: |
| 1401 |
return |
| 1402 |
grid_w = ( |
| 1403 |
self.preview.GetSize()[0] |
| 1404 |
- self.preview.GetRowLabelSize() |
| 1405 |
- wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X) |
| 1406 |
) |
| 1407 |
col_w = round(grid_w / num_cols) |
| 1408 |
for i in range(num_cols): |
| 1409 |
self.preview.SetColSize(i, col_w) |
| 1410 |
self.preview.SetMargins( |
| 1411 |
0 - wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X), 0 |
| 1412 |
) |
| 1413 |
self.preview.ForceRefresh() |
| 1414 |
|
| 1415 |
def tc_grid_range_select_handler(self, event): |
| 1416 |
"""Handler for grid range selection events. |
| 1417 |
|
| 1418 |
Args: |
| 1419 |
event (wx.Event): The event that triggered this handler. |
| 1420 |
""" |
| 1421 |
if DEBUG: |
| 1422 |
print("[D] tc_grid_range_select_handler") |
| 1423 |
if not self.grid.GetBatchCount(): |
| 1424 |
wx.CallAfter(self.tc_set_default_status) |
| 1425 |
event.Skip() |
| 1426 |
|
| 1427 |
def tc_grid_label_left_click_handler(self, event): |
| 1428 |
"""Handler for left-clicking on a grid label. |
| 1429 |
|
| 1430 |
Args: |
| 1431 |
event (wx.Event): The event that triggered this handler. |
| 1432 |
""" |
| 1433 |
wx.CallAfter(self.tc_set_default_status) |
| 1434 |
event.Skip() |
| 1435 |
|
| 1436 |
def tc_grid_label_left_dclick_handler(self, event): |
| 1437 |
"""Handler for double-clicking on a grid label. |
| 1438 |
|
| 1439 |
Args: |
| 1440 |
event (wx.Event): The event that triggered this handler. |
| 1441 |
""" |
| 1442 |
row, col = event.GetRow(), event.GetCol() |
| 1443 |
if col == -1: # row label clicked |
| 1444 |
_data = self.ti1.queryv1("DATA") |
| 1445 |
wp = self.ti1.queryv1("APPROX_WHITE_POINT") |
| 1446 |
if wp: |
| 1447 |
wp = [float(v) for v in wp.split()] |
| 1448 |
wp = [(v / wp[1]) * 100.0 for v in wp] |
| 1449 |
else: |
| 1450 |
wp = colormath.get_standard_illuminant("D65", scale=100) |
| 1451 |
newdata = { |
| 1452 |
"SAMPLE_ID": row + 2, |
| 1453 |
"RGB_R": 100.0, |
| 1454 |
"RGB_G": 100.0, |
| 1455 |
"RGB_B": 100.0, |
| 1456 |
"XYZ_X": wp[0], |
| 1457 |
"XYZ_Y": 100.0, |
| 1458 |
"XYZ_Z": wp[2], |
| 1459 |
} |
| 1460 |
self.tc_add_data(row, [newdata]) |
| 1461 |
event.Skip() |
| 1462 |
|
| 1463 |
def tc_key_handler(self, event): |
| 1464 |
"""Handler for key events in the test chart editor. |
| 1465 |
|
| 1466 |
Args: |
| 1467 |
event (wx.Event): The event that triggered this handler. |
| 1468 |
""" |
| 1469 |
# AltDown |
| 1470 |
# CmdDown |
| 1471 |
# ControlDown |
| 1472 |
# GetKeyCode |
| 1473 |
# GetModifiers |
| 1474 |
# GetPosition |
| 1475 |
# GetRawKeyCode |
| 1476 |
# GetRawKeyFlags |
| 1477 |
# GetUniChar |
| 1478 |
# GetUnicodeKey |
| 1479 |
# GetX |
| 1480 |
# GetY |
| 1481 |
# HasModifiers |
| 1482 |
# KeyCode |
| 1483 |
# MetaDown |
| 1484 |
# Modifiers |
| 1485 |
# Position |
| 1486 |
# RawKeyCode |
| 1487 |
# RawKeyFlags |
| 1488 |
# ShiftDown |
| 1489 |
# UnicodeKey |
| 1490 |
# X |
| 1491 |
# Y |
| 1492 |
if DEBUG: |
| 1493 |
print( |
| 1494 |
"[D] event.KeyCode", |
| 1495 |
event.GetKeyCode(), |
| 1496 |
"event.RawKeyCode", |
| 1497 |
event.GetRawKeyCode(), |
| 1498 |
"event.UniChar", |
| 1499 |
event.GetUniChar(), |
| 1500 |
"event.UnicodeKey", |
| 1501 |
event.GetUnicodeKey(), |
| 1502 |
"CTRL/CMD:", |
| 1503 |
event.ControlDown() or event.CmdDown(), |
| 1504 |
"ALT:", |
| 1505 |
event.AltDown(), |
| 1506 |
"SHIFT:", |
| 1507 |
event.ShiftDown(), |
| 1508 |
) |
| 1509 |
if ( |
| 1510 |
event.ControlDown() or event.CmdDown() |
| 1511 |
): # CTRL (Linux/Mac/Windows) / CMD (Mac) |
| 1512 |
key = event.GetKeyCode() |
| 1513 |
focus = self.FindFocus() |
| 1514 |
if focus and self.grid in ( |
| 1515 |
focus, |
| 1516 |
focus.GetParent(), |
| 1517 |
focus.GetGrandParent(), |
| 1518 |
): |
| 1519 |
if key in (8, 127): # BACKSPACE / DEL |
| 1520 |
rows = self.grid.GetSelectionRows() |
| 1521 |
if ( |
| 1522 |
rows |
| 1523 |
and len(rows) |
| 1524 |
and min(rows) >= 0 |
| 1525 |
and max(rows) + 1 <= self.grid.GetNumberRows() |
| 1526 |
): |
| 1527 |
if len(rows) == self.grid.GetNumberRows(): |
| 1528 |
self.tc_check_save_ti1() |
| 1529 |
else: |
| 1530 |
self.tc_delete_rows(rows) |
| 1531 |
return |
| 1532 |
elif key == 86 and self.grid.IsEditable(): |
| 1533 |
# V |
| 1534 |
wx.CallAfter(self.tc_save_check) |
| 1535 |
if key == 83: # S |
| 1536 |
if hasattr(self, "ti1"): |
| 1537 |
if ( |
| 1538 |
event.ShiftDown() |
| 1539 |
or event.AltDown() |
| 1540 |
or not self.ti1.filename |
| 1541 |
or not os.path.exists(self.ti1.filename) |
| 1542 |
): |
| 1543 |
self.tc_save_as_handler() |
| 1544 |
elif self.ti1.modified: |
| 1545 |
self.tc_save_handler(True) |
| 1546 |
return |
| 1547 |
event.Skip() |
| 1548 |
else: |
| 1549 |
event.Skip() |
| 1550 |
|
| 1551 |
def tc_sash_handler(self, event): |
| 1552 |
"""Handler for the sash position change event. |
| 1553 |
|
| 1554 |
Args: |
| 1555 |
event (wx.Event): The event that triggered this handler. |
| 1556 |
""" |
| 1557 |
if event.GetSashPosition() < self.sizer.GetMinSize()[1]: |
| 1558 |
self.splitter.SetSashPosition(self.sizer.GetMinSize()[1]) |
| 1559 |
event.Skip() |
| 1560 |
|
| 1561 |
def tc_size_handler(self, event=None): |
| 1562 |
"""Handler for the window size event. |
| 1563 |
|
| 1564 |
Args: |
| 1565 |
event (wx.Event): The event that triggered this handler. |
| 1566 |
""" |
| 1567 |
wx.CallAfter(self.resize_grid) |
| 1568 |
if self.IsShownOnScreen() and not self.IsMaximized() and not self.IsIconized(): |
| 1569 |
w, h = self.ClientSize |
| 1570 |
setcfg("size.tcgen.w", w) |
| 1571 |
setcfg("size.tcgen.h", h) |
| 1572 |
if event: |
| 1573 |
event.Skip() |
| 1574 |
|
| 1575 |
def tc_sort_handler(self, event): |
| 1576 |
"""Handler for the change patch order button. |
| 1577 |
|
| 1578 |
Args: |
| 1579 |
event (wx.Event): The event that triggered this handler. |
| 1580 |
""" |
| 1581 |
idx = self.change_patch_order_ctrl.GetSelection() |
| 1582 |
if idx == 0: |
| 1583 |
self.ti1.sort_rgb_gray_to_top() |
| 1584 |
elif idx == 1: |
| 1585 |
self.ti1.sort_rgb_white_to_top() |
| 1586 |
elif idx == 2: |
| 1587 |
self.ti1.sort_rgb_to_top(1, 0, 0) # Red |
| 1588 |
elif idx == 3: |
| 1589 |
self.ti1.sort_rgb_to_top(0, 1, 0) # Green |
| 1590 |
elif idx == 4: |
| 1591 |
self.ti1.sort_rgb_to_top(0, 0, 1) # Blue |
| 1592 |
elif idx == 5: |
| 1593 |
self.ti1.sort_rgb_to_top(0, 1, 1) # Cyan |
| 1594 |
elif idx == 6: |
| 1595 |
self.ti1.sort_rgb_to_top(1, 0, 1) # Magenta |
| 1596 |
elif idx == 7: |
| 1597 |
self.ti1.sort_rgb_to_top(1, 1, 0) # Yellow |
| 1598 |
elif idx == 8: |
| 1599 |
self.ti1.sort_by_hsi() |
| 1600 |
elif idx == 9: |
| 1601 |
self.ti1.sort_by_hsl() |
| 1602 |
elif idx == 10: |
| 1603 |
self.ti1.sort_by_hsv() |
| 1604 |
elif idx == 11: |
| 1605 |
self.ti1.sort_by_l() |
| 1606 |
elif idx == 12: |
| 1607 |
self.ti1.sort_by_rec709_luma() |
| 1608 |
elif idx == 13: |
| 1609 |
self.ti1.sort_by_rgb() |
| 1610 |
elif idx == 14: |
| 1611 |
self.ti1.sort_by_rgb_sum() |
| 1612 |
elif idx == 15: |
| 1613 |
self.ti1.sort_by_bgr() |
| 1614 |
elif idx == 16: |
| 1615 |
# Minimize display response delay |
| 1616 |
self.ti1.sort_by_bgr() |
| 1617 |
self.ti1.sort_rgb_gray_to_top() |
| 1618 |
self.ti1.sort_rgb_white_to_top() |
| 1619 |
elif idx == 17: |
| 1620 |
# Interleave |
| 1621 |
self.ti1.checkerboard(None, None) |
| 1622 |
elif idx == 18: |
| 1623 |
# Shift & interleave |
| 1624 |
self.ti1.checkerboard(None, None, split_grays=True, shift=True) |
| 1625 |
elif idx == 19: |
| 1626 |
# Maximize L* difference |
| 1627 |
self.ti1.checkerboard(sort1=stable_sort_by_l) |
| 1628 |
elif idx == 20: |
| 1629 |
# Maximize Rec. 709 luma difference |
| 1630 |
self.ti1.checkerboard(sort_by_rec709_luma) |
| 1631 |
elif idx == 21: |
| 1632 |
# Maximize RGB difference |
| 1633 |
self.ti1.checkerboard(sort_by_rgb_sum) |
| 1634 |
elif idx == 22: |
| 1635 |
# Vary RGB difference |
| 1636 |
self.ti1.checkerboard(sort_by_rgb, None, split_grays=True, shift=True) |
| 1637 |
self.tc_clear(False) |
| 1638 |
self.tc_preview(True) |
| 1639 |
|
| 1640 |
def tc_enable_sort_controls(self): |
| 1641 |
"""Enable or disable the patch order controls based on the current state.""" |
| 1642 |
enable = hasattr(self, "ti1") |
| 1643 |
self.change_patch_order_ctrl.Enable(enable) |
| 1644 |
self.change_patch_order_btn.Enable(enable) |
| 1645 |
|
| 1646 |
def tc_grid_cell_change_handler(self, event, save_check=True): |
| 1647 |
"""Handler for grid cell changes. |
| 1648 |
|
| 1649 |
Args: |
| 1650 |
event (wx.grid.GridEvent): The grid event that triggered this handler. |
| 1651 |
save_check (bool): Whether to check for unsaved changes. |
| 1652 |
""" |
| 1653 |
data = self.ti1[0]["DATA"] |
| 1654 |
sample = data[event.GetRow()] |
| 1655 |
label = self.label_b2a.get(self.grid.GetColLabelValue(event.GetCol())) |
| 1656 |
strval = "0" + self.grid.GetCellValue(event.GetRow(), event.GetCol()).replace( |
| 1657 |
",", "." |
| 1658 |
) |
| 1659 |
value_set = False |
| 1660 |
try: |
| 1661 |
value = float(strval) |
| 1662 |
if value > 100: |
| 1663 |
raise ValueError(f"RGB value {value!r}% is invalid") |
| 1664 |
if value < 0: |
| 1665 |
raise ValueError(f"Negative RGB value {value!r}% is invalid") |
| 1666 |
except ValueError: |
| 1667 |
if not self.grid.GetBatchCount(): |
| 1668 |
wx.Bell() |
| 1669 |
if label in list(self.ti1[0]["DATA_FORMAT"].values()): |
| 1670 |
strval = str(sample[label]) |
| 1671 |
if "." in strval: |
| 1672 |
strval = strval.rstrip("0").rstrip(".") |
| 1673 |
else: |
| 1674 |
strval = "" |
| 1675 |
else: |
| 1676 |
if label in ("RGB_R", "RGB_G", "RGB_B"): |
| 1677 |
sample[label] = value |
| 1678 |
# If the same RGB combo is already in the ti1, use its XYZ |
| 1679 |
# TODO: Implement proper lookup when using precond profile |
| 1680 |
# This costs too much performance when updating multiple cells! |
| 1681 |
# (e.g. paste operation from spreadsheet) |
| 1682 |
# ref = data.queryi({"RGB_R": sample["RGB_R"], |
| 1683 |
# "RGB_G": sample["RGB_G"], |
| 1684 |
# "RGB_B": sample["RGB_B"]}) |
| 1685 |
# if ref: |
| 1686 |
# for i in ref: |
| 1687 |
# if ref[i] != sample: |
| 1688 |
# ref = ref[i] |
| 1689 |
# break |
| 1690 |
# if "XYZ_X" in ref: |
| 1691 |
# XYZ = [ |
| 1692 |
# component / 100.0 |
| 1693 |
# for component in (ref["XYZ_X"], ref["XYZ_Y"], ref["XYZ_Z"]) |
| 1694 |
# ] |
| 1695 |
# else: |
| 1696 |
# Fall back to default D65-ish values |
| 1697 |
XYZ = argyll_rgb2xyz.rgb2xyz( |
| 1698 |
*[ |
| 1699 |
component / 100.0 |
| 1700 |
for component in ( |
| 1701 |
sample["RGB_R"], |
| 1702 |
sample["RGB_G"], |
| 1703 |
sample["RGB_B"], |
| 1704 |
) |
| 1705 |
] |
| 1706 |
) |
| 1707 |
sample["XYZ_X"], sample["XYZ_Y"], sample["XYZ_Z"] = [ |
| 1708 |
component * 100.0 for component in XYZ |
| 1709 |
] |
| 1710 |
# FIXME: Should this be removed? There are no XYZ fields in the editor |
| 1711 |
# for label in ("XYZ_X", "XYZ_Y", "XYZ_Z"): |
| 1712 |
# for col in range(self.grid.GetNumberCols()): |
| 1713 |
# if self.label_b2a.get(self.grid.GetColLabelValue(col)) == label: |
| 1714 |
# self.grid.SetCellValue( |
| 1715 |
# event.GetRow(), col, str(round(sample[label], 4)) |
| 1716 |
# ) |
| 1717 |
# value_set = True |
| 1718 |
elif label in ("XYZ_X", "XYZ_Y", "XYZ_Z"): |
| 1719 |
# FIXME: Should this be removed? There are no XYZ fields in the editor |
| 1720 |
if value < 0: |
| 1721 |
value = 0.0 |
| 1722 |
sample[label] = value |
| 1723 |
RGB = argyll_rgb2xyz.xyz2rgb( |
| 1724 |
*[ |
| 1725 |
component / 100.0 |
| 1726 |
for component in ( |
| 1727 |
sample["XYZ_X"], |
| 1728 |
sample["XYZ_Y"], |
| 1729 |
sample["XYZ_Z"], |
| 1730 |
) |
| 1731 |
] |
| 1732 |
) |
| 1733 |
sample["RGB_R"], sample["RGB_G"], sample["RGB_B"] = [ |
| 1734 |
component * 100.0 for component in RGB |
| 1735 |
] |
| 1736 |
for label in ("RGB_R", "RGB_G", "RGB_B"): |
| 1737 |
for col in range(self.grid.GetNumberCols()): |
| 1738 |
if self.label_b2a.get(self.grid.GetColLabelValue(col)) == label: |
| 1739 |
self.grid.SetCellValue( |
| 1740 |
event.GetRow(), col, str(round(sample[label], 4)) |
| 1741 |
) |
| 1742 |
value_set = True |
| 1743 |
self.tc_grid_setcolorlabel(event.GetRow(), data) |
| 1744 |
if not self.grid.GetBatchCount() and save_check: |
| 1745 |
self.tc_save_check() |
| 1746 |
if not value_set: |
| 1747 |
self.grid.SetCellValue( |
| 1748 |
event.GetRow(), event.GetCol(), re.sub(r"^0+(?!\.)", "", strval) or "0" |
| 1749 |
) |
| 1750 |
|
| 1751 |
def tc_white_patches_handler(self, event=None): |
| 1752 |
"""Handler for the white patches control. |
| 1753 |
|
| 1754 |
Args: |
| 1755 |
event (wx.Event, optional): The event that triggered this handler. |
| 1756 |
""" |
| 1757 |
setcfg("tc_white_patches", self.tc_white_patches.GetValue()) |
| 1758 |
self.tc_check() |
| 1759 |
if event: |
| 1760 |
event.Skip() |
| 1761 |
|
| 1762 |
def tc_black_patches_handler(self, event=None): |
| 1763 |
"""Handler for the black patches control. |
| 1764 |
|
| 1765 |
Args: |
| 1766 |
event (wx.Event, optional): The event that triggered this handler. |
| 1767 |
""" |
| 1768 |
setcfg("tc_black_patches", self.tc_black_patches.GetValue()) |
| 1769 |
self.tc_check() |
| 1770 |
if event: |
| 1771 |
event.Skip() |
| 1772 |
|
| 1773 |
def tc_single_channel_patches_handler(self, event=None): |
| 1774 |
"""Handler for the single channel patches control. |
| 1775 |
|
| 1776 |
Args: |
| 1777 |
event (wx.Event, optional): The event that triggered this handler. |
| 1778 |
""" |
| 1779 |
if event: |
| 1780 |
event.Skip() |
| 1781 |
event = CustomEvent(event.GetEventType(), event.GetEventObject()) |
| 1782 |
if event and event.GetEventType() == wx.EVT_TEXT.evtType[0]: |
| 1783 |
# 3 seconds delay to allow user |
| 1784 |
# to finish keying in a value before it is validated |
| 1785 |
wx.CallLater(3000, self.tc_single_channel_patches_handler2, event) |
| 1786 |
else: |
| 1787 |
wx.CallAfter(self.tc_single_channel_patches_handler2, event) |
| 1788 |
|
| 1789 |
def tc_single_channel_patches_handler2(self, event=None): |
| 1790 |
"""Handler for the single channel patches control. |
| 1791 |
|
| 1792 |
Args: |
| 1793 |
event (wx.Event, optional): The event that triggered this handler. |
| 1794 |
""" |
| 1795 |
if self.tc_single_channel_patches.GetValue() == 1: |
| 1796 |
if ( |
| 1797 |
event |
| 1798 |
and event.GetEventType() in (0, wx.EVT_SPINCTRL.evtType[0]) |
| 1799 |
and getcfg("tc_single_channel_patches") == 2 |
| 1800 |
): # decrease |
| 1801 |
self.tc_single_channel_patches.SetValue(0) |
| 1802 |
else: # increase |
| 1803 |
self.tc_single_channel_patches.SetValue(2) |
| 1804 |
setcfg("tc_single_channel_patches", self.tc_single_channel_patches.GetValue()) |
| 1805 |
self.tc_check() |
| 1806 |
|
| 1807 |
def tc_gray_handler(self, event=None): |
| 1808 |
"""Handler for the gray patches control. |
| 1809 |
|
| 1810 |
Args: |
| 1811 |
event (wx.Event, optional): The event that triggered this handler. |
| 1812 |
""" |
| 1813 |
if event: |
| 1814 |
event.Skip() |
| 1815 |
event = CustomEvent(event.GetEventType(), event.GetEventObject()) |
| 1816 |
if event and event.GetEventType() == wx.EVT_TEXT.evtType[0]: |
| 1817 |
# 3 seconds delay to allow user |
| 1818 |
# to finish keying in a value before it is validated |
| 1819 |
wx.CallLater(3000, self.tc_gray_handler2, event) |
| 1820 |
else: |
| 1821 |
wx.CallAfter(self.tc_gray_handler2, event) |
| 1822 |
|
| 1823 |
def tc_gray_handler2(self, event=None): |
| 1824 |
"""Handler for the gray patches control. |
| 1825 |
|
| 1826 |
Args: |
| 1827 |
event (wx.Event, optional): The event that triggered this handler. |
| 1828 |
""" |
| 1829 |
if self.tc_gray_patches.GetValue() == 1: |
| 1830 |
if ( |
| 1831 |
event |
| 1832 |
and event.GetEventType() in (0, wx.EVT_SPINCTRL.evtType[0]) |
| 1833 |
and getcfg("tc_gray_patches") == 2 |
| 1834 |
): # decrease |
| 1835 |
self.tc_gray_patches.SetValue(0) |
| 1836 |
else: # increase |
| 1837 |
self.tc_gray_patches.SetValue(2) |
| 1838 |
setcfg("tc_gray_patches", self.tc_gray_patches.GetValue()) |
| 1839 |
self.tc_check() |
| 1840 |
|
| 1841 |
def tc_fullspread_handler(self, event=None): |
| 1842 |
"""Handler for the full spread patches control. |
| 1843 |
|
| 1844 |
Args: |
| 1845 |
event (wx.Event, optional): The event that triggered this handler. |
| 1846 |
""" |
| 1847 |
setcfg("tc_fullspread_patches", self.tc_fullspread_patches.GetValue()) |
| 1848 |
self.tc_algo_handler() |
| 1849 |
self.tc_check() |
| 1850 |
|
| 1851 |
def tc_gamma_handler(self, event): |
| 1852 |
"""Handler for the gamma control. |
| 1853 |
|
| 1854 |
Args: |
| 1855 |
event (wx.Event): The event that triggered this handler. |
| 1856 |
""" |
| 1857 |
setcfg("tc_gamma", self.tc_gamma_floatctrl.GetValue()) |
| 1858 |
|
| 1859 |
def tc_get_total_patches( |
| 1860 |
self, |
| 1861 |
white_patches=None, |
| 1862 |
black_patches=None, |
| 1863 |
single_channel_patches=None, |
| 1864 |
gray_patches=None, |
| 1865 |
multi_steps=None, |
| 1866 |
multi_bcc_steps=None, |
| 1867 |
fullspread_patches=None, |
| 1868 |
): |
| 1869 |
"""Get the total number of patches for the test chart. |
| 1870 |
|
| 1871 |
Args: |
| 1872 |
white_patches (int, optional): Number of white patches. |
| 1873 |
black_patches (int, optional): Number of black patches. |
| 1874 |
single_channel_patches (int, optional): Number of single channel patches. |
| 1875 |
gray_patches (int, optional): Number of gray patches. |
| 1876 |
multi_steps (int, optional): Number of multi steps. |
| 1877 |
multi_bcc_steps (int, optional): Number of multi BCC steps. |
| 1878 |
fullspread_patches (int, optional): Number of full spread patches. |
| 1879 |
|
| 1880 |
Returns: |
| 1881 |
int: The total number of patches. |
| 1882 |
""" |
| 1883 |
if ( |
| 1884 |
hasattr(self, "ti1") |
| 1885 |
and [ |
| 1886 |
white_patches, |
| 1887 |
black_patches, |
| 1888 |
single_channel_patches, |
| 1889 |
gray_patches, |
| 1890 |
multi_steps, |
| 1891 |
multi_bcc_steps, |
| 1892 |
fullspread_patches, |
| 1893 |
] |
| 1894 |
== [None] * 7 |
| 1895 |
): |
| 1896 |
return self.ti1.queryv1("NUMBER_OF_SETS") |
| 1897 |
if white_patches is None: |
| 1898 |
white_patches = self.tc_white_patches.GetValue() |
| 1899 |
if black_patches is None: |
| 1900 |
if self.worker.argyll_version >= [1, 6]: |
| 1901 |
black_patches = self.tc_black_patches.GetValue() |
| 1902 |
elif hasattr(self, "ti1"): |
| 1903 |
black_patches = self.ti1.queryv1("BLACK_COLOR_PATCHES") |
| 1904 |
if single_channel_patches is None: |
| 1905 |
single_channel_patches = self.tc_single_channel_patches.GetValue() |
| 1906 |
if gray_patches is None: |
| 1907 |
gray_patches = self.tc_gray_patches.GetValue() |
| 1908 |
if ( |
| 1909 |
gray_patches == 0 |
| 1910 |
and (single_channel_patches > 0 or black_patches > 0) |
| 1911 |
and white_patches > 0 |
| 1912 |
): |
| 1913 |
gray_patches = 2 |
| 1914 |
if multi_steps is None: |
| 1915 |
multi_steps = self.tc_multi_steps.GetValue() |
| 1916 |
if ( |
| 1917 |
multi_bcc_steps is None |
| 1918 |
and getcfg("tc_multi_bcc") |
| 1919 |
and self.worker.argyll_version >= [1, 6] |
| 1920 |
): |
| 1921 |
multi_bcc_steps = self.tc_multi_steps.GetValue() |
| 1922 |
if fullspread_patches is None: |
| 1923 |
fullspread_patches = self.tc_fullspread_patches.GetValue() |
| 1924 |
return get_total_patches( |
| 1925 |
white_patches, |
| 1926 |
black_patches, |
| 1927 |
single_channel_patches, |
| 1928 |
gray_patches, |
| 1929 |
multi_steps, |
| 1930 |
multi_bcc_steps, |
| 1931 |
fullspread_patches, |
| 1932 |
) |
| 1933 |
|
| 1934 |
def tc_get_black_patches(self): |
| 1935 |
"""Get the number of black patches for the test chart. |
| 1936 |
|
| 1937 |
Returns: |
| 1938 |
int: The number of black patches. |
| 1939 |
""" |
| 1940 |
if self.worker.argyll_version >= [1, 6]: |
| 1941 |
black_patches = self.tc_black_patches.GetValue() |
| 1942 |
else: |
| 1943 |
black_patches = 0 |
| 1944 |
single_channel_patches = self.tc_single_channel_patches.GetValue() |
| 1945 |
gray_patches = self.tc_gray_patches.GetValue() |
| 1946 |
if gray_patches == 0 and single_channel_patches > 0 and black_patches > 0: |
| 1947 |
gray_patches = 2 |
| 1948 |
multi_steps = self.tc_multi_steps.GetValue() |
| 1949 |
if ( |
| 1950 |
multi_steps > 1 or gray_patches > 1 |
| 1951 |
): # black always in multi channel or gray patches |
| 1952 |
black_patches -= 1 |
| 1953 |
return max(0, black_patches) |
| 1954 |
|
| 1955 |
def tc_get_white_patches(self): |
| 1956 |
"""Get the number of white patches for the test chart. |
| 1957 |
|
| 1958 |
Returns: |
| 1959 |
int: The number of white patches. |
| 1960 |
""" |
| 1961 |
white_patches = self.tc_white_patches.GetValue() |
| 1962 |
single_channel_patches = self.tc_single_channel_patches.GetValue() |
| 1963 |
gray_patches = self.tc_gray_patches.GetValue() |
| 1964 |
if gray_patches == 0 and single_channel_patches > 0 and white_patches > 0: |
| 1965 |
gray_patches = 2 |
| 1966 |
multi_steps = self.tc_multi_steps.GetValue() |
| 1967 |
if ( |
| 1968 |
multi_steps > 1 or gray_patches > 1 |
| 1969 |
): # white always in multi channel or gray patches |
| 1970 |
white_patches -= 1 |
| 1971 |
return max(0, white_patches) |
| 1972 |
|
| 1973 |
def tc_multi_steps_handler(self, event=None): |
| 1974 |
"""Handler for the multi steps control. |
| 1975 |
|
| 1976 |
Args: |
| 1977 |
event (wx.Event, optional): The event that triggered this handler. |
| 1978 |
""" |
| 1979 |
if event: |
| 1980 |
event.Skip() |
| 1981 |
event = CustomEvent(event.GetEventType(), event.GetEventObject()) |
| 1982 |
if event and event.GetEventType() == wx.EVT_TEXT.evtType[0]: |
| 1983 |
# 3 seconds delay to allow user |
| 1984 |
# to finish keying in a value before it is validated |
| 1985 |
wx.CallLater(3000, self.tc_multi_steps_handler2, event) |
| 1986 |
else: |
| 1987 |
wx.CallAfter(self.tc_multi_steps_handler2, event) |
| 1988 |
|
| 1989 |
def tc_multi_steps_handler2(self, event=None): |
| 1990 |
"""Handle the multi steps control. |
| 1991 |
|
| 1992 |
Args: |
| 1993 |
event (wx.Event, optional): The event that triggered this handler. |
| 1994 |
""" |
| 1995 |
if self.tc_multi_steps.GetValue() == 1: |
| 1996 |
if ( |
| 1997 |
event |
| 1998 |
and event.GetEventType() in (0, wx.EVT_SPINCTRL.evtType[0]) |
| 1999 |
and getcfg("tc_multi_steps") == 2 |
| 2000 |
): # decrease |
| 2001 |
self.tc_multi_steps.SetValue(0) |
| 2002 |
else: # increase |
| 2003 |
self.tc_multi_steps.SetValue(2) |
| 2004 |
multi_steps = self.tc_multi_steps.GetValue() |
| 2005 |
multi_patches = int(math.pow(multi_steps, 3)) |
| 2006 |
if getcfg("tc_multi_bcc") and self.worker.argyll_version >= [1, 6]: |
| 2007 |
pref = "tc_multi_bcc_steps" |
| 2008 |
if multi_steps: |
| 2009 |
multi_patches += int(math.pow(multi_steps - 1, 3)) |
| 2010 |
multi_steps += multi_steps - 1 |
| 2011 |
setcfg("tc_multi_steps", self.tc_multi_steps.GetValue()) |
| 2012 |
else: |
| 2013 |
pref = "tc_multi_steps" |
| 2014 |
setcfg("tc_multi_bcc_steps", 0) |
| 2015 |
self.tc_multi_patches.SetLabel( |
| 2016 |
lang.getstr("tc.multidim.patches", (multi_patches, multi_steps)) |
| 2017 |
) |
| 2018 |
setcfg(pref, self.tc_multi_steps.GetValue()) |
| 2019 |
self.tc_check() |
| 2020 |
|
| 2021 |
def tc_neutral_axis_emphasis_handler(self, event=None): |
| 2022 |
"""Handler for the neutral axis emphasis slider or intctrl. |
| 2023 |
|
| 2024 |
Args: |
| 2025 |
event (wx.Event, optional): The event that triggered this handler. |
| 2026 |
""" |
| 2027 |
if event.GetId() == self.tc_neutral_axis_emphasis_slider.GetId(): |
| 2028 |
self.tc_neutral_axis_emphasis_intctrl.SetValue( |
| 2029 |
self.tc_neutral_axis_emphasis_slider.GetValue() |
| 2030 |
) |
| 2031 |
else: |
| 2032 |
self.tc_neutral_axis_emphasis_slider.SetValue( |
| 2033 |
self.tc_neutral_axis_emphasis_intctrl.GetValue() |
| 2034 |
) |
| 2035 |
setcfg( |
| 2036 |
"tc_neutral_axis_emphasis", |
| 2037 |
self.tc_neutral_axis_emphasis_intctrl.GetValue() / 100.0, |
| 2038 |
) |
| 2039 |
self.tc_algo_handler() |
| 2040 |
|
| 2041 |
def tc_dark_emphasis_handler(self, event=None): |
| 2042 |
"""Handler for the dark emphasis slider or intctrl. |
| 2043 |
|
| 2044 |
Args: |
| 2045 |
event (wx.Event, optional): The event that triggered this handler. |
| 2046 |
""" |
| 2047 |
if event.GetId() == self.tc_dark_emphasis_slider.GetId(): |
| 2048 |
self.tc_dark_emphasis_intctrl.SetValue( |
| 2049 |
self.tc_dark_emphasis_slider.GetValue() |
| 2050 |
) |
| 2051 |
else: |
| 2052 |
self.tc_dark_emphasis_slider.SetValue( |
| 2053 |
self.tc_dark_emphasis_intctrl.GetValue() |
| 2054 |
) |
| 2055 |
setcfg("tc_dark_emphasis", self.tc_dark_emphasis_intctrl.GetValue() / 100.0) |
| 2056 |
self.tc_algo_handler() |
| 2057 |
|
| 2058 |
def tc_algo_handler(self, event=None): |
| 2059 |
"""Handler for the test chart algorithm selection. |
| 2060 |
|
| 2061 |
Args: |
| 2062 |
event (wx.Event, optional): The event that triggered this handler. |
| 2063 |
""" |
| 2064 |
tc_algo_enable = self.tc_fullspread_patches.GetValue() > 0 |
| 2065 |
self.tc_algo.Enable(tc_algo_enable) |
| 2066 |
tc_algo = self.tc_algos_ba[self.tc_algo.GetStringSelection()] |
| 2067 |
self.tc_adaption_slider.Enable(tc_algo_enable and tc_algo == "") |
| 2068 |
self.tc_adaption_intctrl.Enable(tc_algo_enable and tc_algo == "") |
| 2069 |
tc_precond_enable = tc_algo in ("I", "Q", "R", "t") or ( |
| 2070 |
tc_algo == "" and self.tc_adaption_slider.GetValue() > 0 |
| 2071 |
) |
| 2072 |
if self.worker.argyll_version >= [1, 3, 3]: |
| 2073 |
self.tc_neutral_axis_emphasis_slider.Enable( |
| 2074 |
tc_algo_enable and tc_precond_enable |
| 2075 |
) |
| 2076 |
self.tc_neutral_axis_emphasis_intctrl.Enable( |
| 2077 |
tc_algo_enable and tc_precond_enable |
| 2078 |
) |
| 2079 |
self.tc_precond.Enable(bool(getcfg("tc_precond_profile"))) |
| 2080 |
if not getcfg("tc_precond_profile"): |
| 2081 |
self.tc_precond.SetValue(False) |
| 2082 |
else: |
| 2083 |
self.tc_precond.SetValue(bool(int(getcfg("tc_precond")))) |
| 2084 |
if self.worker.argyll_version >= [1, 6, 2]: |
| 2085 |
tc_dark_emphasis_enable = self.worker.argyll_version >= [1, 6, 3] or ( |
| 2086 |
tc_precond_enable |
| 2087 |
and bool(int(getcfg("tc_precond"))) |
| 2088 |
and bool(getcfg("tc_precond_profile")) |
| 2089 |
) |
| 2090 |
self.tc_dark_emphasis_slider.Enable(tc_dark_emphasis_enable) |
| 2091 |
self.tc_dark_emphasis_intctrl.Enable(tc_dark_emphasis_enable) |
| 2092 |
self.tc_angle_slider.Enable(tc_algo_enable and tc_algo in ("i", "I")) |
| 2093 |
self.tc_angle_intctrl.Enable(tc_algo_enable and tc_algo in ("i", "I")) |
| 2094 |
setcfg("tc_algo", tc_algo) |
| 2095 |
self.tc_enable_add_precond_controls() |
| 2096 |
|
| 2097 |
def tc_enable_add_precond_controls(self): |
| 2098 |
"""Enable or disable controls related to additional preconditioning.""" |
| 2099 |
_tc_algo = getcfg("tc_algo") |
| 2100 |
add_preconditioned_enable = hasattr(self, "ti1") and bool( |
| 2101 |
getcfg("tc_precond_profile") |
| 2102 |
) |
| 2103 |
self.saturation_sweeps_intctrl.Enable(add_preconditioned_enable) |
| 2104 |
for color in ("R", "G", "B", "C", "M", "Y"): |
| 2105 |
getattr(self, f"saturation_sweeps_{color}_btn").Enable( |
| 2106 |
add_preconditioned_enable |
| 2107 |
) |
| 2108 |
RGB = {} |
| 2109 |
for component in ("R", "G", "B"): |
| 2110 |
ctrl = getattr(self, f"saturation_sweeps_custom_{component}_ctrl") |
| 2111 |
ctrl.Enable(add_preconditioned_enable) |
| 2112 |
RGB[component] = ctrl.GetValue() |
| 2113 |
self.saturation_sweeps_custom_btn.Enable( |
| 2114 |
add_preconditioned_enable and not (RGB["R"] == RGB["G"] == RGB["B"]) |
| 2115 |
) |
| 2116 |
self.add_ti3_btn.Enable(add_preconditioned_enable) |
| 2117 |
self.add_ti3_relative_cb.Enable(add_preconditioned_enable) |
| 2118 |
|
| 2119 |
def tc_adaption_handler(self, event=None): |
| 2120 |
"""Handler for adapting the test chart based on the adaption slider or intctrl. |
| 2121 |
|
| 2122 |
Args: |
| 2123 |
event (wx.Event, optional): The event that triggered this handler. |
| 2124 |
""" |
| 2125 |
if event.GetId() == self.tc_adaption_slider.GetId(): |
| 2126 |
self.tc_adaption_intctrl.SetValue(self.tc_adaption_slider.GetValue()) |
| 2127 |
else: |
| 2128 |
self.tc_adaption_slider.SetValue(self.tc_adaption_intctrl.GetValue()) |
| 2129 |
setcfg("tc_adaption", self.tc_adaption_intctrl.GetValue() / 100.0) |
| 2130 |
self.tc_algo_handler() |
| 2131 |
|
| 2132 |
def tc_add_saturation_sweeps_handler(self, event): |
| 2133 |
"""Handler for adding saturation sweeps to the test chart. |
| 2134 |
|
| 2135 |
Args: |
| 2136 |
event (wx.Event): The event that triggered this handler. |
| 2137 |
""" |
| 2138 |
try: |
| 2139 |
profile = ICCProfile(getcfg("tc_precond_profile")) |
| 2140 |
except (OSError, ICCProfileInvalidError) as exception: |
| 2141 |
show_result_dialog(exception, self) |
| 2142 |
return |
| 2143 |
|
| 2144 |
rgb_space = profile.get_rgb_space() |
| 2145 |
if not rgb_space: |
| 2146 |
show_result_dialog( |
| 2147 |
Error( |
| 2148 |
lang.getstr( |
| 2149 |
"profile.required_tags_missing", |
| 2150 |
lang.getstr("profile.type.shaper_matrix"), |
| 2151 |
) |
| 2152 |
), |
| 2153 |
self, |
| 2154 |
) |
| 2155 |
return |
| 2156 |
R, G, B = { |
| 2157 |
self.saturation_sweeps_R_btn.GetId(): (1, 0, 0), |
| 2158 |
self.saturation_sweeps_G_btn.GetId(): (0, 1, 0), |
| 2159 |
self.saturation_sweeps_B_btn.GetId(): (0, 0, 1), |
| 2160 |
self.saturation_sweeps_C_btn.GetId(): (0, 1, 1), |
| 2161 |
self.saturation_sweeps_M_btn.GetId(): (1, 0, 1), |
| 2162 |
self.saturation_sweeps_Y_btn.GetId(): (1, 1, 0), |
| 2163 |
self.saturation_sweeps_custom_btn.GetId(): ( |
| 2164 |
self.saturation_sweeps_custom_R_ctrl.GetValue() / 100.0, |
| 2165 |
self.saturation_sweeps_custom_G_ctrl.GetValue() / 100.0, |
| 2166 |
self.saturation_sweeps_custom_B_ctrl.GetValue() / 100.0, |
| 2167 |
), |
| 2168 |
}[event.GetId()] |
| 2169 |
maxv = self.saturation_sweeps_intctrl.GetValue() |
| 2170 |
newdata = [] |
| 2171 |
rows = self.grid.GetSelectionRows() |
| 2172 |
row = rows[-1] if rows else self.grid.GetNumberRows() - 1 |
| 2173 |
for i in range(maxv): |
| 2174 |
_saturation = 1.0 / (maxv - 1) * i |
| 2175 |
RGB, xyY = colormath.RGBsaturation(R, G, B, 1.0 / (maxv - 1) * i, rgb_space) |
| 2176 |
X, Y, Z = colormath.xyY2XYZ(*xyY) |
| 2177 |
newdata.append( |
| 2178 |
{ |
| 2179 |
"SAMPLE_ID": row + 2, |
| 2180 |
"RGB_R": round(RGB[0] * 100, 4), |
| 2181 |
"RGB_G": round(RGB[1] * 100, 4), |
| 2182 |
"RGB_B": round(RGB[2] * 100, 4), |
| 2183 |
"XYZ_X": X * 100, |
| 2184 |
"XYZ_Y": Y * 100, |
| 2185 |
"XYZ_Z": Z * 100, |
| 2186 |
} |
| 2187 |
) |
| 2188 |
self.tc_add_data(row, newdata) |
| 2189 |
self.grid.select_row(row + len(newdata)) |
| 2190 |
|
| 2191 |
def tc_drop_ti3_handler(self, path): |
| 2192 |
"""Handler for dropping a TI3 file to the test chart. |
| 2193 |
|
| 2194 |
Args: |
| 2195 |
path (str): Path to the dropped file. |
| 2196 |
""" |
| 2197 |
if not hasattr(self, "ti1"): |
| 2198 |
wx.Bell() |
| 2199 |
elif getcfg("tc_precond_profile"): |
| 2200 |
self.tc_add_ti3_handler(None, path) |
| 2201 |
else: |
| 2202 |
show_result_dialog(lang.getstr("tc.precond.notset"), self) |
| 2203 |
|
| 2204 |
def tc_add_ti3_handler(self, event, chart=None): |
| 2205 |
"""Handler for adding a TI3 file to the test chart. |
| 2206 |
|
| 2207 |
Args: |
| 2208 |
event (wx.Event): The event that triggered this handler. |
| 2209 |
chart (str, optional): Path to the chart file. Defaults to None. |
| 2210 |
""" |
| 2211 |
try: |
| 2212 |
profile = ICCProfile(getcfg("tc_precond_profile")) |
| 2213 |
except (OSError, ICCProfileInvalidError) as exception: |
| 2214 |
show_result_dialog(exception, self) |
| 2215 |
return |
| 2216 |
|
| 2217 |
if not chart: |
| 2218 |
defaultDir, defaultFile = get_verified_path("testchart.reference") |
| 2219 |
dlg = wx.FileDialog( |
| 2220 |
self, |
| 2221 |
lang.getstr("testchart_or_reference"), |
| 2222 |
defaultDir=defaultDir, |
| 2223 |
defaultFile=defaultFile, |
| 2224 |
wildcard=( |
| 2225 |
f"{lang.getstr('filetype.ti1_ti3_txt')}|*.cgats;*.cie;" |
| 2226 |
"*.gam;*.icc;*.icm;*.jpg;*.jpeg;*.png;*.ti1;*.ti2;*.ti3;" |
| 2227 |
"*.tif;*.tiff;*.txt" |
| 2228 |
), |
| 2229 |
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST, |
| 2230 |
) |
| 2231 |
dlg.Center(wx.BOTH) |
| 2232 |
result = dlg.ShowModal() |
| 2233 |
if result == wx.ID_OK: |
| 2234 |
chart = dlg.GetPath() |
| 2235 |
setcfg("testchart.reference", chart) |
| 2236 |
dlg.Destroy() |
| 2237 |
if result != wx.ID_OK: |
| 2238 |
return |
| 2239 |
|
| 2240 |
use_gamut = False |
| 2241 |
|
| 2242 |
# Determine if this is an image |
| 2243 |
filename, ext = os.path.splitext(chart) |
| 2244 |
if ext.lower() in (".jpg", ".jpeg", ".png", ".tif", ".tiff"): |
| 2245 |
llevel = wx.Log.GetLogLevel() |
| 2246 |
wx.Log.SetLogLevel(0) # Suppress TIFF library related message popups |
| 2247 |
try: |
| 2248 |
img = wx.Image(chart, wx.BITMAP_TYPE_ANY) |
| 2249 |
if not img.IsOk(): |
| 2250 |
raise Error(lang.getstr("error.file_type_unsupported")) |
| 2251 |
except Exception as exception: |
| 2252 |
show_result_dialog(exception, self) |
| 2253 |
return |
| 2254 |
finally: |
| 2255 |
wx.Log.SetLogLevel(llevel) |
| 2256 |
if TEST: |
| 2257 |
dlg = ConfirmDialog( |
| 2258 |
self, |
| 2259 |
title=lang.getstr("testchart.add_ti3_patches"), |
| 2260 |
msg=lang.getstr("gamut"), |
| 2261 |
ok="L*a*b*", |
| 2262 |
alt="RGB", |
| 2263 |
bitmap=get_icon(32, APPNAME + "-testchart-editor"), |
| 2264 |
) |
| 2265 |
result = dlg.ShowModal() |
| 2266 |
if result == wx.ID_CANCEL: |
| 2267 |
return |
| 2268 |
use_gamut = result == wx.ID_OK |
| 2269 |
else: |
| 2270 |
img = None |
| 2271 |
if ext.lower() in (".icc", ".icm"): |
| 2272 |
try: |
| 2273 |
nclprof = ICCProfile(chart) |
| 2274 |
if ( |
| 2275 |
nclprof.profileClass != "nmcl" |
| 2276 |
or "ncl2" not in nclprof.tags |
| 2277 |
or not isinstance(nclprof.tags.ncl2, NamedColor2Type) |
| 2278 |
or nclprof.connectionColorSpace not in ("Lab", "XYZ") |
| 2279 |
): |
| 2280 |
raise Error(lang.getstr("profile.only_named_color")) |
| 2281 |
except Exception as exception: |
| 2282 |
show_result_dialog(exception, self) |
| 2283 |
return |
| 2284 |
if nclprof.connectionColorSpace == "Lab": |
| 2285 |
data_format = "LAB_L LAB_A LAB_B" |
| 2286 |
else: |
| 2287 |
data_format = " XYZ_X XYZ_Y XYZ_Z" |
| 2288 |
chart = [ |
| 2289 |
"GAMUT ", |
| 2290 |
"BEGIN_DATA_FORMAT", |
| 2291 |
data_format, |
| 2292 |
"END_DATA_FORMAT", |
| 2293 |
"BEGIN_DATA", |
| 2294 |
"END_DATA", |
| 2295 |
] |
| 2296 |
if "wtpt" in nclprof.tags: |
| 2297 |
chart.insert(1, 'KEYWORD "APPROX_WHITE_POINT"') |
| 2298 |
chart.insert( |
| 2299 |
2, |
| 2300 |
'APPROX_WHITE_POINT "{:.4f} {:.4f} {:.4f}"'.format( |
| 2301 |
*tuple(v * 100 for v in list(nclprof.tags.wtpt.ir.values())) |
| 2302 |
), |
| 2303 |
) |
| 2304 |
for k in nclprof.tags.ncl2: |
| 2305 |
v = nclprof.tags.ncl2[k] |
| 2306 |
chart.insert( |
| 2307 |
-1, "{:.4f} {:.4f} {:.4f}".format(*tuple(v.pcs.values())) |
| 2308 |
) |
| 2309 |
chart = "\n".join(chart) |
| 2310 |
|
| 2311 |
self.worker.start( |
| 2312 |
self.tc_add_ti3_consumer, |
| 2313 |
self.tc_add_ti3, |
| 2314 |
cargs=(profile,), |
| 2315 |
wargs=(chart, img, use_gamut, profile), |
| 2316 |
wkwargs={}, |
| 2317 |
progress_msg=lang.getstr("testchart.add_ti3_patches"), |
| 2318 |
parent=self, |
| 2319 |
progress_start=500, |
| 2320 |
fancy=False, |
| 2321 |
) |
| 2322 |
|
| 2323 |
def tc_add_ti3_consumer(self, result, profile=None): |
| 2324 |
"""Consumer for the tc_add_ti3 worker. |
| 2325 |
|
| 2326 |
Args: |
| 2327 |
result (str or Exception): Result from the worker, either a path |
| 2328 |
to the processed ti3 file or an Exception. |
| 2329 |
profile (ICCProfile, optional): Preconditioning profile. Defaults |
| 2330 |
to None. |
| 2331 |
""" |
| 2332 |
if isinstance(result, Exception): |
| 2333 |
show_result_dialog(result, self) |
| 2334 |
return |
| 2335 |
|
| 2336 |
chart = result |
| 2337 |
data_format = list(chart.queryv1("DATA_FORMAT").values()) |
| 2338 |
intent = "r" if getcfg("tc_add_ti3_relative") else "a" |
| 2339 |
if not ( |
| 2340 |
chart[0].type.strip() == "GAMUT" |
| 2341 |
and "RGB_R" in data_format |
| 2342 |
and "RGB_G" in data_format |
| 2343 |
and "RGB_B" in data_format |
| 2344 |
): |
| 2345 |
as_ti3 = ( |
| 2346 |
"LAB_L" in data_format |
| 2347 |
and "LAB_A" in data_format |
| 2348 |
and "LAB_B" in data_format |
| 2349 |
) or ( |
| 2350 |
"XYZ_X" in data_format |
| 2351 |
and "XYZ_Y" in data_format |
| 2352 |
and "XYZ_Z" in data_format |
| 2353 |
) |
| 2354 |
if getcfg("tc_add_ti3_relative"): |
| 2355 |
_ = chart.adapt() |
| 2356 |
ti1, ti3, void = self.worker.chart_lookup( |
| 2357 |
chart, profile, as_ti3, intent=intent, white_patches=False |
| 2358 |
) |
| 2359 |
if not ti1 or not ti3: |
| 2360 |
return |
| 2361 |
chart = ti1 if as_ti3 else ti3 |
| 2362 |
dataset = chart.queryi1("DATA") |
| 2363 |
data_format = list(dataset.queryv1("DATA_FORMAT").values()) |
| 2364 |
# Returned CIE values are always either XYZ or Lab |
| 2365 |
if "LAB_L" in data_format and "LAB_A" in data_format and "LAB_B" in data_format: |
| 2366 |
cie = "Lab" |
| 2367 |
else: |
| 2368 |
cie = "XYZ" |
| 2369 |
newdata = [] |
| 2370 |
rows = self.grid.GetSelectionRows() |
| 2371 |
row = rows[-1] if rows else self.grid.GetNumberRows() - 1 |
| 2372 |
for i in dataset.DATA: |
| 2373 |
if cie == "Lab": |
| 2374 |
( |
| 2375 |
dataset.DATA[i]["XYZ_X"], |
| 2376 |
dataset.DATA[i]["XYZ_Y"], |
| 2377 |
dataset.DATA[i]["XYZ_Z"], |
| 2378 |
) = colormath.Lab2XYZ( |
| 2379 |
dataset.DATA[i]["LAB_L"], |
| 2380 |
dataset.DATA[i]["LAB_A"], |
| 2381 |
dataset.DATA[i]["LAB_B"], |
| 2382 |
scale=100, |
| 2383 |
) |
| 2384 |
if intent == "r": |
| 2385 |
( |
| 2386 |
dataset.DATA[i]["XYZ_X"], |
| 2387 |
dataset.DATA[i]["XYZ_Y"], |
| 2388 |
dataset.DATA[i]["XYZ_Z"], |
| 2389 |
) = colormath.adapt( |
| 2390 |
dataset.DATA[i]["XYZ_X"], |
| 2391 |
dataset.DATA[i]["XYZ_Y"], |
| 2392 |
dataset.DATA[i]["XYZ_Z"], |
| 2393 |
"D50", |
| 2394 |
list(profile.tags.wtpt.values()), |
| 2395 |
) |
| 2396 |
entry = {"SAMPLE_ID": row + 2 + i} |
| 2397 |
for label in ("RGB_R", "RGB_G", "RGB_B", "XYZ_X", "XYZ_Y", "XYZ_Z"): |
| 2398 |
entry[label] = round(dataset.DATA[i][label], 4) |
| 2399 |
newdata.append(entry) |
| 2400 |
self.tc_add_data(row, newdata) |
| 2401 |
self.grid.select_row(row + len(newdata)) |
| 2402 |
|
| 2403 |
def tc_add_ti3(self, chart, img=None, use_gamut=True, profile=None): |
| 2404 |
"""Add a ti3 file or image to the test chart. |
| 2405 |
|
| 2406 |
Args: |
| 2407 |
chart (str): Path to the ti3 file or image. |
| 2408 |
img (wx.Image, optional): Image object if chart is an image. |
| 2409 |
Defaults to None. |
| 2410 |
use_gamut (bool, optional): Whether to use tiffgamut for |
| 2411 |
processing. Defaults to True. |
| 2412 |
profile (ICCProfile, optional): Preconditioning profile. Defaults |
| 2413 |
to None. |
| 2414 |
|
| 2415 |
Returns: |
| 2416 |
str: Path to the processed ti3 file or image. |
| 2417 |
""" |
| 2418 |
if img: |
| 2419 |
cwd = self.worker.create_tempdir() |
| 2420 |
if isinstance(cwd, Exception): |
| 2421 |
return cwd |
| 2422 |
size = 70.0 |
| 2423 |
scale = math.sqrt((img.Width * img.Height) / (size * size)) |
| 2424 |
w = round(img.Width / scale) |
| 2425 |
h = round(img.Height / scale) |
| 2426 |
loresimg = img.Scale(w, h, wx.IMAGE_QUALITY_NORMAL) |
| 2427 |
if loresimg.CountColours() < img.CountColours(size * size): |
| 2428 |
# Assume a photo |
| 2429 |
quality = wx.IMAGE_QUALITY_HIGH |
| 2430 |
else: |
| 2431 |
# Assume a target |
| 2432 |
quality = wx.IMAGE_QUALITY_NORMAL |
| 2433 |
ext = os.path.splitext(chart)[1] |
| 2434 |
if ext.lower() in (".tif", ".tiff") or ( |
| 2435 |
self.worker.argyll_version >= [1, 4] |
| 2436 |
and ext.lower() in (".jpeg", ".jpg") |
| 2437 |
): |
| 2438 |
imgpath = chart |
| 2439 |
else: |
| 2440 |
imgpath = os.path.join(cwd, "image.tif") |
| 2441 |
img.SaveFile(imgpath, wx.BITMAP_TYPE_TIF) |
| 2442 |
outpath = os.path.join(cwd, "imageout.tif") |
| 2443 |
# Process image to get colors |
| 2444 |
# Two ways to do this: Convert image using cctiff |
| 2445 |
# or use tiffgamut |
| 2446 |
# In both cases, a profile embedded in the image will be used |
| 2447 |
# with the preconditioning profile as fallback if there is no |
| 2448 |
# image profile |
| 2449 |
if not use_gamut: |
| 2450 |
# Use cctiff |
| 2451 |
cmdname = "cctiff" |
| 2452 |
else: |
| 2453 |
# Use tiffgamut |
| 2454 |
cmdname = "tiffgamut" |
| 2455 |
gam = os.path.join(cwd, "image.gam") |
| 2456 |
cmd = get_argyll_util(cmdname) |
| 2457 |
if cmd: |
| 2458 |
ppath = getcfg("tc_precond_profile") |
| 2459 |
intent = "r" if getcfg("tc_add_ti3_relative") else "a" |
| 2460 |
for n in range(2 if ppath else 1): |
| 2461 |
if use_gamut: |
| 2462 |
res = 10 if imgpath == chart else 1 |
| 2463 |
args = [f"-d{res}", "-O", gam] |
| 2464 |
# if self.worker.argyll_version >= [1, 0, 4]: |
| 2465 |
# args.append("-f100") |
| 2466 |
else: |
| 2467 |
args = ["-a"] |
| 2468 |
if self.worker.argyll_version >= [1, 4]: |
| 2469 |
# Always save as TIFF |
| 2470 |
args.append("-fT") |
| 2471 |
elif self.worker.argyll_version >= [1, 1]: |
| 2472 |
# TIFF photometric encoding 1..n |
| 2473 |
args.append("-t1") |
| 2474 |
else: |
| 2475 |
# TIFF photometric encoding 1..n |
| 2476 |
args.append("-e1") |
| 2477 |
args.append(f"-i{intent}") |
| 2478 |
if n == 0: |
| 2479 |
# Try to use embedded profile |
| 2480 |
args.append(imgpath) |
| 2481 |
if not use_gamut: |
| 2482 |
# Target |
| 2483 |
args.append(f"-i{intent}") |
| 2484 |
args.append(ppath) |
| 2485 |
else: |
| 2486 |
# Fall back to preconditioning profile |
| 2487 |
args.append(ppath) |
| 2488 |
args.append(imgpath) |
| 2489 |
if not use_gamut: |
| 2490 |
args.append(outpath) |
| 2491 |
result = self.worker.exec_cmd( |
| 2492 |
cmd, ["-v", *args], capture_output=True, skip_scripts=True |
| 2493 |
) |
| 2494 |
if not result: |
| 2495 |
errors = "".join(self.worker.errors) |
| 2496 |
if ( |
| 2497 |
"Error - Can't open profile in file" in errors |
| 2498 |
or "Error - Can't read profile" in errors |
| 2499 |
): |
| 2500 |
# Try again? |
| 2501 |
continue |
| 2502 |
break |
| 2503 |
if isinstance(result, Exception) or not result: |
| 2504 |
self.worker.wrapup(False) |
| 2505 |
if isinstance(result, Exception): |
| 2506 |
return result |
| 2507 |
if result: |
| 2508 |
if use_gamut: |
| 2509 |
chart = gam |
| 2510 |
else: |
| 2511 |
last_output_space = None |
| 2512 |
for line in self.worker.output: |
| 2513 |
if line.startswith("Output space ="): |
| 2514 |
last_output_space = line.split("=")[1].strip() |
| 2515 |
chart = outpath if last_output_space == "RGB" else imgpath |
| 2516 |
else: |
| 2517 |
return Error("\n".join(self.worker.errors or self.worker.output)) |
| 2518 |
else: |
| 2519 |
return Error(lang.getstr("argyll.util.not_found", cmdname)) |
| 2520 |
|
| 2521 |
if not use_gamut: |
| 2522 |
llevel = wx.Log.GetLogLevel() |
| 2523 |
wx.Log.SetLogLevel(0) # Suppress TIFF library related message popups |
| 2524 |
try: |
| 2525 |
img = wx.Image(chart, wx.BITMAP_TYPE_ANY) |
| 2526 |
if not img.IsOk(): |
| 2527 |
raise Error(lang.getstr("error.file_type_unsupported")) |
| 2528 |
except Exception as exception: |
| 2529 |
return exception |
| 2530 |
finally: |
| 2531 |
wx.Log.SetLogLevel(llevel) |
| 2532 |
self.worker.wrapup(False) |
| 2533 |
if img.Width != w or img.Height != h: |
| 2534 |
img.Rescale(w, h, quality) |
| 2535 |
# Select RGB colors and fill chart |
| 2536 |
chart = [ |
| 2537 |
"TI1 ", |
| 2538 |
"BEGIN_DATA_FORMAT", |
| 2539 |
"RGB_R RGB_G RGB_B", |
| 2540 |
"END_DATA_FORMAT", |
| 2541 |
"BEGIN_DATA", |
| 2542 |
"END_DATA", |
| 2543 |
] |
| 2544 |
for y in range(h): |
| 2545 |
for x in range(w): |
| 2546 |
R, G, B = ( |
| 2547 |
img.GetRed(x, y) / 2.55, |
| 2548 |
img.GetGreen(x, y) / 2.55, |
| 2549 |
img.GetBlue(x, y) / 2.55, |
| 2550 |
) |
| 2551 |
chart.insert(-1, f"{R:.4f} {G:.4f} {B:.4f}") |
| 2552 |
chart = "\n".join(chart) |
| 2553 |
|
| 2554 |
try: |
| 2555 |
chart = CGATS(chart) |
| 2556 |
if not chart.queryv1("DATA_FORMAT"): |
| 2557 |
raise CGATSError( |
| 2558 |
lang.getstr( |
| 2559 |
"error.testchart.missing_fields", |
| 2560 |
(chart.filename, "DATA_FORMAT"), |
| 2561 |
) |
| 2562 |
) |
| 2563 |
except (OSError, CGATSError) as exception: |
| 2564 |
return exception |
| 2565 |
finally: |
| 2566 |
path = None |
| 2567 |
if isinstance(chart, CGATS): |
| 2568 |
if chart.filename: |
| 2569 |
path = chart.filename |
| 2570 |
elif os.path.isfile(chart): |
| 2571 |
path = chart |
| 2572 |
if path and os.path.dirname(path) == self.worker.tempdir: |
| 2573 |
self.worker.wrapup(False) |
| 2574 |
if img: |
| 2575 |
if use_gamut: |
| 2576 |
threshold = 2 |
| 2577 |
else: |
| 2578 |
threshold = 4 |
| 2579 |
try: |
| 2580 |
void, ti3, void = self.worker.chart_lookup( |
| 2581 |
chart, |
| 2582 |
profile, |
| 2583 |
intent=intent, |
| 2584 |
white_patches=False, |
| 2585 |
raise_exceptions=True, |
| 2586 |
) |
| 2587 |
except Exception as exception: |
| 2588 |
return exception |
| 2589 |
if ti3: |
| 2590 |
chart = ti3 |
| 2591 |
else: |
| 2592 |
return Error( |
| 2593 |
lang.getstr("error.generic", (-1, lang.getstr("unknown"))) |
| 2594 |
) |
| 2595 |
colorsets = {} |
| 2596 |
weights = {} |
| 2597 |
demph = getcfg("tc_dark_emphasis") |
| 2598 |
# Select Lab color |
| 2599 |
data = chart.queryv1("DATA") |
| 2600 |
for sample in data.values(): |
| 2601 |
if not use_gamut: |
| 2602 |
RGB = sample["RGB_R"], sample["RGB_G"], sample["RGB_B"] |
| 2603 |
L, a, b = (sample["LAB_L"], sample["LAB_A"], sample["LAB_B"]) |
| 2604 |
color = round(L / 10), round(a / 15), round(b / 15) |
| 2605 |
if color not in colorsets: |
| 2606 |
weights[color] = 0 |
| 2607 |
colorsets[color] = [] |
| 2608 |
if L >= 50: |
| 2609 |
weights[color] += L / 50 - demph |
| 2610 |
else: |
| 2611 |
weights[color] += L / 50 + demph |
| 2612 |
colorsets[color].append((L, a, b)) |
| 2613 |
if not use_gamut: |
| 2614 |
colorsets[color][-1] += RGB |
| 2615 |
# Fill chart |
| 2616 |
data_format = "LAB_L LAB_A LAB_B" |
| 2617 |
if not use_gamut: |
| 2618 |
data_format += " RGB_R RGB_G RGB_B" |
| 2619 |
chart = [ |
| 2620 |
"GAMUT ", |
| 2621 |
"BEGIN_DATA_FORMAT", |
| 2622 |
data_format, |
| 2623 |
"END_DATA_FORMAT", |
| 2624 |
"BEGIN_DATA", |
| 2625 |
"END_DATA", |
| 2626 |
] |
| 2627 |
weight = bool( |
| 2628 |
[ |
| 2629 |
color |
| 2630 |
for color in iter(colorsets.keys()) |
| 2631 |
if weights[color] >= threshold |
| 2632 |
] |
| 2633 |
) |
| 2634 |
for color in colorsets: |
| 2635 |
colors = colorsets[color] |
| 2636 |
if weight and weights[color] < threshold: |
| 2637 |
continue |
| 2638 |
L, a, b = 0, 0, 0 |
| 2639 |
R, G, B = 0, 0, 0 |
| 2640 |
for v in colors: |
| 2641 |
L += v[0] |
| 2642 |
a += v[1] |
| 2643 |
b += v[2] |
| 2644 |
if len(v) == 6: |
| 2645 |
R += v[3] |
| 2646 |
G += v[4] |
| 2647 |
B += v[5] |
| 2648 |
L /= len(colors) |
| 2649 |
a /= len(colors) |
| 2650 |
b /= len(colors) |
| 2651 |
R /= len(colors) |
| 2652 |
G /= len(colors) |
| 2653 |
B /= len(colors) |
| 2654 |
chart.insert(-1, f"{L:.4f} {a:.4f} {b:.4f}") |
| 2655 |
if not use_gamut: |
| 2656 |
chart[-2] += f" {R:.4f} {G:.4f} {B:.4f}" |
| 2657 |
|
| 2658 |
chart = CGATS("\n".join(chart)) |
| 2659 |
else: |
| 2660 |
chart.fix_device_values_scaling() |
| 2661 |
|
| 2662 |
return chart |
| 2663 |
|
| 2664 |
def tc_add_ti3_relative_handler(self, event): |
| 2665 |
"""Handle the checkbox for adding TI3 relative to the preconditioned chart. |
| 2666 |
|
| 2667 |
Args: |
| 2668 |
event (wx.Event): The event triggered by the checkbox. |
| 2669 |
""" |
| 2670 |
setcfg("tc_add_ti3_relative", int(self.add_ti3_relative_cb.GetValue())) |
| 2671 |
|
| 2672 |
def tc_angle_handler(self, event=None): |
| 2673 |
"""Handle the angle slider and integer control for test chart generation. |
| 2674 |
|
| 2675 |
Args: |
| 2676 |
event (wx.Event): The event triggered by the slider or integer control. |
| 2677 |
""" |
| 2678 |
if event.GetId() == self.tc_angle_slider.GetId(): |
| 2679 |
self.tc_angle_intctrl.SetValue(self.tc_angle_slider.GetValue()) |
| 2680 |
else: |
| 2681 |
self.tc_angle_slider.SetValue(self.tc_angle_intctrl.GetValue()) |
| 2682 |
setcfg("tc_angle", self.tc_angle_intctrl.GetValue() / 10000.0) |
| 2683 |
|
| 2684 |
def tc_multi_bcc_cb_handler(self, event=None): |
| 2685 |
"""Handle the checkbox for multi BCC steps in test chart generation. |
| 2686 |
|
| 2687 |
Args: |
| 2688 |
event (wx.Event): The event triggered by the checkbox. |
| 2689 |
""" |
| 2690 |
setcfg("tc_multi_bcc", int(self.tc_multi_bcc_cb.GetValue())) |
| 2691 |
self.tc_multi_steps_handler2() |
| 2692 |
|
| 2693 |
def tc_precond_handler(self, event=None): |
| 2694 |
"""Handle the checkbox for test chart preconditioning. |
| 2695 |
|
| 2696 |
Args: |
| 2697 |
event (wx.Event): The event triggered by the checkbox. |
| 2698 |
""" |
| 2699 |
setcfg("tc_precond", int(self.tc_precond.GetValue())) |
| 2700 |
self.tc_adaption_slider.SetValue( |
| 2701 |
int((1 if getcfg("tc_precond") else DEFAULTS["tc_adaption"]) * 100) |
| 2702 |
) |
| 2703 |
self.tc_adaption_handler(self.tc_adaption_slider) |
| 2704 |
self.tc_algo_handler() |
| 2705 |
|
| 2706 |
def tc_precond_profile_handler(self, event=None): |
| 2707 |
"""Handle the test chart preconditioning profile selection. |
| 2708 |
|
| 2709 |
Args: |
| 2710 |
event (wx.Event): The event triggered by the control. |
| 2711 |
""" |
| 2712 |
tc_precond_enable = bool(self.tc_precond_profile.GetPath()) |
| 2713 |
self.tc_precond.Enable(tc_precond_enable) |
| 2714 |
setcfg("tc_precond_profile", self.tc_precond_profile.GetPath()) |
| 2715 |
self.tc_algo_handler() |
| 2716 |
|
| 2717 |
def tc_precond_profile_current_ctrl_handler(self, event): |
| 2718 |
"""Handle the current profile path control for test chart preconditioning. |
| 2719 |
|
| 2720 |
Args: |
| 2721 |
event (wx.Event): The event triggered by the control. |
| 2722 |
""" |
| 2723 |
profile_path = get_current_profile_path(True, True) |
| 2724 |
if profile_path: |
| 2725 |
self.tc_precond_profile.SetPath(profile_path) |
| 2726 |
self.tc_precond_profile_handler() |
| 2727 |
else: |
| 2728 |
show_result_dialog( |
| 2729 |
Error( |
| 2730 |
lang.getstr( |
| 2731 |
"display_profile.not_detected", get_display_name(None, True) |
| 2732 |
) |
| 2733 |
), |
| 2734 |
self, |
| 2735 |
) |
| 2736 |
|
| 2737 |
def tc_filter_handler(self, event=None): |
| 2738 |
"""Handle the checkbox for test chart filtering. |
| 2739 |
|
| 2740 |
Args: |
| 2741 |
event (wx.Event): The event triggered by the checkbox. |
| 2742 |
""" |
| 2743 |
setcfg("tc_filter", int(self.tc_filter.GetValue())) |
| 2744 |
setcfg("tc_filter_L", self.tc_filter_L.GetValue()) |
| 2745 |
setcfg("tc_filter_a", self.tc_filter_a.GetValue()) |
| 2746 |
setcfg("tc_filter_b", self.tc_filter_b.GetValue()) |
| 2747 |
setcfg("tc_filter_rad", self.tc_filter_rad.GetValue()) |
| 2748 |
|
| 2749 |
def tc_vrml_black_offset_ctrl_handler(self, event): |
| 2750 |
"""Handle the VRML black offset control. |
| 2751 |
|
| 2752 |
Args: |
| 2753 |
event (wx.Event): The event triggered by the control. |
| 2754 |
""" |
| 2755 |
setcfg("tc_vrml_black_offset", self.tc_vrml_black_offset_intctrl.GetValue()) |
| 2756 |
|
| 2757 |
def tc_vrml_compress_handler(self, event): |
| 2758 |
"""Handle the checkbox for VRML compression. |
| 2759 |
|
| 2760 |
Args: |
| 2761 |
event (wx.Event): The event triggered by the checkbox. |
| 2762 |
""" |
| 2763 |
setcfg("vrml.compress", int(self.tc_vrml_compress_cb.GetValue())) |
| 2764 |
|
| 2765 |
def tc_vrml_handler(self, event=None): |
| 2766 |
"""Handle the VRML controls and update the configuration.""" |
| 2767 |
d = self.tc_vrml_device.GetValue() |
| 2768 |
l = self.tc_vrml_cie.GetValue() |
| 2769 |
if event: |
| 2770 |
setcfg("tc_vrml_device", int(d)) |
| 2771 |
setcfg("tc_vrml_cie", int(l)) |
| 2772 |
setcfg( |
| 2773 |
"tc_vrml_cie_colorspace", |
| 2774 |
self.tc_vrml_cie_colorspace_ctrl.GetStringSelection(), |
| 2775 |
) |
| 2776 |
setcfg( |
| 2777 |
"tc_vrml_device_colorspace", |
| 2778 |
self.tc_vrml_device_colorspace_ctrl.GetStringSelection(), |
| 2779 |
) |
| 2780 |
self.vrml_save_as_btn.Enable(hasattr(self, "ti1") and (d or l)) |
| 2781 |
self.view_3d_format_btn.Enable(hasattr(self, "ti1") and (d or l)) |
| 2782 |
|
| 2783 |
def tc_vrml_use_D50_handler(self, event): |
| 2784 |
"""Handle the checkbox for using D50 in VRML.""" |
| 2785 |
setcfg("tc_vrml_use_D50", int(self.tc_vrml_use_D50_cb.GetValue())) |
| 2786 |
|
| 2787 |
def tc_update_controls(self): |
| 2788 |
"""Update the test chart controls with the current configuration.""" |
| 2789 |
self.tc_algo.SetStringSelection( |
| 2790 |
self.tc_algos_ab.get( |
| 2791 |
getcfg("tc_algo"), self.tc_algos_ab.get(DEFAULTS["tc_algo"]) |
| 2792 |
) |
| 2793 |
) |
| 2794 |
self.tc_white_patches.SetValue(getcfg("tc_white_patches")) |
| 2795 |
if self.worker.argyll_version >= [1, 6]: |
| 2796 |
self.tc_black_patches.SetValue(getcfg("tc_black_patches")) |
| 2797 |
self.tc_single_channel_patches.SetValue(getcfg("tc_single_channel_patches")) |
| 2798 |
self.tc_gray_patches.SetValue(getcfg("tc_gray_patches")) |
| 2799 |
if getcfg("tc_multi_bcc_steps"): |
| 2800 |
setcfg("tc_multi_bcc", 1) |
| 2801 |
self.tc_multi_steps.SetValue(getcfg("tc_multi_bcc_steps")) |
| 2802 |
else: |
| 2803 |
setcfg("tc_multi_bcc", 0) |
| 2804 |
self.tc_multi_steps.SetValue(getcfg("tc_multi_steps")) |
| 2805 |
if hasattr(self, "tc_multi_bcc_cb"): |
| 2806 |
self.tc_multi_bcc_cb.SetValue(bool(getcfg("tc_multi_bcc"))) |
| 2807 |
self.tc_multi_steps_handler2() |
| 2808 |
self.tc_fullspread_patches.SetValue(getcfg("tc_fullspread_patches")) |
| 2809 |
self.tc_angle_slider.SetValue(int(getcfg("tc_angle") * 10000)) |
| 2810 |
self.tc_angle_handler(self.tc_angle_slider) |
| 2811 |
self.tc_adaption_slider.SetValue(int(getcfg("tc_adaption") * 100)) |
| 2812 |
self.tc_adaption_handler(self.tc_adaption_slider) |
| 2813 |
if self.worker.argyll_version == [ |
| 2814 |
1, |
| 2815 |
1, |
| 2816 |
"RC2", |
| 2817 |
] or self.worker.argyll_version >= [1, 1]: |
| 2818 |
self.tc_gamma_floatctrl.SetValue(getcfg("tc_gamma")) |
| 2819 |
if self.worker.argyll_version >= [1, 3, 3]: |
| 2820 |
self.tc_neutral_axis_emphasis_slider.SetValue( |
| 2821 |
int(getcfg("tc_neutral_axis_emphasis") * 100) |
| 2822 |
) |
| 2823 |
self.tc_neutral_axis_emphasis_handler(self.tc_neutral_axis_emphasis_slider) |
| 2824 |
if self.worker.argyll_version >= [1, 6, 2]: |
| 2825 |
self.tc_dark_emphasis_slider.SetValue(int(getcfg("tc_dark_emphasis") * 100)) |
| 2826 |
self.tc_dark_emphasis_handler(self.tc_dark_emphasis_slider) |
| 2827 |
self.tc_precond_profile.SetPath(getcfg("tc_precond_profile")) |
| 2828 |
self.tc_filter.SetValue(bool(int(getcfg("tc_filter")))) |
| 2829 |
self.tc_filter_L.SetValue(getcfg("tc_filter_L")) |
| 2830 |
self.tc_filter_a.SetValue(getcfg("tc_filter_a")) |
| 2831 |
self.tc_filter_b.SetValue(getcfg("tc_filter_b")) |
| 2832 |
self.tc_filter_rad.SetValue(getcfg("tc_filter_rad")) |
| 2833 |
self.tc_vrml_cie.SetValue(bool(int(getcfg("tc_vrml_cie")))) |
| 2834 |
self.tc_vrml_cie_colorspace_ctrl.SetSelection( |
| 2835 |
config.VALID_VALUES["tc_vrml_cie_colorspace"].index( |
| 2836 |
getcfg("tc_vrml_cie_colorspace") |
| 2837 |
) |
| 2838 |
) |
| 2839 |
self.tc_vrml_device_colorspace_ctrl.SetSelection( |
| 2840 |
config.VALID_VALUES["tc_vrml_device_colorspace"].index( |
| 2841 |
getcfg("tc_vrml_device_colorspace") |
| 2842 |
) |
| 2843 |
) |
| 2844 |
self.tc_vrml_device.SetValue(bool(int(getcfg("tc_vrml_device")))) |
| 2845 |
self.tc_vrml_black_offset_intctrl.SetValue(getcfg("tc_vrml_black_offset")) |
| 2846 |
self.tc_vrml_use_D50_cb.SetValue(bool(getcfg("tc_vrml_use_D50"))) |
| 2847 |
self.tc_vrml_handler() |
| 2848 |
self.tc_vrml_compress_cb.SetValue(bool(getcfg("vrml.compress"))) |
| 2849 |
self.add_ti3_relative_cb.SetValue(bool(getcfg("tc_add_ti3_relative"))) |
| 2850 |
self.tc_enable_sort_controls() |
| 2851 |
|
| 2852 |
def tc_check(self, event=None): |
| 2853 |
"""Validate and update test chart controls.""" |
| 2854 |
white_patches = self.tc_white_patches.GetValue() |
| 2855 |
self.tc_amount = self.tc_get_total_patches(white_patches) |
| 2856 |
self.preview_btn.Enable( |
| 2857 |
self.tc_amount |
| 2858 |
- max(0, self.tc_get_white_patches()) |
| 2859 |
- max(0, self.tc_get_black_patches()) |
| 2860 |
>= 8 |
| 2861 |
) |
| 2862 |
self.clear_btn.Enable(hasattr(self, "ti1")) |
| 2863 |
self.tc_save_check() |
| 2864 |
self.save_as_btn.Enable(hasattr(self, "ti1")) |
| 2865 |
self.export_btn.Enable(hasattr(self, "ti1")) |
| 2866 |
self.tc_vrml_handler() |
| 2867 |
self.tc_enable_add_precond_controls() |
| 2868 |
self.tc_enable_sort_controls() |
| 2869 |
self.tc_set_default_status() |
| 2870 |
|
| 2871 |
def tc_save_check(self): |
| 2872 |
"""Check if the save button should be enabled based on the current state.""" |
| 2873 |
self.save_btn.Enable( |
| 2874 |
hasattr(self, "ti1") |
| 2875 |
and self.ti1.modified |
| 2876 |
and bool(self.ti1.filename) |
| 2877 |
and os.path.exists(self.ti1.filename) |
| 2878 |
and get_data_path(os.path.join("ref", os.path.basename(self.ti1.filename))) |
| 2879 |
!= self.ti1.filename |
| 2880 |
and get_data_path(os.path.join("ti1", os.path.basename(self.ti1.filename))) |
| 2881 |
!= self.ti1.filename |
| 2882 |
) |
| 2883 |
|
| 2884 |
def tc_save_cfg(self): |
| 2885 |
"""Save the current test chart configuration to the settings.""" |
| 2886 |
setcfg("tc_white_patches", self.tc_white_patches.GetValue()) |
| 2887 |
if self.worker.argyll_version >= [1, 6]: |
| 2888 |
setcfg("tc_black_patches", self.tc_black_patches.GetValue()) |
| 2889 |
setcfg("tc_single_channel_patches", self.tc_single_channel_patches.GetValue()) |
| 2890 |
setcfg("tc_gray_patches", self.tc_gray_patches.GetValue()) |
| 2891 |
setcfg("tc_multi_steps", self.tc_multi_steps.GetValue()) |
| 2892 |
setcfg("tc_fullspread_patches", self.tc_fullspread_patches.GetValue()) |
| 2893 |
tc_algo = self.tc_algos_ba[self.tc_algo.GetStringSelection()] |
| 2894 |
setcfg("tc_algo", tc_algo) |
| 2895 |
setcfg("tc_angle", self.tc_angle_intctrl.GetValue() / 10000.0) |
| 2896 |
setcfg("tc_adaption", self.tc_adaption_intctrl.GetValue() / 100.0) |
| 2897 |
tc_precond_enable = tc_algo in ("I", "Q", "R", "t") or ( |
| 2898 |
tc_algo == "" and self.tc_adaption_slider.GetValue() > 0 |
| 2899 |
) |
| 2900 |
if tc_precond_enable: |
| 2901 |
setcfg("tc_precond", int(self.tc_precond.GetValue())) |
| 2902 |
setcfg("tc_precond_profile", self.tc_precond_profile.GetPath()) |
| 2903 |
setcfg("tc_filter", int(self.tc_filter.GetValue())) |
| 2904 |
setcfg("tc_filter_L", self.tc_filter_L.GetValue()) |
| 2905 |
setcfg("tc_filter_a", self.tc_filter_a.GetValue()) |
| 2906 |
setcfg("tc_filter_b", self.tc_filter_b.GetValue()) |
| 2907 |
setcfg("tc_filter_rad", self.tc_filter_rad.GetValue()) |
| 2908 |
setcfg("tc_vrml_cie", int(self.tc_vrml_cie.GetValue())) |
| 2909 |
setcfg("tc_vrml_device", int(self.tc_vrml_device.GetValue())) |
| 2910 |
|
| 2911 |
def tc_preview_handler(self, event=None, path=None): |
| 2912 |
"""Handle the preview button click event. |
| 2913 |
|
| 2914 |
Args: |
| 2915 |
event (wx.Event): The event that triggered the preview. |
| 2916 |
path (str): Optional path to save the preview. |
| 2917 |
""" |
| 2918 |
if self.worker.is_working(): |
| 2919 |
return |
| 2920 |
|
| 2921 |
fullspread_patches = getcfg("tc_fullspread_patches") |
| 2922 |
single_patches = getcfg("tc_single_channel_patches") |
| 2923 |
gray_patches = getcfg("tc_gray_patches") |
| 2924 |
multidim_patches = getcfg("tc_multi_steps") |
| 2925 |
multidim_bcc_patches = getcfg("tc_multi_bcc_steps") |
| 2926 |
wkwargs = {} |
| 2927 |
if ( |
| 2928 |
fullspread_patches |
| 2929 |
and ( |
| 2930 |
single_patches > 2 |
| 2931 |
or gray_patches > 2 |
| 2932 |
or multidim_patches > 2 |
| 2933 |
or multidim_bcc_patches |
| 2934 |
) |
| 2935 |
and wx.GetKeyState(wx.WXK_SHIFT) |
| 2936 |
): |
| 2937 |
dlg = ConfirmDialog( |
| 2938 |
self, |
| 2939 |
-1, |
| 2940 |
lang.getstr("testchart.create"), |
| 2941 |
lang.getstr("testchart.separate_fixed_points"), |
| 2942 |
ok=lang.getstr("ok"), |
| 2943 |
cancel=lang.getstr("cancel"), |
| 2944 |
bitmap=get_icon(32, APPNAME + "-testchart-editor"), |
| 2945 |
) |
| 2946 |
dlg.sizer3.Add((1, 4)) |
| 2947 |
|
| 2948 |
# single |
| 2949 |
if single_patches > 2: |
| 2950 |
dlg.single = wx.CheckBox(dlg, -1, lang.getstr("tc.single")) |
| 2951 |
dlg.sizer3.Add(dlg.single, 1, flag=wx.TOP, border=4) |
| 2952 |
dlg.single.Value = True |
| 2953 |
|
| 2954 |
# gray |
| 2955 |
if gray_patches > 2: |
| 2956 |
dlg.gray_patches = wx.CheckBox(dlg, -1, lang.getstr("tc.gray")) |
| 2957 |
dlg.sizer3.Add(dlg.gray, 1, flag=wx.TOP, border=4) |
| 2958 |
dlg.gray.Value = True |
| 2959 |
|
| 2960 |
# multidim |
| 2961 |
if multidim_patches > 2 or multidim_bcc_patches: |
| 2962 |
dlg.multidim = wx.CheckBox(dlg, -1, lang.getstr("tc.multidim")) |
| 2963 |
dlg.sizer3.Add(dlg.multidim, 1, flag=wx.TOP, border=4) |
| 2964 |
dlg.multidim.Value = True |
| 2965 |
|
| 2966 |
dlg.sizer0.SetSizeHints(dlg) |
| 2967 |
dlg.sizer0.Layout() |
| 2968 |
choice = dlg.ShowModal() |
| 2969 |
for name in ("single", "gray", "multidim"): |
| 2970 |
if hasattr(dlg, name): |
| 2971 |
wkwargs[name] = getattr(dlg, name).Value |
| 2972 |
dlg.Destroy() |
| 2973 |
if choice == wx.ID_CANCEL: |
| 2974 |
return |
| 2975 |
|
| 2976 |
if not self.tc_check_save_ti1(): |
| 2977 |
return |
| 2978 |
if not check_set_argyll_bin(): |
| 2979 |
return |
| 2980 |
|
| 2981 |
print("-" * 80) |
| 2982 |
print(lang.getstr("testchart.create")) |
| 2983 |
self.worker.interactive = False |
| 2984 |
self.worker.start( |
| 2985 |
self.tc_preview, |
| 2986 |
self.tc_create, |
| 2987 |
cargs=(path,), |
| 2988 |
wargs=(), |
| 2989 |
wkwargs=wkwargs, |
| 2990 |
progress_msg=lang.getstr("testchart.create"), |
| 2991 |
parent=self, |
| 2992 |
progress_start=500, |
| 2993 |
) |
| 2994 |
|
| 2995 |
def tc_preview_update(self, startindex): |
| 2996 |
"""Update the preview grid with the current test chart data. |
| 2997 |
|
| 2998 |
Args: |
| 2999 |
startindex (int): The index from which to start updating the preview. |
| 3000 |
""" |
| 3001 |
if not hasattr(self, "preview"): |
| 3002 |
return |
| 3003 |
numcols = self.preview.GetNumberCols() |
| 3004 |
startrow = startindex / numcols |
| 3005 |
startcol = startindex % numcols |
| 3006 |
i = 0 |
| 3007 |
row = startrow |
| 3008 |
numrows = self.preview.GetNumberRows() |
| 3009 |
neededrows = math.ceil(float(self.grid.GetNumberRows()) / numcols) - numrows |
| 3010 |
if neededrows > 0: |
| 3011 |
self.preview.AppendRows(neededrows) |
| 3012 |
while True: |
| 3013 |
cols = range(startcol, numcols) if row == startrow else range(numcols) |
| 3014 |
for col in cols: |
| 3015 |
if startindex + i < self.grid.GetNumberRows(): |
| 3016 |
color = self.grid.GetCellBackgroundColour(startindex + i, 3) |
| 3017 |
textcolor = self.grid.GetCellTextColour(startindex + i, 3) |
| 3018 |
value = self.grid.GetCellValue(startindex + i, 3) |
| 3019 |
else: |
| 3020 |
color = self.preview.GetDefaultCellBackgroundColour() |
| 3021 |
textcolor = self.preview.GetDefaultCellTextColour() |
| 3022 |
value = "" |
| 3023 |
self.preview.SetCellBackgroundColour(row, col, color) |
| 3024 |
self.preview.SetCellTextColour(row, col, textcolor) |
| 3025 |
self.preview.SetCellValue(row, col, value) |
| 3026 |
i += 1 |
| 3027 |
row += 1 |
| 3028 |
if startindex + i >= self.grid.GetNumberRows(): |
| 3029 |
break |
| 3030 |
if row < self.preview.GetNumberRows(): |
| 3031 |
self.preview.DeleteRows(row, self.preview.GetNumberRows() - row) |
| 3032 |
|
| 3033 |
def tc_clear_handler(self, event): |
| 3034 |
"""Clear the test chart editor. |
| 3035 |
|
| 3036 |
Args: |
| 3037 |
event (wx.Event): The event that triggered the clear. |
| 3038 |
""" |
| 3039 |
self.tc_check_save_ti1() |
| 3040 |
|
| 3041 |
def tc_clear(self, clear_ti1=True): |
| 3042 |
"""Clear the test chart editor. |
| 3043 |
|
| 3044 |
Args: |
| 3045 |
clear_ti1 (bool): If True, clear the ti1 object and reset the |
| 3046 |
window title. |
| 3047 |
""" |
| 3048 |
grid = self.grid |
| 3049 |
if grid.GetNumberRows() > 0: |
| 3050 |
grid.DeleteRows(0, grid.GetNumberRows()) |
| 3051 |
if grid.GetNumberCols() > 0: |
| 3052 |
grid.DeleteCols(0, grid.GetNumberCols()) |
| 3053 |
grid.Refresh() |
| 3054 |
self.separator.Hide() |
| 3055 |
self.sizer.Layout() |
| 3056 |
if hasattr(self, "preview"): |
| 3057 |
if self.preview.GetNumberRows() > 0: |
| 3058 |
self.preview.DeleteRows(0, self.preview.GetNumberRows()) |
| 3059 |
if self.preview.GetNumberCols() > 0: |
| 3060 |
self.preview.DeleteCols(0, self.preview.GetNumberCols()) |
| 3061 |
self.preview.Refresh() |
| 3062 |
if clear_ti1: |
| 3063 |
if hasattr(self, "ti1"): |
| 3064 |
del self.ti1 |
| 3065 |
self.tc_update_controls() |
| 3066 |
self.tc_check() |
| 3067 |
# UGLY HACK: This 'print' call fixes a GTK assertion and |
| 3068 |
# segfault under Arch Linux when setting the window title |
| 3069 |
print("") |
| 3070 |
self.SetTitle(lang.getstr("testchart.edit")) |
| 3071 |
|
| 3072 |
def tc_export_handler(self, event): |
| 3073 |
"""Export the test chart to a file. |
| 3074 |
|
| 3075 |
Args: |
| 3076 |
event (wx.Event): The event that triggered the export. |
| 3077 |
""" |
| 3078 |
if not hasattr(self, "ti1"): |
| 3079 |
return |
| 3080 |
path = None |
| 3081 |
(defaultDir, defaultFile) = ( |
| 3082 |
get_verified_path("last_testchart_export_path")[0], |
| 3083 |
os.path.basename( |
| 3084 |
os.path.splitext( |
| 3085 |
self.ti1.filename or DEFAULTS["last_testchart_export_path"] |
| 3086 |
)[0] |
| 3087 |
), |
| 3088 |
) |
| 3089 |
dlg = wx.FileDialog( |
| 3090 |
self, |
| 3091 |
lang.getstr("export"), |
| 3092 |
defaultDir=defaultDir, |
| 3093 |
defaultFile=defaultFile, |
| 3094 |
# Disable JPEG as it introduces slight color errors |
| 3095 |
wildcard=lang.getstr( # lang.getstr("filetype.jpg") + "|*.jpg|" + |
| 3096 |
"filetype.png" |
| 3097 |
) |
| 3098 |
+ " (8-bit)|*.png|" |
| 3099 |
+ lang.getstr("filetype.png") |
| 3100 |
+ " (16-bit)|*.png|" |
| 3101 |
+ lang.getstr("filetype.tif") |
| 3102 |
+ " (8-bit)|*.tif|" |
| 3103 |
+ lang.getstr("filetype.tif") |
| 3104 |
+ " (16-bit)|*.tif|" |
| 3105 |
+ "DPX|*.dpx|" |
| 3106 |
+ "CSV (0.0..100.0)|*.csv|" |
| 3107 |
+ "CSV (0..255)|*.csv|" |
| 3108 |
+ "CSV (0..1023)|*.csv", |
| 3109 |
style=wx.SAVE | wx.OVERWRITE_PROMPT, |
| 3110 |
) |
| 3111 |
dlg.Center(wx.BOTH) |
| 3112 |
if dlg.ShowModal() == wx.ID_OK: |
| 3113 |
filter_index = dlg.GetFilterIndex() |
| 3114 |
path = dlg.GetPath() |
| 3115 |
dlg.Destroy() |
| 3116 |
if path: |
| 3117 |
if not waccess(path, os.W_OK): |
| 3118 |
show_result_dialog( |
| 3119 |
Error(lang.getstr("error.access_denied.write", path)), self |
| 3120 |
) |
| 3121 |
return |
| 3122 |
setcfg("last_testchart_export_path", path) |
| 3123 |
self.writecfg() |
| 3124 |
else: |
| 3125 |
return |
| 3126 |
if filter_index < 5: |
| 3127 |
# Image format |
| 3128 |
scale = getcfg("app.dpi") / config.get_default_dpi() |
| 3129 |
scale = max(scale, 1) |
| 3130 |
dlg = ConfirmDialog( |
| 3131 |
self, |
| 3132 |
title=lang.getstr("export"), |
| 3133 |
msg=lang.getstr("testchart.export.repeat_patch"), |
| 3134 |
ok=lang.getstr("ok"), |
| 3135 |
cancel=lang.getstr("cancel"), |
| 3136 |
bitmap=get_icon(32, APPNAME + "-testchart-editor"), |
| 3137 |
) |
| 3138 |
sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 3139 |
dlg.sizer3.Add(sizer, 0, flag=wx.TOP | wx.ALIGN_LEFT, border=12) |
| 3140 |
intctrl = wx.SpinCtrl( |
| 3141 |
dlg, |
| 3142 |
-1, |
| 3143 |
size=(95 * scale, -1), |
| 3144 |
min=config.VALID_RANGES["tc_export_repeat_patch_max"][0], |
| 3145 |
max=config.VALID_RANGES["tc_export_repeat_patch_max"][1], |
| 3146 |
value=str(getcfg("tc_export_repeat_patch_max")), |
| 3147 |
) |
| 3148 |
sizer.Add(intctrl, 0, flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, border=4) |
| 3149 |
sizer.Add( |
| 3150 |
wx.StaticText(dlg, -1, "× " + lang.getstr("max")), # noqa: RUF001 |
| 3151 |
0, |
| 3152 |
flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, |
| 3153 |
border=12, |
| 3154 |
) |
| 3155 |
intctrl2 = wx.SpinCtrl( |
| 3156 |
dlg, |
| 3157 |
-1, |
| 3158 |
size=(95 * scale, -1), |
| 3159 |
min=config.VALID_RANGES["tc_export_repeat_patch_min"][0], |
| 3160 |
max=config.VALID_RANGES["tc_export_repeat_patch_min"][1], |
| 3161 |
value=str(getcfg("tc_export_repeat_patch_min")), |
| 3162 |
) |
| 3163 |
sizer.Add(intctrl2, 0, flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, border=4) |
| 3164 |
sizer.Add( |
| 3165 |
wx.StaticText(dlg, -1, "× " + lang.getstr("min")), # noqa: RUF001 |
| 3166 |
0, |
| 3167 |
flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, |
| 3168 |
border=12, |
| 3169 |
) |
| 3170 |
dlg.sizer0.SetSizeHints(dlg) |
| 3171 |
dlg.sizer0.Layout() |
| 3172 |
result = dlg.ShowModal() |
| 3173 |
repeatmax = intctrl.GetValue() |
| 3174 |
repeatmin = intctrl2.GetValue() |
| 3175 |
dlg.Destroy() |
| 3176 |
if result != wx.ID_OK: |
| 3177 |
return |
| 3178 |
setcfg("tc_export_repeat_patch_max", repeatmax) |
| 3179 |
setcfg("tc_export_repeat_patch_min", repeatmin) |
| 3180 |
self.writecfg() |
| 3181 |
DEFAULTS["size.measureframe"] = get_default_size() |
| 3182 |
self.display_size = wx.DisplaySize() |
| 3183 |
if path: |
| 3184 |
self.worker.start( |
| 3185 |
lambda result: None, |
| 3186 |
self.tc_export, |
| 3187 |
wargs=(path, filter_index), |
| 3188 |
wkwargs={}, |
| 3189 |
progress_msg=lang.getstr("export"), |
| 3190 |
parent=self, |
| 3191 |
progress_start=500, |
| 3192 |
fancy=False, |
| 3193 |
) |
| 3194 |
|
| 3195 |
def tc_export(self, path, filter_index): |
| 3196 |
"""Export the test chart to the given path. |
| 3197 |
|
| 3198 |
Args: |
| 3199 |
path (str): The file path to export the test chart to. |
| 3200 |
filter_index (int): Index of the selected filter format. |
| 3201 |
""" |
| 3202 |
if filter_index < 5: |
| 3203 |
# Image format |
| 3204 |
self.tc_export_subroutine(path, filter_index) |
| 3205 |
return |
| 3206 |
|
| 3207 |
# CSV |
| 3208 |
with open(path, "w") as csvfile: |
| 3209 |
self.tc_export_subroutine(csv.writer(csvfile), filter_index) |
| 3210 |
|
| 3211 |
def tc_export_subroutine(self, target, filter_index, allow_gaps=False): |
| 3212 |
"""Export the test chart to the given target. |
| 3213 |
|
| 3214 |
Args: |
| 3215 |
target (str or csv.writer): The file path for image formats or a |
| 3216 |
CSV writer object. |
| 3217 |
filter_index (int): Index of the selected filter format. |
| 3218 |
allow_gaps (bool): Whether to allow gaps in the timecode. |
| 3219 |
""" |
| 3220 |
maxlen = len(self.ti1[0].DATA) |
| 3221 |
if filter_index < 5: |
| 3222 |
# Image format |
| 3223 |
name, ext = ( |
| 3224 |
os.path.splitext(target)[0], |
| 3225 |
{0: ".png", 1: ".png", 2: ".tif", 3: ".tif", 4: ".dpx"}[filter_index], |
| 3226 |
) |
| 3227 |
file_format = {".dpx": "DPX", ".png": "PNG", ".tif": "TIFF"}[ext] |
| 3228 |
bitdepth = {0: 8, 1: 16, 2: 8, 3: 16, 4: 10}[filter_index] |
| 3229 |
vscale = 2**bitdepth - 1 |
| 3230 |
repeatmax = getcfg("tc_export_repeat_patch_max") |
| 3231 |
repeatmin = getcfg("tc_export_repeat_patch_min") |
| 3232 |
maxcount = maxlen * repeatmax |
| 3233 |
filename_format = f"{{:s}}-{{:0{len(str(maxcount))}d}}{{:s}}" |
| 3234 |
count = 0 |
| 3235 |
secs = 0 |
| 3236 |
# Scale from screen dimensions to fixed 1080p viewport |
| 3237 |
sw, sh = 1920, 1080 |
| 3238 |
x, y, size = [ |
| 3239 |
float(v) for v in getcfg("dimensions.measureframe").split(",") |
| 3240 |
] |
| 3241 |
size *= DEFAULTS["size.measureframe"] |
| 3242 |
displays = getcfg("displays") |
| 3243 |
match = None |
| 3244 |
display_no = getcfg("display.number") - 1 |
| 3245 |
if display_no in range(len(displays)): |
| 3246 |
match = re.search(r"@ -?\d+, -?\d+, (\d+)x(\d+)", displays[display_no]) |
| 3247 |
if match: |
| 3248 |
display_size = [int(item) for item in match.groups()] |
| 3249 |
else: |
| 3250 |
display_size = self.display_size |
| 3251 |
w, h = [min(size / v, 1.0) for v in display_size] |
| 3252 |
x = (display_size[0] - size) * x / display_size[0] |
| 3253 |
y = (display_size[1] - size) * y / display_size[1] |
| 3254 |
x, y, w, h = [max(v, 0) for v in (x, y, w, h)] |
| 3255 |
x, w = [round(v * sw) for v in (x, w)] |
| 3256 |
y, h = [round(v * sh) for v in (y, h)] |
| 3257 |
dimensions = w, h |
| 3258 |
else: |
| 3259 |
# CSV |
| 3260 |
vscale = {5: 100, 6: 255, 7: 1023}[filter_index] |
| 3261 |
is_winnt6 = sys.platform == "win32" and sys.getwindowsversion() >= (6,) |
| 3262 |
use_winnt6_symlinks = is_winnt6 and is_superuser() |
| 3263 |
for i in range(maxlen): |
| 3264 |
if self.worker.thread_abort: |
| 3265 |
break |
| 3266 |
self.worker.lastmsg.write(f"{100.0 / maxlen * (i + 1)}%\n") |
| 3267 |
R, G, B = ( |
| 3268 |
self.ti1[0].DATA[i]["RGB_R"], |
| 3269 |
self.ti1[0].DATA[i]["RGB_G"], |
| 3270 |
self.ti1[0].DATA[i]["RGB_B"], |
| 3271 |
) |
| 3272 |
if not filter_index < 5: |
| 3273 |
# CSV |
| 3274 |
if vscale != 100: |
| 3275 |
# XXX: Careful when rounding floats! |
| 3276 |
# Incorrect: round(50 * 2.55) = 127 (127.499999) |
| 3277 |
# Correct: round(50 / 100.0 * 255) = 128 (127.5) |
| 3278 |
# |
| 3279 |
# Wouldn't it be better to use: round(50 * 255.0 / 100.0) |
| 3280 |
R, G, B = [round(v / 100.0 * vscale) for v in [R, G, B]] |
| 3281 |
target.writerow([str(v) for v in [i, R, G, B]]) |
| 3282 |
continue |
| 3283 |
# Image format |
| 3284 |
X, Y, Z = colormath.RGB2XYZ(R / 100.0, G / 100.0, B / 100.0, scale=100.0) |
| 3285 |
L, a, b = colormath.XYZ2Lab(X, Y, Z) |
| 3286 |
# XXX: Careful when rounding floats! |
| 3287 |
# Incorrect: int(round(50 * 2.55)) = 127 (127.499999) |
| 3288 |
# Correct: int(round(50 / 100.0 * 255)) = 128 (127.5) |
| 3289 |
color = ( |
| 3290 |
round(R / 100.0 * vscale), |
| 3291 |
round(G / 100.0 * vscale), |
| 3292 |
round(B / 100.0 * vscale), |
| 3293 |
) |
| 3294 |
count += 1 |
| 3295 |
filename = filename_format.format(name, count, ext) |
| 3296 |
repeat = round(repeatmin + ((repeatmax - repeatmin) / 100.0 * (100 - L))) |
| 3297 |
imfile.write( |
| 3298 |
[[color]], |
| 3299 |
filename, |
| 3300 |
bitdepth, |
| 3301 |
file_format, |
| 3302 |
dimensions, |
| 3303 |
{ |
| 3304 |
"original_width": sw, |
| 3305 |
"original_height": sh, |
| 3306 |
"offset_x": x, |
| 3307 |
"offset_y": y, |
| 3308 |
"frame_position": count, |
| 3309 |
"frame_rate": 1, |
| 3310 |
"held_count": repeat if allow_gaps else 1, |
| 3311 |
"timecode": [ |
| 3312 |
int(v) |
| 3313 |
for v in time.strftime("%H:%M:%S:00", time.gmtime(secs)).split( |
| 3314 |
":" |
| 3315 |
) |
| 3316 |
], |
| 3317 |
}, |
| 3318 |
) |
| 3319 |
secs += 1 |
| 3320 |
# print("RGB", R, G, B, "L* %.2f" % L, "repeat", repeat) |
| 3321 |
if repeat > 1: |
| 3322 |
if allow_gaps: |
| 3323 |
count += repeat - 1 |
| 3324 |
secs += repeat - 1 |
| 3325 |
continue |
| 3326 |
for _ in range(repeat - 1): |
| 3327 |
count += 1 |
| 3328 |
filecopyname = filename_format % (name, count, ext) |
| 3329 |
if file_format == "DPX": |
| 3330 |
imfile.write( |
| 3331 |
[[color]], |
| 3332 |
filecopyname, |
| 3333 |
bitdepth, |
| 3334 |
file_format, |
| 3335 |
dimensions, |
| 3336 |
{ |
| 3337 |
"original_width": sw, |
| 3338 |
"original_height": sh, |
| 3339 |
"offset_x": x, |
| 3340 |
"offset_y": y, |
| 3341 |
"frame_position": count, |
| 3342 |
"frame_rate": 1, |
| 3343 |
"timecode": [ |
| 3344 |
int(v) |
| 3345 |
for v in time.strftime( |
| 3346 |
"%H:%M:%S:00", time.gmtime(secs) |
| 3347 |
).split(":") |
| 3348 |
], |
| 3349 |
}, |
| 3350 |
) |
| 3351 |
secs += 1 |
| 3352 |
if file_format == "DPX": |
| 3353 |
continue |
| 3354 |
if os.path.isfile(filecopyname): |
| 3355 |
os.unlink(filecopyname) |
| 3356 |
if is_winnt6: |
| 3357 |
if use_winnt6_symlinks: |
| 3358 |
win32file.CreateSymbolicLink( |
| 3359 |
filecopyname, os.path.basename(filename), 0 |
| 3360 |
) |
| 3361 |
else: |
| 3362 |
shutil.copyfile(filename, filecopyname) |
| 3363 |
else: |
| 3364 |
os.symlink(os.path.basename(filename), filecopyname) |
| 3365 |
|
| 3366 |
def tc_save_handler(self, event=None): |
| 3367 |
"""Save the testchart to its current filename. |
| 3368 |
|
| 3369 |
Args: |
| 3370 |
event: The event that triggered this handler, if any. |
| 3371 |
""" |
| 3372 |
self.tc_save_as_handler(event, path=self.ti1.filename) |
| 3373 |
|
| 3374 |
def tc_save_as_handler(self, event=None, path=None): |
| 3375 |
"""Open a file dialog to save the testchart. |
| 3376 |
|
| 3377 |
Args: |
| 3378 |
event: The event that triggered this handler, if any. |
| 3379 |
path (str): The path to save the testchart to. If None, a dialog |
| 3380 |
will be opened. |
| 3381 |
|
| 3382 |
Returns: |
| 3383 |
bool: True if the testchart was saved successfully, False otherwise. |
| 3384 |
""" |
| 3385 |
checkoverwrite = True |
| 3386 |
if path is None or (event and not os.path.isfile(path)): |
| 3387 |
path = None |
| 3388 |
defaultDir = get_verified_path("last_ti1_path")[0] |
| 3389 |
if hasattr(self, "ti1") and self.ti1.filename: |
| 3390 |
if os.path.isfile(self.ti1.filename): |
| 3391 |
defaultDir = os.path.dirname(self.ti1.filename) |
| 3392 |
defaultFile = os.path.basename(self.ti1.filename) |
| 3393 |
else: |
| 3394 |
defaultFile = os.path.basename(config.DEFAULTS["last_ti1_path"]) |
| 3395 |
dlg = wx.FileDialog( |
| 3396 |
self, |
| 3397 |
lang.getstr("save_as"), |
| 3398 |
defaultDir=defaultDir, |
| 3399 |
defaultFile=defaultFile, |
| 3400 |
wildcard=lang.getstr("filetype.ti1") + "|*.ti1", |
| 3401 |
style=wx.SAVE | wx.OVERWRITE_PROMPT, |
| 3402 |
) |
| 3403 |
dlg.Center(wx.BOTH) |
| 3404 |
if dlg.ShowModal() == wx.ID_OK: |
| 3405 |
path = dlg.GetPath() |
| 3406 |
dlg.Destroy() |
| 3407 |
if path: |
| 3408 |
filename, ext = os.path.splitext(path) |
| 3409 |
if ext.lower() != ".ti1": |
| 3410 |
path += ".ti1" |
| 3411 |
else: |
| 3412 |
checkoverwrite = False |
| 3413 |
if path: |
| 3414 |
if not waccess(path, os.W_OK): |
| 3415 |
show_result_dialog( |
| 3416 |
Error(lang.getstr("error.access_denied.write", path)), self |
| 3417 |
) |
| 3418 |
return None |
| 3419 |
if checkoverwrite and os.path.isfile(path): |
| 3420 |
dlg = ConfirmDialog( |
| 3421 |
self, |
| 3422 |
msg=lang.getstr("dialog.confirm_overwrite", (path)), |
| 3423 |
ok=lang.getstr("overwrite"), |
| 3424 |
cancel=lang.getstr("cancel"), |
| 3425 |
bitmap=get_icon(32, "dialog-warning"), |
| 3426 |
) |
| 3427 |
result = dlg.ShowModal() |
| 3428 |
dlg.Destroy() |
| 3429 |
if result != wx.ID_OK: |
| 3430 |
return None |
| 3431 |
setcfg("last_ti1_path", path) |
| 3432 |
try: |
| 3433 |
with open(path, "wb") as file_: |
| 3434 |
file_.write(bytes(self.ti1)) |
| 3435 |
self.ti1.filename = path |
| 3436 |
self.ti1.root.setmodified(False) |
| 3437 |
if not self.IsBeingDeleted(): |
| 3438 |
# UGLY HACK: This 'print' call fixes a GTK assertion and |
| 3439 |
# segfault under Arch Linux when setting the window title |
| 3440 |
print("") |
| 3441 |
self.SetTitle( |
| 3442 |
lang.getstr("testchart.edit").rstrip(".") |
| 3443 |
+ ": " |
| 3444 |
+ os.path.basename(path) |
| 3445 |
) |
| 3446 |
except Exception as exception: |
| 3447 |
handle_error( |
| 3448 |
Error(f"Error - testchart could not be saved: {exception!s}"), |
| 3449 |
parent=self, |
| 3450 |
) |
| 3451 |
else: |
| 3452 |
if self.Parent: |
| 3453 |
if path != getcfg(self.cfg) and self.parent_set_chart_methodname: |
| 3454 |
dlg = ConfirmDialog( |
| 3455 |
self, |
| 3456 |
msg=lang.getstr("testchart.confirm_select"), |
| 3457 |
ok=lang.getstr("testchart.select"), |
| 3458 |
cancel=lang.getstr("testchart.dont_select"), |
| 3459 |
bitmap=get_icon(32, "dialog-question"), |
| 3460 |
) |
| 3461 |
result = dlg.ShowModal() |
| 3462 |
dlg.Destroy() |
| 3463 |
if result == wx.ID_OK: |
| 3464 |
setcfg(self.cfg, path) |
| 3465 |
self.writecfg() |
| 3466 |
if path == getcfg(self.cfg) and self.parent_set_chart_methodname: |
| 3467 |
getattr(self.Parent, self.parent_set_chart_methodname)(path) |
| 3468 |
if not self.IsBeingDeleted(): |
| 3469 |
self.save_btn.Disable() |
| 3470 |
return True |
| 3471 |
return False |
| 3472 |
|
| 3473 |
def tc_view_3d(self, event): |
| 3474 |
"""View the 3D representation of the testchart. |
| 3475 |
|
| 3476 |
Args: |
| 3477 |
event (wx.Event): The event that triggered this method, if any. |
| 3478 |
""" |
| 3479 |
if ( |
| 3480 |
self.ti1.filename |
| 3481 |
and not ( |
| 3482 |
self.worker.tempdir |
| 3483 |
and self.ti1.filename.startswith(self.worker.tempdir) |
| 3484 |
) |
| 3485 |
and waccess(os.path.dirname(self.ti1.filename), os.W_OK) |
| 3486 |
): |
| 3487 |
regenerate = self.ti1.modified |
| 3488 |
paths = self.tc_save_3d( |
| 3489 |
os.path.splitext(self.ti1.filename)[0], regenerate=regenerate |
| 3490 |
) |
| 3491 |
if not regenerate and os.path.isfile(self.ti1.filename): |
| 3492 |
# Check if the testchart is newer than the 3D file(s) |
| 3493 |
ti1_mtime = os.stat(self.ti1.filename).st_mtime |
| 3494 |
for path in paths: |
| 3495 |
if os.stat(path).st_mtime < ti1_mtime: |
| 3496 |
regenerate = True |
| 3497 |
break |
| 3498 |
if regenerate: |
| 3499 |
paths = self.tc_save_3d( |
| 3500 |
os.path.splitext(self.ti1.filename)[0], regenerate=True |
| 3501 |
) |
| 3502 |
else: |
| 3503 |
paths = self.tc_save_3d_as_handler(None) |
| 3504 |
for path in paths: |
| 3505 |
launch_file(path) |
| 3506 |
|
| 3507 |
def tc_save_3d_as_handler(self, event): |
| 3508 |
"""Open a file dialog to save the 3D representation of the testchart. |
| 3509 |
|
| 3510 |
Args: |
| 3511 |
event: The event that triggered this handler, if any. |
| 3512 |
|
| 3513 |
Returns: |
| 3514 |
list: A list of paths to the saved 3D files. |
| 3515 |
""" |
| 3516 |
path = None |
| 3517 |
paths = [] |
| 3518 |
if ( |
| 3519 |
hasattr(self, "ti1") |
| 3520 |
and self.ti1.filename |
| 3521 |
and os.path.isfile(self.ti1.filename) |
| 3522 |
): |
| 3523 |
defaultDir = os.path.dirname(self.ti1.filename) |
| 3524 |
defaultFile = self.ti1.filename |
| 3525 |
else: |
| 3526 |
defaultDir = get_verified_path("last_vrml_path")[0] |
| 3527 |
defaultFile = DEFAULTS["last_vrml_path"] |
| 3528 |
view_3d_format = getcfg("3d.format") |
| 3529 |
if view_3d_format == "HTML": |
| 3530 |
formatext = ".html" |
| 3531 |
elif view_3d_format == "VRML": |
| 3532 |
formatext = ".wrz" if getcfg("vrml.compress") else ".wrl" |
| 3533 |
else: |
| 3534 |
formatext = ".x3d" |
| 3535 |
defaultFile = os.path.splitext(os.path.basename(defaultFile))[0] + formatext |
| 3536 |
dlg = wx.FileDialog( |
| 3537 |
self, |
| 3538 |
lang.getstr("save_as"), |
| 3539 |
defaultDir=defaultDir, |
| 3540 |
defaultFile=defaultFile, |
| 3541 |
wildcard=lang.getstr("view.3d") + "|*" + formatext, |
| 3542 |
style=wx.SAVE | wx.OVERWRITE_PROMPT, |
| 3543 |
) |
| 3544 |
dlg.Center(wx.BOTH) |
| 3545 |
if dlg.ShowModal() == wx.ID_OK: |
| 3546 |
path = dlg.GetPath() |
| 3547 |
dlg.Destroy() |
| 3548 |
if path: |
| 3549 |
if not waccess(path, os.W_OK): |
| 3550 |
show_result_dialog( |
| 3551 |
Error(lang.getstr("error.access_denied.write", path)), self |
| 3552 |
) |
| 3553 |
return [] |
| 3554 |
filename, ext = os.path.splitext(path) |
| 3555 |
if ext.lower() != formatext: |
| 3556 |
path += formatext |
| 3557 |
setcfg("last_vrml_path", path) |
| 3558 |
paths = self.tc_save_3d(filename) |
| 3559 |
return paths |
| 3560 |
|
| 3561 |
def tc_save_3d(self, filename, regenerate=True): |
| 3562 |
"""Save the 3D representation of the testchart. |
| 3563 |
|
| 3564 |
Args: |
| 3565 |
filename (str): The base filename to save the 3D files to. |
| 3566 |
regenerate (bool): Whether to regenerate the 3D files if they |
| 3567 |
already exist. Defaults to True. |
| 3568 |
|
| 3569 |
Returns: |
| 3570 |
list: A list of paths to the saved 3D files. |
| 3571 |
""" |
| 3572 |
paths = [] |
| 3573 |
view_3d_format = getcfg("3d.format") |
| 3574 |
if view_3d_format == "VRML": |
| 3575 |
formatext = ".wrz" if getcfg("vrml.compress") else ".wrl" |
| 3576 |
else: |
| 3577 |
formatext = ".x3d" |
| 3578 |
if view_3d_format == "HTML": |
| 3579 |
formatext += ".html" |
| 3580 |
if not getcfg("tc_vrml_device") and getcfg("tc_vrml_cie"): |
| 3581 |
return paths |
| 3582 |
colorspaces = [] |
| 3583 |
if getcfg("tc_vrml_device"): |
| 3584 |
colorspaces.append(getcfg("tc_vrml_device_colorspace")) |
| 3585 |
if getcfg("tc_vrml_cie"): |
| 3586 |
colorspaces.append(getcfg("tc_vrml_cie_colorspace")) |
| 3587 |
for colorspace in colorspaces: |
| 3588 |
path = filename + " " + colorspace + formatext |
| 3589 |
if os.path.exists(path): |
| 3590 |
if regenerate: |
| 3591 |
dlg = ConfirmDialog( |
| 3592 |
self, |
| 3593 |
msg=lang.getstr("dialog.confirm_overwrite", (path)), |
| 3594 |
ok=lang.getstr("overwrite"), |
| 3595 |
cancel=lang.getstr("cancel"), |
| 3596 |
bitmap=get_icon(32, "dialog-warning"), |
| 3597 |
) |
| 3598 |
result = dlg.ShowModal() |
| 3599 |
dlg.Destroy() |
| 3600 |
else: |
| 3601 |
result = wx.ID_CANCEL |
| 3602 |
if result != wx.ID_OK: |
| 3603 |
paths.append(path) |
| 3604 |
continue |
| 3605 |
try: |
| 3606 |
self.ti1[0].export_3d( |
| 3607 |
path, |
| 3608 |
colorspace, |
| 3609 |
RGB_black_offset=getcfg("tc_vrml_black_offset"), |
| 3610 |
normalize_RGB_white=getcfg("tc_vrml_use_D50"), |
| 3611 |
compress=formatext == ".wrz", |
| 3612 |
file_format=view_3d_format, |
| 3613 |
) |
| 3614 |
except Exception as exception: |
| 3615 |
handle_error( |
| 3616 |
UserWarning(f"Warning - 3D file could not be saved: {exception}"), |
| 3617 |
parent=self, |
| 3618 |
) |
| 3619 |
else: |
| 3620 |
paths.append(path) |
| 3621 |
return paths |
| 3622 |
|
| 3623 |
def tc_check_save_ti1(self, clear=True): |
| 3624 |
"""Check if the current testchart needs to be saved before closing. |
| 3625 |
|
| 3626 |
Args: |
| 3627 |
clear (bool): If True, clear the testchart after saving or discarding. |
| 3628 |
|
| 3629 |
Returns: |
| 3630 |
bool: True if the testchart can be closed, False otherwise. |
| 3631 |
""" |
| 3632 |
if not hasattr(self, "ti1"): |
| 3633 |
return True |
| 3634 |
if ( |
| 3635 |
self.ti1.root.modified |
| 3636 |
or not self.ti1.filename |
| 3637 |
or not os.path.exists(self.ti1.filename) |
| 3638 |
): |
| 3639 |
if self.save_btn.Enabled: |
| 3640 |
ok = lang.getstr("save") |
| 3641 |
else: |
| 3642 |
ok = lang.getstr("save_as") |
| 3643 |
dlg = ConfirmDialog( |
| 3644 |
self, |
| 3645 |
msg=lang.getstr("testchart.save_or_discard"), |
| 3646 |
ok=ok, |
| 3647 |
cancel=lang.getstr("cancel"), |
| 3648 |
bitmap=get_icon(32, "dialog-warning"), |
| 3649 |
) |
| 3650 |
if self.IsBeingDeleted(): |
| 3651 |
dlg.buttonpanel.Hide(0) |
| 3652 |
if self.save_btn.Enabled: |
| 3653 |
dlg.save_as = wx.Button(dlg.buttonpanel, -1, lang.getstr("save_as")) |
| 3654 |
ID_SAVE_AS = dlg.save_as.GetId() |
| 3655 |
dlg.Bind(wx.EVT_BUTTON, dlg.OnClose, id=ID_SAVE_AS) |
| 3656 |
dlg.sizer2.Add((12, 12)) |
| 3657 |
dlg.sizer2.Add(dlg.save_as) |
| 3658 |
else: |
| 3659 |
ID_SAVE_AS = wx.ID_OK |
| 3660 |
dlg.discard = wx.Button( |
| 3661 |
dlg.buttonpanel, -1, lang.getstr("testchart.discard") |
| 3662 |
) |
| 3663 |
ID_DISCARD = dlg.discard.GetId() |
| 3664 |
dlg.Bind(wx.EVT_BUTTON, dlg.OnClose, id=ID_DISCARD) |
| 3665 |
dlg.sizer2.Add((12, 12)) |
| 3666 |
dlg.sizer2.Add(dlg.discard) |
| 3667 |
dlg.buttonpanel.Layout() |
| 3668 |
dlg.sizer0.SetSizeHints(dlg) |
| 3669 |
dlg.sizer0.Layout() |
| 3670 |
result = dlg.ShowModal() |
| 3671 |
dlg.Destroy() |
| 3672 |
if result in (wx.ID_OK, ID_SAVE_AS): |
| 3673 |
path = None if result == ID_SAVE_AS else self.ti1.filename |
| 3674 |
if not self.tc_save_as_handler(True, path): |
| 3675 |
return False |
| 3676 |
elif result == wx.ID_CANCEL: |
| 3677 |
return False |
| 3678 |
clear = True |
| 3679 |
if clear and not self.IsBeingDeleted(): |
| 3680 |
self.tc_clear() |
| 3681 |
return True |
| 3682 |
|
| 3683 |
def tc_close_handler(self, event=None): |
| 3684 |
"""Handle the closing of the testchart editor. |
| 3685 |
|
| 3686 |
Args: |
| 3687 |
event (wx.CloseEvent, optional): The event that triggered this |
| 3688 |
function. |
| 3689 |
""" |
| 3690 |
if getattr(self.worker, "thread", None) and self.worker.thread.is_alive(): |
| 3691 |
self.worker.abort_subprocess(True) |
| 3692 |
return None |
| 3693 |
if (not event or self.IsShownOnScreen()) and self.tc_check_save_ti1(False): |
| 3694 |
setcfg("tc.saturation_sweeps", self.saturation_sweeps_intctrl.GetValue()) |
| 3695 |
for component in ("R", "G", "B"): |
| 3696 |
setcfg( |
| 3697 |
f"tc.saturation_sweeps.custom.{component}", |
| 3698 |
getattr( |
| 3699 |
self, f"saturation_sweeps_custom_{component}_ctrl" |
| 3700 |
).GetValue(), |
| 3701 |
) |
| 3702 |
self.worker.wrapup(False) |
| 3703 |
# Hide first (looks nicer) |
| 3704 |
self.Hide() |
| 3705 |
if self.Parent: |
| 3706 |
setcfg("tc.show", 0) |
| 3707 |
return True |
| 3708 |
self.writecfg() |
| 3709 |
# Need to use CallAfter to prevent hang under Windows if minimized |
| 3710 |
wx.CallAfter(self.Destroy) |
| 3711 |
elif isinstance(event, wx.CloseEvent) and event.CanVeto(): |
| 3712 |
event.Veto() |
| 3713 |
return None |
| 3714 |
|
| 3715 |
def tc_move_handler(self, event=None): |
| 3716 |
"""Handle the movement of the testchart editor window. |
| 3717 |
|
| 3718 |
Args: |
| 3719 |
event (wx.MoveEvent, optional): The event that triggered this function. |
| 3720 |
""" |
| 3721 |
if self.IsShownOnScreen() and not self.IsMaximized() and not self.IsIconized(): |
| 3722 |
x, y = self.GetScreenPosition() |
| 3723 |
setcfg("position.tcgen.x", x) |
| 3724 |
setcfg("position.tcgen.y", y) |
| 3725 |
if event: |
| 3726 |
event.Skip() |
| 3727 |
|
| 3728 |
def tc_destroy_handler(self, event): |
| 3729 |
"""Handle the destruction of the testchart editor. |
| 3730 |
|
| 3731 |
Args: |
| 3732 |
event: The event that triggered this function. |
| 3733 |
""" |
| 3734 |
event.Skip() |
| 3735 |
|
| 3736 |
def tc_load_cfg_from_ti1( |
| 3737 |
self, |
| 3738 |
event=None, |
| 3739 |
path=None, |
| 3740 |
cfg=None, |
| 3741 |
parent_set_chart_methodname=None, |
| 3742 |
resume=False, |
| 3743 |
): |
| 3744 |
"""Load a testchart from a file and update the UI accordingly. |
| 3745 |
|
| 3746 |
Args: |
| 3747 |
event: The event that triggered this function (optional). |
| 3748 |
path (str): Path to the testchart file (TI1, ICC, ICM, or TI3). |
| 3749 |
cfg (str): Configuration key to set the loaded testchart. |
| 3750 |
parent_set_chart_methodname (str): Method name in the parent to set |
| 3751 |
the chart. |
| 3752 |
resume (bool): Whether to resume a previous operation. |
| 3753 |
""" |
| 3754 |
if self.worker.is_working(): |
| 3755 |
return |
| 3756 |
|
| 3757 |
if cfg: |
| 3758 |
self.cfg = cfg |
| 3759 |
if path is None: |
| 3760 |
path = getcfg(self.cfg) |
| 3761 |
if path == "auto": |
| 3762 |
return |
| 3763 |
if parent_set_chart_methodname: |
| 3764 |
self.parent_set_chart_methodname = parent_set_chart_methodname |
| 3765 |
|
| 3766 |
if not self.tc_check_save_ti1(): |
| 3767 |
return |
| 3768 |
|
| 3769 |
print(lang.getstr("testchart.read")) |
| 3770 |
self.worker.interactive = False |
| 3771 |
self.worker.start( |
| 3772 |
self.tc_load_cfg_from_ti1_finish, |
| 3773 |
self.tc_load_cfg_from_ti1_worker, |
| 3774 |
wargs=(path,), |
| 3775 |
wkwargs={}, |
| 3776 |
progress_title=lang.getstr("testchart.read"), |
| 3777 |
progress_msg=lang.getstr("testchart.read"), |
| 3778 |
parent=self, |
| 3779 |
progress_start=500, |
| 3780 |
cancelable=False, |
| 3781 |
resume=resume, |
| 3782 |
show_remaining_time=False, |
| 3783 |
fancy=False, |
| 3784 |
) |
| 3785 |
|
| 3786 |
def tc_load_cfg_from_ti1_worker(self, path): |
| 3787 |
"""Worker function to load a testchart from a file. |
| 3788 |
|
| 3789 |
Args: |
| 3790 |
path (str): Path to the testchart file (TI1, ICC, ICM, or TI3). |
| 3791 |
|
| 3792 |
Returns: |
| 3793 |
CGATS: The loaded testchart as a CGATS object. |
| 3794 |
""" |
| 3795 |
path = str(path) |
| 3796 |
try: |
| 3797 |
filename, ext = os.path.splitext(path) |
| 3798 |
if ext.lower() not in (".icc", ".icm"): |
| 3799 |
if ext.lower() == ".ti3": |
| 3800 |
with open(path, "rb") as f: |
| 3801 |
ti3_data = f.read() |
| 3802 |
ti1 = CGATS(ti3_to_ti1(ti3_data)) |
| 3803 |
ti1.filename = filename + ".ti1" |
| 3804 |
else: |
| 3805 |
ti1 = CGATS(path) |
| 3806 |
ti1.filename = path |
| 3807 |
else: # icc or icm profile |
| 3808 |
profile = ICCProfile(path) |
| 3809 |
ti1 = CGATS( |
| 3810 |
ti3_to_ti1( |
| 3811 |
profile.tags.get("CIED", "") or profile.tags.get("targ", "") |
| 3812 |
) |
| 3813 |
) |
| 3814 |
ti1.filename = filename + ".ti1" |
| 3815 |
ti1.fix_device_values_scaling() |
| 3816 |
try: |
| 3817 |
ti1_1 = verify_cgats(ti1, ("RGB_R", "RGB_B", "RGB_G")) |
| 3818 |
except CGATSError as exception: |
| 3819 |
msg = { |
| 3820 |
CGATSKeyError: lang.getstr( |
| 3821 |
"error.testchart.missing_fields", (path, "RGB_R, RGB_G, RGB_B") |
| 3822 |
) |
| 3823 |
}.get( |
| 3824 |
exception.__class__, |
| 3825 |
lang.getstr("error.testchart.invalid", path) |
| 3826 |
+ "\n" |
| 3827 |
+ lang.getstr(str(exception)), |
| 3828 |
) |
| 3829 |
return Error(msg) |
| 3830 |
else: |
| 3831 |
try: |
| 3832 |
verify_cgats(ti1, ("XYZ_X", "XYZ_Y", "XYZ_Z")) |
| 3833 |
except CGATSKeyError: |
| 3834 |
# Missing XYZ, add via simple sRGB-like model |
| 3835 |
data = ti1_1.queryv1("DATA") |
| 3836 |
data.parent.DATA_FORMAT.add_data(("XYZ_X", "XYZ_Y", "XYZ_Z")) |
| 3837 |
for sample in data.values(): |
| 3838 |
XYZ = argyll_rgb2xyz.rgb2xyz( |
| 3839 |
*[sample["RGB_" + channel] / 100.0 for channel in "RGB"] |
| 3840 |
) |
| 3841 |
for i, component in enumerate("XYZ"): |
| 3842 |
sample["XYZ_" + component] = XYZ[i] * 100 |
| 3843 |
else: |
| 3844 |
if ext.lower() not in (".ti1", ".ti2") and ti1_1: |
| 3845 |
ti1_1.add_keyword("ACCURATE_EXPECTED_VALUES", "true") |
| 3846 |
ti1.root.setmodified(False) |
| 3847 |
self.ti1 = ti1 |
| 3848 |
except Exception as exception: |
| 3849 |
return Error( |
| 3850 |
"{}\n\n{}".format( |
| 3851 |
lang.getstr("error.testchart.read", path), str(exception) |
| 3852 |
) |
| 3853 |
) |
| 3854 |
|
| 3855 |
white_patches = self.ti1.queryv1("WHITE_COLOR_PATCHES") or None |
| 3856 |
black_patches = self.ti1.queryv1("BLACK_COLOR_PATCHES") or None |
| 3857 |
single_channel_patches = self.ti1.queryv1("SINGLE_DIM_STEPS") or None |
| 3858 |
gray_patches = self.ti1.queryv1("COMP_GREY_STEPS") or None |
| 3859 |
multi_bcc_steps = self.ti1.queryv1("MULTI_DIM_BCC_STEPS") or 0 |
| 3860 |
multi_steps = self.ti1.queryv1("MULTI_DIM_STEPS") or multi_bcc_steps |
| 3861 |
fullspread_patches = self.ti1.queryv1("NUMBER_OF_SETS") |
| 3862 |
gamma = self.ti1.queryv1("EXTRA_DEV_POW") or 1.0 |
| 3863 |
dark_emphasis = ((self.ti1.queryv1("DARK_REGION_EMPHASIS") or 1.0) - 1.0) / 3.0 |
| 3864 |
|
| 3865 |
if None in (white_patches, single_channel_patches, gray_patches, multi_steps): |
| 3866 |
if None in (single_channel_patches, gray_patches, multi_steps): |
| 3867 |
white_patches = 0 |
| 3868 |
black_patches = 0 |
| 3869 |
R = [] |
| 3870 |
G = [] |
| 3871 |
B = [] |
| 3872 |
gray_channel = [0] |
| 3873 |
data = self.ti1.queryv1("DATA") |
| 3874 |
multi = {"R": [], "G": [], "B": []} |
| 3875 |
if multi_steps is None: |
| 3876 |
multi_steps = 0 |
| 3877 |
uniqueRGB = [] |
| 3878 |
vmaxlen = 4 |
| 3879 |
for i in data: |
| 3880 |
if self.worker.thread_abort: |
| 3881 |
return False |
| 3882 |
# XXX Note that round(50 * 2.55) = 127, but |
| 3883 |
# round(50 / 100 * 255) = 128 (the latter is what we want)! |
| 3884 |
patch = [ |
| 3885 |
round(v / 100.0 * 255, vmaxlen) |
| 3886 |
for v in (data[i]["RGB_R"], data[i]["RGB_G"], data[i]["RGB_B"]) |
| 3887 |
] # normalize to 0...255 range |
| 3888 |
strpatch = [str(round(round(v, 1))) for v in patch] |
| 3889 |
if patch[0] == patch[1] == patch[2] == 255: # white |
| 3890 |
white_patches += 1 |
| 3891 |
if 255 not in gray_channel: |
| 3892 |
gray_channel.append(255) |
| 3893 |
elif patch[0] == patch[1] == patch[2] == 0: # black |
| 3894 |
black_patches += 1 |
| 3895 |
if 0 not in R and 0 not in G and 0 not in B: |
| 3896 |
R.append(0) |
| 3897 |
G.append(0) |
| 3898 |
B.append(0) |
| 3899 |
if 0 not in gray_channel: |
| 3900 |
gray_channel.append(0) |
| 3901 |
elif patch[2] == patch[1] == 0 and patch[0] not in R: # red |
| 3902 |
R.append(patch[0]) |
| 3903 |
elif patch[0] == patch[2] == 0 and patch[1] not in G: # green |
| 3904 |
G.append(patch[1]) |
| 3905 |
elif patch[0] == patch[1] == 0 and patch[2] not in B: # blue |
| 3906 |
B.append(patch[2]) |
| 3907 |
elif patch[0] == patch[1] == patch[2]: # gray |
| 3908 |
if patch[0] not in gray_channel: |
| 3909 |
gray_channel.append(patch[0]) |
| 3910 |
elif multi_steps == 0: |
| 3911 |
multi_steps = None |
| 3912 |
if DEBUG >= 9: |
| 3913 |
print("[D]", strpatch) |
| 3914 |
if strpatch not in uniqueRGB: |
| 3915 |
uniqueRGB.append(strpatch) |
| 3916 |
if patch[0] not in multi["R"]: |
| 3917 |
multi["R"].append(patch[0]) |
| 3918 |
if patch[1] not in multi["G"]: |
| 3919 |
multi["G"].append(patch[1]) |
| 3920 |
if patch[2] not in multi["B"]: |
| 3921 |
multi["B"].append(patch[2]) |
| 3922 |
|
| 3923 |
if single_channel_patches is None: |
| 3924 |
single_channel_patches = min(len(R), len(G), len(B)) |
| 3925 |
if gray_patches is None: |
| 3926 |
gray_patches = len(gray_channel) |
| 3927 |
if multi_steps is None: |
| 3928 |
multi_steps = 0 |
| 3929 |
|
| 3930 |
if single_channel_patches is None: |
| 3931 |
# NEVER (old code, needs work for demphasis/gamma, remove?) |
| 3932 |
R_inc = self.tc_get_increments(R, vmaxlen) |
| 3933 |
G_inc = self.tc_get_increments(G, vmaxlen) |
| 3934 |
B_inc = self.tc_get_increments(B, vmaxlen) |
| 3935 |
if DEBUG: |
| 3936 |
print("[D] R_inc:") |
| 3937 |
for i in R_inc: |
| 3938 |
if self.worker.thread_abort: |
| 3939 |
return False |
| 3940 |
print(f"[D] {i}: x{R_inc[i]}") |
| 3941 |
print("[D] G_inc:") |
| 3942 |
for i in G_inc: |
| 3943 |
if self.worker.thread_abort: |
| 3944 |
return False |
| 3945 |
print(f"[D] {i}: x{G_inc[i]}") |
| 3946 |
print("[D] B_inc:") |
| 3947 |
for i in B_inc: |
| 3948 |
if self.worker.thread_abort: |
| 3949 |
return False |
| 3950 |
print(f"[D] {i}: x{B_inc[i]}") |
| 3951 |
RGB_inc = {"0": 0} |
| 3952 |
for inc in R_inc: |
| 3953 |
if self.worker.thread_abort: |
| 3954 |
return False |
| 3955 |
if ( |
| 3956 |
inc in G_inc |
| 3957 |
and inc in B_inc |
| 3958 |
and R_inc[inc] == G_inc[inc] == B_inc[inc] |
| 3959 |
): |
| 3960 |
RGB_inc[inc] = R_inc[inc] |
| 3961 |
for inc in G_inc: |
| 3962 |
if self.worker.thread_abort: |
| 3963 |
return False |
| 3964 |
if ( |
| 3965 |
inc in R_inc |
| 3966 |
and inc in B_inc |
| 3967 |
and R_inc[inc] == G_inc[inc] == B_inc[inc] |
| 3968 |
): |
| 3969 |
RGB_inc[inc] = G_inc[inc] |
| 3970 |
for inc in B_inc: |
| 3971 |
if self.worker.thread_abort: |
| 3972 |
return False |
| 3973 |
if ( |
| 3974 |
inc in R_inc |
| 3975 |
and inc in G_inc |
| 3976 |
and R_inc[inc] == G_inc[inc] == B_inc[inc] |
| 3977 |
): |
| 3978 |
RGB_inc[inc] = B_inc[inc] |
| 3979 |
if False: |
| 3980 |
RGB_inc_max = max(RGB_inc.values()) |
| 3981 |
if RGB_inc_max > 0: |
| 3982 |
single_channel_patches = RGB_inc_max + 1 |
| 3983 |
else: |
| 3984 |
single_channel_patches = 0 |
| 3985 |
else: |
| 3986 |
single_inc = {"0": 0} |
| 3987 |
for inc in RGB_inc: |
| 3988 |
if self.worker.thread_abort: |
| 3989 |
return False |
| 3990 |
if inc == "0": |
| 3991 |
continue |
| 3992 |
finc = float(inc) |
| 3993 |
n = round(float(str(255.0 / finc))) |
| 3994 |
finc = 255.0 / n |
| 3995 |
n += 1 |
| 3996 |
if DEBUG >= 9: |
| 3997 |
print("[D] inc:", inc) |
| 3998 |
print("[D] n:", n) |
| 3999 |
for i in range(n): |
| 4000 |
if self.worker.thread_abort: |
| 4001 |
return False |
| 4002 |
v = str(round(float(str(i * finc)))) |
| 4003 |
if DEBUG >= 9: |
| 4004 |
print("[D] Searching for", v) |
| 4005 |
if ( |
| 4006 |
[v, "0", "0"] in uniqueRGB |
| 4007 |
and ["0", v, "0"] in uniqueRGB |
| 4008 |
and ["0", "0", v] in uniqueRGB |
| 4009 |
): |
| 4010 |
if inc not in single_inc: |
| 4011 |
single_inc[inc] = 0 |
| 4012 |
single_inc[inc] += 1 |
| 4013 |
else: |
| 4014 |
if DEBUG >= 9: |
| 4015 |
print("[D] Not found!") |
| 4016 |
break |
| 4017 |
single_channel_patches = max(single_inc.values()) |
| 4018 |
if DEBUG: |
| 4019 |
print("[D] single_channel_patches:", single_channel_patches) |
| 4020 |
if 0 in R + G + B: |
| 4021 |
fullspread_patches += 3 # black in single channel patches |
| 4022 |
elif single_channel_patches >= 2: |
| 4023 |
fullspread_patches += 3 # black always in SINGLE_DIM_STEPS |
| 4024 |
|
| 4025 |
if gray_patches is None: |
| 4026 |
# NEVER (old code, needs work for demphasis/gamma, remove?) |
| 4027 |
RGB_inc = self.tc_get_increments(gray_channel, vmaxlen) |
| 4028 |
if DEBUG: |
| 4029 |
print("[D] RGB_inc:") |
| 4030 |
for i in RGB_inc: |
| 4031 |
if self.worker.thread_abort: |
| 4032 |
return False |
| 4033 |
print(f"[D] {i}: x{RGB_inc[i]}") |
| 4034 |
if False: |
| 4035 |
RGB_inc_max = max(RGB_inc.values()) |
| 4036 |
gray_patches = RGB_inc_max + 1 if RGB_inc_max > 0 else 0 |
| 4037 |
else: |
| 4038 |
gray_inc = {"0": 0} |
| 4039 |
for inc in RGB_inc: |
| 4040 |
if self.worker.thread_abort: |
| 4041 |
return False |
| 4042 |
if inc == "0": |
| 4043 |
continue |
| 4044 |
finc = float(inc) |
| 4045 |
n = round(float(str(255.0 / finc))) |
| 4046 |
finc = 255.0 / n |
| 4047 |
n += 1 |
| 4048 |
if DEBUG >= 9: |
| 4049 |
print("[D] inc:", inc) |
| 4050 |
print("[D] n:", n) |
| 4051 |
for i in range(n): |
| 4052 |
if self.worker.thread_abort: |
| 4053 |
return False |
| 4054 |
v = str(round(float(str(i * finc)))) |
| 4055 |
if DEBUG >= 9: |
| 4056 |
print("[D] Searching for", v) |
| 4057 |
if [v, v, v] in uniqueRGB: |
| 4058 |
if inc not in gray_inc: |
| 4059 |
gray_inc[inc] = 0 |
| 4060 |
gray_inc[inc] += 1 |
| 4061 |
else: |
| 4062 |
if DEBUG >= 9: |
| 4063 |
print("[D] Not found!") |
| 4064 |
break |
| 4065 |
gray_patches = max(gray_inc.values()) |
| 4066 |
if DEBUG: |
| 4067 |
print("[D] gray_patches:", gray_patches) |
| 4068 |
if 0 in gray_channel: |
| 4069 |
fullspread_patches += 1 # black in gray patches |
| 4070 |
if 255 in gray_channel: |
| 4071 |
fullspread_patches += 1 # white in gray patches |
| 4072 |
elif gray_patches >= 2: |
| 4073 |
fullspread_patches += 2 # black and white always in COMP_GREY_STEPS |
| 4074 |
|
| 4075 |
if multi_steps is None: |
| 4076 |
# NEVER (old code, needs work for demphasis/gamma, remove?) |
| 4077 |
R_inc = self.tc_get_increments(multi["R"], vmaxlen) |
| 4078 |
G_inc = self.tc_get_increments(multi["G"], vmaxlen) |
| 4079 |
B_inc = self.tc_get_increments(multi["B"], vmaxlen) |
| 4080 |
RGB_inc = {"0": 0} |
| 4081 |
for inc in R_inc: |
| 4082 |
if self.worker.thread_abort: |
| 4083 |
return False |
| 4084 |
if ( |
| 4085 |
inc in G_inc |
| 4086 |
and inc in B_inc |
| 4087 |
and R_inc[inc] == G_inc[inc] == B_inc[inc] |
| 4088 |
): |
| 4089 |
RGB_inc[inc] = R_inc[inc] |
| 4090 |
for inc in G_inc: |
| 4091 |
if self.worker.thread_abort: |
| 4092 |
return False |
| 4093 |
if ( |
| 4094 |
inc in R_inc |
| 4095 |
and inc in B_inc |
| 4096 |
and R_inc[inc] == G_inc[inc] == B_inc[inc] |
| 4097 |
): |
| 4098 |
RGB_inc[inc] = G_inc[inc] |
| 4099 |
for inc in B_inc: |
| 4100 |
if self.worker.thread_abort: |
| 4101 |
return False |
| 4102 |
if ( |
| 4103 |
inc in R_inc |
| 4104 |
and inc in G_inc |
| 4105 |
and R_inc[inc] == G_inc[inc] == B_inc[inc] |
| 4106 |
): |
| 4107 |
RGB_inc[inc] = B_inc[inc] |
| 4108 |
if DEBUG: |
| 4109 |
print("[D] RGB_inc:") |
| 4110 |
for i in RGB_inc: |
| 4111 |
if self.worker.thread_abort: |
| 4112 |
return False |
| 4113 |
print(f"[D] {i}: x{RGB_inc[i]}") |
| 4114 |
multi_inc = {"0": 0} |
| 4115 |
for inc in RGB_inc: |
| 4116 |
if self.worker.thread_abort: |
| 4117 |
return False |
| 4118 |
if inc == "0": |
| 4119 |
continue |
| 4120 |
finc = float(inc) |
| 4121 |
n = round(float(str(255.0 / finc))) |
| 4122 |
finc = 255.0 / n |
| 4123 |
n += 1 |
| 4124 |
if DEBUG >= 9: |
| 4125 |
print("[D] inc:", inc) |
| 4126 |
print("[D] n:", n) |
| 4127 |
for i in range(n): |
| 4128 |
if self.worker.thread_abort: |
| 4129 |
return False |
| 4130 |
r = str(round(float(str(i * finc)))) |
| 4131 |
for j in range(n): |
| 4132 |
if self.worker.thread_abort: |
| 4133 |
return False |
| 4134 |
g = str(round(float(str(j * finc)))) |
| 4135 |
for k in range(n): |
| 4136 |
if self.worker.thread_abort: |
| 4137 |
return False |
| 4138 |
b = str(round(float(str(k * finc)))) |
| 4139 |
if DEBUG >= 9: |
| 4140 |
print("[D] Searching for", i, j, k, [r, g, b]) |
| 4141 |
if [r, g, b] in uniqueRGB: |
| 4142 |
if inc not in multi_inc: |
| 4143 |
multi_inc[inc] = 0 |
| 4144 |
multi_inc[inc] += 1 |
| 4145 |
else: |
| 4146 |
if DEBUG >= 9: |
| 4147 |
print("[D] Not found! (b loop)") |
| 4148 |
break |
| 4149 |
if [r, g, b] not in uniqueRGB: |
| 4150 |
if DEBUG >= 9: |
| 4151 |
print("[D] Not found! (g loop)") |
| 4152 |
break |
| 4153 |
if [r, g, b] not in uniqueRGB: |
| 4154 |
if DEBUG >= 9: |
| 4155 |
print("[D] Not found! (r loop)") |
| 4156 |
break |
| 4157 |
multi_patches = max(multi_inc.values()) |
| 4158 |
multi_steps = int(float(str(math.pow(multi_patches, 1 / 3.0)))) |
| 4159 |
if DEBUG: |
| 4160 |
print("[D] multi_patches:", multi_patches) |
| 4161 |
print("[D] multi_steps:", multi_steps) |
| 4162 |
elif multi_steps >= 2: |
| 4163 |
fullspread_patches += 2 # black and white always in MULTI_DIM_STEPS |
| 4164 |
else: |
| 4165 |
white_patches = len( |
| 4166 |
self.ti1[0].queryi({"RGB_R": 100, "RGB_G": 100, "RGB_B": 100}) |
| 4167 |
) |
| 4168 |
black_patches = len( |
| 4169 |
self.ti1[0].queryi({"RGB_R": 0, "RGB_G": 0, "RGB_B": 0}) |
| 4170 |
) |
| 4171 |
if single_channel_patches >= 2: |
| 4172 |
fullspread_patches += 3 # black always in SINGLE_DIM_STEPS |
| 4173 |
if gray_patches >= 2: |
| 4174 |
fullspread_patches += 2 # black and white always in COMP_GREY_STEPS |
| 4175 |
if multi_steps >= 2: |
| 4176 |
fullspread_patches += 2 # black and white always in MULTI_DIM_STEPS |
| 4177 |
fullspread_patches -= white_patches |
| 4178 |
if self.worker.argyll_version >= [1, 6]: |
| 4179 |
fullspread_patches -= black_patches |
| 4180 |
fullspread_patches -= single_channel_patches * 3 |
| 4181 |
fullspread_patches -= gray_patches |
| 4182 |
fullspread_patches -= ( |
| 4183 |
int(float(str(math.pow(multi_steps, 3)))) - single_channel_patches * 3 |
| 4184 |
) |
| 4185 |
|
| 4186 |
return ( |
| 4187 |
white_patches, |
| 4188 |
black_patches, |
| 4189 |
single_channel_patches, |
| 4190 |
gray_patches, |
| 4191 |
multi_steps, |
| 4192 |
multi_bcc_steps, |
| 4193 |
fullspread_patches, |
| 4194 |
gamma, |
| 4195 |
dark_emphasis, |
| 4196 |
) |
| 4197 |
|
| 4198 |
def tc_load_cfg_from_ti1_finish(self, result): |
| 4199 |
"""Finish loading testchart configuration from ti1 file. |
| 4200 |
|
| 4201 |
Args: |
| 4202 |
result (tuple or Exception): The result of the worker thread. |
| 4203 |
""" |
| 4204 |
self.worker.wrapup(False) |
| 4205 |
if isinstance(result, tuple): |
| 4206 |
# UGLY HACK: This 'print' call fixes a GTK assertion and |
| 4207 |
# segfault under Arch Linux when setting the window title |
| 4208 |
print("") |
| 4209 |
self.SetTitle( |
| 4210 |
lang.getstr("testchart.edit").rstrip(".") |
| 4211 |
+ ": " |
| 4212 |
+ os.path.basename(self.ti1.filename) |
| 4213 |
) |
| 4214 |
|
| 4215 |
print(lang.getstr("success")) |
| 4216 |
( |
| 4217 |
white_patches, |
| 4218 |
black_patches, |
| 4219 |
single_channel_patches, |
| 4220 |
gray_patches, |
| 4221 |
multi_steps, |
| 4222 |
multi_bcc_steps, |
| 4223 |
fullspread_patches, |
| 4224 |
gamma, |
| 4225 |
dark_emphasis, |
| 4226 |
) = result |
| 4227 |
|
| 4228 |
fullspread_ba = { |
| 4229 |
"ERROR_OPTIMISED_PATCHES": "", # OFPS in older Argyll CMS versions |
| 4230 |
# "ERROR_OPTIMISED_PATCHES": "R", # Perc. space random |
| 4231 |
# - same keyword as OFPS in older |
| 4232 |
# Argyll CMS versions, don't use. |
| 4233 |
"IFP_PATCHES": "t", # Inc. far point |
| 4234 |
"INC_FAR_PATCHES": "t", # Inc. far point in older Argyll CMS versions |
| 4235 |
"OFPS_PATCHES": "", # OFPS |
| 4236 |
"RANDOM_DEVICE_PATCHES": "r", # Dev. space random |
| 4237 |
"RANDOM_PATCHES": "r", # Dev. space random in older Argyll CMS versions |
| 4238 |
"RANDOM_PERCEPTUAL_PATCHES": "R", # Perc. space random |
| 4239 |
# "RANDOM_PERCEPTUAL_PATCHES": "Q", # Perc. space filling quasi-random |
| 4240 |
# - same keyword as perc. |
| 4241 |
# space random, don't use |
| 4242 |
"SIMPLEX_DEVICE_PATCHES": "i", # Dev. space body centered cubic grid |
| 4243 |
"SIMPLEX_PERCEPTUAL_PATCHES": "I", # Perc. space body centered cubic |
| 4244 |
# grid |
| 4245 |
"SPACEFILING_RANDOM_PATCHES": "q", # Device space filling quasi-random, |
| 4246 |
# typo in older Argyll CMS versions |
| 4247 |
"SPACEFILLING_RANDOM_PATCHES": "q", # Device space filling quasi-random |
| 4248 |
} |
| 4249 |
|
| 4250 |
algo = None |
| 4251 |
|
| 4252 |
for key in list(fullspread_ba.keys()): |
| 4253 |
queryv_ = self.ti1.queryv1(key) |
| 4254 |
if queryv_ is not None and queryv_ > 0: |
| 4255 |
algo = fullspread_ba[key] |
| 4256 |
break |
| 4257 |
|
| 4258 |
if white_patches is not None: |
| 4259 |
setcfg("tc_white_patches", white_patches) |
| 4260 |
if black_patches is not None: |
| 4261 |
setcfg("tc_black_patches", black_patches) |
| 4262 |
if single_channel_patches is not None: |
| 4263 |
setcfg("tc_single_channel_patches", single_channel_patches) |
| 4264 |
if gray_patches is not None: |
| 4265 |
setcfg("tc_gray_patches", gray_patches) |
| 4266 |
if multi_steps is not None: |
| 4267 |
setcfg("tc_multi_steps", multi_steps) |
| 4268 |
if multi_bcc_steps is not None: |
| 4269 |
setcfg("tc_multi_bcc_steps", multi_bcc_steps) |
| 4270 |
setcfg( |
| 4271 |
"tc_fullspread_patches", |
| 4272 |
self.ti1.queryv1("NUMBER_OF_SETS") |
| 4273 |
- self.tc_get_total_patches( |
| 4274 |
white_patches, |
| 4275 |
black_patches, |
| 4276 |
single_channel_patches, |
| 4277 |
gray_patches, |
| 4278 |
multi_steps, |
| 4279 |
multi_bcc_steps, |
| 4280 |
0, |
| 4281 |
), |
| 4282 |
) |
| 4283 |
if gamma is not None: |
| 4284 |
setcfg("tc_gamma", gamma) |
| 4285 |
if dark_emphasis is not None: |
| 4286 |
setcfg("tc_dark_emphasis", dark_emphasis) |
| 4287 |
if algo is not None: |
| 4288 |
setcfg("tc_algo", algo) |
| 4289 |
self.writecfg() |
| 4290 |
|
| 4291 |
self.tc_update_controls() |
| 4292 |
self.tc_preview(True) |
| 4293 |
return True |
| 4294 |
print(lang.getstr("aborted")) |
| 4295 |
if self.Parent and hasattr(self.Parent, "start_timers"): |
| 4296 |
self.Parent.start_timers() |
| 4297 |
if isinstance(result, Exception): |
| 4298 |
show_result_dialog(result, self) |
| 4299 |
return False |
| 4300 |
|
| 4301 |
def tc_get_increments(self, channel, vmaxlen=4): |
| 4302 |
"""Get the increments of a channel. |
| 4303 |
|
| 4304 |
Args: |
| 4305 |
channel (list): The channel. |
| 4306 |
vmaxlen (int): The maximum length of the increment string. |
| 4307 |
|
| 4308 |
Returns: |
| 4309 |
dict: A dictionary with increments as keys and their counts as |
| 4310 |
values. |
| 4311 |
""" |
| 4312 |
channel.sort() |
| 4313 |
increments = {"0": 0} |
| 4314 |
for i, v in enumerate(channel): |
| 4315 |
for j in reversed(range(i, len(channel))): |
| 4316 |
inc = round(float(str(channel[j] - v)), vmaxlen) |
| 4317 |
if inc > 0: |
| 4318 |
inc = str(inc) |
| 4319 |
if inc not in increments: |
| 4320 |
increments[inc] = 0 |
| 4321 |
increments[inc] += 1 |
| 4322 |
return increments |
| 4323 |
|
| 4324 |
def tc_create(self, gray=False, multidim=False, single=False): |
| 4325 |
"""Create testchart using targen. |
| 4326 |
|
| 4327 |
Setting gray, multidim or single to True will ad those patches |
| 4328 |
in a separate step if any number of iterative patches are to be |
| 4329 |
generated as well. |
| 4330 |
|
| 4331 |
Args: |
| 4332 |
gray (bool): Whether to include gray patches. |
| 4333 |
multidim (bool): Whether to include multi-dimensional patches. |
| 4334 |
single (bool): Whether to include single-channel patches. |
| 4335 |
""" |
| 4336 |
self.writecfg() |
| 4337 |
fullspread_patches = getcfg("tc_fullspread_patches") |
| 4338 |
white_patches = getcfg("tc_white_patches") |
| 4339 |
black_patches = getcfg("tc_black_patches") |
| 4340 |
single_patches = getcfg("tc_single_channel_patches") |
| 4341 |
gray_patches = getcfg("tc_gray_patches") |
| 4342 |
multidim_patches = getcfg("tc_multi_steps") |
| 4343 |
multidim_bcc_patches = getcfg("tc_multi_bcc_steps") |
| 4344 |
extra_args = getcfg("extra_args.targen") |
| 4345 |
result = True |
| 4346 |
fixed_ti1 = None |
| 4347 |
if fullspread_patches > 0 and (gray or multidim or single): |
| 4348 |
# Generate fixed points first so they don't punch "holes" into the |
| 4349 |
# OFPS distribution |
| 4350 |
setcfg("tc_white_patches", 0) |
| 4351 |
setcfg("tc_black_patches", 0) |
| 4352 |
if not single: |
| 4353 |
setcfg("tc_single_channel_patches", 0) |
| 4354 |
if not gray: |
| 4355 |
setcfg("tc_gray_patches", 0) |
| 4356 |
if not multidim: |
| 4357 |
setcfg("tc_multi_steps", 0) |
| 4358 |
setcfg("tc_multi_bcc_steps", 0) |
| 4359 |
setcfg("tc_fullspread_patches", 0) |
| 4360 |
setcfg("extra_args.targen", "") |
| 4361 |
result = self.tc_create_ti1() |
| 4362 |
if fullspread_patches > 0 and (gray or multidim or single): |
| 4363 |
setcfg("tc_white_patches", white_patches) |
| 4364 |
setcfg("tc_black_patches", black_patches) |
| 4365 |
if single: |
| 4366 |
setcfg("tc_single_channel_patches", 2) |
| 4367 |
else: |
| 4368 |
setcfg("tc_single_channel_patches", single_patches) |
| 4369 |
if gray: |
| 4370 |
setcfg("tc_gray_patches", 2) |
| 4371 |
else: |
| 4372 |
setcfg("tc_gray_patches", gray_patches) |
| 4373 |
if multidim: |
| 4374 |
setcfg("tc_multi_steps", 2) |
| 4375 |
setcfg("tc_multi_bcc_steps", 0) |
| 4376 |
else: |
| 4377 |
setcfg("tc_multi_steps", multidim_patches) |
| 4378 |
setcfg("tc_multi_bcc_steps", multidim_bcc_patches) |
| 4379 |
setcfg("tc_fullspread_patches", fullspread_patches) |
| 4380 |
setcfg("extra_args.targen", extra_args) |
| 4381 |
fixed_ti1 = result |
| 4382 |
if not isinstance(result, Exception) and result: |
| 4383 |
result = self.tc_create_ti1() |
| 4384 |
if isinstance(result, CGATS): |
| 4385 |
if fixed_ti1: |
| 4386 |
if gray: |
| 4387 |
result[0].add_keyword("COMP_GREY_STEPS", gray_patches) |
| 4388 |
if multidim: |
| 4389 |
result[0].add_keyword("MULTI_DIM_STEPS", multidim_patches) |
| 4390 |
if multidim_bcc_patches: |
| 4391 |
result[0].add_keyword( |
| 4392 |
"MULTI_DIM_BCC_STEPS", multidim_bcc_patches |
| 4393 |
) |
| 4394 |
if single: |
| 4395 |
result[0].add_keyword("SINGLE_DIM_STEPS", single_patches) |
| 4396 |
fixed_data = fixed_ti1.queryv1("DATA") |
| 4397 |
data = result.queryv1("DATA") |
| 4398 |
data_format = result.queryv1("DATA_FORMAT") |
| 4399 |
# Get only RGB data |
| 4400 |
data.parent.DATA_FORMAT = CGATS() |
| 4401 |
data.parent.DATA_FORMAT.key = "DATA_FORMAT" |
| 4402 |
data.parent.DATA_FORMAT.parent = data |
| 4403 |
data.parent.DATA_FORMAT.root = data.root |
| 4404 |
data.parent.DATA_FORMAT.type = "DATA_FORMAT" |
| 4405 |
for i, label in enumerate(("RGB_R", "RGB_G", "RGB_B")): |
| 4406 |
data.parent.DATA_FORMAT[i] = label |
| 4407 |
fixed_data.parent.DATA_FORMAT = data.parent.DATA_FORMAT |
| 4408 |
rgbdata = str(data) |
| 4409 |
# Restore DATA_FORMAT |
| 4410 |
data.parent.DATA_FORMAT = data_format |
| 4411 |
# Collect all fixed point datasets not in data |
| 4412 |
fixed_data.vmaxlen = data.vmaxlen |
| 4413 |
fixed_datasets = [] |
| 4414 |
for i in fixed_data: |
| 4415 |
dataset = fixed_data[i] |
| 4416 |
if str(dataset) not in rgbdata: |
| 4417 |
fixed_datasets.append(dataset) |
| 4418 |
if fixed_datasets: |
| 4419 |
# Insert fixed point datasets after first patch |
| 4420 |
data.moveby1(1, len(fixed_datasets)) |
| 4421 |
for i, dataset in enumerate(fixed_datasets): |
| 4422 |
dataset.key = i + 1 |
| 4423 |
dataset.parent = data |
| 4424 |
dataset.root = data.root |
| 4425 |
data[dataset.key] = dataset |
| 4426 |
self.ti1 = result |
| 4427 |
setcfg("tc_single_channel_patches", single_patches) |
| 4428 |
setcfg("tc_gray_patches", gray_patches) |
| 4429 |
setcfg("tc_multi_steps", multidim_patches) |
| 4430 |
setcfg("tc_multi_bcc_steps", multidim_bcc_patches) |
| 4431 |
return result |
| 4432 |
|
| 4433 |
def tc_create_ti1(self): |
| 4434 |
"""Create a testchart using targen. |
| 4435 |
|
| 4436 |
Returns: |
| 4437 |
CGATS or Exception: The created testchart or an error. |
| 4438 |
""" |
| 4439 |
cmd, args = self.worker.prepare_targen() |
| 4440 |
if not isinstance(cmd, Exception): |
| 4441 |
result = self.worker.exec_cmd( |
| 4442 |
cmd, |
| 4443 |
args, |
| 4444 |
low_contrast=False, |
| 4445 |
skip_scripts=True, |
| 4446 |
silent=False, |
| 4447 |
parent=self, |
| 4448 |
) |
| 4449 |
else: |
| 4450 |
result = cmd |
| 4451 |
if ( |
| 4452 |
not isinstance(result, Exception) |
| 4453 |
and result |
| 4454 |
and not isinstance(result, Exception) |
| 4455 |
): |
| 4456 |
path = os.path.join(self.worker.tempdir, "temp.ti1") |
| 4457 |
result = check_file_isfile(path, silent=False) |
| 4458 |
if not isinstance(result, Exception) and result: |
| 4459 |
try: |
| 4460 |
result = CGATS(path) |
| 4461 |
print(lang.getstr("success")) |
| 4462 |
except Exception as exception: |
| 4463 |
result = Error( |
| 4464 |
f"Error - testchart file could not be read: {exception!s} " |
| 4465 |
) |
| 4466 |
else: |
| 4467 |
result.filename = None |
| 4468 |
self.worker.wrapup(False) |
| 4469 |
return result |
| 4470 |
|
| 4471 |
def tc_preview(self, result, path=None): |
| 4472 |
"""Create a preview of the testchart. |
| 4473 |
|
| 4474 |
Args: |
| 4475 |
result (CGATS or Exception): The result of the testchart creation. |
| 4476 |
path (str, optional): The path to save the testchart. Defaults to None. |
| 4477 |
""" |
| 4478 |
self.tc_check() |
| 4479 |
if isinstance(result, Exception): |
| 4480 |
show_result_dialog(result, self) |
| 4481 |
elif result: |
| 4482 |
if not hasattr(self, "separator"): |
| 4483 |
# We add this here because of a wxGTK 2.8 quirk where the |
| 4484 |
# vertical scrollbar otherwise has a 1px horizontal |
| 4485 |
# line at the top otherwise. |
| 4486 |
separator_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DSHADOW) |
| 4487 |
self.separator = wx.Panel(self.panel, size=(-1, 1)) |
| 4488 |
self.separator.BackgroundColour = separator_color |
| 4489 |
index = len(self.sizer.Children) - 1 |
| 4490 |
if sys.platform not in ("darwin", "win32") or TC_USE_ALTERNATE_PREVIEW: |
| 4491 |
index -= 1 |
| 4492 |
self.sizer.Insert(index, self.separator, flag=wx.EXPAND) |
| 4493 |
else: |
| 4494 |
self.separator.Show() |
| 4495 |
self.sizer.Layout() |
| 4496 |
if VERBOSE >= 1: |
| 4497 |
print(lang.getstr("tc.preview.create")) |
| 4498 |
data = self.ti1.queryv1("DATA") |
| 4499 |
vmaxlen = 6 |
| 4500 |
|
| 4501 |
if hasattr(self, "preview"): |
| 4502 |
self.preview.BeginBatch() |
| 4503 |
w = self.grid.GetDefaultRowSize() |
| 4504 |
numcols = ( |
| 4505 |
self.sizer.Size[0] - wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X) |
| 4506 |
) / w |
| 4507 |
self.preview.AppendCols(numcols) |
| 4508 |
for i in range(numcols): |
| 4509 |
self.preview.SetColLabelValue(i, str(i + 1)) |
| 4510 |
|
| 4511 |
grid = self.grid |
| 4512 |
grid.BeginBatch() |
| 4513 |
data_format = self.ti1.queryv1("DATA_FORMAT") |
| 4514 |
for i in data_format: |
| 4515 |
data_format_str_value = data_format[i].decode("utf-8") |
| 4516 |
if data_format_str_value in ("RGB_R", "RGB_G", "RGB_B"): |
| 4517 |
grid.AppendCols(1) |
| 4518 |
grid.SetColLabelValue( |
| 4519 |
grid.GetNumberCols() - 1, |
| 4520 |
data_format_str_value.split("_")[-1] + " %", |
| 4521 |
) |
| 4522 |
grid.AppendCols(1) |
| 4523 |
grid.SetColLabelValue(grid.GetNumberCols() - 1, "") |
| 4524 |
grid.SetColSize(grid.GetNumberCols() - 1, self.grid.GetDefaultRowSize()) |
| 4525 |
self.tc_amount = self.ti1.queryv1("NUMBER_OF_SETS") |
| 4526 |
grid.AppendRows(self.tc_amount) |
| 4527 |
dc = wx.MemoryDC(wx.EmptyBitmap(1, 1)) |
| 4528 |
dc.SetFont(grid.GetLabelFont()) |
| 4529 |
w, h = dc.GetTextExtent("99{}".format(self.ti1.queryv1("NUMBER_OF_SETS"))) |
| 4530 |
grid.SetRowLabelSize(max(w, grid.GetDefaultRowSize())) |
| 4531 |
attr = wx.grid.GridCellAttr() |
| 4532 |
attr.SetAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER) |
| 4533 |
attr.SetReadOnly() |
| 4534 |
grid.SetColAttr(grid.GetNumberCols() - 1, attr) |
| 4535 |
|
| 4536 |
for i in data: |
| 4537 |
sample = data[i] |
| 4538 |
for j in range(grid.GetNumberCols()): |
| 4539 |
label = self.label_b2a.get(grid.GetColLabelValue(j)) |
| 4540 |
if label in ("RGB_R", "RGB_G", "RGB_B"): |
| 4541 |
grid.SetCellValue( |
| 4542 |
i, |
| 4543 |
j, |
| 4544 |
rpad( |
| 4545 |
sample[label], vmaxlen + (1 if sample[label] < 0 else 0) |
| 4546 |
), |
| 4547 |
) |
| 4548 |
self.tc_grid_setcolorlabel(i, data) |
| 4549 |
self.tc_preview_update(0) |
| 4550 |
|
| 4551 |
if hasattr(self, "preview"): |
| 4552 |
w, h = dc.GetTextExtent(f"99{self.preview.GetNumberRows()}") |
| 4553 |
self.preview.SetRowLabelSize(max(w, grid.GetDefaultRowSize())) |
| 4554 |
self.preview.EndBatch() |
| 4555 |
|
| 4556 |
self.tc_set_default_status() |
| 4557 |
if VERBOSE >= 1: |
| 4558 |
print(lang.getstr("success")) |
| 4559 |
self.resize_grid() |
| 4560 |
grid.EndBatch() |
| 4561 |
if path: |
| 4562 |
wx.CallAfter(self.tc_save_as_handler, path=path) |
| 4563 |
if self.Parent and hasattr(self.Parent, "start_timers"): |
| 4564 |
self.Parent.start_timers() |
| 4565 |
|
| 4566 |
def tc_add_data(self, row, newdata): |
| 4567 |
"""Add new data to the grid and update the preview. |
| 4568 |
|
| 4569 |
Args: |
| 4570 |
row (int): The row number where new data should be inserted. |
| 4571 |
newdata (list): A list of dictionaries containing the new data. |
| 4572 |
""" |
| 4573 |
self.grid.BeginBatch() |
| 4574 |
self.grid.InsertRows(row + 1, len(newdata)) |
| 4575 |
data = self.ti1.queryv1("DATA") |
| 4576 |
if hasattr(self, "preview"): |
| 4577 |
self.preview.BeginBatch() |
| 4578 |
data_format = self.ti1.queryv1("DATA_FORMAT") |
| 4579 |
data.moveby1(row + 1, len(newdata)) |
| 4580 |
for i in range(len(newdata)): |
| 4581 |
dataset = CGATS() |
| 4582 |
for label in data_format.values(): |
| 4583 |
label = label.decode("utf-8") |
| 4584 |
if label not in newdata[i]: |
| 4585 |
newdata[i][label] = 0.0 |
| 4586 |
dataset[label] = newdata[i][label] |
| 4587 |
dataset.key = row + 1 + i |
| 4588 |
dataset.parent = data |
| 4589 |
dataset.root = data.root |
| 4590 |
dataset.type = b"SAMPLE" |
| 4591 |
data[dataset.key] = dataset |
| 4592 |
for label in ("RGB_R", "RGB_G", "RGB_B"): |
| 4593 |
for col in range(self.grid.GetNumberCols()): |
| 4594 |
if self.label_b2a.get(self.grid.GetColLabelValue(col)) == label: |
| 4595 |
sample = newdata[i] |
| 4596 |
self.grid.SetCellValue( |
| 4597 |
row + 1 + i, |
| 4598 |
col, |
| 4599 |
rpad( |
| 4600 |
sample[label], |
| 4601 |
data.vmaxlen + (1 if sample[label] < 0 else 0), |
| 4602 |
), |
| 4603 |
) |
| 4604 |
self.tc_grid_setcolorlabel(row + 1 + i, data) |
| 4605 |
self.tc_preview_update(row + 1) |
| 4606 |
self.tc_amount = self.ti1.queryv1("NUMBER_OF_SETS") |
| 4607 |
dc = wx.MemoryDC(wx.EmptyBitmap(1, 1)) |
| 4608 |
dc.SetFont(self.grid.GetLabelFont()) |
| 4609 |
w, h = dc.GetTextExtent(f"99{self.tc_amount}") |
| 4610 |
self.grid.SetRowLabelSize(max(w, self.grid.GetDefaultRowSize())) |
| 4611 |
self.resize_grid() |
| 4612 |
self.grid.EndBatch() |
| 4613 |
self.tc_set_default_status() |
| 4614 |
self.tc_save_check() |
| 4615 |
if hasattr(self, "preview"): |
| 4616 |
self.preview.EndBatch() |
| 4617 |
|
| 4618 |
def tc_grid_setcolorlabel(self, row, data=None): |
| 4619 |
"""Set the color label and background for a grid cell. |
| 4620 |
|
| 4621 |
Args: |
| 4622 |
row (int): The row number of the grid to update. |
| 4623 |
data (CGATS, optional): The CGATS data object containing sample data. |
| 4624 |
""" |
| 4625 |
grid = self.grid |
| 4626 |
col = grid.GetNumberCols() - 1 |
| 4627 |
if data is None: |
| 4628 |
data = self.ti1.queryv1("DATA") |
| 4629 |
sample = data[row] |
| 4630 |
style, colour, labeltext, labelcolour = self.tc_getcolorlabel(sample) |
| 4631 |
grid.SetCellBackgroundColour(row, col, colour) |
| 4632 |
grid.SetCellValue(row, col, labeltext) |
| 4633 |
if labelcolour: |
| 4634 |
grid.SetCellTextColour(row, col, labelcolour) |
| 4635 |
self.grid.Refresh() |
| 4636 |
if hasattr(self, "preview"): |
| 4637 |
style, colour, labeltext, labelcolour = self.tc_getcolorlabel(sample) |
| 4638 |
numcols = self.preview.GetNumberCols() |
| 4639 |
row = sample.key / numcols |
| 4640 |
col = sample.key % numcols |
| 4641 |
if row > self.preview.GetNumberRows() - 1: |
| 4642 |
self.preview.AppendRows(1) |
| 4643 |
self.preview.SetCellBackgroundColour(row, col, colour) |
| 4644 |
self.preview.SetCellValue(row, col, labeltext) |
| 4645 |
if labelcolour: |
| 4646 |
self.preview.SetCellTextColour(row, col, labelcolour) |
| 4647 |
self.preview.Refresh() |
| 4648 |
|
| 4649 |
def tc_getcolorlabel(self, sample): |
| 4650 |
"""Get the style, colour, label text and label colour for a sample. |
| 4651 |
|
| 4652 |
Args: |
| 4653 |
sample (CGATS): The sample data containing RGB values. |
| 4654 |
""" |
| 4655 |
colour = wx.Colour( |
| 4656 |
*[ |
| 4657 |
round(value / 100.0 * 255) |
| 4658 |
for value in (sample.RGB_R, sample.RGB_G, sample.RGB_B) |
| 4659 |
] |
| 4660 |
) |
| 4661 |
# mark patches: |
| 4662 |
# W = white (R/G/B == 100) |
| 4663 |
# K = black (R/G/B == 0) |
| 4664 |
# k = light black (R == G == B > 0) |
| 4665 |
# R = red |
| 4666 |
# r = light red (R == 100 and G/B > 0) |
| 4667 |
# G = green |
| 4668 |
# g = light green (G == 100 and R/B > 0) |
| 4669 |
# B = blue |
| 4670 |
# b = light blue (B == 100 and R/G > 0) |
| 4671 |
# C = cyan |
| 4672 |
# c = light cyan (G/B == 100 and R > 0) |
| 4673 |
# M = magenta |
| 4674 |
# m = light magenta (R/B == 100 and G > 0) |
| 4675 |
# Y = yellow |
| 4676 |
# y = light yellow (R/G == 100 and B > 0) |
| 4677 |
# border = 50% value |
| 4678 |
style = wx.NO_BORDER |
| 4679 |
if sample.RGB_R == sample.RGB_G == sample.RGB_B: # Neutral / black / white |
| 4680 |
if sample.RGB_R < 50: |
| 4681 |
labelcolour = wx.Colour(255, 255, 255) |
| 4682 |
else: |
| 4683 |
if sample.RGB_R == 50: |
| 4684 |
style = wx.SIMPLE_BORDER |
| 4685 |
labelcolour = wx.Colour(0, 0, 0) |
| 4686 |
if sample.RGB_R <= 50: |
| 4687 |
labeltext = "K" |
| 4688 |
elif sample.RGB_R == 100: |
| 4689 |
labeltext = "W" |
| 4690 |
else: |
| 4691 |
labeltext = "k" |
| 4692 |
elif (sample.RGB_G == 0 and sample.RGB_B == 0) or ( |
| 4693 |
sample.RGB_R == 100 and sample.RGB_G == sample.RGB_B |
| 4694 |
): # Red |
| 4695 |
if sample.RGB_R > 75: |
| 4696 |
labelcolour = wx.Colour(0, 0, 0) |
| 4697 |
else: |
| 4698 |
labelcolour = wx.Colour(255, 255, 255) |
| 4699 |
if sample.RGB_R == 50: |
| 4700 |
style = wx.SIMPLE_BORDER |
| 4701 |
labeltext = "r" if sample.RGB_R == 100 and sample.RGB_G > 0 else "R" |
| 4702 |
elif (sample.RGB_R == 0 and sample.RGB_B == 0) or ( |
| 4703 |
sample.RGB_G == 100 and sample.RGB_R == sample.RGB_B |
| 4704 |
): # Green |
| 4705 |
if sample.RGB_G > 75: |
| 4706 |
labelcolour = wx.Colour(0, 0, 0) |
| 4707 |
else: |
| 4708 |
labelcolour = wx.Colour(255, 255, 255) |
| 4709 |
if sample.RGB_G == 50: |
| 4710 |
style = wx.SIMPLE_BORDER |
| 4711 |
labeltext = "g" if sample.RGB_G == 100 and sample.RGB_R > 0 else "G" |
| 4712 |
elif (sample.RGB_R == 0 and sample.RGB_G == 0) or ( |
| 4713 |
sample.RGB_B == 100 and sample.RGB_R == sample.RGB_G |
| 4714 |
): # Blue |
| 4715 |
if sample.RGB_R > 25: |
| 4716 |
labelcolour = wx.Colour(0, 0, 0) |
| 4717 |
else: |
| 4718 |
labelcolour = wx.Colour(255, 255, 255) |
| 4719 |
if sample.RGB_B == 50: |
| 4720 |
style = wx.SIMPLE_BORDER |
| 4721 |
labeltext = "b" if sample.RGB_B == 100 and sample.RGB_R > 0 else "B" |
| 4722 |
elif ( |
| 4723 |
sample.RGB_R == 0 or sample.RGB_B == 100 |
| 4724 |
) and sample.RGB_G == sample.RGB_B: # Cyan |
| 4725 |
if sample.RGB_G > 75: |
| 4726 |
labelcolour = wx.Colour(0, 0, 0) |
| 4727 |
else: |
| 4728 |
labelcolour = wx.Colour(255, 255, 255) |
| 4729 |
if sample.RGB_G == 50: |
| 4730 |
style = wx.SIMPLE_BORDER |
| 4731 |
labeltext = "c" if sample.RGB_G == 100 and sample.RGB_R > 0 else "C" |
| 4732 |
elif ( |
| 4733 |
sample.RGB_G == 0 or sample.RGB_R == 100 |
| 4734 |
) and sample.RGB_R == sample.RGB_B: # Magenta |
| 4735 |
if sample.RGB_R > 75: |
| 4736 |
labelcolour = wx.Colour(0, 0, 0) |
| 4737 |
else: |
| 4738 |
labelcolour = wx.Colour(255, 255, 255) |
| 4739 |
if sample.RGB_R == 50: |
| 4740 |
style = wx.SIMPLE_BORDER |
| 4741 |
labeltext = "m" if sample.RGB_R == 100 and sample.RGB_G > 0 else "M" |
| 4742 |
elif ( |
| 4743 |
sample.RGB_B == 0 or sample.RGB_G == 100 |
| 4744 |
) and sample.RGB_R == sample.RGB_G: # Yellow |
| 4745 |
if sample.RGB_G > 75: |
| 4746 |
labelcolour = wx.Colour(0, 0, 0) |
| 4747 |
else: |
| 4748 |
labelcolour = wx.Colour(255, 255, 255) |
| 4749 |
if sample.RGB_R == 100 and sample.RGB_G == 50: |
| 4750 |
style = wx.SIMPLE_BORDER |
| 4751 |
labeltext = "y" if sample.RGB_B > 0 else "Y" |
| 4752 |
else: |
| 4753 |
labeltext = "" |
| 4754 |
labelcolour = None |
| 4755 |
return style, colour, labeltext, labelcolour |
| 4756 |
|
| 4757 |
def tc_set_default_status(self, event=None): |
| 4758 |
"""Set the default status text for the testchart editor. |
| 4759 |
|
| 4760 |
Args: |
| 4761 |
event (wx.Event, optional): The event that triggered this method. |
| 4762 |
""" |
| 4763 |
if not hasattr(self, "tc_amount"): |
| 4764 |
return |
| 4765 |
|
| 4766 |
statustxt = "{}: {}".format(lang.getstr("tc.patches.total"), self.tc_amount) |
| 4767 |
sel = self.grid.GetSelectionRows() |
| 4768 |
if sel: |
| 4769 |
statustxt += " / {}: {}".format( |
| 4770 |
lang.getstr("tc.patches.selected"), |
| 4771 |
len(sel), |
| 4772 |
) |
| 4773 |
index = self.grid.GetGridCursorRow() |
| 4774 |
if index > -1: |
| 4775 |
colour = self.grid.GetCellBackgroundColour(index, 3) |
| 4776 |
patchinfo = " \u2014 {} {}: R={} G={} B={}".format( |
| 4777 |
lang.getstr("tc.patch"), |
| 4778 |
index + 1, |
| 4779 |
colour[0], |
| 4780 |
colour[1], |
| 4781 |
colour[2], |
| 4782 |
) |
| 4783 |
statustxt += patchinfo |
| 4784 |
self.SetStatusText(statustxt) |
| 4785 |
|
| 4786 |
def tc_mouseclick_handler(self, event): |
| 4787 |
"""Handle mouse click events on the testchart grid. |
| 4788 |
|
| 4789 |
This method selects the row in the grid based on the mouse click position. |
| 4790 |
|
| 4791 |
Args: |
| 4792 |
event (wx.MouseEvent): The mouse event containing the click position. |
| 4793 |
""" |
| 4794 |
if not getattr(self, "ti1", None): |
| 4795 |
return |
| 4796 |
index = event.Row * self.preview.GetNumberCols() + event.Col |
| 4797 |
if index > self.ti1.queryv1("NUMBER_OF_SETS") - 1: |
| 4798 |
return |
| 4799 |
self.grid.select_row( |
| 4800 |
index, event.ShiftDown(), event.ControlDown() or event.CmdDown() |
| 4801 |
) |
| 4802 |
return |
| 4803 |
|
| 4804 |
def tc_delete_rows(self, rows): |
| 4805 |
"""Delete rows from the testchart grid and update the data accordingly. |
| 4806 |
|
| 4807 |
Args: |
| 4808 |
rows (list): List of row indices to delete. |
| 4809 |
""" |
| 4810 |
self.grid.BeginBatch() |
| 4811 |
if hasattr(self, "preview"): |
| 4812 |
self.preview.BeginBatch() |
| 4813 |
rows.sort() |
| 4814 |
rows.reverse() |
| 4815 |
data = self.ti1.queryv1("DATA") |
| 4816 |
# Optimization: Delete consecutive rows in least number of operations |
| 4817 |
consecutive = [] |
| 4818 |
rows.append(-1) |
| 4819 |
for row in rows: |
| 4820 |
if row == -1 or (consecutive and consecutive[-1] != row + 1): |
| 4821 |
self.grid.DeleteRows(consecutive[-1], len(consecutive)) |
| 4822 |
if consecutive[0] != len(data) - 1: |
| 4823 |
data.moveby1(consecutive[-1] + len(consecutive), -len(consecutive)) |
| 4824 |
for _ in consecutive: |
| 4825 |
dict.pop(data, len(data) - 1) |
| 4826 |
consecutive = [] |
| 4827 |
consecutive.append(row) |
| 4828 |
rows.pop() |
| 4829 |
if hasattr(self, "preview"): |
| 4830 |
self.tc_preview_update(rows[-1]) |
| 4831 |
data.setmodified() |
| 4832 |
self.tc_amount = self.ti1.queryv1("NUMBER_OF_SETS") |
| 4833 |
row = min(rows[-1], self.grid.GetNumberRows() - 1) |
| 4834 |
self.grid.SelectRow(row) |
| 4835 |
self.grid.SetGridCursor(row, 0) |
| 4836 |
self.grid.MakeCellVisible(row, 0) |
| 4837 |
self.grid.EndBatch() |
| 4838 |
self.tc_save_check() |
| 4839 |
if hasattr(self, "preview"): |
| 4840 |
self.preview.EndBatch() |
| 4841 |
self.tc_set_default_status() |
| 4842 |
|
| 4843 |
def view_3d_format_popup(self, event): |
| 4844 |
"""Show a popup menu to select the 3D format for the testchart. |
| 4845 |
|
| 4846 |
Args: |
| 4847 |
event (wx.MouseEvent): The event triggered by the right-click. |
| 4848 |
""" |
| 4849 |
menu = wx.Menu() |
| 4850 |
|
| 4851 |
# item_selected = False |
| 4852 |
for file_format in config.VALID_VALUES["3d.format"]: |
| 4853 |
item = menu.AppendRadioItem(-1, file_format) |
| 4854 |
item.Check(file_format == getcfg("3d.format")) |
| 4855 |
self.Bind(wx.EVT_MENU, self.view_3d_format_handler, id=item.Id) |
| 4856 |
|
| 4857 |
self.PopupMenu(menu) |
| 4858 |
for item in menu.MenuItems: |
| 4859 |
self.Unbind(wx.EVT_MENU, id=item.Id) |
| 4860 |
menu.Destroy() |
| 4861 |
|
| 4862 |
def view_3d_format_handler(self, event): |
| 4863 |
"""Handle the selection of a 3D format from the popup menu. |
| 4864 |
|
| 4865 |
Args: |
| 4866 |
event (wx.CommandEvent): The event triggered by the menu selection. |
| 4867 |
""" |
| 4868 |
for item in event.EventObject.MenuItems: |
| 4869 |
if item.IsChecked(): |
| 4870 |
setcfg("3d.format", item.GetItemLabelText()) |
| 4871 |
|
| 4872 |
self.tc_view_3d(None) |
| 4873 |
|
| 4874 |
def writecfg(self): |
| 4875 |
"""Write configuration settings to the config file.""" |
| 4876 |
if self.Parent: |
| 4877 |
writecfg() |
| 4878 |
else: |
| 4879 |
writecfg( |
| 4880 |
module="testchart-editor", |
| 4881 |
options=( |
| 4882 |
"3d_format", |
| 4883 |
"last_ti1_path", |
| 4884 |
"last_testchart_export_path", |
| 4885 |
"last_vrml_path", |
| 4886 |
"position.tcgen", |
| 4887 |
"size.tcgen", |
| 4888 |
"tc.", |
| 4889 |
"tc_", |
| 4890 |
), |
| 4891 |
) |
| 4892 |
|
| 4893 |
|
| 4894 |
def main(): |
| 4895 |
"""Main function to run the wxPython application.""" |
| 4896 |
config.initcfg("testchart-editor") |
| 4897 |
lang.init() |
| 4898 |
lang.update_defaults() |
| 4899 |
app = BaseApp(0) |
| 4900 |
app.TopWindow = TestchartEditor(setup=False) |
| 4901 |
if sys.platform == "darwin": |
| 4902 |
app.TopWindow.init_menubar() |
| 4903 |
wx.CallLater(1, _main, app) |
| 4904 |
app.MainLoop() |
| 4905 |
|
| 4906 |
|
| 4907 |
def _main(app): |
| 4908 |
app.TopWindow.listen() |
| 4909 |
app.TopWindow.setup(path=False) |
| 4910 |
app.process_argv(1) or app.TopWindow.tc_load_cfg_from_ti1() |
| 4911 |
app.TopWindow.Show() |
| 4912 |
|
| 4913 |
|
| 4914 |
if __name__ == "__main__": |
| 4915 |
main() |