Browse Source

Add parsing of ICCP chunk

pull/1147/head
Brian Popow 6 years ago
parent
commit
4e234625b6
  1. 18
      src/ImageSharp/Formats/WebP/WebPDecoderCore.cs
  2. BIN
      tests/Images/Input/WebP/lossless_iccp.webp
  3. BIN
      tests/Images/Input/WebP/lossy_iccp.webp

18
src/ImageSharp/Formats/WebP/WebPDecoderCore.cs

@ -8,6 +8,7 @@ using System.IO;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.Metadata.Profiles.Icc;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Memory; using SixLabors.Memory;
@ -208,13 +209,22 @@ namespace SixLabors.ImageSharp.Formats.WebP
this.buffer[3] = 0; this.buffer[3] = 0;
int height = BinaryPrimitives.ReadInt32LittleEndian(this.buffer) + 1; int height = BinaryPrimitives.ReadInt32LittleEndian(this.buffer) + 1;
// Optional chunks ALPH, ICCP and ANIM can follow here. Ignoring them for now. // Optional chunks ICCP, ALPH and ANIM can follow here.
WebPChunkType chunkType; WebPChunkType chunkType;
if (isIccPresent) if (isIccPresent)
{ {
chunkType = this.ReadChunkType(); chunkType = this.ReadChunkType();
uint iccpChunkSize = this.ReadChunkSize(); if (chunkType is WebPChunkType.Iccp)
this.currentStream.Skip((int)iccpChunkSize); {
uint iccpChunkSize = this.ReadChunkSize();
var iccpData = new byte[iccpChunkSize];
this.currentStream.Read(iccpData, 0, (int)iccpChunkSize);
var profile = new IccProfile(iccpData);
if (profile.CheckIsValid())
{
this.Metadata.IccProfile = profile;
}
}
} }
if (isAnimationPresent) if (isAnimationPresent)
@ -236,6 +246,8 @@ namespace SixLabors.ImageSharp.Formats.WebP
{ {
chunkType = this.ReadChunkType(); chunkType = this.ReadChunkType();
uint alphaChunkSize = this.ReadChunkSize(); uint alphaChunkSize = this.ReadChunkSize();
// ALPH chunks will be skipped for now.
this.currentStream.Skip((int)alphaChunkSize); this.currentStream.Skip((int)alphaChunkSize);
} }

BIN
tests/Images/Input/WebP/lossless_iccp.webp

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

BIN
tests/Images/Input/WebP/lossy_iccp.webp

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Loading…
Cancel
Save