Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
19bdecc
Replace IImageDecoder
JimBobSquarePants Oct 28, 2022
31def5c
Replace IImageEncoder
JimBobSquarePants Oct 28, 2022
5726089
Make decoder options init only (except Configuration cos tests)
JimBobSquarePants Oct 28, 2022
7d5c05b
Delete ImageTests.ImageLoadTestBase.Fakes.cs
JimBobSquarePants Oct 28, 2022
93a1700
Use new not shared options.
JimBobSquarePants Oct 29, 2022
391442b
Merge branch 'main' into js/decoder-attempt-2
JimBobSquarePants Nov 9, 2022
5669626
Merge branch 'main' into js/decoder-attempt-2
JimBobSquarePants Nov 15, 2022
1d99413
Re-introduce IImageDecoder and split decoding pipelines.
JimBobSquarePants Nov 15, 2022
c550af8
Re-introduce IImageEncoder and split encoding pipelines.
JimBobSquarePants Nov 15, 2022
b1db34d
Rename base encoder
JimBobSquarePants Nov 15, 2022
dd88269
Stub code to prevent unnecessary stream copying on decode.
JimBobSquarePants Nov 15, 2022
b98e1df
Update AotCompilerTools.cs
JimBobSquarePants Nov 15, 2022
1dc7bbf
Update SpecializedImageDecoder{T}.cs
JimBobSquarePants Nov 15, 2022
afa204b
Use ScaleToTargetSize
JimBobSquarePants Nov 20, 2022
2721ad5
Enable optimization.
JimBobSquarePants Nov 20, 2022
0dc9949
Rename and move configuration module.
JimBobSquarePants Nov 20, 2022
b32755d
Merge branch 'main' into js/decoder-attempt-2
JimBobSquarePants Nov 21, 2022
32965d3
Simplify position checks.
JimBobSquarePants Nov 22, 2022
8fdd6b0
Use default cancellation token
JimBobSquarePants Nov 22, 2022
6978235
Feedback
JimBobSquarePants Nov 25, 2022
28243df
Better tests for stream synchronization
JimBobSquarePants Nov 25, 2022
4891dc3
Use real cancellation handling.
JimBobSquarePants Nov 25, 2022
47f1cda
Rename method
JimBobSquarePants Nov 27, 2022
4a613b6
Update src/ImageSharp/IO/BufferedReadStream.cs
JimBobSquarePants Nov 27, 2022
d8c8244
Merge branch 'js/decoder-attempt-2' of https://github.com/SixLabors/I…
JimBobSquarePants Nov 27, 2022
00ca204
re-create add original DecodeAsync_IsCancellable test
antonfirsov Dec 4, 2022
3a7c4f4
fix Decode_Cancellation tests
antonfirsov Dec 4, 2022
447cd85
enough to test this for one format in ImageTests
antonfirsov Dec 4, 2022
937e78c
cover JpegDecoder's own cancellation support
antonfirsov Dec 4, 2022
112b114
with BufferedReadStream decoder cancellation works for all decoders, …
antonfirsov Dec 4, 2022
d1c76e2
fix comments
antonfirsov Dec 4, 2022
f3a2aea
Merge pull request #2301 from SixLabors/af/decoder-tests
JimBobSquarePants Dec 4, 2022
0018845
fix Identify cancellation tests
antonfirsov Dec 4, 2022
6a07a51
one more fix
antonfirsov Dec 4, 2022
6675333
Merge branch 'af/decoder-tests' into js/decoder-attempt-2
antonfirsov Dec 4, 2022
1b1be0a
fix condition
antonfirsov Dec 5, 2022
ce7ef11
cancellation tests: larger images, don't go above 0.7
antonfirsov Dec 7, 2022
b9ba211
only test for pre-cancellation with IdentifyAsync
antonfirsov Dec 7, 2022
834f686
increase timeout
antonfirsov Dec 7, 2022
25e8d01
cancellation detection in png DecodePixelData
antonfirsov Dec 7, 2022
0eadea2
skip PNG cancellation tests for Unix
antonfirsov Dec 7, 2022
a58e6ff
Add more cancellation checks
JimBobSquarePants Dec 8, 2022
e2c5748
Base the buffer size on the stream length
JimBobSquarePants Dec 8, 2022
718bdc4
Experiment with a much shorter timeout.
JimBobSquarePants Dec 8, 2022
5f488ee
Revert "Experiment with a much shorter timeout."
JimBobSquarePants Dec 8, 2022
64b4045
disable gif cancellation tests
antonfirsov Dec 9, 2022
475825d
Merge branch 'js/decoder-attempt-2' of https://github.com/SixLabors/I…
antonfirsov Dec 9, 2022
9a55652
we should validate cancellation for each decoder separately
antonfirsov Dec 9, 2022
bb22d69
Disable cancellation tests on Unix entirely
antonfirsov Dec 9, 2022
2145794
Fix test file
JimBobSquarePants Dec 11, 2022
bd6e58c
Merge branch 'js/decoder-attempt-2' of https://github.com/SixLabors/I…
JimBobSquarePants Dec 11, 2022
1dd2d6e
Better error handling in action wrapper
JimBobSquarePants Dec 12, 2022
85dc0f3
[Experiment] do not timeout LoadAsync_IsCancellable
antonfirsov Dec 12, 2022
205e1b3
Make decoder cancellation token default.
JimBobSquarePants Dec 12, 2022
64c7a8e
Merge branch 'js/decoder-attempt-2' of https://github.com/SixLabors/I…
JimBobSquarePants Dec 12, 2022
4007a48
Use shared instances for all built-in decoders.
JimBobSquarePants Dec 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cancellation detection in png DecodePixelData
  • Loading branch information
antonfirsov committed Dec 7, 2022
commit 25e8d01b3dc6a102c4692b535d9b6b16be759eaa
17 changes: 11 additions & 6 deletions src/ImageSharp/Formats/Png/PngDecoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
this.InitializeImage(metadata, out image);
}

this.ReadScanlines(chunk, image.Frames.RootFrame, pngMetadata);
this.ReadScanlines(chunk, image.Frames.RootFrame, pngMetadata, cancellationToken);

break;
case PngChunkType.Palette:
Expand Down Expand Up @@ -555,7 +555,8 @@ private int CalculateScanlineLength(int width)
/// <param name="chunk">The png chunk containing the compressed scanline data.</param>
/// <param name="image"> The pixel data.</param>
/// <param name="pngMetadata">The png metadata</param>
private void ReadScanlines<TPixel>(PngChunk chunk, ImageFrame<TPixel> image, PngMetadata pngMetadata)
/// <param name="cancellationToken">The cancellation token.</param>
private void ReadScanlines<TPixel>(PngChunk chunk, ImageFrame<TPixel> image, PngMetadata pngMetadata, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
{
using ZlibInflateStream deframeStream = new(this.currentStream, this.ReadNextDataChunk);
Expand All @@ -564,11 +565,11 @@ private void ReadScanlines<TPixel>(PngChunk chunk, ImageFrame<TPixel> image, Png

if (this.header.InterlaceMethod == PngInterlaceMode.Adam7)
{
this.DecodeInterlacedPixelData(dataStream, image, pngMetadata);
this.DecodeInterlacedPixelData(dataStream, image, pngMetadata, cancellationToken);
}
else
{
this.DecodePixelData(dataStream, image, pngMetadata);
this.DecodePixelData(dataStream, image, pngMetadata, cancellationToken);
}
}

Expand All @@ -579,11 +580,13 @@ private void ReadScanlines<TPixel>(PngChunk chunk, ImageFrame<TPixel> image, Png
/// <param name="compressedStream">The compressed pixel data stream.</param>
/// <param name="image">The image to decode to.</param>
/// <param name="pngMetadata">The png metadata</param>
private void DecodePixelData<TPixel>(DeflateStream compressedStream, ImageFrame<TPixel> image, PngMetadata pngMetadata)
/// <param name="cancellationToken">The CancellationToken</param>
private void DecodePixelData<TPixel>(DeflateStream compressedStream, ImageFrame<TPixel> image, PngMetadata pngMetadata, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
{
while (this.currentRow < this.header.Height)
{
cancellationToken.ThrowIfCancellationRequested();
Span<byte> scanlineSpan = this.scanline.GetSpan();
while (this.currentRowBytesRead < this.bytesPerScanline)
{
Expand Down Expand Up @@ -639,7 +642,8 @@ private void DecodePixelData<TPixel>(DeflateStream compressedStream, ImageFrame<
/// <param name="compressedStream">The compressed pixel data stream.</param>
/// <param name="image">The current image.</param>
/// <param name="pngMetadata">The png metadata.</param>
private void DecodeInterlacedPixelData<TPixel>(DeflateStream compressedStream, ImageFrame<TPixel> image, PngMetadata pngMetadata)
/// <param name="cancellationToken">The cancellation token.</param>
private void DecodeInterlacedPixelData<TPixel>(DeflateStream compressedStream, ImageFrame<TPixel> image, PngMetadata pngMetadata, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
{
int pass = 0;
Expand All @@ -661,6 +665,7 @@ private void DecodeInterlacedPixelData<TPixel>(DeflateStream compressedStream, I

while (this.currentRow < this.header.Height)
{
cancellationToken.ThrowIfCancellationRequested();
while (this.currentRowBytesRead < bytesPerInterlaceScanline)
{
int bytesRead = compressedStream.Read(this.scanline.GetSpan(), this.currentRowBytesRead, bytesPerInterlaceScanline - this.currentRowBytesRead);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task LoadAsync_IsCancellable(bool useMemoryStream, string file, dou
await Assert.ThrowsAnyAsync<OperationCanceledException>(async () =>
{
using Image image = await Image.LoadAsync(options, "someFakeFile", cts.Token);
}).WaitAsync(TimeSpan.FromSeconds(60));
}).WaitAsync(TimeSpan.FromSeconds(30));
}
}
}