From d74463d5a616b864fe69be7dff659d969bc32762 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 6 Dec 2020 17:40:50 +0100 Subject: [PATCH] Rename WebP to Webp --- src/ImageSharp/Advanced/AotCompilerTools.cs | 2 +- .../Formats/ImageExtensions.Save.cs | 52 ++-- .../Formats/ImageExtensions.Save.tt | 8 +- .../Formats/WebP/AlphaCompressionMethod.cs | 2 +- src/ImageSharp/Formats/WebP/AlphaDecoder.cs | 38 +-- .../Formats/WebP/BitReader/BitReaderBase.cs | 2 +- .../Formats/WebP/BitReader/Vp8BitReader.cs | 4 +- .../Formats/WebP/BitReader/Vp8LBitReader.cs | 2 +- .../Formats/WebP/BitWriter/BitWriterBase.cs | 6 +- .../Formats/WebP/BitWriter/Vp8BitWriter.cs | 58 ++--- .../Formats/WebP/BitWriter/Vp8LBitWriter.cs | 10 +- src/ImageSharp/Formats/WebP/EntropyIx.cs | 2 +- src/ImageSharp/Formats/WebP/HistoIx.cs | 2 +- .../Formats/WebP/IWebPDecoderOptions.cs | 4 +- .../Formats/WebP/IWebPEncoderOptions.cs | 2 +- .../Formats/WebP/ImageExtensions.cs | 36 --- .../WebP/Lossless/BackwardReferenceEncoder.cs | 16 +- .../Formats/WebP/Lossless/ColorCache.cs | 2 +- .../WebP/Lossless/CostCacheInterval.cs | 2 +- .../Formats/WebP/Lossless/CostInterval.cs | 2 +- .../Formats/WebP/Lossless/CostManager.cs | 2 +- .../Formats/WebP/Lossless/CostModel.cs | 8 +- .../Formats/WebP/Lossless/CrunchConfig.cs | 2 +- .../Formats/WebP/Lossless/CrunchSubConfig.cs | 2 +- .../WebP/Lossless/DominantCostRange.cs | 2 +- .../Formats/WebP/Lossless/HTreeGroup.cs | 6 +- .../Formats/WebP/Lossless/HistogramBinInfo.cs | 2 +- .../Formats/WebP/Lossless/HistogramEncoder.cs | 2 +- .../Formats/WebP/Lossless/HistogramPair.cs | 2 +- .../Formats/WebP/Lossless/HuffIndex.cs | 2 +- .../Formats/WebP/Lossless/HuffmanCode.cs | 2 +- .../Formats/WebP/Lossless/HuffmanTree.cs | 2 +- .../Formats/WebP/Lossless/HuffmanTreeCode.cs | 2 +- .../Formats/WebP/Lossless/HuffmanTreeToken.cs | 2 +- .../Formats/WebP/Lossless/HuffmanUtils.cs | 26 +- .../Formats/WebP/Lossless/LosslessUtils.cs | 26 +- .../Formats/WebP/Lossless/PixOrCopy.cs | 2 +- .../Formats/WebP/Lossless/PixOrCopyMode.cs | 2 +- .../Formats/WebP/Lossless/PredictorEncoder.cs | 10 +- .../Formats/WebP/Lossless/Vp8LBackwardRefs.cs | 2 +- .../Formats/WebP/Lossless/Vp8LBitEntropy.cs | 2 +- .../Formats/WebP/Lossless/Vp8LDecoder.cs | 2 +- .../Formats/WebP/Lossless/Vp8LEncoder.cs | 66 +++--- .../Formats/WebP/Lossless/Vp8LHashChain.cs | 2 +- .../Formats/WebP/Lossless/Vp8LHistogram.cs | 68 +++--- .../Formats/WebP/Lossless/Vp8LLz77Type.cs | 2 +- .../Formats/WebP/Lossless/Vp8LMetadata.cs | 2 +- .../Formats/WebP/Lossless/Vp8LMultipliers.cs | 2 +- .../Formats/WebP/Lossless/Vp8LStreaks.cs | 4 +- .../Formats/WebP/Lossless/Vp8LTransform.cs | 2 +- .../WebP/Lossless/Vp8LTransformType.cs | 2 +- .../WebP/Lossless/WebPLosslessDecoder.cs | 76 +++--- .../Formats/WebP/Lossy/IntraPredictionMode.cs | 2 +- .../Formats/WebP/Lossy/LoopFilter.cs | 2 +- .../Formats/WebP/Lossy/LossyUtils.cs | 222 +++++++++--------- .../Formats/WebP/Lossy/PassStats.cs | 2 +- src/ImageSharp/Formats/WebP/Lossy/QuantEnc.cs | 4 +- .../Formats/WebP/Lossy/VP8BandProbas.cs | 6 +- .../Formats/WebP/Lossy/Vp8CostArray.cs | 4 +- .../Formats/WebP/Lossy/Vp8Decoder.cs | 18 +- .../Formats/WebP/Lossy/Vp8EncIterator.cs | 40 ++-- .../Formats/WebP/Lossy/Vp8EncProba.cs | 60 ++--- .../Formats/WebP/Lossy/Vp8EncSegmentHeader.cs | 2 +- .../Formats/WebP/Lossy/Vp8Encoder.cs | 78 +++--- .../Formats/WebP/Lossy/Vp8Encoding.cs | 38 +-- .../Formats/WebP/Lossy/Vp8FilterHeader.cs | 2 +- .../Formats/WebP/Lossy/Vp8FilterInfo.cs | 2 +- .../Formats/WebP/Lossy/Vp8FrameHeader.cs | 2 +- src/ImageSharp/Formats/WebP/Lossy/Vp8Io.cs | 2 +- .../Formats/WebP/Lossy/Vp8MacroBlock.cs | 2 +- .../Formats/WebP/Lossy/Vp8MacroBlockData.cs | 2 +- .../Formats/WebP/Lossy/Vp8MacroBlockInfo.cs | 2 +- .../Formats/WebP/Lossy/Vp8MacroBlockType.cs | 2 +- .../Formats/WebP/Lossy/Vp8Matrix.cs | 8 +- .../Formats/WebP/Lossy/Vp8ModeScore.cs | 2 +- .../Formats/WebP/Lossy/Vp8PictureHeader.cs | 2 +- src/ImageSharp/Formats/WebP/Lossy/Vp8Proba.cs | 12 +- .../Formats/WebP/Lossy/Vp8ProbaArray.cs | 4 +- .../Formats/WebP/Lossy/Vp8QuantMatrix.cs | 2 +- .../Formats/WebP/Lossy/Vp8RDLevel.cs | 2 +- .../Formats/WebP/Lossy/Vp8Residual.cs | 12 +- .../Formats/WebP/Lossy/Vp8SegmentHeader.cs | 2 +- .../Formats/WebP/Lossy/Vp8SegmentInfo.cs | 2 +- src/ImageSharp/Formats/WebP/Lossy/Vp8Stats.cs | 6 +- .../Formats/WebP/Lossy/Vp8StatsArray.cs | 4 +- .../Formats/WebP/Lossy/Vp8TopSamples.cs | 2 +- .../Formats/WebP/Lossy/WebPLossyDecoder.cs | 118 +++++----- .../Formats/WebP/Lossy/YuvConversion.cs | 18 +- .../Formats/WebP/MetadataExtensions.cs | 6 +- src/ImageSharp/Formats/WebP/Vp8HeaderType.cs | 2 +- .../Formats/WebP/WebPAlphaFilterType.cs | 4 +- .../Formats/WebP/WebPBitsPerPixel.cs | 4 +- src/ImageSharp/Formats/WebP/WebPChunkType.cs | 4 +- .../Formats/WebP/WebPCommonUtils.cs | 6 +- src/ImageSharp/Formats/WebP/WebPConstants.cs | 4 +- src/ImageSharp/Formats/WebP/WebPDecoder.cs | 12 +- .../Formats/WebP/WebPDecoderCore.cs | 128 +++++----- src/ImageSharp/Formats/WebP/WebPEncoder.cs | 8 +- .../Formats/WebP/WebPEncoderCore.cs | 12 +- src/ImageSharp/Formats/WebP/WebPFeatures.cs | 4 +- src/ImageSharp/Formats/WebP/WebPFormat.cs | 14 +- src/ImageSharp/Formats/WebP/WebPFormatType.cs | 4 +- .../Formats/WebP/WebPImageFormatDetector.cs | 10 +- src/ImageSharp/Formats/WebP/WebPImageInfo.cs | 12 +- .../Formats/WebP/WebPLookupTables.cs | 40 ++-- src/ImageSharp/Formats/WebP/WebPMetadata.cs | 18 +- .../Formats/WebP/WebPThrowHelper.cs | 4 +- .../Formats/WebP/WebpConfigurationModule.cs | 10 +- .../Codecs/DecodeWebp.cs | 4 +- .../Codecs/EncodeWebp.cs | 6 +- .../Formats/ImageFormatManagerTests.cs | 2 +- .../Formats/WebP/ImageExtensionsTest.cs | 26 +- .../Formats/WebP/WebPDecoderTests.cs | 16 +- .../Formats/WebP/WebPEncoderTests.cs | 14 +- .../Formats/WebP/WebPMetaDataTests.cs | 10 +- .../TestUtilities/TestEnvironment.Formats.cs | 4 +- .../Tests/TestEnvironmentTests.cs | 10 +- 117 files changed, 820 insertions(+), 856 deletions(-) delete mode 100644 src/ImageSharp/Formats/WebP/ImageExtensions.cs diff --git a/src/ImageSharp/Advanced/AotCompilerTools.cs b/src/ImageSharp/Advanced/AotCompilerTools.cs index bdc60698c..22f107c78 100644 --- a/src/ImageSharp/Advanced/AotCompilerTools.cs +++ b/src/ImageSharp/Advanced/AotCompilerTools.cs @@ -95,7 +95,7 @@ namespace SixLabors.ImageSharp.Advanced AotCodec(new Formats.Gif.GifDecoder(), new Formats.Gif.GifEncoder()); AotCodec(new Formats.Jpeg.JpegDecoder(), new Formats.Jpeg.JpegEncoder()); AotCodec(new Formats.Tga.TgaDecoder(), new Formats.Tga.TgaEncoder()); - AotCodec(new Formats.Experimental.WebP.WebPDecoder(), new Formats.Experimental.WebP.WebPEncoder()); + AotCodec(new Formats.Experimental.Webp.WebpDecoder(), new Formats.Experimental.Webp.WebpEncoder()); // TODO: Do the discovery work to figure out what works and what doesn't. } diff --git a/src/ImageSharp/Formats/ImageExtensions.Save.cs b/src/ImageSharp/Formats/ImageExtensions.Save.cs index f7900ec73..94f058524 100644 --- a/src/ImageSharp/Formats/ImageExtensions.Save.cs +++ b/src/ImageSharp/Formats/ImageExtensions.Save.cs @@ -7,7 +7,7 @@ using System.Threading; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; // using SixLabors.ImageSharp.Formats.Experimental.Tiff; -using SixLabors.ImageSharp.Formats.Experimental.WebP; +using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.Formats.Bmp; using SixLabors.ImageSharp.Formats.Gif; @@ -538,47 +538,47 @@ namespace SixLabors.ImageSharp cancellationToken); /// - /// EXPERIMENTAL! Saves the image to the given stream with the WebP format. + /// EXPERIMENTAL! Saves the image to the given stream with the Webp format. /// /// The image this method extends. /// The file path to save the image to. /// Thrown if the path is null. - public static void SaveAsWebP(this Image source, string path) => SaveAsWebP(source, path, null); + public static void SaveAsWebp(this Image source, string path) => SaveAsWebp(source, path, null); /// - /// EXPERIMENTAL! Saves the image to the given stream with the WebP format. + /// EXPERIMENTAL! Saves the image to the given stream with the Webp format. /// /// The image this method extends. /// The file path to save the image to. /// Thrown if the path is null. /// A representing the asynchronous operation. - public static Task SaveAsWebPAsync(this Image source, string path) => SaveAsWebPAsync(source, path, null); + public static Task SaveAsWebpAsync(this Image source, string path) => SaveAsWebpAsync(source, path, null); /// - /// EXPERIMENTAL! Saves the image to the given stream with the WebP format. + /// EXPERIMENTAL! Saves the image to the given stream with the Webp format. /// /// The image this method extends. /// The file path to save the image to. /// The token to monitor for cancellation requests. /// Thrown if the path is null. /// A representing the asynchronous operation. - public static Task SaveAsWebPAsync(this Image source, string path, CancellationToken cancellationToken) - => SaveAsWebPAsync(source, path, null, cancellationToken); + public static Task SaveAsWebpAsync(this Image source, string path, CancellationToken cancellationToken) + => SaveAsWebpAsync(source, path, null, cancellationToken); /// - /// EXPERIMENTAL! Saves the image to the given stream with the WebP format. + /// EXPERIMENTAL! Saves the image to the given stream with the Webp format. /// /// The image this method extends. /// The file path to save the image to. /// The encoder to save the image with. /// Thrown if the path is null. - public static void SaveAsWebP(this Image source, string path, WebPEncoder encoder) => + public static void SaveAsWebp(this Image source, string path, WebpEncoder encoder) => source.Save( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(WebPFormat.Instance)); + encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(WebpFormat.Instance)); /// - /// EXPERIMENTAL! Saves the image to the given stream with the WebP format. + /// EXPERIMENTAL! Saves the image to the given stream with the Webp format. /// /// The image this method extends. /// The file path to save the image to. @@ -586,47 +586,47 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the path is null. /// A representing the asynchronous operation. - public static Task SaveAsWebPAsync(this Image source, string path, WebPEncoder encoder, CancellationToken cancellationToken = default) => + public static Task SaveAsWebpAsync(this Image source, string path, WebpEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(WebPFormat.Instance), + encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(WebpFormat.Instance), cancellationToken); /// - /// EXPERIMENTAL! Saves the image to the given stream with the WebP format. + /// EXPERIMENTAL! Saves the image to the given stream with the Webp format. /// /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. - public static void SaveAsWebP(this Image source, Stream stream) - => SaveAsWebP(source, stream, null); + public static void SaveAsWebp(this Image source, Stream stream) + => SaveAsWebp(source, stream, null); /// - /// EXPERIMENTAL! Saves the image to the given stream with the WebP format. + /// EXPERIMENTAL! Saves the image to the given stream with the Webp format. /// /// The image this method extends. /// The stream to save the image to. /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAsWebPAsync(this Image source, Stream stream, CancellationToken cancellationToken = default) - => SaveAsWebPAsync(source, stream, null, cancellationToken); + public static Task SaveAsWebpAsync(this Image source, Stream stream, CancellationToken cancellationToken = default) + => SaveAsWebpAsync(source, stream, null, cancellationToken); /// - /// EXPERIMENTAL! Saves the image to the given stream with the WebP format. + /// EXPERIMENTAL! Saves the image to the given stream with the Webp format. /// /// The image this method extends. /// The stream to save the image to. /// The encoder to save the image with. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static void SaveAsWebP(this Image source, Stream stream, WebPEncoder encoder) + public static void SaveAsWebp(this Image source, Stream stream, WebpEncoder encoder) => source.Save( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(WebPFormat.Instance)); + encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(WebpFormat.Instance)); /// - /// EXPERIMENTAL! Saves the image to the given stream with the WebP format. + /// EXPERIMENTAL! Saves the image to the given stream with the Webp format. /// /// The image this method extends. /// The stream to save the image to. @@ -634,10 +634,10 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAsWebPAsync(this Image source, Stream stream, WebPEncoder encoder, CancellationToken cancellationToken = default) => + public static Task SaveAsWebpAsync(this Image source, Stream stream, WebpEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(WebPFormat.Instance), + encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(WebpFormat.Instance), cancellationToken); } diff --git a/src/ImageSharp/Formats/ImageExtensions.Save.tt b/src/ImageSharp/Formats/ImageExtensions.Save.tt index c8979da0d..a9102cb29 100644 --- a/src/ImageSharp/Formats/ImageExtensions.Save.tt +++ b/src/ImageSharp/Formats/ImageExtensions.Save.tt @@ -10,7 +10,7 @@ using System.Threading; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; // using SixLabors.ImageSharp.Formats.Experimental.Tiff; -using SixLabors.ImageSharp.Formats.Experimental.WebP; +using SixLabors.ImageSharp.Formats.Experimental.Webp; <# var formats = new []{ @@ -19,12 +19,12 @@ using SixLabors.ImageSharp.Formats.Experimental.WebP; "Jpeg", "Png", "Tga", - "WebP" + "Webp" }; foreach (string fmt in formats) { - if (fmt == "Tiff" || fmt == "WebP") + if (fmt == "Tiff" || fmt == "Webp") { continue; } @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp <# foreach (string fmt in formats) { - string experimentalString = fmt == "Tiff" || fmt == "WebP" ? @"EXPERIMENTAL! " : ""; + string experimentalString = fmt == "Tiff" || fmt == "Webp" ? @"EXPERIMENTAL! " : ""; #> /// /// <#= experimentalString #>Saves the image to the given stream with the <#= fmt #> format. diff --git a/src/ImageSharp/Formats/WebP/AlphaCompressionMethod.cs b/src/ImageSharp/Formats/WebP/AlphaCompressionMethod.cs index cd66059a1..7b575adae 100644 --- a/src/ImageSharp/Formats/WebP/AlphaCompressionMethod.cs +++ b/src/ImageSharp/Formats/WebP/AlphaCompressionMethod.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { internal enum AlphaCompressionMethod { diff --git a/src/ImageSharp/Formats/WebP/AlphaDecoder.cs b/src/ImageSharp/Formats/WebP/AlphaDecoder.cs index 148a7ad94..041072fa3 100644 --- a/src/ImageSharp/Formats/WebP/AlphaDecoder.cs +++ b/src/ImageSharp/Formats/WebP/AlphaDecoder.cs @@ -6,11 +6,11 @@ using System.Buffers; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats.Experimental.WebP.BitReader; -using SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless; +using SixLabors.ImageSharp.Formats.Experimental.Webp.BitReader; +using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless; using SixLabors.ImageSharp.Memory; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Implements decoding for lossy alpha chunks which may be compressed. @@ -40,20 +40,20 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP var compression = (AlphaCompressionMethod)(alphaChunkHeader & 0x03); if (compression != AlphaCompressionMethod.NoCompression && compression != AlphaCompressionMethod.WebPLosslessCompression) { - WebPThrowHelper.ThrowImageFormatException($"unexpected alpha compression method {compression} found"); + WebpThrowHelper.ThrowImageFormatException($"unexpected alpha compression method {compression} found"); } this.Compressed = compression == AlphaCompressionMethod.WebPLosslessCompression; // The filtering method used. Only values between 0 and 3 are valid. int filter = (alphaChunkHeader >> 2) & 0x03; - if (filter < (int)WebPAlphaFilterType.None || filter > (int)WebPAlphaFilterType.Gradient) + if (filter < (int)WebpAlphaFilterType.None || filter > (int)WebpAlphaFilterType.Gradient) { - WebPThrowHelper.ThrowImageFormatException($"unexpected alpha filter method {filter} found"); + WebpThrowHelper.ThrowImageFormatException($"unexpected alpha filter method {filter} found"); } this.Alpha = memoryAllocator.Allocate(totalPixels); - this.AlphaFilterType = (WebPAlphaFilterType)filter; + this.AlphaFilterType = (WebpAlphaFilterType)filter; this.Vp8LDec = new Vp8LDecoder(width, height, memoryAllocator); if (this.Compressed) @@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// /// Gets the used filter type. /// - public WebPAlphaFilterType AlphaFilterType { get; } + public WebpAlphaFilterType AlphaFilterType { get; } /// /// Gets or sets the last decoded row. @@ -133,11 +133,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP var pixelCount = this.Width * this.Height; if (dataSpan.Length < pixelCount) { - WebPThrowHelper.ThrowImageFormatException("not enough data in the ALPH chunk"); + WebpThrowHelper.ThrowImageFormatException("not enough data in the ALPH chunk"); } Span alphaSpan = this.Alpha.Memory.Span; - if (this.AlphaFilterType == WebPAlphaFilterType.None) + if (this.AlphaFilterType == WebpAlphaFilterType.None) { dataSpan.Slice(0, pixelCount).CopyTo(alphaSpan); return; @@ -150,13 +150,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP { switch (this.AlphaFilterType) { - case WebPAlphaFilterType.Horizontal: + case WebpAlphaFilterType.Horizontal: HorizontalUnfilter(prev, deltas, dst, this.Width); break; - case WebPAlphaFilterType.Vertical: + case WebpAlphaFilterType.Vertical: VerticalUnfilter(prev, deltas, dst, this.Width); break; - case WebPAlphaFilterType.Gradient: + case WebpAlphaFilterType.Gradient: GradientUnfilter(prev, deltas, dst, this.Width); break; } @@ -189,7 +189,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// The stride to use. public void AlphaApplyFilter(int firstRow, int lastRow, Span dst, int stride) { - if (this.AlphaFilterType == WebPAlphaFilterType.None) + if (this.AlphaFilterType == WebpAlphaFilterType.None) { return; } @@ -200,13 +200,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP { switch (this.AlphaFilterType) { - case WebPAlphaFilterType.Horizontal: + case WebpAlphaFilterType.Horizontal: HorizontalUnfilter(prev, dst, dst, this.Width); break; - case WebPAlphaFilterType.Vertical: + case WebpAlphaFilterType.Vertical: VerticalUnfilter(prev, dst, dst, this.Width); break; - case WebPAlphaFilterType.Gradient: + case WebpAlphaFilterType.Gradient: GradientUnfilter(prev, dst, dst, this.Width); break; } @@ -222,7 +222,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP { // For vertical and gradient filtering, we need to decode the part above the // cropTop row, in order to have the correct spatial predictors. - int topRow = (this.AlphaFilterType == WebPAlphaFilterType.None || this.AlphaFilterType == WebPAlphaFilterType.Horizontal) ? 0 : this.LastRow; + int topRow = (this.AlphaFilterType == WebpAlphaFilterType.None || this.AlphaFilterType == WebpAlphaFilterType.Horizontal) ? 0 : this.LastRow; int firstRow = (this.LastRow < topRow) ? topRow : this.LastRow; if (lastRow > firstRow) { @@ -235,7 +235,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP if (this.Vp8LDec.Transforms.Count == 0 || this.Vp8LDec.Transforms[0].TransformType != Vp8LTransformType.ColorIndexingTransform) { - WebPThrowHelper.ThrowImageFormatException("error while decoding alpha channel, expected color index transform data is missing"); + WebpThrowHelper.ThrowImageFormatException("error while decoding alpha channel, expected color index transform data is missing"); } Vp8LTransform transform = this.Vp8LDec.Transforms[0]; diff --git a/src/ImageSharp/Formats/WebP/BitReader/BitReaderBase.cs b/src/ImageSharp/Formats/WebP/BitReader/BitReaderBase.cs index 60ed96ab3..2c1892532 100644 --- a/src/ImageSharp/Formats/WebP/BitReader/BitReaderBase.cs +++ b/src/ImageSharp/Formats/WebP/BitReader/BitReaderBase.cs @@ -7,7 +7,7 @@ using System.IO; using SixLabors.ImageSharp.Memory; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitReader +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.BitReader { /// /// Base class for VP8 and VP8L bitreader. diff --git a/src/ImageSharp/Formats/WebP/BitReader/Vp8BitReader.cs b/src/ImageSharp/Formats/WebP/BitReader/Vp8BitReader.cs index 80208918d..5cc12259a 100644 --- a/src/ImageSharp/Formats/WebP/BitReader/Vp8BitReader.cs +++ b/src/ImageSharp/Formats/WebP/BitReader/Vp8BitReader.cs @@ -7,7 +7,7 @@ using System.IO; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Memory; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitReader +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.BitReader { /// /// A bit reader for VP8 streams. @@ -114,7 +114,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitReader range = split + 1; } - int shift = 7 ^ WebPCommonUtils.BitsLog2Floor(range); + int shift = 7 ^ WebpCommonUtils.BitsLog2Floor(range); range <<= shift; this.bits -= shift; diff --git a/src/ImageSharp/Formats/WebP/BitReader/Vp8LBitReader.cs b/src/ImageSharp/Formats/WebP/BitReader/Vp8LBitReader.cs index 9d8ccc810..61d00323e 100644 --- a/src/ImageSharp/Formats/WebP/BitReader/Vp8LBitReader.cs +++ b/src/ImageSharp/Formats/WebP/BitReader/Vp8LBitReader.cs @@ -6,7 +6,7 @@ using System.IO; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Memory; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitReader +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.BitReader { /// /// A bit reader for reading lossless webp streams. diff --git a/src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs b/src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs index 12dca20ec..f12bacd87 100644 --- a/src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs +++ b/src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs @@ -5,7 +5,7 @@ using System; using System.Buffers.Binary; using System.IO; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.BitWriter { internal abstract class BitWriterBase { @@ -98,10 +98,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter { Span buffer = stackalloc byte[4]; - stream.Write(WebPConstants.RiffFourCc); + stream.Write(WebpConstants.RiffFourCc); BinaryPrimitives.WriteUInt32LittleEndian(buffer, riffSize); stream.Write(buffer); - stream.Write(WebPConstants.WebPHeader); + stream.Write(WebpConstants.WebPHeader); } } } diff --git a/src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs b/src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs index 339e71894..e1483ce30 100644 --- a/src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs +++ b/src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs @@ -4,9 +4,9 @@ using System; using System.Buffers.Binary; using System.IO; -using SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy; +using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.BitWriter { /// /// A bit writer for writing lossy webp streams. @@ -100,13 +100,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter int v = sign ? -c : c; if (!this.PutBit(v != 0, p.Probabilities[1])) { - p = residual.Prob[WebPConstants.Vp8EncBands[n]].Probabilities[0]; + p = residual.Prob[WebpConstants.Vp8EncBands[n]].Probabilities[0]; continue; } if (!this.PutBit(v > 1, p.Probabilities[2])) { - p = residual.Prob[WebPConstants.Vp8EncBands[n]].Probabilities[1]; + p = residual.Prob[WebpConstants.Vp8EncBands[n]].Probabilities[1]; } else { @@ -140,7 +140,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter this.PutBit(0, p.Probabilities[9]); v -= 3 + (8 << 0); mask = 1 << 2; - tab = WebPConstants.Cat3; + tab = WebpConstants.Cat3; } else if (v < 3 + (8 << 2)) { @@ -149,7 +149,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter this.PutBit(1, p.Probabilities[9]); v -= 3 + (8 << 1); mask = 1 << 3; - tab = WebPConstants.Cat4; + tab = WebpConstants.Cat4; } else if (v < 3 + (8 << 3)) { @@ -158,7 +158,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter this.PutBit(0, p.Probabilities[10]); v -= 3 + (8 << 2); mask = 1 << 4; - tab = WebPConstants.Cat5; + tab = WebpConstants.Cat5; } else { @@ -167,7 +167,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter this.PutBit(1, p.Probabilities[10]); v -= 3 + (8 << 3); mask = 1 << 10; - tab = WebPConstants.Cat6; + tab = WebpConstants.Cat6; } var tabIdx = 0; @@ -178,7 +178,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter } } - p = residual.Prob[WebPConstants.Vp8EncBands[n]].Probabilities[2]; + p = residual.Prob[WebpConstants.Vp8EncBands[n]].Probabilities[2]; } this.PutBitUniform(sign ? 1 : 0); @@ -311,8 +311,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter if (this.range < 127) { // emit 'shift' bits out and renormalize. - int shift = WebPLookupTables.Norm[this.range]; - this.range = WebPLookupTables.NewRange[this.range]; + int shift = WebpLookupTables.Norm[this.range]; + this.range = WebpLookupTables.NewRange[this.range]; this.value <<= shift; this.nbBits += shift; if (this.nbBits > 0) @@ -339,7 +339,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter if (this.range < 127) { - this.range = WebPLookupTables.NewRange[this.range]; + this.range = WebpLookupTables.NewRange[this.range]; this.value <<= 1; this.nbBits += 1; if (this.nbBits > 0) @@ -420,14 +420,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter // Partition #0 with header and partition sizes uint size0 = this.GeneratePartition0(bitWriterPartZero); - uint vp8Size = WebPConstants.Vp8FrameHeaderSize + size0; + uint vp8Size = WebpConstants.Vp8FrameHeaderSize + size0; vp8Size += numBytes; uint pad = vp8Size & 1; vp8Size += pad; // Compute RIFF size // At the minimum it is: "WEBPVP8 nnnn" + VP8 data size. - var riffSize = WebPConstants.TagSize + WebPConstants.ChunkHeaderSize + vp8Size; + var riffSize = WebpConstants.TagSize + WebpConstants.ChunkHeaderSize + vp8Size; // Emit headers and partition #0 this.WriteWebPHeaders(stream, size0, vp8Size, riffSize); @@ -474,12 +474,12 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter { // We always use absolute values, not relative ones. bitWriter.PutBitUniform(1); // (segment_feature_mode = 1. Paragraph 9.3.) - for (int s = 0; s < WebPConstants.NumMbSegments; ++s) + for (int s = 0; s < WebpConstants.NumMbSegments; ++s) { bitWriter.PutSignedBits(this.enc.SegmentInfos[s].Quant, 7); } - for (int s = 0; s < WebPConstants.NumMbSegments; ++s) + for (int s = 0; s < WebpConstants.NumMbSegments; ++s) { bitWriter.PutSignedBits(this.enc.SegmentInfos[s].FStrength, 6); } @@ -535,17 +535,17 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter private void WriteProbas(Vp8BitWriter bitWriter) { Vp8EncProba probas = this.enc.Proba; - for (int t = 0; t < WebPConstants.NumTypes; ++t) + for (int t = 0; t < WebpConstants.NumTypes; ++t) { - for (int b = 0; b < WebPConstants.NumBands; ++b) + for (int b = 0; b < WebpConstants.NumBands; ++b) { - for (int c = 0; c < WebPConstants.NumCtx; ++c) + for (int c = 0; c < WebpConstants.NumCtx; ++c) { - for (int p = 0; p < WebPConstants.NumProbas; ++p) + for (int p = 0; p < WebpConstants.NumProbas; ++p) { byte p0 = probas.Coeffs[t][b].Probabilities[c].Probabilities[p]; - bool update = p0 != WebPLookupTables.DefaultCoeffsProba[t, b, c, p]; - if (bitWriter.PutBit(update, WebPLookupTables.CoeffsUpdateProba[t, b, c, p])) + bool update = p0 != WebpLookupTables.DefaultCoeffsProba[t, b, c, p]; + if (bitWriter.PutBit(update, WebpLookupTables.CoeffsUpdateProba[t, b, c, p])) { bitWriter.PutBits(p0, 8); } @@ -594,7 +594,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter int left = it.Preds[predIdx - 1]; for (int x = 0; x < 4; ++x) { - byte[] probas = WebPLookupTables.ModesProba[topPred[x], left]; + byte[] probas = WebpLookupTables.ModesProba[topPred[x], left]; left = bitWriter.PutI4Mode(it.Preds[predIdx + x], probas); } @@ -617,9 +617,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter private void WriteVp8Header(Stream stream, uint size) { - Span vp8ChunkHeader = stackalloc byte[WebPConstants.ChunkHeaderSize]; + Span vp8ChunkHeader = stackalloc byte[WebpConstants.ChunkHeaderSize]; - WebPConstants.Vp8MagicBytes.AsSpan().CopyTo(vp8ChunkHeader); + WebpConstants.Vp8MagicBytes.AsSpan().CopyTo(vp8ChunkHeader); BinaryPrimitives.WriteUInt32LittleEndian(vp8ChunkHeader.Slice(4), size); stream.Write(vp8ChunkHeader); @@ -630,7 +630,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter uint profile = 0; int width = this.enc.Width; int height = this.enc.Height; - var vp8FrameHeader = new byte[WebPConstants.Vp8FrameHeaderSize]; + var vp8FrameHeader = new byte[WebpConstants.Vp8FrameHeaderSize]; // Paragraph 9.1. uint bits = 0 // keyframe (1b) @@ -643,9 +643,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter vp8FrameHeader[2] = (byte)((bits >> 16) & 0xff); // signature - vp8FrameHeader[3] = WebPConstants.Vp8HeaderMagicBytes[0]; - vp8FrameHeader[4] = WebPConstants.Vp8HeaderMagicBytes[1]; - vp8FrameHeader[5] = WebPConstants.Vp8HeaderMagicBytes[2]; + vp8FrameHeader[3] = WebpConstants.Vp8HeaderMagicBytes[0]; + vp8FrameHeader[4] = WebpConstants.Vp8HeaderMagicBytes[1]; + vp8FrameHeader[5] = WebpConstants.Vp8HeaderMagicBytes[2]; // dimensions vp8FrameHeader[6] = (byte)(width & 0xff); diff --git a/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs b/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs index 2e23c530e..4bf3d5f05 100644 --- a/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs +++ b/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs @@ -4,9 +4,9 @@ using System; using System.Buffers.Binary; using System.IO; -using SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless; +using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.BitWriter { /// /// A bit writer for writing lossless webp streams. @@ -143,14 +143,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter // Write RIFF header. uint pad = size & 1; - uint riffSize = WebPConstants.TagSize + WebPConstants.ChunkHeaderSize + size + pad; + uint riffSize = WebpConstants.TagSize + WebpConstants.ChunkHeaderSize + size + pad; this.WriteRiffHeader(stream, riffSize); - stream.Write(WebPConstants.Vp8LMagicBytes); + stream.Write(WebpConstants.Vp8LMagicBytes); // Write Vp8 Header. BinaryPrimitives.WriteUInt32LittleEndian(buffer, size); stream.Write(buffer); - stream.WriteByte(WebPConstants.Vp8LHeaderMagicByte); + stream.WriteByte(WebpConstants.Vp8LHeaderMagicByte); this.WriteToStream(stream); if (pad == 1) diff --git a/src/ImageSharp/Formats/WebP/EntropyIx.cs b/src/ImageSharp/Formats/WebP/EntropyIx.cs index 759717092..f9a70f919 100644 --- a/src/ImageSharp/Formats/WebP/EntropyIx.cs +++ b/src/ImageSharp/Formats/WebP/EntropyIx.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// These five modes are evaluated and their respective entropy is computed. diff --git a/src/ImageSharp/Formats/WebP/HistoIx.cs b/src/ImageSharp/Formats/WebP/HistoIx.cs index 24845b5a7..d766a84bf 100644 --- a/src/ImageSharp/Formats/WebP/HistoIx.cs +++ b/src/ImageSharp/Formats/WebP/HistoIx.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { internal enum HistoIx { diff --git a/src/ImageSharp/Formats/WebP/IWebPDecoderOptions.cs b/src/ImageSharp/Formats/WebP/IWebPDecoderOptions.cs index ac42e30de..81c875761 100644 --- a/src/ImageSharp/Formats/WebP/IWebPDecoderOptions.cs +++ b/src/ImageSharp/Formats/WebP/IWebPDecoderOptions.cs @@ -1,12 +1,12 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Image decoder options for generating an image out of a webp stream. /// - internal interface IWebPDecoderOptions + internal interface IWebpDecoderOptions { /// /// Gets a value indicating whether the metadata should be ignored when the image is being decoded. diff --git a/src/ImageSharp/Formats/WebP/IWebPEncoderOptions.cs b/src/ImageSharp/Formats/WebP/IWebPEncoderOptions.cs index 2922de34b..46f016a5f 100644 --- a/src/ImageSharp/Formats/WebP/IWebPEncoderOptions.cs +++ b/src/ImageSharp/Formats/WebP/IWebPEncoderOptions.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Configuration options for use during webp encoding. diff --git a/src/ImageSharp/Formats/WebP/ImageExtensions.cs b/src/ImageSharp/Formats/WebP/ImageExtensions.cs deleted file mode 100644 index 2531fcee7..000000000 --- a/src/ImageSharp/Formats/WebP/ImageExtensions.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System.IO; - -using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Formats.Experimental.WebP; - -namespace SixLabors.ImageSharp -{ - /// - /// Extension methods for the type. - /// - public static partial class ImageExtensions - { - /// - /// Saves the image to the given stream with the webp format. - /// - /// The image this method extends. - /// The stream to save the image to. - /// Thrown if the stream is null. - public static void SaveAsWebp(this Image source, Stream stream) => SaveAsWebp(source, stream, null); - - /// - /// Saves the image to the given stream with the webp format. - /// - /// The image this method extends. - /// The stream to save the image to. - /// The options for the encoder. - /// Thrown if the stream is null. - public static void SaveAsWebp(this Image source, Stream stream, WebPEncoder encoder) => - source.Save( - stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(WebPFormat.Instance)); - } -} diff --git a/src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs index b416a67a1..9b7e16389 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal class BackwardReferenceEncoder { @@ -129,9 +129,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless double entropyMin = MaxEntropy; int pos = 0; - var colorCache = new ColorCache[WebPConstants.MaxColorCacheBits + 1]; - var histos = new Vp8LHistogram[WebPConstants.MaxColorCacheBits + 1]; - for (int i = 0; i <= WebPConstants.MaxColorCacheBits; i++) + var colorCache = new ColorCache[WebpConstants.MaxColorCacheBits + 1]; + var histos = new Vp8LHistogram[WebpConstants.MaxColorCacheBits + 1]; + for (int i = 0; i <= WebpConstants.MaxColorCacheBits; i++) { histos[i] = new Vp8LHistogram(paletteCodeBits: i); colorCache[i] = new ColorCache(); @@ -166,7 +166,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { if (colorCache[i].Lookup(key) == pix) { - ++histos[i].Literal[WebPConstants.NumLiteralCodes + WebPConstants.NumLengthCodes + key]; + ++histos[i].Literal[WebpConstants.NumLiteralCodes + WebpConstants.NumLengthCodes + key]; } else { @@ -244,7 +244,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { int pixCount = xSize * ySize; bool useColorCache = cacheBits > 0; - var literalArraySize = WebPConstants.NumLiteralCodes + WebPConstants.NumLengthCodes + ((cacheBits > 0) ? (1 << cacheBits) : 0); + var literalArraySize = WebpConstants.NumLiteralCodes + WebpConstants.NumLengthCodes + ((cacheBits > 0) ? (1 << cacheBits) : 0); var costModel = new CostModel(literalArraySize); int offsetPrev = -1; int lenPrev = -1; @@ -824,11 +824,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless int xOffset = dist - (yOffset * xSize); if (xOffset <= 8 && yOffset < 8) { - return (int)WebPLookupTables.PlaneToCodeLut[(yOffset * 16) + 8 - xOffset] + 1; + return (int)WebpLookupTables.PlaneToCodeLut[(yOffset * 16) + 8 - xOffset] + 1; } else if (xOffset > xSize - 8 && yOffset < 7) { - return (int)WebPLookupTables.PlaneToCodeLut[((yOffset + 1) * 16) + 8 + (xSize - xOffset)] + 1; + return (int)WebpLookupTables.PlaneToCodeLut[((yOffset + 1) * 16) + 8 + (xSize - xOffset)] + 1; } return dist + 120; diff --git a/src/ImageSharp/Formats/WebP/Lossless/ColorCache.cs b/src/ImageSharp/Formats/WebP/Lossless/ColorCache.cs index 737901fb8..7fd12236e 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/ColorCache.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/ColorCache.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// A small hash-addressed array to store recently used colors, to be able to recall them with shorter codes. diff --git a/src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs b/src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs index dcd0fd203..c6febb82d 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs @@ -3,7 +3,7 @@ using System.Diagnostics; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// The GetLengthCost(costModel, k) are cached in a CostCacheInterval. diff --git a/src/ImageSharp/Formats/WebP/Lossless/CostInterval.cs b/src/ImageSharp/Formats/WebP/Lossless/CostInterval.cs index e7a16ffd7..2fce1651b 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/CostInterval.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/CostInterval.cs @@ -3,7 +3,7 @@ using System.Diagnostics; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// To perform backward reference every pixel at index index_ is considered and diff --git a/src/ImageSharp/Formats/WebP/Lossless/CostManager.cs b/src/ImageSharp/Formats/WebP/Lossless/CostManager.cs index f3669f31f..0cf6df2a7 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/CostManager.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/CostManager.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// The CostManager is in charge of managing intervals and costs. diff --git a/src/ImageSharp/Formats/WebP/Lossless/CostModel.cs b/src/ImageSharp/Formats/WebP/Lossless/CostModel.cs index f0cb2e1b2..8edbd0aca 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/CostModel.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/CostModel.cs @@ -3,7 +3,7 @@ using System; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal class CostModel { @@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless this.Alpha = new double[ValuesInBytes]; this.Red = new double[ValuesInBytes]; this.Blue = new double[ValuesInBytes]; - this.Distance = new double[WebPConstants.NumDistanceCodes]; + this.Distance = new double[WebpConstants.NumDistanceCodes]; this.Literal = new double[literalArraySize]; } @@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless ConvertPopulationCountTableToBitEstimates(ValuesInBytes, histogram.Red, this.Red); ConvertPopulationCountTableToBitEstimates(ValuesInBytes, histogram.Blue, this.Blue); ConvertPopulationCountTableToBitEstimates(ValuesInBytes, histogram.Alpha, this.Alpha); - ConvertPopulationCountTableToBitEstimates(WebPConstants.NumDistanceCodes, histogram.Distance, this.Distance); + ConvertPopulationCountTableToBitEstimates(WebpConstants.NumDistanceCodes, histogram.Distance, this.Distance); } public double GetLengthCost(int length) @@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless public double GetCacheCost(uint idx) { - int literalIdx = (int)(ValuesInBytes + WebPConstants.NumLengthCodes + idx); + int literalIdx = (int)(ValuesInBytes + WebpConstants.NumLengthCodes + idx); return this.Literal[literalIdx]; } diff --git a/src/ImageSharp/Formats/WebP/Lossless/CrunchConfig.cs b/src/ImageSharp/Formats/WebP/Lossless/CrunchConfig.cs index 9a3ed42ab..62ba42f9b 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/CrunchConfig.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/CrunchConfig.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal class CrunchConfig { diff --git a/src/ImageSharp/Formats/WebP/Lossless/CrunchSubConfig.cs b/src/ImageSharp/Formats/WebP/Lossless/CrunchSubConfig.cs index a4b0ad884..4dc59c0c6 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/CrunchSubConfig.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/CrunchSubConfig.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal class CrunchSubConfig { diff --git a/src/ImageSharp/Formats/WebP/Lossless/DominantCostRange.cs b/src/ImageSharp/Formats/WebP/Lossless/DominantCostRange.cs index 239b99095..1b4011108 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/DominantCostRange.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/DominantCostRange.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Data container to keep track of cost range for the three dominant entropy symbols. diff --git a/src/ImageSharp/Formats/WebP/Lossless/HTreeGroup.cs b/src/ImageSharp/Formats/WebP/Lossless/HTreeGroup.cs index 0e75b62ae..a25dbffb4 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HTreeGroup.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HTreeGroup.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Huffman table group. @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { public HTreeGroup(uint packedTableSize) { - this.HTrees = new List(WebPConstants.HuffmanCodesPerMetaCode); + this.HTrees = new List(WebpConstants.HuffmanCodesPerMetaCode); this.PackedTable = new HuffmanCode[packedTableSize]; for (int i = 0; i < packedTableSize; i++) { @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless } /// - /// Gets the Huffman trees. This has a maximum of (5) entry's. + /// Gets the Huffman trees. This has a maximum of (5) entry's. /// public List HTrees { get; } diff --git a/src/ImageSharp/Formats/WebP/Lossless/HistogramBinInfo.cs b/src/ImageSharp/Formats/WebP/Lossless/HistogramBinInfo.cs index c1e0bf414..5caee010e 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HistogramBinInfo.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HistogramBinInfo.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal struct HistogramBinInfo { diff --git a/src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs index 02e56451a..6b1fee5a6 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal class HistogramEncoder { diff --git a/src/ImageSharp/Formats/WebP/Lossless/HistogramPair.cs b/src/ImageSharp/Formats/WebP/Lossless/HistogramPair.cs index 912e47e78..0b4c20926 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HistogramPair.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HistogramPair.cs @@ -3,7 +3,7 @@ using System.Diagnostics; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Pair of histograms. Negative Idx1 value means that pair is out-of-date. diff --git a/src/ImageSharp/Formats/WebP/Lossless/HuffIndex.cs b/src/ImageSharp/Formats/WebP/Lossless/HuffIndex.cs index 9853935d0..4f43725f4 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HuffIndex.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HuffIndex.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Five Huffman codes are used at each meta code. diff --git a/src/ImageSharp/Formats/WebP/Lossless/HuffmanCode.cs b/src/ImageSharp/Formats/WebP/Lossless/HuffmanCode.cs index 97014c3bc..a7bd5f919 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HuffmanCode.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HuffmanCode.cs @@ -3,7 +3,7 @@ using System.Diagnostics; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// A classic way to do entropy coding where a smaller number of bits are used for more frequent codes. diff --git a/src/ImageSharp/Formats/WebP/Lossless/HuffmanTree.cs b/src/ImageSharp/Formats/WebP/Lossless/HuffmanTree.cs index 588260739..0a1f7d60f 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HuffmanTree.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HuffmanTree.cs @@ -3,7 +3,7 @@ using System.Diagnostics; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Represents the Huffman tree. diff --git a/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeCode.cs b/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeCode.cs index cfd7a4920..a3944a6d4 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeCode.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeCode.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Represents the tree codes (depth and bits array). diff --git a/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeToken.cs b/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeToken.cs index c889b5766..c0472c651 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeToken.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeToken.cs @@ -3,7 +3,7 @@ using System.Diagnostics; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Holds the tree header in coded form. diff --git a/src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs b/src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs index 4625a625b..1329802eb 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs @@ -3,7 +3,7 @@ using System; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Utility functions related to creating the huffman tables. @@ -312,14 +312,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless int totalSize = 1 << rootBits; // total size root table + 2nd level table. int len; // current code length. int symbol; // symbol index in original or sorted table. - var counts = new int[WebPConstants.MaxAllowedCodeLength + 1]; // number of codes of each length. - var offsets = new int[WebPConstants.MaxAllowedCodeLength + 1]; // offsets in sorted table for each length. + var counts = new int[WebpConstants.MaxAllowedCodeLength + 1]; // number of codes of each length. + var offsets = new int[WebpConstants.MaxAllowedCodeLength + 1]; // offsets in sorted table for each length. // Build histogram of code lengths. for (symbol = 0; symbol < codeLengthsSize; ++symbol) { var codeLengthOfSymbol = codeLengths[symbol]; - if (codeLengthOfSymbol > WebPConstants.MaxAllowedCodeLength) + if (codeLengthOfSymbol > WebpConstants.MaxAllowedCodeLength) { return 0; } @@ -335,7 +335,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless // Generate offsets into sorted symbol table by code length. offsets[1] = 0; - for (len = 1; len < WebPConstants.MaxAllowedCodeLength; ++len) + for (len = 1; len < WebpConstants.MaxAllowedCodeLength; ++len) { int codesOfLength = counts[len]; if (codesOfLength > (1 << len)) @@ -357,7 +357,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless } // Special case code with only one value. - if (offsets[WebPConstants.MaxAllowedCodeLength] == 1) + if (offsets[WebpConstants.MaxAllowedCodeLength] == 1) { var huffmanCode = new HuffmanCode() { @@ -407,7 +407,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless // Fill in 2nd level tables and add pointers to root table. Span tableSpan = table; int tablePos = 0; - for (len = rootBits + 1, step = 2; len <= WebPConstants.MaxAllowedCodeLength; ++len, step <<= 1) + for (len = rootBits + 1, step = 2; len <= WebpConstants.MaxAllowedCodeLength; ++len, step <<= 1) { numOpen <<= 1; numNodes += numOpen; @@ -542,8 +542,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless private static void ConvertBitDepthsToSymbols(HuffmanTreeCode tree) { // 0 bit-depth means that the symbol does not exist. - uint[] nextCode = new uint[WebPConstants.MaxAllowedCodeLength + 1]; - int[] depthCount = new int[WebPConstants.MaxAllowedCodeLength + 1]; + uint[] nextCode = new uint[WebpConstants.MaxAllowedCodeLength + 1]; + int[] depthCount = new int[WebpConstants.MaxAllowedCodeLength + 1]; int len = tree.NumSymbols; for (int i = 0; i < len; i++) @@ -556,7 +556,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless nextCode[0] = 0; uint code = 0; - for (int i = 1; i <= WebPConstants.MaxAllowedCodeLength; i++) + for (int i = 1; i <= WebpConstants.MaxAllowedCodeLength; i++) { code = (uint)((code + depthCount[i - 1]) << 1); nextCode[i] = code; @@ -589,11 +589,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless while (i < numBits) { i += 4; - retval |= (uint)(reversedBits[bits & 0xf] << (WebPConstants.MaxAllowedCodeLength + 1 - i)); + retval |= (uint)(reversedBits[bits & 0xf] << (WebpConstants.MaxAllowedCodeLength + 1 - i)); bits >>= 4; } - retval >>= WebPConstants.MaxAllowedCodeLength + 1 - numBits; + retval >>= WebpConstants.MaxAllowedCodeLength + 1 - numBits; return retval; } @@ -604,7 +604,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless private static int NextTableBitSize(int[] count, int len, int rootBits) { int left = 1 << (len - rootBits); - while (len < WebPConstants.MaxAllowedCodeLength) + while (len < WebpConstants.MaxAllowedCodeLength) { left -= count[len]; if (left <= 0) diff --git a/src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs b/src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs index 7b6cf0f78..9f370513b 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs @@ -7,14 +7,14 @@ using System.Runtime.InteropServices; using SixLabors.ImageSharp.Memory; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Utility functions for the lossless decoder. /// internal static unsafe class LosslessUtils { - private const uint Predictor0 = WebPConstants.ArgbBlack; + private const uint Predictor0 = WebpConstants.ArgbBlack; private const int PrefixLookupIdxMax = 512; @@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { if (distance < PrefixLookupIdxMax) { - (int code, int extraBits) prefixCode = WebPLookupTables.PrefixEncodeCode[distance]; + (int code, int extraBits) prefixCode = WebpLookupTables.PrefixEncodeCode[distance]; extraBits = prefixCode.extraBits; return prefixCode.code; } @@ -82,9 +82,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { if (distance < PrefixLookupIdxMax) { - (int code, int extraBits) prefixCode = WebPLookupTables.PrefixEncodeCode[distance]; + (int code, int extraBits) prefixCode = WebpLookupTables.PrefixEncodeCode[distance]; extraBits = prefixCode.extraBits; - extraBitsValue = WebPLookupTables.PrefixEncodeExtraBitsValue[distance]; + extraBitsValue = WebpLookupTables.PrefixEncodeExtraBitsValue[distance]; return prefixCode.code; } @@ -510,7 +510,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless /// public static float FastLog2(uint v) { - return (v < LogLookupIdxMax) ? WebPLookupTables.Log2Table[v] : FastLog2Slow(v); + return (v < LogLookupIdxMax) ? WebpLookupTables.Log2Table[v] : FastLog2Slow(v); } /// @@ -519,7 +519,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless [MethodImpl(InliningOptions.ShortMethod)] public static float FastSLog2(uint v) { - return (v < LogLookupIdxMax) ? WebPLookupTables.SLog2Table[v] : FastSLog2Slow(v); + return (v < LogLookupIdxMax) ? WebpLookupTables.SLog2Table[v] : FastSLog2Slow(v); } [MethodImpl(InliningOptions.ShortMethod)] @@ -567,7 +567,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless // log2(1 + (v % y) / v) ~ LOG_2_RECIPROCAL * (v % y)/v // LOG_2_RECIPROCAL ~ 23/16 correction = (int)((23 * (origV & (y - 1))) >> 4); - return (vF * (WebPLookupTables.Log2Table[v] + logCnt)) + correction; + return (vF * (WebpLookupTables.Log2Table[v] + logCnt)) + correction; } else { @@ -591,7 +591,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless } while (v >= LogLookupIdxMax); - double log2 = WebPLookupTables.Log2Table[v] + logCnt; + double log2 = WebpLookupTables.Log2Table[v] + logCnt; if (origV >= ApproxLogMax) { // Since the division is still expensive, add this correction factor only @@ -615,7 +615,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless /// private static int PrefixEncodeBitsNoLut(int distance, ref int extraBits) { - int highestBit = WebPCommonUtils.BitsLog2Floor((uint)--distance); + int highestBit = WebpCommonUtils.BitsLog2Floor((uint)--distance); int secondHighestBit = (distance >> (highestBit - 1)) & 1; extraBits = highestBit - 1; var code = (2 * highestBit) + secondHighestBit; @@ -624,7 +624,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless private static int PrefixEncodeNoLUT(int distance, ref int extraBits, ref int extraBitsValue) { - int highestBit = WebPCommonUtils.BitsLog2Floor((uint)--distance); + int highestBit = WebpCommonUtils.BitsLog2Floor((uint)--distance); int secondHighestBit = (distance >> (highestBit - 1)) & 1; extraBits = highestBit - 1; extraBitsValue = distance & ((1 << extraBits) - 1); @@ -637,7 +637,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { for (int x = 0; x < numberOfPixels; ++x) { - output[x] = AddPixels(input[x], WebPConstants.ArgbBlack); + output[x] = AddPixels(input[x], WebpConstants.ArgbBlack); } } @@ -848,7 +848,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { for (int i = 0; i < numPixels; ++i) { - output[i] = SubPixels(input[i], WebPConstants.ArgbBlack); + output[i] = SubPixels(input[i], WebpConstants.ArgbBlack); } } diff --git a/src/ImageSharp/Formats/WebP/Lossless/PixOrCopy.cs b/src/ImageSharp/Formats/WebP/Lossless/PixOrCopy.cs index 209a22015..fea729048 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/PixOrCopy.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/PixOrCopy.cs @@ -3,7 +3,7 @@ using System.Diagnostics; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { [DebuggerDisplay("Mode: {Mode}, Len: {Len}, BgraOrDistance: {BgraOrDistance}")] internal class PixOrCopy diff --git a/src/ImageSharp/Formats/WebP/Lossless/PixOrCopyMode.cs b/src/ImageSharp/Formats/WebP/Lossless/PixOrCopyMode.cs index f2a47794d..1a93ef6cc 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/PixOrCopyMode.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/PixOrCopyMode.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal enum PixOrCopyMode { diff --git a/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs index 41a62befe..b41a372fc 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs @@ -5,7 +5,7 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Image transform methods for the lossless webp encoder. @@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless usedSubtractGreen, image); - image[(tileY * tilesPerRow) + tileX] = (uint)(WebPConstants.ArgbBlack | (pred << 8)); + image[(tileY * tilesPerRow) + tileX] = (uint)(WebpConstants.ArgbBlack | (pred << 8)); } } @@ -199,7 +199,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless Span maxDiffs = MemoryMarshal.Cast(currentRow.Slice(width + 1)); float bestDiff = MaxDiffCost; int bestMode = 0; - var residuals = new uint[1 << WebPConstants.MaxTransformBits]; + var residuals = new uint[1 << WebpConstants.MaxTransformBits]; var histoArgb = new int[4][]; var bestHisto = new int[4][]; for (int i = 0; i < 4; i++) @@ -329,7 +329,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless uint residual; if (y == 0) { - predict = (x == 0) ? WebPConstants.ArgbBlack : currentRow[x - 1]; // Left. + predict = (x == 0) ? WebpConstants.ArgbBlack : currentRow[x - 1]; // Left. } else if (x == 0) { @@ -340,7 +340,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless switch (mode) { case 0: - predict = WebPConstants.ArgbBlack; + predict = WebpConstants.ArgbBlack; break; case 1: predict = currentRow[x - 1]; diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LBackwardRefs.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LBackwardRefs.cs index 2c0166ae8..2182e6d81 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LBackwardRefs.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LBackwardRefs.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal class Vp8LBackwardRefs { diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LBitEntropy.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LBitEntropy.cs index 21707fbf0..c11602c72 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LBitEntropy.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LBitEntropy.cs @@ -3,7 +3,7 @@ using System; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Holds bit entropy results and entropy-related functions. diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LDecoder.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LDecoder.cs index 6d0330deb..da9cb9078 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LDecoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LDecoder.cs @@ -6,7 +6,7 @@ using System.Buffers; using System.Collections.Generic; using SixLabors.ImageSharp.Memory; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Holds information for decoding a lossless webp image. diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs index 9782d8ab7..5b7587471 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs @@ -8,11 +8,11 @@ using System.IO; using System.Linq; using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter; +using SixLabors.ImageSharp.Formats.Experimental.Webp.BitWriter; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Encoder for lossless webp images. @@ -72,7 +72,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless this.method = Numerics.Clamp(method, 0, 6); this.bitWriter = new Vp8LBitWriter(initialSize); this.Bgra = memoryAllocator.Allocate(pixelCount); - this.Palette = memoryAllocator.Allocate(WebPConstants.MaxPaletteSize); + this.Palette = memoryAllocator.Allocate(WebpConstants.MaxPaletteSize); this.Refs = new Vp8LBackwardRefs[3]; this.HashChain = new Vp8LHashChain(pixelCount); this.memoryAllocator = memoryAllocator; @@ -195,14 +195,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless /// The input image height. private void WriteImageSize(int inputImgWidth, int inputImgHeight) { - Guard.MustBeLessThan(inputImgWidth, WebPConstants.MaxDimension, nameof(inputImgWidth)); - Guard.MustBeLessThan(inputImgHeight, WebPConstants.MaxDimension, nameof(inputImgHeight)); + Guard.MustBeLessThan(inputImgWidth, WebpConstants.MaxDimension, nameof(inputImgWidth)); + Guard.MustBeLessThan(inputImgHeight, WebpConstants.MaxDimension, nameof(inputImgHeight)); uint width = (uint)inputImgWidth - 1; uint height = (uint)inputImgHeight - 1; - this.bitWriter.PutBits(width, WebPConstants.Vp8LImageSizeBits); - this.bitWriter.PutBits(height, WebPConstants.Vp8LImageSizeBits); + this.bitWriter.PutBits(width, WebpConstants.Vp8LImageSizeBits); + this.bitWriter.PutBits(height, WebpConstants.Vp8LImageSizeBits); } /// @@ -212,7 +212,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless private void WriteAlphaAndVersion(bool hasAlpha) { this.bitWriter.PutBits(hasAlpha ? 1U : 0, 1); - this.bitWriter.PutBits(WebPConstants.Vp8LVersion, WebPConstants.Vp8LVersionBits); + this.bitWriter.PutBits(WebpConstants.Vp8LVersion, WebpConstants.Vp8LVersionBits); } /// @@ -270,9 +270,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless this.MapImageFromPalette(width, height); // If using a color cache, do not have it bigger than the number of colors. - if (useCache && this.PaletteSize < (1 << WebPConstants.MaxColorCacheBits)) + if (useCache && this.PaletteSize < (1 << WebpConstants.MaxColorCacheBits)) { - this.CacheBits = WebPCommonUtils.BitsLog2Floor((uint)this.PaletteSize) + 1; + this.CacheBits = WebpCommonUtils.BitsLog2Floor((uint)this.PaletteSize) + 1; } } @@ -399,7 +399,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { int histogramImageXySize = LosslessUtils.SubSampleSize(width, histogramBits) * LosslessUtils.SubSampleSize(height, histogramBits); var histogramSymbols = new ushort[histogramImageXySize]; - var huffTree = new HuffmanTree[3 * WebPConstants.CodeLengthCodes]; + var huffTree = new HuffmanTree[3 * WebpConstants.CodeLengthCodes]; for (int i = 0; i < huffTree.Length; i++) { huffTree[i] = default; @@ -410,7 +410,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless if (cacheBits == 0) { // TODO: not sure if this should be 10 or 11. Original code comment says "The maximum allowed limit is 11.", but the value itself is 10. - cacheBits = WebPConstants.MaxColorCacheBits; + cacheBits = WebpConstants.MaxColorCacheBits; } } else @@ -543,10 +543,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless /// private void EncodePalette() { - Span tmpPalette = new uint[WebPConstants.MaxPaletteSize]; + Span tmpPalette = new uint[WebpConstants.MaxPaletteSize]; int paletteSize = this.PaletteSize; Span palette = this.Palette.Memory.Span; - this.bitWriter.PutBits(WebPConstants.TransformPresent, 1); + this.bitWriter.PutBits(WebpConstants.TransformPresent, 1); this.bitWriter.PutBits((uint)Vp8LTransformType.ColorIndexingTransform, 2); this.bitWriter.PutBits((uint)paletteSize - 1, 8); for (int i = paletteSize - 1; i >= 1; i--) @@ -565,7 +565,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless /// The height of the image. private void ApplySubtractGreen(int width, int height) { - this.bitWriter.PutBits(WebPConstants.TransformPresent, 1); + this.bitWriter.PutBits(WebpConstants.TransformPresent, 1); this.bitWriter.PutBits((uint)Vp8LTransformType.SubtractGreen, 2); LosslessUtils.SubtractGreenFromBlueAndRed(this.Bgra.GetSpan(), width * height); } @@ -580,7 +580,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless PredictorEncoder.ResidualImage(width, height, predBits, this.Bgra.GetSpan(), this.BgraScratch.GetSpan(), this.TransformData.GetSpan(), nearLosslessStrength, exact, usedSubtractGreen); - this.bitWriter.PutBits(WebPConstants.TransformPresent, 1); + this.bitWriter.PutBits(WebpConstants.TransformPresent, 1); this.bitWriter.PutBits((uint)Vp8LTransformType.PredictorTransform, 2); this.bitWriter.PutBits((uint)(predBits - 2), 3); @@ -595,7 +595,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless PredictorEncoder.ColorSpaceTransform(width, height, colorTransformBits, this.quality, this.Bgra.GetSpan(), this.TransformData.GetSpan()); - this.bitWriter.PutBits(WebPConstants.TransformPresent, 1); + this.bitWriter.PutBits(WebpConstants.TransformPresent, 1); this.bitWriter.PutBits((uint)Vp8LTransformType.CrossColorTransform, 2); this.bitWriter.PutBits((uint)(colorTransformBits - 2), 3); @@ -613,7 +613,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless huffmanCodes[i] = default; } - var huffTree = new HuffmanTree[3UL * WebPConstants.CodeLengthCodes]; + var huffTree = new HuffmanTree[3UL * WebpConstants.CodeLengthCodes]; for (int i = 0; i < huffTree.Length; i++) { huffTree[i] = default; @@ -732,19 +732,19 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless private void StoreFullHuffmanCode(HuffmanTree[] huffTree, HuffmanTreeToken[] tokens, HuffmanTreeCode tree) { int i; - var codeLengthBitDepth = new byte[WebPConstants.CodeLengthCodes]; - var codeLengthBitDepthSymbols = new short[WebPConstants.CodeLengthCodes]; + var codeLengthBitDepth = new byte[WebpConstants.CodeLengthCodes]; + var codeLengthBitDepthSymbols = new short[WebpConstants.CodeLengthCodes]; var huffmanCode = new HuffmanTreeCode { - NumSymbols = WebPConstants.CodeLengthCodes, + NumSymbols = WebpConstants.CodeLengthCodes, CodeLengths = codeLengthBitDepth, Codes = codeLengthBitDepthSymbols }; this.bitWriter.PutBits(0, 1); var numTokens = HuffmanUtils.CreateCompressedHuffmanTree(tree, tokens); - var histogram = new uint[WebPConstants.CodeLengthCodes + 1]; - var bufRle = new bool[WebPConstants.CodeLengthCodes + 1]; + var histogram = new uint[WebpConstants.CodeLengthCodes + 1]; + var bufRle = new bool[WebpConstants.CodeLengthCodes + 1]; for (i = 0; i < numTokens; i++) { histogram[tokens[i].Code]++; @@ -790,7 +790,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless } else { - int nBits = WebPCommonUtils.BitsLog2Floor((uint)trimmedLength - 2); + int nBits = WebpCommonUtils.BitsLog2Floor((uint)trimmedLength - 2); int nBitPairs = (nBits / 2) + 1; this.bitWriter.PutBits((uint)nBitPairs - 1, 3); this.bitWriter.PutBits((uint)trimmedLength - 2, nBitPairs * 2); @@ -830,7 +830,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless byte[] storageOrder = { 17, 18, 0, 1, 2, 3, 4, 5, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; // Throw away trailing zeros: - int codesToStore = WebPConstants.CodeLengthCodes; + int codesToStore = WebpConstants.CodeLengthCodes; for (; codesToStore > 4; codesToStore--) { if (codeLengthBitDepth[storageOrder[codesToStore - 1]] != 0) @@ -882,7 +882,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless else if (v.IsCacheIdx()) { int code = (int)v.CacheIdx(); - int literalIx = 256 + WebPConstants.NumLengthCodes + code; + int literalIx = 256 + WebpConstants.NumLengthCodes + code; this.bitWriter.WriteHuffmanCode(codes[0], literalIx); } else @@ -1084,7 +1084,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { Span palette = this.Palette.Memory.Span; this.PaletteSize = this.GetColorPalette(image, palette); - if (this.PaletteSize > WebPConstants.MaxPaletteSize) + if (this.PaletteSize > WebpConstants.MaxPaletteSize) { this.PaletteSize = 0; return false; @@ -1119,10 +1119,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless for (int x = 0; x < rowSpan.Length; x++) { colors.Add(rowSpan[x]); - if (colors.Count > WebPConstants.MaxPaletteSize) + if (colors.Count > WebpConstants.MaxPaletteSize) { // Exact count is not needed, because a palette will not be used then anyway. - return WebPConstants.MaxPaletteSize + 1; + return WebpConstants.MaxPaletteSize + 1; } } } @@ -1464,7 +1464,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { int numSymbols = (k == 0) ? histo.NumCodes() : - (k == 4) ? WebPConstants.NumDistanceCodes : 256; + (k == 4) ? WebpConstants.NumDistanceCodes : 256; huffmanCodes[startIdx + k].NumSymbols = numSymbols; totalLengthSize += numSymbols; } @@ -1532,7 +1532,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless while (true) { int huffImageSize = LosslessUtils.SubSampleSize(width, histoBits) * LosslessUtils.SubSampleSize(height, histoBits); - if (huffImageSize <= WebPConstants.MaxHuffImageSize) + if (huffImageSize <= WebpConstants.MaxHuffImageSize) { break; } @@ -1540,8 +1540,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless histoBits++; } - return (histoBits < WebPConstants.MinHuffmanBits) ? WebPConstants.MinHuffmanBits : - (histoBits > WebPConstants.MaxHuffmanBits) ? WebPConstants.MaxHuffmanBits : histoBits; + return (histoBits < WebpConstants.MinHuffmanBits) ? WebpConstants.MinHuffmanBits : + (histoBits > WebpConstants.MaxHuffmanBits) ? WebpConstants.MaxHuffmanBits : histoBits; } /// diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LHashChain.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LHashChain.cs index 994731b88..d99a26b01 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LHashChain.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LHashChain.cs @@ -6,7 +6,7 @@ using System.Buffers; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Memory; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal class Vp8LHashChain { diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LHistogram.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LHistogram.cs index ebc1e1175..31c293800 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LHistogram.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LHistogram.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal class Vp8LHistogram : IDeepCloneable { @@ -66,12 +66,12 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless public Vp8LHistogram(int paletteCodeBits) { this.PaletteCodeBits = paletteCodeBits; - this.Red = new uint[WebPConstants.NumLiteralCodes + 1]; - this.Blue = new uint[WebPConstants.NumLiteralCodes + 1]; - this.Alpha = new uint[WebPConstants.NumLiteralCodes + 1]; - this.Distance = new uint[WebPConstants.NumDistanceCodes]; + this.Red = new uint[WebpConstants.NumLiteralCodes + 1]; + this.Blue = new uint[WebpConstants.NumLiteralCodes + 1]; + this.Alpha = new uint[WebpConstants.NumLiteralCodes + 1]; + this.Distance = new uint[WebpConstants.NumDistanceCodes]; - var literalSize = WebPConstants.NumLiteralCodes + WebPConstants.NumLengthCodes + (1 << WebPConstants.MaxColorCacheBits); + var literalSize = WebpConstants.NumLiteralCodes + WebpConstants.NumLengthCodes + (1 << WebpConstants.MaxColorCacheBits); this.Literal = new uint[literalSize + 1]; // 5 for literal, red, blue, alpha, distance. @@ -150,14 +150,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless } else if (v.IsCacheIdx()) { - int literalIx = (int)(WebPConstants.NumLiteralCodes + WebPConstants.NumLengthCodes + v.CacheIdx()); + int literalIx = (int)(WebpConstants.NumLiteralCodes + WebpConstants.NumLengthCodes + v.CacheIdx()); this.Literal[literalIx]++; } else { int extraBits = 0; int code = LosslessUtils.PrefixEncodeBits(v.Length(), ref extraBits); - this.Literal[WebPConstants.NumLiteralCodes + code]++; + this.Literal[WebpConstants.NumLiteralCodes + code]++; if (!useDistanceModifier) { code = LosslessUtils.PrefixEncodeBits((int)v.Distance(), ref extraBits); @@ -173,7 +173,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless public int NumCodes() { - return WebPConstants.NumLiteralCodes + WebPConstants.NumLengthCodes + ((this.PaletteCodeBits > 0) ? (1 << this.PaletteCodeBits) : 0); + return WebpConstants.NumLiteralCodes + WebpConstants.NumLengthCodes + ((this.PaletteCodeBits > 0) ? (1 << this.PaletteCodeBits) : 0); } /// @@ -185,24 +185,24 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless uint notUsed = 0; return PopulationCost(this.Literal, this.NumCodes(), ref notUsed, ref this.IsUsed[0]) - + PopulationCost(this.Red, WebPConstants.NumLiteralCodes, ref notUsed, ref this.IsUsed[1]) - + PopulationCost(this.Blue, WebPConstants.NumLiteralCodes, ref notUsed, ref this.IsUsed[2]) - + PopulationCost(this.Alpha, WebPConstants.NumLiteralCodes, ref notUsed, ref this.IsUsed[3]) - + PopulationCost(this.Distance, WebPConstants.NumDistanceCodes, ref notUsed, ref this.IsUsed[4]) - + ExtraCost(this.Literal.AsSpan(WebPConstants.NumLiteralCodes), WebPConstants.NumLengthCodes) - + ExtraCost(this.Distance, WebPConstants.NumDistanceCodes); + + PopulationCost(this.Red, WebpConstants.NumLiteralCodes, ref notUsed, ref this.IsUsed[1]) + + PopulationCost(this.Blue, WebpConstants.NumLiteralCodes, ref notUsed, ref this.IsUsed[2]) + + PopulationCost(this.Alpha, WebpConstants.NumLiteralCodes, ref notUsed, ref this.IsUsed[3]) + + PopulationCost(this.Distance, WebpConstants.NumDistanceCodes, ref notUsed, ref this.IsUsed[4]) + + ExtraCost(this.Literal.AsSpan(WebpConstants.NumLiteralCodes), WebpConstants.NumLengthCodes) + + ExtraCost(this.Distance, WebpConstants.NumDistanceCodes); } public void UpdateHistogramCost() { uint alphaSym = 0, redSym = 0, blueSym = 0; uint notUsed = 0; - double alphaCost = PopulationCost(this.Alpha, WebPConstants.NumLiteralCodes, ref alphaSym, ref this.IsUsed[3]); - double distanceCost = PopulationCost(this.Distance, WebPConstants.NumDistanceCodes, ref notUsed, ref this.IsUsed[4]) + ExtraCost(this.Distance, WebPConstants.NumDistanceCodes); + double alphaCost = PopulationCost(this.Alpha, WebpConstants.NumLiteralCodes, ref alphaSym, ref this.IsUsed[3]); + double distanceCost = PopulationCost(this.Distance, WebpConstants.NumDistanceCodes, ref notUsed, ref this.IsUsed[4]) + ExtraCost(this.Distance, WebpConstants.NumDistanceCodes); int numCodes = this.NumCodes(); - this.LiteralCost = PopulationCost(this.Literal, numCodes, ref notUsed, ref this.IsUsed[0]) + ExtraCost(this.Literal.AsSpan(WebPConstants.NumLiteralCodes), WebPConstants.NumLengthCodes); - this.RedCost = PopulationCost(this.Red, WebPConstants.NumLiteralCodes, ref redSym, ref this.IsUsed[1]); - this.BlueCost = PopulationCost(this.Blue, WebPConstants.NumLiteralCodes, ref blueSym, ref this.IsUsed[2]); + this.LiteralCost = PopulationCost(this.Literal, numCodes, ref notUsed, ref this.IsUsed[0]) + ExtraCost(this.Literal.AsSpan(WebpConstants.NumLiteralCodes), WebpConstants.NumLengthCodes); + this.RedCost = PopulationCost(this.Red, WebpConstants.NumLiteralCodes, ref redSym, ref this.IsUsed[1]); + this.BlueCost = PopulationCost(this.Blue, WebpConstants.NumLiteralCodes, ref blueSym, ref this.IsUsed[2]); this.BitCost = this.LiteralCost + this.RedCost + this.BlueCost + alphaCost + distanceCost; if ((alphaSym | redSym | blueSym) == NonTrivialSym) { @@ -247,10 +247,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless int literalSize = this.NumCodes(); this.AddLiteral(b, output, literalSize); - this.AddRed(b, output, WebPConstants.NumLiteralCodes); - this.AddBlue(b, output, WebPConstants.NumLiteralCodes); - this.AddAlpha(b, output, WebPConstants.NumLiteralCodes); - this.AddDistance(b, output, WebPConstants.NumDistanceCodes); + this.AddRed(b, output, WebpConstants.NumLiteralCodes); + this.AddBlue(b, output, WebpConstants.NumLiteralCodes); + this.AddAlpha(b, output, WebpConstants.NumLiteralCodes); + this.AddDistance(b, output, WebpConstants.NumDistanceCodes); for (int i = 0; i < 5; i++) { @@ -269,7 +269,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless cost += GetCombinedEntropy(this.Literal, b.Literal, this.NumCodes(), this.IsUsed[0], b.IsUsed[0], false); - cost += ExtraCostCombined(this.Literal.AsSpan(WebPConstants.NumLiteralCodes), b.Literal.AsSpan(WebPConstants.NumLiteralCodes), WebPConstants.NumLengthCodes); + cost += ExtraCostCombined(this.Literal.AsSpan(WebpConstants.NumLiteralCodes), b.Literal.AsSpan(WebpConstants.NumLiteralCodes), WebpConstants.NumLengthCodes); if (cost > costThreshold) { @@ -290,31 +290,31 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless } } - cost += GetCombinedEntropy(this.Red, b.Red, WebPConstants.NumLiteralCodes, this.IsUsed[1], b.IsUsed[1], trivialAtEnd); + cost += GetCombinedEntropy(this.Red, b.Red, WebpConstants.NumLiteralCodes, this.IsUsed[1], b.IsUsed[1], trivialAtEnd); if (cost > costThreshold) { return false; } - cost += GetCombinedEntropy(this.Blue, b.Blue, WebPConstants.NumLiteralCodes, this.IsUsed[2], b.IsUsed[2], trivialAtEnd); + cost += GetCombinedEntropy(this.Blue, b.Blue, WebpConstants.NumLiteralCodes, this.IsUsed[2], b.IsUsed[2], trivialAtEnd); if (cost > costThreshold) { return false; } - cost += GetCombinedEntropy(this.Alpha, b.Alpha, WebPConstants.NumLiteralCodes, this.IsUsed[3], b.IsUsed[3], trivialAtEnd); + cost += GetCombinedEntropy(this.Alpha, b.Alpha, WebpConstants.NumLiteralCodes, this.IsUsed[3], b.IsUsed[3], trivialAtEnd); if (cost > costThreshold) { return false; } - cost += GetCombinedEntropy(this.Distance, b.Distance, WebPConstants.NumDistanceCodes, this.IsUsed[4], b.IsUsed[4], false); + cost += GetCombinedEntropy(this.Distance, b.Distance, WebpConstants.NumDistanceCodes, this.IsUsed[4], b.IsUsed[4], false); if (cost > costThreshold) { return false; } - cost += ExtraCostCombined(this.Distance, b.Distance, WebPConstants.NumDistanceCodes); + cost += ExtraCostCombined(this.Distance, b.Distance, WebpConstants.NumDistanceCodes); if (cost > costThreshold) { return false; @@ -331,7 +331,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { var output = new short[16]; - this.Vp8FTransform(reference.Slice(WebPLookupTables.Vp8DspScan[j]), pred.Slice(WebPLookupTables.Vp8DspScan[j]), output); + this.Vp8FTransform(reference.Slice(WebpLookupTables.Vp8DspScan[j]), pred.Slice(WebpLookupTables.Vp8DspScan[j]), output); // Convert coefficients to bin. for (int k = 0; k < 16; ++k) @@ -352,7 +352,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless // for handling the useful small values which contribute most. int maxValue = this.maxValue; int lastNonZero = this.lastNonZero; - int alpha = (maxValue > 1) ? WebPConstants.AlphaScale * lastNonZero / maxValue : 0; + int alpha = (maxValue > 1) ? WebpConstants.AlphaScale * lastNonZero / maxValue : 0; return alpha; } @@ -400,8 +400,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless // Do not change the span in the last iteration. if (i < 3) { - src = src.Slice(WebPConstants.Bps); - reference = reference.Slice(WebPConstants.Bps); + src = src.Slice(WebpConstants.Bps); + reference = reference.Slice(WebpConstants.Bps); } } diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LLz77Type.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LLz77Type.cs index e582f4b03..34fca4018 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LLz77Type.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LLz77Type.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal enum Vp8LLz77Type { diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LMetadata.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LMetadata.cs index 4aae397ee..4c776c640 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LMetadata.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LMetadata.cs @@ -3,7 +3,7 @@ using System.Buffers; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal class Vp8LMetadata { diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LMultipliers.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LMultipliers.cs index d89a2b7c6..ff3d02705 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LMultipliers.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LMultipliers.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal struct Vp8LMultipliers { diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LStreaks.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LStreaks.cs index ad94db49a..9c3022e9f 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LStreaks.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LStreaks.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { internal class Vp8LStreaks { @@ -55,7 +55,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless private static double InitialHuffmanCost() { // Small bias because Huffman code length is typically not stored in full length. - int huffmanCodeOfHuffmanCodeSize = WebPConstants.CodeLengthCodes * 3; + int huffmanCodeOfHuffmanCodeSize = WebpConstants.CodeLengthCodes * 3; double smallBias = 9.1; return huffmanCodeOfHuffmanCodeSize - smallBias; } diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LTransform.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LTransform.cs index 9b2dcd153..3bfa94525 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LTransform.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LTransform.cs @@ -4,7 +4,7 @@ using System.Buffers; using System.Diagnostics; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Data associated with a VP8L transformation to reduce the entropy. diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LTransformType.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LTransformType.cs index 694c0072e..8dc2af6dd 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LTransformType.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LTransformType.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Enum for the different transform types. Transformations are reversible manipulations of the image data diff --git a/src/ImageSharp/Formats/WebP/Lossless/WebPLosslessDecoder.cs b/src/ImageSharp/Formats/WebP/Lossless/WebPLosslessDecoder.cs index d396d3746..79fbf4bbc 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/WebPLosslessDecoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/WebPLosslessDecoder.cs @@ -8,11 +8,11 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats.Experimental.WebP.BitReader; +using SixLabors.ImageSharp.Formats.Experimental.Webp.BitReader; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { /// /// Decoder for lossless webp images. This code is a port of libwebp, which can be found here: https://chromium.googlesource.com/webm/libwebp @@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless private const uint PackedNonLiteralCode = 0; - private static readonly int CodeToPlaneCodes = WebPLookupTables.CodeToPlane.Length; + private static readonly int CodeToPlaneCodes = WebpLookupTables.CodeToPlane.Length; // Memory needed for lookup tables of one Huffman tree group. Red, blue, alpha and distance alphabets are constant (256 for red, blue and alpha, 40 for // distance) and lookup table sizes for them in worst case are 630 and 410 respectively. Size of green alphabet depends on color cache size and is equal @@ -114,14 +114,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless int numberOfTransformsPresent = 0; if (isLevel0) { - decoder.Transforms = new List(WebPConstants.MaxNumberOfTransforms); + decoder.Transforms = new List(WebpConstants.MaxNumberOfTransforms); // Next bit indicates, if a transformation is present. while (this.bitReader.ReadBit()) { - if (numberOfTransformsPresent > WebPConstants.MaxNumberOfTransforms) + if (numberOfTransformsPresent > WebpConstants.MaxNumberOfTransforms) { - WebPThrowHelper.ThrowImageFormatException($"The maximum number of transforms of {WebPConstants.MaxNumberOfTransforms} was exceeded"); + WebpThrowHelper.ThrowImageFormatException($"The maximum number of transforms of {WebpConstants.MaxNumberOfTransforms} was exceeded"); } this.ReadTransformation(transformXSize, transformYSize, decoder); @@ -148,10 +148,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless // Note: According to webpinfo color cache bits of 11 are valid, even though 10 is defined in the source code as maximum. // That is why 11 bits is also considered valid here. - bool colorCacheBitsIsValid = colorCacheBits >= 1 && colorCacheBits <= (WebPConstants.MaxColorCacheBits + 1); + bool colorCacheBitsIsValid = colorCacheBits >= 1 && colorCacheBits <= (WebpConstants.MaxColorCacheBits + 1); if (!colorCacheBitsIsValid) { - WebPThrowHelper.ThrowImageFormatException("Invalid color cache bits found"); + WebpThrowHelper.ThrowImageFormatException("Invalid color cache bits found"); } } @@ -216,7 +216,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless int height = decoder.Height; int row = lastPixel / width; int col = lastPixel % width; - const int lenCodeLimit = WebPConstants.NumLiteralCodes + WebPConstants.NumLengthCodes; + const int lenCodeLimit = WebpConstants.NumLiteralCodes + WebpConstants.NumLengthCodes; int colorCacheSize = decoder.Metadata.ColorCacheSize; ColorCache colorCache = decoder.Metadata.ColorCache; int colorCacheLimit = lenCodeLimit + colorCacheSize; @@ -267,7 +267,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless } // Literal - if (code < WebPConstants.NumLiteralCodes) + if (code < WebpConstants.NumLiteralCodes) { if (hTreeGroup[0].IsTrivialLiteral) { @@ -292,7 +292,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless else if (code < lenCodeLimit) { // Backward reference is used. - int lengthSym = code - WebPConstants.NumLiteralCodes; + int lengthSym = code - WebpConstants.NumLiteralCodes; int length = this.GetCopyLength(lengthSym); uint distSymbol = this.ReadSymbol(hTreeGroup[0].HTrees[HuffIndex.Dist]); this.bitReader.FillBitWindow(); @@ -341,7 +341,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless } else { - WebPThrowHelper.ThrowImageFormatException("Webp parsing error"); + WebpThrowHelper.ThrowImageFormatException("Webp parsing error"); } } } @@ -403,9 +403,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless } // Find maximum alphabet size for the hTree group. - for (int j = 0; j < WebPConstants.HuffmanCodesPerMetaCode; j++) + for (int j = 0; j < WebpConstants.HuffmanCodesPerMetaCode; j++) { - int alphabetSize = WebPConstants.AlphabetSize[j]; + int alphabetSize = WebpConstants.AlphabetSize[j]; if (j == 0 && colorCacheBits > 0) { alphabetSize += 1 << colorCacheBits; @@ -429,9 +429,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless bool isTrivialLiteral = true; int maxBits = 0; var codeLengths = new int[maxAlphabetSize]; - for (int j = 0; j < WebPConstants.HuffmanCodesPerMetaCode; j++) + for (int j = 0; j < WebpConstants.HuffmanCodesPerMetaCode; j++) { - int alphabetSize = WebPConstants.AlphabetSize[j]; + int alphabetSize = WebpConstants.AlphabetSize[j]; if (j == 0 && colorCacheBits > 0) { alphabetSize += 1 << colorCacheBits; @@ -440,7 +440,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless int size = this.ReadHuffmanCode(alphabetSize, codeLengths, huffmanTable); if (size == 0) { - WebPThrowHelper.ThrowImageFormatException("Huffman table size is zero"); + WebpThrowHelper.ThrowImageFormatException("Huffman table size is zero"); } // TODO: Avoid allocation. @@ -481,7 +481,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless uint green = hTreeGroup.HTrees[HuffIndex.Green][0].Value; uint alpha = hTreeGroup.HTrees[HuffIndex.Alpha][0].Value; hTreeGroup.LiteralArb = (alpha << 24) | (red << 16) | blue; - if (totalSize == 0 && green < WebPConstants.NumLiteralCodes) + if (totalSize == 0 && green < WebpConstants.NumLiteralCodes) { hTreeGroup.IsTrivialCode = true; hTreeGroup.LiteralArb |= green << 8; @@ -538,7 +538,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless uint numCodes = this.bitReader.ReadValue(4) + 4; if (numCodes > NumCodeLengthCodes) { - WebPThrowHelper.ThrowImageFormatException("Bitstream error, numCodes has an invalid value"); + WebpThrowHelper.ThrowImageFormatException("Bitstream error, numCodes has an invalid value"); } for (int i = 0; i < numCodes; i++) @@ -558,11 +558,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { int maxSymbol; int symbol = 0; - int prevCodeLen = WebPConstants.DefaultCodeLength; - int size = HuffmanUtils.BuildHuffmanTable(table, WebPConstants.LengthTableBits, codeLengthCodeLengths, NumCodeLengthCodes); + int prevCodeLen = WebpConstants.DefaultCodeLength; + int size = HuffmanUtils.BuildHuffmanTable(table, WebpConstants.LengthTableBits, codeLengthCodeLengths, NumCodeLengthCodes); if (size == 0) { - WebPThrowHelper.ThrowImageFormatException("Error building huffman table"); + WebpThrowHelper.ThrowImageFormatException("Error building huffman table"); } if (this.bitReader.ReadBit()) @@ -588,7 +588,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless HuffmanCode huffmanCode = table[idx]; this.bitReader.AdvanceBitPosition(huffmanCode.BitsUsed); uint codeLen = huffmanCode.Value; - if (codeLen < WebPConstants.CodeLengthLiterals) + if (codeLen < WebpConstants.CodeLengthLiterals) { codeLengths[symbol++] = (int)codeLen; if (codeLen != 0) @@ -598,10 +598,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless } else { - bool usePrev = codeLen == WebPConstants.CodeLengthRepeatCode; - uint slot = codeLen - WebPConstants.CodeLengthLiterals; - int extraBits = WebPConstants.CodeLengthExtraBits[slot]; - int repeatOffset = WebPConstants.CodeLengthRepeatOffsets[slot]; + bool usePrev = codeLen == WebpConstants.CodeLengthRepeatCode; + uint slot = codeLen - WebpConstants.CodeLengthLiterals; + int extraBits = WebpConstants.CodeLengthExtraBits[slot]; + int repeatOffset = WebpConstants.CodeLengthRepeatOffsets[slot]; int repeat = (int)(this.bitReader.ReadValue(extraBits) + repeatOffset); if (symbol + repeat > numSymbols) { @@ -633,7 +633,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { if (decoderTransform.TransformType == transform.TransformType) { - WebPThrowHelper.ThrowImageFormatException("Each transform can only be present once"); + WebpThrowHelper.ThrowImageFormatException("Each transform can only be present once"); } } @@ -732,7 +732,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless int end = width * height; // End of data. int last = end; // Last pixel to decode. int lastRow = height; - const int lenCodeLimit = WebPConstants.NumLiteralCodes + WebPConstants.NumLengthCodes; + const int lenCodeLimit = WebpConstants.NumLiteralCodes + WebpConstants.NumLengthCodes; int mask = hdr.HuffmanMask; HTreeGroup[] htreeGroup = (pos < last) ? GetHTreeGroupForPos(hdr, col, row) : null; while (!this.bitReader.Eos && pos < last) @@ -745,7 +745,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless this.bitReader.FillBitWindow(); int code = (int)this.ReadSymbol(htreeGroup[0].HTrees[HuffIndex.Green]); - if (code < WebPConstants.NumLiteralCodes) + if (code < WebpConstants.NumLiteralCodes) { // Literal data[pos] = (byte)code; @@ -756,7 +756,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { col = 0; ++row; - if (row <= lastRow && (row % WebPConstants.NumArgbCacheRows == 0)) + if (row <= lastRow && (row % WebpConstants.NumArgbCacheRows == 0)) { dec.ExtractPalettedAlphaRows(row); } @@ -765,7 +765,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless else if (code < lenCodeLimit) { // Backward reference - int lengthSym = code - WebPConstants.NumLiteralCodes; + int lengthSym = code - WebpConstants.NumLiteralCodes; int length = this.GetCopyLength(lengthSym); int distSymbol = (int)this.ReadSymbol(htreeGroup[0].HTrees[HuffIndex.Dist]); this.bitReader.FillBitWindow(); @@ -777,7 +777,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless } else { - WebPThrowHelper.ThrowImageFormatException("error while decoding alpha data"); + WebpThrowHelper.ThrowImageFormatException("error while decoding alpha data"); } pos += length; @@ -786,7 +786,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless { col -= width; ++row; - if (row <= lastRow && (row % WebPConstants.NumArgbCacheRows == 0)) + if (row <= lastRow && (row % WebpConstants.NumArgbCacheRows == 0)) { dec.ExtractPalettedAlphaRows(row); } @@ -799,7 +799,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless } else { - WebPThrowHelper.ThrowImageFormatException("bitstream error while parsing alpha data"); + WebpThrowHelper.ThrowImageFormatException("bitstream error while parsing alpha data"); } this.bitReader.Eos = this.bitReader.IsEndOfStream(); @@ -841,7 +841,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless uint bits = code; HuffmanCode huff = hTreeGroup.PackedTable[bits]; HuffmanCode hCode = hTreeGroup.HTrees[HuffIndex.Green][bits]; - if (hCode.Value >= WebPConstants.NumLiteralCodes) + if (hCode.Value >= WebpConstants.NumLiteralCodes) { huff.BitsUsed = hCode.BitsUsed + BitsSpecialMarker; huff.Value = hCode.Value; @@ -926,7 +926,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless return planeCode - CodeToPlaneCodes; } - int distCode = WebPLookupTables.CodeToPlane[planeCode - 1]; + int distCode = WebpLookupTables.CodeToPlane[planeCode - 1]; int yOffset = distCode >> 4; int xOffset = 8 - (distCode & 0xf); int dist = (yOffset * xSize) + xOffset; @@ -948,7 +948,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless int start = decodedPixels - dist; if (start < 0) { - WebPThrowHelper.ThrowImageFormatException("webp image data seems to be invalid"); + WebpThrowHelper.ThrowImageFormatException("webp image data seems to be invalid"); } if (dist >= length) diff --git a/src/ImageSharp/Formats/WebP/Lossy/IntraPredictionMode.cs b/src/ImageSharp/Formats/WebP/Lossy/IntraPredictionMode.cs index 7ac72c98e..231fc75f1 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/IntraPredictionMode.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/IntraPredictionMode.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal enum IntraPredictionMode { diff --git a/src/ImageSharp/Formats/WebP/Lossy/LoopFilter.cs b/src/ImageSharp/Formats/WebP/Lossy/LoopFilter.cs index 48047d78a..35231a913 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/LoopFilter.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/LoopFilter.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Enum for the different loop filters used. VP8 supports two types of loop filters. diff --git a/src/ImageSharp/Formats/WebP/Lossy/LossyUtils.cs b/src/ImageSharp/Formats/WebP/Lossy/LossyUtils.cs index d9ff33ec0..fcfce918a 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/LossyUtils.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/LossyUtils.cs @@ -6,19 +6,19 @@ using System.Buffers.Binary; using System.Runtime.CompilerServices; // ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal static class LossyUtils { public static void DC16(Span dst, Span yuv, int offset) { int offsetMinus1 = offset - 1; - int offsetMinusBps = offset - WebPConstants.Bps; + int offsetMinusBps = offset - WebpConstants.Bps; int dc = 16; for (int j = 0; j < 16; ++j) { // DC += dst[-1 + j * BPS] + dst[j - BPS]; - dc += yuv[offsetMinus1 + (j * WebPConstants.Bps)] + yuv[offsetMinusBps + j]; + dc += yuv[offsetMinus1 + (j * WebpConstants.Bps)] + yuv[offsetMinusBps + j]; } Put16(dc >> 5, dst); @@ -33,11 +33,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy public static void VE16(Span dst, Span yuv, int offset) { // vertical - Span src = yuv.Slice(offset - WebPConstants.Bps, 16); + Span src = yuv.Slice(offset - WebpConstants.Bps, 16); for (int j = 0; j < 16; ++j) { // memcpy(dst + j * BPS, dst - BPS, 16); - src.CopyTo(dst.Slice(j * WebPConstants.Bps)); + src.CopyTo(dst.Slice(j * WebpConstants.Bps)); } } @@ -50,8 +50,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // memset(dst, dst[-1], 16); byte v = yuv[offset]; Memset(dst, v, 0, 16); - offset += WebPConstants.Bps; - dst = dst.Slice(WebPConstants.Bps); + offset += WebpConstants.Bps; + dst = dst.Slice(WebpConstants.Bps); } } @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy for (int j = 0; j < 16; ++j) { // DC += dst[-1 + j * BPS]; - dc += yuv[-1 + (j * WebPConstants.Bps) + offset]; + dc += yuv[-1 + (j * WebpConstants.Bps) + offset]; } Put16(dc >> 4, dst); @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy for (int i = 0; i < 16; ++i) { // DC += dst[i - BPS]; - dc += yuv[i - WebPConstants.Bps + offset]; + dc += yuv[i - WebpConstants.Bps + offset]; } Put16(dc >> 4, dst); @@ -92,11 +92,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { int dc0 = 8; int offsetMinus1 = offset - 1; - int offsetMinusBps = offset - WebPConstants.Bps; + int offsetMinusBps = offset - WebpConstants.Bps; for (int i = 0; i < 8; ++i) { // dc0 += dst[i - BPS] + dst[-1 + i * BPS]; - dc0 += yuv[offsetMinusBps + i] + yuv[offsetMinus1 + (i * WebPConstants.Bps)]; + dc0 += yuv[offsetMinusBps + i] + yuv[offsetMinus1 + (i * WebpConstants.Bps)]; } Put8x8uv((byte)(dc0 >> 4), dst); @@ -112,10 +112,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy public static void VE8uv(Span dst, Span yuv, int offset) { // vertical - Span src = yuv.Slice(offset - WebPConstants.Bps, 8); + Span src = yuv.Slice(offset - WebpConstants.Bps, 8); - int endIdx = 8 * WebPConstants.Bps; - for (int j = 0; j < endIdx; j += WebPConstants.Bps) + int endIdx = 8 * WebpConstants.Bps; + for (int j = 0; j < endIdx; j += WebpConstants.Bps) { // memcpy(dst + j * BPS, dst - BPS, 8); src.CopyTo(dst.Slice(j)); @@ -132,8 +132,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // dst += BPS; byte v = yuv[offset]; Memset(dst, v, 0, 8); - dst = dst.Slice(WebPConstants.Bps); - offset += WebPConstants.Bps; + dst = dst.Slice(WebpConstants.Bps); + offset += WebpConstants.Bps; } } @@ -142,8 +142,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // DC with no top samples. int dc0 = 4; int offsetMinusOne = offset - 1; - int endIdx = 8 * WebPConstants.Bps; - for (int i = 0; i < endIdx; i += WebPConstants.Bps) + int endIdx = 8 * WebpConstants.Bps; + for (int i = 0; i < endIdx; i += WebpConstants.Bps) { // dc0 += dst[-1 + i * BPS]; dc0 += yuv[offsetMinusOne + i]; @@ -155,7 +155,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy public static void DC8uvNoLeft(Span dst, Span yuv, int offset) { // DC with no left samples. - int offsetMinusBps = offset - WebPConstants.Bps; + int offsetMinusBps = offset - WebpConstants.Bps; int dc0 = 4; for (int i = 0; i < 8; ++i) { @@ -176,16 +176,16 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy public static void DC4(Span dst, Span yuv, int offset) { int dc = 4; - int offsetMinusBps = offset - WebPConstants.Bps; + int offsetMinusBps = offset - WebpConstants.Bps; int offsetMinusOne = offset - 1; for (int i = 0; i < 4; ++i) { - dc += yuv[offsetMinusBps + i] + yuv[offsetMinusOne + (i * WebPConstants.Bps)]; + dc += yuv[offsetMinusBps + i] + yuv[offsetMinusOne + (i * WebpConstants.Bps)]; } dc >>= 3; - int endIndx = 4 * WebPConstants.Bps; - for (int i = 0; i < endIndx; i += WebPConstants.Bps) + int endIndx = 4 * WebpConstants.Bps; + for (int i = 0; i < endIndx; i += WebpConstants.Bps) { Memset(dst, (byte)dc, i, 4); } @@ -200,7 +200,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy public static void VE4(Span dst, Span yuv, int offset) { // vertical - int topOffset = offset - WebPConstants.Bps; + int topOffset = offset - WebpConstants.Bps; byte[] vals = { Avg3(yuv[topOffset - 1], yuv[topOffset], yuv[topOffset + 1]), @@ -209,8 +209,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy Avg3(yuv[topOffset + 2], yuv[topOffset + 3], yuv[topOffset + 4]) }; - int endIdx = 4 * WebPConstants.Bps; - for (int i = 0; i < endIdx; i += WebPConstants.Bps) + int endIdx = 4 * WebpConstants.Bps; + for (int i = 0; i < endIdx; i += WebpConstants.Bps) { vals.CopyTo(dst.Slice(i)); } @@ -220,19 +220,19 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { // horizontal int offsetMinusOne = offset - 1; - byte a = yuv[offsetMinusOne - WebPConstants.Bps]; + byte a = yuv[offsetMinusOne - WebpConstants.Bps]; byte b = yuv[offsetMinusOne]; - byte c = yuv[offsetMinusOne + WebPConstants.Bps]; - byte d = yuv[offsetMinusOne + (2 * WebPConstants.Bps)]; - byte e = yuv[offsetMinusOne + (3 * WebPConstants.Bps)]; + byte c = yuv[offsetMinusOne + WebpConstants.Bps]; + byte d = yuv[offsetMinusOne + (2 * WebpConstants.Bps)]; + byte e = yuv[offsetMinusOne + (3 * WebpConstants.Bps)]; uint val = 0x01010101U * Avg3(a, b, c); BinaryPrimitives.WriteUInt32BigEndian(dst, val); val = 0x01010101U * Avg3(b, c, d); - BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(WebPConstants.Bps), val); + BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(WebpConstants.Bps), val); val = 0x01010101U * Avg3(c, d, e); - BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(2 * WebPConstants.Bps), val); + BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(2 * WebpConstants.Bps), val); val = 0x01010101U * Avg3(d, e, e); - BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(3 * WebPConstants.Bps), val); + BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(3 * WebpConstants.Bps), val); } public static void RD4(Span dst, Span yuv, int offset) @@ -240,14 +240,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // Down-right int offsetMinusOne = offset - 1; byte i = yuv[offsetMinusOne]; - byte j = yuv[offsetMinusOne + (1 * WebPConstants.Bps)]; - byte k = yuv[offsetMinusOne + (2 * WebPConstants.Bps)]; - byte l = yuv[offsetMinusOne + (3 * WebPConstants.Bps)]; - byte x = yuv[offsetMinusOne - WebPConstants.Bps]; - byte a = yuv[offset - WebPConstants.Bps]; - byte b = yuv[offset + 1 - WebPConstants.Bps]; - byte c = yuv[offset + 2 - WebPConstants.Bps]; - byte d = yuv[offset + 3 - WebPConstants.Bps]; + byte j = yuv[offsetMinusOne + (1 * WebpConstants.Bps)]; + byte k = yuv[offsetMinusOne + (2 * WebpConstants.Bps)]; + byte l = yuv[offsetMinusOne + (3 * WebpConstants.Bps)]; + byte x = yuv[offsetMinusOne - WebpConstants.Bps]; + byte a = yuv[offset - WebpConstants.Bps]; + byte b = yuv[offset + 1 - WebpConstants.Bps]; + byte c = yuv[offset + 2 - WebpConstants.Bps]; + byte d = yuv[offset + 3 - WebpConstants.Bps]; Dst(dst, 0, 3, Avg3(j, k, l)); byte ijk = Avg3(i, j, k); @@ -277,13 +277,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // Vertical-Right int offsetMinusOne = offset - 1; byte i = yuv[offsetMinusOne]; - byte j = yuv[offsetMinusOne + (1 * WebPConstants.Bps)]; - byte k = yuv[offsetMinusOne + (2 * WebPConstants.Bps)]; - byte x = yuv[offsetMinusOne - WebPConstants.Bps]; - byte a = yuv[offset - WebPConstants.Bps]; - byte b = yuv[offset + 1 - WebPConstants.Bps]; - byte c = yuv[offset + 2 - WebPConstants.Bps]; - byte d = yuv[offset + 3 - WebPConstants.Bps]; + byte j = yuv[offsetMinusOne + (1 * WebpConstants.Bps)]; + byte k = yuv[offsetMinusOne + (2 * WebpConstants.Bps)]; + byte x = yuv[offsetMinusOne - WebpConstants.Bps]; + byte a = yuv[offset - WebpConstants.Bps]; + byte b = yuv[offset + 1 - WebpConstants.Bps]; + byte c = yuv[offset + 2 - WebpConstants.Bps]; + byte d = yuv[offset + 3 - WebpConstants.Bps]; byte xa = Avg2(x, a); Dst(dst, 0, 0, xa); @@ -312,14 +312,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy public static void LD4(Span dst, Span yuv, int offset) { // Down-Left - byte a = yuv[offset - WebPConstants.Bps]; - byte b = yuv[offset + 1 - WebPConstants.Bps]; - byte c = yuv[offset + 2 - WebPConstants.Bps]; - byte d = yuv[offset + 3 - WebPConstants.Bps]; - byte e = yuv[offset + 4 - WebPConstants.Bps]; - byte f = yuv[offset + 5 - WebPConstants.Bps]; - byte g = yuv[offset + 6 - WebPConstants.Bps]; - byte h = yuv[offset + 7 - WebPConstants.Bps]; + byte a = yuv[offset - WebpConstants.Bps]; + byte b = yuv[offset + 1 - WebpConstants.Bps]; + byte c = yuv[offset + 2 - WebpConstants.Bps]; + byte d = yuv[offset + 3 - WebpConstants.Bps]; + byte e = yuv[offset + 4 - WebpConstants.Bps]; + byte f = yuv[offset + 5 - WebpConstants.Bps]; + byte g = yuv[offset + 6 - WebpConstants.Bps]; + byte h = yuv[offset + 7 - WebpConstants.Bps]; Dst(dst, 0, 0, Avg3(a, b, c)); byte bcd = Avg3(b, c, d); @@ -347,14 +347,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy public static void VL4(Span dst, Span yuv, int offset) { // Vertical-Left - byte a = yuv[offset - WebPConstants.Bps]; - byte b = yuv[offset + 1 - WebPConstants.Bps]; - byte c = yuv[offset + 2 - WebPConstants.Bps]; - byte d = yuv[offset + 3 - WebPConstants.Bps]; - byte e = yuv[offset + 4 - WebPConstants.Bps]; - byte f = yuv[offset + 5 - WebPConstants.Bps]; - byte g = yuv[offset + 6 - WebPConstants.Bps]; - byte h = yuv[offset + 7 - WebPConstants.Bps]; + byte a = yuv[offset - WebpConstants.Bps]; + byte b = yuv[offset + 1 - WebpConstants.Bps]; + byte c = yuv[offset + 2 - WebpConstants.Bps]; + byte d = yuv[offset + 3 - WebpConstants.Bps]; + byte e = yuv[offset + 4 - WebpConstants.Bps]; + byte f = yuv[offset + 5 - WebpConstants.Bps]; + byte g = yuv[offset + 6 - WebpConstants.Bps]; + byte h = yuv[offset + 7 - WebpConstants.Bps]; Dst(dst, 0, 0, Avg2(a, b)); byte bc = Avg2(b, c); @@ -384,13 +384,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { // Horizontal-Down byte i = yuv[offset - 1]; - byte j = yuv[offset - 1 + (1 * WebPConstants.Bps)]; - byte k = yuv[offset - 1 + (2 * WebPConstants.Bps)]; - byte l = yuv[offset - 1 + (3 * WebPConstants.Bps)]; - byte x = yuv[offset - 1 - WebPConstants.Bps]; - byte a = yuv[offset - WebPConstants.Bps]; - byte b = yuv[offset + 1 - WebPConstants.Bps]; - byte c = yuv[offset + 2 - WebPConstants.Bps]; + byte j = yuv[offset - 1 + (1 * WebpConstants.Bps)]; + byte k = yuv[offset - 1 + (2 * WebpConstants.Bps)]; + byte l = yuv[offset - 1 + (3 * WebpConstants.Bps)]; + byte x = yuv[offset - 1 - WebpConstants.Bps]; + byte a = yuv[offset - WebpConstants.Bps]; + byte b = yuv[offset + 1 - WebpConstants.Bps]; + byte c = yuv[offset + 2 - WebpConstants.Bps]; byte ix = Avg2(i, x); Dst(dst, 0, 0, ix); @@ -420,9 +420,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { // Horizontal-Up byte i = yuv[offset - 1]; - byte j = yuv[offset - 1 + (1 * WebPConstants.Bps)]; - byte k = yuv[offset - 1 + (2 * WebPConstants.Bps)]; - byte l = yuv[offset - 1 + (3 * WebPConstants.Bps)]; + byte j = yuv[offset - 1 + (1 * WebpConstants.Bps)]; + byte k = yuv[offset - 1 + (2 * WebpConstants.Bps)]; + byte l = yuv[offset - 1 + (3 * WebpConstants.Bps)]; Dst(dst, 0, 0, Avg2(i, j)); byte jk = Avg2(j, k); @@ -532,7 +532,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy Store(dst, 2, 0, b - c); Store(dst, 3, 0, a - d); tmpOffset++; - dst = dst.Slice(WebPConstants.Bps); + dst = dst.Slice(WebpConstants.Bps); } } @@ -565,7 +565,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy public static void TransformUv(Span src, Span dst) { TransformTwo(src.Slice(0 * 16), dst); - TransformTwo(src.Slice(2 * 16), dst.Slice(4 * WebPConstants.Bps)); + TransformTwo(src.Slice(2 * 16), dst.Slice(4 * WebpConstants.Bps)); } public static void TransformDcuv(Span src, Span dst) @@ -582,12 +582,12 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy if (src[2 * 16] != 0) { - TransformDc(src.Slice(2 * 16), dst.Slice(4 * WebPConstants.Bps)); + TransformDc(src.Slice(2 * 16), dst.Slice(4 * WebpConstants.Bps)); } if (src[3 * 16] != 0) { - TransformDc(src.Slice(3 * 16), dst.Slice((4 * WebPConstants.Bps) + 4)); + TransformDc(src.Slice(3 * 16), dst.Slice((4 * WebpConstants.Bps) + 4)); } } @@ -745,7 +745,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy [MethodImpl(InliningOptions.ShortMethod)] public static void Dst(Span dst, int x, int y, byte v) { - dst[x + (y * WebPConstants.Bps)] = v; + dst[x + (y * WebpConstants.Bps)] = v; } [MethodImpl(InliningOptions.ShortMethod)] @@ -757,7 +757,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // Cost of coding one event with probability 'proba'. public static int Vp8BitCost(int bit, byte proba) { - return bit == 0 ? WebPLookupTables.Vp8EntropyCost[proba] : WebPLookupTables.Vp8EntropyCost[255 - proba]; + return bit == 0 ? WebpLookupTables.Vp8EntropyCost[proba] : WebpLookupTables.Vp8EntropyCost[255 - proba]; } [MethodImpl(InliningOptions.ShortMethod)] @@ -765,14 +765,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { for (int j = 0; j < 16; ++j) { - Memset(dst.Slice(j * WebPConstants.Bps), (byte)v, 0, 16); + Memset(dst.Slice(j * WebpConstants.Bps), (byte)v, 0, 16); } } private static void TrueMotion(Span dst, Span yuv, int offset, int size) { // For information about how true motion works, see rfc6386, page 52. ff and section 20.14. - int topOffset = offset - WebPConstants.Bps; + int topOffset = offset - WebpConstants.Bps; Span top = yuv.Slice(topOffset); byte p = yuv[topOffset - 1]; int leftOffset = offset - 1; @@ -784,9 +784,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy dst[x] = (byte)Clamp255(left + top[x] - p); } - leftOffset += WebPConstants.Bps; + leftOffset += WebpConstants.Bps; left = yuv[leftOffset]; - dst = dst.Slice(WebPConstants.Bps); + dst = dst.Slice(WebpConstants.Bps); } } @@ -856,11 +856,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy int p0 = p[offset - step]; int q0 = p[offset]; int q1 = p[offset + step]; - int a = (3 * (q0 - p0)) + WebPLookupTables.Sclip1[p1 - q1]; - int a1 = WebPLookupTables.Sclip2[(a + 4) >> 3]; - int a2 = WebPLookupTables.Sclip2[(a + 3) >> 3]; - p[offset - step] = WebPLookupTables.Clip1[p0 + a2]; - p[offset] = WebPLookupTables.Clip1[q0 - a1]; + int a = (3 * (q0 - p0)) + WebpLookupTables.Sclip1[p1 - q1]; + int a1 = WebpLookupTables.Sclip2[(a + 4) >> 3]; + int a2 = WebpLookupTables.Sclip2[(a + 3) >> 3]; + p[offset - step] = WebpLookupTables.Clip1[p0 + a2]; + p[offset] = WebpLookupTables.Clip1[q0 - a1]; } private static void DoFilter4(Span p, int offset, int step) @@ -872,13 +872,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy int q0 = p[offset]; int q1 = p[offset + step]; int a = 3 * (q0 - p0); - int a1 = WebPLookupTables.Sclip2[(a + 4) >> 3]; - int a2 = WebPLookupTables.Sclip2[(a + 3) >> 3]; + int a1 = WebpLookupTables.Sclip2[(a + 4) >> 3]; + int a2 = WebpLookupTables.Sclip2[(a + 3) >> 3]; int a3 = (a1 + 1) >> 1; - p[offsetMinus2Step] = WebPLookupTables.Clip1[p1 + a3]; - p[offset - step] = WebPLookupTables.Clip1[p0 + a2]; - p[offset] = WebPLookupTables.Clip1[q0 - a1]; - p[offset + step] = WebPLookupTables.Clip1[q1 - a3]; + p[offsetMinus2Step] = WebpLookupTables.Clip1[p1 + a3]; + p[offset - step] = WebpLookupTables.Clip1[p0 + a2]; + p[offset] = WebpLookupTables.Clip1[q0 - a1]; + p[offset + step] = WebpLookupTables.Clip1[q1 - a3]; } private static void DoFilter6(Span p, int offset, int step) @@ -893,18 +893,18 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy int q0 = p[offset]; int q1 = p[offset + step]; int q2 = p[offset + step2]; - int a = WebPLookupTables.Sclip1[(3 * (q0 - p0)) + WebPLookupTables.Sclip1[p1 - q1]]; + int a = WebpLookupTables.Sclip1[(3 * (q0 - p0)) + WebpLookupTables.Sclip1[p1 - q1]]; // a is in [-128,127], a1 in [-27,27], a2 in [-18,18] and a3 in [-9,9] int a1 = ((27 * a) + 63) >> 7; // eq. to ((3 * a + 7) * 9) >> 7 int a2 = ((18 * a) + 63) >> 7; // eq. to ((2 * a + 7) * 9) >> 7 int a3 = ((9 * a) + 63) >> 7; // eq. to ((1 * a + 7) * 9) >> 7 - p[offset - step3] = WebPLookupTables.Clip1[p2 + a3]; - p[offset - step2] = WebPLookupTables.Clip1[p1 + a2]; - p[offsetMinusStep] = WebPLookupTables.Clip1[p0 + a1]; - p[offset] = WebPLookupTables.Clip1[q0 - a1]; - p[offset + step] = WebPLookupTables.Clip1[q1 - a2]; - p[offset + step2] = WebPLookupTables.Clip1[q2 - a3]; + p[offset - step3] = WebpLookupTables.Clip1[p2 + a3]; + p[offset - step2] = WebpLookupTables.Clip1[p1 + a2]; + p[offsetMinusStep] = WebpLookupTables.Clip1[p0 + a1]; + p[offset] = WebpLookupTables.Clip1[q0 - a1]; + p[offset + step] = WebpLookupTables.Clip1[q1 - a2]; + p[offset + step2] = WebpLookupTables.Clip1[q2 - a3]; } [MethodImpl(InliningOptions.ShortMethod)] @@ -914,7 +914,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy int p0 = p[offset - step]; int q0 = p[offset]; int q1 = p[offset + step]; - return ((4 * WebPLookupTables.Abs0[p0 - q0]) + WebPLookupTables.Abs0[p1 - q1]) <= t; + return ((4 * WebpLookupTables.Abs0[p0 - q0]) + WebpLookupTables.Abs0[p1 - q1]) <= t; } private static bool NeedsFilter2(Span p, int offset, int step, int t, int it) @@ -929,14 +929,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy int q1 = p[offset + step]; int q2 = p[offset + step2]; int q3 = p[offset + step3]; - if (((4 * WebPLookupTables.Abs0[p0 - q0]) + WebPLookupTables.Abs0[p1 - q1]) > t) + if (((4 * WebpLookupTables.Abs0[p0 - q0]) + WebpLookupTables.Abs0[p1 - q1]) > t) { return false; } - return WebPLookupTables.Abs0[p3 - p2] <= it && WebPLookupTables.Abs0[p2 - p1] <= it && - WebPLookupTables.Abs0[p1 - p0] <= it && WebPLookupTables.Abs0[q3 - q2] <= it && - WebPLookupTables.Abs0[q2 - q1] <= it && WebPLookupTables.Abs0[q1 - q0] <= it; + return WebpLookupTables.Abs0[p3 - p2] <= it && WebpLookupTables.Abs0[p2 - p1] <= it && + WebpLookupTables.Abs0[p1 - p0] <= it && WebpLookupTables.Abs0[q3 - q2] <= it && + WebpLookupTables.Abs0[q2 - q1] <= it && WebpLookupTables.Abs0[q1 - q0] <= it; } [MethodImpl(InliningOptions.ShortMethod)] @@ -946,7 +946,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy int p0 = p[offset - step]; int q0 = p[offset]; int q1 = p[offset + step]; - return (WebPLookupTables.Abs0[p1 - p0] > thresh) || (WebPLookupTables.Abs0[q1 - q0] > thresh); + return (WebpLookupTables.Abs0[p1 - p0] > thresh) || (WebpLookupTables.Abs0[q1 - q0] > thresh); } [MethodImpl(InliningOptions.ShortMethod)] @@ -958,7 +958,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy [MethodImpl(InliningOptions.ShortMethod)] private static void Store(Span dst, int x, int y, int v) { - var index = x + (y * WebPConstants.Bps); + var index = x + (y * WebpConstants.Bps); dst[index] = Clip8B(dst[index] + (v >> 3)); } @@ -993,8 +993,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy [MethodImpl(InliningOptions.ShortMethod)] private static void Put8x8uv(byte value, Span dst) { - int end = 8 * WebPConstants.Bps; - for (int j = 0; j < end; j += WebPConstants.Bps) + int end = 8 * WebpConstants.Bps; + for (int j = 0; j < end; j += WebpConstants.Bps) { // memset(dst + j * BPS, value, 8); Memset(dst, value, j, 8); diff --git a/src/ImageSharp/Formats/WebP/Lossy/PassStats.cs b/src/ImageSharp/Formats/WebP/Lossy/PassStats.cs index e041aa26d..115e87245 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/PassStats.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/PassStats.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Class for organizing convergence in either size or PSNR. diff --git a/src/ImageSharp/Formats/WebP/Lossy/QuantEnc.cs b/src/ImageSharp/Formats/WebP/Lossy/QuantEnc.cs index 32141283e..58d441e69 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/QuantEnc.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/QuantEnc.cs @@ -4,7 +4,7 @@ using System; using System.Runtime.CompilerServices; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Quantization methods. @@ -131,7 +131,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy [MethodImpl(InliningOptions.ShortMethod)] private static int QuantDiv(uint n, uint iQ, uint b) { - return (int)(((n * iQ) + b) >> WebPConstants.QFix); + return (int)(((n * iQ) + b) >> WebpConstants.QFix); } } } diff --git a/src/ImageSharp/Formats/WebP/Lossy/VP8BandProbas.cs b/src/ImageSharp/Formats/WebP/Lossy/VP8BandProbas.cs index 8e312a4b1..09424fb79 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/VP8BandProbas.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/VP8BandProbas.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// All the probabilities associated to one band. @@ -13,8 +13,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy /// public Vp8BandProbas() { - this.Probabilities = new Vp8ProbaArray[WebPConstants.NumCtx]; - for (int i = 0; i < WebPConstants.NumCtx; i++) + this.Probabilities = new Vp8ProbaArray[WebpConstants.NumCtx]; + for (int i = 0; i < WebpConstants.NumCtx; i++) { this.Probabilities[i] = new Vp8ProbaArray(); } diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8CostArray.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8CostArray.cs index 527b0d26e..c772b65c7 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8CostArray.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8CostArray.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal class Vp8CostArray { @@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy /// public Vp8CostArray() { - this.Costs = new ushort[WebPConstants.NumCtx * (67 + 1)]; + this.Costs = new ushort[WebpConstants.NumCtx * (67 + 1)]; } public ushort[] Costs { get; } diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8Decoder.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8Decoder.cs index c166632ad..070da84ae 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8Decoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8Decoder.cs @@ -3,10 +3,10 @@ using System; using System.Buffers; -using SixLabors.ImageSharp.Formats.Experimental.WebP.BitReader; +using SixLabors.ImageSharp.Formats.Experimental.Webp.BitReader; using SixLabors.ImageSharp.Memory; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Holds information for decoding a lossy webp image. @@ -49,9 +49,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy this.MacroBlockInfo[this.MbWidth] = new Vp8MacroBlock(); - this.DeQuantMatrices = new Vp8QuantMatrix[WebPConstants.NumMbSegments]; - this.FilterStrength = new Vp8FilterInfo[WebPConstants.NumMbSegments, 2]; - for (int i = 0; i < WebPConstants.NumMbSegments; i++) + this.DeQuantMatrices = new Vp8QuantMatrix[WebpConstants.NumMbSegments]; + this.FilterStrength = new Vp8FilterInfo[WebpConstants.NumMbSegments, 2]; + for (int i = 0; i < WebpConstants.NumMbSegments; i++) { this.DeQuantMatrices[i] = new Vp8QuantMatrix(); for (int j = 0; j < 2; j++) @@ -63,10 +63,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy uint width = pictureHeader.Width; uint height = pictureHeader.Height; - int extraRows = WebPConstants.FilterExtraRows[(int)LoopFilter.Complex]; // assuming worst case: complex filter + int extraRows = WebpConstants.FilterExtraRows[(int)LoopFilter.Complex]; // assuming worst case: complex filter int extraY = extraRows * this.CacheYStride; int extraUv = (extraRows / 2) * this.CacheUvStride; - this.YuvBuffer = memoryAllocator.Allocate((WebPConstants.Bps * 17) + (WebPConstants.Bps * 9) + extraY); + this.YuvBuffer = memoryAllocator.Allocate((WebpConstants.Bps * 17) + (WebpConstants.Bps * 9) + extraY); this.CacheY = memoryAllocator.Allocate((16 * this.CacheYStride) + extraY); int cacheUvSize = (16 * this.CacheUvStride) + extraUv; this.CacheU = memoryAllocator.Allocate(cacheUvSize); @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy this.CacheU.Memory.Span.Fill(205); this.CacheV.Memory.Span.Fill(205); - this.Vp8BitReaders = new Vp8BitReader[WebPConstants.MaxNumPartitions]; + this.Vp8BitReaders = new Vp8BitReader[WebpConstants.MaxNumPartitions]; } /// @@ -276,7 +276,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy } Vp8FilterHeader hdr = this.FilterHeader; - for (int s = 0; s < WebPConstants.NumMbSegments; ++s) + for (int s = 0; s < WebpConstants.NumMbSegments; ++s) { int baseLevel; diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs index 8a5ee8d1a..8f8c7676d 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless; +using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Iterator structure to iterate through macroblocks, pointing to the @@ -67,10 +67,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy this.uvTopIdx = 0; this.predsWidth = (4 * mbw) + 1; this.predIdx = this.predsWidth; - this.YuvIn = new byte[WebPConstants.Bps * 16]; - this.YuvOut = new byte[WebPConstants.Bps * 16]; - this.YuvOut2 = new byte[WebPConstants.Bps * 16]; - this.YuvP = new byte[(32 * WebPConstants.Bps) + (16 * WebPConstants.Bps) + (8 * WebPConstants.Bps)]; // I16+Chroma+I4 preds + this.YuvIn = new byte[WebpConstants.Bps * 16]; + this.YuvOut = new byte[WebpConstants.Bps * 16]; + this.YuvOut2 = new byte[WebpConstants.Bps * 16]; + this.YuvP = new byte[(32 * WebpConstants.Bps) + (16 * WebpConstants.Bps) + (8 * WebpConstants.Bps)]; // I16+Chroma+I4 preds this.YLeft = new byte[32]; this.UvLeft = new byte[32]; this.TopNz = new int[9]; @@ -355,7 +355,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy uint m2; for (k = 0; k < 16; k += 4) { - this.Mean16x4(this.YuvIn.AsSpan(YOffEnc + (k * WebPConstants.Bps)), dc.AsSpan(k)); + this.Mean16x4(this.YuvIn.AsSpan(YOffEnc + (k * WebpConstants.Bps)), dc.AsSpan(k)); } for (m = 0, m2 = 0, k = 0; k < 16; ++k) @@ -466,7 +466,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy int y = this.I4 >> 2; int left = (x == 0) ? this.Preds[predIdx + (y * predsWidth) - 1] : modes[this.I4 - 1]; int top = (y == 0) ? this.Preds[predIdx - predsWidth + x] : modes[this.I4 - 4]; - return WebPLookupTables.Vp8FixedCostsI4[top, left]; + return WebpLookupTables.Vp8FixedCostsI4[top, left]; } public void SetIntraUvMode(int mode) @@ -526,13 +526,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // left for (int i = 0; i < 16; ++i) { - this.YLeft[i + 1] = ySrc[15 + (i * WebPConstants.Bps)]; + this.YLeft[i + 1] = ySrc[15 + (i * WebpConstants.Bps)]; } for (int i = 0; i < 8; ++i) { - this.UvLeft[i + 1] = uvSrc[7 + (i * WebPConstants.Bps)]; - this.UvLeft[i + 16 + 1] = uvSrc[15 + (i * WebPConstants.Bps)]; + this.UvLeft[i + 1] = uvSrc[7 + (i * WebpConstants.Bps)]; + this.UvLeft[i + 16 + 1] = uvSrc[15 + (i * WebpConstants.Bps)]; } // top-left (before 'top'!) @@ -544,14 +544,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy if (y < this.mbh - 1) { // top - ySrc.Slice(15 * WebPConstants.Bps, 16).CopyTo(this.YTop.AsSpan(this.yTopIdx)); - uvSrc.Slice(7 * WebPConstants.Bps, 8 + 8).CopyTo(this.UvTop.AsSpan(this.uvTopIdx)); + ySrc.Slice(15 * WebpConstants.Bps, 16).CopyTo(this.YTop.AsSpan(this.yTopIdx)); + uvSrc.Slice(7 * WebpConstants.Bps, 8 + 8).CopyTo(this.UvTop.AsSpan(this.uvTopIdx)); } } public bool RotateI4(Span yuvOut) { - Span blk = yuvOut.Slice(WebPLookupTables.Vp8Scan[this.I4]); + Span blk = yuvOut.Slice(WebpLookupTables.Vp8Scan[this.I4]); Span top = this.I4Boundary.AsSpan(); int topOffset = this.I4BoundaryIdx; int i; @@ -559,7 +559,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // Update the cache with 7 fresh samples. for (i = 0; i <= 3; ++i) { - top[topOffset - 4 + i] = blk[i + (3 * WebPConstants.Bps)]; // Store future top samples. + top[topOffset - 4 + i] = blk[i + (3 * WebpConstants.Bps)]; // Store future top samples. } if ((this.I4 & 3) != 3) @@ -568,7 +568,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy for (i = 0; i <= 2; ++i) { // store future left samples - top[topOffset + i] = blk[3 + ((2 - i) * WebPConstants.Bps)]; + top[topOffset + i] = blk[3 + ((2 - i) * WebpConstants.Bps)]; } } else @@ -706,7 +706,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { for (int x = 0; x < 4; ++x) { - avg += input[x + (y * WebPConstants.Bps)]; + avg += input[x + (y * WebpConstants.Bps)]; } } @@ -727,14 +727,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy dst.Slice(dstIdx, size - w).Fill(dst[dstIdx + w - 1]); } - dstIdx += WebPConstants.Bps; + dstIdx += WebpConstants.Bps; srcIdx += srcStride; } for (int i = h; i < size; ++i) { - dst.Slice(dstIdx - WebPConstants.Bps, size).CopyTo(dst); - dstIdx += WebPConstants.Bps; + dst.Slice(dstIdx - WebpConstants.Bps, size).CopyTo(dst); + dstIdx += WebpConstants.Bps; } } diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8EncProba.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8EncProba.cs index abc101c56..a39919d7f 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8EncProba.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8EncProba.cs @@ -3,7 +3,7 @@ using System; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal class Vp8EncProba { @@ -25,37 +25,37 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy this.Dirty = true; this.UseSkipProba = false; this.Segments = new byte[3]; - this.Coeffs = new Vp8BandProbas[WebPConstants.NumTypes][]; + this.Coeffs = new Vp8BandProbas[WebpConstants.NumTypes][]; for (int i = 0; i < this.Coeffs.Length; i++) { - this.Coeffs[i] = new Vp8BandProbas[WebPConstants.NumBands]; + this.Coeffs[i] = new Vp8BandProbas[WebpConstants.NumBands]; for (int j = 0; j < this.Coeffs[i].Length; j++) { this.Coeffs[i][j] = new Vp8BandProbas(); } } - this.Stats = new Vp8Stats[WebPConstants.NumTypes][]; + this.Stats = new Vp8Stats[WebpConstants.NumTypes][]; for (int i = 0; i < this.Coeffs.Length; i++) { - this.Stats[i] = new Vp8Stats[WebPConstants.NumBands]; + this.Stats[i] = new Vp8Stats[WebpConstants.NumBands]; for (int j = 0; j < this.Stats[i].Length; j++) { this.Stats[i][j] = new Vp8Stats(); } } - this.LevelCost = new Vp8CostArray[WebPConstants.NumTypes][]; + this.LevelCost = new Vp8CostArray[WebpConstants.NumTypes][]; for (int i = 0; i < this.LevelCost.Length; i++) { - this.LevelCost[i] = new Vp8CostArray[WebPConstants.NumBands]; + this.LevelCost[i] = new Vp8CostArray[WebpConstants.NumBands]; for (int j = 0; j < this.LevelCost[i].Length; j++) { this.LevelCost[i][j] = new Vp8CostArray(); } } - this.RemappedCosts = new Vp8CostArray[WebPConstants.NumTypes][]; + this.RemappedCosts = new Vp8CostArray[WebpConstants.NumTypes][]; for (int i = 0; i < this.RemappedCosts.Length; i++) { this.RemappedCosts[i] = new Vp8CostArray[16]; @@ -67,16 +67,16 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // Initialize with default probabilities. this.Segments.AsSpan().Fill(255); - for (int t = 0; t < WebPConstants.NumTypes; ++t) + for (int t = 0; t < WebpConstants.NumTypes; ++t) { - for (int b = 0; b < WebPConstants.NumBands; ++b) + for (int b = 0; b < WebpConstants.NumBands; ++b) { - for (int c = 0; c < WebPConstants.NumCtx; ++c) + for (int c = 0; c < WebpConstants.NumCtx; ++c) { Vp8ProbaArray dst = this.Coeffs[t][b].Probabilities[c]; - for (int p = 0; p < WebPConstants.NumProbas; ++p) + for (int p = 0; p < WebpConstants.NumProbas; ++p) { - dst.Probabilities[p] = WebPLookupTables.DefaultCoeffsProba[t, b, c, p]; + dst.Probabilities[p] = WebpLookupTables.DefaultCoeffsProba[t, b, c, p]; } } } @@ -123,11 +123,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy return; // nothing to do. } - for (int ctype = 0; ctype < WebPConstants.NumTypes; ++ctype) + for (int ctype = 0; ctype < WebpConstants.NumTypes; ++ctype) { - for (int band = 0; band < WebPConstants.NumBands; ++band) + for (int band = 0; band < WebpConstants.NumBands; ++band) { - for (int ctx = 0; ctx < WebPConstants.NumCtx; ++ctx) + for (int ctx = 0; ctx < WebpConstants.NumCtx; ++ctx) { Vp8ProbaArray p = this.Coeffs[ctype][band].Probabilities[ctx]; Span table = this.LevelCost[ctype][band].Costs.AsSpan(ctx * MaxVariableLevel); @@ -146,10 +146,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy for (int n = 0; n < 16; ++n) { - for (int ctx = 0; ctx < WebPConstants.NumCtx; ++ctx) + for (int ctx = 0; ctx < WebpConstants.NumCtx; ++ctx) { Span dst = this.RemappedCosts[ctype][n].Costs.AsSpan(ctx * MaxVariableLevel, MaxVariableLevel); - Span src = this.LevelCost[ctype][WebPConstants.Vp8EncBands[n]].Costs.AsSpan(ctx * MaxVariableLevel, MaxVariableLevel); + Span src = this.LevelCost[ctype][WebpConstants.Vp8EncBands[n]].Costs.AsSpan(ctx * MaxVariableLevel, MaxVariableLevel); src.CopyTo(dst); } } @@ -162,19 +162,19 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { bool hasChanged = false; int size = 0; - for (int t = 0; t < WebPConstants.NumTypes; ++t) + for (int t = 0; t < WebpConstants.NumTypes; ++t) { - for (int b = 0; b < WebPConstants.NumBands; ++b) + for (int b = 0; b < WebpConstants.NumBands; ++b) { - for (int c = 0; c < WebPConstants.NumCtx; ++c) + for (int c = 0; c < WebpConstants.NumCtx; ++c) { - for (int p = 0; p < WebPConstants.NumProbas; ++p) + for (int p = 0; p < WebpConstants.NumProbas; ++p) { var stats = this.Stats[t][b].Stats[c].Stats[p]; int nb = (int)((stats >> 0) & 0xffff); int total = (int)((stats >> 16) & 0xffff); - int updateProba = WebPLookupTables.CoeffsUpdateProba[t, b, c, p]; - int oldP = WebPLookupTables.DefaultCoeffsProba[t, b, c, p]; + int updateProba = WebpLookupTables.CoeffsUpdateProba[t, b, c, p]; + int oldP = WebpLookupTables.DefaultCoeffsProba[t, b, c, p]; int newP = CalcTokenProba(nb, total); int oldCost = BranchCost(nb, total, oldP) + LossyUtils.Vp8BitCost(0, (byte)updateProba); int newCost = BranchCost(nb, total, newP) + LossyUtils.Vp8BitCost(1, (byte)updateProba) + (8 * 256); @@ -219,13 +219,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy public void ResetTokenStats() { - for (int t = 0; t < WebPConstants.NumTypes; ++t) + for (int t = 0; t < WebpConstants.NumTypes; ++t) { - for (int b = 0; b < WebPConstants.NumBands; ++b) + for (int b = 0; b < WebpConstants.NumBands; ++b) { - for (int c = 0; c < WebPConstants.NumCtx; ++c) + for (int c = 0; c < WebpConstants.NumCtx; ++c) { - for (int p = 0; p < WebPConstants.NumProbas; ++p) + for (int p = 0; p < WebpConstants.NumProbas; ++p) { this.Stats[t][b].Stats[c].Stats[p] = 0; } @@ -241,8 +241,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy private static int VariableLevelCost(int level, Span probas) { - int pattern = WebPLookupTables.Vp8LevelCodes[level - 1][0]; - int bits = WebPLookupTables.Vp8LevelCodes[level - 1][1]; + int pattern = WebpLookupTables.Vp8LevelCodes[level - 1][0]; + int bits = WebpLookupTables.Vp8LevelCodes[level - 1][1]; int cost = 0; for (int i = 2; pattern != 0; ++i) { diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8EncSegmentHeader.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8EncSegmentHeader.cs index 0765efa78..37acc565e 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8EncSegmentHeader.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8EncSegmentHeader.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal class Vp8EncSegmentHeader { diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs index 817b760d1..333b845bc 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs @@ -6,11 +6,11 @@ using System.Buffers; using System.IO; using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Formats.Experimental.WebP.BitWriter; +using SixLabors.ImageSharp.Formats.Experimental.Webp.BitWriter; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Encoder for lossy webp images. @@ -115,9 +115,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // Convergence is considered reached if dq < DqLimit private const float DqLimit = 0.4f; - private const ulong Partition0SizeLimit = (WebPConstants.Vp8MaxPartition0Size - 2048UL) << 11; + private const ulong Partition0SizeLimit = (WebpConstants.Vp8MaxPartition0Size - 2048UL) << 11; - private const long HeaderSizeEstimate = WebPConstants.RiffHeaderSize + WebPConstants.ChunkHeaderSize + WebPConstants.Vp8FrameHeaderSize; + private const long HeaderSizeEstimate = WebpConstants.RiffHeaderSize + WebpConstants.ChunkHeaderSize + WebpConstants.Vp8FrameHeaderSize; private const int QMin = 0; @@ -355,7 +355,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy int uvStride = (yStride + 1) >> 1; var it = new Vp8EncIterator(this.YTop, this.UvTop, this.Nz, this.mbInfo, this.Preds, this.TopDerr, this.mbw, this.mbh); - var alphas = new int[WebPConstants.MaxAlpha + 1]; + var alphas = new int[WebpConstants.MaxAlpha + 1]; this.alpha = this.MacroBlockAnalysis(width, height, it, y, u, v, yStride, uvStride, alphas, out this.uvAlpha); int totalMb = this.mbw * this.mbw; this.alpha = this.alpha / totalMb; @@ -550,7 +550,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy if (FilterStrength > 0) { int maxLevel = 0; - for (int s = 0; s < WebPConstants.NumMbSegments; s++) + for (int s = 0; s < WebpConstants.NumMbSegments; s++) { Vp8SegmentInfo dqm = this.SegmentInfos[s]; @@ -600,18 +600,18 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy int nb = (this.segmentHeader.NumSegments < NumMbSegments) ? this.segmentHeader.NumSegments : NumMbSegments; var centers = new int[NumMbSegments]; int weightedAverage = 0; - var map = new int[WebPConstants.MaxAlpha + 1]; + var map = new int[WebpConstants.MaxAlpha + 1]; int a, n, k; var accum = new int[NumMbSegments]; var distAccum = new int[NumMbSegments]; // Bracket the input. - for (n = 0; n <= WebPConstants.MaxAlpha && alphas[n] == 0; ++n) + for (n = 0; n <= WebpConstants.MaxAlpha && alphas[n] == 0; ++n) { } var minA = n; - for (n = WebPConstants.MaxAlpha; n > minA && alphas[n] == 0; --n) + for (n = WebpConstants.MaxAlpha; n > minA && alphas[n] == 0; --n) { } @@ -730,7 +730,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy int nb = this.segmentHeader.NumSegments; Vp8SegmentInfo[] dqm = this.SegmentInfos; int snsStrength = 50; // TODO: Spatial Noise Shaping, hardcoded for now. - double amp = WebPConstants.SnsToDq * snsStrength / 100.0d / 128.0d; + double amp = WebpConstants.SnsToDq * snsStrength / 100.0d / 128.0d; double cBase = QualityToCompression(quality / 100.0d); for (int i = 0; i < nb; ++i) { @@ -748,13 +748,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // uvAlpha is normally spread around ~60. The useful range is // typically ~30 (quite bad) to ~100 (ok to decimate UV more). // We map it to the safe maximal range of MAX/MIN_DQ_UV for dq_uv. - this.dqUvAc = (this.uvAlpha - WebPConstants.QuantEncMidAlpha) * (WebPConstants.QuantEncMaxDqUv - WebPConstants.QuantEncMinDqUv) / (WebPConstants.QuantEncMaxAlpha - WebPConstants.QuantEncMinAlpha); + this.dqUvAc = (this.uvAlpha - WebpConstants.QuantEncMidAlpha) * (WebpConstants.QuantEncMaxDqUv - WebpConstants.QuantEncMinDqUv) / (WebpConstants.QuantEncMaxAlpha - WebpConstants.QuantEncMinAlpha); // We rescale by the user-defined strength of adaptation. this.dqUvAc = this.dqUvAc * snsStrength / 100; // and make it safe. - this.dqUvAc = Clip(this.dqUvAc, WebPConstants.QuantEncMinDqUv, WebPConstants.QuantEncMaxDqUv); + this.dqUvAc = Clip(this.dqUvAc, WebpConstants.QuantEncMinDqUv, WebpConstants.QuantEncMaxDqUv); // We also boost the dc-uv-quant a little, based on sns-strength, since // U/V channels are quite more reactive to high quants (flat DC-blocks @@ -779,17 +779,17 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // level0 is in [0..500]. Using '-f 50' as filter_strength is mid-filtering. int level0 = 5 * FilterStrength; - for (int i = 0; i < WebPConstants.NumMbSegments; ++i) + for (int i = 0; i < WebpConstants.NumMbSegments; ++i) { Vp8SegmentInfo m = this.SegmentInfos[i]; // We focus on the quantization of AC coeffs. - int qstep = WebPLookupTables.AcTable[Clip(m.Quant, 0, 127)] >> 2; + int qstep = WebpLookupTables.AcTable[Clip(m.Quant, 0, 127)] >> 2; int baseStrength = this.FilterStrengthFromDelta(this.filterHeader.Sharpness, qstep); // Segments with lower complexity ('beta') will be less filtered. int f = baseStrength * level0 / (256 + m.Beta); - m.FStrength = (f < WebPConstants.FilterStrengthCutoff) ? 0 : (f > 63) ? 63 : f; + m.FStrength = (f < WebpConstants.FilterStrengthCutoff) ? 0 : (f > 63) ? 63 : f; } // We record the initial strength (mainly for the case of 1-segment only). @@ -861,14 +861,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy m.Y2 = new Vp8Matrix(); m.Uv = new Vp8Matrix(); - m.Y1.Q[0] = WebPLookupTables.DcTable[Clip(q, 0, 127)]; - m.Y1.Q[1] = WebPLookupTables.AcTable[Clip(q, 0, 127)]; + m.Y1.Q[0] = WebpLookupTables.DcTable[Clip(q, 0, 127)]; + m.Y1.Q[1] = WebpLookupTables.AcTable[Clip(q, 0, 127)]; - m.Y2.Q[0] = (ushort)(WebPLookupTables.DcTable[Clip(q, 0, 127)] * 2); - m.Y2.Q[1] = WebPLookupTables.AcTable2[Clip(q, 0, 127)]; + m.Y2.Q[0] = (ushort)(WebpLookupTables.DcTable[Clip(q, 0, 127)] * 2); + m.Y2.Q[1] = WebpLookupTables.AcTable2[Clip(q, 0, 127)]; - m.Uv.Q[0] = WebPLookupTables.DcTable[Clip(q + this.dqUvDc, 0, 117)]; - m.Uv.Q[1] = WebPLookupTables.AcTable[Clip(q + this.dqUvAc, 0, 127)]; + m.Uv.Q[0] = WebpLookupTables.DcTable[Clip(q + this.dqUvDc, 0, 117)]; + m.Uv.Q[1] = WebpLookupTables.AcTable[Clip(q + this.dqUvAc, 0, 127)]; var qi4 = m.Y1.Expand(0); var qi16 = m.Y2.Expand(1); @@ -974,9 +974,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy for (mode = 0; mode < numPredModes; ++mode) { Span reference = it.YuvP.AsSpan(Vp8Encoding.Vp8I16ModeOffsets[mode]); - long score = (Vp8Sse16X16(src, reference) * WebPConstants.RdDistoMult) + (WebPConstants.Vp8FixedCostsI16[mode] * lambdaDi16); + long score = (Vp8Sse16X16(src, reference) * WebpConstants.RdDistoMult) + (WebpConstants.Vp8FixedCostsI16[mode] * lambdaDi16); - if (mode > 0 && WebPConstants.Vp8FixedCostsI16[mode] > bitLimit) + if (mode > 0 && WebpConstants.Vp8FixedCostsI16[mode] > bitLimit) { continue; } @@ -1014,14 +1014,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { int bestI4Mode = -1; long bestI4Score = Vp8ModeScore.MaxCost; - Span src = it.YuvIn.AsSpan(Vp8EncIterator.YOffEnc + WebPLookupTables.Vp8Scan[it.I4]); + Span src = it.YuvIn.AsSpan(Vp8EncIterator.YOffEnc + WebpLookupTables.Vp8Scan[it.I4]); short[] modeCosts = it.GetCostModeI4(rd.ModesI4); it.MakeIntra4Preds(); for (mode = 0; mode < numBModes; ++mode) { Span reference = it.YuvP.AsSpan(Vp8Encoding.Vp8I4ModeOffsets[mode]); - long score = (Vp8Sse4X4(src, reference) * WebPConstants.RdDistoMult) + (modeCosts[mode] * lambdaDi4); + long score = (Vp8Sse4X4(src, reference) * WebpConstants.RdDistoMult) + (modeCosts[mode] * lambdaDi4); if (score < bestI4Score) { bestI4Mode = mode; @@ -1041,7 +1041,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy else { // Reconstruct partial block inside YuvOut2 buffer - Span tmpDst = it.YuvOut2.AsSpan(Vp8EncIterator.YOffEnc + WebPLookupTables.Vp8Scan[it.I4]); + Span tmpDst = it.YuvOut2.AsSpan(Vp8EncIterator.YOffEnc + WebpLookupTables.Vp8Scan[it.I4]); nz |= this.ReconstructIntra4(it, dqm, rd.YAcLevels.AsSpan(it.I4 * 16, 16), src, tmpDst, bestI4Mode) << it.I4; } } @@ -1070,7 +1070,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy for (mode = 0; mode < numPredModes; ++mode) { Span reference = it.YuvP.AsSpan(Vp8Encoding.Vp8UvModeOffsets[mode]); - long score = (Vp8Sse16X8(src, reference) * WebPConstants.RdDistoMult) + (WebPConstants.Vp8FixedCostsUv[mode] * lambdaDuv); + long score = (Vp8Sse16X8(src, reference) * WebpConstants.RdDistoMult) + (WebpConstants.Vp8FixedCostsUv[mode] * lambdaDuv); if (score < bestUvScore) { bestMode = mode; @@ -1222,7 +1222,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy for (n = 0; n < 16; n += 2) { - Vp8Encoding.FTransform2(src.Slice(WebPLookupTables.Vp8Scan[n]), reference.Slice(WebPLookupTables.Vp8Scan[n]), tmpSpan.Slice(n * 16, 16), tmpSpan.Slice((n + 1) * 16, 16)); + Vp8Encoding.FTransform2(src.Slice(WebpLookupTables.Vp8Scan[n]), reference.Slice(WebpLookupTables.Vp8Scan[n]), tmpSpan.Slice(n * 16, 16), tmpSpan.Slice((n + 1) * 16, 16)); } Vp8Encoding.FTransformWht(tmp, dcTmp); @@ -1240,7 +1240,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy LossyUtils.TransformWht(dcTmp, tmpSpan); for (n = 0; n < 16; n += 2) { - Vp8Encoding.ITransform(reference.Slice(WebPLookupTables.Vp8Scan[n]), tmpSpan.Slice(n * 16, 32), yuvOut.Slice(WebPLookupTables.Vp8Scan[n]), true); + Vp8Encoding.ITransform(reference.Slice(WebpLookupTables.Vp8Scan[n]), tmpSpan.Slice(n * 16, 32), yuvOut.Slice(WebpLookupTables.Vp8Scan[n]), true); } return nz; @@ -1268,8 +1268,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy for (n = 0; n < 8; n += 2) { Vp8Encoding.FTransform2( - src.Slice(WebPLookupTables.Vp8ScanUv[n]), - reference.Slice(WebPLookupTables.Vp8ScanUv[n]), + src.Slice(WebpLookupTables.Vp8ScanUv[n]), + reference.Slice(WebpLookupTables.Vp8ScanUv[n]), tmp.AsSpan(n * 16, 16), tmp.AsSpan((n + 1) * 16, 16)); } @@ -1283,7 +1283,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy for (n = 0; n < 8; n += 2) { - Vp8Encoding.ITransform(reference.Slice(WebPLookupTables.Vp8ScanUv[n]), tmp.AsSpan(n * 16, 32), yuvOut.Slice(WebPLookupTables.Vp8ScanUv[n]), true); + Vp8Encoding.ITransform(reference.Slice(WebpLookupTables.Vp8ScanUv[n]), tmp.AsSpan(n * 16, 32), yuvOut.Slice(WebpLookupTables.Vp8ScanUv[n]), true); } return nz << 16; @@ -1346,8 +1346,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy [MethodImpl(InliningOptions.ShortMethod)] private static int FinalAlphaValue(int alpha) { - alpha = WebPConstants.MaxAlpha - alpha; - return Clip(alpha, 0, WebPConstants.MaxAlpha); + alpha = WebpConstants.MaxAlpha - alpha; + return Clip(alpha, 0, WebpConstants.MaxAlpha); } [MethodImpl(InliningOptions.ShortMethod)] @@ -1387,8 +1387,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy count += diff * diff; } - aOffset += WebPConstants.Bps; - bOffset += WebPConstants.Bps; + aOffset += WebpConstants.Bps; + bOffset += WebpConstants.Bps; } return count; @@ -1407,7 +1407,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy return false; } - src = src.Slice(WebPConstants.Bps); + src = src.Slice(WebpConstants.Bps); } return true; @@ -1435,8 +1435,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy private int FilterStrengthFromDelta(int sharpness, int delta) { - int pos = (delta < WebPConstants.MaxDelzaSize) ? delta : WebPConstants.MaxDelzaSize - 1; - return WebPLookupTables.LevelsFromDelta[sharpness, pos]; + int pos = (delta < WebpConstants.MaxDelzaSize) ? delta : WebpConstants.MaxDelzaSize - 1; + return WebpLookupTables.LevelsFromDelta[sharpness, pos]; } [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoding.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoding.cs index e20683b12..e2cad7faf 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoding.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoding.cs @@ -5,7 +5,7 @@ using System; using System.Buffers.Binary; using System.Runtime.CompilerServices; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Methods for encoding a VP8 frame. @@ -18,19 +18,19 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy private static readonly byte[] Clip1 = new byte[255 + 510 + 1]; // clips [-255,510] to [0,255] - private const int I16DC16 = 0 * 16 * WebPConstants.Bps; + private const int I16DC16 = 0 * 16 * WebpConstants.Bps; private const int I16TM16 = I16DC16 + 16; - private const int I16VE16 = 1 * 16 * WebPConstants.Bps; + private const int I16VE16 = 1 * 16 * WebpConstants.Bps; private const int I16HE16 = I16VE16 + 16; - private const int C8DC8 = 2 * 16 * WebPConstants.Bps; + private const int C8DC8 = 2 * 16 * WebpConstants.Bps; private const int C8TM8 = C8DC8 + (1 * 16); - private const int C8VE8 = (2 * 16 * WebPConstants.Bps) + (8 * WebPConstants.Bps); + private const int C8VE8 = (2 * 16 * WebpConstants.Bps) + (8 * WebpConstants.Bps); private const int C8HE8 = C8VE8 + (1 * 16); @@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy public static readonly int[] Vp8UvModeOffsets = { C8DC8, C8TM8, C8VE8, C8HE8 }; - private const int I4DC4 = (3 * 16 * WebPConstants.Bps) + 0; + private const int I4DC4 = (3 * 16 * WebpConstants.Bps) + 0; private const int I4TM4 = I4DC4 + 4; @@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy private const int I4VL4 = I4DC4 + 28; - private const int I4HD4 = (3 * 16 * WebPConstants.Bps) + (4 * WebPConstants.Bps); + private const int I4HD4 = (3 * 16 * WebpConstants.Bps) + (4 * WebpConstants.Bps); private const int I4HU4 = I4HD4 + 4; @@ -143,8 +143,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy tmp[2 + (i * 4)] = (a0 - a1) * 8; tmp[3 + (i * 4)] = ((a3 * 2217) - (a2 * 5352) + 937) >> 9; - srcIdx += WebPConstants.Bps; - refIdx += WebPConstants.Bps; + srcIdx += WebpConstants.Bps; + refIdx += WebpConstants.Bps; } for (i = 0; i < 4; ++i) @@ -254,7 +254,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { for (int j = 0; j < size; ++j) { - top.Slice(0, size).CopyTo(dst.Slice(j * WebPConstants.Bps)); + top.Slice(0, size).CopyTo(dst.Slice(j * WebpConstants.Bps)); } } else @@ -270,7 +270,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy left = left.Slice(1); // in the reference implementation, left starts at - 1. for (int j = 0; j < size; ++j) { - dst.Slice(j * WebPConstants.Bps, size).Fill(left[j]); + dst.Slice(j * WebpConstants.Bps, size).Fill(left[j]); } } else @@ -294,7 +294,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy dst[x] = clipTable[top[x]]; } - dst = dst.Slice(WebPConstants.Bps); + dst = dst.Slice(WebpConstants.Bps); } } else @@ -391,7 +391,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy dst[x] = clipTable[top[topOffset + x]]; } - dst = dst.Slice(WebPConstants.Bps); + dst = dst.Slice(WebpConstants.Bps); } } @@ -408,7 +408,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy for (int i = 0; i < 4; ++i) { - vals.AsSpan().CopyTo(dst.Slice(i * WebPConstants.Bps)); + vals.AsSpan().CopyTo(dst.Slice(i * WebpConstants.Bps)); } } @@ -424,11 +424,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy uint val = 0x01010101U * LossyUtils.Avg3(x, i, j); BinaryPrimitives.WriteUInt32BigEndian(dst, val); val = 0x01010101U * LossyUtils.Avg3(i, j, k); - BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(1 * WebPConstants.Bps), val); + BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(1 * WebpConstants.Bps), val); val = 0x01010101U * LossyUtils.Avg3(j, k, l); - BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(2 * WebPConstants.Bps), val); + BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(2 * WebpConstants.Bps), val); val = 0x01010101U * LossyUtils.Avg3(k, l, l); - BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(3 * WebPConstants.Bps), val); + BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(3 * WebpConstants.Bps), val); } private static void Rd4(Span dst, Span top, int topOffset) @@ -639,7 +639,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { for (int j = 0; j < size; ++j) { - dst.Slice(j * WebPConstants.Bps, size).Fill((byte)value); + dst.Slice(j * WebpConstants.Bps, size).Fill((byte)value); } } @@ -652,7 +652,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy [MethodImpl(InliningOptions.ShortMethod)] private static void Store(Span dst, Span reference, int x, int y, int v) { - dst[x + (y * WebPConstants.Bps)] = LossyUtils.Clip8B(reference[x + (y * WebPConstants.Bps)] + (v >> 3)); + dst[x + (y * WebpConstants.Bps)] = LossyUtils.Clip8B(reference[x + (y * WebpConstants.Bps)] + (v >> 3)); } [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8FilterHeader.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8FilterHeader.cs index 0710b6fab..67dbb0baf 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8FilterHeader.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8FilterHeader.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal class Vp8FilterHeader { diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8FilterInfo.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8FilterInfo.cs index 4ae39f710..d7155d3e6 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8FilterInfo.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8FilterInfo.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Filter information. diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8FrameHeader.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8FrameHeader.cs index 07541ca0d..2cef291b7 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8FrameHeader.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8FrameHeader.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Vp8 frame header information. diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8Io.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8Io.cs index 65b823b31..ead8bd573 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8Io.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8Io.cs @@ -3,7 +3,7 @@ using System; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal ref struct Vp8Io { diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlock.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlock.cs index b6de2aa8a..76a9b76f7 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlock.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlock.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Contextual macroblock information. diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlockData.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlockData.cs index c46f4f116..b955cac6a 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlockData.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlockData.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Data needed to reconstruct a macroblock. diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlockInfo.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlockInfo.cs index 910ead4fd..4e22b5f58 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlockInfo.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlockInfo.cs @@ -3,7 +3,7 @@ using System.Diagnostics; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { [DebuggerDisplay("Type: {MacroBlockType}, Alpha: {Alpha}, UvMode: {UvMode}")] internal class Vp8MacroBlockInfo diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlockType.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlockType.cs index 65306a0e1..a9325693f 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlockType.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8MacroBlockType.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal enum Vp8MacroBlockType { diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8Matrix.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8Matrix.cs index a2bacefe8..7ceb2ed1d 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8Matrix.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8Matrix.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal class Vp8Matrix { @@ -71,13 +71,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { int isAcCoeff = (i > 0) ? 1 : 0; int bias = BiasMatrices[type][isAcCoeff]; - this.IQ[i] = (ushort)((1 << WebPConstants.QFix) / this.Q[i]); + this.IQ[i] = (ushort)((1 << WebpConstants.QFix) / this.Q[i]); this.Bias[i] = (uint)this.BIAS(bias); // zthresh is the exact value such that QUANTDIV(coeff, iQ, B) is: // * zero if coeff <= zthresh // * non-zero if coeff > zthresh - this.ZThresh[i] = ((1 << WebPConstants.QFix) - 1 - this.Bias[i]) / this.IQ[i]; + this.ZThresh[i] = ((1 << WebpConstants.QFix) - 1 - this.Bias[i]) / this.IQ[i]; } for (i = 2; i < 16; ++i) @@ -108,7 +108,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy private int BIAS(int b) { - return b << (WebPConstants.QFix - 8); + return b << (WebpConstants.QFix - 8); } } } diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8ModeScore.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8ModeScore.cs index 1abf06855..a5360707b 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8ModeScore.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8ModeScore.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Class to accumulate score and info during RD-optimization and mode evaluation. diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8PictureHeader.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8PictureHeader.cs index 697016a87..020ff07a3 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8PictureHeader.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8PictureHeader.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal class Vp8PictureHeader { diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8Proba.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8Proba.cs index 718ca7ded..3d37c2018 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8Proba.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8Proba.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Data for all frame-persistent probabilities. @@ -16,18 +16,18 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy public Vp8Proba() { this.Segments = new uint[MbFeatureTreeProbs]; - this.Bands = new Vp8BandProbas[WebPConstants.NumTypes, WebPConstants.NumBands]; - this.BandsPtr = new Vp8BandProbas[WebPConstants.NumTypes][]; + this.Bands = new Vp8BandProbas[WebpConstants.NumTypes, WebpConstants.NumBands]; + this.BandsPtr = new Vp8BandProbas[WebpConstants.NumTypes][]; - for (int i = 0; i < WebPConstants.NumTypes; i++) + for (int i = 0; i < WebpConstants.NumTypes; i++) { - for (int j = 0; j < WebPConstants.NumBands; j++) + for (int j = 0; j < WebpConstants.NumBands; j++) { this.Bands[i, j] = new Vp8BandProbas(); } } - for (int i = 0; i < WebPConstants.NumTypes; i++) + for (int i = 0; i < WebpConstants.NumTypes; i++) { this.BandsPtr[i] = new Vp8BandProbas[16 + 1]; } diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8ProbaArray.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8ProbaArray.cs index 73614da13..30e1f79ee 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8ProbaArray.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8ProbaArray.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Probabilities associated to one of the contexts. @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy /// public Vp8ProbaArray() { - this.Probabilities = new byte[WebPConstants.NumProbas]; + this.Probabilities = new byte[WebpConstants.NumProbas]; } /// diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8QuantMatrix.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8QuantMatrix.cs index e3b3e9b0f..435631aae 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8QuantMatrix.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8QuantMatrix.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal class Vp8QuantMatrix { diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8RDLevel.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8RDLevel.cs index 067a38379..4b937b813 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8RDLevel.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8RDLevel.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Rate-distortion optimization levels diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8Residual.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8Residual.cs index efba2df7d..f980bd3b9 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8Residual.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8Residual.cs @@ -3,7 +3,7 @@ using System; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// On-the-fly info about the current set of residuals. @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy while ((v = this.Coeffs[n++]) == 0) { this.RecordStats(0, s, 1); - s = this.Stats[WebPConstants.Vp8EncBands[n]].Stats[0]; + s = this.Stats[WebpConstants.Vp8EncBands[n]].Stats[0]; } this.RecordStats(1, s, 1); @@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy if (this.RecordStats(bit ? 1 : 0, s, 2) == 0) { // v = -1 or 1 - s = this.Stats[WebPConstants.Vp8EncBands[n]].Stats[1]; + s = this.Stats[WebpConstants.Vp8EncBands[n]].Stats[1]; } else { @@ -88,8 +88,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy v = MaxVariableLevel; } - int bits = WebPLookupTables.Vp8LevelCodes[v - 1][1]; - int pattern = WebPLookupTables.Vp8LevelCodes[v - 1][0]; + int bits = WebpLookupTables.Vp8LevelCodes[v - 1][1]; + int pattern = WebpLookupTables.Vp8LevelCodes[v - 1][0]; int i; for (i = 0; (pattern >>= 1) != 0; ++i) { @@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy } } - s = this.Stats[WebPConstants.Vp8EncBands[n]].Stats[2]; + s = this.Stats[WebpConstants.Vp8EncBands[n]].Stats[2]; } } diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8SegmentHeader.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8SegmentHeader.cs index 1ea12d51e..96f1fbd60 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8SegmentHeader.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8SegmentHeader.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Segment features. diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8SegmentInfo.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8SegmentInfo.cs index 2feb9384b..cbf946b9f 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8SegmentInfo.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8SegmentInfo.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal class Vp8SegmentInfo { diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8Stats.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8Stats.cs index e4a463751..336124378 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8Stats.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8Stats.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal class Vp8Stats { @@ -10,8 +10,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy /// public Vp8Stats() { - this.Stats = new Vp8StatsArray[WebPConstants.NumCtx]; - for (int i = 0; i < WebPConstants.NumCtx; i++) + this.Stats = new Vp8StatsArray[WebpConstants.NumCtx]; + for (int i = 0; i < WebpConstants.NumCtx; i++) { this.Stats[i] = new Vp8StatsArray(); } diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8StatsArray.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8StatsArray.cs index 6681c23bb..34e7d6733 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8StatsArray.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8StatsArray.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal class Vp8StatsArray { @@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy /// public Vp8StatsArray() { - this.Stats = new uint[WebPConstants.NumProbas]; + this.Stats = new uint[WebpConstants.NumProbas]; } public uint[] Stats { get; } diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8TopSamples.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8TopSamples.cs index 1b696dd3a..a74231ff1 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8TopSamples.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8TopSamples.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal class Vp8TopSamples { diff --git a/src/ImageSharp/Formats/WebP/Lossy/WebPLossyDecoder.cs b/src/ImageSharp/Formats/WebP/Lossy/WebPLossyDecoder.cs index bc3e76231..cd501c45a 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/WebPLossyDecoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/WebPLossyDecoder.cs @@ -6,11 +6,11 @@ using System.Buffers; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats.Experimental.WebP.BitReader; +using SixLabors.ImageSharp.Formats.Experimental.Webp.BitReader; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { /// /// Decoder for lossy webp images. This code is a port of libwebp, which can be found here: https://chromium.googlesource.com/webm/libwebp @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy this.configuration = configuration; } - public void Decode(Buffer2D pixels, int width, int height, WebPImageInfo info) + public void Decode(Buffer2D pixels, int width, int height, WebpImageInfo info) where TPixel : unmanaged, IPixel { // Paragraph 9.2: color space and clamp type follow. @@ -227,11 +227,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy int yMode = left[y]; for (int x = 0; x < 4; ++x) { - byte[] prob = WebPLookupTables.ModesProba[top[x], yMode]; - int i = WebPConstants.YModesIntra4[this.bitReader.GetBit(prob[0])]; + byte[] prob = WebpLookupTables.ModesProba[top[x], yMode]; + int i = WebpConstants.YModesIntra4[this.bitReader.GetBit(prob[0])]; while (i > 0) { - i = WebPConstants.YModesIntra4[(2 * i) + this.bitReader.GetBit(prob[i])]; + i = WebpConstants.YModesIntra4[(2 * i) + this.bitReader.GetBit(prob[i])]; } yMode = -i; @@ -272,8 +272,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy private void ReconstructRow(Vp8Decoder dec) { int mby = dec.MbY; - const int yOff = (WebPConstants.Bps * 1) + 8; - const int uOff = yOff + (WebPConstants.Bps * 16) + WebPConstants.Bps; + const int yOff = (WebpConstants.Bps * 1) + 8; + const int uOff = yOff + (WebpConstants.Bps * 16) + WebpConstants.Bps; const int vOff = uOff + 16; Span yuv = dec.YuvBuffer.Memory.Span; @@ -282,14 +282,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy Span vDst = yuv.Slice(vOff); // Initialize left-most block. - var end = 16 * WebPConstants.Bps; - for (int i = 0; i < end; i += WebPConstants.Bps) + var end = 16 * WebpConstants.Bps; + for (int i = 0; i < end; i += WebpConstants.Bps) { yuv[i - 1 + yOff] = 129; } - end = 8 * WebPConstants.Bps; - for (int i = 0; i < end; i += WebPConstants.Bps) + end = 8 * WebpConstants.Bps; + for (int i = 0; i < end; i += WebpConstants.Bps) { yuv[i - 1 + uOff] = 129; yuv[i - 1 + vOff] = 129; @@ -298,25 +298,25 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // Init top-left sample on left column too. if (mby > 0) { - yuv[yOff - 1 - WebPConstants.Bps] = yuv[uOff - 1 - WebPConstants.Bps] = yuv[vOff - 1 - WebPConstants.Bps] = 129; + yuv[yOff - 1 - WebpConstants.Bps] = yuv[uOff - 1 - WebpConstants.Bps] = yuv[vOff - 1 - WebpConstants.Bps] = 129; } else { // We only need to do this init once at block (0,0). // Afterward, it remains valid for the whole topmost row. - Span tmp = yuv.Slice(yOff - WebPConstants.Bps - 1, 16 + 4 + 1); + Span tmp = yuv.Slice(yOff - WebpConstants.Bps - 1, 16 + 4 + 1); for (int i = 0; i < tmp.Length; ++i) { tmp[i] = 127; } - tmp = yuv.Slice(uOff - WebPConstants.Bps - 1, 8 + 1); + tmp = yuv.Slice(uOff - WebpConstants.Bps - 1, 8 + 1); for (int i = 0; i < tmp.Length; ++i) { tmp[i] = 127; } - tmp = yuv.Slice(vOff - WebPConstants.Bps - 1, 8 + 1); + tmp = yuv.Slice(vOff - WebpConstants.Bps - 1, 8 + 1); for (int i = 0; i < tmp.Length; ++i) { tmp[i] = 127; @@ -334,18 +334,18 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { for (int i = -1; i < 16; ++i) { - int srcIdx = (i * WebPConstants.Bps) + 12 + yOff; - int dstIdx = (i * WebPConstants.Bps) - 4 + yOff; + int srcIdx = (i * WebpConstants.Bps) + 12 + yOff; + int dstIdx = (i * WebpConstants.Bps) - 4 + yOff; yuv.Slice(srcIdx, 4).CopyTo(yuv.Slice(dstIdx)); } for (int i = -1; i < 8; ++i) { - int srcIdx = (i * WebPConstants.Bps) + 4 + uOff; - int dstIdx = (i * WebPConstants.Bps) - 4 + uOff; + int srcIdx = (i * WebpConstants.Bps) + 4 + uOff; + int dstIdx = (i * WebpConstants.Bps) - 4 + uOff; yuv.Slice(srcIdx, 4).CopyTo(yuv.Slice(dstIdx)); - srcIdx = (i * WebPConstants.Bps) + 4 + vOff; - dstIdx = (i * WebPConstants.Bps) - 4 + vOff; + srcIdx = (i * WebpConstants.Bps) + 4 + vOff; + dstIdx = (i * WebpConstants.Bps) - 4 + vOff; yuv.Slice(srcIdx, 4).CopyTo(yuv.Slice(dstIdx)); } } @@ -356,15 +356,15 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy uint bits = block.NonZeroY; if (mby > 0) { - topYuv.Y.CopyTo(yuv.Slice(yOff - WebPConstants.Bps)); - topYuv.U.CopyTo(yuv.Slice(uOff - WebPConstants.Bps)); - topYuv.V.CopyTo(yuv.Slice(vOff - WebPConstants.Bps)); + topYuv.Y.CopyTo(yuv.Slice(yOff - WebpConstants.Bps)); + topYuv.U.CopyTo(yuv.Slice(uOff - WebpConstants.Bps)); + topYuv.V.CopyTo(yuv.Slice(vOff - WebpConstants.Bps)); } // Predict and add residuals. if (block.IsI4x4) { - Span topRight = yuv.Slice(yOff - WebPConstants.Bps + 16); + Span topRight = yuv.Slice(yOff - WebpConstants.Bps + 16); if (mby > 0) { if (mbx >= dec.MbWidth - 1) @@ -383,13 +383,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy } // Replicate the top-right pixels below. - Span topRightUint = MemoryMarshal.Cast(yuv.Slice(yOff - WebPConstants.Bps + 16)); - topRightUint[WebPConstants.Bps] = topRightUint[2 * WebPConstants.Bps] = topRightUint[3 * WebPConstants.Bps] = topRightUint[0]; + Span topRightUint = MemoryMarshal.Cast(yuv.Slice(yOff - WebpConstants.Bps + 16)); + topRightUint[WebpConstants.Bps] = topRightUint[2 * WebpConstants.Bps] = topRightUint[3 * WebpConstants.Bps] = topRightUint[0]; // Predict and add residuals for all 4x4 blocks in turn. for (int n = 0; n < 16; ++n, bits <<= 2) { - int offset = yOff + WebPConstants.Scan[n]; + int offset = yOff + WebpConstants.Scan[n]; Span dst = yuv.Slice(offset); byte lumaMode = block.Modes[n]; switch (lumaMode) @@ -462,7 +462,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { for (int n = 0; n < 16; ++n, bits <<= 2) { - this.DoTransform(bits, coeffs.AsSpan(n * 16), yDst.Slice(WebPConstants.Scan[n])); + this.DoTransform(bits, coeffs.AsSpan(n * 16), yDst.Slice(WebpConstants.Scan[n])); } } } @@ -508,9 +508,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy // Stash away top samples for next block. if (mby < dec.MbHeight - 1) { - yDst.Slice(15 * WebPConstants.Bps, 16).CopyTo(topYuv.Y); - uDst.Slice(7 * WebPConstants.Bps, 8).CopyTo(topYuv.U); - vDst.Slice(7 * WebPConstants.Bps, 8).CopyTo(topYuv.V); + yDst.Slice(15 * WebpConstants.Bps, 16).CopyTo(topYuv.Y); + uDst.Slice(7 * WebpConstants.Bps, 8).CopyTo(topYuv.U); + vDst.Slice(7 * WebpConstants.Bps, 8).CopyTo(topYuv.V); } // Transfer reconstructed samples from yuv_buffer cache to final destination. @@ -519,14 +519,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy Span vOut = dec.CacheV.Memory.Span.Slice(dec.CacheUvOffset + (mbx * 8)); for (int j = 0; j < 16; ++j) { - yDst.Slice(j * WebPConstants.Bps, Math.Min(16, yOut.Length)).CopyTo(yOut.Slice(j * dec.CacheYStride)); + yDst.Slice(j * WebpConstants.Bps, Math.Min(16, yOut.Length)).CopyTo(yOut.Slice(j * dec.CacheYStride)); } for (int j = 0; j < 8; ++j) { int jUvStride = j * dec.CacheUvStride; - uDst.Slice(j * WebPConstants.Bps, Math.Min(8, uOut.Length)).CopyTo(uOut.Slice(jUvStride)); - vDst.Slice(j * WebPConstants.Bps, Math.Min(8, vOut.Length)).CopyTo(vOut.Slice(jUvStride)); + uDst.Slice(j * WebpConstants.Bps, Math.Min(8, uOut.Length)).CopyTo(uOut.Slice(jUvStride)); + vDst.Slice(j * WebpConstants.Bps, Math.Min(8, vOut.Length)).CopyTo(vOut.Slice(jUvStride)); } } } @@ -609,7 +609,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy private void FinishRow(Vp8Decoder dec, Vp8Io io) { - int extraYRows = WebPConstants.FilterExtraRows[(int)dec.Filter]; + int extraYRows = WebpConstants.FilterExtraRows[(int)dec.Filter]; int ySize = extraYRows * dec.CacheYStride; int uvSize = (extraYRows / 2) * dec.CacheUvStride; Span yDst = dec.CacheY.Memory.Span; @@ -1008,7 +1008,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy } int idx = n > 0 ? 1 : 0; - coeffs[WebPConstants.Zigzag[n]] = (short)(br.GetSigned(v) * dq[idx]); + coeffs[WebpConstants.Zigzag[n]] = (short)(br.GetSigned(v) * dq[idx]); } return 16; @@ -1053,19 +1053,19 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy switch (cat) { case 0: - tab = WebPConstants.Cat3; + tab = WebpConstants.Cat3; break; case 1: - tab = WebPConstants.Cat4; + tab = WebpConstants.Cat4; break; case 2: - tab = WebPConstants.Cat5; + tab = WebpConstants.Cat5; break; case 3: - tab = WebPConstants.Cat6; + tab = WebpConstants.Cat6; break; default: - WebPThrowHelper.ThrowImageFormatException("VP8 parsing error"); + WebpThrowHelper.ThrowImageFormatException("VP8 parsing error"); break; } @@ -1162,7 +1162,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy } } - int extraRows = WebPConstants.FilterExtraRows[(int)dec.Filter]; + int extraRows = WebpConstants.FilterExtraRows[(int)dec.Filter]; int extraY = extraRows * dec.CacheYStride; int extraUv = (extraRows / 2) * dec.CacheUvStride; dec.CacheYOffset = extraY; @@ -1213,7 +1213,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy int dquvDc = hasValue ? this.bitReader.ReadSignedValue(4) : 0; hasValue = this.bitReader.ReadBool(); int dquvAc = hasValue ? this.bitReader.ReadSignedValue(4) : 0; - for (int i = 0; i < WebPConstants.NumMbSegments; ++i) + for (int i = 0; i < WebpConstants.NumMbSegments; ++i) { int q; if (vp8SegmentHeader.UseSegment) @@ -1238,20 +1238,20 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy } Vp8QuantMatrix m = decoder.DeQuantMatrices[i]; - m.Y1Mat[0] = WebPLookupTables.DcTable[Clip(q + dqy1Dc, 127)]; - m.Y1Mat[1] = WebPLookupTables.AcTable[Clip(q + 0, 127)]; - m.Y2Mat[0] = WebPLookupTables.DcTable[Clip(q + dqy2Dc, 127)] * 2; + m.Y1Mat[0] = WebpLookupTables.DcTable[Clip(q + dqy1Dc, 127)]; + m.Y1Mat[1] = WebpLookupTables.AcTable[Clip(q + 0, 127)]; + m.Y2Mat[0] = WebpLookupTables.DcTable[Clip(q + dqy2Dc, 127)] * 2; // For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16. // The smallest precision for that is '(x*6349) >> 12' but 16 is a good word size. - m.Y2Mat[1] = (WebPLookupTables.AcTable[Clip(q + dqy2Ac, 127)] * 101581) >> 16; + m.Y2Mat[1] = (WebpLookupTables.AcTable[Clip(q + dqy2Ac, 127)] * 101581) >> 16; if (m.Y2Mat[1] < 8) { m.Y2Mat[1] = 8; } - m.UvMat[0] = WebPLookupTables.DcTable[Clip(q + dquvDc, 117)]; - m.UvMat[1] = WebPLookupTables.AcTable[Clip(q + dquvAc, 127)]; + m.UvMat[0] = WebpLookupTables.DcTable[Clip(q + dquvDc, 117)]; + m.UvMat[1] = WebpLookupTables.AcTable[Clip(q + dquvAc, 127)]; // For dithering strength evaluation. m.UvQuant = q + dquvAc; @@ -1262,18 +1262,18 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy { Vp8Proba proba = dec.Probabilities; - for (int t = 0; t < WebPConstants.NumTypes; ++t) + for (int t = 0; t < WebpConstants.NumTypes; ++t) { - for (int b = 0; b < WebPConstants.NumBands; ++b) + for (int b = 0; b < WebpConstants.NumBands; ++b) { - for (int c = 0; c < WebPConstants.NumCtx; ++c) + for (int c = 0; c < WebpConstants.NumCtx; ++c) { - for (int p = 0; p < WebPConstants.NumProbas; ++p) + for (int p = 0; p < WebpConstants.NumProbas; ++p) { - byte prob = WebPLookupTables.CoeffsUpdateProba[t, b, c, p]; + byte prob = WebpLookupTables.CoeffsUpdateProba[t, b, c, p]; byte v = (byte)(this.bitReader.GetBit(prob) != 0 ? this.bitReader.ReadValue(8) - : WebPLookupTables.DefaultCoeffsProba[t, b, c, p]); + : WebpLookupTables.DefaultCoeffsProba[t, b, c, p]); proba.Bands[t, b].Probabilities[c].Probabilities[p] = v; } } @@ -1281,7 +1281,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy for (int b = 0; b < 16 + 1; ++b) { - proba.BandsPtr[t][b] = proba.Bands[t, WebPConstants.Vp8EncBands[b]]; + proba.BandsPtr[t][b] = proba.Bands[t, WebpConstants.Vp8EncBands[b]]; } } @@ -1309,7 +1309,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy int intraPredModeSize = 4 * dec.MbWidth; dec.IntraT = new byte[intraPredModeSize]; - int extraPixels = WebPConstants.FilterExtraRows[(int)dec.Filter]; + int extraPixels = WebpConstants.FilterExtraRows[(int)dec.Filter]; if (dec.Filter == LoopFilter.Complex) { // For complex filter, we need to preserve the dependency chain. diff --git a/src/ImageSharp/Formats/WebP/Lossy/YuvConversion.cs b/src/ImageSharp/Formats/WebP/Lossy/YuvConversion.cs index 85c36be65..00407608b 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/YuvConversion.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/YuvConversion.cs @@ -5,7 +5,7 @@ using System; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy +namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy { internal static class YuvConversion { @@ -199,7 +199,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy private static int LinearToGammaWeighted(byte rgb0, byte rgb1, byte rgb2, byte rgb3, byte a0, byte a1, byte a2, byte a3, uint totalA) { uint sum = (a0 * GammaToLinear(rgb0)) + (a1 * GammaToLinear(rgb1)) + (a2 * GammaToLinear(rgb2)) + (a3 * GammaToLinear(rgb3)); - return LinearToGamma((sum * WebPLookupTables.InvAlpha[totalA]) >> (WebPConstants.AlphaFix - 2), 0); + return LinearToGamma((sum * WebpLookupTables.InvAlpha[totalA]) >> (WebpConstants.AlphaFix - 2), 0); } // Convert a linear value 'v' to YUV_FIX+2 fixed-point precision @@ -208,23 +208,23 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy private static int LinearToGamma(uint baseValue, int shift) { int y = Interpolate((int)(baseValue << shift)); // Final uplifted value. - return (y + WebPConstants.GammaTabRounder) >> WebPConstants.GammaTabFix; // Descale. + return (y + WebpConstants.GammaTabRounder) >> WebpConstants.GammaTabFix; // Descale. } [MethodImpl(InliningOptions.ShortMethod)] private static uint GammaToLinear(byte v) { - return WebPLookupTables.GammaToLinearTab[v]; + return WebpLookupTables.GammaToLinearTab[v]; } [MethodImpl(InliningOptions.ShortMethod)] private static int Interpolate(int v) { - int tabPos = v >> (WebPConstants.GammaTabFix + 2); // integer part. - int x = v & ((WebPConstants.GammaTabScale << 2) - 1); // fractional part. - int v0 = WebPLookupTables.LinearToGammaTab[tabPos]; - int v1 = WebPLookupTables.LinearToGammaTab[tabPos + 1]; - int y = (v1 * x) + (v0 * ((WebPConstants.GammaTabScale << 2) - x)); // interpolate + int tabPos = v >> (WebpConstants.GammaTabFix + 2); // integer part. + int x = v & ((WebpConstants.GammaTabScale << 2) - 1); // fractional part. + int v0 = WebpLookupTables.LinearToGammaTab[tabPos]; + int v1 = WebpLookupTables.LinearToGammaTab[tabPos + 1]; + int y = (v1 * x) + (v0 * ((WebpConstants.GammaTabScale << 2) - x)); // interpolate return y; } diff --git a/src/ImageSharp/Formats/WebP/MetadataExtensions.cs b/src/ImageSharp/Formats/WebP/MetadataExtensions.cs index 81b0ef90d..810eace48 100644 --- a/src/ImageSharp/Formats/WebP/MetadataExtensions.cs +++ b/src/ImageSharp/Formats/WebP/MetadataExtensions.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Formats.Experimental.WebP; +using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.Metadata; namespace SixLabors.ImageSharp @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp /// Gets the webp format specific metadata for the image. /// /// The metadata this method extends. - /// The . - public static WebPMetadata GetWebpMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(WebPFormat.Instance); + /// The . + public static WebpMetadata GetWebpMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(WebpFormat.Instance); } } diff --git a/src/ImageSharp/Formats/WebP/Vp8HeaderType.cs b/src/ImageSharp/Formats/WebP/Vp8HeaderType.cs index 1e194ce1f..313b8e074 100644 --- a/src/ImageSharp/Formats/WebP/Vp8HeaderType.cs +++ b/src/ImageSharp/Formats/WebP/Vp8HeaderType.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Enum for the different VP8 chunk header types. diff --git a/src/ImageSharp/Formats/WebP/WebPAlphaFilterType.cs b/src/ImageSharp/Formats/WebP/WebPAlphaFilterType.cs index f4d6a4251..a52d18d15 100644 --- a/src/ImageSharp/Formats/WebP/WebPAlphaFilterType.cs +++ b/src/ImageSharp/Formats/WebP/WebPAlphaFilterType.cs @@ -1,12 +1,12 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Enum for the different alpha filter types. /// - internal enum WebPAlphaFilterType : int + internal enum WebpAlphaFilterType : int { /// /// No filtering. diff --git a/src/ImageSharp/Formats/WebP/WebPBitsPerPixel.cs b/src/ImageSharp/Formats/WebP/WebPBitsPerPixel.cs index 731516d2a..b6dc5c9fe 100644 --- a/src/ImageSharp/Formats/WebP/WebPBitsPerPixel.cs +++ b/src/ImageSharp/Formats/WebP/WebPBitsPerPixel.cs @@ -1,12 +1,12 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Enumerates the available bits per pixel the webp image uses. /// - public enum WebPBitsPerPixel : short + public enum WebpBitsPerPixel : short { /// /// 24 bits per pixel. Each pixel consists of 3 bytes. diff --git a/src/ImageSharp/Formats/WebP/WebPChunkType.cs b/src/ImageSharp/Formats/WebP/WebPChunkType.cs index 98a1c2f81..afb1bf97d 100644 --- a/src/ImageSharp/Formats/WebP/WebPChunkType.cs +++ b/src/ImageSharp/Formats/WebP/WebPChunkType.cs @@ -1,13 +1,13 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Contains a list of different webp chunk types. /// /// See WebP Container Specification for more details: https://developers.google.com/speed/webp/docs/riff_container - public enum WebPChunkType : uint + public enum WebpChunkType : uint { /// /// Header signaling the use of the VP8 format. diff --git a/src/ImageSharp/Formats/WebP/WebPCommonUtils.cs b/src/ImageSharp/Formats/WebP/WebPCommonUtils.cs index 024d81b0b..7a93b0f10 100644 --- a/src/ImageSharp/Formats/WebP/WebPCommonUtils.cs +++ b/src/ImageSharp/Formats/WebP/WebPCommonUtils.cs @@ -4,12 +4,12 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Utility methods for lossy and lossless webp format. /// - internal static class WebPCommonUtils + internal static class WebpCommonUtils { /// /// Returns 31 ^ clz(n) = log2(n).Returns 31 ^ clz(n) = log2(n). @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP n >>= 8; } - return logValue + Unsafe.Add(ref MemoryMarshal.GetReference(WebPLookupTables.LogTable8Bit), (int)n); + return logValue + Unsafe.Add(ref MemoryMarshal.GetReference(WebpLookupTables.LogTable8Bit), (int)n); } } } diff --git a/src/ImageSharp/Formats/WebP/WebPConstants.cs b/src/ImageSharp/Formats/WebP/WebPConstants.cs index a0fb02e5b..98c783a40 100644 --- a/src/ImageSharp/Formats/WebP/WebPConstants.cs +++ b/src/ImageSharp/Formats/WebP/WebPConstants.cs @@ -3,12 +3,12 @@ using System.Collections.Generic; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Constants used for encoding and decoding VP8 and VP8L bitstreams. /// - internal static class WebPConstants + internal static class WebpConstants { /// /// The list of file extensions that equate to WebP. diff --git a/src/ImageSharp/Formats/WebP/WebPDecoder.cs b/src/ImageSharp/Formats/WebP/WebPDecoder.cs index 539ba0700..cc2236a70 100644 --- a/src/ImageSharp/Formats/WebP/WebPDecoder.cs +++ b/src/ImageSharp/Formats/WebP/WebPDecoder.cs @@ -9,13 +9,13 @@ using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// EXPERIMENTAL: /// Image decoder for generating an image out of a webp stream. /// - public sealed class WebPDecoder : IImageDecoder, IWebPDecoderOptions, IImageInfoDetector + public sealed class WebpDecoder : IImageDecoder, IWebpDecoderOptions, IImageInfoDetector { /// /// Gets or sets a value indicating whether the metadata should be ignored when the image is being decoded. @@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP { Guard.NotNull(stream, nameof(stream)); - var decoder = new WebPDecoderCore(configuration, this); + var decoder = new WebpDecoderCore(configuration, this); try { @@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP { Guard.NotNull(stream, nameof(stream)); - return new WebPDecoderCore(configuration, this).Identify(configuration, stream); + return new WebpDecoderCore(configuration, this).Identify(configuration, stream); } /// @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP { Guard.NotNull(stream, nameof(stream)); - var decoder = new WebPDecoderCore(configuration, this); + var decoder = new WebpDecoderCore(configuration, this); try { @@ -84,7 +84,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP Guard.NotNull(stream, nameof(stream)); using var bufferedStream = new BufferedReadStream(configuration, stream); - return new WebPDecoderCore(configuration, this).IdentifyAsync(configuration, bufferedStream, cancellationToken); + return new WebpDecoderCore(configuration, this).IdentifyAsync(configuration, bufferedStream, cancellationToken); } } } diff --git a/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs b/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs index f2f654561..5f260deb7 100644 --- a/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs +++ b/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs @@ -5,9 +5,9 @@ using System; using System.Buffers.Binary; using System.IO; using System.Threading; -using SixLabors.ImageSharp.Formats.Experimental.WebP.BitReader; -using SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless; -using SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy; +using SixLabors.ImageSharp.Formats.Experimental.Webp.BitReader; +using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless; +using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy; using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Metadata; @@ -15,12 +15,12 @@ using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.Metadata.Profiles.Icc; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Performs the webp decoding operation. /// - internal sealed class WebPDecoderCore : IImageDecoderInternals + internal sealed class WebpDecoderCore : IImageDecoderInternals { /// /// Reusable buffer. @@ -40,19 +40,19 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// /// The webp specific metadata. /// - private WebPMetadata webpMetadata; + private WebpMetadata webpMetadata; /// /// Information about the webp image. /// - private WebPImageInfo webImageInfo; + private WebpImageInfo webImageInfo; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The configuration. /// The options. - public WebPDecoderCore(Configuration configuration, IWebPDecoderOptions options) + public WebpDecoderCore(Configuration configuration, IWebpDecoderOptions options) { this.Configuration = configuration; this.memoryAllocator = configuration.MemoryAllocator; @@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP { if (this.webImageInfo.Features != null && this.webImageInfo.Features.Animation) { - WebPThrowHelper.ThrowNotSupportedException("Animations are not supported"); + WebpThrowHelper.ThrowNotSupportedException("Animations are not supported"); } var image = new Image(this.Configuration, (int)this.webImageInfo.Width, (int)this.webImageInfo.Height, this.Metadata); @@ -152,24 +152,24 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// Reads information present in the image header, about the image content and how to decode the image. /// /// Information about the webp image. - private WebPImageInfo ReadVp8Info() + private WebpImageInfo ReadVp8Info() { this.Metadata = new ImageMetadata(); - this.webpMetadata = this.Metadata.GetFormatMetadata(WebPFormat.Instance); + this.webpMetadata = this.Metadata.GetFormatMetadata(WebpFormat.Instance); - WebPChunkType chunkType = this.ReadChunkType(); + WebpChunkType chunkType = this.ReadChunkType(); switch (chunkType) { - case WebPChunkType.Vp8: + case WebpChunkType.Vp8: return this.ReadVp8Header(); - case WebPChunkType.Vp8L: + case WebpChunkType.Vp8L: return this.ReadVp8LHeader(); - case WebPChunkType.Vp8X: + case WebpChunkType.Vp8X: return this.ReadVp8XHeader(); default: - WebPThrowHelper.ThrowImageFormatException("Unrecognized VP8 header"); - return new WebPImageInfo(); // this return will never be reached, because throw helper will throw an exception. + WebpThrowHelper.ThrowImageFormatException("Unrecognized VP8 header"); + return new WebpImageInfo(); // this return will never be reached, because throw helper will throw an exception. } } @@ -182,9 +182,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// After the image header, image data will follow. After that optional image metadata chunks (EXIF and XMP) can follow. /// /// Information about this webp image. - private WebPImageInfo ReadVp8XHeader() + private WebpImageInfo ReadVp8XHeader() { - var features = new WebPFeatures(); + var features = new WebpFeatures(); uint chunkSize = this.ReadChunkSize(); // The first byte contains information about the image features used. @@ -193,7 +193,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP // The first two bit of it are reserved and should be 0. if (imageFeatures >> 6 != 0) { - WebPThrowHelper.ThrowImageFormatException( + WebpThrowHelper.ThrowImageFormatException( "first two bits of the VP8X header are expected to be zero"); } @@ -216,7 +216,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP this.currentStream.Read(this.buffer, 0, 3); if (this.buffer[0] != 0 || this.buffer[1] != 0 | this.buffer[2] != 0) { - WebPThrowHelper.ThrowImageFormatException("reserved bytes should be zero"); + WebpThrowHelper.ThrowImageFormatException("reserved bytes should be zero"); } // 3 bytes for the width. @@ -230,7 +230,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP uint height = (uint)BinaryPrimitives.ReadInt32LittleEndian(this.buffer) + 1; // Optional chunks ICCP, ALPH and ANIM can follow here. - WebPChunkType chunkType = this.ReadChunkType(); + WebpChunkType chunkType = this.ReadChunkType(); while (IsOptionalVp8XChunk(chunkType)) { this.ParseOptionalExtendedChunks(chunkType, features); @@ -240,20 +240,20 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP if (features.Animation) { // TODO: Animations are not yet supported. - return new WebPImageInfo() { Width = width, Height = height, Features = features }; + return new WebpImageInfo() { Width = width, Height = height, Features = features }; } switch (chunkType) { - case WebPChunkType.Vp8: + case WebpChunkType.Vp8: return this.ReadVp8Header(features); - case WebPChunkType.Vp8L: + case WebpChunkType.Vp8L: return this.ReadVp8LHeader(features); } - WebPThrowHelper.ThrowImageFormatException("Unexpected chunk followed VP8X header"); + WebpThrowHelper.ThrowImageFormatException("Unexpected chunk followed VP8X header"); - return new WebPImageInfo(); + return new WebpImageInfo(); } /// @@ -261,9 +261,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// /// Webp features. /// Information about this webp image. - private WebPImageInfo ReadVp8Header(WebPFeatures features = null) + private WebpImageInfo ReadVp8Header(WebpFeatures features = null) { - this.webpMetadata.Format = WebPFormatType.Lossy; + this.webpMetadata.Format = WebpFormatType.Lossy; // VP8 data size (not including this 4 bytes). this.currentStream.Read(this.buffer, 0, 4); @@ -284,32 +284,32 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP bool isNoKeyFrame = (frameTag & 0x1) == 1; if (isNoKeyFrame) { - WebPThrowHelper.ThrowImageFormatException("VP8 header indicates the image is not a key frame"); + WebpThrowHelper.ThrowImageFormatException("VP8 header indicates the image is not a key frame"); } uint version = (frameTag >> 1) & 0x7; if (version > 3) { - WebPThrowHelper.ThrowImageFormatException($"VP8 header indicates unknown profile {version}"); + WebpThrowHelper.ThrowImageFormatException($"VP8 header indicates unknown profile {version}"); } bool invisibleFrame = ((frameTag >> 4) & 0x1) == 0; if (invisibleFrame) { - WebPThrowHelper.ThrowImageFormatException("VP8 header indicates that the first frame is invisible"); + WebpThrowHelper.ThrowImageFormatException("VP8 header indicates that the first frame is invisible"); } uint partitionLength = frameTag >> 5; if (partitionLength > dataSize) { - WebPThrowHelper.ThrowImageFormatException("VP8 header contains inconsistent size information"); + WebpThrowHelper.ThrowImageFormatException("VP8 header contains inconsistent size information"); } // Check for VP8 magic bytes. this.currentStream.Read(this.buffer, 0, 3); - if (!this.buffer.AsSpan().Slice(0, 3).SequenceEqual(WebPConstants.Vp8HeaderMagicBytes)) + if (!this.buffer.AsSpan().Slice(0, 3).SequenceEqual(WebpConstants.Vp8HeaderMagicBytes)) { - WebPThrowHelper.ThrowImageFormatException("VP8 magic bytes not found"); + WebpThrowHelper.ThrowImageFormatException("VP8 magic bytes not found"); } this.currentStream.Read(this.buffer, 0, 4); @@ -322,12 +322,12 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP remaining -= 7; if (width == 0 || height == 0) { - WebPThrowHelper.ThrowImageFormatException("width or height can not be zero"); + WebpThrowHelper.ThrowImageFormatException("width or height can not be zero"); } if (partitionLength > remaining) { - WebPThrowHelper.ThrowImageFormatException("bad partition length"); + WebpThrowHelper.ThrowImageFormatException("bad partition length"); } var vp8FrameHeader = new Vp8FrameHeader() @@ -346,13 +346,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP Remaining = remaining }; - return new WebPImageInfo() + return new WebpImageInfo() { Width = width, Height = height, XScale = xScale, YScale = yScale, - BitsPerPixel = features?.Alpha == true ? WebPBitsPerPixel.Pixel32 : WebPBitsPerPixel.Pixel24, + BitsPerPixel = features?.Alpha == true ? WebpBitsPerPixel.Pixel32 : WebpBitsPerPixel.Pixel24, IsLossless = false, Features = features, Vp8Profile = (sbyte)version, @@ -366,9 +366,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// /// Webp image features. /// Information about this image. - private WebPImageInfo ReadVp8LHeader(WebPFeatures features = null) + private WebpImageInfo ReadVp8LHeader(WebpFeatures features = null) { - this.webpMetadata.Format = WebPFormatType.Lossless; + this.webpMetadata.Format = WebpFormatType.Lossless; // VP8 data size. uint imageDataSize = this.ReadChunkSize(); @@ -377,17 +377,17 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP // One byte signature, should be 0x2f. uint signature = bitReader.ReadValue(8); - if (signature != WebPConstants.Vp8LHeaderMagicByte) + if (signature != WebpConstants.Vp8LHeaderMagicByte) { - WebPThrowHelper.ThrowImageFormatException("Invalid VP8L signature"); + WebpThrowHelper.ThrowImageFormatException("Invalid VP8L signature"); } // The first 28 bits of the bitstream specify the width and height of the image. - uint width = bitReader.ReadValue(WebPConstants.Vp8LImageSizeBits) + 1; - uint height = bitReader.ReadValue(WebPConstants.Vp8LImageSizeBits) + 1; + uint width = bitReader.ReadValue(WebpConstants.Vp8LImageSizeBits) + 1; + uint height = bitReader.ReadValue(WebpConstants.Vp8LImageSizeBits) + 1; if (width == 1 || height == 1) { - WebPThrowHelper.ThrowImageFormatException("invalid width or height read"); + WebpThrowHelper.ThrowImageFormatException("invalid width or height read"); } // The alphaIsUsed flag should be set to 0 when all alpha values are 255 in the picture, and 1 otherwise. @@ -396,17 +396,17 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP // The next 3 bits are the version. The version number is a 3 bit code that must be set to 0. // Any other value should be treated as an error. - uint version = bitReader.ReadValue(WebPConstants.Vp8LVersionBits); + uint version = bitReader.ReadValue(WebpConstants.Vp8LVersionBits); if (version != 0) { - WebPThrowHelper.ThrowNotSupportedException($"Unexpected version number {version} found in VP8L header"); + WebpThrowHelper.ThrowNotSupportedException($"Unexpected version number {version} found in VP8L header"); } - return new WebPImageInfo() + return new WebpImageInfo() { Width = width, Height = height, - BitsPerPixel = WebPBitsPerPixel.Pixel32, + BitsPerPixel = WebpBitsPerPixel.Pixel32, IsLossless = true, Features = features, Vp8LBitReader = bitReader @@ -418,11 +418,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// /// The chunk type. /// The webp image features. - private void ParseOptionalExtendedChunks(WebPChunkType chunkType, WebPFeatures features) + private void ParseOptionalExtendedChunks(WebpChunkType chunkType, WebpFeatures features) { switch (chunkType) { - case WebPChunkType.Iccp: + case WebpChunkType.Iccp: uint iccpChunkSize = this.ReadChunkSize(); if (this.IgnoreMetadata) { @@ -441,11 +441,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP break; - case WebPChunkType.Animation: + case WebpChunkType.Animation: this.webpMetadata.Animated = true; break; - case WebPChunkType.Alpha: + case WebpChunkType.Alpha: uint alphaChunkSize = this.ReadChunkSize(); features.AlphaChunkHeader = (byte)this.currentStream.ReadByte(); var alphaDataSize = (int)(alphaChunkSize - 1); @@ -461,7 +461,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// Also, a file may possibly contain both 'EXIF' and 'XMP ' chunks. /// /// The webp features. - private void ParseOptionalChunks(WebPFeatures features) + private void ParseOptionalChunks(WebpFeatures features) { if (this.IgnoreMetadata || (features.ExifProfile == false && features.XmpMetaData == false)) { @@ -472,10 +472,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP while (this.currentStream.Position < streamLength) { // Read chunk header. - WebPChunkType chunkType = this.ReadChunkType(); + WebpChunkType chunkType = this.ReadChunkType(); uint chunkLength = this.ReadChunkSize(); - if (chunkType == WebPChunkType.Exif) + if (chunkType == WebpChunkType.Exif) { var exifData = new byte[chunkLength]; this.currentStream.Read(exifData, 0, (int)chunkLength); @@ -495,11 +495,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// /// Thrown if the input stream is not valid. /// - private WebPChunkType ReadChunkType() + private WebpChunkType ReadChunkType() { if (this.currentStream.Read(this.buffer, 0, 4) == 4) { - var chunkType = (WebPChunkType)BinaryPrimitives.ReadUInt32BigEndian(this.buffer); + var chunkType = (WebpChunkType)BinaryPrimitives.ReadUInt32BigEndian(this.buffer); this.webpMetadata.ChunkTypes.Enqueue(chunkType); return chunkType; } @@ -528,13 +528,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// /// The chunk type. /// True, if its an optional chunk type. - private static bool IsOptionalVp8XChunk(WebPChunkType chunkType) + private static bool IsOptionalVp8XChunk(WebpChunkType chunkType) { return chunkType switch { - WebPChunkType.Alpha => true, - WebPChunkType.Animation => true, - WebPChunkType.Iccp => true, + WebpChunkType.Alpha => true, + WebpChunkType.Animation => true, + WebpChunkType.Iccp => true, _ => false }; } diff --git a/src/ImageSharp/Formats/WebP/WebPEncoder.cs b/src/ImageSharp/Formats/WebP/WebPEncoder.cs index cb9a4101d..88bceddb2 100644 --- a/src/ImageSharp/Formats/WebP/WebPEncoder.cs +++ b/src/ImageSharp/Formats/WebP/WebPEncoder.cs @@ -7,13 +7,13 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// EXPERIMENTAL: /// Image encoder for writing an image to a stream in the WebP format. /// - public sealed class WebPEncoder : IImageEncoder, IWebPEncoderOptions + public sealed class WebpEncoder : IImageEncoder, IWebPEncoderOptions { /// public bool Lossy { get; set; } @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP public void Encode(Image image, Stream stream) where TPixel : unmanaged, IPixel { - var encoder = new WebPEncoderCore(this, image.GetMemoryAllocator()); + var encoder = new WebpEncoderCore(this, image.GetMemoryAllocator()); encoder.Encode(image, stream); } @@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP public Task EncodeAsync(Image image, Stream stream, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { - var encoder = new WebPEncoderCore(this, image.GetMemoryAllocator()); + var encoder = new WebpEncoderCore(this, image.GetMemoryAllocator()); return encoder.EncodeAsync(image, stream); } } diff --git a/src/ImageSharp/Formats/WebP/WebPEncoderCore.cs b/src/ImageSharp/Formats/WebP/WebPEncoderCore.cs index 6b8885a1e..73817e691 100644 --- a/src/ImageSharp/Formats/WebP/WebPEncoderCore.cs +++ b/src/ImageSharp/Formats/WebP/WebPEncoderCore.cs @@ -5,18 +5,18 @@ using System.IO; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless; -using SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy; +using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless; +using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Image encoder for writing an image to a stream in the WebP format. /// - internal sealed class WebPEncoderCore + internal sealed class WebpEncoderCore { /// /// Used for allocating memory during processing operations. @@ -54,11 +54,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP private readonly int entropyPasses; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The encoder options. /// The memory manager. - public WebPEncoderCore(IWebPEncoderOptions options, MemoryAllocator memoryAllocator) + public WebpEncoderCore(IWebPEncoderOptions options, MemoryAllocator memoryAllocator) { this.memoryAllocator = memoryAllocator; this.alphaCompression = options.AlphaCompression; diff --git a/src/ImageSharp/Formats/WebP/WebPFeatures.cs b/src/ImageSharp/Formats/WebP/WebPFeatures.cs index 38292e75e..4a0825c03 100644 --- a/src/ImageSharp/Formats/WebP/WebPFeatures.cs +++ b/src/ImageSharp/Formats/WebP/WebPFeatures.cs @@ -4,12 +4,12 @@ using System; using System.Buffers; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Image features of a VP8X image. /// - internal class WebPFeatures : IDisposable + internal class WebpFeatures : IDisposable { /// /// Gets or sets a value indicating whether this image has an ICC Profile. diff --git a/src/ImageSharp/Formats/WebP/WebPFormat.cs b/src/ImageSharp/Formats/WebP/WebPFormat.cs index 241ec879a..6aaa24728 100644 --- a/src/ImageSharp/Formats/WebP/WebPFormat.cs +++ b/src/ImageSharp/Formats/WebP/WebPFormat.cs @@ -3,22 +3,22 @@ using System.Collections.Generic; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// EXPERIMENTAL: /// Registers the image encoders, decoders and mime type detectors for the WebP format /// - public sealed class WebPFormat : IImageFormat + public sealed class WebpFormat : IImageFormat { - private WebPFormat() + private WebpFormat() { } /// /// Gets the current instance. /// - public static WebPFormat Instance { get; } = new WebPFormat(); + public static WebpFormat Instance { get; } = new WebpFormat(); /// public string Name => "WebP"; @@ -27,12 +27,12 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP public string DefaultMimeType => "image/webp"; /// - public IEnumerable MimeTypes => WebPConstants.MimeTypes; + public IEnumerable MimeTypes => WebpConstants.MimeTypes; /// - public IEnumerable FileExtensions => WebPConstants.FileExtensions; + public IEnumerable FileExtensions => WebpConstants.FileExtensions; /// - public WebPMetadata CreateDefaultFormatMetadata() => new WebPMetadata(); + public WebpMetadata CreateDefaultFormatMetadata() => new WebpMetadata(); } } diff --git a/src/ImageSharp/Formats/WebP/WebPFormatType.cs b/src/ImageSharp/Formats/WebP/WebPFormatType.cs index a85cac34e..3835f8804 100644 --- a/src/ImageSharp/Formats/WebP/WebPFormatType.cs +++ b/src/ImageSharp/Formats/WebP/WebPFormatType.cs @@ -1,12 +1,12 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Info about the webp format used. /// - public enum WebPFormatType + public enum WebpFormatType { /// /// Unknown webp format. diff --git a/src/ImageSharp/Formats/WebP/WebPImageFormatDetector.cs b/src/ImageSharp/Formats/WebP/WebPImageFormatDetector.cs index 6da95ef84..54fcbca46 100644 --- a/src/ImageSharp/Formats/WebP/WebPImageFormatDetector.cs +++ b/src/ImageSharp/Formats/WebP/WebPImageFormatDetector.cs @@ -3,12 +3,12 @@ using System; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Detects WebP file headers. /// - public sealed class WebPImageFormatDetector : IImageFormatDetector + public sealed class WebpImageFormatDetector : IImageFormatDetector { /// public int HeaderSize => 12; @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// public IImageFormat DetectFormat(ReadOnlySpan header) { - return this.IsSupportedFileFormat(header) ? WebPFormat.Instance : null; + return this.IsSupportedFileFormat(header) ? WebpFormat.Instance : null; } private bool IsSupportedFileFormat(ReadOnlySpan header) @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// True, if its a valid RIFF FourCC. private bool IsRiffContainer(ReadOnlySpan header) { - return header.Slice(0, 4).SequenceEqual(WebPConstants.RiffFourCc); + return header.Slice(0, 4).SequenceEqual(WebpConstants.RiffFourCc); } /// @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// True, if its a webp file. private bool IsWebPFile(ReadOnlySpan header) { - return header.Slice(8, 4).SequenceEqual(WebPConstants.WebPHeader); + return header.Slice(8, 4).SequenceEqual(WebpConstants.WebPHeader); } } } diff --git a/src/ImageSharp/Formats/WebP/WebPImageInfo.cs b/src/ImageSharp/Formats/WebP/WebPImageInfo.cs index 89c8170a3..3fa84e7a8 100644 --- a/src/ImageSharp/Formats/WebP/WebPImageInfo.cs +++ b/src/ImageSharp/Formats/WebP/WebPImageInfo.cs @@ -2,12 +2,12 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.Formats.Experimental.WebP.BitReader; -using SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy; +using SixLabors.ImageSharp.Formats.Experimental.Webp.BitReader; +using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { - internal class WebPImageInfo : IDisposable + internal class WebpImageInfo : IDisposable { /// /// Gets or sets the bitmap width in pixels. @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// /// Gets or sets the bits per pixel. /// - public WebPBitsPerPixel BitsPerPixel { get; set; } + public WebpBitsPerPixel BitsPerPixel { get; set; } /// /// Gets or sets a value indicating whether this image uses lossless compression. @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// /// Gets or sets additional features present in a VP8X image. /// - public WebPFeatures Features { get; set; } + public WebpFeatures Features { get; set; } /// /// Gets or sets the VP8 profile / version. Valid values are between 0 and 3. Default value will be the invalid value -1. diff --git a/src/ImageSharp/Formats/WebP/WebPLookupTables.cs b/src/ImageSharp/Formats/WebP/WebPLookupTables.cs index d71949fa5..14e5d333b 100644 --- a/src/ImageSharp/Formats/WebP/WebPLookupTables.cs +++ b/src/ImageSharp/Formats/WebP/WebPLookupTables.cs @@ -4,10 +4,10 @@ using System; using System.Collections.Generic; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { #pragma warning disable SA1201 // Elements should appear in the correct order - internal static class WebPLookupTables + internal static class WebpLookupTables { public static readonly Dictionary Abs0; @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP public static readonly ushort[] GammaToLinearTab = new ushort[256]; - public static readonly int[] LinearToGammaTab = new int[WebPConstants.GammaTabSize + 1]; + public static readonly int[] LinearToGammaTab = new int[WebpConstants.GammaTabSize + 1]; public static readonly short[,][] Vp8FixedCostsI4 = new short[10, 10][]; @@ -30,28 +30,28 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP public static readonly int[] Vp8DspScan = { // Luma - 0 + (0 * WebPConstants.Bps), 4 + (0 * WebPConstants.Bps), 8 + (0 * WebPConstants.Bps), 12 + (0 * WebPConstants.Bps), - 0 + (4 * WebPConstants.Bps), 4 + (4 * WebPConstants.Bps), 8 + (4 * WebPConstants.Bps), 12 + (4 * WebPConstants.Bps), - 0 + (8 * WebPConstants.Bps), 4 + (8 * WebPConstants.Bps), 8 + (8 * WebPConstants.Bps), 12 + (8 * WebPConstants.Bps), - 0 + (12 * WebPConstants.Bps), 4 + (12 * WebPConstants.Bps), 8 + (12 * WebPConstants.Bps), 12 + (12 * WebPConstants.Bps), + 0 + (0 * WebpConstants.Bps), 4 + (0 * WebpConstants.Bps), 8 + (0 * WebpConstants.Bps), 12 + (0 * WebpConstants.Bps), + 0 + (4 * WebpConstants.Bps), 4 + (4 * WebpConstants.Bps), 8 + (4 * WebpConstants.Bps), 12 + (4 * WebpConstants.Bps), + 0 + (8 * WebpConstants.Bps), 4 + (8 * WebpConstants.Bps), 8 + (8 * WebpConstants.Bps), 12 + (8 * WebpConstants.Bps), + 0 + (12 * WebpConstants.Bps), 4 + (12 * WebpConstants.Bps), 8 + (12 * WebpConstants.Bps), 12 + (12 * WebpConstants.Bps), - 0 + (0 * WebPConstants.Bps), 4 + (0 * WebPConstants.Bps), 0 + (4 * WebPConstants.Bps), 4 + (4 * WebPConstants.Bps), // U - 8 + (0 * WebPConstants.Bps), 12 + (0 * WebPConstants.Bps), 8 + (4 * WebPConstants.Bps), 12 + (4 * WebPConstants.Bps) // V + 0 + (0 * WebpConstants.Bps), 4 + (0 * WebpConstants.Bps), 0 + (4 * WebpConstants.Bps), 4 + (4 * WebpConstants.Bps), // U + 8 + (0 * WebpConstants.Bps), 12 + (0 * WebpConstants.Bps), 8 + (4 * WebpConstants.Bps), 12 + (4 * WebpConstants.Bps) // V }; public static readonly short[] Vp8Scan = { // Luma - 0 + (0 * WebPConstants.Bps), 4 + (0 * WebPConstants.Bps), 8 + (0 * WebPConstants.Bps), 12 + (0 * WebPConstants.Bps), - 0 + (4 * WebPConstants.Bps), 4 + (4 * WebPConstants.Bps), 8 + (4 * WebPConstants.Bps), 12 + (4 * WebPConstants.Bps), - 0 + (8 * WebPConstants.Bps), 4 + (8 * WebPConstants.Bps), 8 + (8 * WebPConstants.Bps), 12 + (8 * WebPConstants.Bps), - 0 + (12 * WebPConstants.Bps), 4 + (12 * WebPConstants.Bps), 8 + (12 * WebPConstants.Bps), 12 + (12 * WebPConstants.Bps), + 0 + (0 * WebpConstants.Bps), 4 + (0 * WebpConstants.Bps), 8 + (0 * WebpConstants.Bps), 12 + (0 * WebpConstants.Bps), + 0 + (4 * WebpConstants.Bps), 4 + (4 * WebpConstants.Bps), 8 + (4 * WebpConstants.Bps), 12 + (4 * WebpConstants.Bps), + 0 + (8 * WebpConstants.Bps), 4 + (8 * WebpConstants.Bps), 8 + (8 * WebpConstants.Bps), 12 + (8 * WebpConstants.Bps), + 0 + (12 * WebpConstants.Bps), 4 + (12 * WebpConstants.Bps), 8 + (12 * WebpConstants.Bps), 12 + (12 * WebpConstants.Bps), }; public static readonly short[] Vp8ScanUv = { - 0 + (0 * WebPConstants.Bps), 4 + (0 * WebPConstants.Bps), 0 + (4 * WebPConstants.Bps), 4 + (4 * WebPConstants.Bps), // U - 8 + (0 * WebPConstants.Bps), 12 + (0 * WebPConstants.Bps), 8 + (4 * WebPConstants.Bps), 12 + (4 * WebPConstants.Bps) // V + 0 + (0 * WebpConstants.Bps), 4 + (0 * WebpConstants.Bps), 0 + (4 * WebpConstants.Bps), 4 + (4 * WebpConstants.Bps), // U + 8 + (0 * WebpConstants.Bps), 12 + (0 * WebpConstants.Bps), 8 + (4 * WebpConstants.Bps), 12 + (4 * WebpConstants.Bps) // V }; // This table gives, for a given sharpness, the filtering strength to be @@ -1092,18 +1092,18 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP 515, 515, 514, 514 }; - static WebPLookupTables() + static WebpLookupTables() { - double scale = (double)(1 << WebPConstants.GammaTabFix) / WebPConstants.GammaScale; + double scale = (double)(1 << WebpConstants.GammaTabFix) / WebpConstants.GammaScale; double norm = 1.0d / 255.0d; for (int v = 0; v < 256; ++v) { - GammaToLinearTab[v] = (ushort)((Math.Pow(norm * v, WebPConstants.Gamma) * WebPConstants.GammaScale) + .5); + GammaToLinearTab[v] = (ushort)((Math.Pow(norm * v, WebpConstants.Gamma) * WebpConstants.GammaScale) + .5); } - for (int v = 0; v <= WebPConstants.GammaTabSize; ++v) + for (int v = 0; v <= WebpConstants.GammaTabSize; ++v) { - LinearToGammaTab[v] = (int)((255.0d * Math.Pow(scale * v, 1.0d / WebPConstants.Gamma)) + .5); + LinearToGammaTab[v] = (int)((255.0d * Math.Pow(scale * v, 1.0d / WebpConstants.Gamma)) + .5); } Abs0 = new Dictionary(); diff --git a/src/ImageSharp/Formats/WebP/WebPMetadata.cs b/src/ImageSharp/Formats/WebP/WebPMetadata.cs index 7433072ac..60fccc020 100644 --- a/src/ImageSharp/Formats/WebP/WebPMetadata.cs +++ b/src/ImageSharp/Formats/WebP/WebPMetadata.cs @@ -3,25 +3,25 @@ using System.Collections.Generic; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// Provides WebP specific metadata information for the image. /// - public class WebPMetadata : IDeepCloneable + public class WebpMetadata : IDeepCloneable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public WebPMetadata() + public WebpMetadata() { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The metadata to create an instance from. - private WebPMetadata(WebPMetadata other) + private WebpMetadata(WebpMetadata other) { this.Animated = other.Animated; this.Format = other.Format; @@ -30,12 +30,12 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP /// /// Gets or sets the webp format used. Either lossless or lossy. /// - public WebPFormatType Format { get; set; } + public WebpFormatType Format { get; set; } /// /// Gets or sets all found chunk types ordered by appearance. /// - public Queue ChunkTypes { get; set; } = new Queue(); + public Queue ChunkTypes { get; set; } = new Queue(); /// /// Gets or sets a value indicating whether the webp file contains an animation. @@ -43,6 +43,6 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP public bool Animated { get; set; } = false; /// - public IDeepCloneable DeepClone() => new WebPMetadata(this); + public IDeepCloneable DeepClone() => new WebpMetadata(this); } } diff --git a/src/ImageSharp/Formats/WebP/WebPThrowHelper.cs b/src/ImageSharp/Formats/WebP/WebPThrowHelper.cs index bbe399a36..4918e1ed3 100644 --- a/src/ImageSharp/Formats/WebP/WebPThrowHelper.cs +++ b/src/ImageSharp/Formats/WebP/WebPThrowHelper.cs @@ -4,9 +4,9 @@ using System; using System.Runtime.CompilerServices; -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { - internal static class WebPThrowHelper + internal static class WebpThrowHelper { /// /// Cold path optimization for throwing -s diff --git a/src/ImageSharp/Formats/WebP/WebpConfigurationModule.cs b/src/ImageSharp/Formats/WebP/WebpConfigurationModule.cs index ec2571807..d032578ca 100644 --- a/src/ImageSharp/Formats/WebP/WebpConfigurationModule.cs +++ b/src/ImageSharp/Formats/WebP/WebpConfigurationModule.cs @@ -1,20 +1,20 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Experimental.WebP +namespace SixLabors.ImageSharp.Formats.Experimental.Webp { /// /// EXPERIMENTAL: /// Registers the image encoders, decoders and mime type detectors for the webp format. /// - public sealed class WebPConfigurationModule : IConfigurationModule + public sealed class WebpConfigurationModule : IConfigurationModule { /// public void Configure(Configuration configuration) { - configuration.ImageFormatsManager.SetDecoder(WebPFormat.Instance, new WebPDecoder()); - configuration.ImageFormatsManager.SetEncoder(WebPFormat.Instance, new WebPEncoder()); - configuration.ImageFormatsManager.AddImageFormatDetector(new WebPImageFormatDetector()); + configuration.ImageFormatsManager.SetDecoder(WebpFormat.Instance, new WebpDecoder()); + configuration.ImageFormatsManager.SetEncoder(WebpFormat.Instance, new WebpEncoder()); + configuration.ImageFormatsManager.AddImageFormatDetector(new WebpImageFormatDetector()); } } } diff --git a/tests/ImageSharp.Benchmarks/Codecs/DecodeWebp.cs b/tests/ImageSharp.Benchmarks/Codecs/DecodeWebp.cs index 84130cf40..9f6130bd5 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/DecodeWebp.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/DecodeWebp.cs @@ -5,7 +5,7 @@ using System.IO; using BenchmarkDotNet.Attributes; using ImageMagick; -using SixLabors.ImageSharp.Formats.Experimental.WebP; +using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests; @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs public void ReadImages() { this.configuration = Configuration.CreateDefaultInstance(); - new WebPConfigurationModule().Configure(this.configuration); + new WebpConfigurationModule().Configure(this.configuration); this.webpLossyBytes ??= File.ReadAllBytes(this.TestImageLossyFullPath); this.webpLosslessBytes ??= File.ReadAllBytes(this.TestImageLosslessFullPath); diff --git a/tests/ImageSharp.Benchmarks/Codecs/EncodeWebp.cs b/tests/ImageSharp.Benchmarks/Codecs/EncodeWebp.cs index bc147f430..3aa23c7ff 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/EncodeWebp.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/EncodeWebp.cs @@ -4,7 +4,7 @@ using System.IO; using BenchmarkDotNet.Attributes; using ImageMagick; -using SixLabors.ImageSharp.Formats.Experimental.WebP; +using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests; @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs public void ImageSharpWebpLossy() { using var memoryStream = new MemoryStream(); - this.webp.Save(memoryStream, new WebPEncoder() + this.webp.Save(memoryStream, new WebpEncoder() { Lossy = true }); @@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs public void ImageSharpWebpLossless() { using var memoryStream = new MemoryStream(); - this.webp.Save(memoryStream, new WebPEncoder() + this.webp.Save(memoryStream, new WebpEncoder() { Lossy = false }); diff --git a/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs b/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs index d6ba59e4b..babda726f 100644 --- a/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs +++ b/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs @@ -7,7 +7,7 @@ using System.Linq; using Moq; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Bmp; -using SixLabors.ImageSharp.Formats.Experimental.WebP; +using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Png; diff --git a/tests/ImageSharp.Tests/Formats/WebP/ImageExtensionsTest.cs b/tests/ImageSharp.Tests/Formats/WebP/ImageExtensionsTest.cs index b20376b47..0fd9574af 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/ImageExtensionsTest.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/ImageExtensionsTest.cs @@ -4,7 +4,7 @@ using System.IO; using System.Threading.Tasks; using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.Formats.Experimental.WebP; +using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.PixelFormats; using Xunit; @@ -15,10 +15,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp { public ImageExtensionsTest() { - Configuration.Default.ImageFormatsManager.AddImageFormat(WebPFormat.Instance); - Configuration.Default.ImageFormatsManager.AddImageFormatDetector(new WebPImageFormatDetector()); - Configuration.Default.ImageFormatsManager.SetDecoder(WebPFormat.Instance, new WebPDecoder()); - Configuration.Default.ImageFormatsManager.SetEncoder(WebPFormat.Instance, new WebPEncoder()); + Configuration.Default.ImageFormatsManager.AddImageFormat(WebpFormat.Instance); + Configuration.Default.ImageFormatsManager.AddImageFormatDetector(new WebpImageFormatDetector()); + Configuration.Default.ImageFormatsManager.SetDecoder(WebpFormat.Instance, new WebpDecoder()); + Configuration.Default.ImageFormatsManager.SetEncoder(WebpFormat.Instance, new WebpEncoder()); } [Fact] @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp using (var image = new Image(10, 10)) { - image.SaveAsWebP(file); + image.SaveAsWebp(file); } using (Image.Load(file, out IImageFormat mime)) @@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp using (var image = new Image(10, 10)) { - await image.SaveAsWebPAsync(file); + await image.SaveAsWebpAsync(file); } using (Image.Load(file, out IImageFormat mime)) @@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp using (var image = new Image(10, 10)) { - image.SaveAsWebP(file, new WebPEncoder()); + image.SaveAsWebp(file, new WebpEncoder()); } using (Image.Load(file, out IImageFormat mime)) @@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp using (var image = new Image(10, 10)) { - await image.SaveAsWebPAsync(file, new WebPEncoder()); + await image.SaveAsWebpAsync(file, new WebpEncoder()); } using (Image.Load(file, out IImageFormat mime)) @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp using (var image = new Image(10, 10)) { - image.SaveAsWebP(memoryStream); + image.SaveAsWebp(memoryStream); } memoryStream.Position = 0; @@ -114,7 +114,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp using (var image = new Image(10, 10)) { - await image.SaveAsWebPAsync(memoryStream); + await image.SaveAsWebpAsync(memoryStream); } memoryStream.Position = 0; @@ -132,7 +132,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp using (var image = new Image(10, 10)) { - image.SaveAsWebp(memoryStream, new WebPEncoder()); + image.SaveAsWebp(memoryStream, new WebpEncoder()); } memoryStream.Position = 0; @@ -150,7 +150,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp using (var image = new Image(10, 10)) { - await image.SaveAsWebPAsync(memoryStream, new WebPEncoder()); + await image.SaveAsWebpAsync(memoryStream, new WebpEncoder()); } memoryStream.Position = 0; diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs index c58d4b4e4..35aca6999 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs @@ -3,29 +3,29 @@ using System.IO; -using SixLabors.ImageSharp.Formats.Experimental.WebP; +using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; using Xunit; // ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Tests.Formats.WebP +namespace SixLabors.ImageSharp.Tests.Formats.Webp { using static SixLabors.ImageSharp.Tests.TestImages.WebP; [Trait("Format", "Webp")] - public class WebPDecoderTests + public class WebpDecoderTests { - private static WebPDecoder WebpDecoder => new WebPDecoder(); + private static WebpDecoder WebpDecoder => new WebpDecoder(); private static MagickReferenceDecoder ReferenceDecoder => new MagickReferenceDecoder(); - public WebPDecoderTests() + public WebpDecoderTests() { - Configuration.Default.ImageFormatsManager.AddImageFormat(WebPFormat.Instance); - Configuration.Default.ImageFormatsManager.AddImageFormatDetector(new WebPImageFormatDetector()); - Configuration.Default.ImageFormatsManager.SetDecoder(WebPFormat.Instance, new WebPDecoder()); + Configuration.Default.ImageFormatsManager.AddImageFormat(WebpFormat.Instance); + Configuration.Default.ImageFormatsManager.AddImageFormatDetector(new WebpImageFormatDetector()); + Configuration.Default.ImageFormatsManager.SetDecoder(WebpFormat.Instance, new WebpDecoder()); } [Theory] diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs index 8143503a1..3f6daa312 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs @@ -1,17 +1,17 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Formats.Experimental.WebP; +using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using Xunit; -namespace SixLabors.ImageSharp.Tests.Formats.WebP +namespace SixLabors.ImageSharp.Tests.Formats.Webp { using static TestImages.WebP; [Trait("Format", "Webp")] - public class WebPEncoderTests + public class WebpEncoderTests { [Theory] [WithFile(TestImages.Bmp.Car, PixelTypes.Rgba32, 100)] @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP public void Encode_Lossless_WithDifferentQuality_Works(TestImageProvider provider, int quality) where TPixel : unmanaged, IPixel { - var encoder = new WebPEncoder() + var encoder = new WebpEncoder() { Lossy = false, Quality = quality @@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP public void Encode_Lossless_WithDifferentMethods_Works(TestImageProvider provider, int method) where TPixel : unmanaged, IPixel { - var encoder = new WebPEncoder() + var encoder = new WebpEncoder() { Lossy = false, Method = method, @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP public void Encode_Lossy_WithDifferentQuality_Works(TestImageProvider provider, int quality) where TPixel : unmanaged, IPixel { - var encoder = new WebPEncoder() + var encoder = new WebpEncoder() { Lossy = true, Quality = quality @@ -84,7 +84,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP where TPixel : unmanaged, IPixel { int quality = 75; - var encoder = new WebPEncoder() + var encoder = new WebpEncoder() { Lossy = true, Method = method, diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebPMetaDataTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebPMetaDataTests.cs index 375770117..b73dcdfcf 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebPMetaDataTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebPMetaDataTests.cs @@ -1,15 +1,15 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Formats.Experimental.WebP; +using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.PixelFormats; using Xunit; // ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Tests.Formats.WebP +namespace SixLabors.ImageSharp.Tests.Formats.Webp { [Trait("Format", "Webp")] - public class WebPMetadataTests + public class WebpMetaDataTests { [Theory] [WithFile(TestImages.WebP.Lossless.WithExif, PixelTypes.Rgba32, false)] @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP public void IgnoreMetadata_ControlsWhetherExifIsParsed(TestImageProvider provider, bool ignoreMetadata) where TPixel : unmanaged, IPixel { - var decoder = new WebPDecoder { IgnoreMetadata = ignoreMetadata }; + var decoder = new WebpDecoder { IgnoreMetadata = ignoreMetadata }; using (Image image = provider.GetImage(decoder)) { @@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP public void IgnoreMetadata_ControlsWhetherIccpIsParsed(TestImageProvider provider, bool ignoreMetadata) where TPixel : unmanaged, IPixel { - var decoder = new WebPDecoder { IgnoreMetadata = ignoreMetadata }; + var decoder = new WebpDecoder { IgnoreMetadata = ignoreMetadata }; using (Image image = provider.GetImage(decoder)) { diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs index 583fb9514..f6b5b4ca5 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs @@ -5,7 +5,7 @@ using System; using System.IO; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Bmp; -using SixLabors.ImageSharp.Formats.Experimental.WebP; +using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Png; @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Tests new JpegConfigurationModule(), new GifConfigurationModule(), new TgaConfigurationModule(), - new WebPConfigurationModule()); + new WebpConfigurationModule()); // Magick codecs should work on all platforms IImageEncoder pngEncoder = IsWindows ? (IImageEncoder)SystemDrawingReferenceEncoder.Png : new PngEncoder(); diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs index 7f5627a31..e8c4a1329 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs @@ -5,7 +5,7 @@ using System; using System.IO; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Bmp; -using SixLabors.ImageSharp.Formats.Experimental.WebP; +using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Png; @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.Tests [InlineData("lol/Rofl.bmp", typeof(SystemDrawingReferenceEncoder))] [InlineData("lol/Baz.JPG", typeof(JpegEncoder))] [InlineData("lol/Baz.gif", typeof(GifEncoder))] - [InlineData("lol/foobar.webp", typeof(WebPEncoder))] + [InlineData("lol/foobar.webp", typeof(WebpEncoder))] public void GetReferenceEncoder_ReturnsCorrectEncoders_Windows(string fileName, Type expectedEncoderType) { if (!TestEnvironment.IsWindows) @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Tests [InlineData("lol/Rofl.bmp", typeof(SystemDrawingReferenceDecoder))] [InlineData("lol/Baz.JPG", typeof(JpegDecoder))] [InlineData("lol/Baz.gif", typeof(GifDecoder))] - [InlineData("lol/foobar.webp", typeof(WebPDecoder))] + [InlineData("lol/foobar.webp", typeof(WebpDecoder))] public void GetReferenceDecoder_ReturnsCorrectDecoders_Windows(string fileName, Type expectedDecoderType) { if (!TestEnvironment.IsWindows) @@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.Tests [InlineData("lol/Rofl.bmp", typeof(BmpEncoder))] [InlineData("lol/Baz.JPG", typeof(JpegEncoder))] [InlineData("lol/Baz.gif", typeof(GifEncoder))] - [InlineData("lol/foobar.webp", typeof(WebPEncoder))] + [InlineData("lol/foobar.webp", typeof(WebpEncoder))] public void GetReferenceEncoder_ReturnsCorrectEncoders_Linux(string fileName, Type expectedEncoderType) { if (!TestEnvironment.IsLinux) @@ -115,7 +115,7 @@ namespace SixLabors.ImageSharp.Tests [InlineData("lol/Rofl.bmp", typeof(MagickReferenceDecoder))] [InlineData("lol/Baz.JPG", typeof(JpegDecoder))] [InlineData("lol/Baz.gif", typeof(GifDecoder))] - [InlineData("lol/foobar.webp", typeof(WebPDecoder))] + [InlineData("lol/foobar.webp", typeof(WebpDecoder))] public void GetReferenceDecoder_ReturnsCorrectDecoders_Linux(string fileName, Type expectedDecoderType) { if (!TestEnvironment.IsLinux)