Files
LithiumCMS/MULTICHANNEL_EXPANSION_RESEARCH_AND_PLAN.md
Diaco Soltanpour 95d31976db docs: make paths relative in multichannel expansion plan
Replace machine-specific absolute filesystem paths with repository-relative
paths across the research and plan document. The guide previously contained
hardcoded directory paths from another development machine, which broke
portability when referencing codebase locations and following compilation
instructions across different devices and operating systems.
2026-10-31 23:52:11 +03:30

14 KiB
Raw Blame History

ArgyllCMS Multichannel (5 to 7 Color) ICC Profiling: Research & Implementation Blueprint

Document Version: 1.0
Target Architecture: ArgyllCMS v3.5.0 (Argyll_V3.5.0)
Scope: Expanding printer profile generation from 1–4 color channels (Gray, RGB, CMY, CMYK) to 5, 6, and 7 channels (e.g., 5CLR, 6CLR, 7CLR, CMYK+OGV, CMYK+cm, CcMmYK).


1. Executive Summary & Objective

ArgyllCMS currently supports up to 4 device channels (CMYK, CMY, RGB, Gray) for output device profiling in colprof. However, modern Expanded Color Gamut (ECG) and high-fidelity printing commonly use 5 to 7 colorants (most prominently CMYK + Orange + Green + Violet/Blue or CMYK + Light Cyan + Light Magenta).

The objective is to expand ArgyllCMS to generate valid, high-quality v2 / v4 ICC printer profiles for 5, 6, and 7 device colorants, featuring:

  • Correct ICC device color space signatures (icSig5colorData, icSig6colorData, icSig7colorData).
  • Colorant Table tag (clrT) defining ink names and color coordinates.
  • Forward device-to-PCS lookup tables (AtoB0, AtoB1, AtoB2).
  • Inverse PCS-to-device lookup tables (BtoA0, BtoA1, BtoA2) with proper ink limiting (Total Area Coverage / TAC) and multi-ink separation.

2. Codebase Map & Key Locations

The source code is located at ./Argyll_V3.5.0/ (relative to the repository root):

Directory Purpose Key Files & Responsibilities
icc/ ICC Profile Engine (icclib) icc.h, icc.c, iccV44.h: Profile header, tag directory, LUT8/16/CLUT data structures.
rspl/ Regular Simplex Spline Library rspl.h, rspl.c, rev.c: Multi-dimensional scattered data interpolation and simplicial inversion.
profile/ Profile Generation CLI & Logic colprof.c: Main CLI parser and flow controller.
profout.c: Output device profile builder (AtoB / BtoA generation).
prof.h: Profile creation interfaces.
xicc/ Extended Color Management xlut.c: Multi-stage LUT evaluation and inversion (icxLuLut_inv_clut_aux).
xcolorants.c, xcolorants.h: Known colorant table and ink combinations.
xfit.c: Curve fitting and shaper optimization.
gammap.c: Gamut mapping algorithms.
target/ Chart & Target Generation targen.c: Test patch generation for characterization targets.
cgats/ Measurement File Parser cgats.c, cgats.h: Reading and writing .ti1, .ti2, .ti3 files.
numlib/ Numerical Mathematics Multi-dimensional optimizers (powell, simplex, matrix solvers).

3. Deep Architectural Analysis: What Works vs. What Is Blocked

3.1 What ALREADY Supports Multichannel (>4 Channels)

The underlying architecture of ArgyllCMS is surprisingly well-prepared for multichannel color in several subsystems:

  1. ICC Data Structures (icc/icc.h, icc/iccV44.h):

    • MAX_CHAN is defined as 15 in icc/icc.h:712.
    • Signatures are already declared in icc/iccV44.h:
      • icSig5colorData ('5CLR' = 0x35434C52)
      • icSig6colorData ('6CLR' = 0x36434C52)
      • icSig7colorData ('7CLR' = 0x37434C52)
      • icSig8colorData ('8CLR' = 0x38434C52)
    • LUT structures (lut16Type, lut8Type, multiProcessElementsType) in icclib already accept variable channel counts up to MAX_CHAN.
  2. Colorant Definitions (xicc/xcolorants.c):

    • Argyll already contains definitions for extended colorants: Orange, Green, Blue, Red, Violet, Light Cyan, Light Magenta, Light Yellow, Light Black (xcolorants.c:50-108).
    • Multi-ink masks are already defined in icx_colcomb_table:
      • ICX_CMYKOG (CMYK + Orange + Green, 6 colors)
      • ICX_CMYKRB (CMYK + Red + Blue, 6 colors)
      • ICX_CMYKcm (CMYK + Light Cyan + Light Magenta, 6 colors)
      • ICX_CMYKOGV (CMYK + Orange + Green + Violet, 7 colors)
      • ICX_CMYKRGB (CMYK + Red + Green + Blue, 7 colors)
      • ICX_CMYKcmk (CMYK + Light CMK, 7 colors)
  3. RSPL Forward Interpolation (rspl/rspl.h):

    • Forward Regular Simplex Spline interpolation natively supports up to 10 input dimensions:
      #define MXDI 10   /* Maximum input dimensionality */
      #define MXDO 10   /* Maximum output dimensionality */
      
    • Given scattered 5D, 6D, or 7D measurement points, the forward model can fit a continuous function to predict Lab/XYZ from device values.

3.2 The Four Critical Bottlenecks

flowchart TD
    A[Input .ti3 File with 5-7 Channels] --> B[Bottleneck 1: colprof.c / profout.c]
    B -->|Check COLOR_REP fails on 5CLR/6CLR/7CLR| ERR1[Fatal Error: Unhandled color representation]
    
    B -->|Passes after adding signatures| C[Bottleneck 2: AtoB CLUT Resolution Explosion]
    C -->|If using a2bres=17: 17^7 = 410 Million Nodes| ERR2[Out of Memory / Crash]
    
    C -->|Passes with dimension-scaled grid| D[Bottleneck 3: rspl/rev.c MXRI=4 Limit]
    D -->|s->di > MXRI check| ERR3[Fatal Error: rspl rev_locus_segs can't handle di > 4]
    
    D -->|Passes if using alternative inversion| E[Bottleneck 4: Multi-Ink Separation Ambiguity]
    E -->|7-to-3 has 4 redundant degrees of freedom| SOL[Requires Multi-Ink Separation Strategy]

Bottleneck 1: Hardcoded COLOR_REP Checks

  • Location: profile/profout.c lines 986–1065.
  • Problem: profout.c reads the COLOR_REP keyword from the .ti3 file and only recognizes CMYK_XYZ, CMYK_LAB, CMY_XYZ, CMY_LAB, RGB_XYZ, RGB_LAB, iRGB_XYZ, iRGB_LAB, K_XYZ, W_XYZ.
  • Symptom: Any multichannel .ti3 file halts with: error("Output device input file has unhandled color representation '%s'", icg->t[0].kdata[ti]);

Bottleneck 2: Forward CLUT Grid Explosion ("Curse of Dimensionality")

  • Location: profile/profout.c lines 1068–1105.
  • Problem: For devchan >= 4, a2bres (grid resolution per axis) is set to 23 (high), 17 (med), 9 (low), 5 (fast).
    • For 4D (CMYK): 17^4 = 83,521 nodes (manageable).
    • For 5D: 17^5 = 1,419,857 nodes (high).
    • For 6D: 17^6 = 24,137,569 nodes (~72 MB per table, slow).
    • For 7D: 17^7 = 410,338,673 nodes (~1.2 GB per table \times 3 intents \to OOM).
  • Solution: Resolution must adapt to dimension N:
    • N=5: 7 to 9 points (7^5 = 16,807, 9^5 = 59,049).
    • N=6: 5 to 6 points (5^6 = 15,625, 6^6 = 46,656).
    • N=7: 4 to 5 points (4^7 = 16,384, 5^7 = 78,125).

Bottleneck 3: RSPL Simplicial Inversion Capped at 4D (MXRI 4)

  • Location: rspl/rspl.h:45, rspl/rev.c:829-832.
  • Problem:
    #define MXRI 4  /* Maximum input dimensionality for reverse lookup */
    
    rev.c implements simplicial inversion where an $N$-dimensional hypercube is subdivided into N! simplices. The internal analytic solvers (lchw_edge_solve, lchw_tri_solve, tetrahedron solve) are hard-coded for up to 4 dimensions. If di > 4, line 830 triggers:
    if (di > MXRI)
        error("rspl: rev_locus_segs can't handle di = %d", di);
    

Bottleneck 4: Inversion Redundancy (Color Separation for 5 to 7 Inks)

  • Location: xicc/xlut.c (icxLuLut_inv_clut_aux).
  • Problem:
    • PCS is 3-dimensional (Lab or XYZ).
    • Output is $N$-dimensional (N=5, 6, 7).
    • Degrees of freedom: N - 3 (2 for 5-color, 3 for 6-color, 4 for 7-color).
    • For CMYK (N=4), there is only 1 redundant degree of freedom. Argyll resolves this by calculating the black locus [K_{\min}, K_{\max}] via rev_locus(), selecting a single K using a black generation curve, and then solving uniquely for C, M, Y.
    • For 7 colors (CMYK+OGV), infinitely many combinations of inks produce the exact same Lab color. Without an explicit multichannel separation algorithm, arbitrary ink mixtures occur (e.g. Orange and Green printing on neutral grays, causing severe metamerism and huge ink consumption).

4. Implementation Blueprint: How to Build Multichannel Support

Phase 1: Input Pipeline & Profile Header Support

  1. Extend .ti3 Keywords in cgats/ and profile/:
    • Support 5CLR_LAB, 5CLR_XYZ, 6CLR_LAB, 6CLR_XYZ, 7CLR_LAB, 7CLR_XYZ.
    • Also support semantic names: CMYKOG_LAB, CMYKOGV_LAB, CMYKcm_LAB, etc.
  2. Device Space Detection in profout.c:
    • Parse number of device channels from COLOR_REP or the .ti3 field count.
    • Set devchan = 5, 6, 7.
    • Map to devspace = icSig5colorData, icSig6colorData, or icSig7colorData.
    • Set matching ink mask imask using icx_char2inkmask() from xcolorants.c.
  3. ICC Header & Tags Setup:
    • Set header->colorSpace = devspace.
    • Create colorantTableTag (clrT):
      • Populate entry names ("Cyan", "Magenta", "Yellow", "Black", "Orange", "Green", "Violet") using icx_ink_table.
      • Store 16-bit PCS coordinates for each colorant from measured 100% single-ink patches.

Phase 2: Forward Model & AtoB CLUT Generation

  1. Adaptive Grid Resolution: In profout.c, update the table sizing logic:
    if (devchan == 7) {
        a2bres = (iquality >= 2) ? 5 : 4;  /* 5^7 = 78,125; 4^7 = 16,384 */
    } else if (devchan == 6) {
        a2bres = (iquality >= 2) ? 6 : 5;  /* 6^6 = 46,656; 5^6 = 15,625 */
    } else if (devchan == 5) {
        a2bres = (iquality >= 2) ? 8 : 6;  /* 8^5 = 32,768; 6^5 = 7,776 */
    } else if (devchan == 4) {
        /* Existing CMYK logic (9, 17, 23) */
    }
    
  2. Fitting the RSPL Forward Spline:
    • The forward RSPL object is initialized with di = devchan and do = 3 (PCS).
    • RSPL already supports MXDI 10, so new_rspl(devchan, 3) works without modifications.
    • Evaluate the forward grid points to populate AtoB0 (Perceptual), AtoB1 (Colorimetric), and AtoB2 (Saturation).

Phase 3: The Multichannel Inversion Engine (BtoA CLUT Generation)

Because modifying rspl/rev.c to solve 7D geometric simplices is mathematically prohibitive and unnecessary, implement one of the two industry-standard approaches:

Instead of searching all 7 dimensions simultaneously, decompose the 7-color space into connected 4D sub-gamuts:

  • Neutral / Shadow core: \{C, M, Y, K\} (Standard CMYK GCR rules apply).
  • Red/Orange sector (30^\circ \le h_{ab} < 90^\circ): \{M, Y, K, O\} (Orange replaces Magenta + Yellow).
  • Green sector (90^\circ \le h_{ab} < 210^\circ): \{C, Y, K, G\} (Green replaces Cyan + Yellow).
  • Blue/Violet sector (210^\circ \le h_{ab} < 330^\circ): \{C, M, K, V\} (Violet replaces Cyan + Magenta).
graph TD
    LAB[Target Lab from PCS CLUT Node] --> HUE{Compute Hue Angle hab}
    HUE -->|Neutral / Inside CMYK| SUB_CMYK[Solve 4D: C, M, Y, K]
    HUE -->|Orange Sector 30° - 90°| SUB_CMYKO[Solve 4D: M, Y, K, Orange]
    HUE -->|Green Sector 90° - 210°| SUB_CMYKG[Solve 4D: C, Y, K, Green]
    HUE -->|Violet Sector 210° - 330°| SUB_CMYKV[Solve 4D: C, M, K, Violet]
    SUB_CMYK --> BLEND[Smooth Boundary Blend & Enforce TAC]
    SUB_CMYKO --> BLEND
    SUB_CMYKG --> BLEND
    SUB_CMYKV --> BLEND
    BLEND --> OUT[Final N-Color Device Output]

Why this works:

  • Each sub-system has \le 4 active chromatic inks at any given node.
  • It directly reuses the existing, highly refined 4D inversion logic (rev_locus + K generation).
  • It naturally prevents metamerism by keeping extra inks (OGV) out of neutral grays.

Approach B: Direct Constrained Optimization (Nonlinear Inversion)

For each node in the 33 \times 33 \times 33 BtoA PCS grid: Find the ink vector \mathbf{d} = [c_1, c_2, \dots, c_N]^T \in [0, 1]^N minimizing:

\mathcal{L}(\mathbf{d}) = \Delta E_{00}(\text{AtoB}(\mathbf{d}), \mathbf{Lab}_{\text{target}}) + w_{\text{tac}} \max\left(0, \sum_{i=1}^N d_i - \text{TAC}\right)^2 + w_{\text{gcr}} \Phi_{\text{gcr}}(\mathbf{d}) + w_{\text{smooth}} \|\mathbf{d} - \mathbf{d}_{\text{neighbor}}\|^2

ArgyllCMS already contains robust multidimensional optimization routines in numlib/ (powell() and simplex()).


5. Step-by-Step Code Modification Checklist

1. profile/profout.c

  • Add parsing for 5CLR_LAB, 6CLR_LAB, 7CLR_LAB and CMYKOG* in COLOR_REP check (line 989).
  • Set devchan = 5, 6, or 7, isAdditive = 0.
  • Set devspace = icSig5colorData / icSig6colorData / icSig7colorData.
  • Update a2bres calculation for devchan >= 5 to prevent memory explosion (line 1069).
  • Populate colorantTableTag with all N ink names and coordinates (line 1384).

2. profile/colprof.c

  • Expand Total Area Coverage (TAC) validation: allow ink limits up to N \times 100\% (line 1147).
  • Support multichannel options in CLI arguments.

3. xicc/xcolorants.c & xicc/xcolorants.h

  • Add lookup helpers to map 5CLR, 6CLR, 7CLR signatures to their constituent colorant lists.
  • Ensure icx_icc_to_colorant_comb handles icSig5colorData, icSig6colorData, icSig7colorData.

4. xicc/xlut.c (Inversion Callback)

  • In out_b2a_clut() and icxLuLut_inv_clut_aux():
    • Add dispatch for devchan > 4: call the sector-based sub-gamut inverter or the constrained optimizer.
    • Return the computed $N$-vector to populate the B2A table nodes.

6. Verification and Test Plan

  1. Test Data Preparation:
    • Utilize standard Fogra55 (ECG CMYKOGV characterization dataset) or generate a 7-channel test chart using targen:
      targen -v -d11 -f1000 -g64 test_7clr
      
  2. Compilation:
    • Compile using Argyll's Jam build system:
      cd Argyll_V3.5.0
      jam -q
      
  3. Profile Generation Test:
    bin/colprof -v -qm -D "Test CMYKOGV Profile" test_7clr
    
  4. Validation:
    • Inspect profile structure:
      iccdump test_7clr.icc
      
    • Check device space (7CLR), tags (clrT, A2B0, B2A0).
    • Run round-trip profile check with profcheck or xicclu:
      bin/xicclu -v -ir test_7clr.icc
      
      Input known CMYKOGV values \to verify forward Lab \to run backward conversion \to verify \Delta E < 2.0.