Browse Source

Introduce VP8 Profile which contains the reconstruction filter and the loop filter

pull/1552/head
Brian Popow 6 years ago
parent
commit
ef35d52da2
  1. 12
      src/ImageSharp/Formats/WebP/LoopFilter.cs
  2. 12
      src/ImageSharp/Formats/WebP/ReconstructionFilter.cs
  3. 21
      src/ImageSharp/Formats/WebP/Vp8Profile.cs
  4. 1
      src/ImageSharp/Formats/WebP/WebPDecoderCore.cs
  5. 4
      src/ImageSharp/Formats/WebP/WebPImageInfo.cs
  6. 29
      src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs

12
src/ImageSharp/Formats/WebP/LoopFilter.cs

@ -0,0 +1,12 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Formats.WebP
{
internal enum LoopFilter
{
Normal,
Simple,
None
}
}

12
src/ImageSharp/Formats/WebP/ReconstructionFilter.cs

@ -0,0 +1,12 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Formats.WebP
{
internal enum ReconstructionFilter
{
None,
Bicubic,
Bilinear
}
}

21
src/ImageSharp/Formats/WebP/Vp8Profile.cs

@ -0,0 +1,21 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Formats.WebP
{
/// <summary>
/// The version number setting enables or disables certain features in the bitstream.
/// </summary>
internal class Vp8Profile
{
/// <summary>
/// Gets or sets the reconstruction filter.
/// </summary>
public ReconstructionFilter ReconstructionFilter { get; set; }
/// <summary>
/// Gets or sets the loop filter.
/// </summary>
public LoopFilter LoopFilter { get; set; }
}
}

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

@ -343,6 +343,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
IsLossLess = false,
ImageDataSize = dataSize,
Features = features,
Vp8Profile = (sbyte)version
};
}

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

@ -36,9 +36,9 @@ namespace SixLabors.ImageSharp.Formats.WebP
public uint ImageDataSize { get; set; }
/// <summary>
/// Gets or sets the VP8 profile / version. Valid values are between 0 and 3.
/// Gets or sets the VP8 profile / version. Valid values are between 0 and 3. Default value will be the invalid value -1.
/// </summary>
public byte Vp8Profile { get; set; }
public int Vp8Profile { get; set; } = -1;
/// <summary>
/// Gets or sets Vp8L bitreader. Will be null if its not lossless image.

29
src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.IO;
using SixLabors.ImageSharp.Memory;
@ -16,7 +15,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
private readonly Stream currentStream;
private MemoryAllocator memoryAllocator;
private readonly MemoryAllocator memoryAllocator;
public WebPLossyDecoder(Configuration configuration, Stream currentStream)
{
@ -25,7 +24,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
this.memoryAllocator = configuration.MemoryAllocator;
}
public void Decode<TPixel>(Buffer2D<TPixel> pixels, int width, int height, uint imageDataSize, byte vp8Version)
public void Decode<TPixel>(Buffer2D<TPixel> pixels, int width, int height, uint imageDataSize, int vp8Version)
where TPixel : struct, IPixel<TPixel>
{
// we need buffers for Y U and V in size of the image
@ -37,40 +36,30 @@ namespace SixLabors.ImageSharp.Formats.WebP
// TODO residue signal from DCT: 4x4 blocks of DCT transforms, 16Y, 4U, 4V
var bitReader = new Vp8BitReader(this.currentStream, imageDataSize, this.memoryAllocator);
(ReconstructionFilter rec, LoopFilter loop) = this.DecodeVersion(vp8Version);
Vp8Profile vp8Profile = this.DecodeProfile(vp8Version);
}
private (ReconstructionFilter, LoopFilter) DecodeVersion(byte version)
private Vp8Profile DecodeProfile(int version)
{
var rec = ReconstructionFilter.None;
var loop = LoopFilter.None;
switch (version)
{
case 0:
return (ReconstructionFilter.Bicubic, LoopFilter.Normal);
return new Vp8Profile { ReconstructionFilter = ReconstructionFilter.Bicubic, LoopFilter = LoopFilter.Normal };
case 1:
return (ReconstructionFilter.Bilinear, LoopFilter.Simple);
return new Vp8Profile { ReconstructionFilter = ReconstructionFilter.Bilinear, LoopFilter = LoopFilter.Simple };
case 2:
return (ReconstructionFilter.Bilinear, LoopFilter.None);
return new Vp8Profile { ReconstructionFilter = ReconstructionFilter.Bilinear, LoopFilter = LoopFilter.None };
case 3:
return (ReconstructionFilter.None, LoopFilter.None);
return new Vp8Profile { ReconstructionFilter = ReconstructionFilter.None, LoopFilter = LoopFilter.None };
default:
// Reserved for future use in Spec.
// https://tools.ietf.org/html/rfc6386#page-30
WebPThrowHelper.ThrowNotSupportedException($"unsupported VP8 version {version} found");
return (rec, loop);
return new Vp8Profile();
}
}
}
enum ReconstructionFilter
{
None,
Bicubic,
Bilinear
}
enum LoopFilter
{
Normal,

Loading…
Cancel
Save