SixLabors/ImageSharp · error · NotSupportedException
CICP matrix coefficients other than Identity are not…
Error message
CICP matrix coefficients other than Identity are not supported in PNG
What it means
PngEncoderCore throws this NotSupportedException when writing a cICP chunk for metadata whose CICP MatrixCoefficients is not Identity. The PNG cICP specification requires matrix coefficients to be Identity; other values (e.g. BT.709 or BT.601 matrices from video-oriented profiles) cannot be represented in PNG.
Solutions
- Clear or replace the image's CicpProfile metadata before saving (set a profile with MatrixCoefficients.Identity, or remove it entirely).
- Strip video-derived metadata when transcoding to PNG and let the encoder choose defaults.
- Save to a format that supports non-Identity matrices (e.g. AVIF) if the matrix coefficient must be preserved.
- Remove the cicp metadata chunk with an image metadata editor if re-encoding from source is not possible.
Example fix
// before: keeping video-derived CICP
using var image = Image.Load("frame.avif");
image.SaveAsPng("frame.png"); // throws
// after
using var image = Image.Load("frame.avif");
image.Metadata.RemoveCicpProfile(); // or set MatrixCoefficients = Identity
image.SaveAsPng("frame.png"); Defensive patterns
Strategy: validation
Validate before calling
// ensure CICP metadata is PNG-compatible before saving
var cicp = image.Metadata.GetCicpProfile();
if (cicp is not null && cicp.MatrixCoefficients != Metadata.Profiles.Cicp.CicpMatrixCoefficients.Identity)
{
image.Metadata.RemoveCicpProfile(); // or construct one with Identity
} Type guard
static bool IsPngCompatibleCicp(CicpProfile? p) =>
p is null || p.MatrixCoefficients == CicpMatrixCoefficients.Identity; Try / catch
try
{
image.SaveAsPng(path);
}
catch (NotSupportedException ex) when (ex.Message.Contains("CICP matrix coefficients"))
{
image.Metadata.RemoveCicpProfile();
image.SaveAsPng(path); // retry without the incompatible profile
} Prevention
- Strip or normalize CICP metadata when transcoding from video formats (AVIF/HEVC) to PNG.
- Remember PNG only allows Identity matrix coefficients per spec.
- Route content that must keep non-Identity matrices to AVIF/JXL instead.
When it happens
Trigger: Calling Image.Save/Mutate-save to PNG on an image whose metadata contains a CicpProfile copied from a video source (HEVC/AV1 streams) with a non-Identity MatrixCoefficients value.
Common situations: Transcoding video frames (HDR SDR-transfer content with BT.2020/709 matrix tags) into PNG, or blindly copying CICP metadata from JPEG-XL/AVIF to PNG.
Related errors
- Invalid compressed PNG metadata.
- The iptc value exceeds the limit of
- No encoder was found for extension
- Invalid window size for ZLIB header: cinfo=
- Bad method for ZLIB header: cmf=
AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13).
Data as JSON: /api/errors/8c606d437c62f22e.
Report an issue: GitHub.
Appendix: source
Thrown at src/ImageSharp/Formats/Png/PngEncoderCore.cs:1068
}
/// <summary>
/// Writes the CICP profile chunk
/// </summary>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="metaData">The image meta data.</param>
/// <exception cref="NotSupportedException">CICP matrix coefficients other than Identity are not supported in PNG.</exception>
private void WriteCicpChunk(Stream stream, ImageMetadata metaData)
{
if (metaData.CicpProfile is null)
{
return;
}
// by spec, the matrix coefficients must be set to Identity
if (metaData.CicpProfile.MatrixCoefficients != Metadata.Profiles.Cicp.CicpMatrixCoefficients.Identity)
{
throw new NotSupportedException("CICP matrix coefficients other than Identity are not supported in PNG");
}
Span<byte> outputBytes = this.chunkDataBuffer[..4];
outputBytes[0] = (byte)metaData.CicpProfile.ColorPrimaries;
outputBytes[1] = (byte)metaData.CicpProfile.TransferCharacteristics;
outputBytes[2] = (byte)metaData.CicpProfile.MatrixCoefficients;
outputBytes[3] = (byte)(metaData.CicpProfile.FullRange ? 1 : 0);
this.WriteChunk(stream, PngChunkType.Cicp, outputBytes);
}
/// <summary>
/// Writes the color profile chunk.
/// </summary>
/// <param name="stream">The stream to write to.</param>
/// <param name="metaData">The image meta data.</param>
private void WriteColorProfileChunk(Stream stream, ImageMetadata metaData)
{
if (metaData.IccProfile is null)View on GitHub (pinned to 59ce6af6fc)