Browse Source

Fix some warnings

pull/1552/head
Brian Popow 6 years ago
parent
commit
beca5f5352
  1. 26
      src/ImageSharp/Formats/WebP/LosslessUtils.cs
  2. 4
      src/ImageSharp/Formats/WebP/Vp8LBitReader.cs
  3. 45
      src/ImageSharp/Formats/WebP/WebPConstants.cs
  4. 7
      src/ImageSharp/Formats/WebP/WebPImageInfo.cs
  5. 16
      src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs
  6. 2
      src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs
  7. 9
      src/ImageSharp/Formats/WebP/WebPMetadata.cs

26
src/ImageSharp/Formats/WebP/LosslessUtils.cs

@ -1,3 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Runtime.InteropServices;
@ -132,6 +135,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
newBlue += ColorTransformDelta(m.GreenToBlue, (sbyte)green);
newBlue += ColorTransformDelta(m.RedToBlue, (sbyte)newRed);
newBlue &= 0xff;
// uint pixelValue = (uint)((argb & 0xff00ff00u) | (newRed << 16) | newBlue);
pixelData[i] = (uint)((argb & 0xff00ff00u) | (newRed << 16) | newBlue);
}
@ -162,6 +166,28 @@ namespace SixLabors.ImageSharp.Formats.WebP
return newColorMap;
}
public static void PredictorInverseTransform(Vp8LTransform transform, uint[] pixelData)
{
int processedPixels = 0;
int yStart = 0;
int width = transform.XSize;
// PredictorAdd0(in, NULL, 1, out);
PredictorAdd1(pixelData, width - 1);
processedPixels += width;
yStart++;
int y = yStart;
int tileWidth = 1 << transform.Bits;
int mask = tileWidth - 1;
int tilesPerRow = SubSampleSize(width, transform.Bits);
}
private static uint Predictor0C(uint left, uint[] top)
{
return WebPConstants.ArgbBlack;
}
/// <summary>
/// Computes sampled size of 'size' when sampling using 'sampling bits'.
/// </summary>

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

@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
/// </summary>
private const int VP8L_WBITS = 32;
private uint[] kBitMask =
private readonly uint[] kBitMask =
{
0,
0x000001, 0x000003, 0x000007, 0x00000f,
@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
/// <summary>
/// Buffer length.
/// </summary>
private long len;
private readonly long len;
/// <summary>
/// Byte position in buffer.

45
src/ImageSharp/Formats/WebP/WebPConstants.cs

@ -52,54 +52,57 @@ namespace SixLabors.ImageSharp.Formats.WebP
/// <summary>
/// Signature byte which identifies a VP8L header.
/// </summary>
public static byte Vp8LMagicByte = 0x2F;
public const byte Vp8LMagicByte = 0x2F;
/// <summary>
/// 3 bits reserved for version.
/// </summary>
public static int Vp8LVersionBits = 3;
public const int Vp8LVersionBits = 3;
/// <summary>
/// Bits for width and height infos of a VPL8 image.
/// </summary>
public static int Vp8LImageSizeBits = 14;
public const int Vp8LImageSizeBits = 14;
/// <summary>
/// Maximum number of color cache bits.
/// </summary>
public static int MaxColorCacheBits = 11;
public const int MaxColorCacheBits = 11;
/// <summary>
/// The maximum number of allowed transforms in a bitstream.
/// </summary>
public static int MaxNumberOfTransforms = 4;
public const int MaxNumberOfTransforms = 4;
public static int MaxAllowedCodeLength = 15;
public const int MaxAllowedCodeLength = 15;
public static int DefaultCodeLength = 8;
public const int DefaultCodeLength = 8;
public static int HuffmanCodesPerMetaCode = 5;
public const int HuffmanCodesPerMetaCode = 5;
public static int NumLiteralCodes = 256;
public const uint ArgbBlack = 0xff000000;
public static int NumLengthCodes = 24;
public const int NumLiteralCodes = 256;
public static int NumDistanceCodes = 40;
public const int NumLengthCodes = 24;
public static int LengthTableBits = 7;
public const int NumDistanceCodes = 40;
public static uint kCodeLengthLiterals = 16;
public const int LengthTableBits = 7;
public static int kCodeLengthRepeatCode = 16;
public const uint KCodeLengthLiterals = 16;
public static int[] kCodeLengthExtraBits = { 2, 3, 7 };
public const int KCodeLengthRepeatCode = 16;
public static int[] kCodeLengthRepeatOffsets = { 3, 3, 11 };
public static readonly int[] KCodeLengthExtraBits = { 2, 3, 7 };
public static int[] kAlphabetSize = {
NumLiteralCodes + NumLengthCodes,
NumLiteralCodes, NumLiteralCodes, NumLiteralCodes,
NumDistanceCodes
};
public static readonly int[] KCodeLengthRepeatOffsets = { 3, 3, 11 };
public static readonly int[] KAlphabetSize =
{
NumLiteralCodes + NumLengthCodes,
NumLiteralCodes, NumLiteralCodes, NumLiteralCodes,
NumDistanceCodes
};
}
}

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

@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
public int Height { get; set; }
/// <summary>
/// Gets or sets whether this image uses a lossless compression.
/// Gets or sets a value indicating whether this image uses a lossless compression.
/// </summary>
public bool IsLossLess { get; set; }
@ -26,12 +26,11 @@ namespace SixLabors.ImageSharp.Formats.WebP
public WebPFeatures Features { get; set; }
/// <summary>
/// The bytes of the image payload.
/// Gets or sets the bytes of the image payload.
/// </summary>
public uint ImageDataSize { get; set; }
// TODO: not sure if the bitreader is in the right place here, but for the sake of simplicity it will stay here for now.
// Will be refactored later.
// TODO: not sure if the bitreader is in the right place here, but for the sake of simplicity it will stay here for now. Will be refactored later.
public Vp8LBitReader Vp9LBitReader { get; set; }
}
}

16
src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs

@ -368,7 +368,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
// Find maximum alphabet size for the hTree group.
for (int j = 0; j < WebPConstants.HuffmanCodesPerMetaCode; j++)
{
int alphabetSize = WebPConstants.kAlphabetSize[j];
int alphabetSize = WebPConstants.KAlphabetSize[j];
if (j == 0 && colorCacheBits > 0)
{
alphabetSize += 1 << colorCacheBits;
@ -394,7 +394,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
var codeLengths = new int[maxAlphabetSize];
for (int j = 0; j < WebPConstants.HuffmanCodesPerMetaCode; j++)
{
int alphabetSize = WebPConstants.kAlphabetSize[j];
int alphabetSize = WebPConstants.KAlphabetSize[j];
if (j == 0 && colorCacheBits > 0)
{
alphabetSize += 1 << colorCacheBits;
@ -548,7 +548,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
HuffmanCode huffmanCode = table[idx];
this.bitReader.AdvanceBitPosition(huffmanCode.BitsUsed);
uint codeLen = huffmanCode.Value;
if (codeLen < WebPConstants.kCodeLengthLiterals)
if (codeLen < WebPConstants.KCodeLengthLiterals)
{
codeLengths[symbol++] = (int)codeLen;
if (codeLen != 0)
@ -558,10 +558,10 @@ namespace SixLabors.ImageSharp.Formats.WebP
}
else
{
bool usePrev = codeLen == WebPConstants.kCodeLengthRepeatCode;
uint slot = codeLen - WebPConstants.kCodeLengthLiterals;
int extraBits = WebPConstants.kCodeLengthExtraBits[slot];
int repeatOffset = WebPConstants.kCodeLengthRepeatOffsets[slot];
bool usePrev = codeLen == WebPConstants.KCodeLengthRepeatCode;
uint slot = codeLen - WebPConstants.KCodeLengthLiterals;
int extraBits = WebPConstants.KCodeLengthExtraBits[slot];
int repeatOffset = WebPConstants.KCodeLengthRepeatOffsets[slot];
int repeat = (int)(this.bitReader.ReadBits(extraBits) + repeatOffset);
if (symbol + repeat > numSymbols)
{
@ -637,7 +637,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
switch (transformType)
{
case Vp8LTransformType.PredictorTransform:
// LosslessUtils.PredictorInverseTransform(transforms[i], pixelData);
LosslessUtils.PredictorInverseTransform(transforms[i], pixelData);
break;
case Vp8LTransformType.SubtractGreen:
LosslessUtils.AddGreenToBlueAndRed(pixelData);

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

@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
}
byte version = (byte)((bitReader.ReadBit() ? 2 : 0) | (bitReader.ReadBit() ? 1 : 0));
(ReconstructionFilter rec, LoopFilter loop) = DecodeVersion(version);
(ReconstructionFilter rec, LoopFilter loop) = this.DecodeVersion(version);
bool isShowFrame = bitReader.ReadBit();

9
src/ImageSharp/Formats/WebP/WebPMetadata.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Collections;
using System.Collections.Generic;
namespace SixLabors.ImageSharp.Formats.WebP
@ -28,9 +27,6 @@ namespace SixLabors.ImageSharp.Formats.WebP
this.Format = other.Format;
}
/// <inheritdoc/>
public IDeepCloneable DeepClone() => new WebPMetadata(this);
/// <summary>
/// The webp format used. Either lossless or lossy.
/// </summary>
@ -42,8 +38,11 @@ namespace SixLabors.ImageSharp.Formats.WebP
public Queue<WebPChunkType> ChunkTypes { get; set; } = new Queue<WebPChunkType>();
/// <summary>
/// Indicates, if the webp file contains a animation.
/// Gets or sets a value indicating whether the webp file contains a animation.
/// </summary>
public bool Animated { get; set; } = false;
/// <inheritdoc/>
public IDeepCloneable DeepClone() => new WebPMetadata(this);
}
}

Loading…
Cancel
Save