Browse Source

Use cancellation token when encoding exr images

pull/3096/head
Brian Popow 2 months ago
parent
commit
3e7ef68dca
  1. 14
      src/ImageSharp/Formats/Exr/ExrEncoderCore.cs

14
src/ImageSharp/Formats/Exr/ExrEncoderCore.cs

@ -133,7 +133,7 @@ internal sealed class ExrEncoderCore
case ExrPixelType.Half: case ExrPixelType.Half:
case ExrPixelType.Float: 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; stream.Position = (long)startOfRowOffsetData;
this.WriteRowOffsets(stream, height, rowOffsets); this.WriteRowOffsets(stream, height, rowOffsets);
break; break;
@ -141,7 +141,7 @@ internal sealed class ExrEncoderCore
case ExrPixelType.UnsignedInt: 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; stream.Position = (long)startOfRowOffsetData;
this.WriteRowOffsets(stream, height, rowOffsets); this.WriteRowOffsets(stream, height, rowOffsets);
break; break;
@ -155,7 +155,8 @@ internal sealed class ExrEncoderCore
int width, int width,
int height, int height,
List<ExrChannelInfo> channels, List<ExrChannelInfo> channels,
ExrCompression compression) ExrCompression compression,
CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
uint bytesPerRow = ExrUtils.CalculateBytesPerRow(channels, (uint)width); uint bytesPerRow = ExrUtils.CalculateBytesPerRow(channels, (uint)width);
@ -220,6 +221,8 @@ internal sealed class ExrEncoderCore
stream.Position = pixelDataSizePos; stream.Position = pixelDataSizePos;
stream.Write(this.buffer.AsSpan(0, 4)); stream.Write(this.buffer.AsSpan(0, 4));
stream.Position = positionAfterPixelData; stream.Position = positionAfterPixelData;
cancellationToken.ThrowIfCancellationRequested();
} }
return rowOffsets; return rowOffsets;
@ -231,7 +234,8 @@ internal sealed class ExrEncoderCore
int width, int width,
int height, int height,
List<ExrChannelInfo> channels, List<ExrChannelInfo> channels,
ExrCompression compression) ExrCompression compression,
CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
uint bytesPerRow = ExrUtils.CalculateBytesPerRow(channels, (uint)width); uint bytesPerRow = ExrUtils.CalculateBytesPerRow(channels, (uint)width);
@ -290,6 +294,8 @@ internal sealed class ExrEncoderCore
stream.Position = pixelDataSizePos; stream.Position = pixelDataSizePos;
stream.Write(this.buffer.AsSpan(0, 4)); stream.Write(this.buffer.AsSpan(0, 4));
stream.Position = positionAfterPixelData; stream.Position = positionAfterPixelData;
cancellationToken.ThrowIfCancellationRequested();
} }
return rowOffsets; return rowOffsets;

Loading…
Cancel
Save