feat: complete multichannel (5-7ch) ICC profile generation & verification

- 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
This commit is contained in:
2026-11-18 16:49:43 +03:30
parent d909b331c2
commit eaab9e3dd3
17 changed files with 3336 additions and 247 deletions

View File

@@ -1226,48 +1226,26 @@ make_output_icc(
}
/* B2A table: */
if (devchan >= 7) { /* 7+ channels: small BtoA CLUT */
if (devchan >= 5) { /* 5+ channels: optimization-based BtoA CLUT */
if (oquality >= 3) { /* Ultra High */
b2ainres = 2048;
b2ares = 33;
b2aoutres = 2048;
} else if (oquality == 2) {
b2ainres = 1024;
b2ares = 25; /* High */
b2aoutres = 1024;
} else if (oquality == 1) {
b2ainres = 512;
b2ares = 17; /* Medium */
b2aoutres = 512;
} else if (oquality >= 0) {
b2ainres = 256;
b2ares = 9; /* Low */
b2aoutres = 256;
} else { /* Special, Extremely low quality */
b2ainres = 64;
b2ares = 5;
b2aoutres = 512;
} else if (oquality == 2) {
b2ainres = 512;
b2ares = 4; /* High */
b2aoutres = 512;
} else if (oquality == 1) {
b2ainres = 256;
b2ares = 4; /* Medium */
b2aoutres = 256;
} else if (oquality >= 0) {
b2ainres = 256;
b2ares = 3; /* Low */
b2aoutres = 256;
} else { /* Special, Extremely low quality */
b2ainres = 64;
b2ares = 3;
b2aoutres = 64;
}
} else if (devchan >= 5) { /* 5-6 channels: moderate BtoA CLUT */
if (oquality >= 3) { /* Ultra High */
b2ainres = 1024;
b2ares = 9;
b2aoutres = 1024;
} else if (oquality == 2) {
b2ainres = 1024;
b2ares = 7; /* High */
b2aoutres = 1024;
} else if (oquality == 1) {
b2ainres = 512;
b2ares = 5; /* Medium */
b2aoutres = 512;
} else if (oquality >= 0) {
b2ainres = 256;
b2ares = 4; /* Low */
b2aoutres = 256;
} else { /* Special, Extremely low quality */
b2ainres = 64;
b2ares = 3;
b2aoutres = 64;
}
} else if (devchan >= 2) {
@@ -1753,6 +1731,7 @@ make_output_icc(
{
int ti, ii, ci, mi, yi, ki;
int Xi, Yi, Zi;
int j, chix[MXDI];
/* A sanity check */
if (isAdditive && oink != NULL && oink->tlimit > 0.0 && oink->tlimit < (double)devchan) {
@@ -1780,6 +1759,7 @@ make_output_icc(
error("Field GRAY_K is wrong type - corrupted file ?");
}
mi = yi = ki = ci;
chix[0] = ci;
} else if (devspace == icSigRgbData) {
@@ -1796,6 +1776,9 @@ make_output_icc(
if (icg->t[0].ftype[yi] != r_t)
error("Field RGB_B is wrong type - corrupted file ?");
ki = yi;
chix[0] = ci;
chix[1] = mi;
chix[2] = yi;
} else if (devspace == icSigCmyData) {
@@ -1812,6 +1795,36 @@ make_output_icc(
if (icg->t[0].ftype[yi] != r_t)
error("Field CMY_Y is wrong type - corrupted file ?");
ki = yi;
chix[0] = ci;
chix[1] = mi;
chix[2] = yi;
} else if (devchan >= 5) {
char *bident = NULL;
if (imask != 0)
bident = icx_inkmask2char(imask, 0);
for (j = 0; j < devchan; j++) {
char fname[100];
if (bident != NULL) {
inkmask iimask = icx_index2ink(imask, j);
sprintf(fname, "%s_%s", bident, icx_ink2char(iimask));
} else {
sprintf(fname, "%dCLR_%d", devchan, j+1);
}
if ((chix[j] = icg->find_field(icg, 0, fname)) < 0) {
/* Try generic format */
sprintf(fname, "%dCLR_%d", devchan, j+1);
if ((chix[j] = icg->find_field(icg, 0, fname)) < 0)
error("Input file doesn't contain field %s", fname);
}
if (icg->t[0].ftype[chix[j]] != r_t)
error("Field %s is wrong type - corrupted file ?", fname);
}
ci = chix[0];
mi = chix[1];
yi = chix[2];
ki = (devchan > 3) ? chix[3] : chix[devchan-1];
} else { /* Assume CMYK */
@@ -1831,6 +1844,10 @@ make_output_icc(
error("Input file doesn't contain field CMYK_K");
if (icg->t[0].ftype[ki] != r_t)
error("Field CMYK_K is wrong type - corrupted file ?");
chix[0] = ci;
chix[1] = mi;
chix[2] = yi;
chix[3] = ki;
}
if (spec == 0) { /* Using instrument tristimulous value */
@@ -1866,23 +1883,11 @@ make_output_icc(
for (i = 0; i < npat; i++) {
tpat[i].w = 1.0;
tpat[i].p[0] = *((double *)icg->t[0].fdata[i][ci]) / 100.0;
tpat[i].p[1] = *((double *)icg->t[0].fdata[i][mi]) / 100.0;
tpat[i].p[2] = *((double *)icg->t[0].fdata[i][yi]) / 100.0;
tpat[i].p[3] = *((double *)icg->t[0].fdata[i][ki]) / 100.0;
if (tpat[i].p[0] > 1.0
|| tpat[i].p[1] > 1.0
|| tpat[i].p[2] > 1.0
|| tpat[i].p[3] > 1.0) {
double bgst = 0.0;
int j, bj = 0;
for (j = 0; j < 4; j++) {
if (tpat[i].p[j] > bgst) {
bgst = tpat[i].p[j];
bj = j;
}
for (j = 0; j < devchan; j++) {
tpat[i].p[j] = *((double *)icg->t[0].fdata[i][chix[j]]) / 100.0;
if (tpat[i].p[j] > 1.0) {
error("Device value field value exceeds 100.0 (%d:%d:%f) !",i,j,tpat[i].p[j] * 100.0);
}
error("Device value field value exceeds 100.0 (%d:%d:%f) !",i,bj,bgst * 100.0);
}
tpat[i].v[0] = *((double *)icg->t[0].fdata[i][Xi]);
tpat[i].v[1] = *((double *)icg->t[0].fdata[i][Yi]);
@@ -2027,14 +2032,16 @@ make_output_icc(
&& *((double *)icg->t[0].fdata[i][mi]) < 0.1
&& *((double *)icg->t[0].fdata[i][yi]) < 0.1)
use = 1;
} else { /* Assume CMYK */
if (*((double *)icg->t[0].fdata[i][ci]) < 0.1
&& *((double *)icg->t[0].fdata[i][mi]) < 0.1
&& *((double *)icg->t[0].fdata[i][yi]) < 0.1
&& *((double *)icg->t[0].fdata[i][ki]) < 0.1) {
use = 1;
} else { /* CMYK and Multichannel (subtractive) */
int all_zero = 1;
for (j = 0; j < devchan; j++) {
if (*((double *)icg->t[0].fdata[i][chix[j]]) >= 0.1) {
all_zero = 0;
break;
}
}
if (all_zero)
use = 1;
}
if (use) {
@@ -2090,16 +2097,11 @@ make_output_icc(
for (i = 0; i < npat; i++) {
tpat[i].w = 1.0;
tpat[i].p[0] = *((double *)icg->t[0].fdata[i][ci]) / 100.0;
tpat[i].p[1] = *((double *)icg->t[0].fdata[i][mi]) / 100.0;
tpat[i].p[2] = *((double *)icg->t[0].fdata[i][yi]) / 100.0;
tpat[i].p[3] = *((double *)icg->t[0].fdata[i][ki]) / 100.0;
if (tpat[i].p[0] > 1.0
|| tpat[i].p[1] > 1.0
|| tpat[i].p[2] > 1.0
|| tpat[i].p[3] > 1.0) {
error("Device value field value exceeds 100.0 !");
for (j = 0; j < devchan; j++) {
tpat[i].p[j] = *((double *)icg->t[0].fdata[i][chix[j]]) / 100.0;
if (tpat[i].p[j] > 1.0) {
error("Device value field value exceeds 100.0 !");
}
}
/* Read the spectral values for this patch */