Skip to content

Commit

Permalink
Seal format classes and fix warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Oct 7, 2019
1 parent 43a1ef6 commit 7a4ae3d
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 28 deletions.
12 changes: 11 additions & 1 deletion ImageProcessor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{F7EF30FE
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageProcessor.Tests", "tests\ImageProcessor.Tests\ImageProcessor.Tests.csproj", "{47C75531-C0F3-469B-88CF-4F0B00BDD841}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor.Plugins.WebP", "src\ImageProcessor.Plugins.WebP\ImageProcessor.Plugins.WebP.csproj", "{D8285938-B99E-4B77-BE60-9FBF8A4BD173}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageProcessor.Plugins.WebP", "src\ImageProcessor.Plugins.WebP\ImageProcessor.Plugins.WebP.csproj", "{D8285938-B99E-4B77-BE60-9FBF8A4BD173}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0170E9EB-0F33-45E0-AF6A-7D964F25E73F}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
ImageProcessor.ruleset = ImageProcessor.ruleset
README.md = README.md
stylecop.json = stylecop.json
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 1 addition & 1 deletion src/ImageProcessor.Plugins.WebP/Formats/WebPFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ImageProcessor.Formats
/// Adapted from <see href="http://groups.google.com/a/webmproject.org/forum/#!topic/webp-discuss/1coeidT0rQU"/>
/// by Jose M. Piñeiro.
/// </summary>
public class WebPFormat : FormatBase
public sealed class WebPFormat : FormatBase
{
private static readonly ImageFormat WebP = new ImageFormat(new Guid("{2500426f-ed67-4a31-8523-e304537dd9a7}"));

Expand Down
2 changes: 1 addition & 1 deletion src/ImageProcessor/Formats/BitmapFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace ImageProcessor.Formats
/// <summary>
/// Provides the necessary information to support bitmap images.
/// </summary>
public class BitmapFormat : FormatBase
public sealed class BitmapFormat : FormatBase
{
/// <inheritdoc/>
public override byte[][] FileHeaders { get; } = new[]
Expand Down
2 changes: 1 addition & 1 deletion src/ImageProcessor/Formats/GifFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ImageProcessor.Formats
/// <summary>
/// Provides the necessary information to support gif images.
/// </summary>
public class GifFormat : FormatBase
public sealed class GifFormat : FormatBase
{
/// <inheritdoc/>
public override byte[][] FileHeaders { get; } = new[] { Encoding.ASCII.GetBytes("GIF") };
Expand Down
2 changes: 1 addition & 1 deletion src/ImageProcessor/Formats/PngFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace ImageProcessor.Formats
/// <summary>
/// Provides the necessary information to support png images.
/// </summary>
public class PngFormat : FormatBase
public sealed class PngFormat : FormatBase
{
private static readonly byte[][] Identifier = new[]
{
Expand Down
2 changes: 1 addition & 1 deletion src/ImageProcessor/Formats/TiffFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ImageProcessor.Formats
/// <summary>
/// Provides the necessary information to support tiff images.
/// </summary>
public class TiffFormat : FormatBase
public sealed class TiffFormat : FormatBase
{
private ImageCodecInfo imageCodecInfo;

Expand Down
18 changes: 14 additions & 4 deletions src/ImageProcessor/ImageFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,27 @@ public ImageFactory Save(Stream stream, IImageFormat format, BitDepth bitDepth)

/// <inheritdoc/>
public void Dispose()
{
this.Dispose(true);

GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (this.isDisposed)
{
return;
}

this.Image?.Dispose();
this.Image = null;
if (disposing)
{
this.Image?.Dispose();
this.Image = null;

this.memoryStream?.Dispose();
this.memoryStream = null;
this.memoryStream?.Dispose();
this.memoryStream = null;
}

this.isDisposed = true;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ImageProcessor.Tests/Processing/BrightnessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ImageProcessor.Tests.Processing
{
public class BrightnessTests
{
private const string Category = "Brightness";
private const string category = "Brightness";

public static IEnumerable<object[]> BrightnessFiles = new[]
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public void FactoryCanSetBrightness(TestFile file, int percentage)
{
factory.Load(file.FullName)
.Brightness(percentage)
.SaveAndCompare(file, Category, percentage);
.SaveAndCompare(file, category, percentage);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ImageProcessor.Tests/Processing/ContrastTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ImageProcessor.Tests.Processing
{
public class HueTests
{
private const string Category = "Hue";
private const string category = "Hue";

public static IEnumerable<object[]> HueFiles = new[]
{
Expand Down Expand Up @@ -35,7 +35,7 @@ public void FactoryCanSetHue(TestFile file, int percentage)
{
factory.Load(file.FullName)
.Hue(percentage)
.SaveAndCompare(file, Category, percentage);
.SaveAndCompare(file, category, percentage);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/ImageProcessor.Tests/Processing/CropTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ImageProcessor.Tests.Processing
{
public class CropTests
{
private const string Category = "Crop";
private const string category = "Crop";

[Fact]
public void CropSettingsConstructorSetsOptions()
Expand Down Expand Up @@ -52,7 +52,7 @@ public void FactoryCanCropRectangle()
{
factory.Load(file.FullName)
.Crop(bounds)
.SaveAndCompare(file, Category, bounds);
.SaveAndCompare(file, category, bounds);
}
}

Expand All @@ -66,7 +66,7 @@ public void FactoryCanCropPercentile()
{
factory.Load(file.FullName)
.Crop(settings)
.SaveAndCompare(file, Category, settings);
.SaveAndCompare(file, category, settings);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ImageProcessor.Tests/Processing/DetectEdgesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ImageProcessor.Tests.Processing
{
public class DetectEdgesTests
{
private const string Category = "DetectEdges";
private const string category = "DetectEdges";

// TODO: Test all operators.
[Theory]
Expand All @@ -19,7 +19,7 @@ public void FactoryCanDetectEdges(EdgeDetectionOperators mode)
{
factory.Load(file.FullName)
.DetectEdges(mode)
.SaveAndCompare(file, Category, mode);
.SaveAndCompare(file, category, mode);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ImageProcessor.Tests/Processing/HueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ImageProcessor.Tests.Processing
{
public class ContrastTests
{
private const string Category = "Contrast";
private const string category = "Contrast";

public static IEnumerable<object[]> ContrastFiles = new[]
{
Expand Down Expand Up @@ -43,7 +43,7 @@ public void FactoryCanSetContrast(TestFile file, int percentage)
{
factory.Load(file.FullName)
.Contrast(percentage)
.SaveAndCompare(file, Category, percentage);
.SaveAndCompare(file, category, percentage);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/ImageProcessor.Tests/Processing/PixelateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ImageProcessor.Tests.Processing
{
public class PixelateTests
{
private const string Category = "Pixelate";
private const string category = "Pixelate";

[Fact]
public void PixelateSettingsConstructorSetsOptions()
Expand Down Expand Up @@ -46,7 +46,7 @@ public void FactoryCanPixelate()
{
factory.Load(file.FullName)
.Pixelate(4)
.SaveAndCompare(file, Category);
.SaveAndCompare(file, category);
}
}

Expand All @@ -64,7 +64,7 @@ public void FactoryCanPixelateRectangle()
var options = new PixelateOptions(4, bounds);

factory.Pixelate(options)
.SaveAndCompare(file, Category, bounds);
.SaveAndCompare(file, category, bounds);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ImageProcessor.Tests/Processing/ResizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ImageProcessor.Tests.Processing
{
public class ResizeTests
{
private const string Category = "Resize";
private const string category = "Resize";

[Theory]
[InlineData(ResizeMode.Crop)]
Expand All @@ -21,7 +21,7 @@ public void FactoryCanResize(ResizeMode mode)
{
factory.Load(file.FullName)
.Resize(factory.Image.Width / 2, (factory.Image.Height / 2) + 40, mode)
.SaveAndCompare(file, Category, mode);
.SaveAndCompare(file, category, mode);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ImageProcessor.Tests/Processing/SaturationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ImageProcessor.Tests.Processing
{
public class SaturationTests
{
private const string Category = "Saturation";
private const string category = "Saturation";

public static IEnumerable<object[]> SaturationFiles = new[]
{
Expand Down Expand Up @@ -43,7 +43,7 @@ public void FactoryCanSetSaturation(TestFile file, int percentage)
{
factory.Load(file.FullName)
.Saturation(percentage)
.SaveAndCompare(file, Category, percentage);
.SaveAndCompare(file, category, percentage);
}
}
}
Expand Down

0 comments on commit 7a4ae3d

Please sign in to comment.