From e65febf329bc29dd9ea488260db0df6f7af4b397 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Sun, 19 Apr 2020 17:58:49 +0100 Subject: [PATCH] Tweek extension names --- .../GraphicOptionsDefaultsExtensions.cs | 22 ++++++---- .../Extensions/Drawing/DrawImageExtensions.cs | 8 ++-- .../Extensions/Filters/LomographExtensions.cs | 4 +- .../Extensions/Filters/PolaroidExtensions.cs | 4 +- .../Overlays/BackgroundColorExtensions.cs | 4 +- .../Extensions/Overlays/GlowExtensions.cs | 10 ++--- .../Extensions/Overlays/VignetteExtensions.cs | 10 ++--- .../GraphicOptionsDefaultsExtensionsTests.cs | 42 +++++++++---------- .../BaseImageOperationsExtensionTest.cs | 3 +- .../Processing/Filters/ContrastTest.cs | 4 +- 10 files changed, 58 insertions(+), 53 deletions(-) diff --git a/src/ImageSharp/GraphicOptionsDefaultsExtensions.cs b/src/ImageSharp/GraphicOptionsDefaultsExtensions.cs index 45e444ffe..10909c4f3 100644 --- a/src/ImageSharp/GraphicOptionsDefaultsExtensions.cs +++ b/src/ImageSharp/GraphicOptionsDefaultsExtensions.cs @@ -16,11 +16,13 @@ namespace SixLabors.ImageSharp /// /// The image processing context to store default against. /// The action to update instance of the default options used. - public static void SetDefaultOptions(this IImageProcessingContext context, Action optionsBuilder) + /// The passed in to allow chaining. + public static IImageProcessingContext SetGraphicsOptions(this IImageProcessingContext context, Action optionsBuilder) { - var cloned = context.GetDefaultGraphicsOptions().DeepClone(); + var cloned = context.GetGraphicsOptions().DeepClone(); optionsBuilder(cloned); context.Properties[typeof(GraphicsOptions)] = cloned; + return context; } /// @@ -28,9 +30,9 @@ namespace SixLabors.ImageSharp /// /// The image processing context to store default against. /// The default options to use. - public static void SetDefaultGraphicsOptions(this Configuration context, Action optionsBuilder) + public static void SetGraphicsOptions(this Configuration context, Action optionsBuilder) { - var cloned = context.GetDefaultGraphicsOptions().DeepClone(); + var cloned = context.GetGraphicsOptions().DeepClone(); optionsBuilder(cloned); context.Properties[typeof(GraphicsOptions)] = cloned; } @@ -40,9 +42,11 @@ namespace SixLabors.ImageSharp /// /// The image processing context to store default against. /// The default options to use. - public static void SetDefaultOptions(this IImageProcessingContext context, GraphicsOptions options) + /// The passed in to allow chaining. + public static IImageProcessingContext SetGraphicsOptions(this IImageProcessingContext context, GraphicsOptions options) { context.Properties[typeof(GraphicsOptions)] = options; + return context; } /// @@ -50,7 +54,7 @@ namespace SixLabors.ImageSharp /// /// The image processing context to store default against. /// The default options to use. - public static void SetDefaultGraphicsOptions(this Configuration context, GraphicsOptions options) + public static void SetGraphicsOptions(this Configuration context, GraphicsOptions options) { context.Properties[typeof(GraphicsOptions)] = options; } @@ -60,14 +64,14 @@ namespace SixLabors.ImageSharp /// /// The image processing context to retrieve defaults from. /// The globaly configued default options. - public static GraphicsOptions GetDefaultGraphicsOptions(this IImageProcessingContext context) + public static GraphicsOptions GetGraphicsOptions(this IImageProcessingContext context) { if (context.Properties.TryGetValue(typeof(GraphicsOptions), out var options) && options is GraphicsOptions go) { return go; } - var configOptions = context.Configuration.GetDefaultGraphicsOptions(); + var configOptions = context.Configuration.GetGraphicsOptions(); // do not cache the fall back to config into the the processing context // in case someone want to change the value on the config and expects it re trflow thru @@ -79,7 +83,7 @@ namespace SixLabors.ImageSharp /// /// The image processing context to retrieve defaults from. /// The globaly configued default options. - public static GraphicsOptions GetDefaultGraphicsOptions(this Configuration context) + public static GraphicsOptions GetGraphicsOptions(this Configuration context) { if (context.Properties.TryGetValue(typeof(GraphicsOptions), out var options) && options is GraphicsOptions go) { diff --git a/src/ImageSharp/Processing/Extensions/Drawing/DrawImageExtensions.cs b/src/ImageSharp/Processing/Extensions/Drawing/DrawImageExtensions.cs index 197dcd3ef..3c25bb7c4 100644 --- a/src/ImageSharp/Processing/Extensions/Drawing/DrawImageExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/Drawing/DrawImageExtensions.cs @@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Processing Image image, float opacity) { - var options = source.GetDefaultGraphicsOptions(); + var options = source.GetGraphicsOptions(); return source.ApplyProcessor( new DrawImageProcessor( image, @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Processing image, Point.Empty, colorBlending, - source.GetDefaultGraphicsOptions().AlphaCompositionMode, + source.GetGraphicsOptions().AlphaCompositionMode, opacity)); /// @@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp.Processing Point location, float opacity) { - var options = source.GetDefaultGraphicsOptions(); + var options = source.GetGraphicsOptions(); return source.ApplyProcessor( new DrawImageProcessor( image, @@ -134,7 +134,7 @@ namespace SixLabors.ImageSharp.Processing image, location, colorBlending, - source.GetDefaultGraphicsOptions().AlphaCompositionMode, + source.GetGraphicsOptions().AlphaCompositionMode, opacity)); /// diff --git a/src/ImageSharp/Processing/Extensions/Filters/LomographExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/LomographExtensions.cs index b46f53cf6..3f8a67feb 100644 --- a/src/ImageSharp/Processing/Extensions/Filters/LomographExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/Filters/LomographExtensions.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing /// The image this method extends. /// The to allow chaining of operations. public static IImageProcessingContext Lomograph(this IImageProcessingContext source) - => source.ApplyProcessor(new LomographProcessor(source.GetDefaultGraphicsOptions())); + => source.ApplyProcessor(new LomographProcessor(source.GetGraphicsOptions())); /// /// Alters the colors of the image recreating an old Lomograph camera effect. @@ -28,6 +28,6 @@ namespace SixLabors.ImageSharp.Processing /// /// The to allow chaining of operations. public static IImageProcessingContext Lomograph(this IImageProcessingContext source, Rectangle rectangle) - => source.ApplyProcessor(new LomographProcessor(source.GetDefaultGraphicsOptions()), rectangle); + => source.ApplyProcessor(new LomographProcessor(source.GetGraphicsOptions()), rectangle); } } diff --git a/src/ImageSharp/Processing/Extensions/Filters/PolaroidExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/PolaroidExtensions.cs index 4e216b4f7..ab75ea56b 100644 --- a/src/ImageSharp/Processing/Extensions/Filters/PolaroidExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/Filters/PolaroidExtensions.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing /// The image this method extends. /// The to allow chaining of operations. public static IImageProcessingContext Polaroid(this IImageProcessingContext source) - => source.ApplyProcessor(new PolaroidProcessor(source.GetDefaultGraphicsOptions())); + => source.ApplyProcessor(new PolaroidProcessor(source.GetGraphicsOptions())); /// /// Alters the colors of the image recreating an old Polaroid camera effect. @@ -28,6 +28,6 @@ namespace SixLabors.ImageSharp.Processing /// /// The to allow chaining of operations. public static IImageProcessingContext Polaroid(this IImageProcessingContext source, Rectangle rectangle) - => source.ApplyProcessor(new PolaroidProcessor(source.GetDefaultGraphicsOptions()), rectangle); + => source.ApplyProcessor(new PolaroidProcessor(source.GetGraphicsOptions()), rectangle); } } diff --git a/src/ImageSharp/Processing/Extensions/Overlays/BackgroundColorExtensions.cs b/src/ImageSharp/Processing/Extensions/Overlays/BackgroundColorExtensions.cs index ced37091e..21e244f0a 100644 --- a/src/ImageSharp/Processing/Extensions/Overlays/BackgroundColorExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/Overlays/BackgroundColorExtensions.cs @@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Processing /// The color to set as the background. /// The to allow chaining of operations. public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, Color color) => - BackgroundColor(source, source.GetDefaultGraphicsOptions(), color); + BackgroundColor(source, source.GetGraphicsOptions(), color); /// /// Replaces the background color of image with the given one. @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Processing this IImageProcessingContext source, Color color, Rectangle rectangle) => - BackgroundColor(source, source.GetDefaultGraphicsOptions(), color, rectangle); + BackgroundColor(source, source.GetGraphicsOptions(), color, rectangle); /// /// Replaces the background color of image with the given one. diff --git a/src/ImageSharp/Processing/Extensions/Overlays/GlowExtensions.cs b/src/ImageSharp/Processing/Extensions/Overlays/GlowExtensions.cs index 63f065119..c3ce32e63 100644 --- a/src/ImageSharp/Processing/Extensions/Overlays/GlowExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/Overlays/GlowExtensions.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing /// The image this method extends. /// The to allow chaining of operations. public static IImageProcessingContext Glow(this IImageProcessingContext source) => - Glow(source, source.GetDefaultGraphicsOptions()); + Glow(source, source.GetGraphicsOptions()); /// /// Applies a radial glow effect to an image. @@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Processing /// The to allow chaining of operations. public static IImageProcessingContext Glow(this IImageProcessingContext source, Color color) { - return Glow(source, source.GetDefaultGraphicsOptions(), color); + return Glow(source, source.GetGraphicsOptions(), color); } /// @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing /// The the radius. /// The to allow chaining of operations. public static IImageProcessingContext Glow(this IImageProcessingContext source, float radius) => - Glow(source, source.GetDefaultGraphicsOptions(), radius); + Glow(source, source.GetGraphicsOptions(), radius); /// /// Applies a radial glow effect to an image. @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Processing /// /// The to allow chaining of operations. public static IImageProcessingContext Glow(this IImageProcessingContext source, Rectangle rectangle) => - source.Glow(source.GetDefaultGraphicsOptions(), rectangle); + source.Glow(source.GetGraphicsOptions(), rectangle); /// /// Applies a radial glow effect to an image. @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.Processing Color color, float radius, Rectangle rectangle) => - source.Glow(source.GetDefaultGraphicsOptions(), color, ValueSize.Absolute(radius), rectangle); + source.Glow(source.GetGraphicsOptions(), color, ValueSize.Absolute(radius), rectangle); /// /// Applies a radial glow effect to an image. diff --git a/src/ImageSharp/Processing/Extensions/Overlays/VignetteExtensions.cs b/src/ImageSharp/Processing/Extensions/Overlays/VignetteExtensions.cs index a3063832a..b53880fc1 100644 --- a/src/ImageSharp/Processing/Extensions/Overlays/VignetteExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/Overlays/VignetteExtensions.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing /// The image this method extends. /// The to allow chaining of operations. public static IImageProcessingContext Vignette(this IImageProcessingContext source) => - Vignette(source, source.GetDefaultGraphicsOptions()); + Vignette(source, source.GetGraphicsOptions()); /// /// Applies a radial vignette effect to an image. @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Processing /// The color to set as the vignette. /// The to allow chaining of operations. public static IImageProcessingContext Vignette(this IImageProcessingContext source, Color color) => - Vignette(source, source.GetDefaultGraphicsOptions(), color); + Vignette(source, source.GetGraphicsOptions(), color); /// /// Applies a radial vignette effect to an image. @@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Processing this IImageProcessingContext source, float radiusX, float radiusY) => - Vignette(source, source.GetDefaultGraphicsOptions(), radiusX, radiusY); + Vignette(source, source.GetGraphicsOptions(), radiusX, radiusY); /// /// Applies a radial vignette effect to an image. @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing /// /// The to allow chaining of operations. public static IImageProcessingContext Vignette(this IImageProcessingContext source, Rectangle rectangle) => - Vignette(source, source.GetDefaultGraphicsOptions(), rectangle); + Vignette(source, source.GetGraphicsOptions(), rectangle); /// /// Applies a radial vignette effect to an image. @@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Processing float radiusX, float radiusY, Rectangle rectangle) => - source.Vignette(source.GetDefaultGraphicsOptions(), color, radiusX, radiusY, rectangle); + source.Vignette(source.GetGraphicsOptions(), color, radiusX, radiusY, rectangle); /// /// Applies a radial vignette effect to an image. diff --git a/tests/ImageSharp.Tests/GraphicOptionsDefaultsExtensionsTests.cs b/tests/ImageSharp.Tests/GraphicOptionsDefaultsExtensionsTests.cs index 4b0d7a62d..9c02dd601 100644 --- a/tests/ImageSharp.Tests/GraphicOptionsDefaultsExtensionsTests.cs +++ b/tests/ImageSharp.Tests/GraphicOptionsDefaultsExtensionsTests.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests var config = new Configuration(); var context = new FakeImageOperationsProvider.FakeImageOperations(config, null, true); - context.SetDefaultOptions(option); + context.SetGraphicsOptions(option); // sets the prop on the processing context not on the configuration Assert.Equal(option, context.Properties[typeof(GraphicsOptions)]); @@ -33,15 +33,15 @@ namespace SixLabors.ImageSharp.Tests }; var config = new Configuration(); var context = new FakeImageOperationsProvider.FakeImageOperations(config, null, true); - context.SetDefaultOptions(option); + context.SetGraphicsOptions(option); - context.SetDefaultOptions(o => + context.SetGraphicsOptions(o => { Assert.Equal(0.9f, o.BlendPercentage); // has origional values o.BlendPercentage = 0.4f; }); - var returnedOption = context.GetDefaultGraphicsOptions(); + var returnedOption = context.GetGraphicsOptions(); Assert.Equal(0.4f, returnedOption.BlendPercentage); Assert.Equal(0.9f, option.BlendPercentage); // hasn't been mutated } @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Tests var option = new GraphicsOptions(); var config = new Configuration(); - config.SetDefaultGraphicsOptions(option); + config.SetGraphicsOptions(option); Assert.Equal(option, config.Properties[typeof(GraphicsOptions)]); } @@ -65,15 +65,15 @@ namespace SixLabors.ImageSharp.Tests BlendPercentage = 0.9f }; var config = new Configuration(); - config.SetDefaultGraphicsOptions(option); + config.SetGraphicsOptions(option); - config.SetDefaultGraphicsOptions(o => + config.SetGraphicsOptions(o => { Assert.Equal(0.9f, o.BlendPercentage); // has origional values o.BlendPercentage = 0.4f; }); - var returnedOption = config.GetDefaultGraphicsOptions(); + var returnedOption = config.GetGraphicsOptions(); Assert.Equal(0.4f, returnedOption.BlendPercentage); Assert.Equal(0.9f, option.BlendPercentage); // hasn't been mutated } @@ -83,11 +83,11 @@ namespace SixLabors.ImageSharp.Tests { var config = new Configuration(); - var options = config.GetDefaultGraphicsOptions(); + var options = config.GetGraphicsOptions(); Assert.NotNull(options); - config.SetDefaultGraphicsOptions((GraphicsOptions)null); + config.SetGraphicsOptions((GraphicsOptions)null); - var options2 = config.GetDefaultGraphicsOptions(); + var options2 = config.GetGraphicsOptions(); Assert.NotNull(options2); // we set it to null should now be a new instance @@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.Tests var config = new Configuration(); config.Properties[typeof(GraphicsOptions)] = "wronge type"; - var options = config.GetDefaultGraphicsOptions(); + var options = config.GetGraphicsOptions(); Assert.NotNull(options); Assert.IsType(options); } @@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.Tests var config = new Configuration(); Assert.DoesNotContain(typeof(GraphicsOptions), config.Properties.Keys); - var options = config.GetDefaultGraphicsOptions(); + var options = config.GetGraphicsOptions(); Assert.NotNull(options); } @@ -120,8 +120,8 @@ namespace SixLabors.ImageSharp.Tests { var config = new Configuration(); - var options = config.GetDefaultGraphicsOptions(); - var options2 = config.GetDefaultGraphicsOptions(); + var options = config.GetGraphicsOptions(); + var options2 = config.GetGraphicsOptions(); Assert.Equal(options, options2); } @@ -131,7 +131,7 @@ namespace SixLabors.ImageSharp.Tests var config = new Configuration(); var context = new FakeImageOperationsProvider.FakeImageOperations(config, null, true); - var ctxOptions = context.GetDefaultGraphicsOptions(); + var ctxOptions = context.GetGraphicsOptions(); Assert.NotNull(ctxOptions); } @@ -141,8 +141,8 @@ namespace SixLabors.ImageSharp.Tests var config = new Configuration(); var context = new FakeImageOperationsProvider.FakeImageOperations(config, null, true); - context.SetDefaultOptions((GraphicsOptions)null); - var ctxOptions = context.GetDefaultGraphicsOptions(); + context.SetGraphicsOptions((GraphicsOptions)null); + var ctxOptions = context.GetGraphicsOptions(); Assert.NotNull(ctxOptions); } @@ -151,10 +151,10 @@ namespace SixLabors.ImageSharp.Tests { var option = new GraphicsOptions(); var config = new Configuration(); - config.SetDefaultGraphicsOptions(option); + config.SetGraphicsOptions(option); var context = new FakeImageOperationsProvider.FakeImageOperations(config, null, true); - var ctxOptions = context.GetDefaultGraphicsOptions(); + var ctxOptions = context.GetGraphicsOptions(); Assert.Equal(option, ctxOptions); } @@ -164,7 +164,7 @@ namespace SixLabors.ImageSharp.Tests var config = new Configuration(); var context = new FakeImageOperationsProvider.FakeImageOperations(config, null, true); context.Properties[typeof(GraphicsOptions)] = "wronge type"; - var options = context.GetDefaultGraphicsOptions(); + var options = context.GetGraphicsOptions(); Assert.NotNull(options); Assert.IsType(options); } diff --git a/tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs b/tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs index da2040131..953563006 100644 --- a/tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs +++ b/tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System.ComponentModel.DataAnnotations; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; @@ -25,7 +26,7 @@ namespace SixLabors.ImageSharp.Tests.Processing this.source = new Image(91 + 324, 123 + 56); this.rect = new Rectangle(91, 123, 324, 56); // make this random? this.internalOperations = new FakeImageOperationsProvider.FakeImageOperations(this.source.GetConfiguration(), this.source, false); - this.internalOperations.SetDefaultOptions(this.options); + this.internalOperations.SetGraphicsOptions(this.options); this.operations = this.internalOperations; } diff --git a/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs index e55e983da..bf2d6823a 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using Xunit; @@ -28,4 +28,4 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects Assert.Equal(1.5F, processor.Amount); } } -} \ No newline at end of file +}