Skip to content

Commit

Permalink
Fix a few warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrant committed Oct 30, 2023
1 parent 6d8252a commit f68f603
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 64 deletions.
8 changes: 3 additions & 5 deletions ImageFormats/CutReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ public static class CutReader
/// <param name="fileName">Name of the file to read.</param>
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(string fileName){
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return Load(f);
}
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
return Load(f);
}

/// <summary>
Expand All @@ -52,7 +50,7 @@ public static Image Load(string fileName){
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
var reader = new BinaryReader(stream);

int imgWidth = Util.LittleEndian(reader.ReadUInt16());
int imgHeight = Util.LittleEndian(reader.ReadUInt16());
Expand Down
12 changes: 5 additions & 7 deletions ImageFormats/DicomReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ public static class DicomReader
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(string fileName)
{
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return Load(f);
}
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
return Load(f);
}

/// <summary>
Expand All @@ -54,7 +52,7 @@ public static Image Load(string fileName)
///
public static Image Load(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
var reader = new BinaryReader(stream);
byte[] tempBytes = new byte[256];

stream.Seek(0x80, SeekOrigin.Current);
Expand Down Expand Up @@ -183,7 +181,7 @@ public static Image Load(Stream stream)

//we'll have to read the data by sequential packets

List<byte[]> dataSegments = new List<byte[]>();
var dataSegments = new List<byte[]>();
UInt16 tempShort;
int segmentLen = 0;

Expand Down Expand Up @@ -231,7 +229,7 @@ public static Image Load(Stream stream)
throw new ImageDecodeException("DICOM file does not appear to have any image data.");


MemoryStream dataStream = new MemoryStream(data);
var dataStream = new MemoryStream(data);
reader = new BinaryReader(dataStream);

//detect whether the data is really a JPG image
Expand Down
8 changes: 3 additions & 5 deletions ImageFormats/FitsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ public static class FitsReader
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(string fileName)
{
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return Load(f);
}
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
return Load(f);
}

/// <summary>
Expand Down Expand Up @@ -85,7 +83,7 @@ public static Image Load(Stream stream)
else if (headerSeq > 0 && !itemStr.StartsWith("XTENSION")) { return bmp; }
}

if (!itemStr.Contains("=")) { continue; }
if (!itemStr.Contains('=')) { continue; }

string[] parts = itemStr.Split('=');
if (parts.Length < 2) { continue; }
Expand Down
8 changes: 3 additions & 5 deletions ImageFormats/IffDeepReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ public static class IffDeepReader
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(string fileName)
{
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return Load(f);
}
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
return Load(f);
}

/// <summary>
Expand All @@ -63,7 +61,7 @@ public static Image Load(Stream stream, bool wantOpacity = false)
int[] tvdcTable = new int[16];
byte[] bodyChunk = null;

BinaryReader reader = new BinaryReader(stream);
var reader = new BinaryReader(stream);

byte[] tempBytes = new byte[65536];

Expand Down
10 changes: 4 additions & 6 deletions ImageFormats/IffIlbmReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ public static class IffIlbmReader
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(string fileName)
{
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return Load(f);
}
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
return Load(f);
}

/// <summary>
Expand Down Expand Up @@ -75,7 +73,7 @@ public static Image Load(Stream stream, bool resizeForAspect = false)
int modeXBMI = -1;

long bodyChunkPosition = -1;
BinaryReader reader = new BinaryReader(stream);
var reader = new BinaryReader(stream);

byte[] tempBytes = new byte[65536];

Expand Down Expand Up @@ -344,7 +342,7 @@ public static Image Load(Stream stream, bool resizeForAspect = false)
totalColors >>= delta;
}

ByteRun1Decoder decompressor = new ByteRun1Decoder(stream);
var decompressor = new ByteRun1Decoder(stream);
byte[] bmpData = new byte[(imgWidth + 1) * 4 * imgHeight];

try
Expand Down
8 changes: 3 additions & 5 deletions ImageFormats/IffRgbnReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ public static class IffRgbnReader
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(string fileName)
{
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return Load(f);
}
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
return Load(f);
}

/// <summary>
Expand All @@ -57,7 +55,7 @@ public static Image Load(Stream stream)
int numPlanes = 0;
int compressionType = 0;

BinaryReader reader = new BinaryReader(stream);
var reader = new BinaryReader(stream);

byte[] tempBytes = new byte[65536];

Expand Down
8 changes: 3 additions & 5 deletions ImageFormats/MacPaintReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ public static class MacPaintReader

public static Image Load(string fileName)
{
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
return Load(f);
}
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return Load(f);
}

public static Image Load(Stream stream)
Expand Down Expand Up @@ -76,7 +74,7 @@ public static Image Load(Stream stream)

byte[] bmpData = new byte[(MAC_PAINT_WIDTH + 1) * 4 * MAC_PAINT_HEIGHT];
int x = 0, y = 0;
RleReader rleReader = new RleReader(stream);
var rleReader = new RleReader(stream);

try
{
Expand Down
10 changes: 4 additions & 6 deletions ImageFormats/PcxReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ public static class PcxReader
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(string fileName)
{
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return Load(f);
}
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
return Load(f);
}

/// <summary>
Expand All @@ -59,7 +57,7 @@ public static Image Load(string fileName)
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(Stream stream, bool useCgaPalette = false)
{
BinaryReader reader = new BinaryReader(stream);
var reader = new BinaryReader(stream);

byte tempByte = (byte)stream.ReadByte();
if (tempByte != 10)
Expand Down Expand Up @@ -222,7 +220,7 @@ public static Image Load(Stream stream, bool useCgaPalette = false)
stream.Seek(128, SeekOrigin.Begin);
int x, y, i;

RleReader rleReader = new RleReader(stream);
var rleReader = new RleReader(stream);

try
{
Expand Down
2 changes: 1 addition & 1 deletion ImageFormats/Picture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static class Picture
public static Image Load(string fileName)
{
Image bmp = null;
using (FileStream f = new FileStream(fileName, FileMode.Open, FileAccess.Read))
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
bmp = Load(f);
}
Expand Down
6 changes: 2 additions & 4 deletions ImageFormats/PnmReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ public static class PnmReader
/// <returns>Bitmap that contains the picture.</returns>
public static Image Load(string fileName, bool bigEndian = true)
{
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
return Load(f, bigEndian);
}
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return Load(f, bigEndian);
}

/// <summary>
Expand Down
10 changes: 4 additions & 6 deletions ImageFormats/RasReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ public static class RasReader
/// <param name="fileName">Name of the file to read.</param>
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(string fileName){
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return Load(f);
}
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
return Load(f);
}

/// <summary>
Expand All @@ -58,7 +56,7 @@ public static Image Load(string fileName){
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
var reader = new BinaryReader(stream);
UInt32 tempDword = Util.BigEndian(reader.ReadUInt32());
if (tempDword != 0x59a66a95)
throw new ImageDecodeException("This is not a valid RAS file.");
Expand All @@ -71,7 +69,7 @@ public static Image Load(Stream stream)
UInt32 mapType = Util.BigEndian(reader.ReadUInt32());
int mapLength = (int)Util.BigEndian(reader.ReadUInt32());

RleReader rleReader = new RleReader(stream, rasType == RAS_TYPE_RLE);
var rleReader = new RleReader(stream, rasType == RAS_TYPE_RLE);

if ((imgWidth < 1) || (imgHeight < 1) || (imgWidth > 32767) || (imgHeight > 32767) || (mapLength > 32767))
throw new ImageDecodeException("This RAS file appears to have invalid dimensions.");
Expand Down
8 changes: 3 additions & 5 deletions ImageFormats/SgiReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ public static class SgiReader
/// <param name="fileName">Name of the file to read.</param>
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(string fileName){
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return Load(f);
}
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
return Load(f);
}

/// <summary>
Expand All @@ -52,7 +50,7 @@ public static Image Load(string fileName){
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
var reader = new BinaryReader(stream);

UInt16 magic = Util.BigEndian(reader.ReadUInt16());
if (magic != 0x1DA)
Expand Down
6 changes: 2 additions & 4 deletions ImageFormats/XpmReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ public static class XpmReader
/// <returns>Bitmap that contains the image that was read.</returns>
public static Image Load(string fileName)
{
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return Load(f);
}
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
return Load(f);
}

/// <summary>
Expand Down

0 comments on commit f68f603

Please sign in to comment.