diff --git a/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs b/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs index aa5117159..5d03db558 100644 --- a/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs +++ b/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs @@ -47,6 +47,11 @@ namespace SixLabors.ImageSharp.Formats.WebP /// private ImageMetadata metadata; + /// + /// The webp specific metadata. + /// + private WebPMetadata webpMetadata; + /// /// Initializes a new instance of the class. /// @@ -120,9 +125,8 @@ namespace SixLabors.ImageSharp.Formats.WebP private WebPImageInfo ReadVp8Info() { - var metadata = new ImageMetadata(); - WebPMetadata webpMetadata = metadata.GetFormatMetadata(WebPFormat.Instance); this.metadata = new ImageMetadata(); + this.webpMetadata = metadata.GetFormatMetadata(WebPFormat.Instance); WebPChunkType chunkType = this.ReadChunkType(); @@ -189,6 +193,8 @@ namespace SixLabors.ImageSharp.Formats.WebP if (isAnimationPresent) { + this.webpMetadata.Animated = true; + // ANIM chunk will be followed by n ANMF chunks chunkType = this.ReadChunkType(); uint animationParameterChunkSize = this.ReadChunkSize(); @@ -230,6 +236,8 @@ namespace SixLabors.ImageSharp.Formats.WebP private WebPImageInfo ReadVp8Header() { + this.webpMetadata.Format = WebPFormatType.Lossy; + // VP8 data size. this.currentStream.Read(this.buffer, 0, 3); this.buffer[3] = 0; @@ -271,6 +279,8 @@ namespace SixLabors.ImageSharp.Formats.WebP private WebPImageInfo ReadVp8LHeader() { + this.webpMetadata.Format = WebPFormatType.Lossless; + // VP8 data size. uint dataSize = this.ReadChunkSize(); diff --git a/src/ImageSharp/Formats/WebP/WebPFormatType.cs b/src/ImageSharp/Formats/WebP/WebPFormatType.cs new file mode 100644 index 000000000..291281d00 --- /dev/null +++ b/src/ImageSharp/Formats/WebP/WebPFormatType.cs @@ -0,0 +1,26 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.ImageSharp.Formats.WebP +{ + /// + /// Info about the webp format used. + /// + public enum WebPFormatType + { + /// + /// Unknown webp format. + /// + Unknown, + + /// + /// The lossless webp format. + /// + Lossless, + + /// + /// The lossy webp format. + /// + Lossy, + } +} diff --git a/src/ImageSharp/Formats/WebP/WebPMetadata.cs b/src/ImageSharp/Formats/WebP/WebPMetadata.cs index 95f50fe27..88c687827 100644 --- a/src/ImageSharp/Formats/WebP/WebPMetadata.cs +++ b/src/ImageSharp/Formats/WebP/WebPMetadata.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; - namespace SixLabors.ImageSharp.Formats.WebP { /// @@ -10,7 +8,34 @@ namespace SixLabors.ImageSharp.Formats.WebP /// public class WebPMetadata : IDeepCloneable { + /// + /// Initializes a new instance of the class. + /// + public WebPMetadata() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The metadata to create an instance from. + private WebPMetadata(WebPMetadata other) + { + this.Animated = other.Animated; + this.Format = other.Format; + } + /// - public IDeepCloneable DeepClone() => throw new NotImplementedException(); + public IDeepCloneable DeepClone() => new WebPMetadata(this); + + /// + /// The webp format used. Either lossless or lossy. + /// + public WebPFormatType Format { get; set; } + + /// + /// Indicates, if the webp file contains a animation. + /// + public bool Animated { get; set; } = false; } }