Browse Source

Fix some warnings

pull/1552/head
Brian Popow 7 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;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -132,6 +135,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
newBlue += ColorTransformDelta(m.GreenToBlue, (sbyte)green); newBlue += ColorTransformDelta(m.GreenToBlue, (sbyte)green);
newBlue += ColorTransformDelta(m.RedToBlue, (sbyte)newRed); newBlue += ColorTransformDelta(m.RedToBlue, (sbyte)newRed);
newBlue &= 0xff; newBlue &= 0xff;
// uint pixelValue = (uint)((argb & 0xff00ff00u) | (newRed << 16) | newBlue); // uint pixelValue = (uint)((argb & 0xff00ff00u) | (newRed << 16) | newBlue);
pixelData[i] = (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; 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> /// <summary>
/// Computes sampled size of 'size' when sampling using 'sampling bits'. /// Computes sampled size of 'size' when sampling using 'sampling bits'.
/// </summary> /// </summary>

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

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

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

@ -52,54 +52,57 @@ namespace SixLabors.ImageSharp.Formats.WebP
/// <summary> /// <summary>
/// Signature byte which identifies a VP8L header. /// Signature byte which identifies a VP8L header.
/// </summary> /// </summary>
public static byte Vp8LMagicByte = 0x2F; public const byte Vp8LMagicByte = 0x2F;
/// <summary> /// <summary>
/// 3 bits reserved for version. /// 3 bits reserved for version.
/// </summary> /// </summary>
public static int Vp8LVersionBits = 3; public const int Vp8LVersionBits = 3;
/// <summary> /// <summary>
/// Bits for width and height infos of a VPL8 image. /// Bits for width and height infos of a VPL8 image.
/// </summary> /// </summary>
public static int Vp8LImageSizeBits = 14; public const int Vp8LImageSizeBits = 14;
/// <summary> /// <summary>
/// Maximum number of color cache bits. /// Maximum number of color cache bits.
/// </summary> /// </summary>
public static int MaxColorCacheBits = 11; public const int MaxColorCacheBits = 11;
/// <summary> /// <summary>
/// The maximum number of allowed transforms in a bitstream. /// The maximum number of allowed transforms in a bitstream.
/// </summary> /// </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 = { public static readonly int[] KCodeLengthRepeatOffsets = { 3, 3, 11 };
NumLiteralCodes + NumLengthCodes,
NumLiteralCodes, NumLiteralCodes, NumLiteralCodes, public static readonly int[] KAlphabetSize =
NumDistanceCodes {
}; 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; } public int Height { get; set; }
/// <summary> /// <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> /// </summary>
public bool IsLossLess { get; set; } public bool IsLossLess { get; set; }
@ -26,12 +26,11 @@ namespace SixLabors.ImageSharp.Formats.WebP
public WebPFeatures Features { get; set; } public WebPFeatures Features { get; set; }
/// <summary> /// <summary>
/// The bytes of the image payload. /// Gets or sets the bytes of the image payload.
/// </summary> /// </summary>
public uint ImageDataSize { get; set; } 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. // 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.
// Will be refactored later.
public Vp8LBitReader Vp9LBitReader { get; set; } 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. // 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.kAlphabetSize[j]; int alphabetSize = WebPConstants.KAlphabetSize[j];
if (j == 0 && colorCacheBits > 0) if (j == 0 && colorCacheBits > 0)
{ {
alphabetSize += 1 << colorCacheBits; alphabetSize += 1 << colorCacheBits;
@ -394,7 +394,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
var codeLengths = new int[maxAlphabetSize]; var codeLengths = new int[maxAlphabetSize];
for (int j = 0; j < WebPConstants.HuffmanCodesPerMetaCode; j++) for (int j = 0; j < WebPConstants.HuffmanCodesPerMetaCode; j++)
{ {
int alphabetSize = WebPConstants.kAlphabetSize[j]; int alphabetSize = WebPConstants.KAlphabetSize[j];
if (j == 0 && colorCacheBits > 0) if (j == 0 && colorCacheBits > 0)
{ {
alphabetSize += 1 << colorCacheBits; alphabetSize += 1 << colorCacheBits;
@ -548,7 +548,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
HuffmanCode huffmanCode = table[idx]; HuffmanCode huffmanCode = table[idx];
this.bitReader.AdvanceBitPosition(huffmanCode.BitsUsed); this.bitReader.AdvanceBitPosition(huffmanCode.BitsUsed);
uint codeLen = huffmanCode.Value; uint codeLen = huffmanCode.Value;
if (codeLen < WebPConstants.kCodeLengthLiterals) if (codeLen < WebPConstants.KCodeLengthLiterals)
{ {
codeLengths[symbol++] = (int)codeLen; codeLengths[symbol++] = (int)codeLen;
if (codeLen != 0) if (codeLen != 0)
@ -558,10 +558,10 @@ namespace SixLabors.ImageSharp.Formats.WebP
} }
else else
{ {
bool usePrev = codeLen == WebPConstants.kCodeLengthRepeatCode; bool usePrev = codeLen == WebPConstants.KCodeLengthRepeatCode;
uint slot = codeLen - WebPConstants.kCodeLengthLiterals; uint slot = codeLen - WebPConstants.KCodeLengthLiterals;
int extraBits = WebPConstants.kCodeLengthExtraBits[slot]; int extraBits = WebPConstants.KCodeLengthExtraBits[slot];
int repeatOffset = WebPConstants.kCodeLengthRepeatOffsets[slot]; int repeatOffset = WebPConstants.KCodeLengthRepeatOffsets[slot];
int repeat = (int)(this.bitReader.ReadBits(extraBits) + repeatOffset); int repeat = (int)(this.bitReader.ReadBits(extraBits) + repeatOffset);
if (symbol + repeat > numSymbols) if (symbol + repeat > numSymbols)
{ {
@ -637,7 +637,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
switch (transformType) switch (transformType)
{ {
case Vp8LTransformType.PredictorTransform: case Vp8LTransformType.PredictorTransform:
// LosslessUtils.PredictorInverseTransform(transforms[i], pixelData); LosslessUtils.PredictorInverseTransform(transforms[i], pixelData);
break; break;
case Vp8LTransformType.SubtractGreen: case Vp8LTransformType.SubtractGreen:
LosslessUtils.AddGreenToBlueAndRed(pixelData); 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)); 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(); bool isShowFrame = bitReader.ReadBit();

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

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

Loading…
Cancel
Save