- Profile Creation & Inversion (profout.c, xlut.c, mchan_inv.c):
* Unify BtoA CLUT resolutions for devchan >= 5 (9/17/25/33) to provide dense PCS inversion grids
* Guard all reverse simplicial ops in xlut.c with within_restrictedsize() to prevent SIGSEGV when di > 4 (MXRI cap)
* Enhance Powell optimizer in mchan_inv.c with multi-candidate starting strategy and scaled deltaE^2 Lab coordinates
* Allow icSigColorantTableTag in V2 profiles for devchan >= 5 in icc.c
- Numerical & Geometry Stability (scat.c, gamut.c):
* Fix SIGSEGV in rspl scat.c sparse matrix solver caused by assumption of sorted xcol in 4x unrolled loops
* Add null pointer and tag checks in gamut.c radial_point_triang
- Test Targets & Verification (test_multichannel/):
* Add synthetic .ti1 and .ti3 targets for 5-channel (CMYKO), 6-channel (CMYKOG), and 7-channel (CMYKOGV) workflows
* Add ti1_to_ti3 conversion script and verify_roundtrip.py round-trip verification utility
* Verified end-to-end:
- 5-channel: avg dE = 2.38, max dE = 6.27
- 6-channel: avg dE = 1.90, max dE = 5.40
- 7-channel: avg dE = 2.15, max dE = 5.54
- Build & Housekeeping:
* Add .gitignore for compiled executables, autotools outputs, and generated ICC profiles
* Update MULTICHANNEL_IMPLEMENTATION_PLAN.md with verification results
106 lines
3.4 KiB
Python
106 lines
3.4 KiB
Python
import sys
|
|
import os
|
|
|
|
def xyz_to_lab(X, Y, Z):
|
|
"""CIE XYZ to CIELAB (D50 illuminant)"""
|
|
Xn, Yn, Zn = 96.42, 100.0, 82.49 # D50
|
|
|
|
def f(t):
|
|
if t > 0.008856:
|
|
return t ** (1.0/3.0)
|
|
else:
|
|
return 7.787 * t + 16.0/116.0
|
|
|
|
fx = f(X / Xn)
|
|
fy = f(Y / Yn)
|
|
fz = f(Z / Zn)
|
|
|
|
L = 116.0 * fy - 16.0
|
|
a = 500.0 * (fx - fy)
|
|
b = 200.0 * (fy - fz)
|
|
return L, a, b
|
|
|
|
def convert(ti1_path, ti3_path):
|
|
with open(ti1_path, "r") as fin:
|
|
lines = fin.readlines()
|
|
|
|
color_rep = None
|
|
data_rows = []
|
|
first_format = None
|
|
in_format = False
|
|
in_data = False
|
|
|
|
for line in lines:
|
|
stripped = line.strip()
|
|
if stripped.startswith("COLOR_REP"):
|
|
parts = stripped.split()
|
|
if len(parts) >= 2 and color_rep is None:
|
|
color_rep = parts[1].replace('"', '')
|
|
elif stripped == "BEGIN_DATA_FORMAT":
|
|
in_format = True
|
|
continue
|
|
elif stripped == "END_DATA_FORMAT":
|
|
in_format = False
|
|
continue
|
|
elif in_format and stripped:
|
|
if first_format is None:
|
|
first_format = stripped.split()
|
|
elif stripped == "BEGIN_DATA":
|
|
in_data = True
|
|
continue
|
|
elif stripped == "END_DATA":
|
|
in_data = False
|
|
continue
|
|
elif in_data and stripped:
|
|
data_rows.append(stripped.split())
|
|
|
|
# From first_format, figure out dev_fields
|
|
# first_format is like: ['SAMPLE_ID', 'CMYKO_C', 'CMYKO_M', 'CMYKO_Y', 'CMYKO_K', 'CMYKO_O', 'XYZ_X', 'XYZ_Y', 'XYZ_Z']
|
|
dev_fields = []
|
|
for token in first_format[1:]:
|
|
if token in ("XYZ_X", "XYZ_Y", "XYZ_Z", "LAB_L", "LAB_A", "LAB_B"):
|
|
break
|
|
dev_fields.append(token)
|
|
|
|
num_dev = len(dev_fields)
|
|
ti3_color_rep = f"{color_rep}_LAB"
|
|
|
|
field_names = ["SAMPLE_ID"] + dev_fields + ["LAB_L", "LAB_A", "LAB_B"]
|
|
|
|
with open(ti3_path, "w") as fout:
|
|
fout.write("CTI3 \n\n")
|
|
fout.write('DESCRIPTOR "Argyll Calibration Target chart information 3"\n')
|
|
fout.write('ORIGINATOR "Synthetic test data for multichannel verification"\n')
|
|
fout.write('DEVICE_CLASS "OUTPUT"\n')
|
|
fout.write('APPROX_WHITE_POINT "96.420000 100.000000 82.490000"\n')
|
|
fout.write(f'COLOR_REP "{ti3_color_rep}"\n\n')
|
|
|
|
fout.write(f"NUMBER_OF_FIELDS {len(field_names)}\n")
|
|
fout.write("BEGIN_DATA_FORMAT\n")
|
|
fout.write(" ".join(field_names) + "\n")
|
|
fout.write("END_DATA_FORMAT\n\n")
|
|
|
|
fout.write(f"NUMBER_OF_SETS {len(data_rows)}\n")
|
|
fout.write("BEGIN_DATA\n")
|
|
|
|
for idx, row in enumerate(data_rows, 1):
|
|
# row: [id, dev_0, ..., dev_{num_dev-1}, X, Y, Z]
|
|
dev_vals = row[1:1+num_dev]
|
|
X = float(row[-3])
|
|
Y = float(row[-2])
|
|
Z = float(row[-1])
|
|
L, a, b = xyz_to_lab(X, Y, Z)
|
|
|
|
line_parts = [str(idx)] + [f"{float(v):.5f}" for v in dev_vals] + [f"{L:.4f}", f"{a:.4f}", f"{b:.4f}"]
|
|
fout.write(" ".join(line_parts) + "\n")
|
|
|
|
fout.write("END_DATA\n")
|
|
|
|
print(f"Successfully converted {ti1_path} -> {ti3_path}: {len(data_rows)} patches, {num_dev} channels ({ti3_color_rep})")
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) < 3:
|
|
print("Usage: python3 ti1_to_ti3.py input.ti1 output.ti3")
|
|
sys.exit(1)
|
|
convert(sys.argv[1], sys.argv[2])
|