-
-
Notifications
You must be signed in to change notification settings - Fork 852
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b89bc54
commit 3940f02
Showing
5 changed files
with
181 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,12 +95,10 @@ public WebpLosslessDecoder(Vp8LBitReader bitReader, MemoryAllocator memoryAlloca | |
public void Decode<TPixel>(Buffer2D<TPixel> pixels, int width, int height) | ||
where TPixel : unmanaged, IPixel<TPixel> | ||
{ | ||
using (Vp8LDecoder decoder = new Vp8LDecoder(width, height, this.memoryAllocator)) | ||
{ | ||
this.DecodeImageStream(decoder, width, height, true); | ||
this.DecodeImageData(decoder, decoder.Pixels.Memory.Span); | ||
this.DecodePixelValues(decoder, pixels, width, height); | ||
} | ||
using Vp8LDecoder decoder = new(width, height, this.memoryAllocator); | ||
this.DecodeImageStream(decoder, width, height, true); | ||
this.DecodeImageData(decoder, decoder.Pixels.Memory.Span); | ||
this.DecodePixelValues(decoder, pixels, width, height); | ||
} | ||
|
||
public IMemoryOwner<uint> DecodeImageStream(Vp8LDecoder decoder, int xSize, int ySize, bool isLevel0) | ||
|
@@ -616,15 +614,12 @@ private void ReadHuffmanCodeLengths(Span<HuffmanCode> table, int[] codeLengthCod | |
private void ReadTransformation(int xSize, int ySize, Vp8LDecoder decoder) | ||
{ | ||
Vp8LTransformType transformType = (Vp8LTransformType)this.bitReader.ReadValue(2); | ||
Vp8LTransform transform = new Vp8LTransform(transformType, xSize, ySize); | ||
Vp8LTransform transform = new(transformType, xSize, ySize); | ||
|
||
// Each transform is allowed to be used only once. | ||
foreach (Vp8LTransform decoderTransform in decoder.Transforms) | ||
if (decoder.Transforms.Any(decoderTransform => decoderTransform.TransformType == transform.TransformType)) | ||
{ | ||
if (decoderTransform.TransformType == transform.TransformType) | ||
{ | ||
WebpThrowHelper.ThrowImageFormatException("Each transform can only be present once"); | ||
} | ||
WebpThrowHelper.ThrowImageFormatException("Each transform can only be present once"); | ||
} | ||
|
||
switch (transformType) | ||
|
@@ -744,61 +739,67 @@ public void DecodeAlphaData(AlphaDecoder dec) | |
|
||
this.bitReader.FillBitWindow(); | ||
int code = (int)this.ReadSymbol(htreeGroup[0].HTrees[HuffIndex.Green]); | ||
if (code < WebpConstants.NumLiteralCodes) | ||
switch (code) | ||
{ | ||
// Literal | ||
data[pos] = (byte)code; | ||
++pos; | ||
++col; | ||
|
||
if (col >= width) | ||
case < WebpConstants.NumLiteralCodes: | ||
{ | ||
col = 0; | ||
++row; | ||
if (row <= lastRow && row % WebpConstants.NumArgbCacheRows == 0) | ||
// Literal | ||
data[pos] = (byte)code; | ||
++pos; | ||
++col; | ||
|
||
if (col >= width) | ||
{ | ||
dec.ExtractPalettedAlphaRows(row); | ||
col = 0; | ||
++row; | ||
if (row <= lastRow && row % WebpConstants.NumArgbCacheRows == 0) | ||
{ | ||
dec.ExtractPalettedAlphaRows(row); | ||
} | ||
} | ||
|
||
break; | ||
} | ||
Check failure on line 762 in src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)
Check failure on line 762 in src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)
|
||
} | ||
else if (code < lenCodeLimit) | ||
{ | ||
// Backward reference | ||
int lengthSym = code - WebpConstants.NumLiteralCodes; | ||
int length = this.GetCopyLength(lengthSym); | ||
int distSymbol = (int)this.ReadSymbol(htreeGroup[0].HTrees[HuffIndex.Dist]); | ||
this.bitReader.FillBitWindow(); | ||
int distCode = this.GetCopyDistance(distSymbol); | ||
int dist = PlaneCodeToDistance(width, distCode); | ||
if (pos >= dist && end - pos >= length) | ||
{ | ||
CopyBlock8B(data, pos, dist, length); | ||
} | ||
else | ||
case < lenCodeLimit: | ||
{ | ||
WebpThrowHelper.ThrowImageFormatException("error while decoding alpha data"); | ||
} | ||
// Backward reference | ||
int lengthSym = code - WebpConstants.NumLiteralCodes; | ||
int length = this.GetCopyLength(lengthSym); | ||
int distSymbol = (int)this.ReadSymbol(htreeGroup[0].HTrees[HuffIndex.Dist]); | ||
this.bitReader.FillBitWindow(); | ||
int distCode = this.GetCopyDistance(distSymbol); | ||
int dist = PlaneCodeToDistance(width, distCode); | ||
if (pos >= dist && end - pos >= length) | ||
{ | ||
CopyBlock8B(data, pos, dist, length); | ||
} | ||
else | ||
{ | ||
WebpThrowHelper.ThrowImageFormatException("error while decoding alpha data"); | ||
} | ||
|
||
pos += length; | ||
col += length; | ||
while (col >= width) | ||
{ | ||
col -= width; | ||
++row; | ||
if (row <= lastRow && row % WebpConstants.NumArgbCacheRows == 0) | ||
pos += length; | ||
col += length; | ||
while (col >= width) | ||
{ | ||
dec.ExtractPalettedAlphaRows(row); | ||
col -= width; | ||
++row; | ||
if (row <= lastRow && row % WebpConstants.NumArgbCacheRows == 0) | ||
{ | ||
dec.ExtractPalettedAlphaRows(row); | ||
} | ||
} | ||
} | ||
|
||
if (pos < last && (col & mask) > 0) | ||
{ | ||
htreeGroup = GetHTreeGroupForPos(hdr, col, row); | ||
if (pos < last && (col & mask) > 0) | ||
{ | ||
htreeGroup = GetHTreeGroupForPos(hdr, col, row); | ||
} | ||
|
||
break; | ||
} | ||
Check failure on line 799 in src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)
Check failure on line 799 in src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)
|
||
} | ||
else | ||
{ | ||
WebpThrowHelper.ThrowImageFormatException("bitstream error while parsing alpha data"); | ||
default: | ||
WebpThrowHelper.ThrowImageFormatException("bitstream error while parsing alpha data"); | ||
break; | ||
} | ||
|
||
this.bitReader.Eos = this.bitReader.IsEndOfStream(); | ||
|
Oops, something went wrong.