Skip to content

Commit 4ac91ba

Browse files
committed
Fix a few warnings
1 parent e0ae4ba commit 4ac91ba

14 files changed

+43
-73
lines changed

Diff for: ImageFormats/CutReader.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ public static class CutReader
4040
/// <returns>Bitmap that contains the image that was read.</returns>
4141
public static Image Load(string fileName)
4242
{
43-
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
44-
{
45-
return Load(fs);
46-
}
43+
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
44+
return Load(f);
4745
}
4846

4947
/// <summary>
@@ -53,7 +51,7 @@ public static Image Load(string fileName)
5351
/// <returns>Bitmap that contains the image that was read.</returns>
5452
public static Image Load(Stream stream)
5553
{
56-
BinaryReader reader = new BinaryReader(stream);
54+
var reader = new BinaryReader(stream);
5755

5856
int imgWidth = Util.LittleEndian(reader.ReadUInt16());
5957
int imgHeight = Util.LittleEndian(reader.ReadUInt16());

Diff for: ImageFormats/DdsReader.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ public static class DdsReader
3636
#region Public Methods
3737
public static Image Load(string fileName)
3838
{
39-
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
40-
{
41-
return Load(f);
42-
}
39+
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
40+
return Load(f);
4341
}
4442

4543
public static Image Load(Stream stream)

Diff for: ImageFormats/DicomReader.cs

+5-7
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ public static class DicomReader
3939
/// <returns>Bitmap that contains the image that was read.</returns>
4040
public static Image Load(string fileName)
4141
{
42-
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
43-
{
44-
return Load(f);
45-
}
42+
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
43+
return Load(f);
4644
}
4745

4846
/// <summary>
@@ -53,7 +51,7 @@ public static Image Load(string fileName)
5351
///
5452
public static Image Load(Stream stream)
5553
{
56-
BinaryReader reader = new BinaryReader(stream);
54+
var reader = new BinaryReader(stream);
5755
byte[] tempBytes = new byte[256];
5856

5957
stream.Seek(0x80, SeekOrigin.Current);
@@ -182,7 +180,7 @@ public static Image Load(Stream stream)
182180

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

185-
List<byte[]> dataSegments = new List<byte[]>();
183+
var dataSegments = new List<byte[]>();
186184
UInt16 tempShort;
187185
int segmentLen = 0;
188186

@@ -230,7 +228,7 @@ public static Image Load(Stream stream)
230228
throw new ImageDecodeException("DICOM file does not appear to have any image data.");
231229

232230

233-
MemoryStream dataStream = new MemoryStream(data);
231+
var dataStream = new MemoryStream(data);
234232
reader = new BinaryReader(dataStream);
235233

236234
// detect whether the data is really a JPG image

Diff for: ImageFormats/FitsReader.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ public static class FitsReader
4040
/// </summary>
4141
/// <param name="filename">Name of the file to read.</param>
4242
/// <returns>Bitmap that contains the image that was read.</returns>
43-
public static Image Load(string filename)
43+
public static Image Load(string fileName)
4444
{
45-
using (var f = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
46-
{
47-
return Load(f);
48-
}
45+
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
46+
return Load(f);
4947
}
5048

5149
public static Image Load(Stream stream)
@@ -82,7 +80,7 @@ public static Image Load(Stream stream)
8280
else if (headerSeq > 0 && !itemStr.StartsWith("XTENSION")) { return bmp; }
8381
}
8482

85-
if (!itemStr.Contains("=")) { continue; }
83+
if (!itemStr.Contains('=')) { continue; }
8684

8785
string[] parts = itemStr.Split('=');
8886
if (parts.Length < 2) { continue; }

Diff for: ImageFormats/IffDeepReader.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ public static class IffDeepReader
4141
/// <returns>Bitmap that contains the image that was read.</returns>
4242
public static Image Load(string fileName)
4343
{
44-
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
45-
{
46-
return Load(f);
47-
}
44+
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
45+
return Load(f);
4846
}
4947

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

68-
BinaryReader reader = new BinaryReader(stream);
66+
var reader = new BinaryReader(stream);
6967

7068
byte[] tempBytes = new byte[65536];
7169

Diff for: ImageFormats/IffIlbmReader.cs

+4-8
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ public static class IffIlbmReader
4040
/// <returns>Bitmap that contains the image that was read.</returns>
4141
public static Image Load(string fileName)
4242
{
43-
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
44-
{
45-
return Load(f);
46-
}
43+
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
44+
return Load(f);
4745
}
4846

4947
/// <summary>
@@ -65,7 +63,6 @@ public static Image Load(Stream stream, bool resizeForAspect = false)
6563
int compressionType = 0;
6664
int transparentColor = 0;
6765
bool haveCAMG = false;
68-
bool haveSHAM = false;
6966
bool modeShamLaced = false;
7067
bool modePbm = false;
7168
bool modeAcbm = false;
@@ -75,7 +72,7 @@ public static Image Load(Stream stream, bool resizeForAspect = false)
7572
int modeXBMI = -1;
7673

7774
long bodyChunkPosition = -1;
78-
BinaryReader reader = new BinaryReader(stream);
75+
var reader = new BinaryReader(stream);
7976

8077
byte[] tempBytes = new byte[65536];
8178

@@ -212,7 +209,6 @@ public static Image Load(Stream stream, bool resizeForAspect = false)
212209
}
213210
else if (chunkName == "SHAM")
214211
{
215-
haveSHAM = true;
216212
int bytesPerRow = 32;
217213
int rowsInChunk = (int)(chunkSize - 2) / bytesPerRow;
218214
if (rowsInChunk == imgHeight / 2)
@@ -344,7 +340,7 @@ public static Image Load(Stream stream, bool resizeForAspect = false)
344340
totalColors >>= delta;
345341
}
346342

347-
ByteRun1Decoder decompressor = new ByteRun1Decoder(stream);
343+
var decompressor = new ByteRun1Decoder(stream);
348344
byte[] bmpData = new byte[(imgWidth + 1) * 4 * imgHeight];
349345

350346
try

Diff for: ImageFormats/IffRgbnReader.cs

+3-7
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ public static class IffRgbnReader
3939
/// <returns>Bitmap that contains the image that was read.</returns>
4040
public static Image Load(string fileName)
4141
{
42-
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
43-
{
44-
return Load(f);
45-
}
42+
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
43+
return Load(f);
4644
}
4745

4846
public static Image Load(Stream stream)
@@ -52,7 +50,7 @@ public static Image Load(Stream stream)
5250
int numPlanes = 0;
5351
int compressionType = 0;
5452

55-
BinaryReader reader = new BinaryReader(stream);
53+
var reader = new BinaryReader(stream);
5654

5755
byte[] tempBytes = new byte[65536];
5856

@@ -110,7 +108,6 @@ public static Image Load(Stream stream)
110108
{
111109
if (compressionType == 3)
112110
{
113-
int ptr = 0;
114111
for (int y = 0; y < imgHeight; y++)
115112
{
116113
for (int x = 0; x < imgWidth; x++)
@@ -138,7 +135,6 @@ public static Image Load(Stream stream)
138135
{
139136
var decoder = new RgbnDecoder(stream, isRgb8);
140137

141-
int ptr = 0;
142138
for (int y = 0; y < imgHeight; y++)
143139
{
144140
for (int x = 0; x < imgWidth; x++)

Diff for: ImageFormats/MacPaintReader.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ public static class MacPaintReader
3333

3434
public static Image Load(string fileName)
3535
{
36-
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
37-
{
38-
return Load(f);
39-
}
36+
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
37+
return Load(f);
4038
}
4139

4240
public static Image Load(Stream stream)
@@ -76,7 +74,7 @@ public static Image Load(Stream stream)
7674

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

8179
try
8280
{

Diff for: ImageFormats/PcxReader.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ public static class PcxReader
4141
/// <returns>Bitmap that contains the image that was read.</returns>
4242
public static Image Load(string fileName)
4343
{
44-
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
45-
{
46-
return Load(f);
47-
}
44+
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
45+
return Load(f);
4846
}
4947

5048
/// <summary>
@@ -58,7 +56,7 @@ public static Image Load(string fileName)
5856
/// <returns>Bitmap that contains the image that was read.</returns>
5957
public static Image Load(Stream stream, bool useCgaPalette = false)
6058
{
61-
BinaryReader reader = new BinaryReader(stream);
59+
var reader = new BinaryReader(stream);
6260

6361
byte tempByte = (byte)stream.ReadByte();
6462
if (tempByte != 10)
@@ -224,7 +222,7 @@ public static Image Load(Stream stream, bool useCgaPalette = false)
224222
stream.Seek(128, SeekOrigin.Begin);
225223
int x, y, i;
226224

227-
RleReader rleReader = new RleReader(stream);
225+
var rleReader = new RleReader(stream);
228226

229227
try
230228
{

Diff for: ImageFormats/Picture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static class Picture
3333
public static Image Load(string fileName)
3434
{
3535
Image bmp = null;
36-
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
36+
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
3737
{
3838
bmp = Load(fs);
3939
}

Diff for: ImageFormats/PnmReader.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ public static class PnmReader
4141
/// <returns>Bitmap that contains the picture.</returns>
4242
public static Image Load(string fileName, bool bigEndian = true)
4343
{
44-
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
45-
{
46-
return Load(f, bigEndian);
47-
}
44+
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
45+
return Load(f, bigEndian);
4846
}
4947

5048
/// <summary>

Diff for: ImageFormats/RasReader.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ public static class RasReader
4646
/// <returns>Bitmap that contains the image that was read.</returns>
4747
public static Image Load(string fileName)
4848
{
49-
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
50-
{
51-
return Load(fs);
52-
}
49+
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
50+
return Load(f);
5351
}
5452

5553
/// <summary>
@@ -59,7 +57,7 @@ public static Image Load(string fileName)
5957
/// <returns>Bitmap that contains the image that was read.</returns>
6058
public static Image Load(Stream stream)
6159
{
62-
BinaryReader reader = new BinaryReader(stream);
60+
var reader = new BinaryReader(stream);
6361
UInt32 tempDword = Util.BigEndian(reader.ReadUInt32());
6462
if (tempDword != 0x59a66a95)
6563
throw new ImageDecodeException("This is not a valid RAS file.");
@@ -72,7 +70,7 @@ public static Image Load(Stream stream)
7270
UInt32 mapType = Util.BigEndian(reader.ReadUInt32());
7371
int mapLength = (int)Util.BigEndian(reader.ReadUInt32());
7472

75-
RleReader rleReader = new RleReader(stream, rasType == RAS_TYPE_RLE);
73+
var rleReader = new RleReader(stream, rasType == RAS_TYPE_RLE);
7674

7775
if ((imgWidth < 1) || (imgHeight < 1) || (imgWidth > 32767) || (imgHeight > 32767) || (mapLength > 32767))
7876
throw new ImageDecodeException("This RAS file appears to have invalid dimensions.");

Diff for: ImageFormats/SgiReader.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ public static class SgiReader
4040
/// <returns>Bitmap that contains the image that was read.</returns>
4141
public static Image Load(string fileName)
4242
{
43-
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
44-
{
45-
return Load(f);
46-
}
43+
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
44+
return Load(f);
4745
}
4846

4947

@@ -54,7 +52,7 @@ public static Image Load(string fileName)
5452
/// <returns>Bitmap that contains the image that was read.</returns>
5553
public static Image Load(Stream stream)
5654
{
57-
BinaryReader reader = new BinaryReader(stream);
55+
var reader = new BinaryReader(stream);
5856

5957
UInt16 magic = Util.BigEndian(reader.ReadUInt16());
6058
if (magic != 0x1DA)

Diff for: ImageFormats/XpmReader.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ public static class XpmReader
4343
/// <returns>Bitmap that contains the image that was read.</returns>
4444
public static Image Load(string fileName)
4545
{
46-
using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
47-
{
48-
return Load(f);
49-
}
46+
using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
47+
return Load(f);
5048
}
5149

5250
/// <summary>

0 commit comments

Comments
 (0)