From 3e7ef68dcaa16643e0db9d4738db6dc533331fbb Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Thu, 26 Mar 2026 19:50:51 +0100 Subject: [PATCH] Use cancellation token when encoding exr images --- src/ImageSharp/Formats/Exr/ExrEncoderCore.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ImageSharp/Formats/Exr/ExrEncoderCore.cs b/src/ImageSharp/Formats/Exr/ExrEncoderCore.cs index d6736597a9..7a66dfac26 100644 --- a/src/ImageSharp/Formats/Exr/ExrEncoderCore.cs +++ b/src/ImageSharp/Formats/Exr/ExrEncoderCore.cs @@ -133,7 +133,7 @@ internal sealed class ExrEncoderCore case ExrPixelType.Half: case ExrPixelType.Float: { - ulong[] rowOffsets = this.EncodeFloatingPointPixelData(stream, pixels, width, height, channels, this.Compression); + ulong[] rowOffsets = this.EncodeFloatingPointPixelData(stream, pixels, width, height, channels, this.Compression, cancellationToken); stream.Position = (long)startOfRowOffsetData; this.WriteRowOffsets(stream, height, rowOffsets); break; @@ -141,7 +141,7 @@ internal sealed class ExrEncoderCore case ExrPixelType.UnsignedInt: { - ulong[] rowOffsets = this.EncodeUnsignedIntPixelData(stream, pixels, width, height, channels, this.Compression); + ulong[] rowOffsets = this.EncodeUnsignedIntPixelData(stream, pixels, width, height, channels, this.Compression, cancellationToken); stream.Position = (long)startOfRowOffsetData; this.WriteRowOffsets(stream, height, rowOffsets); break; @@ -155,7 +155,8 @@ internal sealed class ExrEncoderCore int width, int height, List channels, - ExrCompression compression) + ExrCompression compression, + CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { uint bytesPerRow = ExrUtils.CalculateBytesPerRow(channels, (uint)width); @@ -220,6 +221,8 @@ internal sealed class ExrEncoderCore stream.Position = pixelDataSizePos; stream.Write(this.buffer.AsSpan(0, 4)); stream.Position = positionAfterPixelData; + + cancellationToken.ThrowIfCancellationRequested(); } return rowOffsets; @@ -231,7 +234,8 @@ internal sealed class ExrEncoderCore int width, int height, List channels, - ExrCompression compression) + ExrCompression compression, + CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { uint bytesPerRow = ExrUtils.CalculateBytesPerRow(channels, (uint)width); @@ -290,6 +294,8 @@ internal sealed class ExrEncoderCore stream.Position = pixelDataSizePos; stream.Write(this.buffer.AsSpan(0, 4)); stream.Position = positionAfterPixelData; + + cancellationToken.ThrowIfCancellationRequested(); } return rowOffsets;