{"record":{"id":"5375e5f4d01f1950","repo":"SixLabors/ImageSharp","slug":"icc-conversion-supports-at-most-four-tone-response-curves","errorCode":null,"errorMessage":"ICC conversion supports at most four tone response curves.","messagePattern":"ICC conversion supports at most four tone response curves\\.","errorType":"exception","errorClass":"InvalidIccProfileException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/ColorProfiles/Icc/Calculators/TrcCalculator.cs","lineNumber":20,"sourceCode":"// Licensed under the Six Labors Split License.\n\nusing System.Numerics;\nusing System.Runtime.CompilerServices;\nusing SixLabors.ImageSharp.ColorProfiles.Conversion.Icc;\nusing SixLabors.ImageSharp.Metadata.Profiles.Icc;\n\nnamespace SixLabors.ImageSharp.ColorProfiles.Icc.Calculators;\n\ninternal class TrcCalculator : IVector4Calculator\n{\n    private readonly ISingleCalculator[] calculators;\n\n    public TrcCalculator(IccTagDataEntry[] entries, bool inverted)\n    {\n        Guard.NotNull(entries, nameof(entries));\n        if (entries.Length > 4)\n        {\n            throw new InvalidIccProfileException(\"ICC conversion supports at most four tone response curves.\");\n        }\n\n        this.calculators = new ISingleCalculator[entries.Length];\n        for (int i = 0; i < entries.Length; i++)\n        {\n            this.calculators[i] = entries[i] switch\n            {\n                IccCurveTagDataEntry curve => new CurveCalculator(curve, inverted),\n                IccParametricCurveTagDataEntry parametricCurve => new ParametricCurveCalculator(parametricCurve, inverted),\n                _ => throw new InvalidIccProfileException(\"Invalid Entry.\"),\n            };\n        }\n    }\n\n    public unsafe Vector4 Calculate(Vector4 value)\n    {\n        ref float f = ref Unsafe.As<Vector4, float>(ref value);\n        for (int i = 0; i < this.calculators.Length; i++)","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/ColorProfiles/Icc/Calculators/TrcCalculator.cs#L2-L38","documentation":"TrcCalculator's constructor accepts an array of tone response curve tag entries (one per channel) and throws InvalidIccProfileException when more than 4 entries are supplied, since the calculator produces a Vector4 (4-channel max) result.","triggerScenarios":"Building an IccConverter whose conversion path resolves more than 4 TRC tag entries for a color transform (e.g. an N-channel profile with 5+ channels), hitting the InitColorTrc path.","commonSituations":"HiFi / extended-ink ICC profiles (5–8 channel); corrupt profiles with duplicated or garbage TRC tags; unsupported device classes.","solutions":["Use a profile limited to Gray/RGB/CMYK (≤4 channels).","Validate TRC entry counts before conversion and reject profiles exceeding 4.","Fall back to an external ICC engine for N-channel spaces."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (trcEntries.Length > 4)\n{\n    throw new NotSupportedException(\"ICC profile has more than four tone response curves; unsupported.\");\n}","typeGuard":null,"tryCatchPattern":"try { converter.Convert(...); }\ncatch (InvalidIccProfileException ex) { /* reject N-channel profile, use a standard profile instead */ }","preventionTips":["Limit accepted device spaces to Gray/RGB/CMYK.","Check TRC tag counts during profile validation.","Route HiFi/N-channel workflows to an external ICC engine."],"tags":["icc","color-management","profile-validation","csharp"],"backgroundTag":"invalid-argument-value","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}