|
17 | 17 | using SixLabors.ImageSharp.Memory;
|
18 | 18 | using SixLabors.ImageSharp.Memory.Internals;
|
19 | 19 | using SixLabors.ImageSharp.Metadata;
|
| 20 | +using SixLabors.ImageSharp.Metadata.Profiles.Cicp; |
20 | 21 | using SixLabors.ImageSharp.Metadata.Profiles.Exif;
|
21 | 22 | using SixLabors.ImageSharp.Metadata.Profiles.Icc;
|
22 | 23 | using SixLabors.ImageSharp.Metadata.Profiles.Xmp;
|
@@ -191,6 +192,9 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
|
191 | 192 | case PngChunkType.Gamma:
|
192 | 193 | ReadGammaChunk(pngMetadata, chunk.Data.GetSpan());
|
193 | 194 | break;
|
| 195 | + case PngChunkType.Cicp: |
| 196 | + ReadCicpChunk(metadata, chunk.Data.GetSpan()); |
| 197 | + break; |
194 | 198 | case PngChunkType.FrameControl:
|
195 | 199 | frameCount++;
|
196 | 200 | if (frameCount == this.maxFrames)
|
@@ -360,6 +364,15 @@ public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellat
|
360 | 364 |
|
361 | 365 | ReadGammaChunk(pngMetadata, chunk.Data.GetSpan());
|
362 | 366 | break;
|
| 367 | + case PngChunkType.Cicp: |
| 368 | + if (this.colorMetadataOnly) |
| 369 | + { |
| 370 | + this.SkipChunkDataAndCrc(chunk); |
| 371 | + break; |
| 372 | + } |
| 373 | + |
| 374 | + ReadCicpChunk(metadata, chunk.Data.GetSpan()); |
| 375 | + break; |
363 | 376 | case PngChunkType.FrameControl:
|
364 | 377 | ++frameCount;
|
365 | 378 | if (frameCount == this.maxFrames)
|
@@ -1426,6 +1439,26 @@ private static bool TryReadTextChunkMetadata(ImageMetadata baseMetadata, string
|
1426 | 1439 | return false;
|
1427 | 1440 | }
|
1428 | 1441 |
|
| 1442 | + /// <summary> |
| 1443 | + /// Reads the CICP color profile chunk. |
| 1444 | + /// </summary> |
| 1445 | + /// <param name="metadata">The metadata.</param> |
| 1446 | + /// <param name="data">The bytes containing the profile.</param> |
| 1447 | + private static void ReadCicpChunk(ImageMetadata metadata, ReadOnlySpan<byte> data) |
| 1448 | + { |
| 1449 | + if (data.Length < 4) |
| 1450 | + { |
| 1451 | + // Ignore invalid cICP chunks. |
| 1452 | + return; |
| 1453 | + } |
| 1454 | + |
| 1455 | + byte colorPrimaries = data[0]; |
| 1456 | + byte transferFunction = data[1]; |
| 1457 | + byte matrixCoefficients = data[2]; |
| 1458 | + bool? fullRange = data[3] == 1 ? true : data[3] == 0 ? false : null; |
| 1459 | + metadata.CicpProfile = new CicpProfile(colorPrimaries, transferFunction, matrixCoefficients, fullRange); |
| 1460 | + } |
| 1461 | + |
1429 | 1462 | /// <summary>
|
1430 | 1463 | /// Reads exif data encoded into a text chunk with the name "raw profile type exif".
|
1431 | 1464 | /// This method was used by ImageMagick, exiftool, exiv2, digiKam, etc, before the
|
|
0 commit comments