Browse Source

Add to the metadata, if the image is lossy or lossless and also if a animation is present

pull/1552/head
Brian Popow 6 years ago
parent
commit
857002ae81
  1. 14
      src/ImageSharp/Formats/WebP/WebPDecoderCore.cs
  2. 26
      src/ImageSharp/Formats/WebP/WebPFormatType.cs
  3. 31
      src/ImageSharp/Formats/WebP/WebPMetadata.cs

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

@ -47,6 +47,11 @@ namespace SixLabors.ImageSharp.Formats.WebP
/// </summary>
private ImageMetadata metadata;
/// <summary>
/// The webp specific metadata.
/// </summary>
private WebPMetadata webpMetadata;
/// <summary>
/// Initializes a new instance of the <see cref="WebPDecoderCore"/> class.
/// </summary>
@ -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();

26
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
{
/// <summary>
/// Info about the webp format used.
/// </summary>
public enum WebPFormatType
{
/// <summary>
/// Unknown webp format.
/// </summary>
Unknown,
/// <summary>
/// The lossless webp format.
/// </summary>
Lossless,
/// <summary>
/// The lossy webp format.
/// </summary>
Lossy,
}
}

31
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
{
/// <summary>
@ -10,7 +8,34 @@ namespace SixLabors.ImageSharp.Formats.WebP
/// </summary>
public class WebPMetadata : IDeepCloneable
{
/// <summary>
/// Initializes a new instance of the <see cref="WebPMetadata"/> class.
/// </summary>
public WebPMetadata()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="WebPMetadata"/> class.
/// </summary>
/// <param name="other">The metadata to create an instance from.</param>
private WebPMetadata(WebPMetadata other)
{
this.Animated = other.Animated;
this.Format = other.Format;
}
/// <inheritdoc/>
public IDeepCloneable DeepClone() => throw new NotImplementedException();
public IDeepCloneable DeepClone() => new WebPMetadata(this);
/// <summary>
/// The webp format used. Either lossless or lossy.
/// </summary>
public WebPFormatType Format { get; set; }
/// <summary>
/// Indicates, if the webp file contains a animation.
/// </summary>
public bool Animated { get; set; } = false;
}
}

Loading…
Cancel
Save