From fccd5b55d99b8739de3262515313eba36d62ba49 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Mon, 30 Mar 2026 17:23:40 +0200 Subject: [PATCH] Remove unused variables --- src/ImageSharp/Formats/Exr/ExrDecoderCore.cs | 40 +++++++------------- src/ImageSharp/Formats/Exr/ExrEncoderCore.cs | 3 -- 2 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/ImageSharp/Formats/Exr/ExrDecoderCore.cs b/src/ImageSharp/Formats/Exr/ExrDecoderCore.cs index 126c4c8f69..d69cd78e2e 100644 --- a/src/ImageSharp/Formats/Exr/ExrDecoderCore.cs +++ b/src/ImageSharp/Formats/Exr/ExrDecoderCore.cs @@ -371,30 +371,9 @@ internal sealed class ExrDecoderCore : ImageDecoderCore { ExrHeaderAttributes header = this.ReadExrHeader(stream); - int bitsPerPixel = this.CalculateBitsPerPixel(); - return new ImageInfo(new Size(header.DataWindow.XMax, header.DataWindow.YMax), this.metadata); } - private int CalculateBitsPerPixel() - { - int bitsPerPixel = 0; - for (int i = 0; i < this.Channels.Count; i++) - { - ExrChannelInfo channel = this.Channels[0]; - if (channel.PixelType is ExrPixelType.Float or ExrPixelType.UnsignedInt) - { - bitsPerPixel += 32; - } - else if (channel.PixelType == ExrPixelType.Half) - { - bitsPerPixel += 16; - } - } - - return bitsPerPixel; - } - private ExrPixelType ValidateChannels() { if (this.Channels.Count == 0) @@ -475,8 +454,8 @@ internal sealed class ExrDecoderCore : ImageDecoderCore // Next three bytes contain info's about the image. byte flagsByte0 = (byte)stream.ReadByte(); - byte flagsByte1 = (byte)stream.ReadByte(); - byte flagsByte2 = (byte)stream.ReadByte(); + stream.ReadByte(); + stream.ReadByte(); if ((flagsByte0 & (1 << 1)) != 0) { ExrThrowHelper.ThrowNotSupported("Decoding tiled exr images is not supported yet!"); @@ -587,6 +566,11 @@ internal sealed class ExrDecoderCore : ImageDecoderCore ExrThrowHelper.ThrowInvalidImageContentException("Invalid exr image header, the lineOrder attribute is missing!"); } + if (!aspectRatio.HasValue) + { + ExrThrowHelper.ThrowInvalidImageContentException("Invalid exr image header, the aspectRatio attribute is missing!"); + } + if (!screenWindowWidth.HasValue) { ExrThrowHelper.ThrowInvalidImageContentException("Invalid exr image header, the screenWindowWidth attribute is missing!"); @@ -648,7 +632,7 @@ internal sealed class ExrDecoderCore : ImageDecoderCore } // Last byte should be a null byte. - int byteRead = stream.ReadByte(); + stream.ReadByte(); return channels; } @@ -662,9 +646,11 @@ internal sealed class ExrDecoderCore : ImageDecoderCore bytesRead += 4; byte pLinear = (byte)stream.ReadByte(); - byte reserved0 = (byte)stream.ReadByte(); - byte reserved1 = (byte)stream.ReadByte(); - byte reserved2 = (byte)stream.ReadByte(); + + // Next 3 bytes are reserved bytes and not use. + stream.ReadByte(); + stream.ReadByte(); + stream.ReadByte(); bytesRead += 4; int xSampling = this.ReadSignedInteger(stream); diff --git a/src/ImageSharp/Formats/Exr/ExrEncoderCore.cs b/src/ImageSharp/Formats/Exr/ExrEncoderCore.cs index 7a66dfac26..be2b7e5ffe 100644 --- a/src/ImageSharp/Formats/Exr/ExrEncoderCore.cs +++ b/src/ImageSharp/Formats/Exr/ExrEncoderCore.cs @@ -122,8 +122,6 @@ internal sealed class ExrEncoderCore // Next is offsets table to each pixel row, which will be written after the pixel data was written. int bytesPerChannel = this.pixelType == ExrPixelType.Half ? 2 : 4; - int numberOfChannels = 3; - uint rowSizeBytes = (uint)(width * numberOfChannels * bytesPerChannel); ulong startOfRowOffsetData = (ulong)stream.Position; stream.Position += 8 * height; @@ -162,7 +160,6 @@ internal sealed class ExrEncoderCore uint bytesPerRow = ExrUtils.CalculateBytesPerRow(channels, (uint)width); uint rowsPerBlock = ExrUtils.RowsPerBlock(compression); uint bytesPerBlock = bytesPerRow * rowsPerBlock; - int channelCount = channels.Count; using IMemoryOwner rgbBuffer = this.memoryAllocator.Allocate(width * 3, AllocationOptions.Clean); using IMemoryOwner rowBlockBuffer = this.memoryAllocator.Allocate((int)bytesPerBlock, AllocationOptions.Clean);