From d7689c1727436b0589299ca19bdf28b42d4f37d1 Mon Sep 17 00:00:00 2001 From: Peter Amrehn Date: Mon, 28 Oct 2019 19:37:34 +0100 Subject: [PATCH] Decode verison of lossy bitstream to determine Reconstruction- and Loopfilters --- .../Formats/WebP/WebPLossyDecoder.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs b/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs index 294737a885..f09be2faff 100644 --- a/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs +++ b/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs @@ -53,10 +53,47 @@ namespace SixLabors.ImageSharp.Formats.WebP } byte version = (byte)((bitReader.ReadBit() ? 2 : 0) | (bitReader.ReadBit() ? 1 : 0)); + (ReconstructionFilter rec, LoopFilter loop) = DecodeVersion(version); + bool isShowFrame = bitReader.ReadBit(); uint firstPartitionSize = (bitReader.Read(16) << 3) | bitReader.Read(3); } + + private (ReconstructionFilter, LoopFilter) DecodeVersion(byte version) + { + var rec = ReconstructionFilter.None; + var loop = LoopFilter.None; + + switch (version) + { + case 0: + return (ReconstructionFilter.Bicubic, LoopFilter.Normal); + case 1: + return (ReconstructionFilter.Bilinear, LoopFilter.Simple); + case 2: + return (ReconstructionFilter.Bilinear, LoopFilter.None); + case 3: + return (ReconstructionFilter.None, LoopFilter.None); + default: + // https://tools.ietf.org/html/rfc6386#page-30 + throw new NotSupportedException("reserved for future use in Spec"); + } + } + } + + enum ReconstructionFilter + { + None, + Bicubic, + Bilinear + } + + enum LoopFilter + { + Normal, + Simple, + None } struct YUVPixel