From ee08904d7be5d989c1cf8bd81dd7ed3e1fea421c Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 26 Jul 2020 11:33:13 +0200 Subject: [PATCH] Fix warnings and license headers --- .../Formats/WebP/BitWriter/Vp8BitWriter.cs | 10 ++-- .../Formats/WebP/BitWriter/Vp8LBitWriter.cs | 2 +- src/ImageSharp/Formats/WebP/EntropyIx.cs | 4 +- src/ImageSharp/Formats/WebP/HistoIx.cs | 4 +- .../Formats/WebP/IWebPEncoderOptions.cs | 4 +- .../Formats/WebP/ImageExtensions.cs | 4 +- .../WebP/Lossless/BackwardReferenceEncoder.cs | 20 ++++--- .../WebP/Lossless/CostCacheInterval.cs | 4 +- .../Formats/WebP/Lossless/CostInterval.cs | 4 +- .../Formats/WebP/Lossless/CostManager.cs | 5 +- .../Formats/WebP/Lossless/CostModel.cs | 4 +- .../Formats/WebP/Lossless/HistogramBinInfo.cs | 4 +- .../Formats/WebP/Lossless/HistogramEncoder.cs | 5 +- .../Formats/WebP/Lossless/HistogramPair.cs | 4 +- .../Formats/WebP/Lossless/HuffmanTree.cs | 4 +- .../Formats/WebP/Lossless/HuffmanTreeCode.cs | 4 +- .../Formats/WebP/Lossless/HuffmanTreeToken.cs | 4 +- .../Formats/WebP/Lossless/HuffmanUtils.cs | 2 +- .../Formats/WebP/Lossless/LosslessUtils.cs | 2 +- .../Formats/WebP/Lossless/PixOrCopy.cs | 7 ++- .../Formats/WebP/Lossless/PixOrCopyMode.cs | 4 +- .../Formats/WebP/Lossless/PredictorEncoder.cs | 60 ++++++++++++++----- .../Formats/WebP/Lossless/Vp8LBackwardRefs.cs | 9 ++- .../Formats/WebP/Lossless/Vp8LBitEntropy.cs | 4 +- .../Formats/WebP/Lossless/Vp8LEncoder.cs | 12 ++-- .../Formats/WebP/Lossless/Vp8LHashChain.cs | 8 ++- .../Formats/WebP/Lossless/Vp8LHistogram.cs | 10 ++-- .../Formats/WebP/Lossless/Vp8LLz77Type.cs | 4 +- .../Formats/WebP/Lossless/Vp8LMultipliers.cs | 4 +- .../Formats/WebP/Lossless/Vp8LRefsCursor.cs | 18 ------ .../Formats/WebP/Lossless/Vp8LStreaks.cs | 8 ++- .../Formats/WebP/Lossy/Vp8Encoder.cs | 5 +- .../Formats/WebP/WebPCommonUtils.cs | 12 ++-- .../Formats/WebP/WebPLookupTables.cs | 5 +- 34 files changed, 146 insertions(+), 118 deletions(-) delete mode 100644 src/ImageSharp/Formats/WebP/Lossless/Vp8LRefsCursor.cs diff --git a/src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs b/src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs index 2764abc30..a0dd88113 100644 --- a/src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs +++ b/src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Formats.WebP.BitWriter { @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.BitWriter /// internal class Vp8BitWriter { - private uint range; + /*private uint range; private uint value; @@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.BitWriter this.maxPos = 0; this.error = false; - //BitWriterResize(expected_size); - } + // BitWriterResize(expected_size); + }*/ } } diff --git a/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs b/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs index a3e35448b..bd7d260e4 100644 --- a/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs +++ b/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.BitWriter public Vp8LBitWriter Clone() { - byte[] clonedBuffer = new byte[this.buffer.Length]; + var clonedBuffer = new byte[this.buffer.Length]; Buffer.BlockCopy(this.buffer, 0, clonedBuffer, 0, this.cur); return new Vp8LBitWriter(clonedBuffer, this.bits, this.used, this.cur); } diff --git a/src/ImageSharp/Formats/WebP/EntropyIx.cs b/src/ImageSharp/Formats/WebP/EntropyIx.cs index f39c1981a..5bd354345 100644 --- a/src/ImageSharp/Formats/WebP/EntropyIx.cs +++ b/src/ImageSharp/Formats/WebP/EntropyIx.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Formats.WebP { diff --git a/src/ImageSharp/Formats/WebP/HistoIx.cs b/src/ImageSharp/Formats/WebP/HistoIx.cs index 916a2c074..51a77ccd0 100644 --- a/src/ImageSharp/Formats/WebP/HistoIx.cs +++ b/src/ImageSharp/Formats/WebP/HistoIx.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Formats.WebP { diff --git a/src/ImageSharp/Formats/WebP/IWebPEncoderOptions.cs b/src/ImageSharp/Formats/WebP/IWebPEncoderOptions.cs index 3ecef1b45..469421037 100644 --- a/src/ImageSharp/Formats/WebP/IWebPEncoderOptions.cs +++ b/src/ImageSharp/Formats/WebP/IWebPEncoderOptions.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Formats.WebP { diff --git a/src/ImageSharp/Formats/WebP/ImageExtensions.cs b/src/ImageSharp/Formats/WebP/ImageExtensions.cs index 5ceb85d74..0ed072a88 100644 --- a/src/ImageSharp/Formats/WebP/ImageExtensions.cs +++ b/src/ImageSharp/Formats/WebP/ImageExtensions.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System.IO; diff --git a/src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs index e23b6bf8e..d50937258 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs @@ -1,9 +1,8 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System; using System.Collections.Generic; -using SixLabors.ImageSharp.Formats.WebP.Lossy; namespace SixLabors.ImageSharp.Formats.WebP.Lossless { @@ -238,8 +237,16 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless /// The return value is the pointer to the best of the two backward refs viz, /// refs[0] or refs[1]. /// - public static Vp8LBackwardRefs GetBackwardReferences(int width, int height, Span bgra, int quality, - int lz77TypesToTry, ref int cacheBits, Vp8LHashChain hashChain, Vp8LBackwardRefs best, Vp8LBackwardRefs worst) + public static Vp8LBackwardRefs GetBackwardReferences( + int width, + int height, + Span bgra, + int quality, + int lz77TypesToTry, + ref int cacheBits, + Vp8LHashChain hashChain, + Vp8LBackwardRefs best, + Vp8LBackwardRefs worst) { var histo = new Vp8LHistogram[WebPConstants.MaxColorCacheBits]; int lz77TypeBest = 0; @@ -248,7 +255,6 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless Vp8LHashChain hashChainBox = null; for (int lz77Type = 1; lz77TypesToTry > 0; lz77TypesToTry &= ~lz77Type, lz77Type <<= 1) { - double bitCost; int cacheBitsTmp = cacheBitsInitial; if ((lz77TypesToTry & lz77Type) == 0) { @@ -279,7 +285,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless // Keep the best backward references. histo[0] = new Vp8LHistogram(worst, cacheBitsTmp); - bitCost = histo[0].EstimateBits(); + var bitCost = histo[0].EstimateBits(); if (lz77TypeBest == 0 || bitCost < bitCostBest) { diff --git a/src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs b/src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs index 68bd7df11..47f85b738 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System.Diagnostics; diff --git a/src/ImageSharp/Formats/WebP/Lossless/CostInterval.cs b/src/ImageSharp/Formats/WebP/Lossless/CostInterval.cs index 3f20b3dd6..16f2edc15 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/CostInterval.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/CostInterval.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System.Diagnostics; diff --git a/src/ImageSharp/Formats/WebP/Lossless/CostManager.cs b/src/ImageSharp/Formats/WebP/Lossless/CostManager.cs index 1f2241191..f648ae75c 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/CostManager.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/CostManager.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System.Collections.Generic; using System.Linq; @@ -222,7 +222,6 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless private void InsertInterval(double cost, int position, int start, int end) { // TODO: use COST_CACHE_INTERVAL_SIZE_MAX - var interval = new CostCacheInterval() { Cost = cost, diff --git a/src/ImageSharp/Formats/WebP/Lossless/CostModel.cs b/src/ImageSharp/Formats/WebP/Lossless/CostModel.cs index d0226bbbf..3d050ab42 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/CostModel.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/CostModel.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System; diff --git a/src/ImageSharp/Formats/WebP/Lossless/HistogramBinInfo.cs b/src/ImageSharp/Formats/WebP/Lossless/HistogramBinInfo.cs index eb58c6290..b75df6505 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HistogramBinInfo.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HistogramBinInfo.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Formats.WebP.Lossless { diff --git a/src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs index 064152c02..50c77a6e5 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs @@ -32,8 +32,8 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless int histoYSize = histoBits > 0 ? LosslessUtils.SubSampleSize(ySize, histoBits) : 1; int imageHistoRawSize = histoXSize * histoYSize; int entropyCombineNumBins = BinSize; - short[] mapTmp = new short[imageHistoRawSize]; - short[] clusterMappings = new short[imageHistoRawSize]; + var mapTmp = new short[imageHistoRawSize]; + var clusterMappings = new short[imageHistoRawSize]; int numUsed = imageHistoRawSize; var origHisto = new List(imageHistoRawSize); for (int i = 0; i < imageHistoRawSize; i++) @@ -370,6 +370,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless // Pop bestIdx2 from mappings. var mappingIndex = Array.BinarySearch(mappings, bestIdx2); + // TODO: memmove(mapping_index, mapping_index + 1, sizeof(*mapping_index) *((*num_used) - (mapping_index - mappings) - 1)); // Merge the histograms and remove bestIdx2 from the queue. diff --git a/src/ImageSharp/Formats/WebP/Lossless/HistogramPair.cs b/src/ImageSharp/Formats/WebP/Lossless/HistogramPair.cs index edd8a2ba7..7458909e5 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HistogramPair.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HistogramPair.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System.Diagnostics; diff --git a/src/ImageSharp/Formats/WebP/Lossless/HuffmanTree.cs b/src/ImageSharp/Formats/WebP/Lossless/HuffmanTree.cs index daf807335..d7179ad12 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HuffmanTree.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HuffmanTree.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System.Diagnostics; diff --git a/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeCode.cs b/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeCode.cs index 459a53de8..6b6e234d2 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeCode.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeCode.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Formats.WebP.Lossless { diff --git a/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeToken.cs b/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeToken.cs index 3708838c2..bd791b70c 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeToken.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HuffmanTreeToken.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System.Diagnostics; diff --git a/src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs b/src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs index 47f5ec128..62ecfa37a 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs @@ -154,7 +154,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless /// /// Create an optimal Huffman tree. /// - /// + /// /// The huffman tree. /// The histogram. /// The size of the histogram. diff --git a/src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs b/src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs index 94510efd2..eac88609c 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs @@ -205,7 +205,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless newBlue -= ColorTransformDelta((sbyte)m.GreenToBlue, green); newBlue -= ColorTransformDelta((sbyte)m.RedToBlue, red); newBlue &= 0xff; - data[i] = (uint)((argb & 0xff00ff00u) | (newRed << 16) | newBlue); + data[i] = (argb & 0xff00ff00u) | ((uint)newRed << 16) | (uint)newBlue; } } diff --git a/src/ImageSharp/Formats/WebP/Lossless/PixOrCopy.cs b/src/ImageSharp/Formats/WebP/Lossless/PixOrCopy.cs index 356db2e92..b8378d6cd 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/PixOrCopy.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/PixOrCopy.cs @@ -1,8 +1,11 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using System.Diagnostics; namespace SixLabors.ImageSharp.Formats.WebP.Lossless { + [DebuggerDisplay("Mode: {Mode}, Len: {Len}, BgraOrDistance: {BgraOrDistance}")] internal class PixOrCopy { public PixOrCopyMode Mode { get; set; } diff --git a/src/ImageSharp/Formats/WebP/Lossless/PixOrCopyMode.cs b/src/ImageSharp/Formats/WebP/Lossless/PixOrCopyMode.cs index 043a174fc..ae0fbec84 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/PixOrCopyMode.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/PixOrCopyMode.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Formats.WebP.Lossless { diff --git a/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs index ea11fcfe4..fcbac5267 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System; using System.Runtime.CompilerServices; @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless /// /// Finds the best predictor for each tile, and converts the image to residuals - /// with respect to predictions. If nearLosslessQuality < 100, applies + /// with respect to predictions. If nearLosslessQuality < 100, applies /// near lossless processing, shaving off more bits of residuals for lower qualities. /// public static void ResidualImage(int width, int height, int bits, Span argb, Span argbScratch, Span image, int nearLosslessQuality, bool exact, bool usedSubtractGreen) @@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless int tilesPerRow = LosslessUtils.SubSampleSize(width, bits); int tilesPerCol = LosslessUtils.SubSampleSize(height, bits); int maxQuantization = 1 << LosslessUtils.NearLosslessBits(nearLosslessQuality); - int[][] histo = new int[4][]; + var histo = new int[4][]; for (int i = 0; i < 4; i++) { histo[i] = new int[256]; @@ -73,12 +73,18 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless LosslessUtils.ColorCodeToMultipliers(image[offset - tileXSize], ref prevY); } - prevX = GetBestColorTransformForTile(tileX, tileY, bits, - prevX, prevY, - quality, width, height, - accumulatedRedHisto, - accumulatedBlueHisto, - argb); + prevX = GetBestColorTransformForTile( + tileX, + tileY, + bits, + prevX, + prevY, + quality, + width, + height, + accumulatedRedHisto, + accumulatedBlueHisto, + argb); image[offset] = MultipliersToColorCode(prevX); CopyTileWithColorTransform(width, height, tileXOffset, tileYOffset, maxTileSize, prevX, argb); @@ -118,9 +124,19 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless /// the given pixel). /// /// Best predictor. - private static int GetBestPredictorForTile(int width, int height, int tileX, int tileY, - int bits, int[][] accumulated, Span argbScratch, Span argb, - int maxQuantization, bool exact, bool usedSubtractGreen, Span modes) + private static int GetBestPredictorForTile( + int width, + int height, + int tileX, + int tileY, + int bits, + int[][] accumulated, + Span argbScratch, + Span argb, + int maxQuantization, + bool exact, + bool usedSubtractGreen, + Span modes) { const int numPredModes = 14; int startX = tileX << bits; @@ -501,9 +517,21 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless xEnd = width; } - GetResidual(width, height, upperRow, currentRow, currentMaxDiffs, - mode, x, xEnd, y, maxQuantization, exact, - usedSubtractGreen, argb.Slice((y * width) + x)); + GetResidual( + width, + height, + upperRow, + currentRow, + currentMaxDiffs, + mode, + x, + xEnd, + y, + maxQuantization, + exact, + usedSubtractGreen, + argb.Slice((y * width) + x)); + x = xEnd; } } diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LBackwardRefs.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LBackwardRefs.cs index 7f35d08e4..f80d26697 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LBackwardRefs.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LBackwardRefs.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System.Collections.Generic; @@ -13,10 +13,13 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless } /// - /// Common block-size. + /// Gets or sets the common block-size. /// public int BlockSize { get; set; } + /// + /// Gets the backward references. + /// public List Refs { get; } public void Add(PixOrCopy pixOrCopy) diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LBitEntropy.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LBitEntropy.cs index 0433f3eed..bdc8d853f 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LBitEntropy.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LBitEntropy.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System; diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs index 1663c32dd..658a2f58c 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs @@ -315,7 +315,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless cacheBits = 0; } - // Calculate backward references from ARGB image. + // Calculate backward references from BGRA image. BackwardReferenceEncoder.HashChainFill(hashChain, bgra, quality, width, height); Vp8LBitWriter bitWriterBest = null; @@ -333,7 +333,6 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless Vp8LBackwardRefs refsTmp = refsArray[refsBest.Equals(refsArray[0]) ? 1 : 0]; // TODO: this.bitWriter.Reset(); - var tmpHisto = new Vp8LHistogram(cacheBits); var histogramImage = new List(histogramImageXySize); for (int i = 0; i < histogramImageXySize; i++) @@ -419,7 +418,6 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless this.StoreImageToBitMask(width, histogramBits, refsBest, histogramSymbols, huffmanCodes); // TODO: Keep track of the smallest image so far. - if (bitWriterBest != null && this.bitWriter.NumBytes() < bitWriterBest.NumBytes()) { // TODO : This was done in the reference by swapping references, this will be slower @@ -711,7 +709,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless } } - private void StoreHuffmanTreeOfHuffmanTreeToBitMask(byte[] codeLengthBitdepth) + private void StoreHuffmanTreeOfHuffmanTreeToBitMask(byte[] codeLengthBitDepth) { // RFC 1951 will calm you down if you are worried about this funny sequence. // This sequence is tuned from that, but more weighted for lower symbol count, @@ -722,7 +720,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless int codesToStore = WebPConstants.CodeLengthCodes; for (; codesToStore > 4; codesToStore--) { - if (codeLengthBitdepth[storageOrder[codesToStore - 1]] != 0) + if (codeLengthBitDepth[storageOrder[codesToStore - 1]] != 0) { break; } @@ -731,7 +729,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless this.bitWriter.PutBits((uint)codesToStore - 4, 4); for (int i = 0; i < codesToStore; i++) { - this.bitWriter.PutBits(codeLengthBitdepth[storageOrder[i]], 3); + this.bitWriter.PutBits(codeLengthBitDepth[storageOrder[i]], 3); } } @@ -1353,7 +1351,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless } // Create Huffman trees. - bool[] bufRle = new bool[maxNumSymbols]; + var bufRle = new bool[maxNumSymbols]; var huffTree = new HuffmanTree[3 * maxNumSymbols]; for (int i = 0; i < huffTree.Length; i++) { diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LHashChain.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LHashChain.cs index 60b795c15..0262ac332 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LHashChain.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LHashChain.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System; @@ -19,13 +19,15 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless } /// + /// Gets the offset length. /// The 20 most significant bits contain the offset at which the best match is found. - /// These 20 bits are the limit defined by GetWindowSizeForHashChain (through WindowSize = 1 << 20). + /// These 20 bits are the limit defined by GetWindowSizeForHashChain (through WindowSize = 1 << 20). /// The lower 12 bits contain the length of the match. /// public uint[] OffsetLength { get; } /// + /// Gets the size of the hash chain. /// This is the maximum size of the hash_chain that can be constructed. /// Typically this is the pixel count (width x height) for a given image. /// diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LHistogram.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LHistogram.cs index d18910574..9b591dcd0 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LHistogram.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LHistogram.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System; using System.Collections.Generic; @@ -67,9 +67,6 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless this.IsUsed = new bool[5]; } - /// - public IDeepCloneable DeepClone() => new Vp8LHistogram(this); - /// /// Gets or sets the palette code bits. /// @@ -109,6 +106,9 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless public bool[] IsUsed { get; } + /// + public IDeepCloneable DeepClone() => new Vp8LHistogram(this); + /// /// Collect all the references into a histogram (without reset). /// diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LLz77Type.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LLz77Type.cs index 63d9f6e02..734aa5dce 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LLz77Type.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LLz77Type.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Formats.WebP.Lossless { diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LMultipliers.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LMultipliers.cs index 3ce9a93ec..8a9088b57 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LMultipliers.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LMultipliers.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Formats.WebP.Lossless { diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LRefsCursor.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LRefsCursor.cs deleted file mode 100644 index 6578d3f51..000000000 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LRefsCursor.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. - -namespace SixLabors.ImageSharp.Formats.WebP.Lossless -{ - internal class Vp8LRefsCursor - { - public Vp8LRefsCursor(Vp8LBackwardRefs refs) - { - //this.Refs = refs; - //this.CurrentPos = 0; - } - - //public PixOrCopy Refs { get; } - - public PixOrCopy CurrentPos { get; } - } -} diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LStreaks.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LStreaks.cs index bec2cc099..e0e976068 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LStreaks.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LStreaks.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Formats.WebP.Lossless { @@ -17,12 +17,14 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossless } /// + /// Gets the streak count. /// index: 0=zero streak, 1=non-zero streak. /// public int[] Counts { get; } /// - /// [zero/non-zero][streak < 3 / streak >= 3]. + /// Gets the streaks. + /// [zero/non-zero][streak < 3 / streak >= 3]. /// public int[][] Streaks { get; } diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs index 546de6624..89cf1e3b4 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy /// /// A bit writer for writing lossy webp streams. /// - private Vp8BitWriter bitWriter; + private readonly Vp8BitWriter bitWriter; /// /// Initializes a new instance of the class. @@ -34,7 +34,8 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy { this.memoryAllocator = memoryAllocator; - // TODO: initialize bitwriter + // TODO: properly initialize the bitwriter + this.bitWriter = new Vp8BitWriter(); } public void Encode(Image image, Stream stream) diff --git a/src/ImageSharp/Formats/WebP/WebPCommonUtils.cs b/src/ImageSharp/Formats/WebP/WebPCommonUtils.cs index 52027192b..6098d1b69 100644 --- a/src/ImageSharp/Formats/WebP/WebPCommonUtils.cs +++ b/src/ImageSharp/Formats/WebP/WebPCommonUtils.cs @@ -1,5 +1,5 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the GNU Affero General Public License, Version 3. +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. using System.Runtime.CompilerServices; @@ -8,9 +8,11 @@ namespace SixLabors.ImageSharp.Formats.WebP /// /// Utility methods for lossy and lossless webp format. /// - public static class WebPCommonUtils + internal static class WebPCommonUtils { - // Returns 31 ^ clz(n) = log2(n).Returns 31 ^ clz(n) = log2(n). + /// + /// Returns 31 ^ clz(n) = log2(n).Returns 31 ^ clz(n) = log2(n). + /// [MethodImpl(InliningOptions.ShortMethod)] public static int BitsLog2Floor(uint n) { @@ -21,7 +23,7 @@ namespace SixLabors.ImageSharp.Formats.WebP n >>= 8; } - return logValue + WebPLookupTables.LogTable8bit[n]; + return logValue + WebPLookupTables.LogTable8Bit[n]; } } } diff --git a/src/ImageSharp/Formats/WebP/WebPLookupTables.cs b/src/ImageSharp/Formats/WebP/WebPLookupTables.cs index 43ded2c51..148dd0a54 100644 --- a/src/ImageSharp/Formats/WebP/WebPLookupTables.cs +++ b/src/ImageSharp/Formats/WebP/WebPLookupTables.cs @@ -236,7 +236,8 @@ namespace SixLabors.ImageSharp.Formats.WebP 0x40, 0x72, 0x7e, 0x61, 0x6f, 0x50, 0x71, 0x7f, 0x60, 0x70 }; - public static readonly uint[] PlaneToCodeLut = { + public static readonly uint[] PlaneToCodeLut = + { 96, 73, 55, 39, 23, 13, 5, 1, 255, 255, 255, 255, 255, 255, 255, 255, 101, 78, 58, 42, 26, 16, 8, 2, 0, 3, 9, 17, 27, 43, 59, 79, 102, 86, 62, 46, 32, 20, 10, 6, 4, 7, 11, 21, 33, 47, 63, 87, @@ -248,7 +249,7 @@ namespace SixLabors.ImageSharp.Formats.WebP }; // 31 ^ clz(i) - public static readonly byte[] LogTable8bit = + public static readonly byte[] LogTable8Bit = { 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,