{"record":{"id":"7e28447fa5f54b4f","repo":"SixLabors/ImageSharp","slug":"invalid-clut-data-type-of-value-datatype","errorCode":null,"errorMessage":"Invalid CLUT data type of {value.DataType}","messagePattern":"Invalid CLUT data type of (.+?)","errorType":"exception","errorClass":"InvalidIccProfileException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs","lineNumber":65,"sourceCode":"    {\n        int count = this.WriteArray(value.GridPointCount);\n        count += this.WriteEmpty(16 - value.GridPointCount.Length);\n\n        switch (value.DataType)\n        {\n            case IccClutDataType.Float:\n                return count + this.WriteClutF32(value);\n            case IccClutDataType.UInt8:\n                count += this.WriteByte(1);\n                count += this.WriteEmpty(3);\n                return count + this.WriteClut8(value);\n            case IccClutDataType.UInt16:\n                count += this.WriteByte(2);\n                count += this.WriteEmpty(3);\n                return count + this.WriteClut16(value);\n\n            default:\n                throw new InvalidIccProfileException($\"Invalid CLUT data type of {value.DataType}\");\n        }\n    }\n\n    /// <summary>\n    /// Writes a 8bit color lookup table.\n    /// </summary>\n    /// <param name=\"value\">The CLUT to write.</param>\n    /// <returns>The number of bytes written.</returns>\n    public int WriteClut8(IccClut value)\n    {\n        int count = 0;\n        foreach (float item in value.Values)\n        {\n            count += this.WriteByte((byte)Numerics.Clamp((item * byte.MaxValue) + 0.5F, 0, byte.MaxValue));\n        }\n\n        return count;\n    }","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs#L47-L83","documentation":"When writing a CLUT, its DataType must be UInt8, UInt16, or Float32. The writer switches on the declared data type to pick the binary encoding; an unknown IccClutDataType has no on-disk representation, so the writer refuses instead of emitting garbage bytes.","triggerScenarios":"Calling WriteClut (via WriteClutProcessElement / WriteLutAtoBTagDataEntry / WriteLutBToATagDataEntry) with an IccClut whose DataType property is an undefined/invalid IccClutDataType value (e.g. default-initialized struct or manually cast value).","commonSituations":"Programmatic ICC profile generation with a partially initialized IccClut; deserializing a CLUT from an unsupported profile and re-serializing without fixing DataType; enum casts from ints out of range.","solutions":["Set the IccClut DataType explicitly to IccClutDataType.UInt8, UInt16, or Float32 before writing.","Initialize IccClut via a constructor that takes the data and channel counts so DataType is derived correctly.","Check for invalid enum casts into IccClutDataType in your code path."],"exampleFix":"// before: struct default leaves DataType unset\ncount += writer.WriteClut(new IccClut());\n\n// after: construct with valid data and matching channel counts\nvar clut = new IccClut(\n    inChannelCount: 3,\n    outChannelCount: 3,\n    gridPointCount: new byte[] { 2, 2, 2 },\n    IccClutDataType.Float32,\n    values);","handlingStrategy":"validation","validationCode":"// Verify DataType before writing\nif (clut.DataType is not (IccClutDataType.UInt8 or IccClutDataType.UInt16 or IccClutDataType.Float32))\n    throw new ArgumentException(\"CLUT DataType must be UInt8, UInt16, or Float32\");","typeGuard":null,"tryCatchPattern":"try { writer.WriteClut(clut); }\ncatch (InvalidIccProfileException ex) when (ex.Message.Contains(\"CLUT data type\"))\n{\n    // re-initialize clut with explicit, valid DataType\n    clut = RecreateClutWithValidDataType(clut);\n    writer.WriteClut(clut);\n}","preventionTips":["Construct IccClut with constructors that derive DataType from the value array","Avoid raw enum casts into IccClutDataType","Never use default(IccClut) in generated profiles","Round-trip only fully parsed profiles"],"tags":["icc","serialization","clut"],"backgroundTag":"invalid-enum-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"}