Browse Source

Throwing not supported exception for animated images

pull/1552/head
Brian Popow 7 years ago
parent
commit
1de13422ed
  1. 23
      src/ImageSharp/Formats/WebP/WebPDecoderCore.cs
  2. 5
      src/ImageSharp/Formats/WebP/WebPImageInfo.cs
  3. 11
      src/ImageSharp/Formats/WebP/WebPThrowHelper.cs

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

@ -73,6 +73,10 @@ namespace SixLabors.ImageSharp.Formats.WebP
uint fileSize = this.ReadImageHeader();
WebPImageInfo imageInfo = this.ReadVp8Info();
if (imageInfo.IsAnimation)
{
WebPThrowHelper.ThrowNotSupportedException("Animations are not supported");
}
var image = new Image<TPixel>(this.configuration, imageInfo.Width, imageInfo.Height, this.metadata);
Buffer2D<TPixel> pixels = image.GetRootFramePixelBuffer();
@ -195,19 +199,12 @@ namespace SixLabors.ImageSharp.Formats.WebP
{
this.webpMetadata.Animated = true;
// ANIM chunk will be followed by n ANMF chunks
chunkType = this.ReadChunkType();
uint animationParameterChunkSize = this.ReadChunkSize();
this.currentStream.Skip((int)animationParameterChunkSize);
chunkType = this.ReadChunkType();
// TODO: not sure yet how to determine how many animation chunks there will be.
while (chunkType == WebPChunkType.Animation)
{
uint animationChunkSize = this.ReadChunkSize();
this.currentStream.Skip((int)animationChunkSize);
chunkType = this.ReadChunkType();
}
return new WebPImageInfo()
{
Width = width,
Height = height,
IsAnimation = true
};
}
if (isAlphaPresent)

5
src/ImageSharp/Formats/WebP/WebPImageInfo.cs

@ -20,6 +20,11 @@ namespace SixLabors.ImageSharp.Formats.WebP
/// </summary>
public bool IsLossLess { get; set; }
/// <summary>
/// Gets or sets whether this image is a animation.
/// </summary>
public bool IsAnimation { get; set; }
/// <summary>
/// The bytes of the image payload.
/// </summary>

11
src/ImageSharp/Formats/WebP/WebPThrowHelper.cs

@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Formats.WebP
@ -16,5 +17,15 @@ namespace SixLabors.ImageSharp.Formats.WebP
{
throw new ImageFormatException(errorMessage);
}
/// <summary>
/// Cold path optimization for throwing <see cref="NotSupportedException"/>-s
/// </summary>
/// <param name="errorMessage">The error message for the exception.</param>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowNotSupportedException(string errorMessage)
{
throw new NotSupportedException(errorMessage);
}
}
}

Loading…
Cancel
Save