Browse Source

Throwing not supported exception for animated images

pull/1147/head
Brian Popow 7 years ago
parent
commit
9ea185e5fc
  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(); uint fileSize = this.ReadImageHeader();
WebPImageInfo imageInfo = this.ReadVp8Info(); 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); var image = new Image<TPixel>(this.configuration, imageInfo.Width, imageInfo.Height, this.metadata);
Buffer2D<TPixel> pixels = image.GetRootFramePixelBuffer(); Buffer2D<TPixel> pixels = image.GetRootFramePixelBuffer();
@ -195,19 +199,12 @@ namespace SixLabors.ImageSharp.Formats.WebP
{ {
this.webpMetadata.Animated = true; this.webpMetadata.Animated = true;
// ANIM chunk will be followed by n ANMF chunks return new WebPImageInfo()
chunkType = this.ReadChunkType(); {
uint animationParameterChunkSize = this.ReadChunkSize(); Width = width,
this.currentStream.Skip((int)animationParameterChunkSize); Height = height,
chunkType = this.ReadChunkType(); IsAnimation = true
};
// 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();
}
} }
if (isAlphaPresent) if (isAlphaPresent)

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

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

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

@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Formats.WebP namespace SixLabors.ImageSharp.Formats.WebP
@ -16,5 +17,15 @@ namespace SixLabors.ImageSharp.Formats.WebP
{ {
throw new ImageFormatException(errorMessage); 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