Browse Source

Add parsing of ICCP chunk

pull/1552/head
Brian Popow 6 years ago
parent
commit
ee00861062
  1. 18
      src/ImageSharp/Formats/WebP/WebPDecoderCore.cs
  2. 3
      tests/Images/Input/WebP/lossless_iccp.webp
  3. 3
      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.Metadata;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.Metadata.Profiles.Icc;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Memory;
@ -208,13 +209,22 @@ namespace SixLabors.ImageSharp.Formats.WebP
this.buffer[3] = 0;
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;
if (isIccPresent)
{
chunkType = this.ReadChunkType();
uint iccpChunkSize = this.ReadChunkSize();
this.currentStream.Skip((int)iccpChunkSize);
if (chunkType is WebPChunkType.Iccp)
{
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)
@ -236,6 +246,8 @@ namespace SixLabors.ImageSharp.Formats.WebP
{
chunkType = this.ReadChunkType();
uint alphaChunkSize = this.ReadChunkSize();
// ALPH chunks will be skipped for now.
this.currentStream.Skip((int)alphaChunkSize);
}

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

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:312aea5ac9557bdfa78ec95bab5c3446a97c980317f46c96a20a4b7837d0ae37
size 68355

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

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:46e70fecb9cfc72243dfad58b68baa58c14f12660f8d2c88c30d5e050856b059
size 25241
Loading…
Cancel
Save