@@ -10,95 +10,51 @@ SixLabors.ImageSharp
[](https://github.com/SixLabors/ImageSharp/actions)
[](https://codecov.io/gh/SixLabors/ImageSharp)
-[](https://raw.githubusercontent.com/SixLabors/ImageSharp/master/LICENSE)
+[](https://www.gnu.org/licenses/agpl-3.0)
[](https://gitter.im/ImageSharp/General?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://twitter.com/intent/tweet?hashtags=imagesharp,dotnet,oss&text=ImageSharp.+A+new+cross-platform+2D+graphics+API+in+C%23&url=https%3a%2f%2fgithub.com%2fSixLabors%2fImageSharp&via=sixlabors)
-[](#backers)
-[](#sponsors)
### **ImageSharp** is a new, fully featured, fully managed, cross-platform, 2D graphics API.
-Designed to democratize image processing, ImageSharp brings you an incredibly powerful yet beautifully simple API.
+ImageSharp is a new, fully featured, fully managed, cross-platform, 2D graphics library. Designed to simplify image processing, ImageSharp brings you an incredibly powerful yet beautifully simple API.
-Compared to `System.Drawing` we have been able to develop something much more flexible, easier to code against, and much, much less prone to memory leaks. Gone are system-wide process-locks; ImageSharp images are thread-safe and fully supported in web environments.
+ImageSharp is designed from the ground up to be flexible and extensible. The library provides API endpoints for common image processing operations and the building blocks to allow for the development of addtional operations.
-Built against .NET Standard 1.3, ImageSharp can be used in device, cloud, and embedded/IoT scenarios.
+Built against [.NET Standard 1.3](https://docs.microsoft.com/en-us/dotnet/standard/net-standard), ImageSharp can be used in device, cloud, and embedded/IoT scenarios.
-### Documentation
-For all SixLabors projects, including ImageSharp:
-https://sixlabors.github.io/docs/
-### Installation
+## License
+
+- ImageSharp is licensed under the [GNU Affero General Public License v3](https://www.gnu.org/licenses/agpl-3.0)
+- An alternative Commercial License can be purchased for Closed Source projects and applications.
+Please visit https://sixlabors.com/pricing for details.
+- Open Source projects who have taken a dependency on ImageSharp prior to adoption of the AGPL v3 license are permitted to use ImageSharp (including all future versions) under the previous [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0).
-Install stable releases via Nuget; development releases are available via MyGet.
-
-| Package Name | Release (NuGet) | Nightly (MyGet) |
-|--------------------------------|-----------------|-----------------|
-| `SixLabors.ImageSharp` | [](https://www.nuget.org/packages/SixLabors.ImageSharp/) | [](https://www.myget.org/feed/sixlabors/package/nuget/SixLabors.ImageSharp) |
-
-### Packages
+## Documentation
-The **ImageSharp** library is made up of multiple packages:
-- **SixLabors.ImageSharp**
- - Contains the generic `Image` class, PixelFormats, Primitives, Configuration, and other core functionality
- - The `IImageFormat` interface, Jpeg, Png, Bmp, and Gif formats
- - Transform methods like Resize, Crop, Skew, Rotate - anything that alters the dimensions of the image
- - Non-transform methods like Gaussian Blur, Pixelate, Edge Detection - anything that maintains the original image dimensions
+- [Detailed documentation](https://sixlabors.github.io/docs/) for the ImageSharp API is available. This includes additional conceptual documentation to help you get started.
+- Our [Samples Repository](https://github.com/SixLabors/Samples/tree/master/ImageSharp) is also available containing buildable code samples demonstrating common activities.
-### Questions?
+## Questions
-- Do you have questions? We are happy to help! Please [join our gitter channel](https://gitter.im/ImageSharp/General), or ask them on [stackoverflow](https://stackoverflow.com) using the `ImageSharp` tag. **Do not** open issues for questions!
+- Do you have questions? We are happy to help! Please [join our Gitter channel](https://gitter.im/ImageSharp/General), or ask them on [Stack Overflow](https://stackoverflow.com) using the `ImageSharp` tag. Please do not open issues for questions.
- Please read our [Contribution Guide](https://github.com/SixLabors/ImageSharp/blob/master/.github/CONTRIBUTING.md) before opening issues or pull requests!
-### Code of Conduct
+## Code of Conduct
This project has adopted the code of conduct defined by the [Contributor Covenant](https://contributor-covenant.org/) to clarify expected behavior in our community.
For more information, see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).
-### API
-
-Our API is designed to be simple to consume. Here's an example of the code required to resize an image using the default Bicubic resampler then turn the colors into their grayscale equivalent using the BT709 standard matrix.
-
-On platforms supporting netstandard 1.3+
-
-```csharp
-using SixLabors.ImageSharp;
-using SixLabors.ImageSharp.Processing;
-using SixLabors.ImageSharp.PixelFormats;
-
-// Image.Load(string path) is a shortcut for our default type.
-// Other pixel formats use Image.Load(string path))
-using (Image image = Image.Load("foo.jpg"))
-{
- image.Mutate(x => x
- .Resize(image.Width / 2, image.Height / 2)
- .Grayscale());
- image.Save("bar.jpg"); // Automatic encoder selected based on extension.
-}
-```
-
-Setting individual pixel values can be performed as follows:
-
-```csharp
-using SixLabors.ImageSharp;
-using SixLabors.ImageSharp.PixelFormats;
-
-// Individual pixels
-using (var image = new Image(400, 400))
-{
- image[200, 200] = Rgba32.White;
-}
-```
+## Installation
-`Rgba32` is our default PixelFormat, equivalent to `System.Drawing Color`. For advanced pixel format usage there are multiple [PixelFormat implementations](https://github.com/SixLabors/ImageSharp/tree/master/src/ImageSharp/PixelFormats) available allowing developers to implement their own color models in the same manner as Microsoft XNA Game Studio and MonoGame.
+Install stable releases via Nuget; development releases are available via MyGet.
-For more examples check out:
-- [Our Documentation](https://sixlabors.github.io/docs/)
-- Our [Samples Repository](https://github.com/SixLabors/Samples/tree/master/ImageSharp)
-- The [beta1 blog post](https://sixlabors.com/blog/announcing-imagesharp-beta-1/)
+| Package Name | Release (NuGet) | Nightly (MyGet) |
+|--------------------------------|-----------------|-----------------|
+| `SixLabors.ImageSharp` | [](https://www.nuget.org/packages/SixLabors.ImageSharp/) | [](https://www.myget.org/feed/sixlabors/package/nuget/SixLabors.ImageSharp) |
-### Manual build
+## Manual build
If you prefer, you can compile ImageSharp yourself (please do and help!)
@@ -123,95 +79,20 @@ If working with Windows please ensure that you have enabled log file paths in gi
git config --system core.longpaths true
```
-### Submodules
-
This repository contains [git submodules](https://blog.github.com/2016-02-01-working-with-submodules/). To add the submodules to the project, navigate to the repository root and type:
``` bash
git submodule update --init --recursive
```
-### How can you help?
+## How can you help?
Please... Spread the word, contribute algorithms, submit performance improvements, unit tests, no input is too little. Make sure to read our [Contribution Guide](https://github.com/SixLabors/ImageSharp/blob/master/.github/CONTRIBUTING.md) before opening a PR.
-### The ImageSharp Team
+## The ImageSharp Team
-Grand High Eternal Dictator
- [James Jackson-South](https://github.com/jimbobsquarepants)
-
-Core Team
- [Dirk Lemstra](https://github.com/dlemstra)
- [Anton Firsov](https://github.com/antonfirsov)
- [Scott Williams](https://github.com/tocsoft)
- [Brian Popow](https://github.com/brianpopow)
-
-### Backers
-
-Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/imagesharp#backer)]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-### Sponsors
-
-Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/imagesharp#sponsor)]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/shared-infrastructure b/shared-infrastructure
index 8dfef29f1..44686c6a1 160000
--- a/shared-infrastructure
+++ b/shared-infrastructure
@@ -1 +1 @@
-Subproject commit 8dfef29f1838da76be9596f1a2f1be6d93e453d3
+Subproject commit 44686c6a116961f4a5163e19a0d6136e1b0b9f72
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index a78a75d42..87482af6f 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -12,7 +12,7 @@
$(MSBuildAllProjects);$(MSBuildThisFileDirectory)..\Directory.Build.props
- src
+ src
diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets
index 055a6803e..d7171aa0f 100644
--- a/src/Directory.Build.targets
+++ b/src/Directory.Build.targets
@@ -55,14 +55,6 @@
-
-
@@ -70,11 +62,6 @@
-
-
diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
index 0273f02f5..f4e9f3042 100644
--- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
+++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Linq;
@@ -78,84 +78,6 @@ namespace SixLabors.ImageSharp.Advanced
where TPixel : unmanaged, IPixel
=> source?.Frames.RootFrame.GetPixelMemoryGroup() ?? throw new ArgumentNullException(nameof(source));
- ///
- /// Gets the representation of the pixels as a in the source image's pixel format
- /// stored in row major order, if the backing buffer is contiguous.
- ///
- /// The type of the pixel.
- /// The source image.
- /// The
- /// Thrown when the backing buffer is discontiguous.
- [Obsolete(
- @"GetPixelSpan might fail, because the backing buffer could be discontiguous for large images. Use GetPixelMemoryGroup or GetPixelRowSpan instead!")]
- public static Span GetPixelSpan(this ImageFrame source)
- where TPixel : unmanaged, IPixel
- {
- Guard.NotNull(source, nameof(source));
-
- IMemoryGroup mg = source.GetPixelMemoryGroup();
- if (mg.Count > 1)
- {
- throw new InvalidOperationException($"GetPixelSpan is invalid, since the backing buffer of this {source.Width}x{source.Height} sized image is discontiguous!");
- }
-
- return mg.Single().Span;
- }
-
- ///
- /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format
- /// stored in row major order.
- ///
- /// The type of the pixel.
- /// The source.
- /// The
- /// Thrown when the backing buffer is discontiguous.
- [Obsolete(
- @"GetPixelSpan might fail, because the backing buffer could be discontiguous for large images. Use GetPixelMemoryGroup or GetPixelRowSpan instead!")]
- public static Span GetPixelSpan(this Image source)
- where TPixel : unmanaged, IPixel
- {
- Guard.NotNull(source, nameof(source));
-
- return source.Frames.RootFrame.GetPixelSpan();
- }
-
- ///
- /// Gets the representation of the pixels as a of contiguous memory
- /// at row beginning from the the first pixel on that row.
- ///
- /// The type of the pixel.
- /// The source.
- /// The row.
- /// The
- public static Span GetPixelRowSpan(this ImageFrame source, int rowIndex)
- where TPixel : unmanaged, IPixel
- {
- Guard.NotNull(source, nameof(source));
- Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex));
- Guard.MustBeLessThan(rowIndex, source.Height, nameof(rowIndex));
-
- return source.PixelBuffer.GetRowSpan(rowIndex);
- }
-
- ///
- /// Gets the representation of the pixels as of of contiguous memory
- /// at row beginning from the the first pixel on that row.
- ///
- /// The type of the pixel.
- /// The source.
- /// The row.
- /// The
- public static Span GetPixelRowSpan(this Image source, int rowIndex)
- where TPixel : unmanaged, IPixel
- {
- Guard.NotNull(source, nameof(source));
- Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex));
- Guard.MustBeLessThan(rowIndex, source.Height, nameof(rowIndex));
-
- return source.Frames.RootFrame.PixelBuffer.GetRowSpan(rowIndex);
- }
-
///
/// Gets the representation of the pixels as a of contiguous memory
/// at row beginning from the the first pixel on that row.
diff --git a/src/ImageSharp/Advanced/AotCompilerTools.cs b/src/ImageSharp/Advanced/AotCompilerTools.cs
index 23ae62c7a..eaea7a971 100644
--- a/src/ImageSharp/Advanced/AotCompilerTools.cs
+++ b/src/ImageSharp/Advanced/AotCompilerTools.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Diagnostics.CodeAnalysis;
@@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp.Advanced
private static void AotCompileOctreeQuantizer()
where TPixel : unmanaged, IPixel
{
- using (var test = new OctreeFrameQuantizer(Configuration.Default, new OctreeQuantizer().Options))
+ using (var test = new OctreeQuantizer(Configuration.Default, new OctreeQuantizer().Options))
{
var frame = new ImageFrame(Configuration.Default, 1, 1);
test.QuantizeFrame(frame, frame.Bounds());
@@ -126,7 +126,7 @@ namespace SixLabors.ImageSharp.Advanced
private static void AotCompileWuQuantizer()
where TPixel : unmanaged, IPixel
{
- using (var test = new WuFrameQuantizer(Configuration.Default, new WuQuantizer().Options))
+ using (var test = new WuQuantizer(Configuration.Default, new WuQuantizer().Options))
{
var frame = new ImageFrame(Configuration.Default, 1, 1);
test.QuantizeFrame(frame, frame.Bounds());
@@ -140,7 +140,7 @@ namespace SixLabors.ImageSharp.Advanced
private static void AotCompilePaletteQuantizer()
where TPixel : unmanaged, IPixel
{
- using (var test = (PaletteFrameQuantizer)new PaletteQuantizer(Array.Empty()).CreateFrameQuantizer(Configuration.Default))
+ using (var test = (PaletteQuantizer)new PaletteQuantizer(Array.Empty()).CreatePixelSpecificQuantizer(Configuration.Default))
{
var frame = new ImageFrame(Configuration.Default, 1, 1);
test.QuantizeFrame(frame, frame.Bounds());
diff --git a/src/ImageSharp/Advanced/IConfigurationProvider.cs b/src/ImageSharp/Advanced/IConfigurationProvider.cs
index d3e3a91aa..2deb73a20 100644
--- a/src/ImageSharp/Advanced/IConfigurationProvider.cs
+++ b/src/ImageSharp/Advanced/IConfigurationProvider.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Advanced
{
diff --git a/src/ImageSharp/Advanced/IImageVisitor.cs b/src/ImageSharp/Advanced/IImageVisitor.cs
index 079db42c0..50e6337e5 100644
--- a/src/ImageSharp/Advanced/IImageVisitor.cs
+++ b/src/ImageSharp/Advanced/IImageVisitor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Advanced/IPixelSource.cs b/src/ImageSharp/Advanced/IPixelSource.cs
index d7162bc61..f0b2687de 100644
--- a/src/ImageSharp/Advanced/IPixelSource.cs
+++ b/src/ImageSharp/Advanced/IPixelSource.cs
@@ -1,11 +1,22 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Advanced
{
+ ///
+ /// Encapsulates the basic properties and methods required to manipulate images.
+ ///
+ internal interface IPixelSource
+ {
+ ///
+ /// Gets the pixel buffer.
+ ///
+ Buffer2D PixelBuffer { get; }
+ }
+
///
/// Encapsulates the basic properties and methods required to manipulate images.
///
@@ -18,4 +29,4 @@ namespace SixLabors.ImageSharp.Advanced
///
Buffer2D PixelBuffer { get; }
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Advanced/IRowIntervalOperation.cs b/src/ImageSharp/Advanced/IRowIntervalOperation.cs
index 980ed91a7..a044d8fad 100644
--- a/src/ImageSharp/Advanced/IRowIntervalOperation.cs
+++ b/src/ImageSharp/Advanced/IRowIntervalOperation.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Memory;
diff --git a/src/ImageSharp/Advanced/IRowIntervalOperation{TBuffer}.cs b/src/ImageSharp/Advanced/IRowIntervalOperation{TBuffer}.cs
index 47fcf253e..f554e8920 100644
--- a/src/ImageSharp/Advanced/IRowIntervalOperation{TBuffer}.cs
+++ b/src/ImageSharp/Advanced/IRowIntervalOperation{TBuffer}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using SixLabors.ImageSharp.Memory;
diff --git a/src/ImageSharp/Advanced/IRowOperation.cs b/src/ImageSharp/Advanced/IRowOperation.cs
index 0a6065e4b..eeec6dce3 100644
--- a/src/ImageSharp/Advanced/IRowOperation.cs
+++ b/src/ImageSharp/Advanced/IRowOperation.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Advanced
{
diff --git a/src/ImageSharp/Advanced/IRowOperation{TBuffer}.cs b/src/ImageSharp/Advanced/IRowOperation{TBuffer}.cs
index 7a13930fa..7d8250ddf 100644
--- a/src/ImageSharp/Advanced/IRowOperation{TBuffer}.cs
+++ b/src/ImageSharp/Advanced/IRowOperation{TBuffer}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Advanced/ParallelExecutionSettings.cs b/src/ImageSharp/Advanced/ParallelExecutionSettings.cs
index 54ee06918..481189374 100644
--- a/src/ImageSharp/Advanced/ParallelExecutionSettings.cs
+++ b/src/ImageSharp/Advanced/ParallelExecutionSettings.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Threading.Tasks;
diff --git a/src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs b/src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs
index 3f0f77ca3..f8250632b 100644
--- a/src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs
+++ b/src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Advanced/ParallelRowIterator.cs b/src/ImageSharp/Advanced/ParallelRowIterator.cs
index fb85de986..45701f933 100644
--- a/src/ImageSharp/Advanced/ParallelRowIterator.cs
+++ b/src/ImageSharp/Advanced/ParallelRowIterator.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Color/Color.Conversions.cs b/src/ImageSharp/Color/Color.Conversions.cs
index a6e0717f4..1d35b8a31 100644
--- a/src/ImageSharp/Color/Color.Conversions.cs
+++ b/src/ImageSharp/Color/Color.Conversions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Color/Color.NamedColors.cs b/src/ImageSharp/Color/Color.NamedColors.cs
index 240ce304d..49c18c9a5 100644
--- a/src/ImageSharp/Color/Color.NamedColors.cs
+++ b/src/ImageSharp/Color/Color.NamedColors.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
diff --git a/src/ImageSharp/Color/Color.WebSafePalette.cs b/src/ImageSharp/Color/Color.WebSafePalette.cs
index 8e5fb2a55..67c608730 100644
--- a/src/ImageSharp/Color/Color.WebSafePalette.cs
+++ b/src/ImageSharp/Color/Color.WebSafePalette.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Color/Color.WernerPalette.cs b/src/ImageSharp/Color/Color.WernerPalette.cs
index 2948b4c52..f8bada44a 100644
--- a/src/ImageSharp/Color/Color.WernerPalette.cs
+++ b/src/ImageSharp/Color/Color.WernerPalette.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Color/Color.cs b/src/ImageSharp/Color/Color.cs
index e0f9d1e8d..9056d023a 100644
--- a/src/ImageSharp/Color/Color.cs
+++ b/src/ImageSharp/Color/Color.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs
index 146acf12e..837812ad0 100644
--- a/src/ImageSharp/ColorSpaces/CieLab.cs
+++ b/src/ImageSharp/ColorSpaces/CieLab.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs
index 99d4c09e9..52d53ffb2 100644
--- a/src/ImageSharp/ColorSpaces/CieLch.cs
+++ b/src/ImageSharp/ColorSpaces/CieLch.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs
index ab6f639a2..58fcbfcc3 100644
--- a/src/ImageSharp/ColorSpaces/CieLchuv.cs
+++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs
index d54d92b62..183222f3d 100644
--- a/src/ImageSharp/ColorSpaces/CieLuv.cs
+++ b/src/ImageSharp/ColorSpaces/CieLuv.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/CieXyy.cs b/src/ImageSharp/ColorSpaces/CieXyy.cs
index fff296945..2dc4a6204 100644
--- a/src/ImageSharp/ColorSpaces/CieXyy.cs
+++ b/src/ImageSharp/ColorSpaces/CieXyy.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs
index 6c5adcb21..f6c95b44b 100644
--- a/src/ImageSharp/ColorSpaces/CieXyz.cs
+++ b/src/ImageSharp/ColorSpaces/CieXyz.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs
index c2331c379..8228c3050 100644
--- a/src/ImageSharp/ColorSpaces/Cmyk.cs
+++ b/src/ImageSharp/ColorSpaces/Cmyk.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
[MethodImpl(InliningOptions.ShortMethod)]
public Cmyk(Vector4 vector)
{
- vector = Vector4.Clamp(vector, Min, Max);
+ vector = Vector4Utilities.FastClamp(vector, Min, Max);
this.C = vector.X;
this.M = vector.Y;
this.Y = vector.Z;
diff --git a/src/ImageSharp/ColorSpaces/Companding/GammaCompanding.cs b/src/ImageSharp/ColorSpaces/Companding/GammaCompanding.cs
index 09b324b00..73faa30fe 100644
--- a/src/ImageSharp/ColorSpaces/Companding/GammaCompanding.cs
+++ b/src/ImageSharp/ColorSpaces/Companding/GammaCompanding.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Companding/LCompanding.cs b/src/ImageSharp/ColorSpaces/Companding/LCompanding.cs
index 80b8aee7e..7898750a0 100644
--- a/src/ImageSharp/ColorSpaces/Companding/LCompanding.cs
+++ b/src/ImageSharp/ColorSpaces/Companding/LCompanding.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
@@ -35,4 +35,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Companding
public static float Compress(float channel)
=> channel <= CieConstants.Epsilon ? (channel * CieConstants.Kappa) / 100F : (1.16F * MathF.Pow(channel, 0.3333333F)) - 0.16F;
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Companding/Rec2020Companding.cs b/src/ImageSharp/ColorSpaces/Companding/Rec2020Companding.cs
index 773fe8164..fab8e655b 100644
--- a/src/ImageSharp/ColorSpaces/Companding/Rec2020Companding.cs
+++ b/src/ImageSharp/ColorSpaces/Companding/Rec2020Companding.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Companding/Rec709Companding.cs b/src/ImageSharp/ColorSpaces/Companding/Rec709Companding.cs
index edc0b9763..0d2030d0d 100644
--- a/src/ImageSharp/ColorSpaces/Companding/Rec709Companding.cs
+++ b/src/ImageSharp/ColorSpaces/Companding/Rec709Companding.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs b/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs
index cc30c3632..f5c61fe24 100644
--- a/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs
+++ b/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/CieConstants.cs b/src/ImageSharp/ColorSpaces/Conversion/CieConstants.cs
index 2bcdc5127..5ce915e3e 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/CieConstants.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/CieConstants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs
index 892c0d5e3..37aeae6ba 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs
@@ -1,7 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
@@ -157,4 +155,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToRgb(linearOutput);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
index 273c9be91..1880d535c 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
@@ -1,10 +1,9 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs
index 7f4abfa7b..560cd763f 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs
@@ -1,12 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
@@ -447,4 +445,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs
index 6ca40af03..337cccc66 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs
@@ -1,12 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
@@ -447,4 +445,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs
index b790712c5..662564863 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs
@@ -1,12 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs
index d03c10a01..90654efe3 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs
@@ -1,12 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
@@ -440,4 +438,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs
index 21d576fb4..70d6a0c7b 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs
@@ -1,12 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
@@ -475,4 +473,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.linearRgbToCieXyzConverter = new LinearRgbToCieXyzConverter(workingSpace);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs
index 00e20e25b..61534127a 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs
@@ -1,12 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
@@ -440,4 +438,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs
index 76175f1cb..18ccfa054 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs
@@ -1,12 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
@@ -440,4 +438,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs
index e64beb3e4..dbcba38cb 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs
@@ -1,12 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
@@ -440,4 +438,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs
index 91e5549ac..9a9c9be78 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs
index 5b312f4f8..8801f837f 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs
@@ -1,12 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs
index 3b8638f7d..9b089b7c9 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs
index fc5665e5c..4695706d0 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs
@@ -1,12 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
@@ -438,4 +436,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.Adapt(rgb);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs
index 68cd34bf2..83b756817 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs
@@ -1,12 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
@@ -407,4 +405,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public YCbCr ToYCbCr(in Rgb color) => YCbCrAndRgbConverter.Convert(color);
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs
index bcbd64c77..2c08db268 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs
@@ -1,8 +1,7 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
@@ -58,4 +57,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
this.cieXyzToLinearRgbConverter = new CieXyzToLinearRgbConverter(this.targetRgbWorkingSpace);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverterOptions.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverterOptions.cs
index 65fe79994..bf7786875 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverterOptions.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverterOptions.cs
@@ -1,8 +1,7 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
@@ -52,4 +51,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
///
public Matrix4x4 LmsAdaptationMatrix { get; set; } = CieXyzAndLmsConverter.DefaultTransformationMatrix;
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyChromaticityCoordinates.cs
similarity index 95%
rename from src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs
rename to src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyChromaticityCoordinates.cs
index 8e14274f6..6be996fbb 100644
--- a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyChromaticityCoordinates.cs
@@ -1,11 +1,11 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
// ReSharper disable CompareOfFloatsByEqualityOperator
-namespace SixLabors.ImageSharp.ColorSpaces
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Represents the coordinates of CIEXY chromaticity space.
@@ -76,4 +76,4 @@ namespace SixLabors.ImageSharp.ColorSpaces
[MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(CieXyChromaticityCoordinates other) => this.X.Equals(other.X) && this.Y.Equals(other.Y);
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CIeLchToCieLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CIeLchToCieLabConverter.cs
index 40d8c5bc6..b18bd81a6 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CIeLchToCieLabConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CIeLchToCieLabConverter.cs
@@ -1,10 +1,10 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Converts from to .
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieLchConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieLchConverter.cs
index 2b859205a..3bf36efaf 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieLchConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieLchConverter.cs
@@ -1,10 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Converts from to .
@@ -38,4 +38,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
return new CieLch(l, c, hDegrees, input.WhitePoint);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieXyzConverter.cs
index dfbbc8f0c..bd069373b 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieXyzConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieXyzConverter.cs
@@ -1,10 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Converts from to .
@@ -41,4 +41,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
return new CieXyz(xyz);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLchuvToCieLuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLchuvToCieLuvConverter.cs
index ba5b8bfb7..1ccc59dc5 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLchuvToCieLuvConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLchuvToCieLuvConverter.cs
@@ -1,10 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Converts from to .
@@ -30,4 +30,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
return new CieLuv(l, u, v, input.WhitePoint);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieLchuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieLchuvConverter.cs
index 3c7d356a5..78e1c39f5 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieLchuvConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieLchuvConverter.cs
@@ -1,10 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Converts from to .
@@ -38,4 +38,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
return new CieLchuv(l, c, hDegrees, input.WhitePoint);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieXyzConverter.cs
index 33f3ec3d3..b07dcafad 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieXyzConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieXyzConverter.cs
@@ -1,9 +1,9 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Converts from to .
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndCieXyyConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndCieXyyConverter.cs
index 7767b7b44..083259d64 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndCieXyyConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndCieXyyConverter.cs
@@ -1,10 +1,10 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Color converter between CIE XYZ and CIE xyY.
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndHunterLabConverterBase.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndHunterLabConverterBase.cs
index 1cd511e81..47fddbf42 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndHunterLabConverterBase.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndHunterLabConverterBase.cs
@@ -1,9 +1,9 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// The base class for converting between and color spaces.
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndLmsConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndLmsConverter.cs
index f860652b1..5094c46ec 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndLmsConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndLmsConverter.cs
@@ -1,10 +1,10 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Color converter between and
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLabConverter.cs
index c155087ff..42e468733 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLabConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLabConverter.cs
@@ -1,10 +1,10 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Converts from to .
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLuvConverter.cs
index 7f2bb0cf6..acce087fb 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLuvConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLuvConverter.cs
@@ -1,10 +1,10 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Converts from to .
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToHunterLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToHunterLabConverter.cs
index f21235d06..ed43951e3 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToHunterLabConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToHunterLabConverter.cs
@@ -1,10 +1,10 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Color converter between and
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToLinearRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToLinearRgbConverter.cs
index 6497e3060..999fef5fd 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToLinearRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToLinearRgbConverter.cs
@@ -1,10 +1,10 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Color converter between and
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CmykAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CmykAndRgbConverter.cs
index 0700dab43..6f2dafdf2 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CmykAndRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CmykAndRgbConverter.cs
@@ -1,11 +1,11 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Color converter between and .
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HslAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HslAndRgbConverter.cs
index 97465e526..844bf6c88 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HslAndRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HslAndRgbConverter.cs
@@ -1,10 +1,10 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Color converter between HSL and Rgb
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HsvAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HsvAndRgbConverter.cs
index 20ada7e7d..9316db491 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HsvAndRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HsvAndRgbConverter.cs
@@ -1,10 +1,10 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Color converter between HSV and Rgb
@@ -127,4 +127,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
return new Hsv(h, s, v);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs
index 4d6808e6c..e9c8e17a5 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs
@@ -1,10 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Color converter between and
@@ -36,4 +36,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
return new CieXyz(x, y, z);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbAndCieXyzConverterBase.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbAndCieXyzConverterBase.cs
index bdf451cd3..e6d59e0a5 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbAndCieXyzConverterBase.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbAndCieXyzConverterBase.cs
@@ -1,9 +1,9 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Provides base methods for converting between and color spaces.
@@ -74,4 +74,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
};
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToCieXyzConverter.cs
index 21a96071a..25fbf8025 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToCieXyzConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToCieXyzConverter.cs
@@ -1,10 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Color converter between and
@@ -50,4 +50,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
return new CieXyz(vector);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToRgbConverter.cs
index 845443093..e5bde6477 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToRgbConverter.cs
@@ -1,9 +1,9 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Color converter between and .
@@ -25,4 +25,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
workingSpace: input.WorkingSpace);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/RgbToLinearRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/RgbToLinearRgbConverter.cs
index 4ddbe42e5..7a50b67e3 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/RgbToLinearRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/RgbToLinearRgbConverter.cs
@@ -1,9 +1,9 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Color converter between Rgb and LinearRgb.
@@ -25,4 +25,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
workingSpace: input.WorkingSpace);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/YCbCrAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/YCbCrAndRgbConverter.cs
index ee15ffa50..30eda8826 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/YCbCrAndRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/YCbCrAndRgbConverter.cs
@@ -1,11 +1,11 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Color converter between and
diff --git a/src/ImageSharp/ColorSpaces/Conversion/IChromaticAdaptation.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/IChromaticAdaptation.cs
similarity index 96%
rename from src/ImageSharp/ColorSpaces/Conversion/IChromaticAdaptation.cs
rename to src/ImageSharp/ColorSpaces/Conversion/Implementation/IChromaticAdaptation.cs
index 69877d8b5..e26ed0e90 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/IChromaticAdaptation.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/IChromaticAdaptation.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/LmsAdaptationMatrix.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/LmsAdaptationMatrix.cs
index 37e4b1a1a..1e3959db2 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/LmsAdaptationMatrix.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/LmsAdaptationMatrix.cs
@@ -1,9 +1,9 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Matrices used for transformation from to , defining the cone response domain.
@@ -131,4 +131,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
M44 = 1F
});
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs
index 8871d0465..7ec9f2703 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs
@@ -1,9 +1,9 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Represents the chromaticity coordinates of RGB primaries.
diff --git a/src/ImageSharp/ColorSpaces/Conversion/VonKriesChromaticAdaptation.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs
similarity index 95%
rename from src/ImageSharp/ColorSpaces/Conversion/VonKriesChromaticAdaptation.cs
rename to src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs
index a4d96d19e..0e01fd5bd 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/VonKriesChromaticAdaptation.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs
@@ -1,11 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
@@ -99,4 +98,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs
index 6caca54cd..6a2e451e9 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs
@@ -1,11 +1,11 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces.Companding;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// The gamma working space.
@@ -63,4 +63,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
this.ChromaticityCoordinates,
this.Gamma);
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/LWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/LWorkingSpace.cs
index a2eb42ad0..2d97db2bc 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/LWorkingSpace.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/LWorkingSpace.cs
@@ -1,10 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces.Companding;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// L* working space.
@@ -29,4 +29,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
[MethodImpl(InliningOptions.ShortMethod)]
public override float Expand(float channel) => LCompanding.Expand(channel);
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec2020WorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec2020WorkingSpace.cs
index a794b3dda..c3f4e5fb9 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec2020WorkingSpace.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec2020WorkingSpace.cs
@@ -1,10 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces.Companding;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Rec. 2020 (ITU-R Recommendation BT.2020F) working space.
@@ -29,4 +29,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
[MethodImpl(InliningOptions.ShortMethod)]
public override float Expand(float channel) => Rec2020Companding.Expand(channel);
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec709WorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec709WorkingSpace.cs
index ffa9699bc..6c59fd3c3 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec709WorkingSpace.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec709WorkingSpace.cs
@@ -1,10 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces.Companding;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Rec. 709 (ITU-R Recommendation BT.709) working space.
@@ -29,4 +29,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
[MethodImpl(InliningOptions.ShortMethod)]
public override float Expand(float channel) => Rec709Companding.Expand(channel);
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpace.cs
index a97ae22b1..c112d118e 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpace.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpace.cs
@@ -1,9 +1,9 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Base class for all implementations of .
@@ -81,4 +81,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
return HashCode.Combine(this.WhitePoint, this.ChromaticityCoordinates);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/SRgbWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/SRgbWorkingSpace.cs
index c3d850251..7456c6c93 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/SRgbWorkingSpace.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/SRgbWorkingSpace.cs
@@ -1,10 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces.Companding;
-namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
+namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// The sRgb working space.
diff --git a/src/ImageSharp/ColorSpaces/Hsl.cs b/src/ImageSharp/ColorSpaces/Hsl.cs
index 04b3bea41..75ac8c053 100644
--- a/src/ImageSharp/ColorSpaces/Hsl.cs
+++ b/src/ImageSharp/ColorSpaces/Hsl.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs
index 8ccc74ae0..76ed552be 100644
--- a/src/ImageSharp/ColorSpaces/Hsv.cs
+++ b/src/ImageSharp/ColorSpaces/Hsv.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/HunterLab.cs b/src/ImageSharp/ColorSpaces/HunterLab.cs
index 402761d8c..ca1d9eeef 100644
--- a/src/ImageSharp/ColorSpaces/HunterLab.cs
+++ b/src/ImageSharp/ColorSpaces/HunterLab.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Illuminants.cs b/src/ImageSharp/ColorSpaces/Illuminants.cs
index d5c1b3eed..de77f6eee 100644
--- a/src/ImageSharp/ColorSpaces/Illuminants.cs
+++ b/src/ImageSharp/ColorSpaces/Illuminants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.ColorSpaces
{
diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs
index 7ef50e9c4..135185998 100644
--- a/src/ImageSharp/ColorSpaces/LinearRgb.cs
+++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs
@@ -1,10 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
+using SixLabors.ImageSharp.ColorSpaces.Conversion;
namespace SixLabors.ImageSharp.ColorSpaces
{
@@ -143,4 +143,4 @@ namespace SixLabors.ImageSharp.ColorSpaces
&& this.B.Equals(other.B);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/Lms.cs b/src/ImageSharp/ColorSpaces/Lms.cs
index 0ee56abbc..0718398c6 100644
--- a/src/ImageSharp/ColorSpaces/Lms.cs
+++ b/src/ImageSharp/ColorSpaces/Lms.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs
index bb71deba3..8d6db080a 100644
--- a/src/ImageSharp/ColorSpaces/Rgb.cs
+++ b/src/ImageSharp/ColorSpaces/Rgb.cs
@@ -1,10 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
+using SixLabors.ImageSharp.ColorSpaces.Conversion;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.ColorSpaces
@@ -164,4 +164,4 @@ namespace SixLabors.ImageSharp.ColorSpaces
&& this.B.Equals(other.B);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs b/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs
index 3f40fa4f5..ec6db8bb1 100644
--- a/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs
+++ b/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs
@@ -1,8 +1,8 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.ColorSpaces.Companding;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
+using SixLabors.ImageSharp.ColorSpaces.Conversion;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.ColorSpaces
@@ -112,4 +112,4 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
public static readonly RgbWorkingSpace WideGamutRgb = new GammaWorkingSpace(2.2F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7350F, 0.2650F), new CieXyChromaticityCoordinates(0.1150F, 0.8260F), new CieXyChromaticityCoordinates(0.1570F, 0.0180F)));
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/ColorSpaces/YCbCr.cs b/src/ImageSharp/ColorSpaces/YCbCr.cs
index b0563bb89..3f5d63159 100644
--- a/src/ImageSharp/ColorSpaces/YCbCr.cs
+++ b/src/ImageSharp/ColorSpaces/YCbCr.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Common/Constants.cs b/src/ImageSharp/Common/Constants.cs
index a8a693fa6..57b1b904c 100644
--- a/src/ImageSharp/Common/Constants.cs
+++ b/src/ImageSharp/Common/Constants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp
{
diff --git a/src/ImageSharp/Common/Exceptions/ImageFormatException.cs b/src/ImageSharp/Common/Exceptions/ImageFormatException.cs
index 4028b70b0..25ed4b589 100644
--- a/src/ImageSharp/Common/Exceptions/ImageFormatException.cs
+++ b/src/ImageSharp/Common/Exceptions/ImageFormatException.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Common/Exceptions/ImageProcessingException.cs b/src/ImageSharp/Common/Exceptions/ImageProcessingException.cs
index 3c75a6418..9e225b5c1 100644
--- a/src/ImageSharp/Common/Exceptions/ImageProcessingException.cs
+++ b/src/ImageSharp/Common/Exceptions/ImageProcessingException.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
@@ -10,6 +10,13 @@ namespace SixLabors.ImageSharp
///
public sealed class ImageProcessingException : Exception
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public ImageProcessingException()
+ {
+ }
+
///
/// Initializes a new instance of the class with the name of the
/// parameter that causes this exception.
@@ -32,4 +39,4 @@ namespace SixLabors.ImageSharp
{
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs b/src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs
new file mode 100644
index 000000000..34d3c658d
--- /dev/null
+++ b/src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs
@@ -0,0 +1,36 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using System;
+
+namespace SixLabors.ImageSharp
+{
+ ///
+ /// The exception that is thrown when the library tries to load
+ /// an image which contains invalid content.
+ ///
+ public sealed class InvalidImageContentException : ImageFormatException
+ {
+ ///
+ /// Initializes a new instance of the class with the name of the
+ /// parameter that causes this exception.
+ ///
+ /// The error message that explains the reason for this exception.
+ public InvalidImageContentException(string errorMessage)
+ : base(errorMessage)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class with the name of the
+ /// parameter that causes this exception.
+ ///
+ /// The error message that explains the reason for this exception.
+ /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic)
+ /// if no inner exception is specified.
+ public InvalidImageContentException(string errorMessage, Exception innerException)
+ : base(errorMessage, innerException)
+ {
+ }
+ }
+}
diff --git a/src/ImageSharp/Common/Exceptions/UnknownImageFormatException.cs b/src/ImageSharp/Common/Exceptions/UnknownImageFormatException.cs
index 82aa8cf09..6936852e4 100644
--- a/src/ImageSharp/Common/Exceptions/UnknownImageFormatException.cs
+++ b/src/ImageSharp/Common/Exceptions/UnknownImageFormatException.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp
{
diff --git a/src/ImageSharp/Common/Extensions/ComparableExtensions.cs b/src/ImageSharp/Common/Extensions/ComparableExtensions.cs
index 3c8570a2a..e9dfc4bc9 100644
--- a/src/ImageSharp/Common/Extensions/ComparableExtensions.cs
+++ b/src/ImageSharp/Common/Extensions/ComparableExtensions.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
@@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp
///
/// Restricts a to be within a specified range.
///
- /// The The value to clamp.
+ /// The value to clamp.
/// The minimum value. If value is less than min, min will be returned.
/// The maximum value. If value is greater than max, max will be returned.
///
@@ -137,4 +137,4 @@ namespace SixLabors.ImageSharp
return value;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs b/src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs
index 64532af27..66bd63972 100644
--- a/src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs
+++ b/src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Threading.Tasks;
diff --git a/src/ImageSharp/Common/Extensions/EncoderExtensions.cs b/src/ImageSharp/Common/Extensions/EncoderExtensions.cs
index 87aaa93a9..17c72161f 100644
--- a/src/ImageSharp/Common/Extensions/EncoderExtensions.cs
+++ b/src/ImageSharp/Common/Extensions/EncoderExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
#if !SUPPORTS_ENCODING_STRING
using System;
diff --git a/src/ImageSharp/Common/Extensions/EnumerableExtensions.cs b/src/ImageSharp/Common/Extensions/EnumerableExtensions.cs
index 983a1eb8b..2365bd86c 100644
--- a/src/ImageSharp/Common/Extensions/EnumerableExtensions.cs
+++ b/src/ImageSharp/Common/Extensions/EnumerableExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
diff --git a/src/ImageSharp/Common/Extensions/StreamExtensions.cs b/src/ImageSharp/Common/Extensions/StreamExtensions.cs
index 5d8668257..1eff9d7e9 100644
--- a/src/ImageSharp/Common/Extensions/StreamExtensions.cs
+++ b/src/ImageSharp/Common/Extensions/StreamExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.IO;
diff --git a/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs b/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs
index 312ab388d..d81c821ef 100644
--- a/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs
+++ b/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Common/Helpers/DebugGuard.cs b/src/ImageSharp/Common/Helpers/DebugGuard.cs
index 356dd419b..f793e8165 100644
--- a/src/ImageSharp/Common/Helpers/DebugGuard.cs
+++ b/src/ImageSharp/Common/Helpers/DebugGuard.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Diagnostics;
diff --git a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs
index bd25a7b44..7febb3e9b 100644
--- a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs
+++ b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp
ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column);
vector.W = target.W;
- Vector4Utils.UnPremultiply(ref vector);
+ Vector4Utilities.UnPremultiply(ref vector);
target = vector;
}
@@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp
out Vector4 vector);
ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column);
- Vector4Utils.UnPremultiply(ref vector);
+ Vector4Utilities.UnPremultiply(ref vector);
target = vector;
}
@@ -140,7 +140,7 @@ namespace SixLabors.ImageSharp
{
int offsetX = (sourceOffsetColumnBase + x - radiusX).Clamp(minColumn, maxColumn);
var currentColor = sourceRowSpan[offsetX].ToVector4();
- Vector4Utils.Premultiply(ref currentColor);
+ Vector4Utilities.Premultiply(ref currentColor);
vectorX += matrixX[y, x] * currentColor;
vectorY += matrixY[y, x] * currentColor;
@@ -193,7 +193,7 @@ namespace SixLabors.ImageSharp
ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column);
vector.W = target.W;
- Vector4Utils.UnPremultiply(ref vector);
+ Vector4Utilities.UnPremultiply(ref vector);
target = vector;
}
@@ -238,7 +238,7 @@ namespace SixLabors.ImageSharp
ref vector);
ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column);
- Vector4Utils.UnPremultiply(ref vector);
+ Vector4Utilities.UnPremultiply(ref vector);
target = vector;
}
@@ -270,7 +270,7 @@ namespace SixLabors.ImageSharp
{
int offsetX = (sourceOffsetColumnBase + x - radiusX).Clamp(minColumn, maxColumn);
var currentColor = sourceRowSpan[offsetX].ToVector4();
- Vector4Utils.Premultiply(ref currentColor);
+ Vector4Utilities.Premultiply(ref currentColor);
vector += matrix[y, x] * currentColor;
}
}
diff --git a/src/ImageSharp/Common/Helpers/EnumUtils.cs b/src/ImageSharp/Common/Helpers/EnumUtils.cs
index a98b7f84c..6dcfdb0ad 100644
--- a/src/ImageSharp/Common/Helpers/EnumUtils.cs
+++ b/src/ImageSharp/Common/Helpers/EnumUtils.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Common/Helpers/Guard.Numeric.cs b/src/ImageSharp/Common/Helpers/Guard.Numeric.cs
deleted file mode 100644
index 72262e0b9..000000000
--- a/src/ImageSharp/Common/Helpers/Guard.Numeric.cs
+++ /dev/null
@@ -1,1154 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Runtime.CompilerServices;
-
-namespace SixLabors
-{
- ///
- /// Provides methods to protect against invalid parameters.
- ///
- internal static partial class Guard
- {
- ///
- /// Ensures that the specified value is less than a maximum value.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThan(byte value, byte max, string parameterName)
- {
- if (value >= max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThanOrEqualTo(byte value, byte max, string parameterName)
- {
- if (value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThan(byte value, byte min, string parameterName)
- {
- if (value <= min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThanOrEqualTo(byte value, byte min, string parameterName)
- {
- if (value < min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeBetweenOrEqualTo(byte value, byte min, byte max, string parameterName)
- {
- if (value < min || value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
- }
- }
-
- ///
- /// Ensures that the specified value is less than a maximum value.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThan(sbyte value, sbyte max, string parameterName)
- {
- if (value >= max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThanOrEqualTo(sbyte value, sbyte max, string parameterName)
- {
- if (value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThan(sbyte value, sbyte min, string parameterName)
- {
- if (value <= min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThanOrEqualTo(sbyte value, sbyte min, string parameterName)
- {
- if (value < min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeBetweenOrEqualTo(sbyte value, sbyte min, sbyte max, string parameterName)
- {
- if (value < min || value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
- }
- }
-
- ///
- /// Ensures that the specified value is less than a maximum value.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThan(short value, short max, string parameterName)
- {
- if (value >= max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThanOrEqualTo(short value, short max, string parameterName)
- {
- if (value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThan(short value, short min, string parameterName)
- {
- if (value <= min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThanOrEqualTo(short value, short min, string parameterName)
- {
- if (value < min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeBetweenOrEqualTo(short value, short min, short max, string parameterName)
- {
- if (value < min || value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
- }
- }
-
- ///
- /// Ensures that the specified value is less than a maximum value.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThan(ushort value, ushort max, string parameterName)
- {
- if (value >= max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThanOrEqualTo(ushort value, ushort max, string parameterName)
- {
- if (value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThan(ushort value, ushort min, string parameterName)
- {
- if (value <= min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThanOrEqualTo(ushort value, ushort min, string parameterName)
- {
- if (value < min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeBetweenOrEqualTo(ushort value, ushort min, ushort max, string parameterName)
- {
- if (value < min || value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
- }
- }
-
- ///
- /// Ensures that the specified value is less than a maximum value.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThan(char value, char max, string parameterName)
- {
- if (value >= max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThanOrEqualTo(char value, char max, string parameterName)
- {
- if (value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThan(char value, char min, string parameterName)
- {
- if (value <= min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThanOrEqualTo(char value, char min, string parameterName)
- {
- if (value < min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeBetweenOrEqualTo(char value, char min, char max, string parameterName)
- {
- if (value < min || value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
- }
- }
-
- ///
- /// Ensures that the specified value is less than a maximum value.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThan(int value, int max, string parameterName)
- {
- if (value >= max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThanOrEqualTo(int value, int max, string parameterName)
- {
- if (value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThan(int value, int min, string parameterName)
- {
- if (value <= min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThanOrEqualTo(int value, int min, string parameterName)
- {
- if (value < min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeBetweenOrEqualTo(int value, int min, int max, string parameterName)
- {
- if (value < min || value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
- }
- }
-
- ///
- /// Ensures that the specified value is less than a maximum value.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThan(uint value, uint max, string parameterName)
- {
- if (value >= max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThanOrEqualTo(uint value, uint max, string parameterName)
- {
- if (value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThan(uint value, uint min, string parameterName)
- {
- if (value <= min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThanOrEqualTo(uint value, uint min, string parameterName)
- {
- if (value < min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeBetweenOrEqualTo(uint value, uint min, uint max, string parameterName)
- {
- if (value < min || value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
- }
- }
-
- ///
- /// Ensures that the specified value is less than a maximum value.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThan(float value, float max, string parameterName)
- {
- if (value >= max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThanOrEqualTo(float value, float max, string parameterName)
- {
- if (value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThan(float value, float min, string parameterName)
- {
- if (value <= min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThanOrEqualTo(float value, float min, string parameterName)
- {
- if (value < min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeBetweenOrEqualTo(float value, float min, float max, string parameterName)
- {
- if (value < min || value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
- }
- }
-
- ///
- /// Ensures that the specified value is less than a maximum value.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThan(long value, long max, string parameterName)
- {
- if (value >= max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThanOrEqualTo(long value, long max, string parameterName)
- {
- if (value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThan(long value, long min, string parameterName)
- {
- if (value <= min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThanOrEqualTo(long value, long min, string parameterName)
- {
- if (value < min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeBetweenOrEqualTo(long value, long min, long max, string parameterName)
- {
- if (value < min || value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
- }
- }
-
- ///
- /// Ensures that the specified value is less than a maximum value.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThan(ulong value, ulong max, string parameterName)
- {
- if (value >= max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThanOrEqualTo(ulong value, ulong max, string parameterName)
- {
- if (value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThan(ulong value, ulong min, string parameterName)
- {
- if (value <= min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThanOrEqualTo(ulong value, ulong min, string parameterName)
- {
- if (value < min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeBetweenOrEqualTo(ulong value, ulong min, ulong max, string parameterName)
- {
- if (value < min || value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
- }
- }
-
- ///
- /// Ensures that the specified value is less than a maximum value.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThan(double value, double max, string parameterName)
- {
- if (value >= max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThanOrEqualTo(double value, double max, string parameterName)
- {
- if (value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThan(double value, double min, string parameterName)
- {
- if (value <= min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThanOrEqualTo(double value, double min, string parameterName)
- {
- if (value < min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeBetweenOrEqualTo(double value, double min, double max, string parameterName)
- {
- if (value < min || value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
- }
- }
-
- ///
- /// Ensures that the specified value is less than a maximum value.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThan(decimal value, decimal max, string parameterName)
- {
- if (value >= max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeLessThanOrEqualTo(decimal value, decimal max, string parameterName)
- {
- if (value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThan(decimal value, decimal min, string parameterName)
- {
- if (value <= min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeGreaterThanOrEqualTo(decimal value, decimal min, string parameterName)
- {
- if (value < min)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MustBeBetweenOrEqualTo(decimal value, decimal min, decimal max, string parameterName)
- {
- if (value < min || value > max)
- {
- ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
- }
- }
- }
-}
diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs
index 3ab1b199a..1e6e97122 100644
--- a/src/ImageSharp/Common/Helpers/Guard.cs
+++ b/src/ImageSharp/Common/Helpers/Guard.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Reflection;
diff --git a/src/ImageSharp/Common/Helpers/ImageMaths.cs b/src/ImageSharp/Common/Helpers/ImageMaths.cs
index 92430c915..c88aaba76 100644
--- a/src/ImageSharp/Common/Helpers/ImageMaths.cs
+++ b/src/ImageSharp/Common/Helpers/ImageMaths.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -359,7 +359,7 @@ namespace SixLabors.ImageSharp
}
}
- return height;
+ return width;
}
topLeft.Y = GetMinY(bitmap);
diff --git a/src/ImageSharp/Common/Helpers/InliningOptions.cs b/src/ImageSharp/Common/Helpers/InliningOptions.cs
index 069a426d7..d3600d4dd 100644
--- a/src/ImageSharp/Common/Helpers/InliningOptions.cs
+++ b/src/ImageSharp/Common/Helpers/InliningOptions.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
// Uncomment this for verbose profiler results. DO NOT PUSH TO MAIN!
// #define PROFILING
@@ -13,10 +13,16 @@ namespace SixLabors.ImageSharp
internal static class InliningOptions
{
#if PROFILING
+ public const MethodImplOptions HotPath = MethodImplOptions.NoInlining;
public const MethodImplOptions ShortMethod = MethodImplOptions.NoInlining;
#else
+#if SUPPORTS_HOTPATH
+ public const MethodImplOptions HotPath = MethodImplOptions.AggressiveOptimization;
+#else
+ public const MethodImplOptions HotPath = MethodImplOptions.AggressiveInlining;
+#endif
public const MethodImplOptions ShortMethod = MethodImplOptions.AggressiveInlining;
#endif
public const MethodImplOptions ColdPath = MethodImplOptions.NoInlining;
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.Avx2Intrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.Avx2Intrinsics.cs
new file mode 100644
index 000000000..96fbdf124
--- /dev/null
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.Avx2Intrinsics.cs
@@ -0,0 +1,103 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+#if SUPPORTS_RUNTIME_INTRINSICS
+
+using System;
+using System.Numerics;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Runtime.Intrinsics;
+using System.Runtime.Intrinsics.X86;
+
+namespace SixLabors.ImageSharp
+{
+ internal static partial class SimdUtils
+ {
+ public static class Avx2Intrinsics
+ {
+ private static ReadOnlySpan PermuteMaskDeinterleave8x32 => new byte[] { 0, 0, 0, 0, 4, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 3, 0, 0, 0, 7, 0, 0, 0 };
+
+ ///
+ /// as many elements as possible, slicing them down (keeping the remainder).
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ internal static void NormalizedFloatToByteSaturateReduce(
+ ref ReadOnlySpan source,
+ ref Span dest)
+ {
+ DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!");
+
+ if (Avx2.IsSupported)
+ {
+ int remainder = ImageMaths.ModuloP2(source.Length, Vector.Count);
+ int adjustedCount = source.Length - remainder;
+
+ if (adjustedCount > 0)
+ {
+ NormalizedFloatToByteSaturate(
+ source.Slice(0, adjustedCount),
+ dest.Slice(0, adjustedCount));
+
+ source = source.Slice(adjustedCount);
+ dest = dest.Slice(adjustedCount);
+ }
+ }
+ }
+
+ ///
+ /// Implementation of , which is faster on new .NET runtime.
+ ///
+ ///
+ /// Implementation is based on MagicScaler code:
+ /// https://github.com/saucecontrol/PhotoSauce/blob/a9bd6e5162d2160419f0cf743fd4f536c079170b/src/MagicScaler/Magic/Processors/ConvertersFloat.cs#L453-L477
+ ///
+ internal static void NormalizedFloatToByteSaturate(
+ ReadOnlySpan source,
+ Span dest)
+ {
+ VerifySpanInput(source, dest, Vector256.Count);
+
+ int n = dest.Length / Vector256.Count;
+
+ ref Vector256 sourceBase =
+ ref Unsafe.As>(ref MemoryMarshal.GetReference(source));
+ ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest));
+
+ var maxBytes = Vector256.Create(255f);
+ ref byte maskBase = ref MemoryMarshal.GetReference(PermuteMaskDeinterleave8x32);
+ Vector256 mask = Unsafe.As>(ref maskBase);
+
+ for (int i = 0; i < n; i++)
+ {
+ ref Vector256 s = ref Unsafe.Add(ref sourceBase, i * 4);
+
+ Vector256 f0 = s;
+ Vector256 f1 = Unsafe.Add(ref s, 1);
+ Vector256 f2 = Unsafe.Add(ref s, 2);
+ Vector256 f3 = Unsafe.Add(ref s, 3);
+
+ Vector256 w0 = ConvertToInt32(f0, maxBytes);
+ Vector256 w1 = ConvertToInt32(f1, maxBytes);
+ Vector256 w2 = ConvertToInt32(f2, maxBytes);
+ Vector256 w3 = ConvertToInt32(f3, maxBytes);
+
+ Vector256 u0 = Avx2.PackSignedSaturate(w0, w1);
+ Vector256 u1 = Avx2.PackSignedSaturate(w2, w3);
+ Vector256 b = Avx2.PackUnsignedSaturate(u0, u1);
+ b = Avx2.PermuteVar8x32(b.AsInt32(), mask).AsByte();
+
+ Unsafe.Add(ref destBase, i) = b;
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static Vector256 ConvertToInt32(Vector256 vf, Vector256 scale)
+ {
+ vf = Avx.Multiply(vf, scale);
+ return Avx.ConvertToVector256Int32(vf);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs b/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs
index 690bf8309..da6714325 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -17,14 +17,14 @@ namespace SixLabors.ImageSharp
///
public static class BasicIntrinsics256
{
- public static bool IsAvailable { get; } = IsAvx2CompatibleArchitecture;
+ public static bool IsAvailable { get; } = HasVector8;
#if !SUPPORTS_EXTENDED_INTRINSICS
///
- /// as many elements as possible, slicing them down (keeping the remainder).
+ /// as many elements as possible, slicing them down (keeping the remainder).
///
[MethodImpl(InliningOptions.ShortMethod)]
- internal static void BulkConvertByteToNormalizedFloatReduce(
+ internal static void ByteToNormalizedFloatReduce(
ref ReadOnlySpan source,
ref Span dest)
{
@@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp
if (adjustedCount > 0)
{
- BulkConvertByteToNormalizedFloat(
+ ByteToNormalizedFloat(
source.Slice(0, adjustedCount),
dest.Slice(0, adjustedCount));
@@ -50,10 +50,10 @@ namespace SixLabors.ImageSharp
}
///
- /// as many elements as possible, slicing them down (keeping the remainder).
+ /// as many elements as possible, slicing them down (keeping the remainder).
///
[MethodImpl(InliningOptions.ShortMethod)]
- internal static void BulkConvertNormalizedFloatToByteClampOverflowsReduce(
+ internal static void NormalizedFloatToByteSaturateReduce(
ref ReadOnlySpan source,
ref Span dest)
{
@@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp
if (adjustedCount > 0)
{
- BulkConvertNormalizedFloatToByteClampOverflows(source.Slice(0, adjustedCount), dest.Slice(0, adjustedCount));
+ NormalizedFloatToByteSaturate(source.Slice(0, adjustedCount), dest.Slice(0, adjustedCount));
source = source.Slice(adjustedCount);
dest = dest.Slice(adjustedCount);
@@ -78,15 +78,15 @@ namespace SixLabors.ImageSharp
#endif
///
- /// SIMD optimized implementation for .
+ /// SIMD optimized implementation for .
/// Works only with span Length divisible by 8.
/// Implementation adapted from:
/// http://lolengine.net/blog/2011/3/20/understanding-fast-float-integer-conversions
/// http://stackoverflow.com/a/536278
///
- internal static void BulkConvertByteToNormalizedFloat(ReadOnlySpan source, Span dest)
+ internal static void ByteToNormalizedFloat(ReadOnlySpan source, Span dest)
{
- VerifyIsAvx2Compatible(nameof(BulkConvertByteToNormalizedFloat));
+ VerifyHasVector8(nameof(ByteToNormalizedFloat));
VerifySpanInput(source, dest, 8);
var bVec = new Vector(256.0f / 255.0f);
@@ -124,11 +124,11 @@ namespace SixLabors.ImageSharp
}
///
- /// Implementation of which is faster on older runtimes.
+ /// Implementation of which is faster on older runtimes.
///
- internal static void BulkConvertNormalizedFloatToByteClampOverflows(ReadOnlySpan source, Span dest)
+ internal static void NormalizedFloatToByteSaturate(ReadOnlySpan source, Span dest)
{
- VerifyIsAvx2Compatible(nameof(BulkConvertNormalizedFloatToByteClampOverflows));
+ VerifyHasVector8(nameof(NormalizedFloatToByteSaturate));
VerifySpanInput(source, dest, 8);
if (source.Length == 0)
@@ -177,7 +177,7 @@ namespace SixLabors.ImageSharp
///
internal static void BulkConvertNormalizedFloatToByte(ReadOnlySpan source, Span dest)
{
- VerifyIsAvx2Compatible(nameof(BulkConvertNormalizedFloatToByte));
+ VerifyHasVector8(nameof(BulkConvertNormalizedFloatToByte));
VerifySpanInput(source, dest, 8);
if (source.Length == 0)
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs
index 7baa788e4..7df12d5e2 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -43,10 +43,10 @@ namespace SixLabors.ImageSharp
}
///
- /// as many elements as possible, slicing them down (keeping the remainder).
+ /// as many elements as possible, slicing them down (keeping the remainder).
///
[MethodImpl(InliningOptions.ShortMethod)]
- internal static void BulkConvertByteToNormalizedFloatReduce(
+ internal static void ByteToNormalizedFloatReduce(
ref ReadOnlySpan source,
ref Span dest)
{
@@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp
if (adjustedCount > 0)
{
- BulkConvertByteToNormalizedFloat(source.Slice(0, adjustedCount), dest.Slice(0, adjustedCount));
+ ByteToNormalizedFloat(source.Slice(0, adjustedCount), dest.Slice(0, adjustedCount));
source = source.Slice(adjustedCount);
dest = dest.Slice(adjustedCount);
@@ -70,10 +70,10 @@ namespace SixLabors.ImageSharp
}
///
- /// as many elements as possible, slicing them down (keeping the remainder).
+ /// as many elements as possible, slicing them down (keeping the remainder).
///
[MethodImpl(InliningOptions.ShortMethod)]
- internal static void BulkConvertNormalizedFloatToByteClampOverflowsReduce(
+ internal static void NormalizedFloatToByteSaturateReduce(
ref ReadOnlySpan source,
ref Span dest)
{
@@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp
if (adjustedCount > 0)
{
- BulkConvertNormalizedFloatToByteClampOverflows(
+ NormalizedFloatToByteSaturate(
source.Slice(0, adjustedCount),
dest.Slice(0, adjustedCount));
@@ -99,9 +99,9 @@ namespace SixLabors.ImageSharp
}
///
- /// Implementation , which is faster on new RyuJIT runtime.
+ /// Implementation , which is faster on new RyuJIT runtime.
///
- internal static void BulkConvertByteToNormalizedFloat(ReadOnlySpan source, Span dest)
+ internal static void ByteToNormalizedFloat(ReadOnlySpan source, Span dest)
{
VerifySpanInput(source, dest, Vector.Count);
@@ -132,9 +132,9 @@ namespace SixLabors.ImageSharp
}
///
- /// Implementation of , which is faster on new .NET runtime.
+ /// Implementation of , which is faster on new .NET runtime.
///
- internal static void BulkConvertNormalizedFloatToByteClampOverflows(
+ internal static void NormalizedFloatToByteSaturate(
ReadOnlySpan source,
Span dest)
{
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs
index 565ea08f5..3a9cf4631 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -19,10 +19,10 @@ namespace SixLabors.ImageSharp
public static class FallbackIntrinsics128
{
///
- /// as many elements as possible, slicing them down (keeping the remainder).
+ /// as many elements as possible, slicing them down (keeping the remainder).
///
[MethodImpl(InliningOptions.ShortMethod)]
- internal static void BulkConvertByteToNormalizedFloatReduce(
+ internal static void ByteToNormalizedFloatReduce(
ref ReadOnlySpan source,
ref Span dest)
{
@@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp
if (adjustedCount > 0)
{
- BulkConvertByteToNormalizedFloat(
+ ByteToNormalizedFloat(
source.Slice(0, adjustedCount),
dest.Slice(0, adjustedCount));
@@ -43,10 +43,10 @@ namespace SixLabors.ImageSharp
}
///
- /// as many elements as possible, slicing them down (keeping the remainder).
+ /// as many elements as possible, slicing them down (keeping the remainder).
///
[MethodImpl(InliningOptions.ShortMethod)]
- internal static void BulkConvertNormalizedFloatToByteClampOverflowsReduce(
+ internal static void NormalizedFloatToByteSaturateReduce(
ref ReadOnlySpan source,
ref Span dest)
{
@@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp
if (adjustedCount > 0)
{
- BulkConvertNormalizedFloatToByteClampOverflows(
+ NormalizedFloatToByteSaturate(
source.Slice(0, adjustedCount),
dest.Slice(0, adjustedCount));
@@ -67,10 +67,10 @@ namespace SixLabors.ImageSharp
}
///
- /// Implementation of using .
+ /// Implementation of using .
///
[MethodImpl(InliningOptions.ColdPath)]
- internal static void BulkConvertByteToNormalizedFloat(ReadOnlySpan source, Span dest)
+ internal static void ByteToNormalizedFloat(ReadOnlySpan source, Span dest)
{
VerifySpanInput(source, dest, 4);
@@ -99,10 +99,10 @@ namespace SixLabors.ImageSharp
}
///
- /// Implementation of using .
+ /// Implementation of using .
///
[MethodImpl(InliningOptions.ColdPath)]
- internal static void BulkConvertNormalizedFloatToByteClampOverflows(
+ internal static void NormalizedFloatToByteSaturate(
ReadOnlySpan source,
Span dest)
{
@@ -125,10 +125,7 @@ namespace SixLabors.ImageSharp
Vector4 s = Unsafe.Add(ref sBase, i);
s *= maxBytes;
s += half;
-
- // I'm not sure if Vector4.Clamp() is properly implemented with intrinsics.
- s = Vector4.Max(Vector4.Zero, s);
- s = Vector4.Min(maxBytes, s);
+ s = Vector4Utilities.FastClamp(s, Vector4.Zero, maxBytes);
ref ByteVector4 d = ref Unsafe.Add(ref dBase, i);
d.X = (byte)s.X;
@@ -148,4 +145,4 @@ namespace SixLabors.ImageSharp
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.cs b/src/ImageSharp/Common/Helpers/SimdUtils.cs
index 4c34e28bc..054dbed59 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Diagnostics;
@@ -15,9 +15,10 @@ namespace SixLabors.ImageSharp
internal static partial class SimdUtils
{
///
- /// Gets a value indicating whether the code is being executed on AVX2 CPU where both float and integer registers are of size 256 byte.
+ /// Gets a value indicating whether code is being JIT-ed to AVX2 instructions
+ /// where both float and integer registers are of size 256 byte.
///
- public static bool IsAvx2CompatibleArchitecture { get; } =
+ public static bool HasVector8 { get; } =
Vector.IsHardwareAccelerated && Vector.Count == 8 && Vector.Count == 8;
///
@@ -27,7 +28,7 @@ namespace SixLabors.ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static Vector4 PseudoRound(this Vector4 v)
{
- var sign = Vector4.Clamp(v, new Vector4(-1), new Vector4(1));
+ var sign = Vector4Utilities.FastClamp(v, new Vector4(-1), new Vector4(1));
return v + (sign * 0.5f);
}
@@ -60,16 +61,18 @@ namespace SixLabors.ImageSharp
/// The source span of bytes
/// The destination span of floats
[MethodImpl(InliningOptions.ShortMethod)]
- internal static void BulkConvertByteToNormalizedFloat(ReadOnlySpan source, Span dest)
+ internal static void ByteToNormalizedFloat(ReadOnlySpan source, Span dest)
{
DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!");
#if SUPPORTS_EXTENDED_INTRINSICS
- ExtendedIntrinsics.BulkConvertByteToNormalizedFloatReduce(ref source, ref dest);
+ ExtendedIntrinsics.ByteToNormalizedFloatReduce(ref source, ref dest);
#else
- BasicIntrinsics256.BulkConvertByteToNormalizedFloatReduce(ref source, ref dest);
+ BasicIntrinsics256.ByteToNormalizedFloatReduce(ref source, ref dest);
#endif
- FallbackIntrinsics128.BulkConvertByteToNormalizedFloatReduce(ref source, ref dest);
+
+ // Also deals with the remainder from previous conversions:
+ FallbackIntrinsics128.ByteToNormalizedFloatReduce(ref source, ref dest);
// Deal with the remainder:
if (source.Length > 0)
@@ -87,16 +90,20 @@ namespace SixLabors.ImageSharp
/// The source span of floats
/// The destination span of bytes
[MethodImpl(InliningOptions.ShortMethod)]
- internal static void BulkConvertNormalizedFloatToByteClampOverflows(ReadOnlySpan source, Span dest)
+ internal static void NormalizedFloatToByteSaturate(ReadOnlySpan source, Span dest)
{
DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!");
-#if SUPPORTS_EXTENDED_INTRINSICS
- ExtendedIntrinsics.BulkConvertNormalizedFloatToByteClampOverflowsReduce(ref source, ref dest);
+#if SUPPORTS_RUNTIME_INTRINSICS
+ Avx2Intrinsics.NormalizedFloatToByteSaturateReduce(ref source, ref dest);
+#elif SUPPORTS_EXTENDED_INTRINSICS
+ ExtendedIntrinsics.NormalizedFloatToByteSaturateReduce(ref source, ref dest);
#else
- BasicIntrinsics256.BulkConvertNormalizedFloatToByteClampOverflowsReduce(ref source, ref dest);
+ BasicIntrinsics256.NormalizedFloatToByteSaturateReduce(ref source, ref dest);
#endif
- FallbackIntrinsics128.BulkConvertNormalizedFloatToByteClampOverflowsReduce(ref source, ref dest);
+
+ // Also deals with the remainder from previous conversions:
+ FallbackIntrinsics128.NormalizedFloatToByteSaturateReduce(ref source, ref dest);
// Deal with the remainder:
if (source.Length > 0)
@@ -151,9 +158,9 @@ namespace SixLabors.ImageSharp
private static byte ConvertToByte(float f) => (byte)ComparableExtensions.Clamp((f * 255f) + 0.5f, 0, 255f);
[Conditional("DEBUG")]
- private static void VerifyIsAvx2Compatible(string operation)
+ private static void VerifyHasVector8(string operation)
{
- if (!IsAvx2CompatibleArchitecture)
+ if (!HasVector8)
{
throw new NotSupportedException($"{operation} is supported only on AVX2 CPU!");
}
diff --git a/src/ImageSharp/Common/Helpers/TestHelpers.cs b/src/ImageSharp/Common/Helpers/TestHelpers.cs
index c6574e4b5..d1da2def5 100644
--- a/src/ImageSharp/Common/Helpers/TestHelpers.cs
+++ b/src/ImageSharp/Common/Helpers/TestHelpers.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Common.Helpers
{
diff --git a/src/ImageSharp/Common/Helpers/TolerantMath.cs b/src/ImageSharp/Common/Helpers/TolerantMath.cs
index 62b564472..0415ee1e9 100644
--- a/src/ImageSharp/Common/Helpers/TolerantMath.cs
+++ b/src/ImageSharp/Common/Helpers/TolerantMath.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Common/Helpers/UnitConverter.cs b/src/ImageSharp/Common/Helpers/UnitConverter.cs
index 9e4306170..b353e303c 100644
--- a/src/ImageSharp/Common/Helpers/UnitConverter.cs
+++ b/src/ImageSharp/Common/Helpers/UnitConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Common/Helpers/Vector4Utils.cs b/src/ImageSharp/Common/Helpers/Vector4Utilities.cs
similarity index 84%
rename from src/ImageSharp/Common/Helpers/Vector4Utils.cs
rename to src/ImageSharp/Common/Helpers/Vector4Utilities.cs
index 594a5ff10..eee8c49c6 100644
--- a/src/ImageSharp/Common/Helpers/Vector4Utils.cs
+++ b/src/ImageSharp/Common/Helpers/Vector4Utilities.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -11,8 +11,20 @@ namespace SixLabors.ImageSharp
///
/// Utility methods for the struct.
///
- internal static class Vector4Utils
+ internal static class Vector4Utilities
{
+ ///
+ /// Restricts a vector between a minimum and a maximum value.
+ /// 5x Faster then .
+ ///
+ /// The vector to restrict.
+ /// The minimum value.
+ /// The maximum value.
+ /// The .
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static Vector4 FastClamp(Vector4 x, Vector4 min, Vector4 max)
+ => Vector4.Min(Vector4.Max(x, min), max);
+
///
/// Pre-multiplies the "x", "y", "z" components of a vector by its "w" component leaving the "w" component intact.
///
@@ -107,4 +119,4 @@ namespace SixLabors.ImageSharp
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Common/Tuples/Octet{T}.cs b/src/ImageSharp/Common/Tuples/Octet{T}.cs
index 71e7da801..c0bec254a 100644
--- a/src/ImageSharp/Common/Tuples/Octet{T}.cs
+++ b/src/ImageSharp/Common/Tuples/Octet{T}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
diff --git a/src/ImageSharp/Common/Tuples/Vector4Pair.cs b/src/ImageSharp/Common/Tuples/Vector4Pair.cs
index b3a32deee..123f838b3 100644
--- a/src/ImageSharp/Common/Tuples/Vector4Pair.cs
+++ b/src/ImageSharp/Common/Tuples/Vector4Pair.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tuples
/// Downscale method, specific to Jpeg color conversion. Works only if Vector{float}.Count == 4! /// TODO: Move it somewhere else.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal void RoundAndDownscalePreAvx2(float downscaleFactor)
+ internal void RoundAndDownscalePreVector8(float downscaleFactor)
{
ref Vector a = ref Unsafe.As>(ref this.A);
a = a.FastRound();
@@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Tuples
/// TODO: Move it somewhere else.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal void RoundAndDownscaleAvx2(float downscaleFactor)
+ internal void RoundAndDownscaleVector8(float downscaleFactor)
{
ref Vector self = ref Unsafe.As>(ref this);
Vector v = self;
@@ -79,4 +79,4 @@ namespace SixLabors.ImageSharp.Tuples
return $"{nameof(Vector4Pair)}({this.A}, {this.B})";
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs
index 47c7c54ea..1aeea3b7a 100644
--- a/src/ImageSharp/Configuration.cs
+++ b/src/ImageSharp/Configuration.cs
@@ -1,8 +1,9 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
+using System.Net.Http;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Formats.Gif;
@@ -73,6 +74,12 @@ namespace SixLabors.ImageSharp
}
}
+ ///
+ /// Gets a set of properties for the Congiguration.
+ ///
+ /// This can be used for storing global settings and defaults to be accessable to processors.
+ public IDictionary
/// The pixel format.
- /// The stream containing image data.
+ /// The stream containing image data.
/// The decoded image
public Image Decode(Stream stream)
where TPixel : unmanaged, IPixel
@@ -241,6 +241,10 @@ namespace SixLabors.ImageSharp.Formats.Gif
this.stream.Read(this.buffer, 0, 9);
this.imageDescriptor = GifImageDescriptor.Parse(this.buffer);
+ if (this.imageDescriptor.Height == 0 || this.imageDescriptor.Width == 0)
+ {
+ GifThrowHelper.ThrowInvalidImageContentException("Width or height should not be 0");
+ }
}
///
@@ -318,7 +322,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
{
if (length > GifConstants.MaxCommentSubBlockLength)
{
- throw new ImageFormatException($"Gif comment length '{length}' exceeds max '{GifConstants.MaxCommentSubBlockLength}' of a comment data block");
+ GifThrowHelper.ThrowInvalidImageContentException($"Gif comment length '{length}' exceeds max '{GifConstants.MaxCommentSubBlockLength}' of a comment data block");
}
if (this.IgnoreMetadata)
@@ -353,7 +357,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
this.ReadImageDescriptor();
IManagedByteBuffer localColorTable = null;
- IManagedByteBuffer indices = null;
+ Buffer2D indices = null;
try
{
// Determine the color table for this frame. If there is a local one, use it otherwise use the global color table.
@@ -364,11 +368,11 @@ namespace SixLabors.ImageSharp.Formats.Gif
this.stream.Read(localColorTable.Array, 0, length);
}
- indices = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(this.imageDescriptor.Width * this.imageDescriptor.Height, AllocationOptions.Clean);
+ indices = this.configuration.MemoryAllocator.Allocate2D(this.imageDescriptor.Width, this.imageDescriptor.Height, AllocationOptions.Clean);
- this.ReadFrameIndices(this.imageDescriptor, indices.GetSpan());
+ this.ReadFrameIndices(indices);
ReadOnlySpan colorTable = MemoryMarshal.Cast((localColorTable ?? this.globalColorTable).GetSpan());
- this.ReadFrameColors(ref image, ref previousFrame, indices.GetSpan(), colorTable, this.imageDescriptor);
+ this.ReadFrameColors(ref image, ref previousFrame, indices, colorTable, this.imageDescriptor);
// Skip any remaining blocks
this.SkipBlock();
@@ -383,16 +387,13 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
/// Reads the frame indices marking the color to use for each pixel.
///
- /// The .
- /// The pixel array to write to.
+ /// The 2D pixel buffer to write to.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private void ReadFrameIndices(in GifImageDescriptor imageDescriptor, Span indices)
+ private void ReadFrameIndices(Buffer2D indices)
{
int dataSize = this.stream.ReadByte();
- using (var lzwDecoder = new LzwDecoder(this.configuration.MemoryAllocator, this.stream))
- {
- lzwDecoder.DecodePixels(imageDescriptor.Width, imageDescriptor.Height, dataSize, indices);
- }
+ using var lzwDecoder = new LzwDecoder(this.configuration.MemoryAllocator, this.stream);
+ lzwDecoder.DecodePixels(dataSize, indices);
}
///
@@ -404,10 +405,9 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// The indexed pixels.
/// The color table containing the available colors.
/// The
- private void ReadFrameColors(ref Image image, ref ImageFrame previousFrame, Span indices, ReadOnlySpan colorTable, in GifImageDescriptor descriptor)
+ private void ReadFrameColors(ref Image image, ref ImageFrame previousFrame, Buffer2D indices, ReadOnlySpan colorTable, in GifImageDescriptor descriptor)
where TPixel : unmanaged, IPixel
{
- ref byte indicesRef = ref MemoryMarshal.GetReference(indices);
int imageWidth = this.logicalScreenDescriptor.Width;
int imageHeight = this.logicalScreenDescriptor.Height;
@@ -440,13 +440,20 @@ namespace SixLabors.ImageSharp.Formats.Gif
this.RestoreToBackground(imageFrame);
}
- int i = 0;
int interlacePass = 0; // The interlace pass
int interlaceIncrement = 8; // The interlacing line increment
int interlaceY = 0; // The current interlaced line
-
- for (int y = descriptor.Top; y < descriptor.Top + descriptor.Height; y++)
+ int descriptorTop = descriptor.Top;
+ int descriptorBottom = descriptorTop + descriptor.Height;
+ int descriptorLeft = descriptor.Left;
+ int descriptorRight = descriptorLeft + descriptor.Width;
+ bool transFlag = this.graphicsControlExtension.TransparencyFlag;
+ byte transIndex = this.graphicsControlExtension.TransparencyIndex;
+
+ for (int y = descriptorTop; y < descriptorBottom && y < imageHeight; y++)
{
+ ref byte indicesRowRef = ref MemoryMarshal.GetReference(indices.GetRowSpan(y - descriptorTop));
+
// Check if this image is interlaced.
int writeY; // the target y offset to write to
if (descriptor.InterlaceFlag)
@@ -482,35 +489,29 @@ namespace SixLabors.ImageSharp.Formats.Gif
}
ref TPixel rowRef = ref MemoryMarshal.GetReference(imageFrame.GetPixelRowSpan(writeY));
- bool transFlag = this.graphicsControlExtension.TransparencyFlag;
if (!transFlag)
{
// #403 The left + width value can be larger than the image width
- for (int x = descriptor.Left; x < descriptor.Left + descriptor.Width && x < imageWidth; x++)
+ for (int x = descriptorLeft; x < descriptorRight && x < imageWidth; x++)
{
- int index = Unsafe.Add(ref indicesRef, i);
+ int index = Unsafe.Add(ref indicesRowRef, x - descriptorLeft);
ref TPixel pixel = ref Unsafe.Add(ref rowRef, x);
Rgb24 rgb = colorTable[index];
pixel.FromRgb24(rgb);
-
- i++;
}
}
else
{
- byte transIndex = this.graphicsControlExtension.TransparencyIndex;
- for (int x = descriptor.Left; x < descriptor.Left + descriptor.Width && x < imageWidth; x++)
+ for (int x = descriptorLeft; x < descriptorRight && x < imageWidth; x++)
{
- int index = Unsafe.Add(ref indicesRef, i);
+ int index = Unsafe.Add(ref indicesRowRef, x - descriptorLeft);
if (transIndex != index)
{
ref TPixel pixel = ref Unsafe.Add(ref rowRef, x);
Rgb24 rgb = colorTable[index];
pixel.FromRgb24(rgb);
}
-
- i++;
}
}
}
@@ -542,8 +543,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
return;
}
- BufferArea pixelArea = frame.PixelBuffer.GetArea(this.restoreArea.Value);
- pixelArea.Clear();
+ Buffer2DRegion pixelRegion = frame.PixelBuffer.GetRegion(this.restoreArea.Value);
+ pixelRegion.Clear();
this.restoreArea = null;
}
diff --git a/src/ImageSharp/Formats/Gif/GifDisposalMethod.cs b/src/ImageSharp/Formats/Gif/GifDisposalMethod.cs
index 982340db6..872ab3360 100644
--- a/src/ImageSharp/Formats/Gif/GifDisposalMethod.cs
+++ b/src/ImageSharp/Formats/Gif/GifDisposalMethod.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Gif
{
diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs
index 978609d7f..762fc03fc 100644
--- a/src/ImageSharp/Formats/Gif/GifEncoder.cs
+++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs
@@ -1,9 +1,10 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Quantization;
namespace SixLabors.ImageSharp.Formats.Gif
@@ -17,13 +18,19 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Gets or sets the quantizer for reducing the color count.
/// Defaults to the
///
- public IQuantizer Quantizer { get; set; } = new OctreeQuantizer();
+ public IQuantizer Quantizer { get; set; } = KnownQuantizers.Octree;
///
/// Gets or sets the color table mode: Global or local.
///
public GifColorTableMode? ColorTableMode { get; set; }
+ ///
+ /// Gets or sets the used for quantization
+ /// when building a global color table in case of .
+ ///
+ public IPixelSamplingStrategy GlobalPixelSamplingStrategy { get; set; } = new DefaultPixelSamplingStrategy();
+
///
public void Encode(Image image, Stream stream)
where TPixel : unmanaged, IPixel
diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
index 58bb29f2e..34c92a180 100644
--- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
@@ -1,11 +1,12 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
@@ -48,6 +49,11 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
private int bitDepth;
+ ///
+ /// The pixel sampling strategy for global quantization.
+ ///
+ private IPixelSamplingStrategy pixelSamplingStrategy;
+
///
/// Initializes a new instance of the class.
///
@@ -59,6 +65,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
this.memoryAllocator = configuration.MemoryAllocator;
this.quantizer = options.Quantizer;
this.colorTableMode = options.ColorTableMode;
+ this.pixelSamplingStrategy = options.GlobalPixelSamplingStrategy;
}
///
@@ -79,14 +86,23 @@ namespace SixLabors.ImageSharp.Formats.Gif
bool useGlobalTable = this.colorTableMode == GifColorTableMode.Global;
// Quantize the image returning a palette.
- QuantizedFrame quantized;
- using (IFrameQuantizer frameQuantizer = this.quantizer.CreateFrameQuantizer(this.configuration))
+ IndexedImageFrame quantized;
+
+ using (IQuantizer frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer(this.configuration))
{
- quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
+ if (useGlobalTable)
+ {
+ frameQuantizer.BuildPalette(this.pixelSamplingStrategy, image);
+ quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
+ }
+ else
+ {
+ quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(image.Frames.RootFrame, image.Bounds());
+ }
}
// Get the number of bits.
- this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quantized.Palette.Length).Clamp(1, 8);
+ this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quantized.Palette.Length);
// Write the header.
this.WriteHeader(stream);
@@ -119,15 +135,20 @@ namespace SixLabors.ImageSharp.Formats.Gif
}
// Clean up.
- quantized?.Dispose();
+ quantized.Dispose();
// TODO: Write extension etc
stream.WriteByte(GifConstants.EndIntroducer);
}
- private void EncodeGlobal(Image image, QuantizedFrame quantized, int transparencyIndex, Stream stream)
+ private void EncodeGlobal(Image image, IndexedImageFrame quantized, int transparencyIndex, Stream stream)
where TPixel : unmanaged, IPixel
{
+ // The palette quantizer can reuse the same pixel map across multiple frames
+ // since the palette is unchanging. This allows a reduction of memory usage across
+ // multi frame gifs using a global palette.
+ EuclideanPixelMap pixelMap = default;
+ bool pixelMapSet = false;
for (int i = 0; i < image.Frames.Count; i++)
{
ImageFrame frame = image.Frames[i];
@@ -142,22 +163,27 @@ namespace SixLabors.ImageSharp.Formats.Gif
}
else
{
- using (var paletteFrameQuantizer = new PaletteFrameQuantizer(this.configuration, this.quantizer.Options, quantized.Palette))
- using (QuantizedFrame paletteQuantized = paletteFrameQuantizer.QuantizeFrame(frame, frame.Bounds()))
+ if (!pixelMapSet)
{
- this.WriteImageData(paletteQuantized, stream);
+ pixelMapSet = true;
+ pixelMap = new EuclideanPixelMap(this.configuration, quantized.Palette);
}
+
+ using var paletteFrameQuantizer = new PaletteQuantizer(this.configuration, this.quantizer.Options, pixelMap);
+ using IndexedImageFrame paletteQuantized = paletteFrameQuantizer.QuantizeFrame(frame, frame.Bounds());
+ this.WriteImageData(paletteQuantized, stream);
}
}
}
- private void EncodeLocal(Image image, QuantizedFrame quantized, Stream stream)
+ private void EncodeLocal(Image image, IndexedImageFrame quantized, Stream stream)
where TPixel : unmanaged, IPixel
{
ImageFrame previousFrame = null;
GifFrameMetadata previousMeta = null;
- foreach (ImageFrame frame in image.Frames)
+ for (int i = 0; i < image.Frames.Count; i++)
{
+ ImageFrame frame = image.Frames[i];
ImageFrameMetadata metadata = frame.Metadata;
GifFrameMetadata frameMetadata = metadata.GetGifMetadata();
if (quantized is null)
@@ -173,27 +199,23 @@ namespace SixLabors.ImageSharp.Formats.Gif
MaxColors = frameMetadata.ColorTableLength
};
- using (IFrameQuantizer frameQuantizer = this.quantizer.CreateFrameQuantizer(this.configuration, options))
- {
- quantized = frameQuantizer.QuantizeFrame(frame, frame.Bounds());
- }
+ using IQuantizer frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer(this.configuration, options);
+ quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(frame, frame.Bounds());
}
else
{
- using (IFrameQuantizer frameQuantizer = this.quantizer.CreateFrameQuantizer(this.configuration))
- {
- quantized = frameQuantizer.QuantizeFrame(frame, frame.Bounds());
- }
+ using IQuantizer frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer(this.configuration);
+ quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(frame, frame.Bounds());
}
}
- this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quantized.Palette.Length).Clamp(1, 8);
+ this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quantized.Palette.Length);
this.WriteGraphicalControlExtension(frameMetadata, this.GetTransparentIndex(quantized), stream);
this.WriteImageDescriptor(frame, true, stream);
this.WriteColorTable(quantized, stream);
this.WriteImageData(quantized, stream);
- quantized?.Dispose();
+ quantized.Dispose();
quantized = null; // So next frame can regenerate it
previousFrame = frame;
previousMeta = frameMetadata;
@@ -208,25 +230,23 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
/// The .
///
- private int GetTransparentIndex(QuantizedFrame quantized)
+ private int GetTransparentIndex(IndexedImageFrame quantized)
where TPixel : unmanaged, IPixel
{
- // Transparent pixels are much more likely to be found at the end of a palette
+ // Transparent pixels are much more likely to be found at the end of a palette.
int index = -1;
- int length = quantized.Palette.Length;
+ ReadOnlySpan paletteSpan = quantized.Palette.Span;
- using (IMemoryOwner rgbaBuffer = this.memoryAllocator.Allocate(length))
- {
- Span rgbaSpan = rgbaBuffer.GetSpan();
- ref Rgba32 paletteRef = ref MemoryMarshal.GetReference(rgbaSpan);
- PixelOperations.Instance.ToRgba32(this.configuration, quantized.Palette.Span, rgbaSpan);
+ using IMemoryOwner rgbaOwner = quantized.Configuration.MemoryAllocator.Allocate(paletteSpan.Length);
+ Span rgbaSpan = rgbaOwner.GetSpan();
+ PixelOperations.Instance.ToRgba32(quantized.Configuration, paletteSpan, rgbaSpan);
+ ref Rgba32 rgbaSpanRef = ref MemoryMarshal.GetReference(rgbaSpan);
- for (int i = quantized.Palette.Length - 1; i >= 0; i--)
+ for (int i = rgbaSpan.Length - 1; i >= 0; i--)
+ {
+ if (Unsafe.Add(ref rgbaSpanRef, i).Equals(default))
{
- if (Unsafe.Add(ref paletteRef, i).Equals(default))
- {
- index = i;
- }
+ index = i;
}
}
@@ -326,8 +346,9 @@ namespace SixLabors.ImageSharp.Formats.Gif
return;
}
- foreach (string comment in metadata.Comments)
+ for (var i = 0; i < metadata.Comments.Count; i++)
{
+ string comment = metadata.Comments[i];
this.buffer[0] = GifConstants.ExtensionIntroducer;
this.buffer[1] = GifConstants.CommentLabel;
stream.Write(this.buffer, 0, 2);
@@ -335,7 +356,9 @@ namespace SixLabors.ImageSharp.Formats.Gif
// Comment will be stored in chunks of 255 bytes, if it exceeds this size.
ReadOnlySpan commentSpan = comment.AsSpan();
int idx = 0;
- for (; idx <= comment.Length - GifConstants.MaxCommentSubBlockLength; idx += GifConstants.MaxCommentSubBlockLength)
+ for (;
+ idx <= comment.Length - GifConstants.MaxCommentSubBlockLength;
+ idx += GifConstants.MaxCommentSubBlockLength)
{
WriteCommentSubBlock(stream, commentSpan, idx, GifConstants.MaxCommentSubBlockLength);
}
@@ -391,7 +414,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
/// The extension to write to the stream.
/// The stream to write to.
- public void WriteExtension(IGifExtension extension, Stream stream)
+ private void WriteExtension(TGifExtension extension, Stream stream)
+ where TGifExtension : struct, IGifExtension
{
this.buffer[0] = GifConstants.ExtensionIntroducer;
this.buffer[1] = extension.Label;
@@ -437,37 +461,33 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// The pixel format.
/// The to encode.
/// The stream to write to.
- private void WriteColorTable(QuantizedFrame image, Stream stream)
+ private void WriteColorTable(IndexedImageFrame image, Stream stream)
where TPixel : unmanaged, IPixel
{
// The maximum number of colors for the bit depth
- int colorTableLength = ImageMaths.GetColorCountForBitDepth(this.bitDepth) * 3;
- int pixelCount = image.Palette.Length;
+ int colorTableLength = ImageMaths.GetColorCountForBitDepth(this.bitDepth) * Unsafe.SizeOf();
- using (IManagedByteBuffer colorTable = this.memoryAllocator.AllocateManagedByteBuffer(colorTableLength))
- {
- PixelOperations.Instance.ToRgb24Bytes(
- this.configuration,
- image.Palette.Span,
- colorTable.GetSpan(),
- pixelCount);
- stream.Write(colorTable.Array, 0, colorTableLength);
- }
+ using IManagedByteBuffer colorTable = this.memoryAllocator.AllocateManagedByteBuffer(colorTableLength, AllocationOptions.Clean);
+ PixelOperations.Instance.ToRgb24Bytes(
+ this.configuration,
+ image.Palette.Span,
+ colorTable.GetSpan(),
+ image.Palette.Length);
+
+ stream.Write(colorTable.Array, 0, colorTableLength);
}
///
/// Writes the image pixel data to the stream.
///
/// The pixel format.
- /// The containing indexed pixels.
+ /// The containing indexed pixels.
/// The stream to write to.
- private void WriteImageData(QuantizedFrame image, Stream stream)
+ private void WriteImageData(IndexedImageFrame image, Stream stream)
where TPixel : unmanaged, IPixel
{
- using (var encoder = new LzwEncoder(this.memoryAllocator, (byte)this.bitDepth))
- {
- encoder.Encode(image.GetPixelSpan(), stream);
- }
+ using var encoder = new LzwEncoder(this.memoryAllocator, (byte)this.bitDepth);
+ encoder.Encode(((IPixelSource)image).PixelBuffer, stream);
}
}
}
diff --git a/src/ImageSharp/Formats/Gif/GifFormat.cs b/src/ImageSharp/Formats/Gif/GifFormat.cs
index abe87819c..e3122c96e 100644
--- a/src/ImageSharp/Formats/Gif/GifFormat.cs
+++ b/src/ImageSharp/Formats/Gif/GifFormat.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs b/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs
index dfc96af5a..530e368ef 100644
--- a/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs
+++ b/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Gif
{
diff --git a/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs b/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs
index b8f9a03f1..735be07d9 100644
--- a/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs
+++ b/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Formats/Gif/GifMetadata.cs b/src/ImageSharp/Formats/Gif/GifMetadata.cs
index 5fe86c4dd..1a1e90fe6 100644
--- a/src/ImageSharp/Formats/Gif/GifMetadata.cs
+++ b/src/ImageSharp/Formats/Gif/GifMetadata.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Gif/GifThrowHelper.cs b/src/ImageSharp/Formats/Gif/GifThrowHelper.cs
new file mode 100644
index 000000000..dd189ae03
--- /dev/null
+++ b/src/ImageSharp/Formats/Gif/GifThrowHelper.cs
@@ -0,0 +1,28 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using System;
+using System.Runtime.CompilerServices;
+
+namespace SixLabors.ImageSharp.Formats.Gif
+{
+ internal static class GifThrowHelper
+ {
+ ///
+ /// Cold path optimization for throwing 's
+ ///
+ /// The error message for the exception.
+ [MethodImpl(InliningOptions.ColdPath)]
+ public static void ThrowInvalidImageContentException(string errorMessage)
+ => throw new InvalidImageContentException(errorMessage);
+
+ ///
+ /// Cold path optimization for throwing 's.
+ ///
+ /// The error message for the exception.
+ /// The exception that is the cause of the current exception, or a null reference
+ /// if no inner exception is specified.
+ [MethodImpl(InliningOptions.ColdPath)]
+ public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException) => throw new InvalidImageContentException(errorMessage, innerException);
+ }
+}
diff --git a/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs b/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs
index 050ab170b..5bd530bba 100644
--- a/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs
+++ b/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs
index 5936d30cb..cdb6c7260 100644
--- a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs
@@ -1,6 +1,9 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
+using System.Collections.Generic;
+using SixLabors.ImageSharp.Memory;
+using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Quantization;
namespace SixLabors.ImageSharp.Formats.Gif
@@ -19,5 +22,10 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Gets the color table mode: Global or local.
///
GifColorTableMode? ColorTableMode { get; }
+
+ ///
+ /// Gets the used for quantization when building a global color table.
+ ///
+ IPixelSamplingStrategy GlobalPixelSamplingStrategy { get; }
}
}
diff --git a/src/ImageSharp/Formats/Gif/ImageExtensions.cs b/src/ImageSharp/Formats/Gif/ImageExtensions.cs
index c7ac001ff..cc08976e2 100644
--- a/src/ImageSharp/Formats/Gif/ImageExtensions.cs
+++ b/src/ImageSharp/Formats/Gif/ImageExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs
index 0129db0e3..337118a5d 100644
--- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs
+++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
@@ -65,15 +65,15 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
/// Decodes and decompresses all pixel indices from the stream.
///
- /// The width of the pixel index array.
- /// The height of the pixel index array.
/// Size of the data.
/// The pixel array to decode to.
- public void DecodePixels(int width, int height, int dataSize, Span pixels)
+ public void DecodePixels(int dataSize, Buffer2D pixels)
{
Guard.MustBeLessThan(dataSize, int.MaxValue, nameof(dataSize));
// The resulting index table length.
+ int width = pixels.Width;
+ int height = pixels.Height;
int length = width * height;
// Calculate the clear code. The value of the clear code is 2 ^ dataSize
@@ -105,17 +105,28 @@ namespace SixLabors.ImageSharp.Formats.Gif
ref int prefixRef = ref MemoryMarshal.GetReference(this.prefix.GetSpan());
ref int suffixRef = ref MemoryMarshal.GetReference(this.suffix.GetSpan());
ref int pixelStackRef = ref MemoryMarshal.GetReference(this.pixelStack.GetSpan());
- ref byte pixelsRef = ref MemoryMarshal.GetReference(pixels);
for (code = 0; code < clearCode; code++)
{
Unsafe.Add(ref suffixRef, code) = (byte)code;
}
- Span buffer = stackalloc byte[255];
+ Span buffer = stackalloc byte[byte.MaxValue];
+ int y = 0;
+ int x = 0;
+ int rowMax = width;
+ ref byte pixelsRowRef = ref MemoryMarshal.GetReference(pixels.GetRowSpan(y));
while (xyz < length)
{
+ // Reset row reference.
+ if (xyz == rowMax)
+ {
+ x = 0;
+ pixelsRowRef = ref MemoryMarshal.GetReference(pixels.GetRowSpan(++y));
+ rowMax = (y * width) + width;
+ }
+
if (top == 0)
{
if (bits < codeSize)
@@ -209,7 +220,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
top--;
// Clear missing pixels
- Unsafe.Add(ref pixelsRef, xyz++) = (byte)Unsafe.Add(ref pixelStackRef, top);
+ xyz++;
+ Unsafe.Add(ref pixelsRowRef, x++) = (byte)Unsafe.Add(ref pixelStackRef, top);
}
}
diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs
index eda0c5fb8..004c3cb20 100644
--- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs
+++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
@@ -41,13 +41,33 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
private const int HashSize = 5003;
+ ///
+ /// The amount to shift each code.
+ ///
+ private const int HashShift = 4;
+
///
/// Mask used when shifting pixel values
///
private static readonly int[] Masks =
{
- 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF,
- 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF
+ 0b0,
+ 0b1,
+ 0b11,
+ 0b111,
+ 0b1111,
+ 0b11111,
+ 0b111111,
+ 0b1111111,
+ 0b11111111,
+ 0b111111111,
+ 0b1111111111,
+ 0b11111111111,
+ 0b111111111111,
+ 0b1111111111111,
+ 0b11111111111111,
+ 0b111111111111111,
+ 0b1111111111111111
};
///
@@ -80,16 +100,6 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
private readonly byte[] accumulators = new byte[256];
- ///
- /// For dynamic table sizing
- ///
- private readonly int hsize = HashSize;
-
- ///
- /// The current position within the pixelArray.
- ///
- private int position;
-
///
/// Number of bits/code
///
@@ -177,15 +187,13 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
/// Encodes and compresses the indexed pixels to the stream.
///
- /// The span of indexed pixels.
+ /// The 2D buffer of indexed pixels.
/// The stream to write to.
- public void Encode(ReadOnlySpan indexedPixels, Stream stream)
+ public void Encode(Buffer2D indexedPixels, Stream stream)
{
// Write "initial code size" byte
stream.WriteByte((byte)this.initialCodeSize);
- this.position = 0;
-
// Compress and write the pixel data
this.Compress(indexedPixels, this.initialCodeSize + 1, stream);
@@ -199,10 +207,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// The number of bits
/// See
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int GetMaxcode(int bitCount)
- {
- return (1 << bitCount) - 1;
- }
+ private static int GetMaxcode(int bitCount) => (1 << bitCount) - 1;
///
/// Add a character to the end of the current packet, and if it is 254 characters,
@@ -239,25 +244,16 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Reset the code table.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private void ResetCodeTable()
- {
- this.hashTable.GetSpan().Fill(-1);
- }
+ private void ResetCodeTable() => this.hashTable.GetSpan().Fill(-1);
///
/// Compress the packets to the stream.
///
- /// The span of indexed pixels.
+ /// The 2D buffer of indexed pixels.
/// The initial bits.
/// The stream to write to.
- private void Compress(ReadOnlySpan indexedPixels, int initialBits, Stream stream)
+ private void Compress(Buffer2D indexedPixels, int initialBits, Stream stream)
{
- int fcode;
- int c;
- int ent;
- int hsizeReg;
- int hshift;
-
// Set up the globals: globalInitialBits - initial number of bits
this.globalInitialBits = initialBits;
@@ -265,92 +261,82 @@ namespace SixLabors.ImageSharp.Formats.Gif
this.clearFlag = false;
this.bitCount = this.globalInitialBits;
this.maxCode = GetMaxcode(this.bitCount);
-
this.clearCode = 1 << (initialBits - 1);
this.eofCode = this.clearCode + 1;
this.freeEntry = this.clearCode + 2;
+ this.accumulatorCount = 0; // Clear packet
- this.accumulatorCount = 0; // clear packet
-
- ent = this.NextPixel(indexedPixels);
-
- // TODO: PERF: It looks likt hshift could be calculated once statically.
- hshift = 0;
- for (fcode = this.hsize; fcode < 65536; fcode *= 2)
- {
- ++hshift;
- }
-
- hshift = 8 - hshift; // set hash code range bound
-
- hsizeReg = this.hsize;
-
- this.ResetCodeTable(); // clear hash table
-
+ this.ResetCodeTable(); // Clear hash table
this.Output(this.clearCode, stream);
ref int hashTableRef = ref MemoryMarshal.GetReference(this.hashTable.GetSpan());
ref int codeTableRef = ref MemoryMarshal.GetReference(this.codeTable.GetSpan());
- while (this.position < indexedPixels.Length)
- {
- c = this.NextPixel(indexedPixels);
+ int entry = indexedPixels[0, 0];
- fcode = (c << MaxBits) + ent;
- int i = (c << hshift) ^ ent /* = 0 */;
+ for (int y = 0; y < indexedPixels.Height; y++)
+ {
+ ref byte rowSpanRef = ref MemoryMarshal.GetReference(indexedPixels.GetRowSpan(y));
+ int offsetX = y == 0 ? 1 : 0;
- if (Unsafe.Add(ref hashTableRef, i) == fcode)
+ for (int x = offsetX; x < indexedPixels.Width; x++)
{
- ent = Unsafe.Add(ref codeTableRef, i);
- continue;
- }
+ int code = Unsafe.Add(ref rowSpanRef, x);
+ int freeCode = (code << MaxBits) + entry;
+ int hashIndex = (code << HashShift) ^ entry;
- // Non-empty slot
- if (Unsafe.Add(ref hashTableRef, i) >= 0)
- {
- int disp = 1;
- if (i != 0)
+ if (Unsafe.Add(ref hashTableRef, hashIndex) == freeCode)
{
- disp = hsizeReg - i;
+ entry = Unsafe.Add(ref codeTableRef, hashIndex);
+ continue;
}
- do
+ // Non-empty slot
+ if (Unsafe.Add(ref hashTableRef, hashIndex) >= 0)
{
- if ((i -= disp) < 0)
+ int disp = 1;
+ if (hashIndex != 0)
+ {
+ disp = HashSize - hashIndex;
+ }
+
+ do
{
- i += hsizeReg;
+ if ((hashIndex -= disp) < 0)
+ {
+ hashIndex += HashSize;
+ }
+
+ if (Unsafe.Add(ref hashTableRef, hashIndex) == freeCode)
+ {
+ entry = Unsafe.Add(ref codeTableRef, hashIndex);
+ break;
+ }
}
+ while (Unsafe.Add(ref hashTableRef, hashIndex) >= 0);
- if (Unsafe.Add(ref hashTableRef, i) == fcode)
+ if (Unsafe.Add(ref hashTableRef, hashIndex) == freeCode)
{
- ent = Unsafe.Add(ref codeTableRef, i);
- break;
+ continue;
}
}
- while (Unsafe.Add(ref hashTableRef, i) >= 0);
- if (Unsafe.Add(ref hashTableRef, i) == fcode)
+ this.Output(entry, stream);
+ entry = code;
+ if (this.freeEntry < MaxMaxCode)
{
- continue;
+ Unsafe.Add(ref codeTableRef, hashIndex) = this.freeEntry++; // code -> hashtable
+ Unsafe.Add(ref hashTableRef, hashIndex) = freeCode;
+ }
+ else
+ {
+ this.ClearBlock(stream);
}
- }
-
- this.Output(ent, stream);
- ent = c;
- if (this.freeEntry < MaxMaxCode)
- {
- Unsafe.Add(ref codeTableRef, i) = this.freeEntry++; // code -> hashtable
- Unsafe.Add(ref hashTableRef, i) = fcode;
- }
- else
- {
- this.ClearBlock(stream);
}
}
- // Put out the final code.
- this.Output(ent, stream);
-
+ // Output the final code.
+ this.Output(entry, stream);
this.Output(this.eofCode, stream);
}
@@ -366,19 +352,6 @@ namespace SixLabors.ImageSharp.Formats.Gif
this.accumulatorCount = 0;
}
- ///
- /// Reads the next pixel from the image.
- ///
- /// The span of indexed pixels.
- ///
- /// The
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private int NextPixel(ReadOnlySpan indexedPixels)
- {
- return indexedPixels[this.position++] & 0xFF;
- }
-
///
/// Output the current code to the stream.
///
diff --git a/src/ImageSharp/Formats/Gif/MetadataExtensions.cs b/src/ImageSharp/Formats/Gif/MetadataExtensions.cs
index 7c432d26f..a504ffdf5 100644
--- a/src/ImageSharp/Formats/Gif/MetadataExtensions.cs
+++ b/src/ImageSharp/Formats/Gif/MetadataExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Formats/Gif/README.md b/src/ImageSharp/Formats/Gif/README.md
index d47a4c683..eeda20c06 100644
--- a/src/ImageSharp/Formats/Gif/README.md
+++ b/src/ImageSharp/Formats/Gif/README.md
@@ -1,4 +1,6 @@
-Encoder/Decoder adapted and extended from:
+Encoder/Decoder adapted and extended from:
-https://github.com/yufeih/Nine.Imaging/
-https://imagetools.codeplex.com/
+- [Nine.Imaging](https://github.com/yufeih/Nine.Imaging/)
+- [imagetools.codeplex](https://imagetools.codeplex.com/)
+
+A useful set of gif test images can be found at [pygif](https://github.com/robert-ancell/pygif/tree/master/test-suite)
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs b/src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs
index cb548d687..e5a8b8eba 100644
--- a/src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs
+++ b/src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs b/src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs
index c3504dfe7..c7cdb44ad 100644
--- a/src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs
+++ b/src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs b/src/ImageSharp/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs
index 1cfec4763..71a661a66 100644
--- a/src/ImageSharp/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs
+++ b/src/ImageSharp/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs b/src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs
index 5e26370ba..251f262b7 100644
--- a/src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs
+++ b/src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Formats/Gif/Sections/IGifExtension.cs b/src/ImageSharp/Formats/Gif/Sections/IGifExtension.cs
index c8bd28674..efeb0e602 100644
--- a/src/ImageSharp/Formats/Gif/Sections/IGifExtension.cs
+++ b/src/ImageSharp/Formats/Gif/Sections/IGifExtension.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Formats/IImageDecoder.cs b/src/ImageSharp/Formats/IImageDecoder.cs
index 7a7fc4b26..4f17f6729 100644
--- a/src/ImageSharp/Formats/IImageDecoder.cs
+++ b/src/ImageSharp/Formats/IImageDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Formats/IImageEncoder.cs b/src/ImageSharp/Formats/IImageEncoder.cs
index d5ff4b93c..01478eb3e 100644
--- a/src/ImageSharp/Formats/IImageEncoder.cs
+++ b/src/ImageSharp/Formats/IImageEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Formats/IImageFormat.cs b/src/ImageSharp/Formats/IImageFormat.cs
index bd0d6357c..de49afffb 100644
--- a/src/ImageSharp/Formats/IImageFormat.cs
+++ b/src/ImageSharp/Formats/IImageFormat.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/IImageFormatDetector.cs b/src/ImageSharp/Formats/IImageFormatDetector.cs
index becd8200c..8d5f0677f 100644
--- a/src/ImageSharp/Formats/IImageFormatDetector.cs
+++ b/src/ImageSharp/Formats/IImageFormatDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Formats/IImageInfoDetector.cs b/src/ImageSharp/Formats/IImageInfoDetector.cs
index b7769e895..2bd33c616 100644
--- a/src/ImageSharp/Formats/IImageInfoDetector.cs
+++ b/src/ImageSharp/Formats/IImageInfoDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
diff --git a/src/ImageSharp/Formats/ImageFormatManager.cs b/src/ImageSharp/Formats/ImageFormatManager.cs
index e34155706..f4f4c1b10 100644
--- a/src/ImageSharp/Formats/ImageFormatManager.cs
+++ b/src/ImageSharp/Formats/ImageFormatManager.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Concurrent;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs
index acde84c91..0879aaaeb 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Diagnostics;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs
index 23b51f092..5fe2b3ba3 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -99,29 +99,29 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
var CMax4 = new Vector4(maximum);
var COff4 = new Vector4(MathF.Ceiling(maximum / 2));
- this.V0L = Vector4.Clamp(this.V0L + COff4, CMin4, CMax4);
- this.V0R = Vector4.Clamp(this.V0R + COff4, CMin4, CMax4);
- this.V1L = Vector4.Clamp(this.V1L + COff4, CMin4, CMax4);
- this.V1R = Vector4.Clamp(this.V1R + COff4, CMin4, CMax4);
- this.V2L = Vector4.Clamp(this.V2L + COff4, CMin4, CMax4);
- this.V2R = Vector4.Clamp(this.V2R + COff4, CMin4, CMax4);
- this.V3L = Vector4.Clamp(this.V3L + COff4, CMin4, CMax4);
- this.V3R = Vector4.Clamp(this.V3R + COff4, CMin4, CMax4);
- this.V4L = Vector4.Clamp(this.V4L + COff4, CMin4, CMax4);
- this.V4R = Vector4.Clamp(this.V4R + COff4, CMin4, CMax4);
- this.V5L = Vector4.Clamp(this.V5L + COff4, CMin4, CMax4);
- this.V5R = Vector4.Clamp(this.V5R + COff4, CMin4, CMax4);
- this.V6L = Vector4.Clamp(this.V6L + COff4, CMin4, CMax4);
- this.V6R = Vector4.Clamp(this.V6R + COff4, CMin4, CMax4);
- this.V7L = Vector4.Clamp(this.V7L + COff4, CMin4, CMax4);
- this.V7R = Vector4.Clamp(this.V7R + COff4, CMin4, CMax4);
+ this.V0L = Vector4Utilities.FastClamp(this.V0L + COff4, CMin4, CMax4);
+ this.V0R = Vector4Utilities.FastClamp(this.V0R + COff4, CMin4, CMax4);
+ this.V1L = Vector4Utilities.FastClamp(this.V1L + COff4, CMin4, CMax4);
+ this.V1R = Vector4Utilities.FastClamp(this.V1R + COff4, CMin4, CMax4);
+ this.V2L = Vector4Utilities.FastClamp(this.V2L + COff4, CMin4, CMax4);
+ this.V2R = Vector4Utilities.FastClamp(this.V2R + COff4, CMin4, CMax4);
+ this.V3L = Vector4Utilities.FastClamp(this.V3L + COff4, CMin4, CMax4);
+ this.V3R = Vector4Utilities.FastClamp(this.V3R + COff4, CMin4, CMax4);
+ this.V4L = Vector4Utilities.FastClamp(this.V4L + COff4, CMin4, CMax4);
+ this.V4R = Vector4Utilities.FastClamp(this.V4R + COff4, CMin4, CMax4);
+ this.V5L = Vector4Utilities.FastClamp(this.V5L + COff4, CMin4, CMax4);
+ this.V5R = Vector4Utilities.FastClamp(this.V5R + COff4, CMin4, CMax4);
+ this.V6L = Vector4Utilities.FastClamp(this.V6L + COff4, CMin4, CMax4);
+ this.V6R = Vector4Utilities.FastClamp(this.V6R + COff4, CMin4, CMax4);
+ this.V7L = Vector4Utilities.FastClamp(this.V7L + COff4, CMin4, CMax4);
+ this.V7R = Vector4Utilities.FastClamp(this.V7R + COff4, CMin4, CMax4);
}
///
/// AVX2-only variant for executing and in one step.
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void NormalizeColorsAndRoundInplaceAvx2(float maximum)
+ public void NormalizeColorsAndRoundInplaceVector8(float maximum)
{
var off = new Vector(MathF.Ceiling(maximum / 2));
var max = new Vector(maximum);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt
index 176591972..7a7f35e30 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt
+++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt
@@ -1,6 +1,6 @@
<#
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
#>
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
@@ -9,7 +9,7 @@
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
for (int j = 0; j < 2; j++)
{
char side = j == 0 ? 'L' : 'R';
- Write($"this.V{i}{side} = Vector4.Clamp(this.V{i}{side} + COff4, CMin4, CMax4);\r\n");
+ Write($"this.V{i}{side} = Vector4Utilities.FastClamp(this.V{i}{side} + COff4, CMin4, CMax4);\r\n");
}
}
PopIndent();
@@ -84,7 +84,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// AVX2-only variant for executing and in one step.
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void NormalizeColorsAndRoundInplaceAvx2(float maximum)
+ public void NormalizeColorsAndRoundInplaceVector8(float maximum)
{
var off = new Vector(MathF.Ceiling(maximum / 2));
var max = new Vector(maximum);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopyTo.cs
similarity index 77%
rename from src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs
rename to src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopyTo.cs
index 64d1d68b7..48ca39163 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopyTo.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -15,29 +15,36 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Copy block data into the destination color buffer pixel area with the provided horizontal and vertical scale factors.
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void CopyTo(in BufferArea area, int horizontalScale, int verticalScale)
+ public void ScaledCopyTo(in Buffer2DRegion region, int horizontalScale, int verticalScale)
+ {
+ ref float areaOrigin = ref region.GetReferenceToOrigin();
+ this.ScaledCopyTo(ref areaOrigin, region.Stride, horizontalScale, verticalScale);
+ }
+
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void ScaledCopyTo(ref float areaOrigin, int areaStride, int horizontalScale, int verticalScale)
{
if (horizontalScale == 1 && verticalScale == 1)
{
- this.Copy1x1Scale(area);
+ this.Copy1x1Scale(ref areaOrigin, areaStride);
return;
}
if (horizontalScale == 2 && verticalScale == 2)
{
- this.Copy2x2Scale(area);
+ this.Copy2x2Scale(ref areaOrigin, areaStride);
return;
}
// TODO: Optimize: implement all cases with scale-specific, loopless code!
- this.CopyArbitraryScale(area, horizontalScale, verticalScale);
+ this.CopyArbitraryScale(ref areaOrigin, areaStride, horizontalScale, verticalScale);
}
- public void Copy1x1Scale(in BufferArea destination)
+ public void Copy1x1Scale(ref float areaOrigin, int areaStride)
{
ref byte selfBase = ref Unsafe.As(ref this);
- ref byte destBase = ref Unsafe.As(ref destination.GetReferenceToOrigin());
- int destStride = destination.Stride * sizeof(float);
+ ref byte destBase = ref Unsafe.As(ref areaOrigin);
+ int destStride = areaStride * sizeof(float);
CopyRowImpl(ref selfBase, ref destBase, destStride, 0);
CopyRowImpl(ref selfBase, ref destBase, destStride, 1);
@@ -57,10 +64,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
Unsafe.CopyBlock(ref d, ref s, 8 * sizeof(float));
}
- private void Copy2x2Scale(in BufferArea area)
+ private void Copy2x2Scale(ref float areaOrigin, int areaStride)
{
- ref Vector2 destBase = ref Unsafe.As(ref area.GetReferenceToOrigin());
- int destStride = area.Stride / 2;
+ ref Vector2 destBase = ref Unsafe.As(ref areaOrigin);
+ int destStride = areaStride / 2;
this.WidenCopyRowImpl2x2(ref destBase, 0, destStride);
this.WidenCopyRowImpl2x2(ref destBase, 1, destStride);
@@ -110,10 +117,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
[MethodImpl(InliningOptions.ColdPath)]
- private void CopyArbitraryScale(BufferArea area, int horizontalScale, int verticalScale)
+ private void CopyArbitraryScale(ref float areaOrigin, int areaStride, int horizontalScale, int verticalScale)
{
- ref float destBase = ref area.GetReferenceToOrigin();
-
for (int y = 0; y < 8; y++)
{
int yy = y * verticalScale;
@@ -127,12 +132,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
for (int i = 0; i < verticalScale; i++)
{
- int baseIdx = ((yy + i) * area.Stride) + xx;
+ int baseIdx = ((yy + i) * areaStride) + xx;
for (int j = 0; j < horizontalScale; j++)
{
// area[xx + j, yy + i] = value;
- Unsafe.Add(ref destBase, baseIdx + j) = value;
+ Unsafe.Add(ref areaOrigin, baseIdx + j) = value;
}
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
index f11b0f8fa..713f21d2a 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Diagnostics;
@@ -201,7 +201,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
///
/// Destination
[MethodImpl(InliningOptions.ShortMethod)]
- public void CopyTo(Span dest)
+ public void ScaledCopyTo(Span dest)
{
ref byte d = ref Unsafe.As(ref MemoryMarshal.GetReference(dest));
ref byte s = ref Unsafe.As(ref this);
@@ -215,7 +215,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Pointer to block
/// Destination
[MethodImpl(InliningOptions.ShortMethod)]
- public static unsafe void CopyTo(Block8x8F* blockPtr, Span dest)
+ public static unsafe void ScaledCopyTo(Block8x8F* blockPtr, Span dest)
{
float* fPtr = (float*)blockPtr;
for (int i = 0; i < Size; i++)
@@ -231,9 +231,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// The block pointer.
/// The destination.
[MethodImpl(InliningOptions.ShortMethod)]
- public static unsafe void CopyTo(Block8x8F* blockPtr, Span dest)
+ public static unsafe void ScaledCopyTo(Block8x8F* blockPtr, Span dest)
{
- blockPtr->CopyTo(dest);
+ blockPtr->ScaledCopyTo(dest);
}
///
@@ -241,7 +241,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
///
/// Destination
[MethodImpl(InliningOptions.ShortMethod)]
- public unsafe void CopyTo(float[] dest)
+ public unsafe void ScaledCopyTo(float[] dest)
{
fixed (void* ptr = &this.V0L)
{
@@ -253,7 +253,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Copy raw 32bit floating point data to dest
///
/// Destination
- public unsafe void CopyTo(Span dest)
+ public unsafe void ScaledCopyTo(Span dest)
{
fixed (Vector4* ptr = &this.V0L)
{
@@ -268,7 +268,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
public float[] ToArray()
{
var result = new float[Size];
- this.CopyTo(result);
+ this.ScaledCopyTo(result);
return result;
}
@@ -471,9 +471,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
///
public void NormalizeColorsAndRoundInplace(float maximum)
{
- if (SimdUtils.IsAvx2CompatibleArchitecture)
+ if (SimdUtils.HasVector8)
{
- this.NormalizeColorsAndRoundInplaceAvx2(maximum);
+ this.NormalizeColorsAndRoundInplaceVector8(maximum);
}
else
{
@@ -497,7 +497,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
public void LoadFrom(ref Block8x8 source)
{
#if SUPPORTS_EXTENDED_INTRINSICS
- if (SimdUtils.IsAvx2CompatibleArchitecture)
+ if (SimdUtils.HasVector8)
{
this.LoadFromInt16ExtendedAvx2(ref source);
return;
@@ -513,7 +513,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
public void LoadFromInt16ExtendedAvx2(ref Block8x8 source)
{
DebugGuard.IsTrue(
- SimdUtils.IsAvx2CompatibleArchitecture,
+ SimdUtils.HasVector8,
"LoadFromUInt16ExtendedAvx2 only works on AVX2 compatible architecture!");
ref Vector sRef = ref Unsafe.As>(ref source);
@@ -589,7 +589,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
private static Vector4 DivideRound(Vector4 dividend, Vector4 divisor)
{
// sign(dividend) = max(min(dividend, 1), -1)
- var sign = Vector4.Clamp(dividend, NegativeOne, Vector4.One);
+ var sign = Vector4Utilities.FastClamp(dividend, NegativeOne, Vector4.One);
// AlmostRound(dividend/divisor) = dividend/divisor + 0.5*sign(dividend)
return (dividend / divisor) + (sign * Offset);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs
index e34af9825..a3e787470 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs
index f106d67ad..56fb32fb9 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs
index 68ab6f912..007ca5a8f 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs
index 7a92a4ed4..a36942c52 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrBasic.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrBasic.cs
index a646cd6cf..47a96afd1 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrBasic.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrBasic.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs
index 1706b4c1b..c9c740716 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -90,21 +90,21 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters
if (Vector.Count == 4)
{
// TODO: Find a way to properly run & test this path on AVX2 PC-s! (Have I already mentioned that Vector is terrible?)
- r.RoundAndDownscalePreAvx2(maxValue);
- g.RoundAndDownscalePreAvx2(maxValue);
- b.RoundAndDownscalePreAvx2(maxValue);
+ r.RoundAndDownscalePreVector8(maxValue);
+ g.RoundAndDownscalePreVector8(maxValue);
+ b.RoundAndDownscalePreVector8(maxValue);
}
- else if (SimdUtils.IsAvx2CompatibleArchitecture)
+ else if (SimdUtils.HasVector8)
{
- r.RoundAndDownscaleAvx2(maxValue);
- g.RoundAndDownscaleAvx2(maxValue);
- b.RoundAndDownscaleAvx2(maxValue);
+ r.RoundAndDownscaleVector8(maxValue);
+ g.RoundAndDownscaleVector8(maxValue);
+ b.RoundAndDownscaleVector8(maxValue);
}
else
{
// TODO: Run fallback scalar code here
// However, no issues expected before someone implements this: https://github.com/dotnet/coreclr/issues/12007
- throw new NotImplementedException("Your CPU architecture is too modern!");
+ JpegThrowHelper.ThrowNotImplementedException("Your CPU architecture is too modern!");
}
// Collect (r0,r1...r8) (g0,g1...g8) (b0,b1...b8) vector values in the expected (r0,g0,g1,1), (r1,g1,g2,1) ... order:
@@ -114,4 +114,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs
index 093ea2f9a..663ed44e8 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -13,14 +13,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters
{
internal abstract partial class JpegColorConverter
{
- internal sealed class FromYCbCrSimdAvx2 : JpegColorConverter
+ internal sealed class FromYCbCrSimdVector8 : JpegColorConverter
{
- public FromYCbCrSimdAvx2(int precision)
+ public FromYCbCrSimdVector8(int precision)
: base(JpegColorSpace.YCbCr, precision)
{
}
- public static bool IsAvailable => Vector.IsHardwareAccelerated && SimdUtils.IsAvx2CompatibleArchitecture;
+ public static bool IsAvailable => Vector.IsHardwareAccelerated && SimdUtils.HasVector8;
public override void ConvertToRgba(in ComponentValues values, Span result)
{
@@ -107,4 +107,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs
index f1d773708..562fa8f44 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs
index 44314759c..af7b21fb0 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
@@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters
/// Returns the for the YCbCr colorspace that matches the current CPU architecture.
///
private static JpegColorConverter GetYCbCrConverter(int precision) =>
- FromYCbCrSimdAvx2.IsAvailable ? (JpegColorConverter)new FromYCbCrSimdAvx2(precision) : new FromYCbCrSimd(precision);
+ FromYCbCrSimdVector8.IsAvailable ? (JpegColorConverter)new FromYCbCrSimdVector8(precision) : new FromYCbCrSimd(precision);
///
/// A stack-only struct to reference the input buffers using -s.
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanBuffer.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanBuffer.cs
index 34fe1aecb..09adbc44e 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanBuffer.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanBuffer.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.IO;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
index fbb2b5272..bc68fb3b0 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTable.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTable.cs
index 602593016..b5f4f1b31 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTable.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTable.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs
index 169b02e9f..d77b0e864 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Memory;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs
index 8075fd4ba..7ee8a4b15 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs
index 7497c8a40..8a1389842 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using SixLabors.ImageSharp.Metadata;
@@ -29,12 +29,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
if (xDensity <= 0)
{
- JpegThrowHelper.ThrowImageFormatException($"X-Density {xDensity} must be greater than 0.");
+ JpegThrowHelper.ThrowInvalidImageContentException($"X-Density {xDensity} must be greater than 0.");
}
if (yDensity <= 0)
{
- JpegThrowHelper.ThrowImageFormatException($"Y-Density {yDensity} must be greater than 0.");
+ JpegThrowHelper.ThrowInvalidImageContentException($"Y-Density {yDensity} must be greater than 0.");
}
this.MajorVersion = majorVersion;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs
index 44f9048a5..8bd15ea12 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.InteropServices;
@@ -68,11 +68,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// - Copy the resulting color values into 'destArea' scaling up the block by amount defined in .
///
/// The source block.
- /// The destination buffer area.
+ /// Reference to the origin of the destination pixel area.
+ /// The width of the destination pixel buffer.
/// The maximum value derived from the bitdepth.
public void ProcessBlockColorsInto(
ref Block8x8 sourceBlock,
- in BufferArea destArea,
+ ref float destAreaOrigin,
+ int destAreaStride,
float maximumValue)
{
ref Block8x8F b = ref this.SourceBlock;
@@ -88,7 +90,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
// To be "more accurate", we need to emulate this by rounding!
this.WorkspaceBlock1.NormalizeColorsAndRoundInplace(maximumValue);
- this.WorkspaceBlock1.CopyTo(destArea, this.subSamplingDivisors.Width, this.subSamplingDivisors.Height);
+ this.WorkspaceBlock1.ScaledCopyTo(
+ ref destAreaOrigin,
+ destAreaStride,
+ this.subSamplingDivisors.Width,
+ this.subSamplingDivisors.Height);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegColorSpace.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegColorSpace.cs
index aa33744ad..f7332852d 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegColorSpace.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegColorSpace.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs
index 622c34e9b..f254f9e86 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs
index 22bc8ccaa..aa3ba9c4c 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
@@ -79,6 +79,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
var blockPp = new JpegBlockPostProcessor(this.ImagePostProcessor.RawJpeg, this.Component);
float maximumValue = MathF.Pow(2, this.ImagePostProcessor.RawJpeg.Precision) - 1;
+ int destAreaStride = this.ColorBuffer.Width;
+
for (int y = 0; y < this.BlockRowsPerStep; y++)
{
int yBlock = this.currentComponentRowInBlocks + y;
@@ -90,22 +92,19 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
int yBuffer = y * this.blockAreaSize.Height;
+ Span colorBufferRow = this.ColorBuffer.GetRowSpan(yBuffer);
Span blockRow = this.Component.SpectralBlocks.GetRowSpan(yBlock);
- ref Block8x8 blockRowBase = ref MemoryMarshal.GetReference(blockRow);
+ // see: https://github.com/SixLabors/ImageSharp/issues/824
+ int widthInBlocks = Math.Min(this.Component.SpectralBlocks.Width, this.SizeInBlocks.Width);
- for (int xBlock = 0; xBlock < this.SizeInBlocks.Width; xBlock++)
+ for (int xBlock = 0; xBlock < widthInBlocks; xBlock++)
{
- ref Block8x8 block = ref Unsafe.Add(ref blockRowBase, xBlock);
+ ref Block8x8 block = ref blockRow[xBlock];
int xBuffer = xBlock * this.blockAreaSize.Width;
+ ref float destAreaOrigin = ref colorBufferRow[xBuffer];
- BufferArea destArea = this.ColorBuffer.GetArea(
- xBuffer,
- yBuffer,
- this.blockAreaSize.Width,
- this.blockAreaSize.Height);
-
- blockPp.ProcessBlockColorsInto(ref block, destArea, maximumValue);
+ blockPp.ProcessBlockColorsInto(ref block, ref destAreaOrigin, destAreaStride, maximumValue);
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs
index d2b0ee26e..389632cae 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs
index f426eb1b1..483c22a39 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
@@ -28,12 +28,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
///
/// Gets or sets the number of scanlines within the frame.
///
- public short Scanlines { get; set; }
+ public int Scanlines { get; set; }
///
/// Gets or sets the number of samples per scanline.
///
- public short SamplesPerLine { get; set; }
+ public int SamplesPerLine { get; set; }
///
/// Gets or sets the number of components within a frame. In progressive frames this value can range from only 1 to 4.
@@ -105,4 +105,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs
index 5352a0bff..93de973d5 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs
index 87b486ea6..c8ec92f97 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
@@ -28,6 +28,30 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
(byte)'I', (byte)'L', (byte)'E', (byte)'\0'
};
+ ///
+ /// Gets the adobe photoshop APP13 marker which can contain IPTC meta data.
+ ///
+ public static ReadOnlySpan AdobePhotoshopApp13Marker => new[]
+ {
+ (byte)'P', (byte)'h', (byte)'o', (byte)'t', (byte)'o', (byte)'s', (byte)'h', (byte)'o', (byte)'p', (byte)' ', (byte)'3', (byte)'.', (byte)'0', (byte)'\0'
+ };
+
+ ///
+ /// Gets the 8BIM marker, which signals the start of a adobe specific image resource block.
+ ///
+ public static ReadOnlySpan AdobeImageResourceBlockMarker => new[]
+ {
+ (byte)'8', (byte)'B', (byte)'I', (byte)'M'
+ };
+
+ ///
+ /// Gets a IPTC Image resource ID.
+ ///
+ public static ReadOnlySpan AdobeIptcMarker => new[]
+ {
+ (byte)4, (byte)4
+ };
+
///
/// Gets the EXIF specific markers.
///
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/QualityEvaluator.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/QualityEvaluator.cs
index a7d2a0fde..c304c00b6 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/QualityEvaluator.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/QualityEvaluator.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/BlockQuad.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/BlockQuad.cs
index 7a312138d..714c4f823 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/BlockQuad.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/BlockQuad.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffIndex.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffIndex.cs
index 633d7ea80..6f5d4700d 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffIndex.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffIndex.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs
index a31c4bf2f..a92e06dac 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs
index 2e2ee9575..acf25a120 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/QuantIndex.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/QuantIndex.cs
index d0933af0c..204652b7e 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/QuantIndex.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/QuantIndex.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbToYCbCrTables.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbToYCbCrTables.cs
index cb0810985..8ae50a167 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbToYCbCrTables.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbToYCbCrTables.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter{TPixel}.cs
index ba604e891..38a955f65 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter{TPixel}.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.cs b/src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.cs
index dcdc7e9ba..26c709d5e 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.cs b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.cs
index 0cc729371..69c634c35 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
namespace SixLabors.ImageSharp.Formats.Jpeg.Components
diff --git a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.tt b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.tt
index 28bcea791..4afd1f72d 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.tt
+++ b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.tt
@@ -1,6 +1,6 @@
<#
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
#>
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
@@ -9,7 +9,7 @@
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
namespace SixLabors.ImageSharp.Formats.Jpeg.Components
diff --git a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs
index 534c66b99..d72c6f17e 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs b/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs
index 8c3daa4d5..971890924 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/SizeExtensions.cs b/src/ImageSharp/Formats/Jpeg/Components/SizeExtensions.cs
index 94771aa64..f3e797228 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/SizeExtensions.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/SizeExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs b/src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs
index 669abad28..801867d56 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs b/src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs
index ef7b377d2..dc0971e51 100644
--- a/src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs
+++ b/src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Jpeg
{
diff --git a/src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs b/src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs
index 53108de93..5f1a2a99c 100644
--- a/src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Jpeg
{
diff --git a/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs b/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs
index 7fec050b4..36c6d5615 100644
--- a/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs
+++ b/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
diff --git a/src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs b/src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs
index 9840a2ae8..6719f5498 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Jpeg
{
diff --git a/src/ImageSharp/Formats/Jpeg/JpegConstants.cs b/src/ImageSharp/Formats/Jpeg/JpegConstants.cs
index 9f50e2cab..30a0e4a00 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegConstants.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegConstants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Collections.Generic;
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder;
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
index b1144508e..97f455c6f 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
using SixLabors.ImageSharp.Memory;
@@ -32,9 +32,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
{
(int w, int h) = (decoder.ImageWidth, decoder.ImageHeight);
- // TODO: use InvalidImageContentException here, if we decide to define it
- // https://github.com/SixLabors/ImageSharp/issues/1110
- throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {w}x{h}.", ex);
+ JpegThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {w}x{h}.", ex);
+
+ // Not reachable, as the previous statement will throw a exception.
+ return null;
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
index 951fec1d4..e61ca326a 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers.Binary;
@@ -14,6 +14,7 @@ using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.Metadata.Profiles.Icc;
+using SixLabors.ImageSharp.Metadata.Profiles.Iptc;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Jpeg
@@ -46,7 +47,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
private readonly byte[] markerBuffer = new byte[2];
///
- /// The DC Huffman tables
+ /// The DC Huffman tables.
///
private HuffmanTable[] dcHuffmanTables;
@@ -56,37 +57,47 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
private HuffmanTable[] acHuffmanTables;
///
- /// The reset interval determined by RST markers
+ /// The reset interval determined by RST markers.
///
private ushort resetInterval;
///
- /// Whether the image has an EXIF marker
+ /// Whether the image has an EXIF marker.
///
private bool isExif;
///
- /// Contains exif data
+ /// Contains exif data.
///
private byte[] exifData;
///
- /// Whether the image has an ICC marker
+ /// Whether the image has an ICC marker.
///
private bool isIcc;
///
- /// Contains ICC data
+ /// Contains ICC data.
///
private byte[] iccData;
///
- /// Contains information about the JFIF marker
+ /// Whether the image has a IPTC data.
+ ///
+ private bool isIptc;
+
+ ///
+ /// Contains IPTC data.
+ ///
+ private byte[] iptcData;
+
+ ///
+ /// Contains information about the JFIF marker.
///
private JFifMarker jFif;
///
- /// Contains information about the Adobe marker
+ /// Contains information about the Adobe marker.
///
private AdobeMarker adobe;
@@ -213,6 +224,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
this.ParseStream(stream);
this.InitExifProfile();
this.InitIccProfile();
+ this.InitIptcProfile();
this.InitDerivedMetadataProperties();
return this.PostProcessIntoImage();
}
@@ -226,6 +238,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
this.ParseStream(stream, true);
this.InitExifProfile();
this.InitIccProfile();
+ this.InitIptcProfile();
this.InitDerivedMetadataProperties();
return new ImageInfo(new PixelTypeInfo(this.BitsPerPixel), this.ImageWidth, this.ImageHeight, this.Metadata);
@@ -246,7 +259,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
var fileMarker = new JpegFileMarker(this.markerBuffer[1], 0);
if (fileMarker.Marker != JpegConstants.Markers.SOI)
{
- JpegThrowHelper.ThrowImageFormatException("Missing SOI marker.");
+ JpegThrowHelper.ThrowInvalidImageContentException("Missing SOI marker.");
}
this.InputStream.Read(this.markerBuffer, 0, 2);
@@ -344,10 +357,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
case JpegConstants.Markers.APP10:
case JpegConstants.Markers.APP11:
case JpegConstants.Markers.APP12:
- case JpegConstants.Markers.APP13:
this.InputStream.Skip(remaining);
break;
+ case JpegConstants.Markers.APP13:
+ this.ProcessApp13Marker(remaining);
+ break;
+
case JpegConstants.Markers.APP14:
this.ProcessApp14Marker(remaining);
break;
@@ -407,7 +423,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
: JpegColorSpace.Cmyk;
}
- JpegThrowHelper.ThrowImageFormatException($"Unsupported color mode. Supported component counts 1, 3, and 4; found {this.ComponentCount}");
+ JpegThrowHelper.ThrowInvalidImageContentException($"Unsupported color mode. Supported component counts 1, 3, and 4; found {this.ComponentCount}");
return default;
}
@@ -437,6 +453,18 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
}
}
+ ///
+ /// Initializes the IPTC profile.
+ ///
+ private void InitIptcProfile()
+ {
+ if (this.isIptc)
+ {
+ var profile = new IptcProfile(this.iptcData);
+ this.Metadata.IptcProfile = profile;
+ }
+ }
+
///
/// Assigns derived metadata properties to , eg. horizontal and vertical resolution if it has a JFIF header.
///
@@ -582,6 +610,95 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
}
}
+ ///
+ /// Processes a App13 marker, which contains IPTC data stored with Adobe Photoshop.
+ /// The content of an APP13 segment is formed by an identifier string followed by a sequence of resource data blocks.
+ ///
+ /// The remaining bytes in the segment block.
+ private void ProcessApp13Marker(int remaining)
+ {
+ if (remaining < ProfileResolver.AdobePhotoshopApp13Marker.Length || this.IgnoreMetadata)
+ {
+ this.InputStream.Skip(remaining);
+ return;
+ }
+
+ this.InputStream.Read(this.temp, 0, ProfileResolver.AdobePhotoshopApp13Marker.Length);
+ remaining -= ProfileResolver.AdobePhotoshopApp13Marker.Length;
+ if (ProfileResolver.IsProfile(this.temp, ProfileResolver.AdobePhotoshopApp13Marker))
+ {
+ var resourceBlockData = new byte[remaining];
+ this.InputStream.Read(resourceBlockData, 0, remaining);
+ Span blockDataSpan = resourceBlockData.AsSpan();
+
+ while (blockDataSpan.Length > 12)
+ {
+ if (!ProfileResolver.IsProfile(blockDataSpan.Slice(0, 4), ProfileResolver.AdobeImageResourceBlockMarker))
+ {
+ return;
+ }
+
+ blockDataSpan = blockDataSpan.Slice(4);
+ Span imageResourceBlockId = blockDataSpan.Slice(0, 2);
+ if (ProfileResolver.IsProfile(imageResourceBlockId, ProfileResolver.AdobeIptcMarker))
+ {
+ var resourceBlockNameLength = ReadImageResourceNameLength(blockDataSpan);
+ var resourceDataSize = ReadResourceDataLength(blockDataSpan, resourceBlockNameLength);
+ int dataStartIdx = 2 + resourceBlockNameLength + 4;
+ if (resourceDataSize > 0 && blockDataSpan.Length >= dataStartIdx + resourceDataSize)
+ {
+ this.isIptc = true;
+ this.iptcData = blockDataSpan.Slice(dataStartIdx, resourceDataSize).ToArray();
+ break;
+ }
+ }
+ else
+ {
+ var resourceBlockNameLength = ReadImageResourceNameLength(blockDataSpan);
+ var resourceDataSize = ReadResourceDataLength(blockDataSpan, resourceBlockNameLength);
+ int dataStartIdx = 2 + resourceBlockNameLength + 4;
+ if (blockDataSpan.Length < dataStartIdx + resourceDataSize)
+ {
+ // Not enough data or the resource data size is wrong.
+ break;
+ }
+
+ blockDataSpan = blockDataSpan.Slice(dataStartIdx + resourceDataSize);
+ }
+ }
+ }
+ }
+
+ ///
+ /// Reads the adobe image resource block name: a Pascal string (padded to make size even).
+ ///
+ /// The span holding the block resource data.
+ /// The length of the name.
+ [MethodImpl(InliningOptions.ShortMethod)]
+ private static int ReadImageResourceNameLength(Span blockDataSpan)
+ {
+ byte nameLength = blockDataSpan[2];
+ var nameDataSize = nameLength == 0 ? 2 : nameLength;
+ if (nameDataSize % 2 != 0)
+ {
+ nameDataSize++;
+ }
+
+ return nameDataSize;
+ }
+
+ ///
+ /// Reads the length of a adobe image resource data block.
+ ///
+ /// The span holding the block resource data.
+ /// The length of the block name.
+ /// The block length.
+ [MethodImpl(InliningOptions.ShortMethod)]
+ private static int ReadResourceDataLength(Span blockDataSpan, int resourceBlockNameLength)
+ {
+ return BinaryPrimitives.ReadInt32BigEndian(blockDataSpan.Slice(2 + resourceBlockNameLength, 4));
+ }
+
///
/// Processes the application header containing the Adobe identifier
/// which stores image encoding information for DCT filters.
@@ -704,7 +821,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
{
if (this.Frame != null)
{
- JpegThrowHelper.ThrowImageFormatException("Multiple SOF markers. Only single frame jpegs supported.");
+ JpegThrowHelper.ThrowInvalidImageContentException("Multiple SOF markers. Only single frame jpegs supported.");
}
// Read initial marker definitions.
@@ -714,7 +831,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
// We only support 8-bit and 12-bit precision.
if (Array.IndexOf(this.supportedPrecisions, this.temp[0]) == -1)
{
- JpegThrowHelper.ThrowImageFormatException("Only 8-Bit and 12-Bit precision supported.");
+ JpegThrowHelper.ThrowInvalidImageContentException("Only 8-Bit and 12-Bit precision supported.");
}
this.Precision = this.temp[0];
@@ -724,8 +841,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
Extended = frameMarker.Marker == JpegConstants.Markers.SOF1,
Progressive = frameMarker.Marker == JpegConstants.Markers.SOF2,
Precision = this.temp[0],
- Scanlines = (short)((this.temp[1] << 8) | this.temp[2]),
- SamplesPerLine = (short)((this.temp[3] << 8) | this.temp[4]),
+ Scanlines = (this.temp[1] << 8) | this.temp[2],
+ SamplesPerLine = (this.temp[3] << 8) | this.temp[4],
ComponentCount = this.temp[5]
};
@@ -811,13 +928,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
// Types 0..1 DC..AC
if (tableType > 1)
{
- JpegThrowHelper.ThrowImageFormatException("Bad Huffman Table type.");
+ JpegThrowHelper.ThrowInvalidImageContentException("Bad Huffman Table type.");
}
// Max tables of each type
if (tableIndex > 3)
{
- JpegThrowHelper.ThrowImageFormatException("Bad Huffman Table index.");
+ JpegThrowHelper.ThrowInvalidImageContentException("Bad Huffman Table index.");
}
this.InputStream.Read(huffmanData.Array, 0, 16);
@@ -836,7 +953,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
if (codeLengthSum > 256 || codeLengthSum > length)
{
- JpegThrowHelper.ThrowImageFormatException("Huffman table has excessive length.");
+ JpegThrowHelper.ThrowInvalidImageContentException("Huffman table has excessive length.");
}
using (IManagedByteBuffer huffmanValues = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(256, AllocationOptions.Clean))
@@ -878,7 +995,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
{
if (this.Frame is null)
{
- JpegThrowHelper.ThrowImageFormatException("No readable SOFn (Start Of Frame) marker found.");
+ JpegThrowHelper.ThrowInvalidImageContentException("No readable SOFn (Start Of Frame) marker found.");
}
int selectorsCount = this.InputStream.ReadByte();
@@ -899,7 +1016,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
if (componentIndex < 0)
{
- JpegThrowHelper.ThrowImageFormatException($"Unknown component selector {componentIndex}.");
+ JpegThrowHelper.ThrowInvalidImageContentException($"Unknown component selector {componentIndex}.");
}
ref JpegComponent component = ref this.Frame.Components[componentIndex];
diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs
index 1c4035a98..9f3d04a8a 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
index 32f4d2287..21bf538ec 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
@@ -1,9 +1,10 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers.Binary;
using System.IO;
+using System.Linq;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Common.Helpers;
using SixLabors.ImageSharp.Formats.Jpeg.Components;
@@ -13,6 +14,7 @@ using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.Metadata.Profiles.Icc;
+using SixLabors.ImageSharp.Metadata.Profiles.Iptc;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Jpeg
@@ -231,7 +233,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
// Write the Start Of Image marker.
this.WriteApplicationHeader(metadata);
- // Write Exif and ICC profiles
+ // Write Exif, ICC and IPTC profiles
this.WriteProfiles(metadata);
// Write the quantization tables.
@@ -647,9 +649,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// Writes the EXIF profile.
///
/// The exif profile.
- ///
- /// Thrown if the EXIF profile size exceeds the limit
- ///
private void WriteExifProfile(ExifProfile exifProfile)
{
if (exifProfile is null || exifProfile.Values.Count == 0)
@@ -697,16 +696,68 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
}
}
+ ///
+ /// Writes the IPTC metadata.
+ ///
+ /// The iptc metadata to write.
+ ///
+ /// Thrown if the IPTC profile size exceeds the limit of 65533 bytes.
+ ///
+ private void WriteIptcProfile(IptcProfile iptcProfile)
+ {
+ const int Max = 65533;
+ if (iptcProfile is null || !iptcProfile.Values.Any())
+ {
+ return;
+ }
+
+ iptcProfile.UpdateData();
+ byte[] data = iptcProfile.Data;
+ if (data.Length == 0)
+ {
+ return;
+ }
+
+ if (data.Length > Max)
+ {
+ throw new ImageFormatException($"Iptc profile size exceeds limit of {Max} bytes");
+ }
+
+ var app13Length = 2 + ProfileResolver.AdobePhotoshopApp13Marker.Length +
+ ProfileResolver.AdobeImageResourceBlockMarker.Length +
+ ProfileResolver.AdobeIptcMarker.Length +
+ 2 + 4 + data.Length;
+ this.WriteAppHeader(app13Length, JpegConstants.Markers.APP13);
+ this.outputStream.Write(ProfileResolver.AdobePhotoshopApp13Marker);
+ this.outputStream.Write(ProfileResolver.AdobeImageResourceBlockMarker);
+ this.outputStream.Write(ProfileResolver.AdobeIptcMarker);
+ this.outputStream.WriteByte(0); // a empty pascal string (padded to make size even)
+ this.outputStream.WriteByte(0);
+ BinaryPrimitives.WriteInt32BigEndian(this.buffer, data.Length);
+ this.outputStream.Write(this.buffer, 0, 4);
+ this.outputStream.Write(data, 0, data.Length);
+ }
+
///
/// Writes the App1 header.
///
- /// The length of the data the app1 marker contains
+ /// The length of the data the app1 marker contains.
private void WriteApp1Header(int app1Length)
+ {
+ this.WriteAppHeader(app1Length, JpegConstants.Markers.APP1);
+ }
+
+ ///
+ /// Writes a AppX header.
+ ///
+ /// The length of the data the app marker contains.
+ /// The app marker to write.
+ private void WriteAppHeader(int length, byte appMarker)
{
this.buffer[0] = JpegConstants.Markers.XFF;
- this.buffer[1] = JpegConstants.Markers.APP1; // Application Marker
- this.buffer[2] = (byte)((app1Length >> 8) & 0xFF);
- this.buffer[3] = (byte)(app1Length & 0xFF);
+ this.buffer[1] = appMarker;
+ this.buffer[2] = (byte)((length >> 8) & 0xFF);
+ this.buffer[3] = (byte)(length & 0xFF);
this.outputStream.Write(this.buffer, 0, 4);
}
@@ -805,6 +856,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
metadata.SyncProfiles();
this.WriteExifProfile(metadata.ExifProfile);
this.WriteIccProfile(metadata.IccProfile);
+ this.WriteIptcProfile(metadata.IptcProfile);
}
///
diff --git a/src/ImageSharp/Formats/Jpeg/JpegFormat.cs b/src/ImageSharp/Formats/Jpeg/JpegFormat.cs
index f56072a4b..4d9899f7a 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegFormat.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegFormat.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs b/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs
index 7594f4477..c3b938348 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Formats/Jpeg/JpegMetadata.cs b/src/ImageSharp/Formats/Jpeg/JpegMetadata.cs
index 9f0deae02..85506c170 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegMetadata.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegMetadata.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Jpeg
{
diff --git a/src/ImageSharp/Formats/Jpeg/JpegSubsample.cs b/src/ImageSharp/Formats/Jpeg/JpegSubsample.cs
index 855815705..71aa0ca22 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegSubsample.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegSubsample.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Jpeg
{
diff --git a/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs b/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs
index 7e8384dcf..2850fd968 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs
@@ -1,6 +1,7 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+using System;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Formats.Jpeg
@@ -8,25 +9,42 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
internal static class JpegThrowHelper
{
///
- /// Cold path optimization for throwing 's.
+ /// Cold path optimization for throwing 's.
///
/// The error message for the exception.
[MethodImpl(InliningOptions.ColdPath)]
- public static void ThrowImageFormatException(string errorMessage) => throw new ImageFormatException(errorMessage);
+ public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);
+
+ ///
+ /// Cold path optimization for throwing 's.
+ ///
+ /// The error message for the exception.
+ /// The exception that is the cause of the current exception, or a null reference
+ /// if no inner exception is specified.
+ [MethodImpl(InliningOptions.ColdPath)]
+ public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException) => throw new InvalidImageContentException(errorMessage, innerException);
+
+ ///
+ /// Cold path optimization for throwing 's
+ ///
+ /// The error message for the exception.
+ [MethodImpl(InliningOptions.ColdPath)]
+ public static void ThrowNotImplementedException(string errorMessage)
+ => throw new NotImplementedException(errorMessage);
[MethodImpl(InliningOptions.ColdPath)]
- public static void ThrowBadMarker(string marker, int length) => throw new ImageFormatException($"Marker {marker} has bad length {length}.");
+ public static void ThrowBadMarker(string marker, int length) => throw new InvalidImageContentException($"Marker {marker} has bad length {length}.");
[MethodImpl(InliningOptions.ColdPath)]
- public static void ThrowBadQuantizationTable() => throw new ImageFormatException("Bad Quantization Table index.");
+ public static void ThrowBadQuantizationTable() => throw new InvalidImageContentException("Bad Quantization Table index.");
[MethodImpl(InliningOptions.ColdPath)]
- public static void ThrowBadSampling() => throw new ImageFormatException("Bad sampling factor.");
+ public static void ThrowBadSampling() => throw new InvalidImageContentException("Bad sampling factor.");
[MethodImpl(InliningOptions.ColdPath)]
- public static void ThrowBadProgressiveScan(int ss, int se, int ah, int al) => throw new ImageFormatException($"Invalid progressive parameters Ss={ss} Se={se} Ah={ah} Al={al}.");
+ public static void ThrowBadProgressiveScan(int ss, int se, int ah, int al) => throw new InvalidImageContentException($"Invalid progressive parameters Ss={ss} Se={se} Ah={ah} Al={al}.");
[MethodImpl(InliningOptions.ColdPath)]
- public static void ThrowInvalidImageDimensions(int width, int height) => throw new ImageFormatException($"Invalid image dimensions: {width}x{height}.");
+ public static void ThrowInvalidImageDimensions(int width, int height) => throw new InvalidImageContentException($"Invalid image dimensions: {width}x{height}.");
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Formats/Jpeg/MetadataExtensions.cs b/src/ImageSharp/Formats/Jpeg/MetadataExtensions.cs
index 53a9d2a35..79383902c 100644
--- a/src/ImageSharp/Formats/Jpeg/MetadataExtensions.cs
+++ b/src/ImageSharp/Formats/Jpeg/MetadataExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Formats/PixelTypeInfo.cs b/src/ImageSharp/Formats/PixelTypeInfo.cs
index 1683519c2..67d19d756 100644
--- a/src/ImageSharp/Formats/PixelTypeInfo.cs
+++ b/src/ImageSharp/Formats/PixelTypeInfo.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/Adam7.cs b/src/ImageSharp/Formats/Png/Adam7.cs
index b392332d7..4290e2ca0 100644
--- a/src/ImageSharp/Formats/Png/Adam7.cs
+++ b/src/ImageSharp/Formats/Png/Adam7.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/Chunks/PhysicalChunkData.cs b/src/ImageSharp/Formats/Png/Chunks/PhysicalChunkData.cs
index 8b3c3e9aa..f26f4262a 100644
--- a/src/ImageSharp/Formats/Png/Chunks/PhysicalChunkData.cs
+++ b/src/ImageSharp/Formats/Png/Chunks/PhysicalChunkData.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
index bc5a54e8b..238e1934e 100644
--- a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/Filters/FilterType.cs b/src/ImageSharp/Formats/Png/Filters/FilterType.cs
index 83a005380..613288c63 100644
--- a/src/ImageSharp/Formats/Png/Filters/FilterType.cs
+++ b/src/ImageSharp/Formats/Png/Filters/FilterType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Png.Filters
{
diff --git a/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs b/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs
index 97e16ef23..0d1122a3a 100644
--- a/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
index 4cd61e043..69b9c85af 100644
--- a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs
index e6fc1b6ae..85bbd90ea 100644
--- a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs
index 5d9dc6a89..2f0e0dc19 100644
--- a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs b/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs
index e3036d4bd..27ef8cc5a 100644
--- a/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs
+++ b/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Png
{
diff --git a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
index 87fd2582a..66117371e 100644
--- a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Quantization;
@@ -28,9 +28,9 @@ namespace SixLabors.ImageSharp.Formats.Png
///
/// Gets the compression level 1-9.
- /// Defaults to 6.
+ /// Defaults to .
///
- int CompressionLevel { get; }
+ PngCompressionLevel CompressionLevel { get; }
///
/// Gets the threshold of characters in text metadata, when compression should be used.
@@ -57,5 +57,22 @@ namespace SixLabors.ImageSharp.Formats.Png
/// Gets a value indicating whether this instance should write an Adam7 interlaced image.
///
PngInterlaceMode? InterlaceMethod { get; }
+
+ ///
+ /// Gets a value indicating whether the metadata should be ignored when the image is being encoded.
+ /// When set to true, all ancillary chunks will be skipped.
+ ///
+ bool IgnoreMetadata { get; }
+
+ ///
+ /// Gets the chunk filter method. This allows to filter ancillary chunks.
+ ///
+ PngChunkFilter? ChunkFilter { get; }
+
+ ///
+ /// Gets a value indicating whether fully transparent pixels that may contain R, G, B values which are not 0,
+ /// should be converted to transparent black, which can yield in better compression in some cases.
+ ///
+ PngTransparentColorMode TransparentColorMode { get; }
}
}
diff --git a/src/ImageSharp/Formats/Png/ImageExtensions.cs b/src/ImageSharp/Formats/Png/ImageExtensions.cs
index af56830f4..bdbddd0c6 100644
--- a/src/ImageSharp/Formats/Png/ImageExtensions.cs
+++ b/src/ImageSharp/Formats/Png/ImageExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
diff --git a/src/ImageSharp/Formats/Png/MetadataExtensions.cs b/src/ImageSharp/Formats/Png/MetadataExtensions.cs
index 762a6c40c..24274531c 100644
--- a/src/ImageSharp/Formats/Png/MetadataExtensions.cs
+++ b/src/ImageSharp/Formats/Png/MetadataExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Formats/Png/PngBitDepth.cs b/src/ImageSharp/Formats/Png/PngBitDepth.cs
index 0321b532a..1af76e746 100644
--- a/src/ImageSharp/Formats/Png/PngBitDepth.cs
+++ b/src/ImageSharp/Formats/Png/PngBitDepth.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
// Note the value assignment, This will allow us to add 1, 2, and 4 bit encoding when we support it.
namespace SixLabors.ImageSharp.Formats.Png
diff --git a/src/ImageSharp/Formats/Png/PngChunk.cs b/src/ImageSharp/Formats/Png/PngChunk.cs
index 7d8498ab7..1d0337f4f 100644
--- a/src/ImageSharp/Formats/Png/PngChunk.cs
+++ b/src/ImageSharp/Formats/Png/PngChunk.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Memory;
diff --git a/src/ImageSharp/Formats/Png/PngChunkFilter.cs b/src/ImageSharp/Formats/Png/PngChunkFilter.cs
new file mode 100644
index 000000000..4e8b5ab96
--- /dev/null
+++ b/src/ImageSharp/Formats/Png/PngChunkFilter.cs
@@ -0,0 +1,44 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using System;
+
+namespace SixLabors.ImageSharp.Formats.Png
+{
+ ///
+ /// Provides enumeration of available PNG optimization methods.
+ ///
+ [Flags]
+ public enum PngChunkFilter
+ {
+ ///
+ /// With the None filter, all chunks will be written.
+ ///
+ None = 0,
+
+ ///
+ /// Excludes the physical dimension information chunk from encoding.
+ ///
+ ExcludePhysicalChunk = 1 << 0,
+
+ ///
+ /// Excludes the gamma information chunk from encoding.
+ ///
+ ExcludeGammaChunk = 1 << 1,
+
+ ///
+ /// Excludes the eXIf chunk from encoding.
+ ///
+ ExcludeExifChunk = 1 << 2,
+
+ ///
+ /// Excludes the tTXt, iTXt or zTXt chunk from encoding.
+ ///
+ ExcludeTextChunks = 1 << 3,
+
+ ///
+ /// All ancillary chunks will be excluded.
+ ///
+ ExcludeAll = ~None
+ }
+}
diff --git a/src/ImageSharp/Formats/Png/PngChunkType.cs b/src/ImageSharp/Formats/Png/PngChunkType.cs
index e41b49066..2dd9cc8b5 100644
--- a/src/ImageSharp/Formats/Png/PngChunkType.cs
+++ b/src/ImageSharp/Formats/Png/PngChunkType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Png
{
@@ -73,6 +73,58 @@ namespace SixLabors.ImageSharp.Formats.Png
/// either alpha values associated with palette entries (for indexed-color images)
/// or a single transparent color (for grayscale and true color images).
///
- Transparency = 0x74524E53U
+ Transparency = 0x74524E53U,
+
+ ///
+ /// The tIME chunk gives the time of the last image modification (not the time of initial image creation).
+ ///
+ Time = 0x74494d45,
+
+ ///
+ /// The bKGD chunk specifies a default background colour to present the image against.
+ /// If there is any other preferred background, either user-specified or part of a larger page (as in a browser),
+ /// the bKGD chunk should be ignored.
+ ///
+ Background = 0x624b4744,
+
+ ///
+ /// The iCCP chunk contains a embedded color profile. If the iCCP chunk is present,
+ /// the image samples conform to the colour space represented by the embedded ICC profile as defined by the International Color Consortium.
+ ///
+ EmbeddedColorProfile = 0x69434350,
+
+ ///
+ /// The sBIT chunk defines the original number of significant bits (which can be less than or equal to the sample depth).
+ /// This allows PNG decoders to recover the original data losslessly even if the data had a sample depth not directly supported by PNG.
+ ///
+ SignificantBits = 0x73424954,
+
+ ///
+ /// If the sRGB chunk is present, the image samples conform to the sRGB colour space [IEC 61966-2-1] and should be displayed
+ /// using the specified rendering intent defined by the International Color Consortium.
+ ///
+ StandardRgbColourSpace = 0x73524742,
+
+ ///
+ /// The hIST chunk gives the approximate usage frequency of each colour in the palette.
+ ///
+ Histogram = 0x68495354,
+
+ ///
+ /// The sPLT chunk contains the suggested palette.
+ ///
+ SuggestedPalette = 0x73504c54,
+
+ ///
+ /// The cHRM chunk may be used to specify the 1931 CIE x,y chromaticities of the red,
+ /// green, and blue display primaries used in the image, and the referenced white point.
+ ///
+ Chroma = 0x6348524d,
+
+ ///
+ /// Malformed chunk named CgBI produced by apple, which is not conform to the specification.
+ /// Related issue is here https://github.com/SixLabors/ImageSharp/issues/410
+ ///
+ ProprietaryApple = 0x43674249
}
}
diff --git a/src/ImageSharp/Formats/Png/PngColorType.cs b/src/ImageSharp/Formats/Png/PngColorType.cs
index fc376ca16..59a6de335 100644
--- a/src/ImageSharp/Formats/Png/PngColorType.cs
+++ b/src/ImageSharp/Formats/Png/PngColorType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Png
{
diff --git a/src/ImageSharp/Formats/Png/PngCompressionLevel.cs b/src/ImageSharp/Formats/Png/PngCompressionLevel.cs
new file mode 100644
index 000000000..74c967544
--- /dev/null
+++ b/src/ImageSharp/Formats/Png/PngCompressionLevel.cs
@@ -0,0 +1,81 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+namespace SixLabors.ImageSharp.Formats.Png
+{
+ ///
+ /// Provides enumeration of available PNG compression levels.
+ ///
+ public enum PngCompressionLevel
+ {
+ ///
+ /// Level 0. Equivalent to .
+ ///
+ Level0 = 0,
+
+ ///
+ /// No compression. Equivalent to .
+ ///
+ NoCompression = Level0,
+
+ ///
+ /// Level 1. Equivalent to .
+ ///
+ Level1 = 1,
+
+ ///
+ /// Best speed compression level.
+ ///
+ BestSpeed = Level1,
+
+ ///
+ /// Level 2.
+ ///
+ Level2 = 2,
+
+ ///
+ /// Level 3.
+ ///
+ Level3 = 3,
+
+ ///
+ /// Level 4.
+ ///
+ Level4 = 4,
+
+ ///
+ /// Level 5.
+ ///
+ Level5 = 5,
+
+ ///
+ /// Level 6. Equivalent to .
+ ///
+ Level6 = 6,
+
+ ///
+ /// The default compression level. Equivalent to .
+ ///
+ DefaultCompression = Level6,
+
+ ///
+ /// Level 7.
+ ///
+ Level7 = 7,
+
+ ///
+ /// Level 8.
+ ///
+ Level8 = 8,
+
+ ///
+ /// Level 9. Equivalent to .
+ ///
+ Level9 = 9,
+
+ ///
+ /// Best compression level. Equivalent to .
+ ///
+ BestCompression = Level9,
+ }
+}
diff --git a/src/ImageSharp/Formats/Png/PngConfigurationModule.cs b/src/ImageSharp/Formats/Png/PngConfigurationModule.cs
index 3c9fddbad..3acbfd87a 100644
--- a/src/ImageSharp/Formats/Png/PngConfigurationModule.cs
+++ b/src/ImageSharp/Formats/Png/PngConfigurationModule.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Png
{
diff --git a/src/ImageSharp/Formats/Png/PngConstants.cs b/src/ImageSharp/Formats/Png/PngConstants.cs
index 247bb3c75..60f38dda8 100644
--- a/src/ImageSharp/Formats/Png/PngConstants.cs
+++ b/src/ImageSharp/Formats/Png/PngConstants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Png/PngDecoder.cs b/src/ImageSharp/Formats/Png/PngDecoder.cs
index d605577e7..b2e243997 100644
--- a/src/ImageSharp/Formats/Png/PngDecoder.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
using SixLabors.ImageSharp.Memory;
@@ -54,9 +54,10 @@ namespace SixLabors.ImageSharp.Formats.Png
{
Size dims = decoder.Dimensions;
- // TODO: use InvalidImageContentException here, if we decide to define it
- // https://github.com/SixLabors/ImageSharp/issues/1110
- throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
+ PngThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
+
+ // Not reachable, as the previous statement will throw a exception.
+ return null;
}
}
diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
index 4d7de4161..b6943e5ac 100644
--- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers.Binary;
@@ -9,7 +9,7 @@ using System.IO.Compression;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
-using SixLabors.ImageSharp.Advanced;
+
using SixLabors.ImageSharp.Formats.Png.Chunks;
using SixLabors.ImageSharp.Formats.Png.Filters;
using SixLabors.ImageSharp.Formats.Png.Zlib;
@@ -30,11 +30,6 @@ namespace SixLabors.ImageSharp.Formats.Png
///
private readonly byte[] buffer = new byte[4];
- ///
- /// Reusable CRC for validating chunks.
- ///
- private readonly Crc32 crc = new Crc32();
-
///
/// The global configuration.
///
@@ -215,6 +210,9 @@ namespace SixLabors.ImageSharp.Formats.Png
case PngChunkType.End:
this.isEndChunkReached = true;
break;
+ case PngChunkType.ProprietaryApple:
+ PngThrowHelper.ThrowInvalidChunkType("Proprietary Apple PNG detected! This PNG file is not conform to the specification and cannot be decoded.");
+ break;
}
}
finally
@@ -269,6 +267,21 @@ namespace SixLabors.ImageSharp.Formats.Png
break;
case PngChunkType.Text:
this.ReadTextChunk(pngMetadata, chunk.Data.Array.AsSpan(0, chunk.Length));
+ break;
+ case PngChunkType.CompressedText:
+ this.ReadCompressedTextChunk(pngMetadata, chunk.Data.Array.AsSpan(0, chunk.Length));
+ break;
+ case PngChunkType.InternationalText:
+ this.ReadInternationalTextChunk(pngMetadata, chunk.Data.Array.AsSpan(0, chunk.Length));
+ break;
+ case PngChunkType.Exif:
+ if (!this.ignoreMetadata)
+ {
+ var exifData = new byte[chunk.Length];
+ Buffer.BlockCopy(chunk.Data.Array, 0, exifData, 0, chunk.Length);
+ metadata.ExifProfile = new ExifProfile(exifData);
+ }
+
break;
case PngChunkType.End:
this.isEndChunkReached = true;
@@ -380,7 +393,12 @@ namespace SixLabors.ImageSharp.Formats.Png
private void InitializeImage(ImageMetadata metadata, out Image image)
where TPixel : unmanaged, IPixel
{
- image = new Image(this.configuration, this.header.Width, this.header.Height, metadata);
+ image = Image.CreateUninitialized(
+ this.configuration,
+ this.header.Width,
+ this.header.Height,
+ metadata);
+
this.bytesPerPixel = this.CalculateBytesPerPixel();
this.bytesPerScanline = this.CalculateScanlineLength(this.header.Width) + 1;
this.bytesPerSample = 1;
@@ -1034,7 +1052,7 @@ namespace SixLabors.ImageSharp.Formats.Png
var uncompressedBytes = new List();
- // Note: this uses the a buffer which is only 4 bytes long to read the stream, maybe allocating a larger buffer makes sense here.
+ // Note: this uses a buffer which is only 4 bytes long to read the stream, maybe allocating a larger buffer makes sense here.
int bytesRead = inflateStream.CompressedStream.Read(this.buffer, 0, this.buffer.Length);
while (bytesRead != 0)
{
@@ -1136,24 +1154,21 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The .
private void ValidateChunk(in PngChunk chunk)
{
- if (!chunk.IsCritical)
- {
- return;
- }
+ uint inputCrc = this.ReadChunkCrc();
- Span chunkType = stackalloc byte[4];
-
- BinaryPrimitives.WriteUInt32BigEndian(chunkType, (uint)chunk.Type);
+ if (chunk.IsCritical)
+ {
+ Span chunkType = stackalloc byte[4];
+ BinaryPrimitives.WriteUInt32BigEndian(chunkType, (uint)chunk.Type);
- this.crc.Reset();
- this.crc.Update(chunkType);
- this.crc.Update(chunk.Data.GetSpan());
+ uint validCrc = Crc32.Calculate(chunkType);
+ validCrc = Crc32.Calculate(validCrc, chunk.Data.GetSpan());
- uint crc = this.ReadChunkCrc();
- if (this.crc.Value != crc)
- {
- string chunkTypeName = Encoding.ASCII.GetString(chunkType);
- PngThrowHelper.ThrowInvalidChunkCrc(chunkTypeName);
+ if (validCrc != inputCrc)
+ {
+ string chunkTypeName = Encoding.ASCII.GetString(chunkType);
+ PngThrowHelper.ThrowInvalidChunkCrc(chunkTypeName);
+ }
}
}
diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs
index e654036a8..9b1fc80e0 100644
--- a/src/ImageSharp/Formats/Png/PngEncoder.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
using SixLabors.ImageSharp.Advanced;
@@ -13,55 +13,42 @@ namespace SixLabors.ImageSharp.Formats.Png
///
public sealed class PngEncoder : IImageEncoder, IPngEncoderOptions
{
- ///
- /// Gets or sets the number of bits per sample or per palette index (not per pixel).
- /// Not all values are allowed for all values.
- ///
+ ///
public PngBitDepth? BitDepth { get; set; }
- ///
- /// Gets or sets the color type.
- ///
+ ///
public PngColorType? ColorType { get; set; }
- ///
- /// Gets or sets the filter method.
- ///
+ ///
public PngFilterMethod? FilterMethod { get; set; }
- ///
- /// Gets or sets the compression level 1-9.
- /// Defaults to 6.
- ///
- public int CompressionLevel { get; set; } = 6;
+ ///
+ public PngCompressionLevel CompressionLevel { get; set; } = PngCompressionLevel.DefaultCompression;
- ///
- /// Gets or sets the threshold of characters in text metadata, when compression should be used.
- /// Defaults to 1024.
- ///
+ ///
public int TextCompressionThreshold { get; set; } = 1024;
- ///
- /// Gets or sets the gamma value, that will be written the image.
- ///
+ ///
public float? Gamma { get; set; }
- ///
- /// Gets or sets quantizer for reducing the color count.
- /// Defaults to the .
- ///
+ ///
public IQuantizer Quantizer { get; set; }
- ///
- /// Gets or sets the transparency threshold.
- ///
+ ///
public byte Threshold { get; set; } = byte.MaxValue;
- ///
- /// Gets or sets a value indicating whether this instance should write an Adam7 interlaced image.
- ///
+ ///
public PngInterlaceMode? InterlaceMethod { get; set; }
+ ///
+ public PngChunkFilter? ChunkFilter { get; set; }
+
+ ///
+ public bool IgnoreMetadata { get; set; }
+
+ ///
+ public PngTransparentColorMode TransparentColorMode { get; set; }
+
///
/// Encodes the image to the specified stream from the .
///
diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
index 73833e82b..a25f51fe1 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
@@ -1,22 +1,19 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
using System.Buffers.Binary;
using System.IO;
-using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Png.Chunks;
using SixLabors.ImageSharp.Formats.Png.Filters;
using SixLabors.ImageSharp.Formats.Png.Zlib;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.ImageSharp.Processing.Processors.Quantization;
namespace SixLabors.ImageSharp.Formats.Png
{
@@ -50,11 +47,6 @@ namespace SixLabors.ImageSharp.Formats.Png
///
private readonly byte[] chunkDataBuffer = new byte[16];
- ///
- /// Reusable CRC for validating chunks.
- ///
- private readonly Crc32 crc = new Crc32();
-
///
/// The encoder options
///
@@ -144,25 +136,35 @@ namespace SixLabors.ImageSharp.Formats.Png
this.height = image.Height;
ImageMetadata metadata = image.Metadata;
- PngMetadata pngMetadata = metadata.GetPngMetadata();
+
+ PngMetadata pngMetadata = metadata.GetFormatMetadata(PngFormat.Instance);
PngEncoderOptionsHelpers.AdjustOptions(this.options, pngMetadata, out this.use16Bit, out this.bytesPerPixel);
- QuantizedFrame quantized = PngEncoderOptionsHelpers.CreateQuantizedFrame(this.options, image);
- this.bitDepth = PngEncoderOptionsHelpers.CalculateBitDepth(this.options, image, quantized);
+ Image clonedImage = null;
+ bool clearTransparency = this.options.TransparentColorMode == PngTransparentColorMode.Clear;
+ if (clearTransparency)
+ {
+ clonedImage = image.Clone();
+ ClearTransparentPixels(clonedImage);
+ }
+
+ IndexedImageFrame quantized = this.CreateQuantizedImage(image, clonedImage);
stream.Write(PngConstants.HeaderBytes);
this.WriteHeaderChunk(stream);
+ this.WriteGammaChunk(stream);
this.WritePaletteChunk(stream, quantized);
this.WriteTransparencyChunk(stream, pngMetadata);
this.WritePhysicalChunk(stream, metadata);
- this.WriteGammaChunk(stream);
this.WriteExifChunk(stream, metadata);
this.WriteTextChunks(stream, pngMetadata);
- this.WriteDataChunks(image.Frames.RootFrame, quantized, stream);
+ this.WriteDataChunks(clearTransparency ? clonedImage : image, quantized, stream);
this.WriteEndChunk(stream);
+
stream.Flush();
quantized?.Dispose();
+ clonedImage?.Dispose();
}
///
@@ -183,6 +185,55 @@ namespace SixLabors.ImageSharp.Formats.Png
this.filterBuffer = null;
}
+ ///
+ /// Convert transparent pixels, to transparent black pixels, which can yield to better compression in some cases.
+ ///
+ /// The type of the pixel.
+ /// The cloned image where the transparent pixels will be changed.
+ private static void ClearTransparentPixels(Image image)
+ where TPixel : unmanaged, IPixel
+ {
+ Rgba32 rgba32 = default;
+ for (int y = 0; y < image.Height; y++)
+ {
+ Span span = image.GetPixelRowSpan(y);
+ for (int x = 0; x < image.Width; x++)
+ {
+ span[x].ToRgba32(ref rgba32);
+
+ if (rgba32.A == 0)
+ {
+ span[x].FromRgba32(Color.Transparent);
+ }
+ }
+ }
+ }
+
+ ///
+ /// Creates the quantized image and sets calculates and sets the bit depth.
+ ///
+ /// The type of the pixel.
+ /// The image to quantize.
+ /// Cloned image with transparent pixels are changed to black.
+ /// The quantized image.
+ private IndexedImageFrame CreateQuantizedImage(Image image, Image clonedImage)
+ where TPixel : unmanaged, IPixel
+ {
+ IndexedImageFrame quantized;
+ if (this.options.TransparentColorMode == PngTransparentColorMode.Clear)
+ {
+ quantized = PngEncoderOptionsHelpers.CreateQuantizedFrame(this.options, clonedImage);
+ this.bitDepth = PngEncoderOptionsHelpers.CalculateBitDepth(this.options, quantized);
+ }
+ else
+ {
+ quantized = PngEncoderOptionsHelpers.CreateQuantizedFrame(this.options, image);
+ this.bitDepth = PngEncoderOptionsHelpers.CalculateBitDepth(this.options, quantized);
+ }
+
+ return quantized;
+ }
+
/// Collects a row of grayscale pixels.
/// The pixel format.
/// The image row span.
@@ -371,7 +422,7 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The row span.
/// The quantized pixels. Can be null.
/// The row.
- private void CollectPixelBytes(ReadOnlySpan rowSpan, QuantizedFrame quantized, int row)
+ private void CollectPixelBytes(ReadOnlySpan rowSpan, IndexedImageFrame quantized, int row)
where TPixel : unmanaged, IPixel
{
switch (this.options.ColorType)
@@ -380,12 +431,11 @@ namespace SixLabors.ImageSharp.Formats.Png
if (this.bitDepth < 8)
{
- PngEncoderHelpers.ScaleDownFrom8BitArray(quantized.GetRowSpan(row), this.currentScanline.GetSpan(), this.bitDepth);
+ PngEncoderHelpers.ScaleDownFrom8BitArray(quantized.GetPixelRowSpan(row), this.currentScanline.GetSpan(), this.bitDepth);
}
else
{
- int stride = this.currentScanline.Length();
- quantized.GetPixelSpan().Slice(row * stride, stride).CopyTo(this.currentScanline.GetSpan());
+ quantized.GetPixelRowSpan(row).CopyTo(this.currentScanline.GetSpan());
}
break;
@@ -440,7 +490,7 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The quantized pixels. Can be null.
/// The row.
/// The
- private IManagedByteBuffer EncodePixelRow(ReadOnlySpan rowSpan, QuantizedFrame quantized, int row)
+ private IManagedByteBuffer EncodePixelRow(ReadOnlySpan rowSpan, IndexedImageFrame quantized, int row)
where TPixel : unmanaged, IPixel
{
this.CollectPixelBytes(rowSpan, quantized, row);
@@ -542,73 +592,75 @@ namespace SixLabors.ImageSharp.Formats.Png
///
/// Writes the palette chunk to the stream.
+ /// Should be written before the first IDAT chunk.
///
/// The pixel format.
/// The containing image data.
/// The quantized frame.
- private void WritePaletteChunk(Stream stream, QuantizedFrame quantized)
+ private void WritePaletteChunk(Stream stream, IndexedImageFrame quantized)
where TPixel : unmanaged, IPixel
{
- if (quantized == null)
+ if (quantized is null)
{
return;
}
// Grab the palette and write it to the stream.
ReadOnlySpan palette = quantized.Palette.Span;
- int paletteLength = Math.Min(palette.Length, 256);
- int colorTableLength = paletteLength * 3;
- bool anyAlpha = false;
+ int paletteLength = palette.Length;
+ int colorTableLength = paletteLength * Unsafe.SizeOf();
+ bool hasAlpha = false;
- using (IManagedByteBuffer colorTable = this.memoryAllocator.AllocateManagedByteBuffer(colorTableLength))
- using (IManagedByteBuffer alphaTable = this.memoryAllocator.AllocateManagedByteBuffer(paletteLength))
- {
- ref byte colorTableRef = ref MemoryMarshal.GetReference(colorTable.GetSpan());
- ref byte alphaTableRef = ref MemoryMarshal.GetReference(alphaTable.GetSpan());
- ReadOnlySpan quantizedSpan = quantized.GetPixelSpan();
+ using IManagedByteBuffer colorTable = this.memoryAllocator.AllocateManagedByteBuffer(colorTableLength);
+ using IManagedByteBuffer alphaTable = this.memoryAllocator.AllocateManagedByteBuffer(paletteLength);
- Rgba32 rgba = default;
+ ref Rgb24 colorTableRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(colorTable.GetSpan()));
+ ref byte alphaTableRef = ref MemoryMarshal.GetReference(alphaTable.GetSpan());
- for (int i = 0; i < paletteLength; i++)
- {
- if (quantizedSpan.IndexOf((byte)i) > -1)
- {
- int offset = i * 3;
- palette[i].ToRgba32(ref rgba);
-
- byte alpha = rgba.A;
+ // Bulk convert our palette to RGBA to allow assignment to tables.
+ using IMemoryOwner rgbaOwner = quantized.Configuration.MemoryAllocator.Allocate(paletteLength);
+ Span rgbaPaletteSpan = rgbaOwner.GetSpan();
+ PixelOperations.Instance.ToRgba32(quantized.Configuration, quantized.Palette.Span, rgbaPaletteSpan);
+ ref Rgba32 rgbaPaletteRef = ref MemoryMarshal.GetReference(rgbaPaletteSpan);
- Unsafe.Add(ref colorTableRef, offset) = rgba.R;
- Unsafe.Add(ref colorTableRef, offset + 1) = rgba.G;
- Unsafe.Add(ref colorTableRef, offset + 2) = rgba.B;
-
- if (alpha > this.options.Threshold)
- {
- alpha = byte.MaxValue;
- }
+ // Loop, assign, and extract alpha values from the palette.
+ for (int i = 0; i < paletteLength; i++)
+ {
+ Rgba32 rgba = Unsafe.Add(ref rgbaPaletteRef, i);
+ byte alpha = rgba.A;
- anyAlpha = anyAlpha || alpha < byte.MaxValue;
- Unsafe.Add(ref alphaTableRef, i) = alpha;
- }
+ Unsafe.Add(ref colorTableRef, i) = rgba.Rgb;
+ if (alpha > this.options.Threshold)
+ {
+ alpha = byte.MaxValue;
}
- this.WriteChunk(stream, PngChunkType.Palette, colorTable.Array, 0, colorTableLength);
+ hasAlpha = hasAlpha || alpha < byte.MaxValue;
+ Unsafe.Add(ref alphaTableRef, i) = alpha;
+ }
- // Write the transparency data
- if (anyAlpha)
- {
- this.WriteChunk(stream, PngChunkType.Transparency, alphaTable.Array, 0, paletteLength);
- }
+ this.WriteChunk(stream, PngChunkType.Palette, colorTable.Array, 0, colorTableLength);
+
+ // Write the transparency data
+ if (hasAlpha)
+ {
+ this.WriteChunk(stream, PngChunkType.Transparency, alphaTable.Array, 0, paletteLength);
}
}
///
/// Writes the physical dimension information to the stream.
+ /// Should be written before IDAT chunk.
///
/// The containing image data.
/// The image metadata.
private void WritePhysicalChunk(Stream stream, ImageMetadata meta)
{
+ if (((this.options.ChunkFilter ?? PngChunkFilter.None) & PngChunkFilter.ExcludePhysicalChunk) == PngChunkFilter.ExcludePhysicalChunk)
+ {
+ return;
+ }
+
PhysicalChunkData.FromMetadata(meta).WriteTo(this.chunkDataBuffer);
this.WriteChunk(stream, PngChunkType.Physical, this.chunkDataBuffer, 0, PhysicalChunkData.Size);
@@ -621,6 +673,11 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The image metadata.
private void WriteExifChunk(Stream stream, ImageMetadata meta)
{
+ if (((this.options.ChunkFilter ?? PngChunkFilter.None) & PngChunkFilter.ExcludeExifChunk) == PngChunkFilter.ExcludeExifChunk)
+ {
+ return;
+ }
+
if (meta.ExifProfile is null || meta.ExifProfile.Values.Count == 0)
{
return;
@@ -638,11 +695,27 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The image metadata.
private void WriteTextChunks(Stream stream, PngMetadata meta)
{
+ if (((this.options.ChunkFilter ?? PngChunkFilter.None) & PngChunkFilter.ExcludeTextChunks) == PngChunkFilter.ExcludeTextChunks)
+ {
+ return;
+ }
+
const int MaxLatinCode = 255;
- foreach (PngTextData textData in meta.TextData)
+ for (int i = 0; i < meta.TextData.Count; i++)
{
- bool hasUnicodeCharacters = textData.Value.Any(c => c > MaxLatinCode);
- if (hasUnicodeCharacters || (!string.IsNullOrWhiteSpace(textData.LanguageTag) || !string.IsNullOrWhiteSpace(textData.TranslatedKeyword)))
+ PngTextData textData = meta.TextData[i];
+ bool hasUnicodeCharacters = false;
+ foreach (var c in textData.Value)
+ {
+ if (c > MaxLatinCode)
+ {
+ hasUnicodeCharacters = true;
+ break;
+ }
+ }
+
+ if (hasUnicodeCharacters || (!string.IsNullOrWhiteSpace(textData.LanguageTag) ||
+ !string.IsNullOrWhiteSpace(textData.TranslatedKeyword)))
{
// Write iTXt chunk.
byte[] keywordBytes = PngConstants.Encoding.GetBytes(textData.Keyword);
@@ -653,7 +726,8 @@ namespace SixLabors.ImageSharp.Formats.Png
byte[] translatedKeyword = PngConstants.TranslatedEncoding.GetBytes(textData.TranslatedKeyword);
byte[] languageTag = PngConstants.LanguageEncoding.GetBytes(textData.LanguageTag);
- Span outputBytes = new byte[keywordBytes.Length + textBytes.Length + translatedKeyword.Length + languageTag.Length + 5];
+ Span outputBytes = new byte[keywordBytes.Length + textBytes.Length +
+ translatedKeyword.Length + languageTag.Length + 5];
keywordBytes.CopyTo(outputBytes);
if (textData.Value.Length > this.options.TextCompressionThreshold)
{
@@ -673,7 +747,8 @@ namespace SixLabors.ImageSharp.Formats.Png
if (textData.Value.Length > this.options.TextCompressionThreshold)
{
// Write zTXt chunk.
- byte[] compressedData = this.GetCompressedTextBytes(PngConstants.Encoding.GetBytes(textData.Value));
+ byte[] compressedData =
+ this.GetCompressedTextBytes(PngConstants.Encoding.GetBytes(textData.Value));
Span outputBytes = new byte[textData.Keyword.Length + compressedData.Length + 2];
PngConstants.Encoding.GetBytes(textData.Keyword).CopyTo(outputBytes);
compressedData.CopyTo(outputBytes.Slice(textData.Keyword.Length + 2));
@@ -684,7 +759,8 @@ namespace SixLabors.ImageSharp.Formats.Png
// Write tEXt chunk.
Span outputBytes = new byte[textData.Keyword.Length + textData.Value.Length + 1];
PngConstants.Encoding.GetBytes(textData.Keyword).CopyTo(outputBytes);
- PngConstants.Encoding.GetBytes(textData.Value).CopyTo(outputBytes.Slice(textData.Keyword.Length + 1));
+ PngConstants.Encoding.GetBytes(textData.Value)
+ .CopyTo(outputBytes.Slice(textData.Keyword.Length + 1));
this.WriteChunk(stream, PngChunkType.Text, outputBytes.ToArray());
}
}
@@ -711,10 +787,16 @@ namespace SixLabors.ImageSharp.Formats.Png
///
/// Writes the gamma information to the stream.
+ /// Should be written before PLTE and IDAT chunk.
///
/// The containing image data.
private void WriteGammaChunk(Stream stream)
{
+ if (((this.options.ChunkFilter ?? PngChunkFilter.None) & PngChunkFilter.ExcludeGammaChunk) == PngChunkFilter.ExcludeGammaChunk)
+ {
+ return;
+ }
+
if (this.options.Gamma > 0)
{
// 4-byte unsigned integer of gamma * 100,000.
@@ -728,6 +810,7 @@ namespace SixLabors.ImageSharp.Formats.Png
///
/// Writes the transparency chunk to the stream.
+ /// Should be written after PLTE and before IDAT.
///
/// The containing image data.
/// The image metadata.
@@ -783,7 +866,7 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The image.
/// The quantized pixel data. Can be null.
/// The stream.
- private void WriteDataChunks(ImageFrame pixels, QuantizedFrame quantized, Stream stream)
+ private void WriteDataChunks(Image pixels, IndexedImageFrame quantized, Stream stream)
where TPixel : unmanaged, IPixel
{
byte[] buffer;
@@ -881,8 +964,8 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The pixels.
/// The quantized pixels span.
/// The deflate stream.
- private void EncodePixels(ImageFrame pixels, QuantizedFrame quantized, ZlibDeflateStream deflateStream)
- where TPixel : unmanaged, IPixel
+ private void EncodePixels(Image pixels, IndexedImageFrame quantized, ZlibDeflateStream deflateStream)
+ where TPixel : unmanaged, IPixel
{
int bytesPerScanline = this.CalculateScanlineLength(this.width);
int resultLength = bytesPerScanline + 1;
@@ -905,7 +988,7 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The type of the pixel.
/// The pixels.
/// The deflate stream.
- private void EncodeAdam7Pixels(ImageFrame pixels, ZlibDeflateStream deflateStream)
+ private void EncodeAdam7Pixels(Image pixels, ZlibDeflateStream deflateStream)
where TPixel : unmanaged, IPixel
{
int width = pixels.Width;
@@ -960,7 +1043,7 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The type of the pixel.
/// The quantized.
/// The deflate stream.
- private void EncodeAdam7IndexedPixels(QuantizedFrame quantized, ZlibDeflateStream deflateStream)
+ private void EncodeAdam7IndexedPixels(IndexedImageFrame quantized, ZlibDeflateStream deflateStream)
where TPixel : unmanaged, IPixel
{
int width = quantized.Width;
@@ -987,7 +1070,7 @@ namespace SixLabors.ImageSharp.Formats.Png
row += Adam7.RowIncrement[pass])
{
// collect data
- ReadOnlySpan srcRow = quantized.GetRowSpan(row);
+ ReadOnlySpan srcRow = quantized.GetPixelRowSpan(row);
for (int col = startCol, i = 0;
col < width;
col += Adam7.ColumnIncrement[pass])
@@ -1032,18 +1115,16 @@ namespace SixLabors.ImageSharp.Formats.Png
stream.Write(this.buffer, 0, 8);
- this.crc.Reset();
-
- this.crc.Update(this.buffer.AsSpan(4, 4)); // Write the type buffer
+ uint crc = Crc32.Calculate(this.buffer.AsSpan(4, 4)); // Write the type buffer
if (data != null && length > 0)
{
stream.Write(data, offset, length);
- this.crc.Update(data.AsSpan(offset, length));
+ crc = Crc32.Calculate(crc, data.AsSpan(offset, length));
}
- BinaryPrimitives.WriteUInt32BigEndian(this.buffer, (uint)this.crc.Value);
+ BinaryPrimitives.WriteUInt32BigEndian(this.buffer, crc);
stream.Write(this.buffer, 0, 4); // write the crc
}
diff --git a/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs b/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs
index 78cd5d874..e54d5864a 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/PngEncoderOptions.cs b/src/ImageSharp/Formats/Png/PngEncoderOptions.cs
index dd6c66cb7..53e6ee30f 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Quantization;
@@ -29,54 +29,45 @@ namespace SixLabors.ImageSharp.Formats.Png
this.Quantizer = source.Quantizer;
this.Threshold = source.Threshold;
this.InterlaceMethod = source.InterlaceMethod;
+ this.ChunkFilter = source.ChunkFilter;
+ this.IgnoreMetadata = source.IgnoreMetadata;
+ this.TransparentColorMode = source.TransparentColorMode;
}
- ///
- /// Gets or sets the number of bits per sample or per palette index (not per pixel).
- /// Not all values are allowed for all values.
- ///
+ ///
public PngBitDepth? BitDepth { get; set; }
- ///
- /// Gets or sets the color type.
- ///
+ ///
public PngColorType? ColorType { get; set; }
- ///
- /// Gets the filter method.
- ///
+ ///
public PngFilterMethod? FilterMethod { get; }
- ///
- /// Gets the compression level 1-9.
- /// Defaults to 6.
- ///
- public int CompressionLevel { get; }
+ ///
+ public PngCompressionLevel CompressionLevel { get; } = PngCompressionLevel.DefaultCompression;
///
public int TextCompressionThreshold { get; }
- ///
- /// Gets or sets the gamma value, that will be written the image.
- ///
- ///
- /// The gamma value of the image.
- ///
+ ///
public float? Gamma { get; set; }
- ///
- /// Gets or sets the quantizer for reducing the color count.
- ///
+ ///
public IQuantizer Quantizer { get; set; }
- ///
- /// Gets the transparency threshold.
- ///
+ ///
public byte Threshold { get; }
- ///
- /// Gets or sets a value indicating whether this instance should write an Adam7 interlaced image.
- ///
+ ///
public PngInterlaceMode? InterlaceMethod { get; set; }
+
+ ///
+ public PngChunkFilter? ChunkFilter { get; set; }
+
+ ///
+ public bool IgnoreMetadata { get; set; }
+
+ ///
+ public PngTransparentColorMode TransparentColorMode { get; set; }
}
}
diff --git a/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs
index 20b8c41c9..d0f708e93 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using SixLabors.ImageSharp.Advanced;
@@ -40,6 +40,11 @@ namespace SixLabors.ImageSharp.Formats.Png
use16Bit = options.BitDepth == PngBitDepth.Bit16;
bytesPerPixel = CalculateBytesPerPixel(options.ColorType, use16Bit);
+ if (options.IgnoreMetadata)
+ {
+ options.ChunkFilter = PngChunkFilter.ExcludeAll;
+ }
+
// Ensure we are not allowing impossible combinations.
if (!PngConstants.ColorTypes.ContainsKey(options.ColorType.Value))
{
@@ -53,7 +58,7 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The type of the pixel.
/// The options.
/// The image.
- public static QuantizedFrame CreateQuantizedFrame(
+ public static IndexedImageFrame CreateQuantizedFrame(
PngEncoderOptions options,
Image image)
where TPixel : unmanaged, IPixel
@@ -77,10 +82,10 @@ namespace SixLabors.ImageSharp.Formats.Png
}
// Create quantized frame returning the palette and set the bit depth.
- using (IFrameQuantizer frameQuantizer = options.Quantizer.CreateFrameQuantizer(image.GetConfiguration()))
+ using (IQuantizer frameQuantizer = options.Quantizer.CreatePixelSpecificQuantizer(image.GetConfiguration()))
{
ImageFrame frame = image.Frames.RootFrame;
- return frameQuantizer.QuantizeFrame(frame, frame.Bounds());
+ return frameQuantizer.BuildPaletteAndQuantizeFrame(frame, frame.Bounds());
}
}
@@ -89,12 +94,10 @@ namespace SixLabors.ImageSharp.Formats.Png
///
/// The type of the pixel.
/// The options.
- /// The image.
/// The quantized frame.
public static byte CalculateBitDepth(
PngEncoderOptions options,
- Image image,
- QuantizedFrame quantizedFrame)
+ IndexedImageFrame quantizedFrame)
where TPixel : unmanaged, IPixel
{
byte bitDepth;
diff --git a/src/ImageSharp/Formats/Png/PngFilterMethod.cs b/src/ImageSharp/Formats/Png/PngFilterMethod.cs
index e16c1234f..aa1899494 100644
--- a/src/ImageSharp/Formats/Png/PngFilterMethod.cs
+++ b/src/ImageSharp/Formats/Png/PngFilterMethod.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Png
{
diff --git a/src/ImageSharp/Formats/Png/PngFormat.cs b/src/ImageSharp/Formats/Png/PngFormat.cs
index 408e37802..a0f493b95 100644
--- a/src/ImageSharp/Formats/Png/PngFormat.cs
+++ b/src/ImageSharp/Formats/Png/PngFormat.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Png/PngHeader.cs b/src/ImageSharp/Formats/Png/PngHeader.cs
index ea43ba96a..3844a15aa 100644
--- a/src/ImageSharp/Formats/Png/PngHeader.cs
+++ b/src/ImageSharp/Formats/Png/PngHeader.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs b/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs
index 5deed86e3..c294aab3f 100644
--- a/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs
+++ b/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Formats/Png/PngInterlaceMode.cs b/src/ImageSharp/Formats/Png/PngInterlaceMode.cs
index e8c2db147..6516b8473 100644
--- a/src/ImageSharp/Formats/Png/PngInterlaceMode.cs
+++ b/src/ImageSharp/Formats/Png/PngInterlaceMode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Png
{
diff --git a/src/ImageSharp/Formats/Png/PngMetadata.cs b/src/ImageSharp/Formats/Png/PngMetadata.cs
index 341fc53ed..d3b34fbd7 100644
--- a/src/ImageSharp/Formats/Png/PngMetadata.cs
+++ b/src/ImageSharp/Formats/Png/PngMetadata.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Collections.Generic;
using SixLabors.ImageSharp.PixelFormats;
@@ -91,34 +91,12 @@ namespace SixLabors.ImageSharp.Formats.Png
public bool HasTransparency { get; set; }
///
- /// Gets or sets the collection of text data stored within the iTXt, tEXt, and zTXt chunks.
+ /// Gets or sets the collection of text data stored within the iTXt, tEXt, and zTXt chunks.
/// Used for conveying textual information associated with the image.
///
public IList TextData { get; set; } = new List();
- ///
- /// Gets the list of png text properties for storing meta information about this image.
- ///
- public IList PngTextProperties { get; } = new List();
-
///
public IDeepCloneable DeepClone() => new PngMetadata(this);
-
- internal bool TryGetPngTextProperty(string keyword, out PngTextData result)
- {
- for (int i = 0; i < this.TextData.Count; i++)
- {
- if (this.TextData[i].Keyword == keyword)
- {
- result = this.TextData[i];
-
- return true;
- }
- }
-
- result = default;
-
- return false;
- }
}
}
diff --git a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
index cf365c8b9..ef3a8034e 100644
--- a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
+++ b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Formats/Png/PngTextData.cs b/src/ImageSharp/Formats/Png/PngTextData.cs
index 21171487e..5b5e4b8ab 100644
--- a/src/ImageSharp/Formats/Png/PngTextData.cs
+++ b/src/ImageSharp/Formats/Png/PngTextData.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Formats/Png/PngThrowHelper.cs b/src/ImageSharp/Formats/Png/PngThrowHelper.cs
index dd3a05464..61e986d06 100644
--- a/src/ImageSharp/Formats/Png/PngThrowHelper.cs
+++ b/src/ImageSharp/Formats/Png/PngThrowHelper.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
@@ -12,21 +12,28 @@ namespace SixLabors.ImageSharp.Formats.Png
internal static class PngThrowHelper
{
[MethodImpl(InliningOptions.ColdPath)]
- public static void ThrowNoHeader() => throw new ImageFormatException("PNG Image does not contain a header chunk");
+ public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException)
+ => throw new InvalidImageContentException(errorMessage, innerException);
[MethodImpl(InliningOptions.ColdPath)]
- public static void ThrowNoData() => throw new ImageFormatException("PNG Image does not contain a data chunk");
+ public static void ThrowNoHeader() => throw new InvalidImageContentException("PNG Image does not contain a header chunk");
[MethodImpl(InliningOptions.ColdPath)]
- public static void ThrowInvalidChunkType() => throw new ImageFormatException("Invalid PNG data.");
+ public static void ThrowNoData() => throw new InvalidImageContentException("PNG Image does not contain a data chunk");
[MethodImpl(InliningOptions.ColdPath)]
- public static void ThrowInvalidChunkCrc(string chunkTypeName) => throw new ImageFormatException($"CRC Error. PNG {chunkTypeName} chunk is corrupt!");
+ public static void ThrowInvalidChunkType() => throw new InvalidImageContentException("Invalid PNG data.");
[MethodImpl(InliningOptions.ColdPath)]
- public static void ThrowNotSupportedColor() => new NotSupportedException("Unsupported PNG color type");
+ public static void ThrowInvalidChunkType(string message) => throw new InvalidImageContentException(message);
[MethodImpl(InliningOptions.ColdPath)]
- public static void ThrowUnknownFilter() => throw new ImageFormatException("Unknown filter type.");
+ public static void ThrowInvalidChunkCrc(string chunkTypeName) => throw new InvalidImageContentException($"CRC Error. PNG {chunkTypeName} chunk is corrupt!");
+
+ [MethodImpl(InliningOptions.ColdPath)]
+ public static void ThrowNotSupportedColor() => throw new NotSupportedException("Unsupported PNG color type");
+
+ [MethodImpl(InliningOptions.ColdPath)]
+ public static void ThrowUnknownFilter() => throw new InvalidImageContentException("Unknown filter type.");
}
}
diff --git a/src/ImageSharp/Formats/Png/PngTransparentColorMode.cs b/src/ImageSharp/Formats/Png/PngTransparentColorMode.cs
new file mode 100644
index 000000000..63967c153
--- /dev/null
+++ b/src/ImageSharp/Formats/Png/PngTransparentColorMode.cs
@@ -0,0 +1,22 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+namespace SixLabors.ImageSharp.Formats.Png
+{
+ ///
+ /// Enum indicating how the transparency should be handled on encoding.
+ ///
+ public enum PngTransparentColorMode
+ {
+ ///
+ /// The transparency will be kept as is.
+ ///
+ Preserve = 0,
+
+ ///
+ /// Converts fully transparent pixels that may contain R, G, B values which are not 0,
+ /// to transparent black, which can yield in better compression in some cases.
+ ///
+ Clear = 1,
+ }
+}
diff --git a/src/ImageSharp/Formats/Png/Zlib/Adler32.cs b/src/ImageSharp/Formats/Png/Zlib/Adler32.cs
index c4dc82a4d..d348e7df1 100644
--- a/src/ImageSharp/Formats/Png/Zlib/Adler32.cs
+++ b/src/ImageSharp/Formats/Png/Zlib/Adler32.cs
@@ -1,148 +1,260 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+#if SUPPORTS_RUNTIME_INTRINSICS
+using System.Runtime.Intrinsics;
+using System.Runtime.Intrinsics.X86;
+#endif
+#pragma warning disable IDE0007 // Use implicit type
namespace SixLabors.ImageSharp.Formats.Png.Zlib
{
///
- /// Computes Adler32 checksum for a stream of data. An Adler32
- /// checksum is not as reliable as a CRC32 checksum, but a lot faster to
- /// compute.
+ /// Calculates the 32 bit Adler checksum of a given buffer according to
+ /// RFC 1950. ZLIB Compressed Data Format Specification version 3.3)
///
- ///
- /// The specification for Adler32 may be found in RFC 1950.
- /// ZLIB Compressed Data Format Specification version 3.3)
- ///
- ///
- /// From that document:
- ///
- /// "ADLER32 (Adler-32 checksum)
- /// This contains a checksum value of the uncompressed data
- /// (excluding any dictionary data) computed according to Adler-32
- /// algorithm. This algorithm is a 32-bit extension and improvement
- /// of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073
- /// standard.
- ///
- /// Adler-32 is composed of two sums accumulated per byte: s1 is
- /// the sum of all bytes, s2 is the sum of all s1 values. Both sums
- /// are done modulo 65521. s1 is initialized to 1, s2 to zero. The
- /// Adler-32 checksum is stored as s2*65536 + s1 in most-
- /// significant-byte first (network) order."
- ///
- /// "8.2. The Adler-32 algorithm
- ///
- /// The Adler-32 algorithm is much faster than the CRC32 algorithm yet
- /// still provides an extremely low probability of undetected errors.
- ///
- /// The modulo on unsigned long accumulators can be delayed for 5552
- /// bytes, so the modulo operation time is negligible. If the bytes
- /// are a, b, c, the second sum is 3a + 2b + c + 3, and so is position
- /// and order sensitive, unlike the first sum, which is just a
- /// checksum. That 65521 is prime is important to avoid a possible
- /// large class of two-byte errors that leave the check unchanged.
- /// (The Fletcher checksum uses 255, which is not prime and which also
- /// makes the Fletcher check insensitive to single byte changes 0 -
- /// 255.)
- ///
- /// The sum s1 is initialized to 1 instead of zero to make the length
- /// of the sequence part of s2, so that the length does not have to be
- /// checked separately. (Any sequence of zeroes has a Fletcher
- /// checksum of zero.)"
- ///
- ///
- ///
- internal sealed class Adler32 : IChecksum
+ internal static class Adler32
{
///
- /// largest prime smaller than 65536
+ /// The default initial seed value of a Adler32 checksum calculation.
///
- private const uint Base = 65521;
+ public const uint SeedValue = 1U;
- ///
- /// The checksum calculated to far.
- ///
- private uint checksum;
+ // Largest prime smaller than 65536
+ private const uint BASE = 65521;
- ///
- /// Initializes a new instance of the class.
- /// The checksum starts off with a value of 1.
- ///
- public Adler32()
- {
- this.Reset();
- }
+ // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
+ private const uint NMAX = 5552;
- ///
- public long Value
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.checksum;
- }
+#if SUPPORTS_RUNTIME_INTRINSICS
+ private const int MinBufferSize = 64;
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Reset()
+ // The C# compiler emits this as a compile-time constant embedded in the PE file.
+ private static ReadOnlySpan Tap1Tap2 => new byte[]
{
- this.checksum = 1;
- }
+ 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, // tap1
+ 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 // tap2
+ };
+#endif
+
+ ///
+ /// Calculates the Adler32 checksum with the bytes taken from the span.
+ ///
+ /// The readonly span of bytes.
+ /// The .
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static uint Calculate(ReadOnlySpan buffer)
+ => Calculate(SeedValue, buffer);
///
- /// Updates the checksum with a byte value.
+ /// Calculates the Adler32 checksum with the bytes taken from the span and seed.
///
- ///
- /// The data value to add. The high byte of the int is ignored.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Update(int value)
+ /// The input Adler32 value.
+ /// The readonly span of bytes.
+ /// The .
+ [MethodImpl(InliningOptions.HotPath | InliningOptions.ShortMethod)]
+ public static uint Calculate(uint adler, ReadOnlySpan buffer)
{
- // We could make a length 1 byte array and call update again, but I
- // would rather not have that overhead
- uint s1 = this.checksum & 0xFFFF;
- uint s2 = this.checksum >> 16;
+ if (buffer.IsEmpty)
+ {
+ return adler;
+ }
- s1 = (s1 + ((uint)value & 0xFF)) % Base;
- s2 = (s1 + s2) % Base;
+#if SUPPORTS_RUNTIME_INTRINSICS
+ if (Sse3.IsSupported && buffer.Length >= MinBufferSize)
+ {
+ return CalculateSse(adler, buffer);
+ }
- this.checksum = (s2 << 16) + s1;
+ return CalculateScalar(adler, buffer);
+#else
+ return CalculateScalar(adler, buffer);
+#endif
}
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Update(ReadOnlySpan data)
+ // Based on https://github.com/chromium/chromium/blob/master/third_party/zlib/adler32_simd.c
+#if SUPPORTS_RUNTIME_INTRINSICS
+ [MethodImpl(InliningOptions.HotPath | InliningOptions.ShortMethod)]
+ private static unsafe uint CalculateSse(uint adler, ReadOnlySpan buffer)
{
- ref byte dataRef = ref MemoryMarshal.GetReference(data);
- uint s1 = this.checksum & 0xFFFF;
- uint s2 = this.checksum >> 16;
+ uint s1 = adler & 0xFFFF;
+ uint s2 = (adler >> 16) & 0xFFFF;
- int count = data.Length;
- int offset = 0;
+ // Process the data in blocks.
+ const int BLOCK_SIZE = 1 << 5;
- while (count > 0)
+ uint length = (uint)buffer.Length;
+ uint blocks = length / BLOCK_SIZE;
+ length -= blocks * BLOCK_SIZE;
+
+ int index = 0;
+ fixed (byte* bufferPtr = buffer)
+ fixed (byte* tapPtr = Tap1Tap2)
{
- // We can defer the modulo operation:
- // s1 maximally grows from 65521 to 65521 + 255 * 3800
- // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31
- int n = 3800;
- if (n > count)
+ index += (int)blocks * BLOCK_SIZE;
+ var localBufferPtr = bufferPtr;
+
+ // _mm_setr_epi8 on x86
+ Vector128 tap1 = Sse2.LoadVector128((sbyte*)tapPtr);
+ Vector128 tap2 = Sse2.LoadVector128((sbyte*)(tapPtr + 0x10));
+ Vector128 zero = Vector128.Zero;
+ var ones = Vector128.Create((short)1);
+
+ while (blocks > 0)
{
- n = count;
+ uint n = NMAX / BLOCK_SIZE; /* The NMAX constraint. */
+ if (n > blocks)
+ {
+ n = blocks;
+ }
+
+ blocks -= n;
+
+ // Process n blocks of data. At most NMAX data bytes can be
+ // processed before s2 must be reduced modulo BASE.
+ Vector128 v_ps = Vector128.CreateScalar(s1 * n);
+ Vector128 v_s2 = Vector128.CreateScalar(s2);
+ Vector128 v_s1 = Vector128.Zero;
+
+ do
+ {
+ // Load 32 input bytes.
+ Vector128 bytes1 = Sse3.LoadDquVector128(localBufferPtr);
+ Vector128 bytes2 = Sse3.LoadDquVector128(localBufferPtr + 0x10);
+
+ // Add previous block byte sum to v_ps.
+ v_ps = Sse2.Add(v_ps, v_s1);
+
+ // Horizontally add the bytes for s1, multiply-adds the
+ // bytes by [ 32, 31, 30, ... ] for s2.
+ v_s1 = Sse2.Add(v_s1, Sse2.SumAbsoluteDifferences(bytes1, zero).AsUInt32());
+ Vector128 mad1 = Ssse3.MultiplyAddAdjacent(bytes1, tap1);
+ v_s2 = Sse2.Add(v_s2, Sse2.MultiplyAddAdjacent(mad1, ones).AsUInt32());
+
+ v_s1 = Sse2.Add(v_s1, Sse2.SumAbsoluteDifferences(bytes2, zero).AsUInt32());
+ Vector128 mad2 = Ssse3.MultiplyAddAdjacent(bytes2, tap2);
+ v_s2 = Sse2.Add(v_s2, Sse2.MultiplyAddAdjacent(mad2, ones).AsUInt32());
+
+ localBufferPtr += BLOCK_SIZE;
+ }
+ while (--n > 0);
+
+ v_s2 = Sse2.Add(v_s2, Sse2.ShiftLeftLogical(v_ps, 5));
+
+ // Sum epi32 ints v_s1(s2) and accumulate in s1(s2).
+ const byte S2301 = 0b1011_0001; // A B C D -> B A D C
+ const byte S1032 = 0b0100_1110; // A B C D -> C D A B
+
+ v_s1 = Sse2.Add(v_s1, Sse2.Shuffle(v_s1, S1032));
+
+ s1 += v_s1.ToScalar();
+
+ v_s2 = Sse2.Add(v_s2, Sse2.Shuffle(v_s2, S2301));
+ v_s2 = Sse2.Add(v_s2, Sse2.Shuffle(v_s2, S1032));
+
+ s2 = v_s2.ToScalar();
+
+ // Reduce.
+ s1 %= BASE;
+ s2 %= BASE;
}
- count -= n;
- while (--n >= 0)
+ if (length > 0)
{
- s1 += Unsafe.Add(ref dataRef, offset++);
- s2 += s1;
+ if (length >= 16)
+ {
+ s2 += s1 += localBufferPtr[0];
+ s2 += s1 += localBufferPtr[1];
+ s2 += s1 += localBufferPtr[2];
+ s2 += s1 += localBufferPtr[3];
+ s2 += s1 += localBufferPtr[4];
+ s2 += s1 += localBufferPtr[5];
+ s2 += s1 += localBufferPtr[6];
+ s2 += s1 += localBufferPtr[7];
+ s2 += s1 += localBufferPtr[8];
+ s2 += s1 += localBufferPtr[9];
+ s2 += s1 += localBufferPtr[10];
+ s2 += s1 += localBufferPtr[11];
+ s2 += s1 += localBufferPtr[12];
+ s2 += s1 += localBufferPtr[13];
+ s2 += s1 += localBufferPtr[14];
+ s2 += s1 += localBufferPtr[15];
+
+ localBufferPtr += 16;
+ length -= 16;
+ }
+
+ while (length-- > 0)
+ {
+ s2 += s1 += *localBufferPtr++;
+ }
+
+ if (s1 >= BASE)
+ {
+ s1 -= BASE;
+ }
+
+ s2 %= BASE;
}
- s1 %= Base;
- s2 %= Base;
+ return s1 | (s2 << 16);
}
+ }
+#endif
- this.checksum = (s2 << 16) | s1;
+ [MethodImpl(InliningOptions.HotPath | InliningOptions.ShortMethod)]
+ private static unsafe uint CalculateScalar(uint adler, ReadOnlySpan buffer)
+ {
+ uint s1 = adler & 0xFFFF;
+ uint s2 = (adler >> 16) & 0xFFFF;
+ uint k;
+
+ fixed (byte* bufferPtr = buffer)
+ {
+ var localBufferPtr = bufferPtr;
+ uint length = (uint)buffer.Length;
+
+ while (length > 0)
+ {
+ k = length < NMAX ? length : NMAX;
+ length -= k;
+
+ while (k >= 16)
+ {
+ s2 += s1 += localBufferPtr[0];
+ s2 += s1 += localBufferPtr[1];
+ s2 += s1 += localBufferPtr[2];
+ s2 += s1 += localBufferPtr[3];
+ s2 += s1 += localBufferPtr[4];
+ s2 += s1 += localBufferPtr[5];
+ s2 += s1 += localBufferPtr[6];
+ s2 += s1 += localBufferPtr[7];
+ s2 += s1 += localBufferPtr[8];
+ s2 += s1 += localBufferPtr[9];
+ s2 += s1 += localBufferPtr[10];
+ s2 += s1 += localBufferPtr[11];
+ s2 += s1 += localBufferPtr[12];
+ s2 += s1 += localBufferPtr[13];
+ s2 += s1 += localBufferPtr[14];
+ s2 += s1 += localBufferPtr[15];
+
+ localBufferPtr += 16;
+ k -= 16;
+ }
+
+ while (k-- > 0)
+ {
+ s2 += s1 += *localBufferPtr++;
+ }
+
+ s1 %= BASE;
+ s2 %= BASE;
+ }
+
+ return (s2 << 16) | s1;
+ }
}
}
}
diff --git a/src/ImageSharp/Formats/Png/Zlib/Crc32.Lut.cs b/src/ImageSharp/Formats/Png/Zlib/Crc32.Lut.cs
new file mode 100644
index 000000000..77fb9f825
--- /dev/null
+++ b/src/ImageSharp/Formats/Png/Zlib/Crc32.Lut.cs
@@ -0,0 +1,70 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+namespace SixLabors.ImageSharp.Formats.Png.Zlib
+{
+ ///
+ /// Contains precalulated tables for scalar calculations.
+ ///
+ internal static partial class Crc32
+ {
+ ///
+ /// The table of all possible eight bit values for fast scalar lookup.
+ ///
+ private static readonly uint[] CrcTable =
+ {
+ 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419,
+ 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4,
+ 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07,
+ 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
+ 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856,
+ 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
+ 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4,
+ 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
+ 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3,
+ 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A,
+ 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599,
+ 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
+ 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190,
+ 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
+ 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E,
+ 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
+ 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED,
+ 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,
+ 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3,
+ 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
+ 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A,
+ 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5,
+ 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010,
+ 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
+ 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17,
+ 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6,
+ 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615,
+ 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
+ 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344,
+ 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
+ 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A,
+ 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
+ 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1,
+ 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C,
+ 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF,
+ 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
+ 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE,
+ 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31,
+ 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C,
+ 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
+ 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B,
+ 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
+ 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1,
+ 0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
+ 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278,
+ 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7,
+ 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66,
+ 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
+ 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605,
+ 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8,
+ 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B,
+ 0x2D02EF8D
+ };
+ }
+}
diff --git a/src/ImageSharp/Formats/Png/Zlib/Crc32.cs b/src/ImageSharp/Formats/Png/Zlib/Crc32.cs
index 77355e908..5b29e3590 100644
--- a/src/ImageSharp/Formats/Png/Zlib/Crc32.cs
+++ b/src/ImageSharp/Formats/Png/Zlib/Crc32.cs
@@ -1,154 +1,215 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+#if SUPPORTS_RUNTIME_INTRINSICS
+using System.Runtime.Intrinsics;
+using System.Runtime.Intrinsics.X86;
+#endif
namespace SixLabors.ImageSharp.Formats.Png.Zlib
{
///
- /// Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
- /// x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
+ /// Calculates the 32 bit Cyclic Redundancy Check (CRC) checksum of a given buffer
+ /// according to the IEEE 802.3 specification.
///
- ///
- ///
- /// Polynomials over GF(2) are represented in binary, one bit per coefficient,
- /// with the lowest powers in the most significant bit. Then adding polynomials
- /// is just exclusive-or, and multiplying a polynomial by x is a right shift by
- /// one. If we call the above polynomial p, and represent a byte as the
- /// polynomial q, also with the lowest power in the most significant bit (so the
- /// byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
- /// where a mod b means the remainder after dividing a by b.
- ///
- ///
- /// This calculation is done using the shift-register method of multiplying and
- /// taking the remainder. The register is initialized to zero, and for each
- /// incoming bit, x^32 is added mod p to the register if the bit is a one (where
- /// x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
- /// x (which is shifting right by one and adding x^32 mod p if the bit shifted
- /// out is a one). We start with the highest power (least significant bit) of
- /// q and repeat for all eight bits of q.
- ///
- ///
- /// The table is simply the CRC of all possible eight bit values. This is all
- /// the information needed to generate CRC's on data a byte at a time for all
- /// combinations of CRC register values and incoming bytes.
- ///
- ///
- internal sealed class Crc32 : IChecksum
+ internal static partial class Crc32
{
///
- /// The cycle redundancy check seed
+ /// The default initial seed value of a Crc32 checksum calculation.
///
- private const uint CrcSeed = 0xFFFFFFFF;
+ public const uint SeedValue = 0U;
- ///
- /// The table of all possible eight bit values for fast lookup.
- ///
- private static readonly uint[] CrcTable =
+#if SUPPORTS_RUNTIME_INTRINSICS
+ private const int MinBufferSize = 64;
+ private const int ChunksizeMask = 15;
+
+ // Definitions of the bit-reflected domain constants k1, k2, k3, etc and
+ // the CRC32+Barrett polynomials given at the end of the paper.
+ private static readonly ulong[] K05Poly =
{
- 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419,
- 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4,
- 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07,
- 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
- 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856,
- 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
- 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4,
- 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
- 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3,
- 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A,
- 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599,
- 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
- 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190,
- 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
- 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E,
- 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
- 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED,
- 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,
- 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3,
- 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
- 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A,
- 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5,
- 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010,
- 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
- 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17,
- 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6,
- 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615,
- 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
- 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344,
- 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
- 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A,
- 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
- 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1,
- 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C,
- 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF,
- 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
- 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE,
- 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31,
- 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C,
- 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
- 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B,
- 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
- 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1,
- 0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
- 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278,
- 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7,
- 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66,
- 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
- 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605,
- 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8,
- 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B,
- 0x2D02EF8D
+ 0x0154442bd4, 0x01c6e41596, // k1, k2
+ 0x01751997d0, 0x00ccaa009e, // k3, k4
+ 0x0163cd6124, 0x0000000000, // k5, k0
+ 0x01db710641, 0x01f7011641 // polynomial
};
+#endif
///
- /// The data checksum so far.
+ /// Calculates the CRC checksum with the bytes taken from the span.
///
- private uint crc;
+ /// The readonly span of bytes.
+ /// The .
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static uint Calculate(ReadOnlySpan buffer)
+ => Calculate(SeedValue, buffer);
- ///
- public long Value
+ ///
+ /// Calculates the CRC checksum with the bytes taken from the span and seed.
+ ///
+ /// The input CRC value.
+ /// The readonly span of bytes.
+ /// The .
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static uint Calculate(uint crc, ReadOnlySpan buffer)
{
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.crc;
+ if (buffer.IsEmpty)
+ {
+ return crc;
+ }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- set => this.crc = (uint)value;
+#if SUPPORTS_RUNTIME_INTRINSICS
+ if (Sse41.IsSupported && Pclmulqdq.IsSupported && buffer.Length >= MinBufferSize)
+ {
+ return ~CalculateSse(~crc, buffer);
+ }
+ else
+ {
+ return ~CalculateScalar(~crc, buffer);
+ }
+#else
+ return ~CalculateScalar(~crc, buffer);
+#endif
}
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Reset()
+#if SUPPORTS_RUNTIME_INTRINSICS
+ // Based on https://github.com/chromium/chromium/blob/master/third_party/zlib/crc32_simd.c
+ [MethodImpl(InliningOptions.HotPath | InliningOptions.ShortMethod)]
+ private static unsafe uint CalculateSse(uint crc, ReadOnlySpan buffer)
{
- this.crc = 0;
- }
+ int chunksize = buffer.Length & ~ChunksizeMask;
+ int length = chunksize;
- ///
- /// Updates the checksum with the given value.
- ///
- /// The byte is taken as the lower 8 bits of value.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Update(int value)
- {
- this.crc ^= CrcSeed;
- this.crc = CrcTable[(this.crc ^ value) & 0xFF] ^ (this.crc >> 8);
- this.crc ^= CrcSeed;
+ fixed (byte* bufferPtr = buffer)
+ fixed (ulong* k05PolyPtr = K05Poly)
+ {
+ byte* localBufferPtr = bufferPtr;
+ ulong* localK05PolyPtr = k05PolyPtr;
+
+ // There's at least one block of 64.
+ Vector128 x1 = Sse2.LoadVector128((ulong*)(localBufferPtr + 0x00));
+ Vector128 x2 = Sse2.LoadVector128((ulong*)(localBufferPtr + 0x10));
+ Vector128 x3 = Sse2.LoadVector128((ulong*)(localBufferPtr + 0x20));
+ Vector128 x4 = Sse2.LoadVector128((ulong*)(localBufferPtr + 0x30));
+ Vector128 x5;
+
+ x1 = Sse2.Xor(x1, Sse2.ConvertScalarToVector128UInt32(crc).AsUInt64());
+
+ // k1, k2
+ Vector128 x0 = Sse2.LoadVector128(localK05PolyPtr + 0x0);
+
+ localBufferPtr += 64;
+ length -= 64;
+
+ // Parallel fold blocks of 64, if any.
+ while (length >= 64)
+ {
+ x5 = Pclmulqdq.CarrylessMultiply(x1, x0, 0x00);
+ Vector128 x6 = Pclmulqdq.CarrylessMultiply(x2, x0, 0x00);
+ Vector128 x7 = Pclmulqdq.CarrylessMultiply(x3, x0, 0x00);
+ Vector128 x8 = Pclmulqdq.CarrylessMultiply(x4, x0, 0x00);
+
+ x1 = Pclmulqdq.CarrylessMultiply(x1, x0, 0x11);
+ x2 = Pclmulqdq.CarrylessMultiply(x2, x0, 0x11);
+ x3 = Pclmulqdq.CarrylessMultiply(x3, x0, 0x11);
+ x4 = Pclmulqdq.CarrylessMultiply(x4, x0, 0x11);
+
+ Vector128 y5 = Sse2.LoadVector128((ulong*)(localBufferPtr + 0x00));
+ Vector128 y6 = Sse2.LoadVector128((ulong*)(localBufferPtr + 0x10));
+ Vector128 y7 = Sse2.LoadVector128((ulong*)(localBufferPtr + 0x20));
+ Vector128 y8 = Sse2.LoadVector128((ulong*)(localBufferPtr + 0x30));
+
+ x1 = Sse2.Xor(x1, x5);
+ x2 = Sse2.Xor(x2, x6);
+ x3 = Sse2.Xor(x3, x7);
+ x4 = Sse2.Xor(x4, x8);
+
+ x1 = Sse2.Xor(x1, y5);
+ x2 = Sse2.Xor(x2, y6);
+ x3 = Sse2.Xor(x3, y7);
+ x4 = Sse2.Xor(x4, y8);
+
+ localBufferPtr += 64;
+ length -= 64;
+ }
+
+ // Fold into 128-bits.
+ // k3, k4
+ x0 = Sse2.LoadVector128(k05PolyPtr + 0x2);
+
+ x5 = Pclmulqdq.CarrylessMultiply(x1, x0, 0x00);
+ x1 = Pclmulqdq.CarrylessMultiply(x1, x0, 0x11);
+ x1 = Sse2.Xor(x1, x2);
+ x1 = Sse2.Xor(x1, x5);
+
+ x5 = Pclmulqdq.CarrylessMultiply(x1, x0, 0x00);
+ x1 = Pclmulqdq.CarrylessMultiply(x1, x0, 0x11);
+ x1 = Sse2.Xor(x1, x3);
+ x1 = Sse2.Xor(x1, x5);
+
+ x5 = Pclmulqdq.CarrylessMultiply(x1, x0, 0x00);
+ x1 = Pclmulqdq.CarrylessMultiply(x1, x0, 0x11);
+ x1 = Sse2.Xor(x1, x4);
+ x1 = Sse2.Xor(x1, x5);
+
+ // Single fold blocks of 16, if any.
+ while (length >= 16)
+ {
+ x2 = Sse2.LoadVector128((ulong*)localBufferPtr);
+
+ x5 = Pclmulqdq.CarrylessMultiply(x1, x0, 0x00);
+ x1 = Pclmulqdq.CarrylessMultiply(x1, x0, 0x11);
+ x1 = Sse2.Xor(x1, x2);
+ x1 = Sse2.Xor(x1, x5);
+
+ localBufferPtr += 16;
+ length -= 16;
+ }
+
+ // Fold 128 - bits to 64 - bits.
+ x2 = Pclmulqdq.CarrylessMultiply(x1, x0, 0x10);
+ x3 = Vector128.Create(~0, 0, ~0, 0).AsUInt64(); // _mm_setr_epi32 on x86
+ x1 = Sse2.ShiftRightLogical128BitLane(x1, 8);
+ x1 = Sse2.Xor(x1, x2);
+
+ // k5, k0
+ x0 = Sse2.LoadScalarVector128(localK05PolyPtr + 0x4);
+
+ x2 = Sse2.ShiftRightLogical128BitLane(x1, 4);
+ x1 = Sse2.And(x1, x3);
+ x1 = Pclmulqdq.CarrylessMultiply(x1, x0, 0x00);
+ x1 = Sse2.Xor(x1, x2);
+
+ // Barret reduce to 32-bits.
+ // polynomial
+ x0 = Sse2.LoadVector128(localK05PolyPtr + 0x6);
+
+ x2 = Sse2.And(x1, x3);
+ x2 = Pclmulqdq.CarrylessMultiply(x2, x0, 0x10);
+ x2 = Sse2.And(x2, x3);
+ x2 = Pclmulqdq.CarrylessMultiply(x2, x0, 0x00);
+ x1 = Sse2.Xor(x1, x2);
+
+ crc = (uint)Sse41.Extract(x1.AsInt32(), 1);
+ return buffer.Length - chunksize == 0 ? crc : CalculateScalar(crc, buffer.Slice(chunksize));
+ }
}
+#endif
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Update(ReadOnlySpan data)
+ [MethodImpl(InliningOptions.HotPath | InliningOptions.ShortMethod)]
+ private static uint CalculateScalar(uint crc, ReadOnlySpan buffer)
{
- this.crc ^= CrcSeed;
-
ref uint crcTableRef = ref MemoryMarshal.GetReference(CrcTable.AsSpan());
- for (int i = 0; i < data.Length; i++)
+ ref byte bufferRef = ref MemoryMarshal.GetReference(buffer);
+
+ for (int i = 0; i < buffer.Length; i++)
{
- this.crc = Unsafe.Add(ref crcTableRef, (int)((this.crc ^ data[i]) & 0xFF)) ^ (this.crc >> 8);
+ crc = Unsafe.Add(ref crcTableRef, (int)((crc ^ Unsafe.Add(ref bufferRef, i)) & 0xFF)) ^ (crc >> 8);
}
- this.crc ^= CrcSeed;
+ return crc;
}
}
}
diff --git a/src/ImageSharp/Formats/Png/Zlib/DeflateThrowHelper.cs b/src/ImageSharp/Formats/Png/Zlib/DeflateThrowHelper.cs
index 5f62b13c7..c2296e013 100644
--- a/src/ImageSharp/Formats/Png/Zlib/DeflateThrowHelper.cs
+++ b/src/ImageSharp/Formats/Png/Zlib/DeflateThrowHelper.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/Zlib/Deflater.cs b/src/ImageSharp/Formats/Png/Zlib/Deflater.cs
index 7398b089b..c99a4c351 100644
--- a/src/ImageSharp/Formats/Png/Zlib/Deflater.cs
+++ b/src/ImageSharp/Formats/Png/Zlib/Deflater.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
@@ -288,8 +288,6 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
this.engine = null;
this.isDisposed = true;
}
-
- GC.SuppressFinalize(this);
}
}
}
diff --git a/src/ImageSharp/Formats/Png/Zlib/DeflaterConstants.cs b/src/ImageSharp/Formats/Png/Zlib/DeflaterConstants.cs
index 67e8c6900..62943a5ae 100644
--- a/src/ImageSharp/Formats/Png/Zlib/DeflaterConstants.cs
+++ b/src/ImageSharp/Formats/Png/Zlib/DeflaterConstants.cs
@@ -1,17 +1,15 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
using System;
-using System.Collections.Generic;
-using System.Text;
namespace SixLabors.ImageSharp.Formats.Png.Zlib
{
///
/// This class contains constants used for deflation.
///
- public static class DeflaterConstants
+ internal static class DeflaterConstants
{
///
/// Set to true to enable debugging
diff --git a/src/ImageSharp/Formats/Png/Zlib/DeflaterEngine.cs b/src/ImageSharp/Formats/Png/Zlib/DeflaterEngine.cs
index 7be794b5e..11b39efb5 100644
--- a/src/ImageSharp/Formats/Png/Zlib/DeflaterEngine.cs
+++ b/src/ImageSharp/Formats/Png/Zlib/DeflaterEngine.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
///
/// Strategies for deflater
///
- public enum DeflateStrategy
+ internal enum DeflateStrategy
{
///
/// The default strategy
@@ -362,7 +362,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
more = this.inputEnd - this.inputOff;
}
- Array.Copy(this.inputBuf, this.inputOff, this.window, this.strstart + this.lookahead, more);
+ Buffer.BlockCopy(this.inputBuf, this.inputOff, this.window, this.strstart + this.lookahead, more);
this.inputOff += more;
this.lookahead += more;
@@ -397,8 +397,6 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
this.isDisposed = true;
}
-
- GC.SuppressFinalize(this);
}
[MethodImpl(InliningOptions.ShortMethod)]
@@ -464,6 +462,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
///
/// The current match.
/// True if a match greater than the minimum length is found
+ [MethodImpl(InliningOptions.HotPath)]
private bool FindLongestMatch(int curMatch)
{
int match;
diff --git a/src/ImageSharp/Formats/Png/Zlib/DeflaterHuffman.cs b/src/ImageSharp/Formats/Png/Zlib/DeflaterHuffman.cs
index 543a1fe30..4d1be0fc4 100644
--- a/src/ImageSharp/Formats/Png/Zlib/DeflaterHuffman.cs
+++ b/src/ImageSharp/Formats/Png/Zlib/DeflaterHuffman.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
@@ -36,11 +36,6 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
private const int EofSymbol = 256;
- private static readonly short[] StaticLCodes;
- private static readonly byte[] StaticLLength;
- private static readonly short[] StaticDCodes;
- private static readonly byte[] StaticDLength;
-
private Tree literalTree;
private Tree distTree;
private Tree blTree;
@@ -58,49 +53,6 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
private int extraBits;
private bool isDisposed;
- // TODO: These should be pre-generated array/readonlyspans.
- static DeflaterHuffman()
- {
- // See RFC 1951 3.2.6
- // Literal codes
- StaticLCodes = new short[LiteralNumber];
- StaticLLength = new byte[LiteralNumber];
-
- int i = 0;
- while (i < 144)
- {
- StaticLCodes[i] = BitReverse((0x030 + i) << 8);
- StaticLLength[i++] = 8;
- }
-
- while (i < 256)
- {
- StaticLCodes[i] = BitReverse((0x190 - 144 + i) << 7);
- StaticLLength[i++] = 9;
- }
-
- while (i < 280)
- {
- StaticLCodes[i] = BitReverse((0x000 - 256 + i) << 9);
- StaticLLength[i++] = 7;
- }
-
- while (i < LiteralNumber)
- {
- StaticLCodes[i] = BitReverse((0x0c0 - 280 + i) << 8);
- StaticLLength[i++] = 8;
- }
-
- // Distance codes
- StaticDCodes = new short[DistanceNumber];
- StaticDLength = new byte[DistanceNumber];
- for (i = 0; i < DistanceNumber; i++)
- {
- StaticDCodes[i] = BitReverse(i << 11);
- StaticDLength[i] = 5;
- }
- }
-
///
/// Initializes a new instance of the class.
///
@@ -122,12 +74,80 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
this.pinnedLiteralBuffer = (short*)this.literalBufferHandle.Pointer;
}
+#pragma warning disable SA1201 // Elements should appear in the correct order
+
+ // See RFC 1951 3.2.6
+ // Literal codes
+ private static readonly short[] StaticLCodes = new short[]
+ {
+ 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
+ 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
+ 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
+ 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
+ 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
+ 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241, 9,
+ 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, 5,
+ 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, 13,
+ 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, 19,
+ 275, 147, 403, 83, 339, 211, 467, 51, 307, 179, 435, 115, 371, 243, 499,
+ 11, 267, 139, 395, 75, 331, 203, 459, 43, 299, 171, 427, 107, 363, 235, 491,
+ 27, 283, 155, 411, 91, 347, 219, 475, 59, 315, 187, 443, 123, 379, 251, 507,
+ 7, 263, 135, 391, 71, 327, 199, 455, 39, 295, 167, 423, 103, 359, 231, 487,
+ 23, 279, 151, 407, 87, 343, 215, 471, 55, 311, 183, 439, 119, 375, 247, 503,
+ 15, 271, 143, 399, 79, 335, 207, 463, 47, 303, 175, 431, 111, 367, 239, 495,
+ 31, 287, 159, 415, 95, 351, 223, 479, 63, 319, 191, 447, 127, 383, 255, 511,
+ 0, 64, 32, 96, 16, 80, 48, 112, 8, 72, 40, 104, 24, 88, 56, 120, 4, 68, 36,
+ 100, 20, 84, 52, 116, 3, 131, 67, 195, 35, 163
+ };
+
+ private static ReadOnlySpan StaticLLength => new byte[]
+ {
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8
+ };
+
+ // Distance codes and lengths.
+ private static readonly short[] StaticDCodes = new short[]
+ {
+ 0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14,
+ 30, 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23
+ };
+
+ private static ReadOnlySpan StaticDLength => new byte[]
+ {
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
+ };
+#pragma warning restore SA1201 // Elements should appear in the correct order
+
///
/// Gets the lengths of the bit length codes are sent in order of decreasing probability, to avoid transmitting the lengths for unused bit length codes.
///
- private static ReadOnlySpan BitLengthOrder => new byte[] { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
+ private static ReadOnlySpan BitLengthOrder => new byte[]
+ {
+ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
+ };
- private static ReadOnlySpan Bit4Reverse => new byte[] { 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 };
+ private static ReadOnlySpan Bit4Reverse => new byte[]
+ {
+ 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
+ };
///
/// Gets the pending buffer to use.
@@ -413,8 +433,6 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
this.distTree = null;
this.isDisposed = true;
}
-
- GC.SuppressFinalize(this);
}
[MethodImpl(InliningOptions.ShortMethod)]
@@ -553,6 +571,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
}
}
+ [MethodImpl(InliningOptions.HotPath)]
public void BuildTree()
{
int numSymbols = this.elementCount;
@@ -964,8 +983,6 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
this.isDisposed = true;
}
-
- GC.SuppressFinalize(this);
}
}
}
diff --git a/src/ImageSharp/Formats/Png/Zlib/DeflaterOutputStream.cs b/src/ImageSharp/Formats/Png/Zlib/DeflaterOutputStream.cs
index a777e6f7d..11e566739 100644
--- a/src/ImageSharp/Formats/Png/Zlib/DeflaterOutputStream.cs
+++ b/src/ImageSharp/Formats/Png/Zlib/DeflaterOutputStream.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.IO;
diff --git a/src/ImageSharp/Formats/Png/Zlib/DeflaterPendingBuffer.cs b/src/ImageSharp/Formats/Png/Zlib/DeflaterPendingBuffer.cs
index 731c9e80f..095cb33cc 100644
--- a/src/ImageSharp/Formats/Png/Zlib/DeflaterPendingBuffer.cs
+++ b/src/ImageSharp/Formats/Png/Zlib/DeflaterPendingBuffer.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
@@ -172,8 +172,6 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
this.bufferMemoryOwner = null;
this.isDisposed = true;
}
-
- GC.SuppressFinalize(this);
}
}
}
diff --git a/src/ImageSharp/Formats/Png/Zlib/IChecksum.cs b/src/ImageSharp/Formats/Png/Zlib/IChecksum.cs
deleted file mode 100644
index da5deb49e..000000000
--- a/src/ImageSharp/Formats/Png/Zlib/IChecksum.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-
-namespace SixLabors.ImageSharp.Formats.Png.Zlib
-{
- ///
- /// Interface to compute a data checksum used by checked input/output streams.
- /// A data checksum can be updated by one byte or with a byte array. After each
- /// update the value of the current checksum can be returned by calling
- /// Value. The complete checksum object can also be reset
- /// so it can be used again with new data.
- ///
- internal interface IChecksum
- {
- ///
- /// Gets the data checksum computed so far.
- ///
- long Value { get; }
-
- ///
- /// Resets the data checksum as if no update was ever called.
- ///
- void Reset();
-
- ///
- /// Adds one byte to the data checksum.
- ///
- ///
- /// The data value to add. The high byte of the integer is ignored.
- ///
- void Update(int value);
-
- ///
- /// Updates the data checksum with the bytes taken from the span.
- ///
- ///
- /// buffer an array of bytes
- ///
- void Update(ReadOnlySpan data);
- }
-}
diff --git a/src/ImageSharp/Formats/Png/Zlib/README.md b/src/ImageSharp/Formats/Png/Zlib/README.md
index 59f75d05f..3875f9884 100644
--- a/src/ImageSharp/Formats/Png/Zlib/README.md
+++ b/src/ImageSharp/Formats/Png/Zlib/README.md
@@ -1,5 +1,11 @@
-Deflatestream implementation adapted from
+DeflateStream implementation adapted from
https://github.com/icsharpcode/SharpZipLib
-LIcensed under MIT
+Licensed under MIT
+
+Crc32 and Adler32 SIMD implementation adapted from
+
+https://github.com/chromium/chromium
+
+Licensed under BSD 3-Clause "New" or "Revised" License
diff --git a/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs b/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs
index c723b463f..3257fa884 100644
--- a/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs
+++ b/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs
@@ -1,8 +1,9 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.IO;
+using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.Png.Zlib
@@ -20,7 +21,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
///
/// Computes the checksum for the data stream.
///
- private readonly Adler32 adler32 = new Adler32();
+ private uint adler = Adler32.SeedValue;
///
/// A value indicating whether this instance of the given entity has been disposed.
@@ -46,9 +47,10 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
///
/// The memory allocator to use for buffer allocations.
/// The stream to compress.
- /// The compression level.
- public ZlibDeflateStream(MemoryAllocator memoryAllocator, Stream stream, int compressionLevel)
+ /// The compression level.
+ public ZlibDeflateStream(MemoryAllocator memoryAllocator, Stream stream, PngCompressionLevel level)
{
+ int compressionLevel = (int)level;
this.rawStream = stream;
// Write the zlib header : http://tools.ietf.org/html/rfc1950
@@ -132,10 +134,11 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
public override void SetLength(long value) => throw new NotSupportedException();
///
+ [MethodImpl(InliningOptions.ShortMethod)]
public override void Write(byte[] buffer, int offset, int count)
{
this.deflateStream.Write(buffer, offset, count);
- this.adler32.Update(buffer.AsSpan(offset, count));
+ this.adler = Adler32.Calculate(this.adler, buffer.AsSpan(offset, count));
}
///
@@ -152,7 +155,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
this.deflateStream.Dispose();
// Add the crc
- uint crc = (uint)this.adler32.Value;
+ uint crc = this.adler;
this.rawStream.WriteByte((byte)((crc >> 24) & 0xFF));
this.rawStream.WriteByte((byte)((crc >> 16) & 0xFF));
this.rawStream.WriteByte((byte)((crc >> 8) & 0xFF));
diff --git a/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs b/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs
index 3eb34b861..387ff9301 100644
--- a/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs
+++ b/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.IO;
diff --git a/src/ImageSharp/Formats/Png/Zlib/fast-crc-computation-generic-polynomials-pclmulqdq-paper.pdf b/src/ImageSharp/Formats/Png/Zlib/fast-crc-computation-generic-polynomials-pclmulqdq-paper.pdf
new file mode 100644
index 000000000..d0eca86b3
Binary files /dev/null and b/src/ImageSharp/Formats/Png/Zlib/fast-crc-computation-generic-polynomials-pclmulqdq-paper.pdf differ
diff --git a/src/ImageSharp/Formats/Tga/ITgaDecoderOptions.cs b/src/ImageSharp/Formats/Tga/ITgaDecoderOptions.cs
index e99e8b0c8..3d99f136f 100644
--- a/src/ImageSharp/Formats/Tga/ITgaDecoderOptions.cs
+++ b/src/ImageSharp/Formats/Tga/ITgaDecoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/ITgaEncoderOptions.cs b/src/ImageSharp/Formats/Tga/ITgaEncoderOptions.cs
index 49983d236..b85431e51 100644
--- a/src/ImageSharp/Formats/Tga/ITgaEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Tga/ITgaEncoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/ImageExtensions.cs b/src/ImageSharp/Formats/Tga/ImageExtensions.cs
new file mode 100644
index 000000000..3f9bdacec
--- /dev/null
+++ b/src/ImageSharp/Formats/Tga/ImageExtensions.cs
@@ -0,0 +1,36 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using System.IO;
+
+using SixLabors.ImageSharp.Advanced;
+using SixLabors.ImageSharp.Formats.Tga;
+
+namespace SixLabors.ImageSharp
+{
+ ///
+ /// Extension methods for the type.
+ ///
+ public static partial class ImageExtensions
+ {
+ ///
+ /// Saves the image to the given stream with the tga format.
+ ///
+ /// The image this method extends.
+ /// The stream to save the image to.
+ /// Thrown if the stream is null.
+ public static void SaveAsTga(this Image source, Stream stream) => SaveAsTga(source, stream, null);
+
+ ///
+ /// Saves the image to the given stream with the tga format.
+ ///
+ /// The image this method extends.
+ /// The stream to save the image to.
+ /// The options for the encoder.
+ /// Thrown if the stream is null.
+ public static void SaveAsTga(this Image source, Stream stream, TgaEncoder encoder) =>
+ source.Save(
+ stream,
+ encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(TgaFormat.Instance));
+ }
+}
diff --git a/src/ImageSharp/Formats/Tga/MetadataExtensions.cs b/src/ImageSharp/Formats/Tga/MetadataExtensions.cs
index 2b0e405e7..e8af82a0e 100644
--- a/src/ImageSharp/Formats/Tga/MetadataExtensions.cs
+++ b/src/ImageSharp/Formats/Tga/MetadataExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Formats.Tga;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Formats/Tga/TgaBitsPerPixel.cs b/src/ImageSharp/Formats/Tga/TgaBitsPerPixel.cs
index a0666fa84..0bba5a4d5 100644
--- a/src/ImageSharp/Formats/Tga/TgaBitsPerPixel.cs
+++ b/src/ImageSharp/Formats/Tga/TgaBitsPerPixel.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/TgaCompression.cs b/src/ImageSharp/Formats/Tga/TgaCompression.cs
index cc6e005ed..2686afd5b 100644
--- a/src/ImageSharp/Formats/Tga/TgaCompression.cs
+++ b/src/ImageSharp/Formats/Tga/TgaCompression.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/TgaConfigurationModule.cs b/src/ImageSharp/Formats/Tga/TgaConfigurationModule.cs
index 18fbf4acd..13bcc54c6 100644
--- a/src/ImageSharp/Formats/Tga/TgaConfigurationModule.cs
+++ b/src/ImageSharp/Formats/Tga/TgaConfigurationModule.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/TgaConstants.cs b/src/ImageSharp/Formats/Tga/TgaConstants.cs
index 5aabe92a1..ec84fa451 100644
--- a/src/ImageSharp/Formats/Tga/TgaConstants.cs
+++ b/src/ImageSharp/Formats/Tga/TgaConstants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Tga/TgaDecoder.cs b/src/ImageSharp/Formats/Tga/TgaDecoder.cs
index 2249c86bf..abfaba629 100644
--- a/src/ImageSharp/Formats/Tga/TgaDecoder.cs
+++ b/src/ImageSharp/Formats/Tga/TgaDecoder.cs
@@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
-using System;
using System.IO;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
@@ -29,9 +28,10 @@ namespace SixLabors.ImageSharp.Formats.Tga
{
Size dims = decoder.Dimensions;
- // TODO: use InvalidImageContentException here, if we decide to define it
- // https://github.com/SixLabors/ImageSharp/issues/1110
- throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
+ TgaThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
+
+ // Not reachable, as the previous statement will throw a exception.
+ return null;
}
}
diff --git a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs
index ead004003..ead053572 100644
--- a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs
+++ b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
@@ -12,8 +12,16 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Tga
{
+ ///
+ /// Performs the tga decoding operation.
+ ///
internal sealed class TgaDecoderCore
{
+ ///
+ /// A scratch buffer to reduce allocations.
+ ///
+ private readonly byte[] scratchBuffer = new byte[4];
+
///
/// The metadata.
///
@@ -49,6 +57,11 @@ namespace SixLabors.ImageSharp.Formats.Tga
///
private readonly ITgaDecoderOptions options;
+ ///
+ /// Indicates whether there is a alpha channel present.
+ ///
+ private bool hasAlpha;
+
///
/// Initializes a new instance of the class.
///
@@ -80,7 +93,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
{
try
{
- bool inverted = this.ReadFileHeader(stream);
+ TgaImageOrigin origin = this.ReadFileHeader(stream);
this.currentStream.Skip(this.fileHeader.IdLength);
// Parse the color map, if present.
@@ -97,16 +110,16 @@ namespace SixLabors.ImageSharp.Formats.Tga
var image = Image.CreateUninitialized(this.configuration, this.fileHeader.Width, this.fileHeader.Height, this.metadata);
Buffer2D pixels = image.GetRootFramePixelBuffer();
- if (this.fileHeader.ColorMapType is 1)
+ if (this.fileHeader.ColorMapType == 1)
{
if (this.fileHeader.CMapLength <= 0)
{
- TgaThrowHelper.ThrowImageFormatException("Missing tga color map length");
+ TgaThrowHelper.ThrowInvalidImageContentException("Missing tga color map length");
}
if (this.fileHeader.CMapDepth <= 0)
{
- TgaThrowHelper.ThrowImageFormatException("Missing tga color map depth");
+ TgaThrowHelper.ThrowInvalidImageContentException("Missing tga color map depth");
}
int colorMapPixelSizeInBytes = this.fileHeader.CMapDepth / 8;
@@ -115,7 +128,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
{
this.currentStream.Read(palette.Array, this.fileHeader.CMapStart, colorMapSizeInBytes);
- if (this.fileHeader.ImageType is TgaImageType.RleColorMapped)
+ if (this.fileHeader.ImageType == TgaImageType.RleColorMapped)
{
this.ReadPalettedRle(
this.fileHeader.Width,
@@ -123,7 +136,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
pixels,
palette.Array,
colorMapPixelSizeInBytes,
- inverted);
+ origin);
}
else
{
@@ -133,7 +146,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
pixels,
palette.Array,
colorMapPixelSizeInBytes,
- inverted);
+ origin);
}
}
@@ -152,11 +165,11 @@ namespace SixLabors.ImageSharp.Formats.Tga
case 8:
if (this.fileHeader.ImageType.IsRunLengthEncoded())
{
- this.ReadRle(this.fileHeader.Width, this.fileHeader.Height, pixels, 1, inverted);
+ this.ReadRle(this.fileHeader.Width, this.fileHeader.Height, pixels, 1, origin);
}
else
{
- this.ReadMonoChrome(this.fileHeader.Width, this.fileHeader.Height, pixels, inverted);
+ this.ReadMonoChrome(this.fileHeader.Width, this.fileHeader.Height, pixels, origin);
}
break;
@@ -165,11 +178,11 @@ namespace SixLabors.ImageSharp.Formats.Tga
case 16:
if (this.fileHeader.ImageType.IsRunLengthEncoded())
{
- this.ReadRle(this.fileHeader.Width, this.fileHeader.Height, pixels, 2, inverted);
+ this.ReadRle(this.fileHeader.Width, this.fileHeader.Height, pixels, 2, origin);
}
else
{
- this.ReadBgra16(this.fileHeader.Width, this.fileHeader.Height, pixels, inverted);
+ this.ReadBgra16(this.fileHeader.Width, this.fileHeader.Height, pixels, origin);
}
break;
@@ -177,11 +190,11 @@ namespace SixLabors.ImageSharp.Formats.Tga
case 24:
if (this.fileHeader.ImageType.IsRunLengthEncoded())
{
- this.ReadRle(this.fileHeader.Width, this.fileHeader.Height, pixels, 3, inverted);
+ this.ReadRle(this.fileHeader.Width, this.fileHeader.Height, pixels, 3, origin);
}
else
{
- this.ReadBgr24(this.fileHeader.Width, this.fileHeader.Height, pixels, inverted);
+ this.ReadBgr24(this.fileHeader.Width, this.fileHeader.Height, pixels, origin);
}
break;
@@ -189,17 +202,17 @@ namespace SixLabors.ImageSharp.Formats.Tga
case 32:
if (this.fileHeader.ImageType.IsRunLengthEncoded())
{
- this.ReadRle(this.fileHeader.Width, this.fileHeader.Height, pixels, 4, inverted);
+ this.ReadRle(this.fileHeader.Width, this.fileHeader.Height, pixels, 4, origin);
}
else
{
- this.ReadBgra32(this.fileHeader.Width, this.fileHeader.Height, pixels, inverted);
+ this.ReadBgra32(this.fileHeader.Width, this.fileHeader.Height, pixels, origin);
}
break;
default:
- TgaThrowHelper.ThrowNotSupportedException("Does not support this kind of tga files.");
+ TgaThrowHelper.ThrowNotSupportedException("ImageSharp does not support this kind of tga files.");
break;
}
@@ -220,56 +233,73 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// The to assign the palette to.
/// The color palette.
/// Color map size of one entry in bytes.
- /// Indicates, if the origin of the image is top left rather the bottom left (the default).
- private void ReadPaletted(int width, int height, Buffer2D pixels, byte[] palette, int colorMapPixelSizeInBytes, bool inverted)
+ /// The image origin.
+ private void ReadPaletted(int width, int height, Buffer2D pixels, byte[] palette, int colorMapPixelSizeInBytes, TgaImageOrigin origin)
where TPixel : unmanaged, IPixel
{
- using (IManagedByteBuffer row = this.memoryAllocator.AllocateManagedByteBuffer(width, AllocationOptions.Clean))
+ TPixel color = default;
+ bool invertX = InvertX(origin);
+
+ for (int y = 0; y < height; y++)
{
- TPixel color = default;
- Span rowSpan = row.GetSpan();
+ int newY = InvertY(y, height, origin);
+ Span pixelRow = pixels.GetRowSpan(newY);
- for (int y = 0; y < height; y++)
+ switch (colorMapPixelSizeInBytes)
{
- this.currentStream.Read(row);
- int newY = Invert(y, height, inverted);
- Span pixelRow = pixels.GetRowSpan(newY);
- switch (colorMapPixelSizeInBytes)
- {
- case 2:
+ case 2:
+ if (invertX)
+ {
+ for (int x = width - 1; x >= 0; x--)
+ {
+ this.ReadPalettedBgra16Pixel(palette, colorMapPixelSizeInBytes, x, color, pixelRow);
+ }
+ }
+ else
+ {
for (int x = 0; x < width; x++)
{
- int colorIndex = rowSpan[x];
-
- // Set alpha value to 1, to treat it as opaque for Bgra5551.
- Bgra5551 bgra = Unsafe.As(ref palette[colorIndex * colorMapPixelSizeInBytes]);
- bgra.PackedValue = (ushort)(bgra.PackedValue | 0x8000);
- color.FromBgra5551(bgra);
- pixelRow[x] = color;
+ this.ReadPalettedBgra16Pixel(palette, colorMapPixelSizeInBytes, x, color, pixelRow);
}
+ }
- break;
+ break;
- case 3:
+ case 3:
+ if (invertX)
+ {
+ for (int x = width - 1; x >= 0; x--)
+ {
+ this.ReadPalettedBgr24Pixel(palette, colorMapPixelSizeInBytes, x, color, pixelRow);
+ }
+ }
+ else
+ {
for (int x = 0; x < width; x++)
{
- int colorIndex = rowSpan[x];
- color.FromBgr24(Unsafe.As(ref palette[colorIndex * colorMapPixelSizeInBytes]));
- pixelRow[x] = color;
+ this.ReadPalettedBgr24Pixel(palette, colorMapPixelSizeInBytes, x, color, pixelRow);
}
+ }
- break;
+ break;
- case 4:
+ case 4:
+ if (invertX)
+ {
+ for (int x = width - 1; x >= 0; x--)
+ {
+ this.ReadPalettedBgra32Pixel(palette, colorMapPixelSizeInBytes, x, color, pixelRow);
+ }
+ }
+ else
+ {
for (int x = 0; x < width; x++)
{
- int colorIndex = rowSpan[x];
- color.FromBgra32(Unsafe.As(ref palette[colorIndex * colorMapPixelSizeInBytes]));
- pixelRow[x] = color;
+ this.ReadPalettedBgra32Pixel(palette, colorMapPixelSizeInBytes, x, color, pixelRow);
}
+ }
- break;
- }
+ break;
}
}
}
@@ -283,8 +313,8 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// The to assign the palette to.
/// The color palette.
/// Color map size of one entry in bytes.
- /// Indicates, if the origin of the image is top left rather the bottom left (the default).
- private void ReadPalettedRle(int width, int height, Buffer2D pixels, byte[] palette, int colorMapPixelSizeInBytes, bool inverted)
+ /// The image origin.
+ private void ReadPalettedRle(int width, int height, Buffer2D pixels, byte[] palette, int colorMapPixelSizeInBytes, TgaImageOrigin origin)
where TPixel : unmanaged, IPixel
{
int bytesPerPixel = 1;
@@ -296,7 +326,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
for (int y = 0; y < height; y++)
{
- int newY = Invert(y, height, inverted);
+ int newY = InvertY(y, height, origin);
Span pixelRow = pixels.GetRowSpan(newY);
int rowStartIdx = y * width * bytesPerPixel;
for (int x = 0; x < width; x++)
@@ -308,10 +338,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
color.FromL8(Unsafe.As(ref palette[bufferSpan[idx] * colorMapPixelSizeInBytes]));
break;
case 2:
- // Set alpha value to 1, to treat it as opaque for Bgra5551.
- Bgra5551 bgra = Unsafe.As(ref palette[bufferSpan[idx] * colorMapPixelSizeInBytes]);
- bgra.PackedValue = (ushort)(bgra.PackedValue | 0x8000);
- color.FromBgra5551(bgra);
+ this.ReadPalettedBgra16Pixel(palette, bufferSpan[idx], colorMapPixelSizeInBytes, ref color);
break;
case 3:
color.FromBgr24(Unsafe.As(ref palette[bufferSpan[idx] * colorMapPixelSizeInBytes]));
@@ -321,7 +348,8 @@ namespace SixLabors.ImageSharp.Formats.Tga
break;
}
- pixelRow[x] = color;
+ int newX = InvertX(x, width, origin);
+ pixelRow[newX] = color;
}
}
}
@@ -334,22 +362,43 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// The width of the image.
/// The height of the image.
/// The to assign the palette to.
- /// Indicates, if the origin of the image is top left rather the bottom left (the default).
- private void ReadMonoChrome(int width, int height, Buffer2D pixels, bool inverted)
+ /// the image origin.
+ private void ReadMonoChrome(int width, int height, Buffer2D pixels, TgaImageOrigin origin)
where TPixel : unmanaged, IPixel
{
- using (IManagedByteBuffer row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 1, 0))
+ bool invertX = InvertX(origin);
+ if (invertX)
{
+ TPixel color = default;
for (int y = 0; y < height; y++)
{
- this.currentStream.Read(row);
- int newY = Invert(y, height, inverted);
+ int newY = InvertY(y, height, origin);
Span pixelSpan = pixels.GetRowSpan(newY);
- PixelOperations.Instance.FromL8Bytes(
- this.configuration,
- row.GetSpan(),
- pixelSpan,
- width);
+ for (int x = width - 1; x >= 0; x--)
+ {
+ this.ReadL8Pixel(color, x, pixelSpan);
+ }
+ }
+
+ return;
+ }
+
+ using (IManagedByteBuffer row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 1, 0))
+ {
+ bool invertY = InvertY(origin);
+ if (invertY)
+ {
+ for (int y = height - 1; y >= 0; y--)
+ {
+ this.ReadL8Row(width, pixels, row, y);
+ }
+ }
+ else
+ {
+ for (int y = 0; y < height; y++)
+ {
+ this.ReadL8Row(width, pixels, row, y);
+ }
}
}
}
@@ -361,30 +410,64 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// The width of the image.
/// The height of the image.
/// The to assign the palette to.
- /// Indicates, if the origin of the image is top left rather the bottom left (the default).
- private void ReadBgra16(int width, int height, Buffer2D pixels, bool inverted)
+ /// The image origin.
+ private void ReadBgra16(int width, int height, Buffer2D pixels, TgaImageOrigin origin)
where TPixel : unmanaged, IPixel
{
+ TPixel color = default;
+ bool invertX = InvertX(origin);
using (IManagedByteBuffer row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 2, 0))
{
for (int y = 0; y < height; y++)
{
- this.currentStream.Read(row);
- Span rowSpan = row.GetSpan();
+ int newY = InvertY(y, height, origin);
+ Span pixelSpan = pixels.GetRowSpan(newY);
- // We need to set each alpha component value to fully opaque.
- for (int x = 1; x < rowSpan.Length; x += 2)
+ if (invertX)
{
- rowSpan[x] = (byte)(rowSpan[x] | (1 << 7));
+ for (int x = width - 1; x >= 0; x--)
+ {
+ this.currentStream.Read(this.scratchBuffer, 0, 2);
+ if (!this.hasAlpha)
+ {
+ this.scratchBuffer[1] |= 1 << 7;
+ }
+
+ if (this.fileHeader.ImageType == TgaImageType.BlackAndWhite)
+ {
+ color.FromLa16(Unsafe.As(ref this.scratchBuffer[0]));
+ }
+ else
+ {
+ color.FromBgra5551(Unsafe.As(ref this.scratchBuffer[0]));
+ }
+
+ pixelSpan[x] = color;
+ }
}
+ else
+ {
+ this.currentStream.Read(row);
+ Span rowSpan = row.GetSpan();
- int newY = Invert(y, height, inverted);
- Span pixelSpan = pixels.GetRowSpan(newY);
- PixelOperations.Instance.FromBgra5551Bytes(
- this.configuration,
- rowSpan,
- pixelSpan,
- width);
+ if (!this.hasAlpha)
+ {
+ // We need to set the alpha component value to fully opaque.
+ for (int x = 1; x < rowSpan.Length; x += 2)
+ {
+ rowSpan[x] |= 1 << 7;
+ }
+ }
+
+ if (this.fileHeader.ImageType == TgaImageType.BlackAndWhite)
+ {
+ PixelOperations.Instance.FromLa16Bytes(this.configuration, rowSpan, pixelSpan, width);
+ }
+ else
+ {
+ PixelOperations.Instance.FromBgra5551Bytes(this.configuration, rowSpan, pixelSpan, width);
+ }
+ }
}
}
}
@@ -396,22 +479,44 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// The width of the image.
/// The height of the image.
/// The to assign the palette to.
- /// Indicates, if the origin of the image is top left rather the bottom left (the default).
- private void ReadBgr24(int width, int height, Buffer2D pixels, bool inverted)
+ /// The image origin.
+ private void ReadBgr24(int width, int height, Buffer2D pixels, TgaImageOrigin origin)
where TPixel : unmanaged, IPixel
{
- using (IManagedByteBuffer row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 3, 0))
+ bool invertX = InvertX(origin);
+ if (invertX)
{
+ TPixel color = default;
for (int y = 0; y < height; y++)
{
- this.currentStream.Read(row);
- int newY = Invert(y, height, inverted);
+ int newY = InvertY(y, height, origin);
Span pixelSpan = pixels.GetRowSpan(newY);
- PixelOperations.Instance.FromBgr24Bytes(
- this.configuration,
- row.GetSpan(),
- pixelSpan,
- width);
+ for (int x = width - 1; x >= 0; x--)
+ {
+ this.ReadBgr24Pixel(color, x, pixelSpan);
+ }
+ }
+
+ return;
+ }
+
+ using (IManagedByteBuffer row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 3, 0))
+ {
+ bool invertY = InvertY(origin);
+
+ if (invertY)
+ {
+ for (int y = height - 1; y >= 0; y--)
+ {
+ this.ReadBgr24Row(width, pixels, row, y);
+ }
+ }
+ else
+ {
+ for (int y = 0; y < height; y++)
+ {
+ this.ReadBgr24Row(width, pixels, row, y);
+ }
}
}
}
@@ -423,22 +528,52 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// The width of the image.
/// The height of the image.
/// The to assign the palette to.
- /// Indicates, if the origin of the image is top left rather the bottom left (the default).
- private void ReadBgra32(int width, int height, Buffer2D pixels, bool inverted)
+ /// The image origin.
+ private void ReadBgra32(int width, int height, Buffer2D pixels, TgaImageOrigin origin)
where TPixel : unmanaged, IPixel
{
- using (IManagedByteBuffer row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 4, 0))
+ TPixel color = default;
+ bool invertX = InvertX(origin);
+ if (this.tgaMetadata.AlphaChannelBits == 8 && !invertX)
{
- for (int y = 0; y < height; y++)
+ using (IManagedByteBuffer row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 4, 0))
{
- this.currentStream.Read(row);
- int newY = Invert(y, height, inverted);
- Span pixelSpan = pixels.GetRowSpan(newY);
- PixelOperations.Instance.FromBgra32Bytes(
- this.configuration,
- row.GetSpan(),
- pixelSpan,
- width);
+ if (InvertY(origin))
+ {
+ for (int y = height - 1; y >= 0; y--)
+ {
+ this.ReadBgra32Row(width, pixels, row, y);
+ }
+ }
+ else
+ {
+ for (int y = 0; y < height; y++)
+ {
+ this.ReadBgra32Row(width, pixels, row, y);
+ }
+ }
+ }
+
+ return;
+ }
+
+ for (int y = 0; y < height; y++)
+ {
+ int newY = InvertY(y, height, origin);
+ Span pixelRow = pixels.GetRowSpan(newY);
+ if (invertX)
+ {
+ for (int x = width - 1; x >= 0; x--)
+ {
+ this.ReadBgra32Pixel(x, color, pixelRow);
+ }
+ }
+ else
+ {
+ for (int x = 0; x < width; x++)
+ {
+ this.ReadBgra32Pixel(x, color, pixelRow);
+ }
}
}
}
@@ -451,18 +586,19 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// The height of the image.
/// The to assign the palette to.
/// The bytes per pixel.
- /// Indicates, if the origin of the image is top left rather the bottom left (the default).
- private void ReadRle(int width, int height, Buffer2D pixels, int bytesPerPixel, bool inverted)
+ /// The image origin.
+ private void ReadRle(int width, int height, Buffer2D pixels, int bytesPerPixel, TgaImageOrigin origin)
where TPixel : unmanaged, IPixel
{
TPixel color = default;
+ var alphaBits = this.tgaMetadata.AlphaChannelBits;
using (IMemoryOwner buffer = this.memoryAllocator.Allocate(width * height * bytesPerPixel, AllocationOptions.Clean))
{
Span bufferSpan = buffer.GetSpan();
this.UncompressRle(width, height, bufferSpan, bytesPerPixel);
for (int y = 0; y < height; y++)
{
- int newY = Invert(y, height, inverted);
+ int newY = InvertY(y, height, origin);
Span pixelRow = pixels.GetRowSpan(newY);
int rowStartIdx = y * width * bytesPerPixel;
for (int x = 0; x < width; x++)
@@ -474,19 +610,41 @@ namespace SixLabors.ImageSharp.Formats.Tga
color.FromL8(Unsafe.As(ref bufferSpan[idx]));
break;
case 2:
- // Set alpha value to 1, to treat it as opaque for Bgra5551.
- bufferSpan[idx + 1] = (byte)(bufferSpan[idx + 1] | 128);
- color.FromBgra5551(Unsafe.As(ref bufferSpan[idx]));
+ if (!this.hasAlpha)
+ {
+ // Set alpha value to 1, to treat it as opaque for Bgra5551.
+ bufferSpan[idx + 1] = (byte)(bufferSpan[idx + 1] | 128);
+ }
+
+ if (this.fileHeader.ImageType == TgaImageType.RleBlackAndWhite)
+ {
+ color.FromLa16(Unsafe.As(ref bufferSpan[idx]));
+ }
+ else
+ {
+ color.FromBgra5551(Unsafe.As(ref bufferSpan[idx]));
+ }
+
break;
case 3:
color.FromBgr24(Unsafe.As(ref bufferSpan[idx]));
break;
case 4:
- color.FromBgra32(Unsafe.As(ref bufferSpan[idx]));
+ if (this.hasAlpha)
+ {
+ color.FromBgra32(Unsafe.As(ref bufferSpan[idx]));
+ }
+ else
+ {
+ var alpha = alphaBits == 0 ? byte.MaxValue : bufferSpan[idx + 3];
+ color.FromBgra32(new Bgra32(bufferSpan[idx + 2], bufferSpan[idx + 1], bufferSpan[idx], (byte)alpha));
+ }
+
break;
}
- pixelRow[x] = color;
+ int newX = InvertX(x, width, origin);
+ pixelRow[newX] = color;
}
}
}
@@ -506,6 +664,104 @@ namespace SixLabors.ImageSharp.Formats.Tga
this.metadata);
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void ReadL8Row(int width, Buffer2D pixels, IManagedByteBuffer row, int y)
+ where TPixel : unmanaged, IPixel
+ {
+ this.currentStream.Read(row);
+ Span pixelSpan = pixels.GetRowSpan(y);
+ PixelOperations.Instance.FromL8Bytes(this.configuration, row.GetSpan(), pixelSpan, width);
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void ReadL8Pixel(TPixel color, int x, Span pixelSpan)
+ where TPixel : unmanaged, IPixel
+ {
+ var pixelValue = (byte)this.currentStream.ReadByte();
+ color.FromL8(Unsafe.As(ref pixelValue));
+ pixelSpan[x] = color;
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void ReadBgr24Pixel(TPixel color, int x, Span pixelSpan)
+ where TPixel : unmanaged, IPixel
+ {
+ this.currentStream.Read(this.scratchBuffer, 0, 3);
+ color.FromBgr24(Unsafe.As(ref this.scratchBuffer[0]));
+ pixelSpan[x] = color;
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void ReadBgr24Row(int width, Buffer2D pixels, IManagedByteBuffer row, int y)
+ where TPixel : unmanaged, IPixel
+ {
+ this.currentStream.Read(row);
+ Span pixelSpan = pixels.GetRowSpan(y);
+ PixelOperations.Instance.FromBgr24Bytes(this.configuration, row.GetSpan(), pixelSpan, width);
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void ReadBgra32Pixel(int x, TPixel color, Span pixelRow)
+ where TPixel : unmanaged, IPixel
+ {
+ this.currentStream.Read(this.scratchBuffer, 0, 4);
+ var alpha = this.tgaMetadata.AlphaChannelBits == 0 ? byte.MaxValue : this.scratchBuffer[3];
+ color.FromBgra32(new Bgra32(this.scratchBuffer[2], this.scratchBuffer[1], this.scratchBuffer[0], alpha));
+ pixelRow[x] = color;
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void ReadBgra32Row(int width, Buffer2D pixels, IManagedByteBuffer row, int y)
+ where TPixel : unmanaged, IPixel
+ {
+ this.currentStream.Read(row);
+ Span pixelSpan = pixels.GetRowSpan(y);
+ PixelOperations.Instance.FromBgra32Bytes(this.configuration, row.GetSpan(), pixelSpan, width);
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void ReadPalettedBgra16Pixel(byte[] palette, int colorMapPixelSizeInBytes, int x, TPixel color, Span pixelRow)
+ where TPixel : unmanaged, IPixel
+ {
+ int colorIndex = this.currentStream.ReadByte();
+ this.ReadPalettedBgra16Pixel(palette, colorIndex, colorMapPixelSizeInBytes, ref color);
+ pixelRow[x] = color;
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void ReadPalettedBgra16Pixel(byte[] palette, int index, int colorMapPixelSizeInBytes, ref TPixel color)
+ where TPixel : unmanaged, IPixel
+ {
+ Bgra5551 bgra = default;
+ bgra.FromBgra5551(Unsafe.As(ref palette[index * colorMapPixelSizeInBytes]));
+
+ if (!this.hasAlpha)
+ {
+ // Set alpha value to 1, to treat it as opaque.
+ bgra.PackedValue = (ushort)(bgra.PackedValue | 0x8000);
+ }
+
+ color.FromBgra5551(bgra);
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void ReadPalettedBgr24Pixel(byte[] palette, int colorMapPixelSizeInBytes, int x, TPixel color, Span pixelRow)
+ where TPixel : unmanaged, IPixel
+ {
+ int colorIndex = this.currentStream.ReadByte();
+ color.FromBgr24(Unsafe.As(ref palette[colorIndex * colorMapPixelSizeInBytes]));
+ pixelRow[x] = color;
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void ReadPalettedBgra32Pixel(byte[] palette, int colorMapPixelSizeInBytes, int x, TPixel color, Span pixelRow)
+ where TPixel : unmanaged, IPixel
+ {
+ int colorIndex = this.currentStream.ReadByte();
+ color.FromBgra32(Unsafe.As(ref palette[colorIndex * colorMapPixelSizeInBytes]));
+ pixelRow[x] = color;
+ }
+
///
/// Produce uncompressed tga data from a run length encoded stream.
///
@@ -554,18 +810,80 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// Returns the y- value based on the given height.
///
/// The y- value representing the current row.
- /// The height of the bitmap.
- /// Whether the bitmap is inverted.
+ /// The height of the image.
+ /// The image origin.
/// The representing the inverted value.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int Invert(int y, int height, bool inverted) => (!inverted) ? height - y - 1 : y;
+ private static int InvertY(int y, int height, TgaImageOrigin origin)
+ {
+ if (InvertY(origin))
+ {
+ return height - y - 1;
+ }
+
+ return y;
+ }
+
+ ///
+ /// Indicates whether the y coordinates needs to be inverted, to keep a top left origin.
+ ///
+ /// The image origin.
+ /// True, if y coordinate needs to be inverted.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static bool InvertY(TgaImageOrigin origin)
+ {
+ switch (origin)
+ {
+ case TgaImageOrigin.BottomLeft:
+ case TgaImageOrigin.BottomRight:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ ///
+ /// Returns the x- value based on the given width.
+ ///
+ /// The x- value representing the current column.
+ /// The width of the image.
+ /// The image origin.
+ /// The representing the inverted value.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static int InvertX(int x, int width, TgaImageOrigin origin)
+ {
+ if (InvertX(origin))
+ {
+ return width - x - 1;
+ }
+
+ return x;
+ }
+
+ ///
+ /// Indicates whether the x coordinates needs to be inverted, to keep a top left origin.
+ ///
+ /// The image origin.
+ /// True, if x coordinate needs to be inverted.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static bool InvertX(TgaImageOrigin origin)
+ {
+ switch (origin)
+ {
+ case TgaImageOrigin.TopRight:
+ case TgaImageOrigin.BottomRight:
+ return true;
+ default:
+ return false;
+ }
+ }
///
/// Reads the tga file header from the stream.
///
/// The containing image data.
- /// true, if the image origin is top left.
- private bool ReadFileHeader(Stream stream)
+ /// The image origin.
+ private TgaImageOrigin ReadFileHeader(Stream stream)
{
this.currentStream = stream;
@@ -577,13 +895,18 @@ namespace SixLabors.ImageSharp.Formats.Tga
this.tgaMetadata = this.metadata.GetTgaMetadata();
this.tgaMetadata.BitsPerPixel = (TgaBitsPerPixel)this.fileHeader.PixelDepth;
- // Bit at position 5 of the descriptor indicates, that the origin is top left instead of bottom right.
- if ((this.fileHeader.ImageDescriptor & (1 << 5)) != 0)
+ var alphaBits = this.fileHeader.ImageDescriptor & 0xf;
+ if (alphaBits != 0 && alphaBits != 1 && alphaBits != 8)
{
- return true;
+ TgaThrowHelper.ThrowInvalidImageContentException("Invalid alpha channel bits");
}
- return false;
+ this.tgaMetadata.AlphaChannelBits = (byte)alphaBits;
+ this.hasAlpha = alphaBits > 0;
+
+ // Bits 4 and 5 describe the image origin.
+ var origin = (TgaImageOrigin)((this.fileHeader.ImageDescriptor & 0x30) >> 4);
+ return origin;
}
}
}
diff --git a/src/ImageSharp/Formats/Tga/TgaEncoder.cs b/src/ImageSharp/Formats/Tga/TgaEncoder.cs
index e938067a1..6280b2ae6 100644
--- a/src/ImageSharp/Formats/Tga/TgaEncoder.cs
+++ b/src/ImageSharp/Formats/Tga/TgaEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
diff --git a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
index d5d7ce49e..aee3a26cc 100644
--- a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
+++ b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers.Binary;
@@ -78,8 +78,24 @@ namespace SixLabors.ImageSharp.Formats.Tga
imageType = this.compression is TgaCompression.RunLength ? TgaImageType.RleBlackAndWhite : TgaImageType.BlackAndWhite;
}
- // If compression is used, set bit 5 of the image descriptor to indicate an left top origin.
- byte imageDescriptor = (byte)(this.compression is TgaCompression.RunLength ? 32 : 0);
+ byte imageDescriptor = 0;
+ if (this.compression is TgaCompression.RunLength)
+ {
+ // If compression is used, set bit 5 of the image descriptor to indicate a left top origin.
+ imageDescriptor |= 0x20;
+ }
+
+ if (this.bitsPerPixel is TgaBitsPerPixel.Pixel32)
+ {
+ // Indicate, that 8 bit are used for the alpha channel.
+ imageDescriptor |= 0x8;
+ }
+
+ if (this.bitsPerPixel is TgaBitsPerPixel.Pixel16)
+ {
+ // Indicate, that 1 bit is used for the alpha channel.
+ imageDescriptor |= 0x1;
+ }
var fileHeader = new TgaFileHeader(
idLength: 0,
diff --git a/src/ImageSharp/Formats/Tga/TgaFileHeader.cs b/src/ImageSharp/Formats/Tga/TgaFileHeader.cs
index e2bbb6fbd..452c7e4c5 100644
--- a/src/ImageSharp/Formats/Tga/TgaFileHeader.cs
+++ b/src/ImageSharp/Formats/Tga/TgaFileHeader.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Tga/TgaFormat.cs b/src/ImageSharp/Formats/Tga/TgaFormat.cs
index badb1d77a..0afdb3075 100644
--- a/src/ImageSharp/Formats/Tga/TgaFormat.cs
+++ b/src/ImageSharp/Formats/Tga/TgaFormat.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs b/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs
index af40c333b..300172f6c 100644
--- a/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs
+++ b/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Formats/Tga/TgaImageOrigin.cs b/src/ImageSharp/Formats/Tga/TgaImageOrigin.cs
new file mode 100644
index 000000000..6e311a525
--- /dev/null
+++ b/src/ImageSharp/Formats/Tga/TgaImageOrigin.cs
@@ -0,0 +1,28 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+namespace SixLabors.ImageSharp.Formats.Tga
+{
+ internal enum TgaImageOrigin
+ {
+ ///
+ /// Bottom left origin.
+ ///
+ BottomLeft = 0,
+
+ ///
+ /// Bottom right origin.
+ ///
+ BottomRight = 1,
+
+ ///
+ /// Top left origin.
+ ///
+ TopLeft = 2,
+
+ ///
+ /// Top right origin.
+ ///
+ TopRight = 3,
+ }
+}
diff --git a/src/ImageSharp/Formats/Tga/TgaImageType.cs b/src/ImageSharp/Formats/Tga/TgaImageType.cs
index 491fd3ea7..4ee95ccb5 100644
--- a/src/ImageSharp/Formats/Tga/TgaImageType.cs
+++ b/src/ImageSharp/Formats/Tga/TgaImageType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.
ImageSharp.Formats.Tga
diff --git a/src/ImageSharp/Formats/Tga/TgaImageTypeExtensions.cs b/src/ImageSharp/Formats/Tga/TgaImageTypeExtensions.cs
index 6a30cdddd..b8b8b75c4 100644
--- a/src/ImageSharp/Formats/Tga/TgaImageTypeExtensions.cs
+++ b/src/ImageSharp/Formats/Tga/TgaImageTypeExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/TgaMetadata.cs b/src/ImageSharp/Formats/Tga/TgaMetadata.cs
index 4ce61d2e4..17225ea0c 100644
--- a/src/ImageSharp/Formats/Tga/TgaMetadata.cs
+++ b/src/ImageSharp/Formats/Tga/TgaMetadata.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Formats.Tga
{
@@ -29,6 +29,11 @@ namespace SixLabors.ImageSharp.Formats.Tga
///
public TgaBitsPerPixel BitsPerPixel { get; set; } = TgaBitsPerPixel.Pixel24;
+ ///
+ /// Gets or sets the the number of alpha bits per pixel.
+ ///
+ public byte AlphaChannelBits { get; set; } = 0;
+
///
public IDeepCloneable DeepClone() => new TgaMetadata(this);
}
diff --git a/src/ImageSharp/Formats/Tga/TgaThrowHelper.cs b/src/ImageSharp/Formats/Tga/TgaThrowHelper.cs
index 845d00922..c6df287d8 100644
--- a/src/ImageSharp/Formats/Tga/TgaThrowHelper.cs
+++ b/src/ImageSharp/Formats/Tga/TgaThrowHelper.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
@@ -9,23 +9,29 @@ namespace SixLabors.ImageSharp.Formats.Tga
internal static class TgaThrowHelper
{
///
- /// Cold path optimization for throwing -s
+ /// Cold path optimization for throwing 's
///
/// The error message for the exception.
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowImageFormatException(string errorMessage)
- {
- throw new ImageFormatException(errorMessage);
- }
+ [MethodImpl(InliningOptions.ColdPath)]
+ public static void ThrowInvalidImageContentException(string errorMessage)
+ => throw new InvalidImageContentException(errorMessage);
///
- /// Cold path optimization for throwing -s
+ /// Cold path optimization for throwing 's
///
/// The error message for the exception.
- [MethodImpl(MethodImplOptions.NoInlining)]
+ /// The exception that is the cause of the current exception, or a null reference
+ /// if no inner exception is specified.
+ [MethodImpl(InliningOptions.ColdPath)]
+ public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException)
+ => throw new InvalidImageContentException(errorMessage, innerException);
+
+ ///
+ /// Cold path optimization for throwing 's
+ ///
+ /// The error message for the exception.
+ [MethodImpl(InliningOptions.ColdPath)]
public static void ThrowNotSupportedException(string errorMessage)
- {
- throw new NotSupportedException(errorMessage);
- }
+ => throw new NotSupportedException(errorMessage);
}
}
diff --git a/src/ImageSharp/GeometryUtilities.cs b/src/ImageSharp/GeometryUtilities.cs
index 43c46f181..4e82442f6 100644
--- a/src/ImageSharp/GeometryUtilities.cs
+++ b/src/ImageSharp/GeometryUtilities.cs
@@ -1,10 +1,10 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
-namespace SixLabors
+namespace SixLabors.ImageSharp
{
///
/// Utility class for common geometric functions.
@@ -31,4 +31,4 @@ namespace SixLabors
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float RadianToDegree(float radian) => radian / (MathF.PI / 180F);
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/GraphicOptionsDefaultsExtensions.cs b/src/ImageSharp/GraphicOptionsDefaultsExtensions.cs
new file mode 100644
index 000000000..4912f55c8
--- /dev/null
+++ b/src/ImageSharp/GraphicOptionsDefaultsExtensions.cs
@@ -0,0 +1,100 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using System;
+using SixLabors.ImageSharp.Processing;
+
+namespace SixLabors.ImageSharp
+{
+ ///
+ /// Adds extensions that allow the processing of images to the type.
+ ///
+ public static class GraphicOptionsDefaultsExtensions
+ {
+ ///
+ /// Sets the default options against the image processing context.
+ ///
+ /// The image processing context to store default against.
+ /// The action to update instance of the default options used.
+ /// The passed in to allow chaining.
+ public static IImageProcessingContext SetGraphicsOptions(this IImageProcessingContext context, Action optionsBuilder)
+ {
+ var cloned = context.GetGraphicsOptions().DeepClone();
+ optionsBuilder(cloned);
+ context.Properties[typeof(GraphicsOptions)] = cloned;
+ return context;
+ }
+
+ ///
+ /// Sets the default options against the configuration.
+ ///
+ /// The configuration to store default against.
+ /// The default options to use.
+ public static void SetGraphicsOptions(this Configuration configuration, Action optionsBuilder)
+ {
+ var cloned = configuration.GetGraphicsOptions().DeepClone();
+ optionsBuilder(cloned);
+ configuration.Properties[typeof(GraphicsOptions)] = cloned;
+ }
+
+ ///
+ /// Sets the default options against the image processing context.
+ ///
+ /// The image processing context to store default against.
+ /// The default options to use.
+ /// The passed in to allow chaining.
+ public static IImageProcessingContext SetGraphicsOptions(this IImageProcessingContext context, GraphicsOptions options)
+ {
+ context.Properties[typeof(GraphicsOptions)] = options;
+ return context;
+ }
+
+ ///
+ /// Sets the default options against the configuration.
+ ///
+ /// The configuration to store default against.
+ /// The default options to use.
+ public static void SetGraphicsOptions(this Configuration configuration, GraphicsOptions options)
+ {
+ configuration.Properties[typeof(GraphicsOptions)] = options;
+ }
+
+ ///
+ /// Gets the default options against the image processing context.
+ ///
+ /// The image processing context to retrieve defaults from.
+ /// The globaly configued default options.
+ 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.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
+ return configOptions;
+ }
+
+ ///
+ /// Gets the default options against the image processing context.
+ ///
+ /// The configuration to retrieve defaults from.
+ /// The globaly configued default options.
+ public static GraphicsOptions GetGraphicsOptions(this Configuration configuration)
+ {
+ if (configuration.Properties.TryGetValue(typeof(GraphicsOptions), out var options) && options is GraphicsOptions go)
+ {
+ return go;
+ }
+
+ var configOptions = new GraphicsOptions();
+
+ // capture the fallback so the same instance will always be returned in case its mutated
+ configuration.Properties[typeof(GraphicsOptions)] = configOptions;
+ return configOptions;
+ }
+ }
+}
diff --git a/src/ImageSharp/GraphicsOptions.cs b/src/ImageSharp/GraphicsOptions.cs
index 47b930e65..8c3060547 100644
--- a/src/ImageSharp/GraphicsOptions.cs
+++ b/src/ImageSharp/GraphicsOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/IConfigurationModule.cs b/src/ImageSharp/IConfigurationModule.cs
index 3ca8ed918..a47bb89bb 100644
--- a/src/ImageSharp/IConfigurationModule.cs
+++ b/src/ImageSharp/IConfigurationModule.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp
{
diff --git a/src/ImageSharp/IDeepCloneable.cs b/src/ImageSharp/IDeepCloneable.cs
index f80247a5d..caf837b66 100644
--- a/src/ImageSharp/IDeepCloneable.cs
+++ b/src/ImageSharp/IDeepCloneable.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp
{
diff --git a/src/ImageSharp/IImage.cs b/src/ImageSharp/IImage.cs
index 0d4dc3c9d..8e9df0108 100644
--- a/src/ImageSharp/IImage.cs
+++ b/src/ImageSharp/IImage.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/IImageInfo.cs b/src/ImageSharp/IImageInfo.cs
index b270c2c4d..92ff5c5c3 100644
--- a/src/ImageSharp/IImageInfo.cs
+++ b/src/ImageSharp/IImageInfo.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/IO/DoubleBufferedStreamReader.cs b/src/ImageSharp/IO/DoubleBufferedStreamReader.cs
index 0345717d2..f0d9620eb 100644
--- a/src/ImageSharp/IO/DoubleBufferedStreamReader.cs
+++ b/src/ImageSharp/IO/DoubleBufferedStreamReader.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/IO/IFileSystem.cs b/src/ImageSharp/IO/IFileSystem.cs
index 9dc97afb6..75d844dab 100644
--- a/src/ImageSharp/IO/IFileSystem.cs
+++ b/src/ImageSharp/IO/IFileSystem.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
diff --git a/src/ImageSharp/IO/LocalFileSystem.cs b/src/ImageSharp/IO/LocalFileSystem.cs
index 11f3d7972..4a3b68ea9 100644
--- a/src/ImageSharp/IO/LocalFileSystem.cs
+++ b/src/ImageSharp/IO/LocalFileSystem.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.IO;
diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs
index c28a21452..cb6f01ce4 100644
--- a/src/ImageSharp/Image.Decode.cs
+++ b/src/ImageSharp/Image.Decode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.IO;
diff --git a/src/ImageSharp/Image.FromBytes.cs b/src/ImageSharp/Image.FromBytes.cs
index 0850e2213..3cd6228a1 100644
--- a/src/ImageSharp/Image.FromBytes.cs
+++ b/src/ImageSharp/Image.FromBytes.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.IO;
@@ -17,23 +17,71 @@ namespace SixLabors.ImageSharp
/// By reading the header on the provided byte array this calculates the images format.
///
/// The byte array containing encoded image data to read the header from.
+ /// The data is null.
/// The format or null if none found.
public static IImageFormat DetectFormat(byte[] data)
- {
- return DetectFormat(Configuration.Default, data);
- }
+ => DetectFormat(Configuration.Default, data);
///
/// By reading the header on the provided byte array this calculates the images format.
///
- /// The configuration.
+ /// The configuration.
/// The byte array containing encoded image data to read the header from.
+ /// The configuration is null.
+ /// The data is null.
/// The mime type or null if none found.
- public static IImageFormat DetectFormat(Configuration config, byte[] data)
+ public static IImageFormat DetectFormat(Configuration configuration, byte[] data)
+ {
+ Guard.NotNull(data, nameof(data));
+
+ using (var stream = new MemoryStream(data, 0, data.Length, false, true))
+ {
+ return DetectFormat(configuration, stream);
+ }
+ }
+
+ ///
+ /// Reads the raw image information from the specified stream without fully decoding it.
+ ///
+ /// The byte array containing encoded image data to read the header from.
+ /// The data is null.
+ /// The data is not readable.
+ ///
+ /// The or null if suitable info detector not found.
+ ///
+ public static IImageInfo Identify(byte[] data) => Identify(data, out IImageFormat _);
+
+ ///
+ /// Reads the raw image information from the specified stream without fully decoding it.
+ ///
+ /// The byte array containing encoded image data to read the header from.
+ /// The format type of the decoded image.
+ /// The data is null.
+ /// The data is not readable.
+ ///
+ /// The or null if suitable info detector not found.
+ ///
+ public static IImageInfo Identify(byte[] data, out IImageFormat format) => Identify(Configuration.Default, data, out format);
+
+ ///
+ /// Reads the raw image information from the specified stream without fully decoding it.
+ ///
+ /// The configuration.
+ /// The byte array containing encoded image data to read the header from.
+ /// The format type of the decoded image.
+ /// The configuration is null.
+ /// The data is null.
+ /// The data is not readable.
+ ///
+ /// The or null if suitable info detector is not found.
+ ///
+ public static IImageInfo Identify(Configuration configuration, byte[] data, out IImageFormat format)
{
- using (var stream = new MemoryStream(data))
+ Guard.NotNull(data, nameof(data));
+
+ using (var stream = new MemoryStream(data, 0, data.Length, false, true))
{
- return DetectFormat(config, stream);
+ return Identify(configuration, stream, out format);
}
}
@@ -41,14 +89,20 @@ namespace SixLabors.ImageSharp
/// Load a new instance of from the given encoded byte array.
///
/// The byte array containing image data.
+ /// The configuration is null.
+ /// The data is null.
/// A new .
- public static Image Load(byte[] data) => Load(Configuration.Default, data);
+ public static Image Load(byte[] data)
+ => Load(Configuration.Default, data);
///
/// Load a new instance of from the given encoded byte array.
///
/// The byte array containing encoded image data.
/// The pixel format.
+ /// The data is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
public static Image Load(byte[] data)
where TPixel : unmanaged, IPixel
@@ -60,6 +114,9 @@ namespace SixLabors.ImageSharp
/// The byte array containing image data.
/// The mime type of the decoded image.
/// The pixel format.
+ /// The data is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
public static Image Load(byte[] data, out IImageFormat format)
where TPixel : unmanaged, IPixel
@@ -68,33 +125,45 @@ namespace SixLabors.ImageSharp
///
/// Load a new instance of from the given encoded byte array.
///
- /// The configuration options.
+ /// The configuration options.
/// The byte array containing encoded image data.
/// The pixel format.
+ /// The configuration is null.
+ /// The data is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
- public static Image Load(Configuration config, byte[] data)
+ public static Image Load(Configuration configuration, byte[] data)
where TPixel : unmanaged, IPixel
{
+ Guard.NotNull(data, nameof(data));
+
using (var stream = new MemoryStream(data, 0, data.Length, false, true))
{
- return Load(config, stream);
+ return Load(configuration, stream);
}
}
///
/// Load a new instance of from the given encoded byte array.
///
- /// The configuration options.
+ /// The configuration options.
/// The byte array containing encoded image data.
/// The of the decoded image.
/// The pixel format.
+ /// The configuration is null.
+ /// The data is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
- public static Image Load(Configuration config, byte[] data, out IImageFormat format)
+ public static Image Load(Configuration configuration, byte[] data, out IImageFormat format)
where TPixel : unmanaged, IPixel
{
+ Guard.NotNull(data, nameof(data));
+
using (var stream = new MemoryStream(data, 0, data.Length, false, true))
{
- return Load(config, stream, out format);
+ return Load(configuration, stream, out format);
}
}
@@ -104,10 +173,15 @@ namespace SixLabors.ImageSharp
/// The byte array containing encoded image data.
/// The decoder.
/// The pixel format.
+ /// The data is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
public static Image Load(byte[] data, IImageDecoder decoder)
where TPixel : unmanaged, IPixel
{
+ Guard.NotNull(data, nameof(data));
+
using (var stream = new MemoryStream(data, 0, data.Length, false, true))
{
return Load(stream, decoder);
@@ -117,24 +191,30 @@ namespace SixLabors.ImageSharp
///
/// Load a new instance of from the given encoded byte array.
///
- /// The Configuration.
+ /// The Configuration.
/// The byte array containing encoded image data.
/// The decoder.
/// The pixel format.
+ /// The configuration is null.
+ /// The data is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
- public static Image Load(Configuration config, byte[] data, IImageDecoder decoder)
+ public static Image Load(Configuration configuration, byte[] data, IImageDecoder decoder)
where TPixel : unmanaged, IPixel
{
+ Guard.NotNull(data, nameof(data));
+
using (var stream = new MemoryStream(data, 0, data.Length, false, true))
{
- return Load(config, stream, decoder);
+ return Load(configuration, stream, decoder);
}
}
///
- /// By reading the header on the provided byte array this calculates the images format.
+ /// By reading the header on the provided byte span this calculates the images format.
///
- /// The byte array containing encoded image data to read the header from.
+ /// The byte span containing encoded image data to read the header from.
/// The format or null if none found.
public static IImageFormat DetectFormat(ReadOnlySpan data)
{
@@ -142,20 +222,23 @@ namespace SixLabors.ImageSharp
}
///
- /// By reading the header on the provided byte array this calculates the images format.
+ /// By reading the header on the provided byte span this calculates the images format.
///
- /// The configuration.
- /// The byte array containing encoded image data to read the header from.
+ /// The configuration.
+ /// The byte span containing encoded image data to read the header from.
+ /// The configuration is null.
/// The mime type or null if none found.
- public static IImageFormat DetectFormat(Configuration config, ReadOnlySpan data)
+ public static IImageFormat DetectFormat(Configuration configuration, ReadOnlySpan data)
{
- int maxHeaderSize = config.MaxHeaderSize;
+ Guard.NotNull(configuration, nameof(configuration));
+
+ int maxHeaderSize = configuration.MaxHeaderSize;
if (maxHeaderSize <= 0)
{
return null;
}
- foreach (IImageFormatDetector detector in config.ImageFormatsManager.FormatDetectors)
+ foreach (IImageFormatDetector detector in configuration.ImageFormatsManager.FormatDetectors)
{
IImageFormat f = detector.DetectFormat(data);
@@ -173,28 +256,34 @@ namespace SixLabors.ImageSharp
///
/// The byte span containing encoded image data.
/// The pixel format.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
public static Image Load(ReadOnlySpan data)
where TPixel : unmanaged, IPixel
=> Load(Configuration.Default, data);
///
- /// Load a new instance of from the given encoded byte array.
+ /// Load a new instance of from the given encoded byte span.
///
/// The byte span containing image data.
/// The mime type of the decoded image.
/// The pixel format.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
public static Image Load(ReadOnlySpan data, out IImageFormat format)
where TPixel : unmanaged, IPixel
=> Load(Configuration.Default, data, out format);
///
- /// Load a new instance of from the given encoded byte array.
+ /// Load a new instance of from the given encoded byte span.
///
/// The byte span containing encoded image data.
/// The decoder.
/// The pixel format.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
public static Image Load(ReadOnlySpan data, IImageDecoder decoder)
where TPixel : unmanaged, IPixel
@@ -203,18 +292,21 @@ namespace SixLabors.ImageSharp
///
/// Load a new instance of from the given encoded byte span.
///
- /// The configuration options.
+ /// The configuration options.
/// The byte span containing encoded image data.
/// The pixel format.
+ /// The configuration is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
- public static unsafe Image Load(Configuration config, ReadOnlySpan data)
+ public static unsafe Image Load(Configuration configuration, ReadOnlySpan data)
where TPixel : unmanaged, IPixel
{
fixed (byte* ptr = &data.GetPinnableReference())
{
using (var stream = new UnmanagedMemoryStream(ptr, data.Length))
{
- return Load(config, stream);
+ return Load(configuration, stream);
}
}
}
@@ -222,13 +314,16 @@ namespace SixLabors.ImageSharp
///
/// Load a new instance of from the given encoded byte span.
///
- /// The Configuration.
+ /// The Configuration.
/// The byte span containing image data.
/// The decoder.
/// The pixel format.
+ /// The configuration is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
public static unsafe Image Load(
- Configuration config,
+ Configuration configuration,
ReadOnlySpan data,
IImageDecoder decoder)
where TPixel : unmanaged, IPixel
@@ -237,7 +332,7 @@ namespace SixLabors.ImageSharp
{
using (var stream = new UnmanagedMemoryStream(ptr, data.Length))
{
- return Load(config, stream, decoder);
+ return Load(configuration, stream, decoder);
}
}
}
@@ -245,13 +340,16 @@ namespace SixLabors.ImageSharp
///
/// Load a new instance of from the given encoded byte span.
///
- /// The configuration options.
+ /// The configuration options.
/// The byte span containing image data.
/// The of the decoded image.
/// The pixel format.
+ /// The configuration is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
public static unsafe Image Load(
- Configuration config,
+ Configuration configuration,
ReadOnlySpan data,
out IImageFormat format)
where TPixel : unmanaged, IPixel
@@ -260,7 +358,7 @@ namespace SixLabors.ImageSharp
{
using (var stream = new UnmanagedMemoryStream(ptr, data.Length))
{
- return Load(config, stream, out format);
+ return Load(configuration, stream, out format);
}
}
}
@@ -270,53 +368,74 @@ namespace SixLabors.ImageSharp
///
/// The byte array containing image data.
/// The detected format.
+ /// The configuration is null.
+ /// The data is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
- public static Image Load(byte[] data, out IImageFormat format) =>
- Load(Configuration.Default, data, out format);
+ public static Image Load(byte[] data, out IImageFormat format)
+ => Load(Configuration.Default, data, out format);
///
/// Load a new instance of from the given encoded byte array.
///
/// The byte array containing encoded image data.
/// The decoder.
+ /// The data is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
- public static Image Load(byte[] data, IImageDecoder decoder) => Load(Configuration.Default, data, decoder);
+ public static Image Load(byte[] data, IImageDecoder decoder)
+ => Load(Configuration.Default, data, decoder);
///
/// Load a new instance of from the given encoded byte array.
///
- /// The config for the decoder.
+ /// The configuration for the decoder.
/// The byte array containing encoded image data.
+ /// The configuration is null.
+ /// The data is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
- public static Image Load(Configuration config, byte[] data) => Load(config, data, out _);
+ public static Image Load(Configuration configuration, byte[] data)
+ => Load(configuration, data, out _);
///
/// Load a new instance of from the given encoded byte array.
///
- /// The config for the decoder.
+ /// The configuration for the decoder.
/// The byte array containing image data.
/// The decoder.
+ /// The configuration is null.
+ /// The data is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
- public static Image Load(Configuration config, byte[] data, IImageDecoder decoder)
+ public static Image Load(Configuration configuration, byte[] data, IImageDecoder decoder)
{
using (var stream = new MemoryStream(data, 0, data.Length, false, true))
{
- return Load(config, stream, decoder);
+ return Load(configuration, stream, decoder);
}
}
///
/// Load a new instance of from the given encoded byte array.
///
- /// The config for the decoder.
+ /// The configuration for the decoder.
/// The byte array containing image data.
/// The mime type of the decoded image.
+ /// The configuration is null.
+ /// The data is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
- public static Image Load(Configuration config, byte[] data, out IImageFormat format)
+ public static Image Load(Configuration configuration, byte[] data, out IImageFormat format)
{
using (var stream = new MemoryStream(data, 0, data.Length, false, true))
{
- return Load(config, stream, out format);
+ return Load(configuration, stream, out format);
}
}
@@ -324,44 +443,60 @@ namespace SixLabors.ImageSharp
/// Load a new instance of from the given encoded byte span.
///
/// The byte span containing image data.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
- public static Image Load(ReadOnlySpan data) => Load(Configuration.Default, data);
+ public static Image Load(ReadOnlySpan data)
+ => Load(Configuration.Default, data);
///
/// Load a new instance of from the given encoded byte span.
///
/// The byte span containing image data.
/// The decoder.
+ /// The data is null.
+ /// The decoder is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
- public static Image Load(ReadOnlySpan data, IImageDecoder decoder) =>
- Load(Configuration.Default, data, decoder);
+ public static Image Load(ReadOnlySpan data, IImageDecoder decoder)
+ => Load(Configuration.Default, data, decoder);
///
/// Load a new instance of from the given encoded byte array.
///
/// The byte span containing image data.
/// The detected format.
+ /// The decoder is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
- public static Image Load(ReadOnlySpan data, out IImageFormat format) =>
- Load(Configuration.Default, data, out format);
+ public static Image Load(ReadOnlySpan data, out IImageFormat format)
+ => Load(Configuration.Default, data, out format);
///
/// Decodes a new instance of from the given encoded byte span.
///
- /// The configuration options.
+ /// The configuration options.
/// The byte span containing image data.
/// The .
- public static Image Load(Configuration config, ReadOnlySpan data) => Load(config, data, out _);
+ public static Image Load(Configuration configuration, ReadOnlySpan data)
+ => Load(configuration, data, out _);
///
/// Load a new instance of from the given encoded byte span.
///
- /// The Configuration.
+ /// The Configuration.
/// The byte span containing image data.
/// The decoder.
+ /// The configuration is null.
+ /// The decoder is null.
+ /// The stream is not readable.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
public static unsafe Image Load(
- Configuration config,
+ Configuration configuration,
ReadOnlySpan data,
IImageDecoder decoder)
{
@@ -369,7 +504,7 @@ namespace SixLabors.ImageSharp
{
using (var stream = new UnmanagedMemoryStream(ptr, data.Length))
{
- return Load(config, stream, decoder);
+ return Load(configuration, stream, decoder);
}
}
}
@@ -377,12 +512,15 @@ namespace SixLabors.ImageSharp
///
/// Load a new instance of from the given encoded byte span.
///
- /// The configuration options.
+ /// The configuration options.
/// The byte span containing image data.
/// The of the decoded image.>
+ /// The configuration is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
public static unsafe Image Load(
- Configuration config,
+ Configuration configuration,
ReadOnlySpan data,
out IImageFormat format)
{
@@ -390,7 +528,7 @@ namespace SixLabors.ImageSharp
{
using (var stream = new UnmanagedMemoryStream(ptr, data.Length))
{
- return Load(config, stream, out format);
+ return Load(configuration, stream, out format);
}
}
}
diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs
index 45ea378cf..91b6ca3a7 100644
--- a/src/ImageSharp/Image.FromFile.cs
+++ b/src/ImageSharp/Image.FromFile.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.IO;
@@ -19,22 +19,62 @@ namespace SixLabors.ImageSharp
/// The image file to open and to read the header from.
/// The mime type or null if none found.
public static IImageFormat DetectFormat(string filePath)
- {
- return DetectFormat(Configuration.Default, filePath);
- }
+ => DetectFormat(Configuration.Default, filePath);
///
/// By reading the header on the provided file this calculates the images mime type.
///
- /// The configuration.
+ /// The configuration.
/// The image file to open and to read the header from.
+ /// The configuration is null.
/// The mime type or null if none found.
- public static IImageFormat DetectFormat(Configuration config, string filePath)
+ public static IImageFormat DetectFormat(Configuration configuration, string filePath)
+ {
+ Guard.NotNull(configuration, nameof(configuration));
+
+ using (Stream file = configuration.FileSystem.OpenRead(filePath))
+ {
+ return DetectFormat(configuration, file);
+ }
+ }
+
+ ///
+ /// Reads the raw image information from the specified stream without fully decoding it.
+ ///
+ /// The image file to open and to read the header from.
+ ///
+ /// The or null if suitable info detector not found.
+ ///
+ public static IImageInfo Identify(string filePath)
+ => Identify(filePath, out IImageFormat _);
+
+ ///
+ /// Reads the raw image information from the specified stream without fully decoding it.
+ ///
+ /// The image file to open and to read the header from.
+ /// The format type of the decoded image.
+ ///
+ /// The or null if suitable info detector not found.
+ ///
+ public static IImageInfo Identify(string filePath, out IImageFormat format)
+ => Identify(Configuration.Default, filePath, out format);
+
+ ///
+ /// Reads the raw image information from the specified stream without fully decoding it.
+ ///
+ /// The configuration.
+ /// The image file to open and to read the header from.
+ /// The format type of the decoded image.
+ /// The configuration is null.
+ ///
+ /// The or null if suitable info detector is not found.
+ ///
+ public static IImageInfo Identify(Configuration configuration, string filePath, out IImageFormat format)
{
- config = config ?? Configuration.Default;
- using (Stream file = config.FileSystem.OpenRead(filePath))
+ Guard.NotNull(configuration, nameof(configuration));
+ using (Stream file = configuration.FileSystem.OpenRead(filePath))
{
- return DetectFormat(config, file);
+ return Identify(configuration, file, out format);
}
}
@@ -46,7 +86,8 @@ namespace SixLabors.ImageSharp
/// Thrown if the stream is not readable nor seekable.
///
/// The .
- public static Image Load(string path) => Load(Configuration.Default, path);
+ public static Image Load(string path)
+ => Load(Configuration.Default, path);
///
/// Create a new instance of the class from the given file.
@@ -57,34 +98,42 @@ namespace SixLabors.ImageSharp
/// Thrown if the stream is not readable nor seekable.
///
/// A new .
- public static Image Load(string path, out IImageFormat format) => Load(Configuration.Default, path, out format);
+ public static Image Load(string path, out IImageFormat format)
+ => Load(Configuration.Default, path, out format);
///
/// Create a new instance of the class from the given file.
///
- /// The config for the decoder.
+ /// The configuration for the decoder.
/// The file path to the image.
- ///
- /// Thrown if the stream is not readable nor seekable.
- ///
+ /// The configuration is null.
+ /// The path is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
- public static Image Load(Configuration config, string path) => Load(config, path, out _);
+ public static Image Load(Configuration configuration, string path)
+ => Load(configuration, path, out _);
///
/// Create a new instance of the class from the given file.
///
- /// The Configuration.
+ /// The Configuration.
/// The file path to the image.
/// The decoder.
- ///
- /// Thrown if the stream is not readable nor seekable.
- ///
+ /// The configuration is null.
+ /// The path is null.
+ /// The decoder is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
- public static Image Load(Configuration config, string path, IImageDecoder decoder)
+ public static Image Load(Configuration configuration, string path, IImageDecoder decoder)
{
- using (Stream stream = config.FileSystem.OpenRead(path))
+ Guard.NotNull(configuration, nameof(configuration));
+ Guard.NotNull(path, nameof(path));
+
+ using (Stream stream = configuration.FileSystem.OpenRead(path))
{
- return Load(config, stream, decoder);
+ return Load(configuration, stream, decoder);
}
}
@@ -93,79 +142,85 @@ namespace SixLabors.ImageSharp
///
/// The file path to the image.
/// The decoder.
- ///
- /// Thrown if the stream is not readable nor seekable.
- ///
+ /// The path is null.
+ /// The decoder is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
- public static Image Load(string path, IImageDecoder decoder) => Load(Configuration.Default, path, decoder);
+ public static Image Load(string path, IImageDecoder decoder)
+ => Load(Configuration.Default, path, decoder);
///
/// Create a new instance of the class from the given file.
///
/// The file path to the image.
- ///
- /// Thrown if the stream is not readable nor seekable.
- ///
+ /// The path is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The pixel format.
/// A new .
public static Image Load(string path)
where TPixel : unmanaged, IPixel
- {
- return Load(Configuration.Default, path);
- }
+ => Load(Configuration.Default, path);
///
/// Create a new instance of the class from the given file.
///
/// The file path to the image.
/// The mime type of the decoded image.
- ///
- /// Thrown if the stream is not readable nor seekable.
- ///
+ /// The path is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The pixel format.
/// A new .
public static Image Load(string path, out IImageFormat format)
where TPixel : unmanaged, IPixel
- {
- return Load(Configuration.Default, path, out format);
- }
+ => Load(Configuration.Default, path, out format);
///
/// Create a new instance of the class from the given file.
///
- /// The configuration options.
+ /// The configuration options.
/// The file path to the image.
- ///
- /// Thrown if the stream is not readable nor seekable.
- ///
+ /// The configuration is null.
+ /// The path is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The pixel format.
/// A new .
- public static Image Load(Configuration config, string path)
+ public static Image Load(Configuration configuration, string path)
where TPixel : unmanaged, IPixel
{
- using (Stream stream = config.FileSystem.OpenRead(path))
+ Guard.NotNull(configuration, nameof(configuration));
+ Guard.NotNull(path, nameof(path));
+
+ using (Stream stream = configuration.FileSystem.OpenRead(path))
{
- return Load(config, stream);
+ return Load(configuration, stream);
}
}
///
/// Create a new instance of the class from the given file.
///
- /// The configuration options.
+ /// The configuration options.
/// The file path to the image.
/// The mime type of the decoded image.
- ///
- /// Thrown if the stream is not readable nor seekable.
- ///
+ /// The configuration is null.
+ /// The path is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The pixel format.
/// A new .
- public static Image Load(Configuration config, string path, out IImageFormat format)
+ public static Image Load(Configuration configuration, string path, out IImageFormat format)
where TPixel : unmanaged, IPixel
{
- using (Stream stream = config.FileSystem.OpenRead(path))
+ Guard.NotNull(configuration, nameof(configuration));
+ Guard.NotNull(path, nameof(path));
+
+ using (Stream stream = configuration.FileSystem.OpenRead(path))
{
- return Load(config, stream, out format);
+ return Load(configuration, stream, out format);
}
}
@@ -173,18 +228,22 @@ namespace SixLabors.ImageSharp
/// Create a new instance of the class from the given file.
/// The pixel type is selected by the decoder.
///
- /// The configuration options.
+ /// The configuration options.
/// The file path to the image.
/// The mime type of the decoded image.
- ///
- /// Thrown if the stream is not readable nor seekable.
- ///
+ /// The configuration is null.
+ /// The path is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
- public static Image Load(Configuration config, string path, out IImageFormat format)
+ public static Image Load(Configuration configuration, string path, out IImageFormat format)
{
- using (Stream stream = config.FileSystem.OpenRead(path))
+ Guard.NotNull(configuration, nameof(configuration));
+ Guard.NotNull(path, nameof(path));
+
+ using (Stream stream = configuration.FileSystem.OpenRead(path))
{
- return Load(config, stream, out format);
+ return Load(configuration, stream, out format);
}
}
@@ -193,34 +252,37 @@ namespace SixLabors.ImageSharp
///
/// The file path to the image.
/// The decoder.
- ///
- /// Thrown if the stream is not readable nor seekable.
- ///
+ /// The path is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The pixel format.
/// A new .
public static Image Load(string path, IImageDecoder decoder)
where TPixel : unmanaged, IPixel
- {
- return Load(Configuration.Default, path, decoder);
- }
+ => Load(Configuration.Default, path, decoder);
///
/// Create a new instance of the class from the given file.
///
- /// The Configuration.
+ /// The Configuration.
/// The file path to the image.
/// The decoder.
- ///
- /// Thrown if the stream is not readable nor seekable.
- ///
+ /// The configuration is null.
+ /// The path is null.
+ /// The decoder is null.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The pixel format.
/// A new .
- public static Image Load(Configuration config, string path, IImageDecoder decoder)
+ public static Image Load(Configuration configuration, string path, IImageDecoder decoder)
where TPixel : unmanaged, IPixel
{
- using (Stream stream = config.FileSystem.OpenRead(path))
+ Guard.NotNull(configuration, nameof(configuration));
+ Guard.NotNull(path, nameof(path));
+
+ using (Stream stream = configuration.FileSystem.OpenRead(path))
{
- return Load(config, stream, decoder);
+ return Load(configuration, stream, decoder);
}
}
}
diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs
index d756ff7ac..bcd11845b 100644
--- a/src/ImageSharp/Image.FromStream.cs
+++ b/src/ImageSharp/Image.FromStream.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
@@ -19,54 +19,67 @@ namespace SixLabors.ImageSharp
/// By reading the header on the provided stream this calculates the images format type.
///
/// The image stream to read the header from.
- /// Thrown if the stream is not readable.
+ /// The stream is null.
+ /// The stream is not readable.
/// The format type or null if none found.
- public static IImageFormat DetectFormat(Stream stream) => DetectFormat(Configuration.Default, stream);
+ public static IImageFormat DetectFormat(Stream stream)
+ => DetectFormat(Configuration.Default, stream);
///
/// By reading the header on the provided stream this calculates the images format type.
///
- /// The configuration.
+ /// The configuration.
/// The image stream to read the header from.
- /// Thrown if the stream is not readable.
+ /// The configuration is null.
+ /// The stream is null.
+ /// The stream is not readable.
/// The format type or null if none found.
- public static IImageFormat DetectFormat(Configuration config, Stream stream)
- => WithSeekableStream(config, stream, s => InternalDetectFormat(s, config));
+ public static IImageFormat DetectFormat(Configuration configuration, Stream stream)
+ => WithSeekableStream(configuration, stream, s => InternalDetectFormat(s, configuration));
///
- /// By reading the header on the provided stream this reads the raw image information.
+ /// Reads the raw image information from the specified stream without fully decoding it.
///
/// The image stream to read the header from.
- /// Thrown if the stream is not readable.
+ /// The stream is null.
+ /// The stream is not readable.
+ /// Image contains invalid content.
///
/// The or null if suitable info detector not found.
///
- public static IImageInfo Identify(Stream stream) => Identify(stream, out IImageFormat _);
+ public static IImageInfo Identify(Stream stream)
+ => Identify(stream, out IImageFormat _);
///
- /// By reading the header on the provided stream this reads the raw image information.
+ /// Reads the raw image information from the specified stream without fully decoding it.
///
/// The image stream to read the header from.
/// The format type of the decoded image.
- /// Thrown if the stream is not readable.
+ /// The stream is null.
+ /// The stream is not readable.
+ /// Image contains invalid content.
///
/// The or null if suitable info detector not found.
///
- public static IImageInfo Identify(Stream stream, out IImageFormat format) => Identify(Configuration.Default, stream, out format);
+ public static IImageInfo Identify(Stream stream, out IImageFormat format)
+ => Identify(Configuration.Default, stream, out format);
///
/// Reads the raw image information from the specified stream without fully decoding it.
///
- /// The configuration.
+ /// The configuration.
/// The image stream to read the information from.
/// The format type of the decoded image.
- /// Thrown if the stream is not readable.
+ /// The configuration is null.
+ /// The stream is null.
+ /// The stream is not readable.
+ /// Image contains invalid content.
///
/// The or null if suitable info detector is not found.
///
- public static IImageInfo Identify(Configuration config, Stream stream, out IImageFormat format)
+ public static IImageInfo Identify(Configuration configuration, Stream stream, out IImageFormat format)
{
- (IImageInfo info, IImageFormat format) data = WithSeekableStream(config, stream, s => InternalIdentity(s, config ?? Configuration.Default));
+ (IImageInfo info, IImageFormat format) data = WithSeekableStream(configuration, stream, s => InternalIdentity(s, configuration ?? Configuration.Default));
format = data.format;
return data.info;
@@ -78,18 +91,23 @@ namespace SixLabors.ImageSharp
///
/// The stream containing image information.
/// The format type of the decoded image.
- /// Thrown if the stream is not readable.
- /// Image cannot be loaded.
+ /// The stream is null.
+ /// The stream is not readable.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
- public static Image Load(Stream stream, out IImageFormat format) => Load(Configuration.Default, stream, out format);
+ public static Image Load(Stream stream, out IImageFormat format)
+ => Load(Configuration.Default, stream, out format);
///
/// Decode a new instance of the class from the given stream.
/// The pixel format is selected by the decoder.
///
/// The stream containing image information.
- /// Thrown if the stream is not readable.
- /// Image cannot be loaded.
+ /// The stream is null.
+ /// The stream is not readable.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
public static Image Load(Stream stream) => Load(Configuration.Default, stream);
@@ -99,66 +117,86 @@ namespace SixLabors.ImageSharp
///
/// The stream containing image information.
/// The decoder.
- /// Thrown if the stream is not readable.
- /// Image cannot be loaded.
+ /// The stream is null.
+ /// The decoder is null.
+ /// The stream is not readable.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The .
- public static Image Load(Stream stream, IImageDecoder decoder) => Load(Configuration.Default, stream, decoder);
+ public static Image Load(Stream stream, IImageDecoder decoder)
+ => Load(Configuration.Default, stream, decoder);
///
/// Decode a new instance of the class from the given stream.
/// The pixel format is selected by the decoder.
///
- /// The config for the decoder.
+ /// The configuration for the decoder.
/// The stream containing image information.
/// The decoder.
- /// Thrown if the stream is not readable.
- /// Image cannot be loaded.
+ /// The configuration is null.
+ /// The stream is null.
+ /// The decoder is null.
+ /// The stream is not readable.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .>
- public static Image Load(Configuration config, Stream stream, IImageDecoder decoder) =>
- WithSeekableStream(config, stream, s => decoder.Decode(config, s));
+ public static Image Load(Configuration configuration, Stream stream, IImageDecoder decoder)
+ {
+ Guard.NotNull(decoder, nameof(decoder));
+ return WithSeekableStream(configuration, stream, s => decoder.Decode(configuration, s));
+ }
///
/// Decode a new instance of the class from the given stream.
///
- /// The config for the decoder.
+ /// The configuration for the decoder.
/// The stream containing image information.
- /// Thrown if the stream is not readable.
- /// Image cannot be loaded.
+ /// The configuration is null.
+ /// The stream is null.
+ /// The stream is not readable.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .>
- public static Image Load(Configuration config, Stream stream) => Load(config, stream, out _);
+ public static Image Load(Configuration configuration, Stream stream) => Load(configuration, stream, out _);
///
/// Create a new instance of the class from the given stream.
///
/// The stream containing image information.
- /// Thrown if the stream is not readable.
- /// Image cannot be loaded.
+ /// The stream is null.
+ /// The stream is not readable.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The pixel format.
/// A new .>
public static Image Load(Stream stream)
where TPixel : unmanaged, IPixel
- => Load(null, stream);
+ => Load(Configuration.Default, stream);
///
/// Create a new instance of the class from the given stream.
///
/// The stream containing image information.
/// The format type of the decoded image.
- /// Thrown if the stream is not readable.
- /// Image cannot be loaded.
+ /// The stream is null.
+ /// The stream is not readable.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The pixel format.
/// A new .>
public static Image Load(Stream stream, out IImageFormat format)
where TPixel : unmanaged, IPixel
- => Load(null, stream, out format);
+ => Load(Configuration.Default, stream, out format);
///
/// Create a new instance of the class from the given stream.
///
/// The stream containing image information.
/// The decoder.
- /// Thrown if the stream is not readable.
- /// Image cannot be loaded.
+ /// The stream is null.
+ /// The stream is not readable.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The pixel format.
/// A new .>
public static Image Load(Stream stream, IImageDecoder decoder)
@@ -168,45 +206,53 @@ namespace SixLabors.ImageSharp
///
/// Create a new instance of the class from the given stream.
///
- /// The Configuration.
+ /// The Configuration.
/// The stream containing image information.
/// The decoder.
- /// Thrown if the stream is not readable.
- /// Image cannot be loaded.
+ /// The configuration is null.
+ /// The stream is null.
+ /// The stream is not readable.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The pixel format.
/// A new .>
- public static Image Load(Configuration config, Stream stream, IImageDecoder decoder)
+ public static Image Load(Configuration configuration, Stream stream, IImageDecoder decoder)
where TPixel : unmanaged, IPixel
- => WithSeekableStream(config, stream, s => decoder.Decode(config, s));
+ => WithSeekableStream(configuration, stream, s => decoder.Decode(configuration, s));
///
/// Create a new instance of the class from the given stream.
///
- /// The configuration options.
+ /// The configuration options.
/// The stream containing image information.
- /// Thrown if the stream is not readable.
- /// Image cannot be loaded.
+ /// The configuration is null.
+ /// The stream is null.
+ /// The stream is not readable.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The pixel format.
/// A new .>
- public static Image Load(Configuration config, Stream stream)
+ public static Image Load(Configuration configuration, Stream stream)
where TPixel : unmanaged, IPixel
- => Load(config, stream, out IImageFormat _);
+ => Load(configuration, stream, out IImageFormat _);
///
/// Create a new instance of the class from the given stream.
///
- /// The configuration options.
+ /// The configuration options.
/// The stream containing image information.
/// The format type of the decoded image.
- /// Thrown if the stream is not readable.
- /// Image cannot be loaded.
+ /// The configuration is null.
+ /// The stream is null.
+ /// The stream is not readable.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// The pixel format.
- /// A new .>
- public static Image Load(Configuration config, Stream stream, out IImageFormat format)
+ /// A new .
+ public static Image Load(Configuration configuration, Stream stream, out IImageFormat format)
where TPixel : unmanaged, IPixel
{
- config = config ?? Configuration.Default;
- (Image img, IImageFormat format) data = WithSeekableStream(config, stream, s => Decode(s, config));
+ (Image img, IImageFormat format) data = WithSeekableStream(configuration, stream, s => Decode(s, configuration));
format = data.format;
@@ -218,9 +264,9 @@ namespace SixLabors.ImageSharp
var sb = new StringBuilder();
sb.AppendLine("Image cannot be loaded. Available decoders:");
- foreach (KeyValuePair val in config.ImageFormatsManager.ImageDecoders)
+ foreach (KeyValuePair val in configuration.ImageFormatsManager.ImageDecoders)
{
- sb.AppendLine($" - {val.Key.Name} : {val.Value.GetType().Name}");
+ sb.AppendFormat(" - {0} : {1}{2}", val.Key.Name, val.Value.GetType().Name, Environment.NewLine);
}
throw new UnknownImageFormatException(sb.ToString());
@@ -230,16 +276,18 @@ namespace SixLabors.ImageSharp
/// Decode a new instance of the class from the given stream.
/// The pixel format is selected by the decoder.
///
- /// The configuration options.
+ /// The configuration options.
/// The stream containing image information.
/// The format type of the decoded image.
- /// Thrown if the stream is not readable.
- /// Image cannot be loaded.
+ /// The configuration is null.
+ /// The stream is null.
+ /// The stream is not readable.
+ /// Image format not recognised.
+ /// Image contains invalid content.
/// A new .
- public static Image Load(Configuration config, Stream stream, out IImageFormat format)
+ public static Image Load(Configuration configuration, Stream stream, out IImageFormat format)
{
- config = config ?? Configuration.Default;
- (Image img, IImageFormat format) data = WithSeekableStream(config, stream, s => Decode(s, config));
+ (Image img, IImageFormat format) data = WithSeekableStream(configuration, stream, s => Decode(s, configuration));
format = data.format;
@@ -251,16 +299,19 @@ namespace SixLabors.ImageSharp
var sb = new StringBuilder();
sb.AppendLine("Image cannot be loaded. Available decoders:");
- foreach (KeyValuePair val in config.ImageFormatsManager.ImageDecoders)
+ foreach (KeyValuePair val in configuration.ImageFormatsManager.ImageDecoders)
{
- sb.AppendLine($" - {val.Key.Name} : {val.Value.GetType().Name}");
+ sb.AppendFormat(" - {0} : {1}{2}", val.Key.Name, val.Value.GetType().Name, Environment.NewLine);
}
throw new UnknownImageFormatException(sb.ToString());
}
- private static T WithSeekableStream(Configuration config, Stream stream, Func action)
+ private static T WithSeekableStream(Configuration configuration, Stream stream, Func action)
{
+ Guard.NotNull(configuration, nameof(configuration));
+ Guard.NotNull(stream, nameof(stream));
+
if (!stream.CanRead)
{
throw new NotSupportedException("Cannot read from the stream.");
@@ -268,7 +319,7 @@ namespace SixLabors.ImageSharp
if (stream.CanSeek)
{
- if (config.ReadOrigin == ReadOrigin.Begin)
+ if (configuration.ReadOrigin == ReadOrigin.Begin)
{
stream.Position = 0;
}
diff --git a/src/ImageSharp/Image.LoadPixelData.cs b/src/ImageSharp/Image.LoadPixelData.cs
index f8f2e8485..8b827f170 100644
--- a/src/ImageSharp/Image.LoadPixelData.cs
+++ b/src/ImageSharp/Image.LoadPixelData.cs
@@ -1,9 +1,8 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
@@ -21,6 +20,7 @@ namespace SixLabors.ImageSharp
/// The width of the final image.
/// The height of the final image.
/// The pixel format.
+ /// The data length is incorrect.
/// A new .
public static Image LoadPixelData(TPixel[] data, int width, int height)
where TPixel : unmanaged, IPixel
@@ -33,6 +33,7 @@ namespace SixLabors.ImageSharp
/// The width of the final image.
/// The height of the final image.
/// The pixel format.
+ /// The data length is incorrect.
/// A new .
public static Image LoadPixelData(ReadOnlySpan data, int width, int height)
where TPixel : unmanaged, IPixel
@@ -45,6 +46,7 @@ namespace SixLabors.ImageSharp
/// The width of the final image.
/// The height of the final image.
/// The pixel format.
+ /// The data length is incorrect.
/// A new .
public static Image LoadPixelData(byte[] data, int width, int height)
where TPixel : unmanaged, IPixel
@@ -57,6 +59,7 @@ namespace SixLabors.ImageSharp
/// The width of the final image.
/// The height of the final image.
/// The pixel format.
+ /// The data length is incorrect.
/// A new .
public static Image LoadPixelData(ReadOnlySpan data, int width, int height)
where TPixel : unmanaged, IPixel
@@ -65,60 +68,68 @@ namespace SixLabors.ImageSharp
///
/// Create a new instance of the class from the given byte array in format.
///
- /// The config for the decoder.
+ /// The configuration for the decoder.
/// The byte array containing image data.
/// The width of the final image.
/// The height of the final image.
/// The pixel format.
+ /// The configuration is null.
+ /// The data length is incorrect.
/// A new .
- public static Image LoadPixelData(Configuration config, byte[] data, int width, int height)
+ public static Image LoadPixelData(Configuration configuration, byte[] data, int width, int height)
where TPixel : unmanaged, IPixel
- => LoadPixelData(config, MemoryMarshal.Cast(new ReadOnlySpan(data)), width, height);
+ => LoadPixelData(configuration, MemoryMarshal.Cast(new ReadOnlySpan(data)), width, height);
///
/// Create a new instance of the class from the given byte array in format.
///
- /// The config for the decoder.
+ /// The configuration for the decoder.
/// The byte array containing image data.
/// The width of the final image.
/// The height of the final image.
/// The pixel format.
+ /// The configuration is null.
+ /// The data length is incorrect.
/// A new .
- public static Image LoadPixelData(Configuration config, ReadOnlySpan data, int width, int height)
+ public static Image LoadPixelData(Configuration configuration, ReadOnlySpan data, int width, int height)
where TPixel : unmanaged, IPixel
- => LoadPixelData(config, MemoryMarshal.Cast(data), width, height);
+ => LoadPixelData(configuration, MemoryMarshal.Cast(data), width, height);
///
/// Create a new instance of the class from the raw data.
///
- /// The config for the decoder.
+ /// The configuration for the decoder.
/// The Span containing the image Pixel data.
/// The width of the final image.
/// The height of the final image.
/// The pixel format.
+ /// The configuration is null.
+ /// The data length is incorrect.
/// A new .
- public static Image LoadPixelData(Configuration config, TPixel[] data, int width, int height)
+ public static Image LoadPixelData(Configuration configuration, TPixel[] data, int width, int height)
where TPixel : unmanaged, IPixel
- {
- return LoadPixelData(config, new ReadOnlySpan(data), width, height);
- }
+ => LoadPixelData(configuration, new ReadOnlySpan(data), width, height);
///
/// Create a new instance of the class from the raw data.
///
- /// The config for the decoder.
+ /// The configuration for the decoder.
/// The Span containing the image Pixel data.
/// The width of the final image.
/// The height of the final image.
+ /// The configuration is null.
+ /// The data length is incorrect.
/// The pixel format.
/// A new .
- public static Image LoadPixelData(Configuration config, ReadOnlySpan data, int width, int height)
+ public static Image LoadPixelData(Configuration configuration, ReadOnlySpan data, int width, int height)
where TPixel : unmanaged, IPixel
{
+ Guard.NotNull(configuration, nameof(configuration));
+
int count = width * height;
Guard.MustBeGreaterThanOrEqualTo(data.Length, count, nameof(data));
- var image = new Image(config, width, height);
+ var image = new Image(configuration, width, height);
data = data.Slice(0, count);
data.CopyTo(image.Frames.RootFrame.PixelBuffer.FastMemoryGroup);
diff --git a/src/ImageSharp/Image.WrapMemory.cs b/src/ImageSharp/Image.WrapMemory.cs
index e5181a0db..03b5cb9a0 100644
--- a/src/ImageSharp/Image.WrapMemory.cs
+++ b/src/ImageSharp/Image.WrapMemory.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
@@ -20,22 +20,27 @@ namespace SixLabors.ImageSharp
/// allowing to view/manipulate it as an ImageSharp instance.
///
/// The pixel type
- /// The
+ /// The
/// The pixel memory.
/// The width of the memory image.
/// The height of the memory image.
/// The .
+ /// The configuration is null.
+ /// The metadata is null.
/// An instance
public static Image WrapMemory(
- Configuration config,
+ Configuration configuration,
Memory pixelMemory,
int width,
int height,
ImageMetadata metadata)
where TPixel : unmanaged, IPixel
{
+ Guard.NotNull(configuration, nameof(configuration));
+ Guard.NotNull(metadata, nameof(metadata));
+
var memorySource = MemoryGroup.Wrap(pixelMemory);
- return new Image(config, memorySource, width, height, metadata);
+ return new Image(configuration, memorySource, width, height, metadata);
}
///
@@ -43,20 +48,19 @@ namespace SixLabors.ImageSharp
/// allowing to view/manipulate it as an ImageSharp instance.
///
/// The pixel type
- /// The
+ /// The
/// The pixel memory.
/// The width of the memory image.
/// The height of the memory image.
+ /// The configuration is null.
/// An instance.
public static Image WrapMemory(
- Configuration config,
+ Configuration configuration,
Memory pixelMemory,
int width,
int height)
where TPixel : unmanaged, IPixel
- {
- return WrapMemory(config, pixelMemory, width, height, new ImageMetadata());
- }
+ => WrapMemory(configuration, pixelMemory, width, height, new ImageMetadata());
///
/// Wraps an existing contiguous memory area of 'width' x 'height' pixels,
@@ -73,9 +77,7 @@ namespace SixLabors.ImageSharp
int width,
int height)
where TPixel : unmanaged, IPixel
- {
- return WrapMemory(Configuration.Default, pixelMemory, width, height);
- }
+ => WrapMemory(Configuration.Default, pixelMemory, width, height);
///
/// Wraps an existing contiguous memory area of 'width' x 'height' pixels,
@@ -85,22 +87,27 @@ namespace SixLabors.ImageSharp
/// It will be disposed together with the result image.
///
/// The pixel type
- /// The
+ /// The
/// The that is being transferred to the image
/// The width of the memory image.
/// The height of the memory image.
/// The
+ /// The configuration is null.
+ /// The metadata is null.
/// An instance
public static Image WrapMemory(
- Configuration config,
+ Configuration configuration,
IMemoryOwner pixelMemoryOwner,
int width,
int height,
ImageMetadata metadata)
where TPixel : unmanaged, IPixel
{
+ Guard.NotNull(configuration, nameof(configuration));
+ Guard.NotNull(metadata, nameof(metadata));
+
var memorySource = MemoryGroup.Wrap(pixelMemoryOwner);
- return new Image(config, memorySource, width, height, metadata);
+ return new Image(configuration, memorySource, width, height, metadata);
}
///
@@ -111,20 +118,19 @@ namespace SixLabors.ImageSharp
/// It will be disposed together with the result image.
///
/// The pixel type.
- /// The
+ /// The
/// The that is being transferred to the image.
/// The width of the memory image.
/// The height of the memory image.
+ /// The configuration is null.
/// An instance
public static Image WrapMemory(
- Configuration config,
+ Configuration configuration,
IMemoryOwner pixelMemoryOwner,
int width,
int height)
where TPixel : unmanaged, IPixel
- {
- return WrapMemory(config, pixelMemoryOwner, width, height, new ImageMetadata());
- }
+ => WrapMemory(configuration, pixelMemoryOwner, width, height, new ImageMetadata());
///
/// Wraps an existing contiguous memory area of 'width' x 'height' pixels,
@@ -143,8 +149,6 @@ namespace SixLabors.ImageSharp
int width,
int height)
where TPixel : unmanaged, IPixel
- {
- return WrapMemory(Configuration.Default, pixelMemoryOwner, width, height);
- }
+ => WrapMemory(Configuration.Default, pixelMemoryOwner, width, height);
}
}
diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs
index b1cefdf1d..c43a20842 100644
--- a/src/ImageSharp/Image.cs
+++ b/src/ImageSharp/Image.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.IO;
diff --git a/src/ImageSharp/ImageExtensions.Internal.cs b/src/ImageSharp/ImageExtensions.Internal.cs
index a1fc51043..65e2701a2 100644
--- a/src/ImageSharp/ImageExtensions.Internal.cs
+++ b/src/ImageSharp/ImageExtensions.Internal.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/ImageExtensions.cs b/src/ImageSharp/ImageExtensions.cs
index bb3128282..aa9030c6e 100644
--- a/src/ImageSharp/ImageExtensions.cs
+++ b/src/ImageSharp/ImageExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
@@ -7,12 +7,11 @@ using System.IO;
using System.Text;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats;
-using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
{
///
- /// Extension methods over Image{TPixel}.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
@@ -20,13 +19,13 @@ namespace SixLabors.ImageSharp
/// Writes the image to the given stream using the currently loaded image format.
///
/// The source image.
- /// The file path to save the image to.
- /// Thrown if the stream is null.
- public static void Save(this Image source, string filePath)
+ /// The file path to save the image to.
+ /// The path is null.
+ public static void Save(this Image source, string path)
{
- Guard.NotNullOrWhiteSpace(filePath, nameof(filePath));
+ Guard.NotNull(path, nameof(path));
- string ext = Path.GetExtension(filePath);
+ string ext = Path.GetExtension(path);
IImageFormat format = source.GetConfiguration().ImageFormatsManager.FindFormatByFileExtension(ext);
if (format is null)
{
@@ -34,7 +33,7 @@ namespace SixLabors.ImageSharp
sb.AppendLine($"No encoder was found for extension '{ext}'. Registered encoders include:");
foreach (IImageFormat fmt in source.GetConfiguration().ImageFormats)
{
- sb.AppendLine($" - {fmt.Name} : {string.Join(", ", fmt.FileExtensions)}");
+ sb.AppendFormat(" - {0} : {1}{2}", fmt.Name, string.Join(", ", fmt.FileExtensions), Environment.NewLine);
}
throw new NotSupportedException(sb.ToString());
@@ -48,26 +47,28 @@ namespace SixLabors.ImageSharp
sb.AppendLine($"No encoder was found for extension '{ext}' using image format '{format.Name}'. Registered encoders include:");
foreach (KeyValuePair enc in source.GetConfiguration().ImageFormatsManager.ImageEncoders)
{
- sb.AppendLine($" - {enc.Key} : {enc.Value.GetType().Name}");
+ sb.AppendFormat(" - {0} : {1}{2}", enc.Key, enc.Value.GetType().Name, Environment.NewLine);
}
throw new NotSupportedException(sb.ToString());
}
- source.Save(filePath, encoder);
+ source.Save(path, encoder);
}
///
/// Writes the image to the given stream using the currently loaded image format.
///
/// The source image.
- /// The file path to save the image to.
+ /// The file path to save the image to.
/// The encoder to save the image with.
- /// Thrown if the encoder is null.
- public static void Save(this Image source, string filePath, IImageEncoder encoder)
+ /// The path is null.
+ /// The encoder is null.
+ public static void Save(this Image source, string path, IImageEncoder encoder)
{
+ Guard.NotNull(path, nameof(path));
Guard.NotNull(encoder, nameof(encoder));
- using (Stream fs = source.GetConfiguration().FileSystem.Create(filePath))
+ using (Stream fs = source.GetConfiguration().FileSystem.Create(path))
{
source.Save(fs, encoder);
}
@@ -79,10 +80,20 @@ namespace SixLabors.ImageSharp
/// The source image.
/// The stream to save the image to.
/// The format to save the image in.
- /// Thrown if the stream is null.
+ /// The stream is null.
+ /// The format is null.
+ /// The stream is not writable.
+ /// No encoder available for provided format.
public static void Save(this Image source, Stream stream, IImageFormat format)
{
+ Guard.NotNull(stream, nameof(stream));
Guard.NotNull(format, nameof(format));
+
+ if (!stream.CanWrite)
+ {
+ throw new NotSupportedException("Cannot write to the stream.");
+ }
+
IImageEncoder encoder = source.GetConfiguration().ImageFormatsManager.FindEncoder(format);
if (encoder is null)
@@ -92,7 +103,7 @@ namespace SixLabors.ImageSharp
foreach (KeyValuePair val in source.GetConfiguration().ImageFormatsManager.ImageEncoders)
{
- sb.AppendLine($" - {val.Key.Name} : {val.Value.GetType().Name}");
+ sb.AppendFormat(" - {0} : {1}{2}", val.Key.Name, val.Value.GetType().Name, Environment.NewLine);
}
throw new NotSupportedException(sb.ToString());
@@ -103,21 +114,28 @@ namespace SixLabors.ImageSharp
///
/// Returns a Base64 encoded string from the given image.
+ /// The result is prepended with a Data URI
+ ///
+ ///
+ /// For example:
+ ///
+ ///
+ ///
///
- ///
- /// The pixel format.
/// The source image
/// The format.
+ /// The format is null.
/// The
- public static string ToBase64String(this Image source, IImageFormat format)
- where TPixel : unmanaged, IPixel
+ public static string ToBase64String(this Image source, IImageFormat format)
{
- using (var stream = new MemoryStream())
- {
- source.Save(stream, format);
- stream.Flush();
- return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(stream.ToArray())}";
- }
+ Guard.NotNull(format, nameof(format));
+
+ using var stream = new MemoryStream();
+ source.Save(stream, format);
+
+ // Always available.
+ stream.TryGetBuffer(out ArraySegment buffer);
+ return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(buffer.Array, 0, (int)stream.Length)}";
}
}
}
diff --git a/src/ImageSharp/ImageFrame.LoadPixelData.cs b/src/ImageSharp/ImageFrame.LoadPixelData.cs
index e6035a177..a5a792472 100644
--- a/src/ImageSharp/ImageFrame.LoadPixelData.cs
+++ b/src/ImageSharp/ImageFrame.LoadPixelData.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.InteropServices;
diff --git a/src/ImageSharp/ImageFrame.cs b/src/ImageSharp/ImageFrame.cs
index 93fa20587..38c853fd7 100644
--- a/src/ImageSharp/ImageFrame.cs
+++ b/src/ImageSharp/ImageFrame.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using SixLabors.ImageSharp.Advanced;
diff --git a/src/ImageSharp/ImageFrameCollection.cs b/src/ImageSharp/ImageFrameCollection.cs
index c584d2d19..75b7fe84c 100644
--- a/src/ImageSharp/ImageFrameCollection.cs
+++ b/src/ImageSharp/ImageFrameCollection.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections;
diff --git a/src/ImageSharp/ImageFrameCollection{TPixel}.cs b/src/ImageSharp/ImageFrameCollection{TPixel}.cs
index 89a1dfcc1..1e674198b 100644
--- a/src/ImageSharp/ImageFrameCollection{TPixel}.cs
+++ b/src/ImageSharp/ImageFrameCollection{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections;
diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs
index a35443ec9..be4e988c6 100644
--- a/src/ImageSharp/ImageFrame{TPixel}.cs
+++ b/src/ImageSharp/ImageFrame{TPixel}.cs
@@ -1,7 +1,8 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
+using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
@@ -166,6 +167,40 @@ namespace SixLabors.ImageSharp
}
}
+ ///
+ /// Gets the representation of the pixels as a of contiguous memory
+ /// at row beginning from the first pixel on that row.
+ ///
+ /// The row.
+ /// The
+ /// Thrown when row index is out of range.
+ public Span GetPixelRowSpan(int rowIndex)
+ {
+ Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex));
+ Guard.MustBeLessThan(rowIndex, this.Height, nameof(rowIndex));
+
+ return this.PixelBuffer.GetRowSpan(rowIndex);
+ }
+
+ ///
+ /// Gets the representation of the pixels as a in the source image's pixel format
+ /// stored in row major order, if the backing buffer is contiguous.
+ ///
+ /// The .
+ /// The .
+ public bool TryGetSinglePixelSpan(out Span span)
+ {
+ IMemoryGroup mg = this.GetPixelMemoryGroup();
+ if (mg.Count > 1)
+ {
+ span = default;
+ return false;
+ }
+
+ span = mg.Single().Span;
+ return true;
+ }
+
///
/// Gets a reference to the pixel at the specified position.
///
diff --git a/src/ImageSharp/ImageInfo.cs b/src/ImageSharp/ImageInfo.cs
index 12dcf1ed7..baff7fd08 100644
--- a/src/ImageSharp/ImageInfo.cs
+++ b/src/ImageSharp/ImageInfo.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/ImageInfoExtensions.cs b/src/ImageSharp/ImageInfoExtensions.cs
index abaa7c4bc..f87b19b1a 100644
--- a/src/ImageSharp/ImageInfoExtensions.cs
+++ b/src/ImageSharp/ImageInfoExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp
{
diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj
index 24d4f4a00..baf4a2ce1 100644
--- a/src/ImageSharp/ImageSharp.csproj
+++ b/src/ImageSharp/ImageSharp.csproj
@@ -36,17 +36,7 @@
-
-
-
- True
- True
- Guard.Numeric.tt
-
-
+ TrueTrue
@@ -212,10 +202,6 @@
DefaultPixelBlenders.Generated.csTextTemplatingFileGenerator
-
- Guard.Numeric.cs
- TextTemplatingFileGenerator
-
diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs
index 56f1f6b7b..7eda2050a 100644
--- a/src/ImageSharp/Image{TPixel}.cs
+++ b/src/ImageSharp/Image{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
@@ -48,6 +48,18 @@ namespace SixLabors.ImageSharp
{
}
+ ///
+ /// Initializes a new instance of the class
+ /// with the height and the width of the image.
+ ///
+ /// The width of the image in pixels.
+ /// The height of the image in pixels.
+ /// The color to initialize the pixels with.
+ public Image(int width, int height, TPixel backgroundColor)
+ : this(Configuration.Default, width, height, backgroundColor, new ImageMetadata())
+ {
+ }
+
///
/// Initializes a new instance of the class
/// with the height and the width of the image.
@@ -163,6 +175,40 @@ namespace SixLabors.ImageSharp
}
}
+ ///
+ /// Gets the representation of the pixels as a of contiguous memory
+ /// at row beginning from the first pixel on that row.
+ ///
+ /// The row.
+ /// The
+ /// Thrown when row index is out of range.
+ public Span GetPixelRowSpan(int rowIndex)
+ {
+ Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex));
+ Guard.MustBeLessThan(rowIndex, this.Height, nameof(rowIndex));
+
+ return this.PixelSource.PixelBuffer.GetRowSpan(rowIndex);
+ }
+
+ ///
+ /// Gets the representation of the pixels as a in the source image's pixel format
+ /// stored in row major order, if the backing buffer is contiguous.
+ ///
+ /// The .
+ /// The .
+ public bool TryGetSinglePixelSpan(out Span span)
+ {
+ IMemoryGroup mg = this.GetPixelMemoryGroup();
+ if (mg.Count > 1)
+ {
+ span = default;
+ return false;
+ }
+
+ span = mg.Single().Span;
+ return true;
+ }
+
///
/// Clones the current image
///
diff --git a/src/ImageSharp/IndexedImageFrame{TPixel}.cs b/src/ImageSharp/IndexedImageFrame{TPixel}.cs
new file mode 100644
index 000000000..410cd7655
--- /dev/null
+++ b/src/ImageSharp/IndexedImageFrame{TPixel}.cs
@@ -0,0 +1,114 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using System;
+using System.Buffers;
+using System.Runtime.CompilerServices;
+using SixLabors.ImageSharp.Advanced;
+using SixLabors.ImageSharp.Memory;
+using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.ImageSharp.Processing.Processors.Quantization;
+
+namespace SixLabors.ImageSharp
+{
+ ///
+ /// A pixel-specific image frame where each pixel buffer value represents an index in a color palette.
+ ///
+ /// The pixel format.
+ public sealed class IndexedImageFrame : IPixelSource, IDisposable
+ where TPixel : unmanaged, IPixel
+ {
+ private Buffer2D pixelBuffer;
+ private IMemoryOwner paletteOwner;
+ private bool isDisposed;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The configuration which allows altering default behaviour or extending the library.
+ ///
+ /// The frame width.
+ /// The frame height.
+ /// The color palette.
+ internal IndexedImageFrame(Configuration configuration, int width, int height, ReadOnlyMemory palette)
+ {
+ Guard.NotNull(configuration, nameof(configuration));
+ Guard.MustBeLessThanOrEqualTo(palette.Length, QuantizerConstants.MaxColors, nameof(palette));
+ Guard.MustBeGreaterThan(width, 0, nameof(width));
+ Guard.MustBeGreaterThan(height, 0, nameof(height));
+
+ this.Configuration = configuration;
+ this.Width = width;
+ this.Height = height;
+ this.pixelBuffer = configuration.MemoryAllocator.Allocate2D(width, height);
+
+ // Copy the palette over. We want the lifetime of this frame to be independant of any palette source.
+ this.paletteOwner = configuration.MemoryAllocator.Allocate(palette.Length);
+ palette.Span.CopyTo(this.paletteOwner.GetSpan());
+ this.Palette = this.paletteOwner.Memory.Slice(0, palette.Length);
+ }
+
+ ///
+ /// Gets the configuration which allows altering default behaviour or extending the library.
+ ///
+ public Configuration Configuration { get; }
+
+ ///
+ /// Gets the width of this .
+ ///
+ public int Width { get; }
+
+ ///
+ /// Gets the height of this .
+ ///
+ public int Height { get; }
+
+ ///
+ /// Gets the color palette of this .
+ ///
+ public ReadOnlyMemory Palette { get; }
+
+ ///
+ Buffer2D IPixelSource.PixelBuffer => this.pixelBuffer;
+
+ ///
+ /// Gets the representation of the pixels as a of contiguous memory
+ /// at row beginning from the first pixel on that row.
+ ///
+ /// The row index in the pixel buffer.
+ /// The pixel row as a .
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public ReadOnlySpan GetPixelRowSpan(int rowIndex)
+ => this.GetWritablePixelRowSpanUnsafe(rowIndex);
+
+ ///
+ ///
+ /// Gets the representation of the pixels as a of contiguous memory
+ /// at row beginning from the first pixel on that row.
+ ///
+ ///
+ /// Note: Values written to this span are not sanitized against the palette length.
+ /// Care should be taken during assignment to prevent out-of-bounds errors.
+ ///
+ ///
+ /// The row index in the pixel buffer.
+ /// The pixel row as a .
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public Span GetWritablePixelRowSpanUnsafe(int rowIndex)
+ => this.pixelBuffer.GetRowSpan(rowIndex);
+
+ ///
+ public void Dispose()
+ {
+ if (!this.isDisposed)
+ {
+ this.isDisposed = true;
+ this.pixelBuffer.Dispose();
+ this.paletteOwner.Dispose();
+ this.pixelBuffer = null;
+ this.paletteOwner = null;
+ }
+ }
+ }
+}
diff --git a/src/ImageSharp/Memory/Allocators/AllocationOptions.cs b/src/ImageSharp/Memory/Allocators/AllocationOptions.cs
index 4edb702ed..7c97f08b3 100644
--- a/src/ImageSharp/Memory/Allocators/AllocationOptions.cs
+++ b/src/ImageSharp/Memory/Allocators/AllocationOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Memory
{
diff --git a/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.Buffer{T}.cs b/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.Buffer{T}.cs
index 7a8b4f8bd..a468fecee 100644
--- a/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.Buffer{T}.cs
+++ b/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.Buffer{T}.cs
@@ -1,8 +1,9 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory.Internals;
@@ -48,9 +49,9 @@ namespace SixLabors.ImageSharp.Memory
///
public override Span GetSpan()
{
- if (this.Data == null)
+ if (this.Data is null)
{
- throw new ObjectDisposedException("ArrayPoolMemoryAllocator.Buffer");
+ ThrowObjectDisposedException();
}
return MemoryMarshal.Cast(this.Data.AsSpan()).Slice(0, this.length);
@@ -74,6 +75,12 @@ namespace SixLabors.ImageSharp.Memory
}
protected override object GetPinnableObject() => this.Data;
+
+ [MethodImpl(InliningOptions.ColdPath)]
+ private static void ThrowObjectDisposedException()
+ {
+ throw new ObjectDisposedException("ArrayPoolMemoryAllocator.Buffer");
+ }
}
///
diff --git a/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs b/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs
index 5ef60c9ed..b0ea00f5b 100644
--- a/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs
+++ b/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Memory
{
diff --git a/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.cs b/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.cs
index 8043c1888..57d8c0e45 100644
--- a/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.cs
+++ b/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
@@ -133,8 +133,7 @@ namespace SixLabors.ImageSharp.Memory
int bufferSizeInBytes = length * itemSizeBytes;
if (bufferSizeInBytes < 0 || bufferSizeInBytes > this.BufferCapacityInBytes)
{
- throw new InvalidMemoryOperationException(
- $"Requested allocation: {length} elements of {typeof(T).Name} is over the capacity of the MemoryAllocator.");
+ ThrowInvalidAllocationException(length);
}
ArrayPool pool = this.GetArrayPool(bufferSizeInBytes);
@@ -171,6 +170,11 @@ namespace SixLabors.ImageSharp.Memory
return maxPoolSizeInBytes / 4;
}
+ [MethodImpl(InliningOptions.ColdPath)]
+ private static void ThrowInvalidAllocationException(int length) =>
+ throw new InvalidMemoryOperationException(
+ $"Requested allocation: {length} elements of {typeof(T).Name} is over the capacity of the MemoryAllocator.");
+
private ArrayPool GetArrayPool(int bufferSizeInBytes)
{
return bufferSizeInBytes <= this.PoolSelectorThresholdInBytes ? this.normalArrayPool : this.largeArrayPool;
diff --git a/src/ImageSharp/Memory/Allocators/IManagedByteBuffer.cs b/src/ImageSharp/Memory/Allocators/IManagedByteBuffer.cs
index cb1f58ddb..ef17e6953 100644
--- a/src/ImageSharp/Memory/Allocators/IManagedByteBuffer.cs
+++ b/src/ImageSharp/Memory/Allocators/IManagedByteBuffer.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Buffers;
diff --git a/src/ImageSharp/Memory/Allocators/Internals/BasicArrayBuffer.cs b/src/ImageSharp/Memory/Allocators/Internals/BasicArrayBuffer.cs
index 56057f372..d88e0bd5d 100644
--- a/src/ImageSharp/Memory/Allocators/Internals/BasicArrayBuffer.cs
+++ b/src/ImageSharp/Memory/Allocators/Internals/BasicArrayBuffer.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Memory/Allocators/Internals/BasicByteBuffer.cs b/src/ImageSharp/Memory/Allocators/Internals/BasicByteBuffer.cs
index 571ad70c5..b3ece76eb 100644
--- a/src/ImageSharp/Memory/Allocators/Internals/BasicByteBuffer.cs
+++ b/src/ImageSharp/Memory/Allocators/Internals/BasicByteBuffer.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Memory.Internals
{
diff --git a/src/ImageSharp/Memory/Allocators/Internals/ManagedBufferBase.cs b/src/ImageSharp/Memory/Allocators/Internals/ManagedBufferBase.cs
index 890963860..ca4483e3b 100644
--- a/src/ImageSharp/Memory/Allocators/Internals/ManagedBufferBase.cs
+++ b/src/ImageSharp/Memory/Allocators/Internals/ManagedBufferBase.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Buffers;
using System.Runtime.InteropServices;
diff --git a/src/ImageSharp/Memory/Allocators/MemoryAllocator.cs b/src/ImageSharp/Memory/Allocators/MemoryAllocator.cs
index a4e1de197..71564836b 100644
--- a/src/ImageSharp/Memory/Allocators/MemoryAllocator.cs
+++ b/src/ImageSharp/Memory/Allocators/MemoryAllocator.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Memory/Allocators/SimpleGcMemoryAllocator.cs b/src/ImageSharp/Memory/Allocators/SimpleGcMemoryAllocator.cs
index 4c62e4ded..5996d0c49 100644
--- a/src/ImageSharp/Memory/Allocators/SimpleGcMemoryAllocator.cs
+++ b/src/ImageSharp/Memory/Allocators/SimpleGcMemoryAllocator.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Buffers;
using SixLabors.ImageSharp.Memory.Internals;
diff --git a/src/ImageSharp/Memory/Buffer2DExtensions.cs b/src/ImageSharp/Memory/Buffer2DExtensions.cs
index 8b0f3845e..56de1fd07 100644
--- a/src/ImageSharp/Memory/Buffer2DExtensions.cs
+++ b/src/ImageSharp/Memory/Buffer2DExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Diagnostics;
@@ -27,52 +27,6 @@ namespace SixLabors.ImageSharp.Memory
return buffer.FastMemoryGroup.View;
}
- ///
- /// Gets a to the backing data of
- /// if the backing group consists of one single contiguous memory buffer.
- /// Throws otherwise.
- ///
- /// The .
- /// The value type.
- /// The referencing the memory area.
- ///
- /// Thrown when the backing group is discontiguous.
- ///
- internal static Span GetSingleSpan(this Buffer2D buffer)
- where T : struct
- {
- Guard.NotNull(buffer, nameof(buffer));
- if (buffer.FastMemoryGroup.Count > 1)
- {
- throw new InvalidOperationException("GetSingleSpan is only valid for a single-buffer group!");
- }
-
- return buffer.FastMemoryGroup.Single().Span;
- }
-
- ///
- /// Gets a to the backing data of
- /// if the backing group consists of one single contiguous memory buffer.
- /// Throws otherwise.
- ///
- /// The .
- /// The value type.
- /// The .
- ///
- /// Thrown when the backing group is discontiguous.
- ///
- internal static Memory GetSingleMemory(this Buffer2D buffer)
- where T : struct
- {
- Guard.NotNull(buffer, nameof(buffer));
- if (buffer.FastMemoryGroup.Count > 1)
- {
- throw new InvalidOperationException("GetSingleMemory is only valid for a single-buffer group!");
- }
-
- return buffer.FastMemoryGroup.Single();
- }
-
///
/// TODO: Does not work with multi-buffer groups, should be specific to Resize.
/// Copy columns of inplace,
@@ -126,29 +80,29 @@ namespace SixLabors.ImageSharp.Memory
}
///
- /// Return a to the subarea represented by 'rectangle'
+ /// Return a to the subregion represented by 'rectangle'
///
/// The element type
/// The
- /// The rectangle subarea
- /// The
- internal static BufferArea GetArea(this Buffer2D buffer, in Rectangle rectangle)
- where T : struct =>
- new BufferArea(buffer, rectangle);
+ /// The rectangle subregion
+ /// The
+ internal static Buffer2DRegion GetRegion(this Buffer2D buffer, Rectangle rectangle)
+ where T : unmanaged =>
+ new Buffer2DRegion(buffer, rectangle);
- internal static BufferArea GetArea(this Buffer2D buffer, int x, int y, int width, int height)
- where T : struct =>
- new BufferArea(buffer, new Rectangle(x, y, width, height));
+ internal static Buffer2DRegion GetRegion(this Buffer2D buffer, int x, int y, int width, int height)
+ where T : unmanaged =>
+ new Buffer2DRegion(buffer, new Rectangle(x, y, width, height));
///
- /// Return a to the whole area of 'buffer'
+ /// Return a to the whole area of 'buffer'
///
/// The element type
/// The
- /// The
- internal static BufferArea GetArea(this Buffer2D buffer)
- where T : struct =>
- new BufferArea(buffer);
+ /// The
+ internal static Buffer2DRegion GetRegion(this Buffer2D buffer)
+ where T : unmanaged =>
+ new Buffer2DRegion(buffer);
///
/// Returns the size of the buffer.
diff --git a/src/ImageSharp/Memory/BufferArea{T}.cs b/src/ImageSharp/Memory/Buffer2DRegion{T}.cs
similarity index 55%
rename from src/ImageSharp/Memory/BufferArea{T}.cs
rename to src/ImageSharp/Memory/Buffer2DRegion{T}.cs
index f5cbc6953..2a44a4b72 100644
--- a/src/ImageSharp/Memory/BufferArea{T}.cs
+++ b/src/ImageSharp/Memory/Buffer2DRegion{T}.cs
@@ -1,50 +1,53 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Memory
{
///
- /// Represents a rectangular area inside a 2D memory buffer ().
- /// This type is kind-of 2D Span, but it can live on heap.
+ /// Represents a rectangular region inside a 2D memory buffer ().
///
/// The element type.
- internal readonly struct BufferArea
- where T : struct
+ public readonly struct Buffer2DRegion
+ where T : unmanaged
{
///
- /// The rectangle specifying the boundaries of the area in .
+ /// Initializes a new instance of the struct.
///
- public readonly Rectangle Rectangle;
-
+ /// The .
+ /// The defining a rectangular area within the buffer.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public BufferArea(Buffer2D destinationBuffer, Rectangle rectangle)
+ public Buffer2DRegion(Buffer2D buffer, Rectangle rectangle)
{
DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.X, 0, nameof(rectangle));
DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.Y, 0, nameof(rectangle));
- DebugGuard.MustBeLessThanOrEqualTo(rectangle.Width, destinationBuffer.Width, nameof(rectangle));
- DebugGuard.MustBeLessThanOrEqualTo(rectangle.Height, destinationBuffer.Height, nameof(rectangle));
+ DebugGuard.MustBeLessThanOrEqualTo(rectangle.Width, buffer.Width, nameof(rectangle));
+ DebugGuard.MustBeLessThanOrEqualTo(rectangle.Height, buffer.Height, nameof(rectangle));
- this.DestinationBuffer = destinationBuffer;
+ this.Buffer = buffer;
this.Rectangle = rectangle;
}
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public BufferArea(Buffer2D destinationBuffer)
- : this(destinationBuffer, destinationBuffer.FullRectangle())
+ public Buffer2DRegion(Buffer2D buffer)
+ : this(buffer, buffer.FullRectangle())
{
}
///
- /// Gets the being pointed by this instance.
+ /// Gets the rectangle specifying the boundaries of the area in .
///
- public Buffer2D DestinationBuffer { get; }
+ public Rectangle Rectangle { get; }
///
- /// Gets the size of the area.
+ /// Gets the being pointed by this instance.
///
- public Size Size => this.Rectangle.Size;
+ public Buffer2D Buffer { get; }
///
/// Gets the width
@@ -57,14 +60,19 @@ namespace SixLabors.ImageSharp.Memory
public int Height => this.Rectangle.Height;
///
- /// Gets the pixel stride which is equal to the width of .
+ /// Gets the pixel stride which is equal to the width of .
+ ///
+ public int Stride => this.Buffer.Width;
+
+ ///
+ /// Gets the size of the area.
///
- public int Stride => this.DestinationBuffer.Width;
+ internal Size Size => this.Rectangle.Size;
///
- /// Gets a value indicating whether the area refers to the entire
+ /// Gets a value indicating whether the area refers to the entire
///
- public bool IsFullBufferArea => this.Size == this.DestinationBuffer.Size();
+ internal bool IsFullBufferArea => this.Size == this.Buffer.Size();
///
/// Gets or sets a value at the given index.
@@ -72,15 +80,7 @@ namespace SixLabors.ImageSharp.Memory
/// The position inside a row
/// The row index
/// The reference to the value
- public ref T this[int x, int y] => ref this.DestinationBuffer[x + this.Rectangle.X, y + this.Rectangle.Y];
-
- ///
- /// Gets a reference to the [0,0] element.
- ///
- /// The reference to the [0,0] element
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ref T GetReferenceToOrigin() =>
- ref this.GetRowSpan(0)[0];
+ internal ref T this[int x, int y] => ref this.Buffer[x + this.Rectangle.X, y + this.Rectangle.Y];
///
/// Gets a span to row 'y' inside this area.
@@ -90,35 +90,35 @@ namespace SixLabors.ImageSharp.Memory
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span GetRowSpan(int y)
{
- int yy = this.GetRowIndex(y);
+ int yy = this.Rectangle.Y + y;
int xx = this.Rectangle.X;
int width = this.Rectangle.Width;
- return this.DestinationBuffer.FastMemoryGroup.GetBoundedSlice(yy + xx, width).Span;
+ return this.Buffer.GetRowSpan(yy).Slice(xx, width);
}
///
- /// Returns a sub-area as . (Similar to .)
+ /// Returns a subregion as . (Similar to .)
///
- /// The x index at the subarea origin.
- /// The y index at the subarea origin.
- /// The desired width of the subarea.
- /// The desired height of the subarea.
- /// The subarea
+ /// The x index at the subregion origin.
+ /// The y index at the subregion origin.
+ /// The desired width of the subregion.
+ /// The desired height of the subregion.
+ /// The subregion
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public BufferArea GetSubArea(int x, int y, int width, int height)
+ public Buffer2DRegion GetSubRegion(int x, int y, int width, int height)
{
var rectangle = new Rectangle(x, y, width, height);
- return this.GetSubArea(rectangle);
+ return this.GetSubRegion(rectangle);
}
///
- /// Returns a sub-area as . (Similar to .)
+ /// Returns a subregion as . (Similar to .)
///
- /// The specifying the boundaries of the subarea
- /// The subarea
+ /// The specifying the boundaries of the subregion
+ /// The subregion
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public BufferArea GetSubArea(Rectangle rectangle)
+ public Buffer2DRegion GetSubRegion(Rectangle rectangle)
{
DebugGuard.MustBeLessThanOrEqualTo(rectangle.Width, this.Rectangle.Width, nameof(rectangle));
DebugGuard.MustBeLessThanOrEqualTo(rectangle.Height, this.Rectangle.Height, nameof(rectangle));
@@ -126,21 +126,27 @@ namespace SixLabors.ImageSharp.Memory
int x = this.Rectangle.X + rectangle.X;
int y = this.Rectangle.Y + rectangle.Y;
rectangle = new Rectangle(x, y, rectangle.Width, rectangle.Height);
- return new BufferArea(this.DestinationBuffer, rectangle);
+ return new Buffer2DRegion(this.Buffer, rectangle);
}
+ ///
+ /// Gets a reference to the [0,0] element.
+ ///
+ /// The reference to the [0,0] element
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal int GetRowIndex(int y)
+ internal ref T GetReferenceToOrigin()
{
- return (y + this.Rectangle.Y) * this.DestinationBuffer.Width;
+ int y = this.Rectangle.Y;
+ int x = this.Rectangle.X;
+ return ref this.Buffer.GetRowSpan(y)[x];
}
- public void Clear()
+ internal void Clear()
{
// Optimization for when the size of the area is the same as the buffer size.
if (this.IsFullBufferArea)
{
- this.DestinationBuffer.FastMemoryGroup.Clear();
+ this.Buffer.FastMemoryGroup.Clear();
return;
}
diff --git a/src/ImageSharp/Memory/Buffer2D{T}.cs b/src/ImageSharp/Memory/Buffer2D{T}.cs
index f22b9a875..6c8741c5d 100644
--- a/src/ImageSharp/Memory/Buffer2D{T}.cs
+++ b/src/ImageSharp/Memory/Buffer2D{T}.cs
@@ -1,7 +1,8 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
+using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -155,7 +156,37 @@ namespace SixLabors.ImageSharp.Memory
{
DebugGuard.MustBeGreaterThanOrEqualTo(y, 0, nameof(y));
DebugGuard.MustBeLessThan(y, this.Height, nameof(y));
- return this.FastMemoryGroup.View.GetBoundedSlice(y * this.Width, this.Width);
+ return this.FastMemoryGroup.View.GetBoundedSlice(y * (long)this.Width, this.Width);
+ }
+
+ ///
+ /// Gets a to the backing data if the backing group consists of a single contiguous memory buffer.
+ /// Throws otherwise.
+ ///
+ /// The referencing the memory area.
+ ///
+ /// Thrown when the backing group is discontiguous.
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ internal Span GetSingleSpan()
+ {
+ // TODO: If we need a public version of this method, we need to cache the non-fast Memory of this.MemoryGroup
+ return this.cachedMemory.Length != 0 ? this.cachedMemory.Span : this.GetSingleSpanSlow();
+ }
+
+ ///
+ /// Gets a to the backing data of if the backing group consists of a single contiguous memory buffer.
+ /// Throws otherwise.
+ ///
+ /// The .
+ ///
+ /// Thrown when the backing group is discontiguous.
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ internal Memory GetSingleMemory()
+ {
+ // TODO: If we need a public version of this method, we need to cache the non-fast Memory of this.MemoryGroup
+ return this.cachedMemory.Length != 0 ? this.cachedMemory : this.GetSingleMemorySlow();
}
///
@@ -169,7 +200,13 @@ namespace SixLabors.ImageSharp.Memory
}
[MethodImpl(InliningOptions.ColdPath)]
- private Memory GetRowMemorySlow(int y) => this.FastMemoryGroup.GetBoundedSlice(y * this.Width, this.Width);
+ private Memory GetRowMemorySlow(int y) => this.FastMemoryGroup.GetBoundedSlice(y * (long)this.Width, this.Width);
+
+ [MethodImpl(InliningOptions.ColdPath)]
+ private Memory GetSingleMemorySlow() => this.FastMemoryGroup.Single();
+
+ [MethodImpl(InliningOptions.ColdPath)]
+ private Span GetSingleSpanSlow() => this.FastMemoryGroup.Single().Span;
[MethodImpl(InliningOptions.ColdPath)]
private ref T GetElementSlow(int x, int y)
diff --git a/src/ImageSharp/Memory/DiscontiguousBuffers/IMemoryGroup{T}.cs b/src/ImageSharp/Memory/DiscontiguousBuffers/IMemoryGroup{T}.cs
index 2649b7fb1..8f46ae3b8 100644
--- a/src/ImageSharp/Memory/DiscontiguousBuffers/IMemoryGroup{T}.cs
+++ b/src/ImageSharp/Memory/DiscontiguousBuffers/IMemoryGroup{T}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
@@ -18,12 +18,12 @@ namespace SixLabors.ImageSharp.Memory
/// Gets the number of elements per contiguous sub-buffer preceding the last buffer.
/// The last buffer is allowed to be smaller.
///
- public int BufferLength { get; }
+ int BufferLength { get; }
///
/// Gets the aggregate number of elements in the group.
///
- public long TotalLength { get; }
+ long TotalLength { get; }
///
/// Gets a value indicating whether the group has been invalidated.
@@ -33,5 +33,15 @@ namespace SixLabors.ImageSharp.Memory
/// the image buffers internally.
///
bool IsValid { get; }
+
+ ///
+ /// Returns a value-type implementing an allocation-free enumerator of the memory groups in the current
+ /// instance. The return type shouldn't be used directly: just use a block on
+ /// the instance in use and the C# compiler will automatically invoke this
+ /// method behind the scenes. This method takes precedence over the
+ /// implementation, which is still available when casting to one of the underlying interfaces.
+ ///
+ /// A new instance mapping the current values in use.
+ new MemoryGroupEnumerator GetEnumerator();
}
}
diff --git a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupEnumerator{T}.cs b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupEnumerator{T}.cs
new file mode 100644
index 000000000..64f7e368c
--- /dev/null
+++ b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupEnumerator{T}.cs
@@ -0,0 +1,69 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using System;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
+
+namespace SixLabors.ImageSharp.Memory
+{
+ ///
+ /// A value-type enumerator for instances.
+ ///
+ /// The element type.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public ref struct MemoryGroupEnumerator
+ where T : struct
+ {
+ private readonly IMemoryGroup memoryGroup;
+ private readonly int count;
+ private int index;
+
+ [MethodImpl(InliningOptions.ShortMethod)]
+ internal MemoryGroupEnumerator(MemoryGroup.Owned memoryGroup)
+ {
+ this.memoryGroup = memoryGroup;
+ this.count = memoryGroup.Count;
+ this.index = -1;
+ }
+
+ [MethodImpl(InliningOptions.ShortMethod)]
+ internal MemoryGroupEnumerator(MemoryGroup.Consumed memoryGroup)
+ {
+ this.memoryGroup = memoryGroup;
+ this.count = memoryGroup.Count;
+ this.index = -1;
+ }
+
+ [MethodImpl(InliningOptions.ShortMethod)]
+ internal MemoryGroupEnumerator(MemoryGroupView memoryGroup)
+ {
+ this.memoryGroup = memoryGroup;
+ this.count = memoryGroup.Count;
+ this.index = -1;
+ }
+
+ ///
+ public Memory Current
+ {
+ [MethodImpl(InliningOptions.ShortMethod)]
+ get => this.memoryGroup[this.index];
+ }
+
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public bool MoveNext()
+ {
+ int index = this.index + 1;
+
+ if (index < this.count)
+ {
+ this.index = index;
+
+ return true;
+ }
+
+ return false;
+ }
+ }
+}
diff --git a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs
index 28da49263..ca8123f6a 100644
--- a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs
+++ b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
@@ -38,6 +38,12 @@ namespace SixLabors.ImageSharp.Memory
Guard.MustBeLessThan(start, group.TotalLength, nameof(start));
int bufferIdx = (int)(start / group.BufferLength);
+
+ if (bufferIdx < 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(start));
+ }
+
if (bufferIdx >= group.Count)
{
throw new ArgumentOutOfRangeException(nameof(start));
diff --git a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupView{T}.cs b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupView{T}.cs
index 3f39ba12f..d301b528d 100644
--- a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupView{T}.cs
+++ b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupView{T}.cs
@@ -1,10 +1,11 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
+using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Memory
{
@@ -37,6 +38,7 @@ namespace SixLabors.ImageSharp.Memory
public int Count
{
+ [MethodImpl(InliningOptions.ShortMethod)]
get
{
this.EnsureIsValid();
@@ -73,7 +75,15 @@ namespace SixLabors.ImageSharp.Memory
}
}
- public IEnumerator> GetEnumerator()
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public MemoryGroupEnumerator GetEnumerator()
+ {
+ return new MemoryGroupEnumerator(this);
+ }
+
+ ///
+ IEnumerator> IEnumerable>.GetEnumerator()
{
this.EnsureIsValid();
for (int i = 0; i < this.Count; i++)
@@ -82,7 +92,8 @@ namespace SixLabors.ImageSharp.Memory
}
}
- IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
+ ///
+ IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable>)this).GetEnumerator();
internal void Invalidate()
{
diff --git a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Consumed.cs b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Consumed.cs
index f1fe4ed9c..3f21d768c 100644
--- a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Consumed.cs
+++ b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Consumed.cs
@@ -1,17 +1,18 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
-using System.Buffers;
using System.Collections.Generic;
-using System.Linq;
+using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Memory
{
internal abstract partial class MemoryGroup
{
- // Analogous to the "consumed" variant of MemorySource
- private sealed class Consumed : MemoryGroup
+ ///
+ /// A implementation that consumes the underlying memory buffers.
+ ///
+ public sealed class Consumed : MemoryGroup, IEnumerable>
{
private readonly Memory[] source;
@@ -22,16 +23,31 @@ namespace SixLabors.ImageSharp.Memory
this.View = new MemoryGroupView(this);
}
- public override int Count => this.source.Length;
+ public override int Count
+ {
+ [MethodImpl(InliningOptions.ShortMethod)]
+ get => this.source.Length;
+ }
public override Memory this[int index] => this.source[index];
- public override IEnumerator> GetEnumerator()
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public override MemoryGroupEnumerator GetEnumerator()
+ {
+ return new MemoryGroupEnumerator(this);
+ }
+
+ ///
+ IEnumerator> IEnumerable>.GetEnumerator()
{
- for (int i = 0; i < this.source.Length; i++)
- {
- yield return this.source[i];
- }
+ /* The runtime sees the Array class as if it implemented the
+ * type-generic collection interfaces explicitly, so here we
+ * can just cast the source array to IList> (or to
+ * an equivalent type), and invoke the generic GetEnumerator
+ * method directly from that interface reference. This saves
+ * having to create our own iterator block here. */
+ return ((IList>)this.source).GetEnumerator();
}
public override void Dispose()
diff --git a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs
index b42b90d28..041e5838a 100644
--- a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs
+++ b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs
@@ -1,17 +1,20 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Memory
{
- // Analogous to the "owned" variant of MemorySource
internal abstract partial class MemoryGroup
{
- private sealed class Owned : MemoryGroup
+ ///
+ /// A implementation that owns the underlying memory buffers.
+ ///
+ public sealed class Owned : MemoryGroup, IEnumerable>
{
private IMemoryOwner[] memoryOwners;
@@ -29,6 +32,7 @@ namespace SixLabors.ImageSharp.Memory
public override int Count
{
+ [MethodImpl(InliningOptions.ShortMethod)]
get
{
this.EnsureNotDisposed();
@@ -45,7 +49,15 @@ namespace SixLabors.ImageSharp.Memory
}
}
- public override IEnumerator> GetEnumerator()
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public override MemoryGroupEnumerator GetEnumerator()
+ {
+ return new MemoryGroupEnumerator(this);
+ }
+
+ ///
+ IEnumerator> IEnumerable>.GetEnumerator()
{
this.EnsureNotDisposed();
return this.memoryOwners.Select(mo => mo.Memory).GetEnumerator();
@@ -69,14 +81,21 @@ namespace SixLabors.ImageSharp.Memory
this.IsValid = false;
}
+ [MethodImpl(InliningOptions.ShortMethod)]
private void EnsureNotDisposed()
{
- if (this.memoryOwners == null)
+ if (this.memoryOwners is null)
{
- throw new ObjectDisposedException(nameof(MemoryGroup));
+ ThrowObjectDisposedException();
}
}
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static void ThrowObjectDisposedException()
+ {
+ throw new ObjectDisposedException(nameof(MemoryGroup));
+ }
+
internal static void SwapContents(Owned a, Owned b)
{
a.EnsureNotDisposed();
diff --git a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs
index 38de57b4a..f010855bc 100644
--- a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs
+++ b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs
@@ -1,12 +1,11 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
-using SixLabors.ImageSharp.Memory.Internals;
namespace SixLabors.ImageSharp.Memory
{
@@ -48,10 +47,21 @@ namespace SixLabors.ImageSharp.Memory
public abstract void Dispose();
///
- public abstract IEnumerator> GetEnumerator();
+ public abstract MemoryGroupEnumerator GetEnumerator();
///
- IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
+ IEnumerator> IEnumerable>.GetEnumerator()
+ {
+ /* This method is implemented in each derived class.
+ * Implementing the method here as non-abstract and throwing,
+ * then reimplementing it explicitly in each derived class, is
+ * a workaround for the lack of support for abstract explicit
+ * interface method implementations in C#. */
+ throw new NotImplementedException($"The type {this.GetType()} needs to override IEnumerable>.GetEnumerator()");
+ }
+
+ ///
+ IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable>)this).GetEnumerator();
///
/// Creates a new memory group, allocating it's buffers with the provided allocator.
diff --git a/src/ImageSharp/Memory/InvalidMemoryOperationException.cs b/src/ImageSharp/Memory/InvalidMemoryOperationException.cs
index c1d5c5d41..88df49bd3 100644
--- a/src/ImageSharp/Memory/InvalidMemoryOperationException.cs
+++ b/src/ImageSharp/Memory/InvalidMemoryOperationException.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs
index 22d1bddd2..1595b0f48 100644
--- a/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs
+++ b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Buffers;
diff --git a/src/ImageSharp/Memory/MemoryOwnerExtensions.cs b/src/ImageSharp/Memory/MemoryOwnerExtensions.cs
index 6d4468f78..d86b1e784 100644
--- a/src/ImageSharp/Memory/MemoryOwnerExtensions.cs
+++ b/src/ImageSharp/Memory/MemoryOwnerExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Memory/RowInterval.cs b/src/ImageSharp/Memory/RowInterval.cs
index c2962cfe9..4f3df7df5 100644
--- a/src/ImageSharp/Memory/RowInterval.cs
+++ b/src/ImageSharp/Memory/RowInterval.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Memory/TransformItemsDelegate{T}.cs b/src/ImageSharp/Memory/TransformItemsDelegate{T}.cs
index 31825b7b4..5e14e90f2 100644
--- a/src/ImageSharp/Memory/TransformItemsDelegate{T}.cs
+++ b/src/ImageSharp/Memory/TransformItemsDelegate{T}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Memory/TransformItemsInplaceDelegate.cs b/src/ImageSharp/Memory/TransformItemsInplaceDelegate.cs
index 023606f52..e6981548b 100644
--- a/src/ImageSharp/Memory/TransformItemsInplaceDelegate.cs
+++ b/src/ImageSharp/Memory/TransformItemsInplaceDelegate.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/FrameDecodingMode.cs b/src/ImageSharp/Metadata/FrameDecodingMode.cs
index 835e43354..55cfdc6ab 100644
--- a/src/ImageSharp/Metadata/FrameDecodingMode.cs
+++ b/src/ImageSharp/Metadata/FrameDecodingMode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata
{
diff --git a/src/ImageSharp/Metadata/ImageFrameMetadata.cs b/src/ImageSharp/Metadata/ImageFrameMetadata.cs
index 3858a7d0a..19b4d8aa6 100644
--- a/src/ImageSharp/Metadata/ImageFrameMetadata.cs
+++ b/src/ImageSharp/Metadata/ImageFrameMetadata.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Collections.Generic;
using SixLabors.ImageSharp.Formats;
diff --git a/src/ImageSharp/Metadata/ImageMetadata.cs b/src/ImageSharp/Metadata/ImageMetadata.cs
index b3751bfbd..a9b2e9658 100644
--- a/src/ImageSharp/Metadata/ImageMetadata.cs
+++ b/src/ImageSharp/Metadata/ImageMetadata.cs
@@ -1,10 +1,11 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Collections.Generic;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.Metadata.Profiles.Icc;
+using SixLabors.ImageSharp.Metadata.Profiles.Iptc;
namespace SixLabors.ImageSharp.Metadata
{
@@ -65,6 +66,7 @@ namespace SixLabors.ImageSharp.Metadata
this.ExifProfile = other.ExifProfile?.DeepClone();
this.IccProfile = other.IccProfile?.DeepClone();
+ this.IptcProfile = other.IptcProfile?.DeepClone();
}
///
@@ -122,6 +124,11 @@ namespace SixLabors.ImageSharp.Metadata
///
public IccProfile IccProfile { get; set; }
+ ///
+ /// Gets or sets the iptc profile.
+ ///
+ public IptcProfile IptcProfile { get; set; }
+
///
/// Gets the metadata value associated with the specified key.
///
diff --git a/src/ImageSharp/Metadata/PixelResolutionUnit.cs b/src/ImageSharp/Metadata/PixelResolutionUnit.cs
index 661e7a308..d894ce877 100644
--- a/src/ImageSharp/Metadata/PixelResolutionUnit.cs
+++ b/src/ImageSharp/Metadata/PixelResolutionUnit.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifConstants.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifConstants.cs
index c58b224e4..f2c237094 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/ExifConstants.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifConstants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifDataType.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifDataType.cs
index 74c86f721..d6273f0dc 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/ExifDataType.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifDataType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifDataTypes.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifDataTypes.cs
index d94dc5640..870a7714a 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/ExifDataTypes.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifDataTypes.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifParts.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifParts.cs
index 6405a7ff2..189edf8ca 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/ExifParts.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifParts.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.cs
index 11d0bd01b..2c26cfd57 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
@@ -57,8 +57,11 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
/// by making a copy from another EXIF profile.
///
/// The other EXIF profile, where the clone should be made from.
+ /// is null.>
private ExifProfile(ExifProfile other)
{
+ Guard.NotNull(other, nameof(other));
+
this.Parts = other.Parts;
this.thumbnailLength = other.thumbnailLength;
this.thumbnailOffset = other.thumbnailOffset;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs
index 6ad8d24fa..1e944b999 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifTagDescriptionAttribute.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifTagDescriptionAttribute.cs
index b9bb2ee05..c1f3aaf9a 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/ExifTagDescriptionAttribute.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifTagDescriptionAttribute.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Reflection;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifTags.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifTags.cs
index a4123d02f..38ef49197 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/ExifTags.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifTags.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifWriter.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifWriter.cs
index b00813730..70d2664ff 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/ExifWriter.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifWriter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Byte.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Byte.cs
index dc33fd8b0..0f22d358a 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Byte.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Byte.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.ByteArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.ByteArray.cs
index 2bfa8ff21..ef59c9d90 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.ByteArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.ByteArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.DoubleArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.DoubleArray.cs
index 6cbae4c55..76482fb75 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.DoubleArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.DoubleArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Long.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Long.cs
index 571b50efb..8f2fd3e62 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Long.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Long.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.LongArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.LongArray.cs
index 120f2dab0..e164f3c62 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.LongArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.LongArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Number.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Number.cs
index 6cea52b1a..9c3e30d50 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Number.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Number.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.NumberArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.NumberArray.cs
index b515ab36a..ddc0d3b0f 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.NumberArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.NumberArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Rational.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Rational.cs
index 2281dee49..a53f81579 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Rational.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Rational.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.RationalArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.RationalArray.cs
index cf43a8a8a..741e40c7d 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.RationalArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.RationalArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Short.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Short.cs
index 7fe9a58bc..6bca94afd 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Short.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Short.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.ShortArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.ShortArray.cs
index 90485f75a..f5a386cb8 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.ShortArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.ShortArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.SignedRational.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.SignedRational.cs
index 29d61db88..00d29ad4a 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.SignedRational.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.SignedRational.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.SignedRationalArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.SignedRationalArray.cs
index 9a6e3063b..954b544a6 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.SignedRationalArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.SignedRationalArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.String.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.String.cs
index 506f87454..24a4789c1 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.String.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.String.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Undefined.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Undefined.cs
index 5f4841226..4a2af0bff 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Undefined.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Undefined.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.cs
index 65e031462..35a6fbab9 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTagValue.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTagValue.cs
index f70bcea37..a35b3301c 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTagValue.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTagValue.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag{TValueType}.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag{TValueType}.cs
index 5a674277a..6b727e8db 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag{TValueType}.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag{TValueType}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Tags/UnkownExifTag.cs b/src/ImageSharp/Metadata/Profiles/Exif/Tags/UnkownExifTag.cs
index 8f0b36638..51cab264a 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Tags/UnkownExifTag.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Tags/UnkownExifTag.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifArrayValue{TValueType}.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifArrayValue{TValueType}.cs
index 263bf0934..3d1282ca4 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifArrayValue{TValueType}.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifArrayValue{TValueType}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByte.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByte.cs
index 184f4a07c..d55447ed7 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByte.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByte.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByteArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByteArray.cs
index 854eafc76..83819844d 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByteArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByteArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifDouble.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifDouble.cs
index 0af5f47ce..2d0ac3a0f 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifDouble.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifDouble.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifDoubleArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifDoubleArray.cs
index 259d5c98a..6157cffc9 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifDoubleArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifDoubleArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifFloat.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifFloat.cs
index 8d6c41f58..4c53b36cf 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifFloat.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifFloat.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifFloatArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifFloatArray.cs
index 7789bc3b5..3dfd2989d 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifFloatArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifFloatArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong.cs
index 7f2f631a9..98d016af0 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLongArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLongArray.cs
index e05f50bee..944cd6ceb 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLongArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLongArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumber.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumber.cs
index ef7d20c85..a36eae16f 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumber.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumber.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumberArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumberArray.cs
index 521cfc085..414996ed1 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumberArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumberArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRational.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRational.cs
index 3ab77ab32..2afca7dba 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRational.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRational.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRationalArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRationalArray.cs
index f78e363da..866e8d22b 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRationalArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRationalArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShort.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShort.cs
index b11f3fc9f..c8837b82e 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShort.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShort.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShortArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShortArray.cs
index 379338c10..39d0bac4d 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShortArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShortArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedByte.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedByte.cs
index a9cb013ca..8d18f8eb7 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedByte.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedByte.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedByteArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedByteArray.cs
index b0d35cc8a..6da81f77b 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedByteArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedByteArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedLong.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedLong.cs
index c1e6808bf..be5aef3d0 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedLong.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedLong.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedLongArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedLongArray.cs
index 36d4c0007..e94f66b59 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedLongArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedLongArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedRational.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedRational.cs
index 61fba979b..90c30501c 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedRational.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedRational.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedRationalArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedRationalArray.cs
index 2545bd9b2..88927c548 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedRationalArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedRationalArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShort.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShort.cs
index e00f5c085..a460f1407 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShort.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShort.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShortArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShortArray.cs
index 403a50186..14bb59071 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShortArray.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShortArray.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifString.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifString.cs
index 0678bc3e4..a4429de7d 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifString.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifString.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue.cs
index 547e099c9..0c6f61d18 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValues.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValues.cs
index 62d3f40ac..f5caf1583 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValues.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValues.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue{TValueType}.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue{TValueType}.cs
index 601630af6..25b8d1dbb 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue{TValueType}.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue{TValueType}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/IExifValue.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/IExifValue.cs
index 50c421832..ca780448c 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/IExifValue.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/IExifValue.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/IExifValue{TValueType}.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/IExifValue{TValueType}.cs
index 72b93ddf9..9631d780a 100644
--- a/src/ImageSharp/Metadata/Profiles/Exif/Values/IExifValue{TValueType}.cs
+++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/IExifValue{TValueType}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccCurveSegment.cs b/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccCurveSegment.cs
index 7bf1f8421..6880385d1 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccCurveSegment.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccCurveSegment.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccFormulaCurveElement.cs b/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccFormulaCurveElement.cs
index d013f6ef1..ec2f9bd01 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccFormulaCurveElement.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccFormulaCurveElement.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccOneDimensionalCurve.cs b/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccOneDimensionalCurve.cs
index cbb433012..36877916a 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccOneDimensionalCurve.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccOneDimensionalCurve.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccParametricCurve.cs b/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccParametricCurve.cs
index 04a9faf7d..a6cedd530 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccParametricCurve.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccParametricCurve.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccResponseCurve.cs b/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccResponseCurve.cs
index b9a50acd4..c55c145fd 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccResponseCurve.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccResponseCurve.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccSampledCurveElement.cs b/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccSampledCurveElement.cs
index 4872bd2b0..30e9bf4b4 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccSampledCurveElement.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Curves/IccSampledCurveElement.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Curves.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Curves.cs
index 58ca46d81..4f9cebce4 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Curves.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Curves.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Lut.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Lut.cs
index 0aa3c31e0..dd3c5020b 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Lut.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Lut.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Matrix.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Matrix.cs
index ecc33dd77..7541fe1e3 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Matrix.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Matrix.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.MultiProcessElement.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.MultiProcessElement.cs
index b854247da..7cbb146ec 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.MultiProcessElement.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.MultiProcessElement.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs
index b5326225c..bbeb2f211 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Primitives.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Primitives.cs
index 3f016444b..00c902339 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Primitives.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Primitives.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs
index a30e45dde..91dd8bbc1 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.cs
index 79542b85f..14ad06bb8 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs
index 4f03ed610..6a7564ec4 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs
index 016bd8009..fd9310e74 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs
index 585892e96..d03d17330 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElement.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElement.cs
index 65490f180..2854fb3e8 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElement.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElement.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs
index ce80574ad..4af49e5db 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs
index 6c49eb0c4..2053fed41 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Text;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs
index b761f48ba..5577d7c24 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Linq;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.cs
index 17f15df71..9c72fa3e5 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.IO;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccClutDataType.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccClutDataType.cs
index 71e68f6af..e1306e689 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccClutDataType.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccClutDataType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccColorSpaceType.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccColorSpaceType.cs
index 721545df3..649e2700c 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccColorSpaceType.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccColorSpaceType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccColorantEncoding.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccColorantEncoding.cs
index 14b2dd960..d42195cd1 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccColorantEncoding.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccColorantEncoding.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccCurveMeasurementEncodings.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccCurveMeasurementEncodings.cs
index a620632da..5b58b74c2 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccCurveMeasurementEncodings.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccCurveMeasurementEncodings.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccCurveSegmentSignature.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccCurveSegmentSignature.cs
index 9a5ae1805..a66556cbe 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccCurveSegmentSignature.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccCurveSegmentSignature.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccDataType.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccDataType.cs
index de1f11636..57a25e254 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccDataType.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccDataType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccDeviceAttribute.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccDeviceAttribute.cs
index c8598b0e0..0428789e2 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccDeviceAttribute.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccDeviceAttribute.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccFormulaCurveType.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccFormulaCurveType.cs
index 11e5985af..be43bc3ff 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccFormulaCurveType.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccFormulaCurveType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccMeasurementGeometry.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccMeasurementGeometry.cs
index 937324194..4849fa3af 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccMeasurementGeometry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccMeasurementGeometry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccMultiProcessElementSignature.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccMultiProcessElementSignature.cs
index d7f78889d..2f216ff37 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccMultiProcessElementSignature.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccMultiProcessElementSignature.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccParametricCurveType.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccParametricCurveType.cs
index fce08a3af..9d87d9548 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccParametricCurveType.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccParametricCurveType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccPrimaryPlatformType.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccPrimaryPlatformType.cs
index 035fd3d4d..07abc024f 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccPrimaryPlatformType.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccPrimaryPlatformType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccProfileClass.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccProfileClass.cs
index 3d59192a7..db49aa4ce 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccProfileClass.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccProfileClass.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccProfileFlag.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccProfileFlag.cs
index 9fbe5b5b5..fc1f3237c 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccProfileFlag.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccProfileFlag.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccProfileTag.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccProfileTag.cs
index b19641e0f..cb901028b 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccProfileTag.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccProfileTag.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccRenderingIntent.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccRenderingIntent.cs
index 8ae241b44..301b7448f 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccRenderingIntent.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccRenderingIntent.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccScreeningFlag.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccScreeningFlag.cs
index b43ad52c4..ead39c3c5 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccScreeningFlag.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccScreeningFlag.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccScreeningSpotType.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccScreeningSpotType.cs
index 0631892b6..414db39bf 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccScreeningSpotType.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccScreeningSpotType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccSignatureName.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccSignatureName.cs
index f93d22f3e..af3c7a3f0 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccSignatureName.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccSignatureName.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccStandardIlluminant.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccStandardIlluminant.cs
index fc8ebae5c..961a7f2cd 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccStandardIlluminant.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccStandardIlluminant.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccStandardObserver.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccStandardObserver.cs
index 14c0a0467..fb5e8cac4 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccStandardObserver.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccStandardObserver.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccTypeSignature.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccTypeSignature.cs
index d7a18579e..751020c3c 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccTypeSignature.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccTypeSignature.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Exceptions/InvalidIccProfileException.cs b/src/ImageSharp/Metadata/Profiles/ICC/Exceptions/InvalidIccProfileException.cs
index 019bf9202..3d031e25b 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Exceptions/InvalidIccProfileException.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Exceptions/InvalidIccProfileException.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/IccProfile.cs b/src/ImageSharp/Metadata/Profiles/ICC/IccProfile.cs
index 7c5139475..53157b95e 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/IccProfile.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/IccProfile.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Security.Cryptography;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/IccProfileHeader.cs b/src/ImageSharp/Metadata/Profiles/ICC/IccProfileHeader.cs
index 326dd351e..d5962318b 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/IccProfileHeader.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/IccProfileHeader.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs b/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs
index 30a6de40d..9c02f3a8c 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/IccTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/IccTagDataEntry.cs
index 658d4c2f1..6bdd6b993 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/IccTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/IccTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs b/src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs
index 186f06df0..e1e181dc6 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Collections.Generic;
using System.Linq;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccBAcsProcessElement.cs b/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccBAcsProcessElement.cs
index c825a3535..f95236f29 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccBAcsProcessElement.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccBAcsProcessElement.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccClutProcessElement.cs b/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccClutProcessElement.cs
index 7ee7f821d..4e68c411b 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccClutProcessElement.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccClutProcessElement.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccCurveSetProcessElement.cs b/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccCurveSetProcessElement.cs
index c6409e3c1..397a9c292 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccCurveSetProcessElement.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccCurveSetProcessElement.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccEAcsProcessElement.cs b/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccEAcsProcessElement.cs
index d6f42aea7..1ad702da0 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccEAcsProcessElement.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccEAcsProcessElement.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs b/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs
index 668883e1a..0208220d9 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs b/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs
index 24649d8b5..6bbee5b8d 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs
index 813271d48..072644827 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Linq;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs
index 4136b9a38..bed0446b1 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs
index aff33ff82..881b14427 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs
index bcf9d5c9e..998e8d920 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs
index f2205cbad..43592cc9d 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs
index 6a0b6c05e..118f0d0bd 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Text;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs
index 371397a6f..56c25a7c7 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs
index 50bfca175..46e303896 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs
index 8f7db49ad..d8d13a15e 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs
index 3a1859a1c..190265fe9 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Linq;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs
index 0dfaef7d4..223165acd 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Linq;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs
index 929a70ed8..b0f20a08b 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Linq;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs
index ad3a9f2c3..68440870d 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs
index 34a027126..8c61f7744 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs
index f2713e8ce..966b1cb6d 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Linq;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs
index 4fd0cfcfb..457ee49b4 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Linq;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs
index 752d05aae..b384d10fe 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs
index 7897c394f..9a5c108e9 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs
index 06e52cb63..26dea9d1b 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs
index e9c8af9be..3db6afccb 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Linq;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs
index bf64e4fed..a9761a270 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs
index 87d369f85..70d982f0b 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs
index 23e81fe99..0791cd77d 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs
index 6cf9e9154..0e6e82679 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs
index 3e4a5ff3a..49cd4518e 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs
index 46799b16a..0c41770d7 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs
index 9fbbf8bf5..7f5de5b88 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs
index 09bec9b7a..7e18675d6 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs
index 099916d89..94740250c 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs
index d28b6edc9..b0f2325a8 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs
index 0227983fa..feea43293 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs
index 2b2893c38..fe60ca6da 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs
index 1e7d53231..67f25934c 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccClut.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccClut.cs
index bd8f784ae..14c11cfa5 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccClut.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccClut.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Linq;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccColorantTableEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccColorantTableEntry.cs
index db1feea9a..60fc7e54f 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccColorantTableEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccColorantTableEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccLocalizedString.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccLocalizedString.cs
index b2852c8a3..c8d097d38 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccLocalizedString.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccLocalizedString.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Globalization;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccLut.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccLut.cs
index 9e0c6c40d..bacf3f22a 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccLut.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccLut.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccNamedColor.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccNamedColor.cs
index 3c640ab03..c55a1849a 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccNamedColor.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccNamedColor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccPositionNumber.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccPositionNumber.cs
index c9b75903d..959269b4e 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccPositionNumber.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccPositionNumber.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccProfileDescription.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccProfileDescription.cs
index d630f015e..476f43c26 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccProfileDescription.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccProfileDescription.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccProfileId.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccProfileId.cs
index 4a73f7e07..c113e8ddf 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccProfileId.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccProfileId.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccProfileSequenceIdentifier.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccProfileSequenceIdentifier.cs
index 6bf420b49..7818229e1 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccProfileSequenceIdentifier.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccProfileSequenceIdentifier.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccResponseNumber.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccResponseNumber.cs
index 859080263..ea9f3286c 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccResponseNumber.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccResponseNumber.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccScreeningChannel.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccScreeningChannel.cs
index 354442b47..7736255c3 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccScreeningChannel.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccScreeningChannel.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.InteropServices;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccTagTableEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccTagTableEntry.cs
index 889dec41e..1ce66146e 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccTagTableEntry.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccTagTableEntry.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccVersion.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccVersion.cs
index b388fa5a4..d8f5b13fe 100644
--- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccVersion.cs
+++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccVersion.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Metadata/Profiles/IPTC/IIMV4.2_IPTC.pdf b/src/ImageSharp/Metadata/Profiles/IPTC/IIMV4.2_IPTC.pdf
new file mode 100644
index 000000000..b00355181
Binary files /dev/null and b/src/ImageSharp/Metadata/Profiles/IPTC/IIMV4.2_IPTC.pdf differ
diff --git a/src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs b/src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs
new file mode 100644
index 000000000..6e864db14
--- /dev/null
+++ b/src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs
@@ -0,0 +1,298 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using System;
+using System.Buffers.Binary;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Text;
+
+namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc
+{
+ ///
+ /// Represents an IPTC profile providing access to the collection of values.
+ ///
+ public sealed class IptcProfile : IDeepCloneable
+ {
+ private Collection values;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public IptcProfile()
+ : this((byte[])null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The byte array to read the iptc profile from.
+ public IptcProfile(byte[] data)
+ {
+ this.Data = data;
+ this.Initialize();
+ }
+
+ ///
+ /// Initializes a new instance of the class
+ /// by making a copy from another IPTC profile.
+ ///
+ /// The other IPTC profile, from which the clone should be made from.
+ private IptcProfile(IptcProfile other)
+ {
+ Guard.NotNull(other, nameof(other));
+
+ if (other.values != null)
+ {
+ this.values = new Collection();
+
+ foreach (IptcValue value in other.Values)
+ {
+ this.values.Add(value.DeepClone());
+ }
+ }
+
+ if (other.Data != null)
+ {
+ this.Data = new byte[other.Data.Length];
+ other.Data.AsSpan().CopyTo(this.Data);
+ }
+ }
+
+ ///
+ /// Gets the byte data of the IPTC profile.
+ ///
+ public byte[] Data { get; private set; }
+
+ ///
+ /// Gets the values of this iptc profile.
+ ///
+ public IEnumerable Values
+ {
+ get
+ {
+ this.Initialize();
+ return this.values;
+ }
+ }
+
+ ///
+ public IptcProfile DeepClone() => new IptcProfile(this);
+
+ ///
+ /// Returns all values with the specified tag.
+ ///
+ /// The tag of the iptc value.
+ /// The values found with the specified tag.
+ public List GetValues(IptcTag tag)
+ {
+ var iptcValues = new List();
+ foreach (IptcValue iptcValue in this.Values)
+ {
+ if (iptcValue.Tag == tag)
+ {
+ iptcValues.Add(iptcValue);
+ }
+ }
+
+ return iptcValues;
+ }
+
+ ///
+ /// Removes all values with the specified tag.
+ ///
+ /// The tag of the iptc value to remove.
+ /// True when the value was found and removed.
+ public bool RemoveValue(IptcTag tag)
+ {
+ this.Initialize();
+
+ bool removed = false;
+ for (int i = this.values.Count - 1; i >= 0; i--)
+ {
+ if (this.values[i].Tag == tag)
+ {
+ this.values.RemoveAt(i);
+ removed = true;
+ }
+ }
+
+ return removed;
+ }
+
+ ///
+ /// Removes values with the specified tag and value.
+ ///
+ /// The tag of the iptc value to remove.
+ /// The value of the iptc item to remove.
+ /// True when the value was found and removed.
+ public bool RemoveValue(IptcTag tag, string value)
+ {
+ this.Initialize();
+
+ bool removed = false;
+ for (int i = this.values.Count - 1; i >= 0; i--)
+ {
+ if (this.values[i].Tag == tag && this.values[i].Value.Equals(value))
+ {
+ this.values.RemoveAt(i);
+ removed = true;
+ }
+ }
+
+ return removed;
+ }
+
+ ///
+ /// Changes the encoding for all the values.
+ ///
+ /// The encoding to use when storing the bytes.
+ public void SetEncoding(Encoding encoding)
+ {
+ Guard.NotNull(encoding, nameof(encoding));
+
+ foreach (IptcValue value in this.Values)
+ {
+ value.Encoding = encoding;
+ }
+ }
+
+ ///
+ /// Sets the value for the specified tag.
+ ///
+ /// The tag of the iptc value.
+ /// The encoding to use when storing the bytes.
+ /// The value.
+ ///
+ /// Indicates if length restrictions from the specification should be followed strictly.
+ /// Defaults to true.
+ ///
+ public void SetValue(IptcTag tag, Encoding encoding, string value, bool strict = true)
+ {
+ Guard.NotNull(encoding, nameof(encoding));
+ Guard.NotNull(value, nameof(value));
+
+ if (!tag.IsRepeatable())
+ {
+ foreach (IptcValue iptcValue in this.Values)
+ {
+ if (iptcValue.Tag == tag)
+ {
+ iptcValue.Strict = strict;
+ iptcValue.Encoding = encoding;
+ iptcValue.Value = value;
+ return;
+ }
+ }
+ }
+
+ this.values.Add(new IptcValue(tag, encoding, value, strict));
+ }
+
+ ///
+ /// Makes sure the datetime is formatted according to the iptc specification.
+ ///
+ /// A date will be formatted as CCYYMMDD, e.g. "19890317" for 17 March 1989.
+ /// A time value will be formatted as HHMMSS±HHMM, e.g. "090000+0200" for 9 o'clock Berlin time,
+ /// two hours ahead of UTC.
+ ///
+ ///
+ /// The tag of the iptc value.
+ /// The datetime.
+ public void SetDateTimeValue(IptcTag tag, DateTimeOffset dateTimeOffset)
+ {
+ if (!tag.IsDate() && !tag.IsTime())
+ {
+ throw new ArgumentException("iptc tag is not a time or date type");
+ }
+
+ var formattedDate = tag.IsDate()
+ ? dateTimeOffset.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture)
+ : dateTimeOffset.ToString("HHmmsszzzz", System.Globalization.CultureInfo.InvariantCulture)
+ .Replace(":", string.Empty);
+
+ this.SetValue(tag, Encoding.UTF8, formattedDate);
+ }
+
+ ///
+ /// Sets the value of the specified tag.
+ ///
+ /// The tag of the iptc value.
+ /// The value.
+ ///
+ /// Indicates if length restrictions from the specification should be followed strictly.
+ /// Defaults to true.
+ ///
+ public void SetValue(IptcTag tag, string value, bool strict = true) => this.SetValue(tag, Encoding.UTF8, value, strict);
+
+ ///
+ /// Updates the data of the profile.
+ ///
+ public void UpdateData()
+ {
+ var length = 0;
+ foreach (IptcValue value in this.Values)
+ {
+ length += value.Length + 5;
+ }
+
+ this.Data = new byte[length];
+
+ int i = 0;
+ foreach (IptcValue value in this.Values)
+ {
+ this.Data[i++] = 28;
+ this.Data[i++] = 2;
+ this.Data[i++] = (byte)value.Tag;
+ this.Data[i++] = (byte)(value.Length >> 8);
+ this.Data[i++] = (byte)value.Length;
+ if (value.Length > 0)
+ {
+ Buffer.BlockCopy(value.ToByteArray(), 0, this.Data, i, value.Length);
+ i += value.Length;
+ }
+ }
+ }
+
+ private void Initialize()
+ {
+ if (this.values != null)
+ {
+ return;
+ }
+
+ this.values = new Collection();
+
+ if (this.Data == null || this.Data[0] != 0x1c)
+ {
+ return;
+ }
+
+ int i = 0;
+ while (i + 4 < this.Data.Length)
+ {
+ if (this.Data[i++] != 28)
+ {
+ continue;
+ }
+
+ i++;
+
+ var tag = (IptcTag)this.Data[i++];
+
+ int count = BinaryPrimitives.ReadInt16BigEndian(this.Data.AsSpan(i, 2));
+ i += 2;
+
+ var iptcData = new byte[count];
+ if ((count > 0) && (i + count <= this.Data.Length))
+ {
+ Buffer.BlockCopy(this.Data, i, iptcData, 0, count);
+ this.values.Add(new IptcValue(tag, iptcData, false));
+ }
+
+ i += count;
+ }
+ }
+ }
+}
diff --git a/src/ImageSharp/Metadata/Profiles/IPTC/IptcTag.cs b/src/ImageSharp/Metadata/Profiles/IPTC/IptcTag.cs
new file mode 100644
index 000000000..68807918c
--- /dev/null
+++ b/src/ImageSharp/Metadata/Profiles/IPTC/IptcTag.cs
@@ -0,0 +1,397 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc
+{
+ ///
+ /// Provides enumeration of all IPTC tags relevant for images.
+ ///
+ public enum IptcTag
+ {
+ ///
+ /// Unknown.
+ ///
+ Unknown = -1,
+
+ ///
+ /// Record version identifying the version of the Information Interchange Model.
+ /// Not repeatable. Max length is 2.
+ ///
+ RecordVersion = 0,
+
+ ///
+ /// Object type, not repeatable. Max Length is 67.
+ ///
+ ObjectType = 3,
+
+ ///
+ /// Object attribute. Max length is 68.
+ ///
+ ObjectAttribute = 4,
+
+ ///
+ /// Object Name, not repeatable. Max length is 64.
+ ///
+ Name = 5,
+
+ ///
+ /// Edit status, not repeatable. Max length is 64.
+ ///
+ EditStatus = 7,
+
+ ///
+ /// Editorial update, not repeatable. Max length is 2.
+ ///
+ EditorialUpdate = 8,
+
+ ///
+ /// Urgency, not repeatable. Max length is 2.
+ ///
+ Urgency = 10,
+
+ ///
+ /// Subject Reference. Max length is 236.
+ ///
+ SubjectReference = 12,
+
+ ///
+ /// Category, not repeatable. Max length is 3.
+ ///
+ Category = 15,
+
+ ///
+ /// Supplemental categories. Max length is 32.
+ ///
+ SupplementalCategories = 20,
+
+ ///
+ /// Fixture identifier, not repeatable. Max length is 32.
+ ///
+ FixtureIdentifier = 22,
+
+ ///
+ /// Keywords. Max length is 64.
+ ///
+ Keywords = 25,
+
+ ///
+ /// Location code. Max length is 3.
+ ///
+ LocationCode = 26,
+
+ ///
+ /// Location name. Max length is 64.
+ ///
+ LocationName = 27,
+
+ ///
+ /// Release date. Format should be CCYYMMDD.
+ /// Not repeatable, max length is 8.
+ ///
+ /// A date will be formatted as CCYYMMDD, e.g. "19890317" for 17 March 1989.
+ ///
+ ///
+ ReleaseDate = 30,
+
+ ///
+ /// Release time. Format should be HHMMSS±HHMM.
+ /// Not repeatable, max length is 11.
+ ///
+ /// A time value will be formatted as HHMMSS±HHMM, e.g. "090000+0200" for 9 o'clock Berlin time,
+ /// two hours ahead of UTC.
+ ///
+ ///
+ ReleaseTime = 35,
+
+ ///
+ /// Expiration date. Format should be CCYYMMDD.
+ /// Not repeatable, max length is 8.
+ ///
+ /// A date will be formatted as CCYYMMDD, e.g. "19890317" for 17 March 1989.
+ ///
+ ///
+ ExpirationDate = 37,
+
+ ///
+ /// Expiration time. Format should be HHMMSS±HHMM.
+ /// Not repeatable, max length is 11.
+ ///
+ /// A time value will be formatted as HHMMSS±HHMM, e.g. "090000+0200" for 9 o'clock Berlin time,
+ /// two hours ahead of UTC.
+ ///
+ ///
+ ExpirationTime = 38,
+
+ ///
+ /// Special instructions, not repeatable. Max length is 256.
+ ///
+ SpecialInstructions = 40,
+
+ ///
+ /// Action advised, not repeatable. Max length is 2.
+ ///
+ ActionAdvised = 42,
+
+ ///
+ /// Reference service. Max length is 10.
+ ///
+ ReferenceService = 45,
+
+ ///
+ /// Reference date. Format should be CCYYMMDD.
+ /// Not repeatable, max length is 8.
+ ///
+ /// A date will be formatted as CCYYMMDD, e.g. "19890317" for 17 March 1989.
+ ///
+ ///
+ ReferenceDate = 47,
+
+ ///
+ /// ReferenceNumber. Max length is 8.
+ ///
+ ReferenceNumber = 50,
+
+ ///
+ /// Created date. Format should be CCYYMMDD.
+ /// Not repeatable, max length is 8.
+ ///
+ /// A date will be formatted as CCYYMMDD, e.g. "19890317" for 17 March 1989.
+ ///
+ ///
+ CreatedDate = 55,
+
+ ///
+ /// Created time. Format should be HHMMSS±HHMM.
+ /// Not repeatable, max length is 11.
+ ///
+ /// A time value will be formatted as HHMMSS±HHMM, e.g. "090000+0200" for 9 o'clock Berlin time,
+ /// two hours ahead of UTC.
+ ///
+ ///
+ CreatedTime = 60,
+
+ ///
+ /// Digital creation date. Format should be CCYYMMDD.
+ /// Not repeatable, max length is 8.
+ ///
+ /// A date will be formatted as CCYYMMDD, e.g. "19890317" for 17 March 1989.
+ ///
+ ///
+ DigitalCreationDate = 62,
+
+ ///
+ /// Digital creation time. Format should be HHMMSS±HHMM.
+ /// Not repeatable, max length is 11.
+ ///
+ /// A time value will be formatted as HHMMSS±HHMM, e.g. "090000+0200" for 9 o'clock Berlin time,
+ /// two hours ahead of UTC.
+ ///
+ ///
+ DigitalCreationTime = 63,
+
+ ///
+ /// Originating program, not repeatable. Max length is 32.
+ ///
+ OriginatingProgram = 65,
+
+ ///
+ /// Program version, not repeatable. Max length is 10.
+ ///
+ ProgramVersion = 70,
+
+ ///
+ /// Object cycle, not repeatable. Max length is 1.
+ ///
+ ObjectCycle = 75,
+
+ ///
+ /// Byline. Max length is 32.
+ ///
+ Byline = 80,
+
+ ///
+ /// Byline title. Max length is 32.
+ ///
+ BylineTitle = 85,
+
+ ///
+ /// City, not repeatable. Max length is 32.
+ ///
+ City = 90,
+
+ ///
+ /// Sub location, not repeatable. Max length is 32.
+ ///
+ SubLocation = 92,
+
+ ///
+ /// Province/State, not repeatable. Max length is 32.
+ ///
+ ProvinceState = 95,
+
+ ///
+ /// Country code, not repeatable. Max length is 3.
+ ///
+ CountryCode = 100,
+
+ ///
+ /// Country, not repeatable. Max length is 64.
+ ///
+ Country = 101,
+
+ ///
+ /// Original transmission reference, not repeatable. Max length is 32.
+ ///
+ OriginalTransmissionReference = 103,
+
+ ///
+ /// Headline, not repeatable. Max length is 256.
+ ///
+ Headline = 105,
+
+ ///
+ /// Credit, not repeatable. Max length is 32.
+ ///
+ Credit = 110,
+
+ ///
+ /// Source, not repeatable. Max length is 32.
+ ///
+ Source = 115,
+
+ ///
+ /// Copyright notice, not repeatable. Max length is 128.
+ ///
+ CopyrightNotice = 116,
+
+ ///
+ /// Contact. Max length 128.
+ ///
+ Contact = 118,
+
+ ///
+ /// Caption, not repeatable. Max length is 2000.
+ ///
+ Caption = 120,
+
+ ///
+ /// Local caption.
+ ///
+ LocalCaption = 121,
+
+ ///
+ /// Caption writer. Max length is 32.
+ ///
+ CaptionWriter = 122,
+
+ ///
+ /// Image type, not repeatable. Max length is 2.
+ ///
+ ImageType = 130,
+
+ ///
+ /// Image orientation, not repeatable. Max length is 1.
+ ///
+ ImageOrientation = 131,
+
+ ///
+ /// Custom field 1
+ ///
+ CustomField1 = 200,
+
+ ///
+ /// Custom field 2
+ ///
+ CustomField2 = 201,
+
+ ///
+ /// Custom field 3
+ ///
+ CustomField3 = 202,
+
+ ///
+ /// Custom field 4
+ ///
+ CustomField4 = 203,
+
+ ///
+ /// Custom field 5
+ ///
+ CustomField5 = 204,
+
+ ///
+ /// Custom field 6
+ ///
+ CustomField6 = 205,
+
+ ///
+ /// Custom field 7
+ ///
+ CustomField7 = 206,
+
+ ///
+ /// Custom field 8
+ ///
+ CustomField8 = 207,
+
+ ///
+ /// Custom field 9
+ ///
+ CustomField9 = 208,
+
+ ///
+ /// Custom field 10
+ ///
+ CustomField10 = 209,
+
+ ///
+ /// Custom field 11
+ ///
+ CustomField11 = 210,
+
+ ///
+ /// Custom field 12
+ ///
+ CustomField12 = 211,
+
+ ///
+ /// Custom field 13
+ ///
+ CustomField13 = 212,
+
+ ///
+ /// Custom field 14
+ ///
+ CustomField14 = 213,
+
+ ///
+ /// Custom field 15
+ ///
+ CustomField15 = 214,
+
+ ///
+ /// Custom field 16
+ ///
+ CustomField16 = 215,
+
+ ///
+ /// Custom field 17
+ ///
+ CustomField17 = 216,
+
+ ///
+ /// Custom field 18
+ ///
+ CustomField18 = 217,
+
+ ///
+ /// Custom field 19
+ ///
+ CustomField19 = 218,
+
+ ///
+ /// Custom field 20
+ ///
+ CustomField20 = 219,
+ }
+}
diff --git a/src/ImageSharp/Metadata/Profiles/IPTC/IptcTagExtensions.cs b/src/ImageSharp/Metadata/Profiles/IPTC/IptcTagExtensions.cs
new file mode 100644
index 000000000..525d90c89
--- /dev/null
+++ b/src/ImageSharp/Metadata/Profiles/IPTC/IptcTagExtensions.cs
@@ -0,0 +1,162 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc
+{
+ ///
+ /// Extension methods for IPTC tags.
+ ///
+ public static class IptcTagExtensions
+ {
+ ///
+ /// Maximum length of the IPTC value with the given tag according to the specification.
+ ///
+ /// The tag to check the max length for.
+ /// The maximum length.
+ public static int MaxLength(this IptcTag tag)
+ {
+ return tag switch
+ {
+ IptcTag.RecordVersion => 2,
+ IptcTag.ObjectType => 67,
+ IptcTag.ObjectAttribute => 68,
+ IptcTag.Name => 64,
+ IptcTag.EditStatus => 64,
+ IptcTag.EditorialUpdate => 2,
+ IptcTag.Urgency => 1,
+ IptcTag.SubjectReference => 236,
+ IptcTag.Category => 3,
+ IptcTag.SupplementalCategories => 32,
+ IptcTag.FixtureIdentifier => 32,
+ IptcTag.Keywords => 64,
+ IptcTag.LocationCode => 3,
+ IptcTag.LocationName => 64,
+ IptcTag.ReleaseDate => 8,
+ IptcTag.ReleaseTime => 11,
+ IptcTag.ExpirationDate => 8,
+ IptcTag.ExpirationTime => 11,
+ IptcTag.SpecialInstructions => 256,
+ IptcTag.ActionAdvised => 2,
+ IptcTag.ReferenceService => 10,
+ IptcTag.ReferenceDate => 8,
+ IptcTag.ReferenceNumber => 8,
+ IptcTag.CreatedDate => 8,
+ IptcTag.CreatedTime => 11,
+ IptcTag.DigitalCreationDate => 8,
+ IptcTag.DigitalCreationTime => 11,
+ IptcTag.OriginatingProgram => 32,
+ IptcTag.ProgramVersion => 10,
+ IptcTag.ObjectCycle => 1,
+ IptcTag.Byline => 32,
+ IptcTag.BylineTitle => 32,
+ IptcTag.City => 32,
+ IptcTag.SubLocation => 32,
+ IptcTag.ProvinceState => 32,
+ IptcTag.CountryCode => 3,
+ IptcTag.Country => 64,
+ IptcTag.OriginalTransmissionReference => 32,
+ IptcTag.Headline => 256,
+ IptcTag.Credit => 32,
+ IptcTag.Source => 32,
+ IptcTag.CopyrightNotice => 128,
+ IptcTag.Contact => 128,
+ IptcTag.Caption => 2000,
+ IptcTag.CaptionWriter => 32,
+ IptcTag.ImageType => 2,
+ IptcTag.ImageOrientation => 1,
+ _ => 256
+ };
+ }
+
+ ///
+ /// Determines if the given tag can be repeated according to the specification.
+ ///
+ /// The tag to check.
+ /// True, if the tag can occur multiple times.
+ public static bool IsRepeatable(this IptcTag tag)
+ {
+ switch (tag)
+ {
+ case IptcTag.RecordVersion:
+ case IptcTag.ObjectType:
+ case IptcTag.Name:
+ case IptcTag.EditStatus:
+ case IptcTag.EditorialUpdate:
+ case IptcTag.Urgency:
+ case IptcTag.Category:
+ case IptcTag.FixtureIdentifier:
+ case IptcTag.ReleaseDate:
+ case IptcTag.ReleaseTime:
+ case IptcTag.ExpirationDate:
+ case IptcTag.ExpirationTime:
+ case IptcTag.SpecialInstructions:
+ case IptcTag.ActionAdvised:
+ case IptcTag.CreatedDate:
+ case IptcTag.CreatedTime:
+ case IptcTag.DigitalCreationDate:
+ case IptcTag.DigitalCreationTime:
+ case IptcTag.OriginatingProgram:
+ case IptcTag.ProgramVersion:
+ case IptcTag.ObjectCycle:
+ case IptcTag.City:
+ case IptcTag.SubLocation:
+ case IptcTag.ProvinceState:
+ case IptcTag.CountryCode:
+ case IptcTag.Country:
+ case IptcTag.OriginalTransmissionReference:
+ case IptcTag.Headline:
+ case IptcTag.Credit:
+ case IptcTag.Source:
+ case IptcTag.CopyrightNotice:
+ case IptcTag.Caption:
+ case IptcTag.ImageType:
+ case IptcTag.ImageOrientation:
+ return false;
+
+ default:
+ return true;
+ }
+ }
+
+ ///
+ /// Determines if the tag is a datetime tag which needs to be formatted as CCYYMMDD.
+ ///
+ /// The tag to check.
+ /// True, if its a datetime tag.
+ public static bool IsDate(this IptcTag tag)
+ {
+ switch (tag)
+ {
+ case IptcTag.CreatedDate:
+ case IptcTag.DigitalCreationDate:
+ case IptcTag.ExpirationDate:
+ case IptcTag.ReferenceDate:
+ case IptcTag.ReleaseDate:
+ return true;
+
+ default:
+ return false;
+ }
+ }
+
+ ///
+ /// Determines if the tag is a time tag which need to be formatted as HHMMSS±HHMM.
+ ///
+ /// The tag to check.
+ /// True, if its a time tag.
+ public static bool IsTime(this IptcTag tag)
+ {
+ switch (tag)
+ {
+ case IptcTag.CreatedTime:
+ case IptcTag.DigitalCreationTime:
+ case IptcTag.ExpirationTime:
+ case IptcTag.ReleaseTime:
+ return true;
+
+ default:
+ return false;
+ }
+ }
+ }
+}
diff --git a/src/ImageSharp/Metadata/Profiles/IPTC/IptcValue.cs b/src/ImageSharp/Metadata/Profiles/IPTC/IptcValue.cs
new file mode 100644
index 000000000..a09239b8d
--- /dev/null
+++ b/src/ImageSharp/Metadata/Profiles/IPTC/IptcValue.cs
@@ -0,0 +1,219 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using System;
+using System.Text;
+
+namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc
+{
+ ///
+ /// Represents a single value of the IPTC profile.
+ ///
+ public sealed class IptcValue : IDeepCloneable
+ {
+ private byte[] data = Array.Empty();
+ private Encoding encoding;
+
+ internal IptcValue(IptcValue other)
+ {
+ if (other.data != null)
+ {
+ this.data = new byte[other.data.Length];
+ other.data.AsSpan().CopyTo(this.data);
+ }
+
+ if (other.Encoding != null)
+ {
+ this.Encoding = (Encoding)other.Encoding.Clone();
+ }
+
+ this.Tag = other.Tag;
+ this.Strict = other.Strict;
+ }
+
+ internal IptcValue(IptcTag tag, byte[] value, bool strict)
+ {
+ Guard.NotNull(value, nameof(value));
+
+ this.Strict = strict;
+ this.Tag = tag;
+ this.data = value;
+ this.encoding = Encoding.UTF8;
+ }
+
+ internal IptcValue(IptcTag tag, Encoding encoding, string value, bool strict)
+ {
+ this.Strict = strict;
+ this.Tag = tag;
+ this.encoding = encoding;
+ this.Value = value;
+ }
+
+ internal IptcValue(IptcTag tag, string value, bool strict)
+ {
+ this.Strict = strict;
+ this.Tag = tag;
+ this.encoding = Encoding.UTF8;
+ this.Value = value;
+ }
+
+ ///
+ /// Gets or sets the encoding to use for the Value.
+ ///
+ public Encoding Encoding
+ {
+ get => this.encoding;
+ set
+ {
+ if (value != null)
+ {
+ this.encoding = value;
+ }
+ }
+ }
+
+ ///
+ /// Gets the tag of the iptc value.
+ ///
+ public IptcTag Tag { get; }
+
+ ///
+ /// Gets or sets a value indicating whether to be enforce value length restrictions according
+ /// to the specification.
+ ///
+ public bool Strict { get; set; }
+
+ ///
+ /// Gets or sets the value.
+ ///
+ public string Value
+ {
+ get => this.encoding.GetString(this.data);
+ set
+ {
+ if (string.IsNullOrEmpty(value))
+ {
+ this.data = Array.Empty();
+ }
+ else
+ {
+ int maxLength = this.Tag.MaxLength();
+ byte[] valueBytes;
+ if (this.Strict && value.Length > maxLength)
+ {
+ var cappedValue = value.Substring(0, maxLength);
+ valueBytes = this.encoding.GetBytes(cappedValue);
+
+ // It is still possible that the bytes of the string exceed the limit.
+ if (valueBytes.Length > maxLength)
+ {
+ throw new ArgumentException($"The iptc value exceeds the limit of {maxLength} bytes for the tag {this.Tag}");
+ }
+ }
+ else
+ {
+ valueBytes = this.encoding.GetBytes(value);
+ }
+
+ this.data = valueBytes;
+ }
+ }
+ }
+
+ ///
+ /// Gets the length of the value.
+ ///
+ public int Length => this.data.Length;
+
+ ///
+ public IptcValue DeepClone() => new IptcValue(this);
+
+ ///
+ /// Determines whether the specified object is equal to the current .
+ ///
+ /// The object to compare this with.
+ /// True when the specified object is equal to the current .
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(this, obj))
+ {
+ return true;
+ }
+
+ return this.Equals(obj as IptcValue);
+ }
+
+ ///
+ /// Determines whether the specified iptc value is equal to the current .
+ ///
+ /// The iptc value to compare this with.
+ /// True when the specified iptc value is equal to the current .
+ public bool Equals(IptcValue other)
+ {
+ if (other is null)
+ {
+ return false;
+ }
+
+ if (ReferenceEquals(this, other))
+ {
+ return true;
+ }
+
+ if (this.Tag != other.Tag)
+ {
+ return false;
+ }
+
+ if (this.data.Length != other.data.Length)
+ {
+ return false;
+ }
+
+ for (int i = 0; i < this.data.Length; i++)
+ {
+ if (this.data[i] != other.data[i])
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ ///
+ /// Serves as a hash of this type.
+ ///
+ /// A hash code for the current instance.
+ public override int GetHashCode() => HashCode.Combine(this.data, this.Tag);
+
+ ///
+ /// Converts this instance to a byte array.
+ ///
+ /// A array.
+ public byte[] ToByteArray()
+ {
+ var result = new byte[this.data.Length];
+ this.data.CopyTo(result, 0);
+ return result;
+ }
+
+ ///
+ /// Returns a string that represents the current value.
+ ///
+ /// A string that represents the current value.
+ public override string ToString() => this.Value;
+
+ ///
+ /// Returns a string that represents the current value with the specified encoding.
+ ///
+ /// The encoding to use.
+ /// A string that represents the current value with the specified encoding.
+ public string ToString(Encoding encoding)
+ {
+ Guard.NotNull(encoding, nameof(encoding));
+
+ return encoding.GetString(this.data);
+ }
+ }
+}
diff --git a/src/ImageSharp/Metadata/Profiles/IPTC/README.md b/src/ImageSharp/Metadata/Profiles/IPTC/README.md
new file mode 100644
index 000000000..1217ca0c7
--- /dev/null
+++ b/src/ImageSharp/Metadata/Profiles/IPTC/README.md
@@ -0,0 +1,11 @@
+IPTC source code is from [Magick.NET](https://github.com/dlemstra/Magick.NET)
+
+Information about IPTC can be found here in the following sources:
+
+- [metacpan.org, APP13-segment](https://metacpan.org/pod/Image::MetaData::JPEG::Structures#Structure-of-a-Photoshop-style-APP13-segment)
+
+- [iptc.org](https://www.iptc.org/std/photometadata/documentation/userguide/)
+
+- [Adobe File Formats Specification](http://oldschoolprg.x10.mx/downloads/ps6ffspecsv2.pdf)
+
+- [Tag Overview](https://exiftool.org/TagNames/IPTC.html)
\ No newline at end of file
diff --git a/src/ImageSharp/PixelFormats/HalfTypeHelper.cs b/src/ImageSharp/PixelFormats/HalfTypeHelper.cs
index e8cfaa462..3110e4599 100644
--- a/src/ImageSharp/PixelFormats/HalfTypeHelper.cs
+++ b/src/ImageSharp/PixelFormats/HalfTypeHelper.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
diff --git a/src/ImageSharp/PixelFormats/IPackedVector{TPacked}.cs b/src/ImageSharp/PixelFormats/IPackedVector{TPacked}.cs
index 6775cbc58..47962ef20 100644
--- a/src/ImageSharp/PixelFormats/IPackedVector{TPacked}.cs
+++ b/src/ImageSharp/PixelFormats/IPackedVector{TPacked}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/PixelFormats/IPixel.cs b/src/ImageSharp/PixelFormats/IPixel.cs
index 6d1c03e4b..5d4d3ff94 100644
--- a/src/ImageSharp/PixelFormats/IPixel.cs
+++ b/src/ImageSharp/PixelFormats/IPixel.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs b/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs
index b2f6261ef..46f13f008 100644
--- a/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs
+++ b/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.PixelFormats
{
diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
index f966de63c..6ad5af8e5 100644
--- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
using System;
diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt
index a882de066..d2633ae3f 100644
--- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt
+++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt
@@ -1,6 +1,6 @@
<#
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
#>
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
@@ -9,7 +9,7 @@
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
using System;
diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs
index 8184f1577..9a385937e 100644
--- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt
index be2beb2f8..1869eb3c9 100644
--- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt
+++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt
@@ -1,6 +1,6 @@
<#
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
#>
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
@@ -9,7 +9,7 @@
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs
index 97b4458af..54cf72ae8 100644
--- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs
+++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs
index 244aba7de..17cd33d55 100644
--- a/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs
+++ b/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/PixelFormats/PixelColorBlendingMode.cs b/src/ImageSharp/PixelFormats/PixelColorBlendingMode.cs
index a68f7d949..d3c0dc13d 100644
--- a/src/ImageSharp/PixelFormats/PixelColorBlendingMode.cs
+++ b/src/ImageSharp/PixelFormats/PixelColorBlendingMode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.PixelFormats
{
diff --git a/src/ImageSharp/PixelFormats/PixelConversionModifiers.cs b/src/ImageSharp/PixelFormats/PixelConversionModifiers.cs
index eb64e532e..c5124ebe6 100644
--- a/src/ImageSharp/PixelFormats/PixelConversionModifiers.cs
+++ b/src/ImageSharp/PixelFormats/PixelConversionModifiers.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/PixelFormats/PixelConversionModifiersExtensions.cs b/src/ImageSharp/PixelFormats/PixelConversionModifiersExtensions.cs
index 529041481..5d08ee69c 100644
--- a/src/ImageSharp/PixelFormats/PixelConversionModifiersExtensions.cs
+++ b/src/ImageSharp/PixelFormats/PixelConversionModifiersExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
index 444221d88..114ed46b4 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
index d5f4c54fb..925f0c301 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -373,7 +373,7 @@ namespace SixLabors.ImageSharp.PixelFormats
{
vector *= MaxBytes;
vector += Half;
- vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes);
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes);
this.R = (byte)vector.X;
this.G = (byte)vector.Y;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
index 0a2f58409..13a38e811 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
index 2659689bd..e2c24efdf 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
index 0f2991a35..0faaca257 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -296,7 +296,7 @@ namespace SixLabors.ImageSharp.PixelFormats
{
vector *= MaxBytes;
vector += Half;
- vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes);
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes);
this.R = (byte)vector.X;
this.G = (byte)vector.Y;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
index f06831284..e1246f276 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -162,7 +162,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
private static ushort Pack(ref Vector4 vector)
{
- vector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One);
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One);
return (ushort)((((int)Math.Round(vector.W * 15F) & 0x0F) << 12)
| (((int)Math.Round(vector.X * 15F) & 0x0F) << 8)
| (((int)Math.Round(vector.Y * 15F) & 0x0F) << 4)
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
index 92f2a3f75..06f5532ef 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -163,7 +163,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
private static ushort Pack(ref Vector4 vector)
{
- vector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One);
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One);
return (ushort)(
(((int)Math.Round(vector.X * 31F) & 0x1F) << 10)
| (((int)Math.Round(vector.Y * 31F) & 0x1F) << 5)
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
index 728966b00..296bb3df1 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -171,7 +171,7 @@ namespace SixLabors.ImageSharp.PixelFormats
const float Max = 255F;
// Clamp the value between min and max values
- vector = Vector4.Clamp(vector, Vector4.Zero, new Vector4(Max));
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, new Vector4(Max));
uint byte4 = (uint)Math.Round(vector.X) & 0xFF;
uint byte3 = ((uint)Math.Round(vector.Y) & 0xFF) << 0x8;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.cs
index 83bc46d8e..8d0a86a12 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.cs
index 8f21ef2d4..23b91c5f8 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.cs
index 58a68bd03..7892a2de0 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.cs
index 4def59ea1..251251842 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.cs
index dd9a3ac10..e7bdb1ebe 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.cs
index 6a5ec6971..95612035a 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.cs
index 66e8d7dc0..3c4624c09 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.cs
index e3f033008..0b01a215b 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.cs
index face124a6..081f33573 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.cs
index 6828079c2..cd6924733 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.cs
index 6437b0409..0a621748e 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.cs
index c48493faf..ac04da77b 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/_Common.ttinclude b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/_Common.ttinclude
index 076db616b..f8427ed53 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/_Common.ttinclude
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Generated/_Common.ttinclude
@@ -4,7 +4,7 @@
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
index 977df78b8..788cb4b59 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
index 1ecaa05da..dfd4aa838 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
index 35822779f..1575c8e5e 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
index 7235abd21..78bd8e4b8 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -176,7 +176,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
internal void ConvertFromRgbaScaledVector4(Vector4 vector)
{
- vector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One) * Max;
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max;
this.PackedValue = ImageMaths.Get16BitBT709Luminance(
vector.X,
vector.Y,
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
index c622f1750..5fb2834f6 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -156,7 +156,7 @@ namespace SixLabors.ImageSharp.PixelFormats
{
vector *= MaxBytes;
vector += Half;
- vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes);
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes);
this.PackedValue = ImageMaths.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z);
}
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
index 66cb757c3..410cd853e 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -219,7 +219,7 @@ namespace SixLabors.ImageSharp.PixelFormats
{
vector *= MaxBytes;
vector += Half;
- vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes);
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes);
this.L = ImageMaths.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z);
this.A = (byte)vector.W;
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
index 4885dae61..3c5b60034 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -233,7 +233,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
internal void ConvertFromRgbaScaledVector4(Vector4 vector)
{
- vector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One) * Max;
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max;
this.L = ImageMaths.Get16BitBT709Luminance(
vector.X,
vector.Y,
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
index 54effcb22..930d8d296 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
index 3a4b92ff3..28d81a8b6 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -174,7 +174,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
private static uint Pack(ref Vector4 vector)
{
- vector = Vector4.Clamp(vector, MinusOne, Vector4.One) * Half;
+ vector = Vector4Utilities.FastClamp(vector, MinusOne, Vector4.One) * Half;
uint byte4 = ((uint)MathF.Round(vector.X) & 0xFF) << 0;
uint byte3 = ((uint)MathF.Round(vector.Y) & 0xFF) << 8;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
index 6be347bcc..672a86def 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
index 052e44f71..653aaafd5 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -177,7 +177,7 @@ namespace SixLabors.ImageSharp.PixelFormats
private static ulong Pack(ref Vector4 vector)
{
vector *= Max;
- vector = Vector4.Clamp(vector, Min, Max);
+ vector = Vector4Utilities.FastClamp(vector, Min, Max);
// Round rather than truncate.
ulong word4 = ((ulong)MathF.Round(vector.X) & 0xFFFF) << 0x00;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs
index 60c401003..436711e91 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
index 5eb7b74b2..099ea2105 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -254,7 +254,7 @@ namespace SixLabors.ImageSharp.PixelFormats
{
vector *= MaxBytes;
vector += Half;
- vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes);
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes);
this.R = (byte)vector.X;
this.G = (byte)vector.Y;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
index e494ff68e..ffc42ad1f 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromVector4(Vector4 vector)
{
- vector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One) * Max;
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max;
this.R = (ushort)MathF.Round(vector.X);
this.G = (ushort)MathF.Round(vector.Y);
this.B = (ushort)MathF.Round(vector.Z);
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs
index 2b5670778..de69ad172 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -163,7 +163,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
private static uint Pack(ref Vector4 vector)
{
- vector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One) * Multiplier;
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Multiplier;
return (uint)(
(((int)Math.Round(vector.X) & 0x03FF) << 0)
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs
index 7337c0c89..aa66bbf66 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.PixelFormats
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationVectors, nameof(destinationVectors));
destinationVectors = destinationVectors.Slice(0, sourcePixels.Length);
- SimdUtils.BulkConvertByteToNormalizedFloat(
+ SimdUtils.ByteToNormalizedFloat(
MemoryMarshal.Cast(sourcePixels),
MemoryMarshal.Cast(destinationVectors));
Vector4Converters.ApplyForwardConversionModifiers(destinationVectors, modifiers);
@@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.PixelFormats
destinationPixels = destinationPixels.Slice(0, sourceVectors.Length);
Vector4Converters.ApplyBackwardConversionModifiers(sourceVectors, modifiers);
- SimdUtils.BulkConvertNormalizedFloatToByteClampOverflows(
+ SimdUtils.NormalizedFloatToByteSaturate(
MemoryMarshal.Cast(sourceVectors),
MemoryMarshal.Cast(destinationPixels));
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
index 8f67f2166..2a3cbf3aa 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers.Binary;
@@ -452,7 +452,7 @@ namespace SixLabors.ImageSharp.PixelFormats
{
vector *= MaxBytes;
vector += Half;
- vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes);
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes);
return new Rgba32((byte)vector.X, (byte)vector.Y, (byte)vector.Z, (byte)vector.W);
}
@@ -491,7 +491,7 @@ namespace SixLabors.ImageSharp.PixelFormats
{
vector *= MaxBytes;
vector += Half;
- vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes);
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes);
this.R = (byte)vector.X;
this.G = (byte)vector.Y;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
index 88ef1dc98..b9539bac3 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -127,7 +127,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public Rgba64(Vector4 vector)
{
- vector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One) * Max;
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max;
this.R = (ushort)MathF.Round(vector.X);
this.G = (ushort)MathF.Round(vector.Y);
this.B = (ushort)MathF.Round(vector.Z);
@@ -209,7 +209,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromVector4(Vector4 vector)
{
- vector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One) * Max;
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max;
this.R = (ushort)MathF.Round(vector.X);
this.G = (ushort)MathF.Round(vector.Y);
this.B = (ushort)MathF.Round(vector.Z);
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.PixelOperations.cs
index 0f9871244..fd59222fd 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.PixelOperations.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
index 8a6bc94a7..688e48824 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromVector4(Vector4 vector)
{
- vector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One);
+ vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One);
this.R = vector.X;
this.G = vector.Y;
this.B = vector.Z;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs
index 526e831f8..16c7da0d3 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs
index e709cd04f..43b4649d4 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -183,7 +183,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
private static ulong Pack(ref Vector4 vector)
{
- vector = Vector4.Clamp(vector, Min, Max);
+ vector = Vector4Utilities.FastClamp(vector, Min, Max);
// Clamp the value between min and max values
ulong word4 = ((ulong)Math.Round(vector.X) & 0xFFFF) << 0x00;
diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs
index d1f4a11c7..2c620eeaa 100644
--- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
using System;
diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt
index d24273964..286745a92 100644
--- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt
+++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt
@@ -1,6 +1,6 @@
<#
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
#>
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
@@ -97,7 +97,7 @@
#>
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
//
using System;
diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs
index 17af972a8..11a85cf88 100644
--- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs
+++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats.PixelBlenders;
diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
index 1e1047e2b..42d7992cf 100644
--- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
+++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/PixelFormats/RgbaComponent.cs b/src/ImageSharp/PixelFormats/RgbaComponent.cs
index 76df62c43..29f3ef4f1 100644
--- a/src/ImageSharp/PixelFormats/RgbaComponent.cs
+++ b/src/ImageSharp/PixelFormats/RgbaComponent.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp
{
diff --git a/src/ImageSharp/PixelFormats/Utils/PixelConverter.cs b/src/ImageSharp/PixelFormats/Utils/PixelConverter.cs
index 12ec389b0..167103477 100644
--- a/src/ImageSharp/PixelFormats/Utils/PixelConverter.cs
+++ b/src/ImageSharp/PixelFormats/Utils/PixelConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Buffers.Binary;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.Default.cs b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.Default.cs
index ac50dd8c4..614925f19 100644
--- a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.Default.cs
+++ b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.Default.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.RgbaCompatible.cs b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.RgbaCompatible.cs
index 11a23b6eb..e49efd5c3 100644
--- a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.RgbaCompatible.cs
+++ b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.RgbaCompatible.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
@@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
// 'destVectors' and 'lastQuarterOfDestBuffer' are overlapping buffers,
// but we are always reading/writing at different positions:
- SimdUtils.BulkConvertByteToNormalizedFloat(
+ SimdUtils.ByteToNormalizedFloat(
MemoryMarshal.Cast(lastQuarterOfDestBuffer),
MemoryMarshal.Cast(destVectors.Slice(0, countWithoutLastItem)));
@@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
{
Span tempSpan = tempBuffer.Memory.Span;
- SimdUtils.BulkConvertNormalizedFloatToByteClampOverflows(
+ SimdUtils.NormalizedFloatToByteSaturate(
MemoryMarshal.Cast(sourceVectors),
MemoryMarshal.Cast(tempSpan));
@@ -122,7 +122,7 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
return int.MaxValue;
}
- return SimdUtils.ExtendedIntrinsics.IsAvailable && SimdUtils.IsAvx2CompatibleArchitecture ? 256 : 128;
+ return SimdUtils.ExtendedIntrinsics.IsAvailable && SimdUtils.HasVector8 ? 256 : 128;
}
}
}
diff --git a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs
index 447869a7d..83edef064 100644
--- a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs
+++ b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
if (modifiers.IsDefined(PixelConversionModifiers.Premultiply))
{
- Vector4Utils.Premultiply(vectors);
+ Vector4Utilities.Premultiply(vectors);
}
}
@@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
{
if (modifiers.IsDefined(PixelConversionModifiers.Premultiply))
{
- Vector4Utils.UnPremultiply(vectors);
+ Vector4Utilities.UnPremultiply(vectors);
}
if (modifiers.IsDefined(PixelConversionModifiers.SRgbCompand))
diff --git a/src/ImageSharp/Primitives/ColorMatrix.cs b/src/ImageSharp/Primitives/ColorMatrix.cs
index 09a2d17ae..24be37fad 100644
--- a/src/ImageSharp/Primitives/ColorMatrix.cs
+++ b/src/ImageSharp/Primitives/ColorMatrix.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
#pragma warning disable SA1117 // Parameters should be on same line or separate lines
using System;
diff --git a/src/ImageSharp/Primitives/Complex64.cs b/src/ImageSharp/Primitives/Complex64.cs
index a5af3f2f7..4a3c564b8 100644
--- a/src/ImageSharp/Primitives/Complex64.cs
+++ b/src/ImageSharp/Primitives/Complex64.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Primitives/ComplexVector4.cs b/src/ImageSharp/Primitives/ComplexVector4.cs
index 5287ab23f..1cc1e8e68 100644
--- a/src/ImageSharp/Primitives/ComplexVector4.cs
+++ b/src/ImageSharp/Primitives/ComplexVector4.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Primitives/DenseMatrix{T}.cs b/src/ImageSharp/Primitives/DenseMatrix{T}.cs
index 3fda03b77..4393e4e66 100644
--- a/src/ImageSharp/Primitives/DenseMatrix{T}.cs
+++ b/src/ImageSharp/Primitives/DenseMatrix{T}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Diagnostics;
diff --git a/src/ImageSharp/Primitives/LongRational.cs b/src/ImageSharp/Primitives/LongRational.cs
index d0f56917e..248cb2e27 100644
--- a/src/ImageSharp/Primitives/LongRational.cs
+++ b/src/ImageSharp/Primitives/LongRational.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Globalization;
diff --git a/src/ImageSharp/Primitives/Matrix3x2Extensions.cs b/src/ImageSharp/Primitives/Matrix3x2Extensions.cs
index 4ddbcc017..0675ff464 100644
--- a/src/ImageSharp/Primitives/Matrix3x2Extensions.cs
+++ b/src/ImageSharp/Primitives/Matrix3x2Extensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
diff --git a/src/ImageSharp/Primitives/Number.cs b/src/ImageSharp/Primitives/Number.cs
index 3d575e866..81adf1013 100644
--- a/src/ImageSharp/Primitives/Number.cs
+++ b/src/ImageSharp/Primitives/Number.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Globalization;
diff --git a/src/ImageSharp/Primitives/Point.cs b/src/ImageSharp/Primitives/Point.cs
index 96e73766b..6776e584d 100644
--- a/src/ImageSharp/Primitives/Point.cs
+++ b/src/ImageSharp/Primitives/Point.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.ComponentModel;
diff --git a/src/ImageSharp/Primitives/PointF.cs b/src/ImageSharp/Primitives/PointF.cs
index e43ad4daf..d8918a52c 100644
--- a/src/ImageSharp/Primitives/PointF.cs
+++ b/src/ImageSharp/Primitives/PointF.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.ComponentModel;
diff --git a/src/ImageSharp/Primitives/Rational.cs b/src/ImageSharp/Primitives/Rational.cs
index 212178a24..7c55d8f17 100644
--- a/src/ImageSharp/Primitives/Rational.cs
+++ b/src/ImageSharp/Primitives/Rational.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Globalization;
diff --git a/src/ImageSharp/Primitives/Rectangle.cs b/src/ImageSharp/Primitives/Rectangle.cs
index d391057a9..eac5cf04c 100644
--- a/src/ImageSharp/Primitives/Rectangle.cs
+++ b/src/ImageSharp/Primitives/Rectangle.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.ComponentModel;
diff --git a/src/ImageSharp/Primitives/RectangleF.cs b/src/ImageSharp/Primitives/RectangleF.cs
index 354daa446..05af7b430 100644
--- a/src/ImageSharp/Primitives/RectangleF.cs
+++ b/src/ImageSharp/Primitives/RectangleF.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.ComponentModel;
diff --git a/src/ImageSharp/Primitives/SignedRational.cs b/src/ImageSharp/Primitives/SignedRational.cs
index 93a0ffe39..440fbd71e 100644
--- a/src/ImageSharp/Primitives/SignedRational.cs
+++ b/src/ImageSharp/Primitives/SignedRational.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Globalization;
diff --git a/src/ImageSharp/Primitives/Size.cs b/src/ImageSharp/Primitives/Size.cs
index effd657a6..099a56c43 100644
--- a/src/ImageSharp/Primitives/Size.cs
+++ b/src/ImageSharp/Primitives/Size.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.ComponentModel;
diff --git a/src/ImageSharp/Primitives/SizeF.cs b/src/ImageSharp/Primitives/SizeF.cs
index 7d9bc5814..ff8ea1950 100644
--- a/src/ImageSharp/Primitives/SizeF.cs
+++ b/src/ImageSharp/Primitives/SizeF.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.ComponentModel;
diff --git a/src/ImageSharp/Primitives/ValueSize.cs b/src/ImageSharp/Primitives/ValueSize.cs
index be2ccb725..996f0979d 100644
--- a/src/ImageSharp/Primitives/ValueSize.cs
+++ b/src/ImageSharp/Primitives/ValueSize.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Processing/AdaptiveThresholdExtensions.cs b/src/ImageSharp/Processing/AdaptiveThresholdExtensions.cs
new file mode 100644
index 000000000..d4f376a31
--- /dev/null
+++ b/src/ImageSharp/Processing/AdaptiveThresholdExtensions.cs
@@ -0,0 +1,74 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using SixLabors.ImageSharp.Processing.Processors.Binarization;
+
+namespace SixLabors.ImageSharp.Processing
+{
+ ///
+ /// Extensions to perform AdaptiveThreshold through Mutator.
+ ///
+ public static class AdaptiveThresholdExtensions
+ {
+ ///
+ /// Applies Bradley Adaptive Threshold to the image.
+ ///
+ /// The image this method extends.
+ /// The .
+ public static IImageProcessingContext AdaptiveThreshold(this IImageProcessingContext source)
+ => source.ApplyProcessor(new AdaptiveThresholdProcessor());
+
+ ///
+ /// Applies Bradley Adaptive Threshold to the image.
+ ///
+ /// The image this method extends.
+ /// Threshold limit (0.0-1.0) to consider for binarization.
+ /// The .
+ public static IImageProcessingContext AdaptiveThreshold(this IImageProcessingContext source, float thresholdLimit)
+ => source.ApplyProcessor(new AdaptiveThresholdProcessor(thresholdLimit));
+
+ ///
+ /// Applies Bradley Adaptive Threshold to the image.
+ ///
+ /// The image this method extends.
+ /// Upper (white) color for thresholding.
+ /// Lower (black) color for thresholding.
+ /// The .
+ public static IImageProcessingContext AdaptiveThreshold(this IImageProcessingContext source, Color upper, Color lower)
+ => source.ApplyProcessor(new AdaptiveThresholdProcessor(upper, lower));
+
+ ///
+ /// Applies Bradley Adaptive Threshold to the image.
+ ///
+ /// The image this method extends.
+ /// Upper (white) color for thresholding.
+ /// Lower (black) color for thresholding.
+ /// Threshold limit (0.0-1.0) to consider for binarization.
+ /// The .
+ public static IImageProcessingContext AdaptiveThreshold(this IImageProcessingContext source, Color upper, Color lower, float thresholdLimit)
+ => source.ApplyProcessor(new AdaptiveThresholdProcessor(upper, lower, thresholdLimit));
+
+ ///
+ /// Applies Bradley Adaptive Threshold to the image.
+ ///
+ /// The image this method extends.
+ /// Upper (white) color for thresholding.
+ /// Lower (black) color for thresholding.
+ /// Rectangle region to apply the processor on.
+ /// The .
+ public static IImageProcessingContext AdaptiveThreshold(this IImageProcessingContext source, Color upper, Color lower, Rectangle rectangle)
+ => source.ApplyProcessor(new AdaptiveThresholdProcessor(upper, lower), rectangle);
+
+ ///
+ /// Applies Bradley Adaptive Threshold to the image.
+ ///
+ /// The image this method extends.
+ /// Upper (white) color for thresholding.
+ /// Lower (black) color for thresholding.
+ /// Threshold limit (0.0-1.0) to consider for binarization.
+ /// Rectangle region to apply the processor on.
+ /// The .
+ public static IImageProcessingContext AdaptiveThreshold(this IImageProcessingContext source, Color upper, Color lower, float thresholdLimit, Rectangle rectangle)
+ => source.ApplyProcessor(new AdaptiveThresholdProcessor(upper, lower, thresholdLimit), rectangle);
+ }
+}
diff --git a/src/ImageSharp/Processing/AffineTransformBuilder.cs b/src/ImageSharp/Processing/AffineTransformBuilder.cs
index dde7beb3e..66e46f683 100644
--- a/src/ImageSharp/Processing/AffineTransformBuilder.cs
+++ b/src/ImageSharp/Processing/AffineTransformBuilder.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
@@ -247,15 +247,33 @@ namespace SixLabors.ImageSharp.Processing
/// Prepends a raw matrix.
///
/// The matrix to prepend.
+ ///
+ /// The resultant matrix is degenerate containing one or more values equivalent
+ /// to or a zero determinant and therefore cannot be used
+ /// for linear transforms.
+ ///
/// The .
- public AffineTransformBuilder PrependMatrix(Matrix3x2 matrix) => this.Prepend(_ => matrix);
+ public AffineTransformBuilder PrependMatrix(Matrix3x2 matrix)
+ {
+ CheckDegenerate(matrix);
+ return this.Prepend(_ => matrix);
+ }
///
/// Appends a raw matrix.
///
/// The matrix to append.
+ ///
+ /// The resultant matrix is degenerate containing one or more values equivalent
+ /// to or a zero determinant and therefore cannot be used
+ /// for linear transforms.
+ ///
/// The .
- public AffineTransformBuilder AppendMatrix(Matrix3x2 matrix) => this.Append(_ => matrix);
+ public AffineTransformBuilder AppendMatrix(Matrix3x2 matrix)
+ {
+ CheckDegenerate(matrix);
+ return this.Append(_ => matrix);
+ }
///
/// Returns the combined matrix for a given source size.
@@ -268,6 +286,11 @@ namespace SixLabors.ImageSharp.Processing
/// Returns the combined matrix for a given source rectangle.
///
/// The rectangle in the source image.
+ ///
+ /// The resultant matrix is degenerate containing one or more values equivalent
+ /// to or a zero determinant and therefore cannot be used
+ /// for linear transforms.
+ ///
/// The .
public Matrix3x2 BuildMatrix(Rectangle sourceRectangle)
{
@@ -284,9 +307,19 @@ namespace SixLabors.ImageSharp.Processing
matrix *= factory(size);
}
+ CheckDegenerate(matrix);
+
return matrix;
}
+ private static void CheckDegenerate(Matrix3x2 matrix)
+ {
+ if (TransformUtilities.IsDegenerate(matrix))
+ {
+ throw new DegenerateTransformException("Matrix is degenerate. Check input values.");
+ }
+ }
+
private AffineTransformBuilder Prepend(Func factory)
{
this.matrixFactories.Insert(0, factory);
@@ -299,4 +332,4 @@ namespace SixLabors.ImageSharp.Processing
return this;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Processing/AnchorPositionMode.cs b/src/ImageSharp/Processing/AnchorPositionMode.cs
index ef9c0fdaf..d492ed5e8 100644
--- a/src/ImageSharp/Processing/AnchorPositionMode.cs
+++ b/src/ImageSharp/Processing/AnchorPositionMode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing
{
diff --git a/src/ImageSharp/Processing/ColorBlindnessMode.cs b/src/ImageSharp/Processing/ColorBlindnessMode.cs
index 2ff19e77e..78b54744f 100644
--- a/src/ImageSharp/Processing/ColorBlindnessMode.cs
+++ b/src/ImageSharp/Processing/ColorBlindnessMode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing
{
diff --git a/src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs b/src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs
index 2e5919d1e..e65e44072 100644
--- a/src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs
+++ b/src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
+using System.Collections.Generic;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
@@ -39,6 +40,9 @@ namespace SixLabors.ImageSharp.Processing
///
public Configuration Configuration { get; }
+ ///
+ public IDictionary Properties { get; } = new Dictionary();
+
///
public Image GetResultImage()
{
diff --git a/src/ImageSharp/Processing/EdgeDetectionOperators.cs b/src/ImageSharp/Processing/EdgeDetectionOperators.cs
index 1f3526760..e36df76bc 100644
--- a/src/ImageSharp/Processing/EdgeDetectionOperators.cs
+++ b/src/ImageSharp/Processing/EdgeDetectionOperators.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing
{
diff --git a/src/ImageSharp/Processing/Extensions/Binarization/BinaryDitherExtensions.cs b/src/ImageSharp/Processing/Extensions/Binarization/BinaryDitherExtensions.cs
index 659b538fc..f52aab015 100644
--- a/src/ImageSharp/Processing/Extensions/Binarization/BinaryDitherExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Binarization/BinaryDitherExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Dithering;
diff --git a/src/ImageSharp/Processing/Extensions/Binarization/BinaryThresholdExtensions.cs b/src/ImageSharp/Processing/Extensions/Binarization/BinaryThresholdExtensions.cs
index d4fe9b562..55fe2501b 100644
--- a/src/ImageSharp/Processing/Extensions/Binarization/BinaryThresholdExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Binarization/BinaryThresholdExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Binarization;
diff --git a/src/ImageSharp/Processing/Extensions/Convolution/BokehBlurExtensions.cs b/src/ImageSharp/Processing/Extensions/Convolution/BokehBlurExtensions.cs
index 7e0b3df39..08ae60623 100644
--- a/src/ImageSharp/Processing/Extensions/Convolution/BokehBlurExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Convolution/BokehBlurExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Convolution;
diff --git a/src/ImageSharp/Processing/Extensions/Convolution/BoxBlurExtensions.cs b/src/ImageSharp/Processing/Extensions/Convolution/BoxBlurExtensions.cs
index 4534e474a..ba9b84f19 100644
--- a/src/ImageSharp/Processing/Extensions/Convolution/BoxBlurExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Convolution/BoxBlurExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Convolution;
diff --git a/src/ImageSharp/Processing/Extensions/Convolution/DetectEdgesExtensions.cs b/src/ImageSharp/Processing/Extensions/Convolution/DetectEdgesExtensions.cs
index 53b2d40b0..d1ce9cdf7 100644
--- a/src/ImageSharp/Processing/Extensions/Convolution/DetectEdgesExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Convolution/DetectEdgesExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.ImageSharp.Processing.Processors.Convolution;
diff --git a/src/ImageSharp/Processing/Extensions/Convolution/GaussianBlurExtensions.cs b/src/ImageSharp/Processing/Extensions/Convolution/GaussianBlurExtensions.cs
index 9c40d94ed..a8b7bf190 100644
--- a/src/ImageSharp/Processing/Extensions/Convolution/GaussianBlurExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Convolution/GaussianBlurExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Convolution;
diff --git a/src/ImageSharp/Processing/Extensions/Convolution/GaussianSharpenExtensions.cs b/src/ImageSharp/Processing/Extensions/Convolution/GaussianSharpenExtensions.cs
index 007fffb1a..7dd6823b8 100644
--- a/src/ImageSharp/Processing/Extensions/Convolution/GaussianSharpenExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Convolution/GaussianSharpenExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Convolution;
diff --git a/src/ImageSharp/Processing/Extensions/Dithering/DitherExtensions.cs b/src/ImageSharp/Processing/Extensions/Dithering/DitherExtensions.cs
index a04aa0df8..c595cc83b 100644
--- a/src/ImageSharp/Processing/Extensions/Dithering/DitherExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Dithering/DitherExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using SixLabors.ImageSharp.Processing.Processors.Dithering;
diff --git a/src/ImageSharp/Processing/Extensions/Drawing/DrawImageExtensions.cs b/src/ImageSharp/Processing/Extensions/Drawing/DrawImageExtensions.cs
index 4717c09ea..048ccf1be 100644
--- a/src/ImageSharp/Processing/Extensions/Drawing/DrawImageExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Drawing/DrawImageExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Drawing;
@@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Processing
Image image,
float opacity)
{
- var options = new GraphicsOptions();
+ var options = source.GetGraphicsOptions();
return source.ApplyProcessor(
new DrawImageProcessor(
image,
@@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Processing
image,
Point.Empty,
colorBlending,
- new GraphicsOptions().AlphaCompositionMode,
+ source.GetGraphicsOptions().AlphaCompositionMode,
opacity));
///
@@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp.Processing
Point location,
float opacity)
{
- var options = new GraphicsOptions();
+ var options = source.GetGraphicsOptions();
return source.ApplyProcessor(
new DrawImageProcessor(
image,
@@ -134,7 +134,7 @@ namespace SixLabors.ImageSharp.Processing
image,
location,
colorBlending,
- new GraphicsOptions().AlphaCompositionMode,
+ source.GetGraphicsOptions().AlphaCompositionMode,
opacity));
///
diff --git a/src/ImageSharp/Processing/Extensions/Effects/OilPaintExtensions.cs b/src/ImageSharp/Processing/Extensions/Effects/OilPaintExtensions.cs
index 521617281..aafab4b99 100644
--- a/src/ImageSharp/Processing/Extensions/Effects/OilPaintExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Effects/OilPaintExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Effects;
diff --git a/src/ImageSharp/Processing/Extensions/Effects/PixelRowDelegateExtensions.cs b/src/ImageSharp/Processing/Extensions/Effects/PixelRowDelegateExtensions.cs
index b622141b7..84c5cb422 100644
--- a/src/ImageSharp/Processing/Extensions/Effects/PixelRowDelegateExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Effects/PixelRowDelegateExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Effects;
diff --git a/src/ImageSharp/Processing/Extensions/Effects/PixelateExtensions.cs b/src/ImageSharp/Processing/Extensions/Effects/PixelateExtensions.cs
index f2a10532d..0639c5a16 100644
--- a/src/ImageSharp/Processing/Extensions/Effects/PixelateExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Effects/PixelateExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Effects;
diff --git a/src/ImageSharp/Processing/Extensions/Filters/BlackWhiteExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/BlackWhiteExtensions.cs
index 788677fc8..92abd0ff0 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/BlackWhiteExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/BlackWhiteExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Filters;
diff --git a/src/ImageSharp/Processing/Extensions/Filters/BrightnessExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/BrightnessExtensions.cs
index 7bc441297..02d73d42a 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/BrightnessExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/BrightnessExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Filters;
diff --git a/src/ImageSharp/Processing/Extensions/Filters/ColorBlindnessExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/ColorBlindnessExtensions.cs
index e214c5a16..33efccecf 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/ColorBlindnessExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/ColorBlindnessExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.ImageSharp.Processing.Processors.Filters;
diff --git a/src/ImageSharp/Processing/Extensions/Filters/ContrastExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/ContrastExtensions.cs
index 4a3e460b8..3f05651df 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/ContrastExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/ContrastExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Filters;
diff --git a/src/ImageSharp/Processing/Extensions/Filters/FilterExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/FilterExtensions.cs
index 088f61884..e395e2778 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/FilterExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/FilterExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Filters;
@@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Processing
public static class FilterExtensions
{
///
- /// Filters an image but the given color matrix
+ /// Filters an image by the given color matrix
///
/// The image this method extends.
/// The filter color matrix
@@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing
=> source.ApplyProcessor(new FilterProcessor(matrix));
///
- /// Filters an image but the given color matrix
+ /// Filters an image by the given color matrix
///
/// The image this method extends.
/// The filter color matrix
@@ -32,4 +32,4 @@ namespace SixLabors.ImageSharp.Processing
public static IImageProcessingContext Filter(this IImageProcessingContext source, ColorMatrix matrix, Rectangle rectangle)
=> source.ApplyProcessor(new FilterProcessor(matrix), rectangle);
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Processing/Extensions/Filters/GrayscaleExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/GrayscaleExtensions.cs
index 4125de832..00b0f4bb5 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/GrayscaleExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/GrayscaleExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.ImageSharp.Processing.Processors.Filters;
diff --git a/src/ImageSharp/Processing/Extensions/Filters/HueExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/HueExtensions.cs
index ef1fa2a6e..d387fc7e3 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/HueExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/HueExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Filters;
diff --git a/src/ImageSharp/Processing/Extensions/Filters/InvertExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/InvertExtensions.cs
index 0642db849..97acd1aa7 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/InvertExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/InvertExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Filters;
diff --git a/src/ImageSharp/Processing/Extensions/Filters/KodachromeExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/KodachromeExtensions.cs
index eadbde7bc..7810e7c5c 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/KodachromeExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/KodachromeExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Filters;
diff --git a/src/ImageSharp/Processing/Extensions/Filters/LightnessExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/LightnessExtensions.cs
index d68cb6aac..f50021dd3 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/LightnessExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/LightnessExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Filters;
diff --git a/src/ImageSharp/Processing/Extensions/Filters/LomographExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/LomographExtensions.cs
index 84b11c5e7..5bff26f0c 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/LomographExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/LomographExtensions.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Filters;
@@ -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.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(), rectangle);
+ => source.ApplyProcessor(new LomographProcessor(source.GetGraphicsOptions()), rectangle);
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Processing/Extensions/Filters/OpacityExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/OpacityExtensions.cs
index 2cf6085f3..386fa5fca 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/OpacityExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/OpacityExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Filters;
diff --git a/src/ImageSharp/Processing/Extensions/Filters/PolaroidExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/PolaroidExtensions.cs
index 94ced7108..d2c05765b 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/PolaroidExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/PolaroidExtensions.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Filters;
@@ -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.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(), rectangle);
+ => source.ApplyProcessor(new PolaroidProcessor(source.GetGraphicsOptions()), rectangle);
}
}
diff --git a/src/ImageSharp/Processing/Extensions/Filters/SaturateExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/SaturateExtensions.cs
index f68c424bd..f3f0a82cc 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/SaturateExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/SaturateExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Filters;
diff --git a/src/ImageSharp/Processing/Extensions/Filters/SepiaExtensions.cs b/src/ImageSharp/Processing/Extensions/Filters/SepiaExtensions.cs
index 629ba03e7..537d280d0 100644
--- a/src/ImageSharp/Processing/Extensions/Filters/SepiaExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Filters/SepiaExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Filters;
diff --git a/src/ImageSharp/Processing/Extensions/Normalization/HistogramEqualizationExtensions.cs b/src/ImageSharp/Processing/Extensions/Normalization/HistogramEqualizationExtensions.cs
index 72962a3f9..a1e708993 100644
--- a/src/ImageSharp/Processing/Extensions/Normalization/HistogramEqualizationExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Normalization/HistogramEqualizationExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Normalization;
diff --git a/src/ImageSharp/Processing/Extensions/Overlays/BackgroundColorExtensions.cs b/src/ImageSharp/Processing/Extensions/Overlays/BackgroundColorExtensions.cs
index d068ba10b..10a570959 100644
--- a/src/ImageSharp/Processing/Extensions/Overlays/BackgroundColorExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Overlays/BackgroundColorExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Overlays;
@@ -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, new GraphicsOptions(), 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, new GraphicsOptions(), 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 d5114e30a..55fe83da0 100644
--- a/src/ImageSharp/Processing/Extensions/Overlays/GlowExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Overlays/GlowExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Overlays;
@@ -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, new GraphicsOptions());
+ 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, new GraphicsOptions(), 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, new GraphicsOptions(), 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(new GraphicsOptions(), 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(new GraphicsOptions(), 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 799b30e01..47b05ffe9 100644
--- a/src/ImageSharp/Processing/Extensions/Overlays/VignetteExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Overlays/VignetteExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Overlays;
@@ -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, new GraphicsOptions());
+ 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, new GraphicsOptions(), 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, new GraphicsOptions(), 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, new GraphicsOptions(), 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(new GraphicsOptions(), color, radiusX, radiusY, rectangle);
+ source.Vignette(source.GetGraphicsOptions(), color, radiusX, radiusY, rectangle);
///
/// Applies a radial vignette effect to an image.
diff --git a/src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs b/src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs
index 59be5bf02..fae679276 100644
--- a/src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
@@ -19,6 +19,10 @@ namespace SixLabors.ImageSharp.Processing
///
/// The image to mutate.
/// The operation to perform on the source.
+ /// The source is null.
+ /// The operation is null.
+ /// The source has been disposed.
+ /// The processing operation failed.
public static void Mutate(this Image source, Action operation)
=> Mutate(source, source.GetConfiguration(), operation);
@@ -28,6 +32,11 @@ namespace SixLabors.ImageSharp.Processing
/// The image to mutate.
/// The configuration which allows altering default behaviour or extending the library.
/// The operation to perform on the source.
+ /// The configuration is null.
+ /// The source is null.
+ /// The operation is null.
+ /// The source has been disposed.
+ /// The processing operation failed.
public static void Mutate(this Image source, Configuration configuration, Action operation)
{
Guard.NotNull(configuration, nameof(configuration));
@@ -44,6 +53,10 @@ namespace SixLabors.ImageSharp.Processing
/// The pixel format.
/// The image to mutate.
/// The operation to perform on the source.
+ /// The source is null.
+ /// The operation is null.
+ /// The source has been disposed.
+ /// The processing operation failed.
public static void Mutate(this Image source, Action operation)
where TPixel : unmanaged, IPixel
=> Mutate(source, source.GetConfiguration(), operation);
@@ -55,6 +68,11 @@ namespace SixLabors.ImageSharp.Processing
/// The image to mutate.
/// The configuration which allows altering default behaviour or extending the library.
/// The operation to perform on the source.
+ /// The configuration is null.
+ /// The source is null.
+ /// The operation is null.
+ /// The source has been disposed.
+ /// The processing operation failed.
public static void Mutate(this Image source, Configuration configuration, Action operation)
where TPixel : unmanaged, IPixel
{
@@ -75,6 +93,10 @@ namespace SixLabors.ImageSharp.Processing
/// The pixel format.
/// The image to mutate.
/// The operations to perform on the source.
+ /// The source is null.
+ /// The operations are null.
+ /// The source has been disposed.
+ /// The processing operation failed.
public static void Mutate(this Image source, params IImageProcessor[] operations)
where TPixel : unmanaged, IPixel
=> Mutate(source, source.GetConfiguration(), operations);
@@ -86,6 +108,11 @@ namespace SixLabors.ImageSharp.Processing
/// The image to mutate.
/// The configuration which allows altering default behaviour or extending the library.
/// The operations to perform on the source.
+ /// The configuration is null.
+ /// The source is null.
+ /// The operations are null.
+ /// The source has been disposed.
+ /// The processing operation failed.
public static void Mutate(this Image source, Configuration configuration, params IImageProcessor[] operations)
where TPixel : unmanaged, IPixel
{
@@ -104,7 +131,11 @@ namespace SixLabors.ImageSharp.Processing
///
/// The image to clone.
/// The operation to perform on the clone.
- /// The new .
+ /// The new .
+ /// The source is null.
+ /// The operation is null.
+ /// The source has been disposed.
+ /// The processing operation failed.
public static Image Clone(this Image source, Action operation)
=> Clone(source, source.GetConfiguration(), operation);
@@ -114,7 +145,12 @@ namespace SixLabors.ImageSharp.Processing
/// The image to clone.
/// The configuration which allows altering default behaviour or extending the library.
/// The operation to perform on the clone.
- /// The new .
+ /// The configuration is null.
+ /// The source is null.
+ /// The operation is null.
+ /// The source has been disposed.
+ /// The processing operation failed.
+ /// The new .
public static Image Clone(this Image source, Configuration configuration, Action operation)
{
Guard.NotNull(configuration, nameof(configuration));
@@ -133,7 +169,11 @@ namespace SixLabors.ImageSharp.Processing
/// The pixel format.
/// The image to clone.
/// The operation to perform on the clone.
- /// The new
+ /// The source is null.
+ /// The operation is null.
+ /// The source has been disposed.
+ /// The processing operation failed.
+ /// The new .
public static Image Clone(this Image source, Action operation)
where TPixel : unmanaged, IPixel
=> Clone(source, source.GetConfiguration(), operation);
@@ -145,7 +185,12 @@ namespace SixLabors.ImageSharp.Processing
/// The image to clone.
/// The configuration which allows altering default behaviour or extending the library.
/// The operation to perform on the clone.
- /// The new
+ /// The configuration is null.
+ /// The source is null.
+ /// The operation is null.
+ /// The source has been disposed.
+ /// The processing operation failed.
+ /// The new
public static Image Clone(this Image source, Configuration configuration, Action operation)
where TPixel : unmanaged, IPixel
{
@@ -167,7 +212,11 @@ namespace SixLabors.ImageSharp.Processing
/// The pixel format.
/// The image to clone.
/// The operations to perform on the clone.
- /// The new
+ /// The source is null.
+ /// The operations are null.
+ /// The source has been disposed.
+ /// The processing operation failed.
+ /// The new
public static Image Clone(this Image source, params IImageProcessor[] operations)
where TPixel : unmanaged, IPixel
=> Clone(source, source.GetConfiguration(), operations);
@@ -179,7 +228,12 @@ namespace SixLabors.ImageSharp.Processing
/// The image to clone.
/// The configuration which allows altering default behaviour or extending the library.
/// The operations to perform on the clone.
- /// The new
+ /// The configuration is null.
+ /// The source is null.
+ /// The operations are null.
+ /// The source has been disposed.
+ /// The processing operation failed.
+ /// The new
public static Image Clone(this Image source, Configuration configuration, params IImageProcessor[] operations)
where TPixel : unmanaged, IPixel
{
@@ -200,6 +254,7 @@ namespace SixLabors.ImageSharp.Processing
///
/// The image processing context.
/// The operations to perform on the source.
+ /// The processing operation failed.
/// The to allow chaining of operations.
public static IImageProcessingContext ApplyProcessors(
this IImageProcessingContext source,
diff --git a/src/ImageSharp/Processing/Extensions/Quantization/QuantizeExtensions.cs b/src/ImageSharp/Processing/Extensions/Quantization/QuantizeExtensions.cs
index 86ccddd85..e160ee921 100644
--- a/src/ImageSharp/Processing/Extensions/Quantization/QuantizeExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Quantization/QuantizeExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Quantization;
diff --git a/src/ImageSharp/Processing/Extensions/Transforms/AutoOrientExtensions.cs b/src/ImageSharp/Processing/Extensions/Transforms/AutoOrientExtensions.cs
index 984081dff..5a357375b 100644
--- a/src/ImageSharp/Processing/Extensions/Transforms/AutoOrientExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Transforms/AutoOrientExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Transforms;
diff --git a/src/ImageSharp/Processing/Extensions/Transforms/CropExtensions.cs b/src/ImageSharp/Processing/Extensions/Transforms/CropExtensions.cs
index 5fc8125ea..0afc3bf17 100644
--- a/src/ImageSharp/Processing/Extensions/Transforms/CropExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Transforms/CropExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Transforms;
diff --git a/src/ImageSharp/Processing/Extensions/Transforms/EntropyCropExtensions.cs b/src/ImageSharp/Processing/Extensions/Transforms/EntropyCropExtensions.cs
index de5296d83..ce9f65e96 100644
--- a/src/ImageSharp/Processing/Extensions/Transforms/EntropyCropExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Transforms/EntropyCropExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Transforms;
diff --git a/src/ImageSharp/Processing/Extensions/Transforms/FlipExtensions.cs b/src/ImageSharp/Processing/Extensions/Transforms/FlipExtensions.cs
index f6b3c0c37..7fd1198d5 100644
--- a/src/ImageSharp/Processing/Extensions/Transforms/FlipExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Transforms/FlipExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Transforms;
diff --git a/src/ImageSharp/Processing/Extensions/Transforms/PadExtensions.cs b/src/ImageSharp/Processing/Extensions/Transforms/PadExtensions.cs
index 33a6fc36d..f7e28cd73 100644
--- a/src/ImageSharp/Processing/Extensions/Transforms/PadExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Transforms/PadExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing
{
diff --git a/src/ImageSharp/Processing/Extensions/Transforms/ResizeExtensions.cs b/src/ImageSharp/Processing/Extensions/Transforms/ResizeExtensions.cs
index 882b17721..ff70c8f74 100644
--- a/src/ImageSharp/Processing/Extensions/Transforms/ResizeExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Transforms/ResizeExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Transforms;
diff --git a/src/ImageSharp/Processing/Extensions/Transforms/RotateExtensions.cs b/src/ImageSharp/Processing/Extensions/Transforms/RotateExtensions.cs
index 395462ae3..7eac4d0fa 100644
--- a/src/ImageSharp/Processing/Extensions/Transforms/RotateExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Transforms/RotateExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Transforms;
diff --git a/src/ImageSharp/Processing/Extensions/Transforms/RotateFlipExtensions.cs b/src/ImageSharp/Processing/Extensions/Transforms/RotateFlipExtensions.cs
index 0e4ad4066..09470a732 100644
--- a/src/ImageSharp/Processing/Extensions/Transforms/RotateFlipExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Transforms/RotateFlipExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing
{
diff --git a/src/ImageSharp/Processing/Extensions/Transforms/SkewExtensions.cs b/src/ImageSharp/Processing/Extensions/Transforms/SkewExtensions.cs
index 77a46af0d..e3efc8391 100644
--- a/src/ImageSharp/Processing/Extensions/Transforms/SkewExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Transforms/SkewExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Transforms;
diff --git a/src/ImageSharp/Processing/Extensions/Transforms/TransformExtensions.cs b/src/ImageSharp/Processing/Extensions/Transforms/TransformExtensions.cs
index ee8f3854e..d5adc2701 100644
--- a/src/ImageSharp/Processing/Extensions/Transforms/TransformExtensions.cs
+++ b/src/ImageSharp/Processing/Extensions/Transforms/TransformExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
diff --git a/src/ImageSharp/Processing/FlipMode.cs b/src/ImageSharp/Processing/FlipMode.cs
index 96cd38de4..56b8300ab 100644
--- a/src/ImageSharp/Processing/FlipMode.cs
+++ b/src/ImageSharp/Processing/FlipMode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing
{
diff --git a/src/ImageSharp/Processing/GrayscaleMode.cs b/src/ImageSharp/Processing/GrayscaleMode.cs
index e42a2e633..42a3c0ae3 100644
--- a/src/ImageSharp/Processing/GrayscaleMode.cs
+++ b/src/ImageSharp/Processing/GrayscaleMode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing
{
diff --git a/src/ImageSharp/Processing/IImageProcessingContext.cs b/src/ImageSharp/Processing/IImageProcessingContext.cs
index 8b57a289d..8398f093e 100644
--- a/src/ImageSharp/Processing/IImageProcessingContext.cs
+++ b/src/ImageSharp/Processing/IImageProcessingContext.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
+using System.Collections.Generic;
using SixLabors.ImageSharp.Processing.Processors;
namespace SixLabors.ImageSharp.Processing
@@ -15,6 +16,12 @@ namespace SixLabors.ImageSharp.Processing
///
Configuration Configuration { get; }
+ ///
+ /// Gets a set of properties for the Image Processing Context.
+ ///
+ /// This can be used for storing global settings and defaults to be accessable to processors.
+ IDictionary Properties { get; }
+
///
/// Gets the image dimensions at the current point in the processing pipeline.
///
diff --git a/src/ImageSharp/Processing/IImageProcessingContextFactory.cs b/src/ImageSharp/Processing/IImageProcessingContextFactory.cs
index 5394fac8b..d843d453b 100644
--- a/src/ImageSharp/Processing/IImageProcessingContextFactory.cs
+++ b/src/ImageSharp/Processing/IImageProcessingContextFactory.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/IInternalImageProcessingContext{TPixel}.cs b/src/ImageSharp/Processing/IInternalImageProcessingContext{TPixel}.cs
index a39483b0d..38a1ef202 100644
--- a/src/ImageSharp/Processing/IInternalImageProcessingContext{TPixel}.cs
+++ b/src/ImageSharp/Processing/IInternalImageProcessingContext{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/KnownDitherings.cs b/src/ImageSharp/Processing/KnownDitherings.cs
index bb968d2ef..b5f670232 100644
--- a/src/ImageSharp/Processing/KnownDitherings.cs
+++ b/src/ImageSharp/Processing/KnownDitherings.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Dithering;
diff --git a/src/ImageSharp/Processing/KnownFilterMatrices.cs b/src/ImageSharp/Processing/KnownFilterMatrices.cs
index 268281e4f..1dadccfd9 100644
--- a/src/ImageSharp/Processing/KnownFilterMatrices.cs
+++ b/src/ImageSharp/Processing/KnownFilterMatrices.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Processing/KnownQuantizers.cs b/src/ImageSharp/Processing/KnownQuantizers.cs
index e4a7a75d5..1d3c09c51 100644
--- a/src/ImageSharp/Processing/KnownQuantizers.cs
+++ b/src/ImageSharp/Processing/KnownQuantizers.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Quantization;
diff --git a/src/ImageSharp/Processing/KnownResamplers.cs b/src/ImageSharp/Processing/KnownResamplers.cs
index 348c08407..694328207 100644
--- a/src/ImageSharp/Processing/KnownResamplers.cs
+++ b/src/ImageSharp/Processing/KnownResamplers.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Processing.Processors.Transforms;
diff --git a/src/ImageSharp/Processing/OrientationMode.cs b/src/ImageSharp/Processing/OrientationMode.cs
index ba55425b8..c6ef1a035 100644
--- a/src/ImageSharp/Processing/OrientationMode.cs
+++ b/src/ImageSharp/Processing/OrientationMode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing
{
diff --git a/src/ImageSharp/Processing/PixelRowOperation.cs b/src/ImageSharp/Processing/PixelRowOperation.cs
index 6857b24f1..1ce20d7b8 100644
--- a/src/ImageSharp/Processing/PixelRowOperation.cs
+++ b/src/ImageSharp/Processing/PixelRowOperation.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Processing/Processors/Binarization/AdaptiveThresholdProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/AdaptiveThresholdProcessor.cs
new file mode 100644
index 000000000..a09181fa8
--- /dev/null
+++ b/src/ImageSharp/Processing/Processors/Binarization/AdaptiveThresholdProcessor.cs
@@ -0,0 +1,77 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using SixLabors.ImageSharp.PixelFormats;
+
+namespace SixLabors.ImageSharp.Processing.Processors.Binarization
+{
+ ///
+ /// Performs Bradley Adaptive Threshold filter against an image.
+ ///
+ ///
+ /// Implements "Adaptive Thresholding Using the Integral Image",
+ /// see paper: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.420.7883&rep=rep1&type=pdf
+ ///
+ public class AdaptiveThresholdProcessor : IImageProcessor
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public AdaptiveThresholdProcessor()
+ : this(Color.White, Color.Black, 0.85f)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Threshold limit.
+ public AdaptiveThresholdProcessor(float thresholdLimit)
+ : this(Color.White, Color.Black, thresholdLimit)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Color for upper threshold.
+ /// Color for lower threshold.
+ public AdaptiveThresholdProcessor(Color upper, Color lower)
+ : this(upper, lower, 0.85f)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Color for upper threshold.
+ /// Color for lower threshold.
+ /// Threshold limit.
+ public AdaptiveThresholdProcessor(Color upper, Color lower, float thresholdLimit)
+ {
+ this.Upper = upper;
+ this.Lower = lower;
+ this.ThresholdLimit = thresholdLimit;
+ }
+
+ ///
+ /// Gets or sets upper color limit for thresholding.
+ ///
+ public Color Upper { get; set; }
+
+ ///
+ /// Gets or sets lower color limit for threshold.
+ ///
+ public Color Lower { get; set; }
+
+ ///
+ /// Gets or sets the value for threshold limit.
+ ///
+ public float ThresholdLimit { get; set; }
+
+ ///
+ public IImageProcessor CreatePixelSpecificProcessor(Configuration configuration, Image source, Rectangle sourceRectangle)
+ where TPixel : unmanaged, IPixel
+ => new AdaptiveThresholdProcessor(configuration, this, source, sourceRectangle);
+ }
+}
diff --git a/src/ImageSharp/Processing/Processors/Binarization/AdaptiveThresholdProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Binarization/AdaptiveThresholdProcessor{TPixel}.cs
new file mode 100644
index 000000000..2d5918ec7
--- /dev/null
+++ b/src/ImageSharp/Processing/Processors/Binarization/AdaptiveThresholdProcessor{TPixel}.cs
@@ -0,0 +1,160 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+using SixLabors.ImageSharp.Advanced;
+using SixLabors.ImageSharp.Memory;
+using SixLabors.ImageSharp.PixelFormats;
+
+namespace SixLabors.ImageSharp.Processing.Processors.Binarization
+{
+ ///
+ /// Performs Bradley Adaptive Threshold filter against an image.
+ ///
+ internal class AdaptiveThresholdProcessor : ImageProcessor
+ where TPixel : unmanaged, IPixel
+ {
+ private readonly AdaptiveThresholdProcessor definition;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The configuration which allows altering default behaviour or extending the library.
+ /// The defining the processor parameters.
+ /// The source for the current processor instance.
+ /// The source area to process for the current processor instance.
+ public AdaptiveThresholdProcessor(Configuration configuration, AdaptiveThresholdProcessor definition, Image source, Rectangle sourceRectangle)
+ : base(configuration, source, sourceRectangle)
+ {
+ this.definition = definition;
+ }
+
+ ///
+ protected override void OnFrameApply(ImageFrame source)
+ {
+ var intersect = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
+
+ Configuration configuration = this.Configuration;
+ TPixel upper = this.definition.Upper.ToPixel();
+ TPixel lower = this.definition.Lower.ToPixel();
+ float thresholdLimit = this.definition.ThresholdLimit;
+
+ int startY = intersect.Y;
+ int endY = intersect.Bottom;
+ int startX = intersect.X;
+ int endX = intersect.Right;
+
+ int width = intersect.Width;
+ int height = intersect.Height;
+
+ // ClusterSize defines the size of cluster to used to check for average. Tweaked to support up to 4k wide pixels and not more. 4096 / 16 is 256 thus the '-1'
+ byte clusterSize = (byte)Math.Truncate((width / 16f) - 1);
+
+ // Using pooled 2d buffer for integer image table and temp memory to hold Rgb24 converted pixel data.
+ using (Buffer2D intImage = this.Configuration.MemoryAllocator.Allocate2D(width, height))
+ {
+ Rgba32 rgb = default;
+ for (int x = startX; x < endX; x++)
+ {
+ ulong sum = 0;
+ for (int y = startY; y < endY; y++)
+ {
+ Span row = source.GetPixelRowSpan(y);
+ ref TPixel rowRef = ref MemoryMarshal.GetReference(row);
+ ref TPixel color = ref Unsafe.Add(ref rowRef, x);
+ color.ToRgba32(ref rgb);
+
+ sum += (ulong)(rgb.R + rgb.G + rgb.G);
+ if (x - startX != 0)
+ {
+ intImage[x - startX, y - startY] = intImage[x - startX - 1, y - startY] + sum;
+ }
+ else
+ {
+ intImage[x - startX, y - startY] = sum;
+ }
+ }
+ }
+
+ var operation = new RowOperation(intersect, source, intImage, upper, lower, thresholdLimit, clusterSize, startX, endX, startY);
+ ParallelRowIterator.IterateRows(
+ configuration,
+ intersect,
+ in operation);
+ }
+ }
+
+ private readonly struct RowOperation : IRowOperation
+ {
+ private readonly Rectangle bounds;
+ private readonly ImageFrame source;
+ private readonly Buffer2D intImage;
+ private readonly TPixel upper;
+ private readonly TPixel lower;
+ private readonly float thresholdLimit;
+ private readonly int startX;
+ private readonly int endX;
+ private readonly int startY;
+ private readonly byte clusterSize;
+
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public RowOperation(
+ Rectangle bounds,
+ ImageFrame source,
+ Buffer2D intImage,
+ TPixel upper,
+ TPixel lower,
+ float thresholdLimit,
+ byte clusterSize,
+ int startX,
+ int endX,
+ int startY)
+ {
+ this.bounds = bounds;
+ this.source = source;
+ this.intImage = intImage;
+ this.upper = upper;
+ this.lower = lower;
+ this.thresholdLimit = thresholdLimit;
+ this.startX = startX;
+ this.endX = endX;
+ this.startY = startY;
+ this.clusterSize = clusterSize;
+ }
+
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void Invoke(int y)
+ {
+ Rgba32 rgb = default;
+ Span pixelRow = this.source.GetPixelRowSpan(y);
+
+ for (int x = this.startX; x < this.endX; x++)
+ {
+ TPixel pixel = pixelRow[x];
+ pixel.ToRgba32(ref rgb);
+
+ var x1 = Math.Max(x - this.startX - this.clusterSize + 1, 0);
+ var x2 = Math.Min(x - this.startX + this.clusterSize + 1, this.bounds.Width - 1);
+ var y1 = Math.Max(y - this.startY - this.clusterSize + 1, 0);
+ var y2 = Math.Min(y - this.startY + this.clusterSize + 1, this.bounds.Height - 1);
+
+ var count = (uint)((x2 - x1) * (y2 - y1));
+ var sum = (long)Math.Min(this.intImage[x2, y2] - this.intImage[x1, y2] - this.intImage[x2, y1] + this.intImage[x1, y1], long.MaxValue);
+
+ if ((rgb.R + rgb.G + rgb.B) * count <= sum * this.thresholdLimit)
+ {
+ this.source[x, y] = this.lower;
+ }
+ else
+ {
+ this.source[x, y] = this.upper;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs
index 17fb39df3..a90f5f6f4 100644
--- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs
index 0d363689d..559e6e447 100644
--- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs b/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs
index 36cc7f697..416f5ad07 100644
--- a/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/CloningImageProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/CloningImageProcessor{TPixel}.cs
index e933978c2..0c9af05e5 100644
--- a/src/ImageSharp/Processing/Processors/CloningImageProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/CloningImageProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs
index 65aa81c60..3c2ec0ef3 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs
index 493218cde..080e29a36 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
@@ -304,7 +304,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
for (int x = 0; x < this.bounds.Width; x++)
{
ref Vector4 v = ref Unsafe.Add(ref sourceRef, x);
- var clamp = Vector4.Clamp(v, low, high);
+ var clamp = Vector4Utilities.FastClamp(v, low, high);
v.X = MathF.Pow(clamp.X, this.inverseGamma);
v.Y = MathF.Pow(clamp.Y, this.inverseGamma);
v.Z = MathF.Pow(clamp.Z, this.inverseGamma);
diff --git a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs
index 92f7ab02d..3ae74571f 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor{TPixel}.cs
index fc80905ee..400adb267 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs
index f7439879e..a4048e6a8 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs
index 4bbb15cba..627cb7fbd 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessorHelpers.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessorHelpers.cs
index 34b085fc6..191681c3e 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessorHelpers.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessorHelpers.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs
index a2c8fc1fb..70bd69f32 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -58,9 +58,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
var operation = new RowOperation(interest, targetPixels, source.PixelBuffer, this.KernelXY, this.Configuration, this.PreserveAlpha);
ParallelRowIterator.IterateRows(
- this.Configuration,
- interest,
- in operation);
+ this.Configuration,
+ interest,
+ in operation);
Buffer2D.SwapOrCopyContent(source.PixelBuffer, targetPixels);
}
diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetector2DProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetector2DProcessor{TPixel}.cs
index bdcf3cbc0..3325ea495 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetector2DProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetector2DProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Filters;
@@ -52,6 +52,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
///
protected override void BeforeImageApply()
{
+ using (IImageProcessor opaque = new OpaqueProcessor(this.Configuration, this.Source, this.SourceRectangle))
+ {
+ opaque.Execute();
+ }
+
if (this.Grayscale)
{
new GrayscaleBt709Processor(1F).Execute(this.Configuration, this.Source, this.SourceRectangle);
diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs
index 159c67b5c..df7abee68 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -40,6 +40,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
///
protected override void BeforeImageApply()
{
+ using (IImageProcessor opaque = new OpaqueProcessor(this.Configuration, this.Source, this.SourceRectangle))
+ {
+ opaque.Execute();
+ }
+
if (this.Grayscale)
{
new GrayscaleBt709Processor(1F).Execute(this.Configuration, this.Source, this.SourceRectangle);
diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor.cs
index 472547765..f422146b8 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor{TPixel}.cs
index c49d03eb5..bf4623ac8 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Filters;
@@ -43,6 +43,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
///
protected override void BeforeImageApply()
{
+ using (IImageProcessor opaque = new OpaqueProcessor(this.Configuration, this.Source, this.SourceRectangle))
+ {
+ opaque.Execute();
+ }
+
if (this.Grayscale)
{
new GrayscaleBt709Processor(1F).Execute(this.Configuration, this.Source, this.SourceRectangle);
diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs
index d566f6691..a5ff500df 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor{TPixel}.cs
index cb77c8741..92a848a1f 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs
index 4854eae68..6c904a17f 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor{TPixel}.cs
index 24c56363a..6b35f120a 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/KayyaliProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/KayyaliProcessor.cs
index 90ed15aa3..65b2d2529 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/KayyaliProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/KayyaliProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Kernels/CompassKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/Kernels/CompassKernels.cs
index 423fc6591..bc0239a99 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Kernels/CompassKernels.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Kernels/CompassKernels.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Kernels/KayyaliKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/Kernels/KayyaliKernels.cs
index 50d5bfafe..6df09ca32 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Kernels/KayyaliKernels.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Kernels/KayyaliKernels.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Kernels/KirschKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/Kernels/KirschKernels.cs
index 58568ce40..644e8d668 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Kernels/KirschKernels.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Kernels/KirschKernels.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Kernels/LaplacianKernelFactory.cs b/src/ImageSharp/Processing/Processors/Convolution/Kernels/LaplacianKernelFactory.cs
index 8371212fe..c36bedb91 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Kernels/LaplacianKernelFactory.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Kernels/LaplacianKernelFactory.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Kernels/LaplacianKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/Kernels/LaplacianKernels.cs
index f72e95ee8..3c98c1673 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Kernels/LaplacianKernels.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Kernels/LaplacianKernels.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Kernels/PrewittKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/Kernels/PrewittKernels.cs
index cae9ecb5b..35c7f9716 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Kernels/PrewittKernels.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Kernels/PrewittKernels.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Kernels/RobertsCrossKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/Kernels/RobertsCrossKernels.cs
index 8ffd624d2..23b06a987 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Kernels/RobertsCrossKernels.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Kernels/RobertsCrossKernels.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Kernels/RobinsonKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/Kernels/RobinsonKernels.cs
index ba60bfdf6..89c576e8f 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Kernels/RobinsonKernels.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Kernels/RobinsonKernels.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Kernels/ScharrKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/Kernels/ScharrKernels.cs
index ec583862f..70b4d195f 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Kernels/ScharrKernels.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Kernels/ScharrKernels.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Kernels/SobelKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/Kernels/SobelKernels.cs
index 3dbd54a2c..3918936fb 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Kernels/SobelKernels.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Kernels/SobelKernels.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/KirschProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/KirschProcessor.cs
index 7207f95c4..2be8a8d30 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/KirschProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/KirschProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Laplacian3x3Processor.cs b/src/ImageSharp/Processing/Processors/Convolution/Laplacian3x3Processor.cs
index b147a87cc..5079ecc23 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Laplacian3x3Processor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Laplacian3x3Processor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Laplacian5x5Processor.cs b/src/ImageSharp/Processing/Processors/Convolution/Laplacian5x5Processor.cs
index 663ebf051..417fffec0 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Laplacian5x5Processor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Laplacian5x5Processor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/LaplacianOfGaussianProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/LaplacianOfGaussianProcessor.cs
index 8b0cfc6ff..95e6fdbdd 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/LaplacianOfGaussianProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/LaplacianOfGaussianProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelData.cs b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelData.cs
index 561892683..7a8e953d9 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelData.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelData.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Numerics;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs
index f7828fa9e..a51f42bdc 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Concurrent;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurParameters.cs b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurParameters.cs
index 73688c586..305b71e19 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurParameters.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurParameters.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/PrewittProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/PrewittProcessor.cs
index 7fc54ff96..d1d9316cf 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/PrewittProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/PrewittProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/RobertsCrossProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/RobertsCrossProcessor.cs
index 74d5094f5..fdda446ac 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/RobertsCrossProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/RobertsCrossProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/RobinsonProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/RobinsonProcessor.cs
index 18ac90614..6c77bc904 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/RobinsonProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/RobinsonProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/ScharrProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/ScharrProcessor.cs
index 24248204b..e42c3b42b 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/ScharrProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/ScharrProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Convolution/SobelProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/SobelProcessor.cs
index 1ab56d120..ac99d2d4d 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/SobelProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/SobelProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
diff --git a/src/ImageSharp/Processing/Processors/Dithering/ErroDither.KnownTypes.cs b/src/ImageSharp/Processing/Processors/Dithering/ErroDither.KnownTypes.cs
index d39237a2c..01f26fbbb 100644
--- a/src/ImageSharp/Processing/Processors/Dithering/ErroDither.KnownTypes.cs
+++ b/src/ImageSharp/Processing/Processors/Dithering/ErroDither.KnownTypes.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Dithering
{
diff --git a/src/ImageSharp/Processing/Processors/Dithering/ErrorDither.cs b/src/ImageSharp/Processing/Processors/Dithering/ErrorDither.cs
index 7b8e83585..75253fd37 100644
--- a/src/ImageSharp/Processing/Processors/Dithering/ErrorDither.cs
+++ b/src/ImageSharp/Processing/Processors/Dithering/ErrorDither.cs
@@ -1,9 +1,10 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Quantization;
@@ -89,29 +90,25 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyQuantizationDither(
ref TFrameQuantizer quantizer,
- ReadOnlyMemory palette,
ImageFrame source,
- Memory output,
+ IndexedImageFrame destination,
Rectangle bounds)
- where TFrameQuantizer : struct, IFrameQuantizer
+ where TFrameQuantizer : struct, IQuantizer
where TPixel : unmanaged, IPixel
{
- Span outputSpan = output.Span;
- ReadOnlySpan paletteSpan = palette.Span;
- int width = bounds.Width;
int offsetY = bounds.Top;
int offsetX = bounds.Left;
float scale = quantizer.Options.DitherScale;
for (int y = bounds.Top; y < bounds.Bottom; y++)
{
- Span row = source.GetPixelRowSpan(y);
- int rowStart = (y - offsetY) * width;
+ ref TPixel sourceRowRef = ref MemoryMarshal.GetReference(source.GetPixelRowSpan(y));
+ ref byte destinationRowRef = ref MemoryMarshal.GetReference(destination.GetWritablePixelRowSpanUnsafe(y - offsetY));
for (int x = bounds.Left; x < bounds.Right; x++)
{
- TPixel sourcePixel = row[x];
- outputSpan[rowStart + x - offsetX] = quantizer.GetQuantizedColor(sourcePixel, paletteSpan, out TPixel transformed);
+ TPixel sourcePixel = Unsafe.Add(ref sourceRowRef, x);
+ Unsafe.Add(ref destinationRowRef, x - offsetX) = quantizer.GetQuantizedColor(sourcePixel, out TPixel transformed);
this.Dither(source, bounds, sourcePixel, transformed, x, y, scale);
}
}
@@ -119,25 +116,23 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void ApplyPaletteDither(
- Configuration configuration,
- ReadOnlyMemory palette,
+ public void ApplyPaletteDither(
+ in TPaletteDitherImageProcessor processor,
ImageFrame source,
- Rectangle bounds,
- float scale)
+ Rectangle bounds)
+ where TPaletteDitherImageProcessor : struct, IPaletteDitherImageProcessor
where TPixel : unmanaged, IPixel
{
- var pixelMap = new EuclideanPixelMap(palette);
-
+ float scale = processor.DitherScale;
for (int y = bounds.Top; y < bounds.Bottom; y++)
{
- Span row = source.GetPixelRowSpan(y);
+ ref TPixel sourceRowRef = ref MemoryMarshal.GetReference(source.GetPixelRowSpan(y));
for (int x = bounds.Left; x < bounds.Right; x++)
{
- TPixel sourcePixel = row[x];
- pixelMap.GetClosestColor(sourcePixel, out TPixel transformed);
+ ref TPixel sourcePixel = ref Unsafe.Add(ref sourceRowRef, x);
+ TPixel transformed = Unsafe.AsRef(processor).GetPaletteColor(sourcePixel);
this.Dither(source, bounds, sourcePixel, transformed, x, y, scale);
- row[x] = transformed;
+ sourcePixel = transformed;
}
}
}
diff --git a/src/ImageSharp/Processing/Processors/Dithering/IDither.cs b/src/ImageSharp/Processing/Processors/Dithering/IDither.cs
index 3d6edc9fa..5cb95ead8 100644
--- a/src/ImageSharp/Processing/Processors/Dithering/IDither.cs
+++ b/src/ImageSharp/Processing/Processors/Dithering/IDither.cs
@@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
-using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Quantization;
@@ -19,35 +18,31 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// The type of frame quantizer.
/// The pixel format.
/// The frame quantizer.
- /// The quantized palette.
/// The source image.
- /// The output target
+ /// The destination quantized frame.
/// The region of interest bounds.
void ApplyQuantizationDither(
ref TFrameQuantizer quantizer,
- ReadOnlyMemory palette,
ImageFrame source,
- Memory output,
+ IndexedImageFrame destination,
Rectangle bounds)
- where TFrameQuantizer : struct, IFrameQuantizer
+ where TFrameQuantizer : struct, IQuantizer
where TPixel : unmanaged, IPixel;
///
/// Transforms the image frame applying a dither matrix.
/// This method should be treated as destructive, altering the input pixels.
///
+ /// The type of palette dithering processor.
/// The pixel format.
- /// The configuration.
- /// The quantized palette.
+ /// The palette dithering processor.
/// The source image.
/// The region of interest bounds.
- /// The dithering scale used to adjust the amount of dither. Range 0..1.
- void ApplyPaletteDither(
- Configuration configuration,
- ReadOnlyMemory palette,
+ void ApplyPaletteDither(
+ in TPaletteDitherImageProcessor processor,
ImageFrame source,
- Rectangle bounds,
- float scale)
+ Rectangle bounds)
+ where TPaletteDitherImageProcessor : struct, IPaletteDitherImageProcessor
where TPixel : unmanaged, IPixel;
}
}
diff --git a/src/ImageSharp/Processing/Processors/Dithering/IPaletteDitherImageProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Dithering/IPaletteDitherImageProcessor{TPixel}.cs
new file mode 100644
index 000000000..2a929c6fd
--- /dev/null
+++ b/src/ImageSharp/Processing/Processors/Dithering/IPaletteDitherImageProcessor{TPixel}.cs
@@ -0,0 +1,38 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using System;
+using SixLabors.ImageSharp.PixelFormats;
+
+namespace SixLabors.ImageSharp.Processing.Processors.Dithering
+{
+ ///
+ /// Implements an algorithm to alter the pixels of an image via palette dithering.
+ ///
+ /// The pixel format.
+ public interface IPaletteDitherImageProcessor
+ where TPixel : unmanaged, IPixel
+ {
+ ///
+ /// Gets the configuration instance to use when performing operations.
+ ///
+ Configuration Configuration { get; }
+
+ ///
+ /// Gets the dithering palette.
+ ///
+ ReadOnlyMemory Palette { get; }
+
+ ///
+ /// Gets the dithering scale used to adjust the amount of dither. Range 0..1.
+ ///
+ float DitherScale { get; }
+
+ ///
+ /// Returns the color from the dithering palette corresponding to the given color.
+ ///
+ /// The color to match.
+ /// The match.
+ TPixel GetPaletteColor(TPixel color);
+ }
+}
diff --git a/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.KnownTypes.cs b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.KnownTypes.cs
index d3e710782..83f7d6136 100644
--- a/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.KnownTypes.cs
+++ b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.KnownTypes.cs
@@ -1,12 +1,12 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Dithering
{
///
/// An ordered dithering matrix with equal sides of arbitrary length
///
- public readonly partial struct OrderedDither : IDither
+ public readonly partial struct OrderedDither
{
///
/// Applies order dithering using the 2x2 Bayer dithering matrix.
diff --git a/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs
index 6efb84be9..811599e71 100644
--- a/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs
+++ b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs
@@ -1,10 +1,10 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Quantization;
@@ -105,23 +105,20 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyQuantizationDither(
ref TFrameQuantizer quantizer,
- ReadOnlyMemory palette,
ImageFrame source,
- Memory output,
+ IndexedImageFrame destination,
Rectangle bounds)
- where TFrameQuantizer : struct, IFrameQuantizer
+ where TFrameQuantizer : struct, IQuantizer
where TPixel : unmanaged, IPixel
{
- var ditherOperation = new QuantizeDitherRowIntervalOperation(
+ var ditherOperation = new QuantizeDitherRowOperation(
ref quantizer,
in Unsafe.AsRef(this),
source,
- output,
- bounds,
- palette,
- ImageMaths.GetBitsNeededForColorDepth(palette.Span.Length));
+ destination,
+ bounds);
- ParallelRowIterator.IterateRowIntervals(
+ ParallelRowIterator.IterateRows(
quantizer.Configuration,
bounds,
in ditherOperation);
@@ -129,24 +126,21 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void ApplyPaletteDither(
- Configuration configuration,
- ReadOnlyMemory palette,
+ public void ApplyPaletteDither(
+ in TPaletteDitherImageProcessor processor,
ImageFrame source,
- Rectangle bounds,
- float scale)
+ Rectangle bounds)
+ where TPaletteDitherImageProcessor : struct, IPaletteDitherImageProcessor
where TPixel : unmanaged, IPixel
{
- var ditherOperation = new PaletteDitherRowIntervalOperation(
+ var ditherOperation = new PaletteDitherRowOperation(
+ in processor,
in Unsafe.AsRef(this),
source,
- bounds,
- palette,
- scale,
- ImageMaths.GetBitsNeededForColorDepth(palette.Span.Length));
+ bounds);
- ParallelRowIterator.IterateRowIntervals(
- configuration,
+ ParallelRowIterator.IterateRows(
+ processor.Configuration,
bounds,
in ditherOperation);
}
@@ -200,102 +194,87 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
public override int GetHashCode()
=> HashCode.Combine(this.thresholdMatrix, this.modulusX, this.modulusY);
- private readonly struct QuantizeDitherRowIntervalOperation : IRowIntervalOperation
- where TFrameQuantizer : struct, IFrameQuantizer
+ private readonly struct QuantizeDitherRowOperation : IRowOperation
+ where TFrameQuantizer : struct, IQuantizer
where TPixel : unmanaged, IPixel
{
private readonly TFrameQuantizer quantizer;
private readonly OrderedDither dither;
private readonly ImageFrame source;
- private readonly Memory output;
+ private readonly IndexedImageFrame destination;
private readonly Rectangle bounds;
- private readonly ReadOnlyMemory palette;
private readonly int bitDepth;
[MethodImpl(InliningOptions.ShortMethod)]
- public QuantizeDitherRowIntervalOperation(
+ public QuantizeDitherRowOperation(
ref TFrameQuantizer quantizer,
in OrderedDither dither,
ImageFrame source,
- Memory output,
- Rectangle bounds,
- ReadOnlyMemory palette,
- int bitDepth)
+ IndexedImageFrame destination,
+ Rectangle bounds)
{
this.quantizer = quantizer;
this.dither = dither;
this.source = source;
- this.output = output;
+ this.destination = destination;
this.bounds = bounds;
- this.palette = palette;
- this.bitDepth = bitDepth;
+ this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(destination.Palette.Length);
}
[MethodImpl(InliningOptions.ShortMethod)]
- public void Invoke(in RowInterval rows)
+ public void Invoke(int y)
{
- ReadOnlySpan paletteSpan = this.palette.Span;
- Span outputSpan = this.output.Span;
- int width = this.bounds.Width;
int offsetY = this.bounds.Top;
int offsetX = this.bounds.Left;
float scale = this.quantizer.Options.DitherScale;
- for (int y = rows.Min; y < rows.Max; y++)
+ ref TPixel sourceRowRef = ref MemoryMarshal.GetReference(this.source.GetPixelRowSpan(y));
+ ref byte destinationRowRef = ref MemoryMarshal.GetReference(this.destination.GetWritablePixelRowSpanUnsafe(y - offsetY));
+
+ for (int x = this.bounds.Left; x < this.bounds.Right; x++)
{
- Span row = this.source.GetPixelRowSpan(y);
- int rowStart = (y - offsetY) * width;
-
- // TODO: This can be a bulk operation.
- for (int x = this.bounds.Left; x < this.bounds.Right; x++)
- {
- TPixel dithered = this.dither.Dither(row[x], x, y, this.bitDepth, scale);
- outputSpan[rowStart + x - offsetX] = this.quantizer.GetQuantizedColor(dithered, paletteSpan, out TPixel _);
- }
+ TPixel dithered = this.dither.Dither(Unsafe.Add(ref sourceRowRef, x), x, y, this.bitDepth, scale);
+ Unsafe.Add(ref destinationRowRef, x - offsetX) = Unsafe.AsRef(this.quantizer).GetQuantizedColor(dithered, out TPixel _);
}
}
}
- private readonly struct PaletteDitherRowIntervalOperation : IRowIntervalOperation
+ private readonly struct PaletteDitherRowOperation : IRowOperation
+ where TPaletteDitherImageProcessor : struct, IPaletteDitherImageProcessor
where TPixel : unmanaged, IPixel
{
+ private readonly TPaletteDitherImageProcessor processor;
private readonly OrderedDither dither;
private readonly ImageFrame source;
private readonly Rectangle bounds;
- private readonly EuclideanPixelMap pixelMap;
private readonly float scale;
private readonly int bitDepth;
[MethodImpl(InliningOptions.ShortMethod)]
- public PaletteDitherRowIntervalOperation(
+ public PaletteDitherRowOperation(
+ in TPaletteDitherImageProcessor processor,
in OrderedDither dither,
ImageFrame source,
- Rectangle bounds,
- ReadOnlyMemory palette,
- float scale,
- int bitDepth)
+ Rectangle bounds)
{
+ this.processor = processor;
this.dither = dither;
this.source = source;
this.bounds = bounds;
- this.pixelMap = new EuclideanPixelMap(palette);
- this.scale = scale;
- this.bitDepth = bitDepth;
+ this.scale = processor.DitherScale;
+ this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(processor.Palette.Span.Length);
}
[MethodImpl(InliningOptions.ShortMethod)]
- public void Invoke(in RowInterval rows)
+ public void Invoke(int y)
{
- for (int y = rows.Min; y < rows.Max; y++)
+ ref TPixel sourceRowRef = ref MemoryMarshal.GetReference(this.source.GetPixelRowSpan(y));
+
+ for (int x = this.bounds.Left; x < this.bounds.Right; x++)
{
- Span row = this.source.GetPixelRowSpan(y);
-
- for (int x = this.bounds.Left; x < this.bounds.Right; x++)
- {
- TPixel dithered = this.dither.Dither(row[x], x, y, this.bitDepth, this.scale);
- this.pixelMap.GetClosestColor(dithered, out TPixel transformed);
- row[x] = transformed;
- }
+ ref TPixel sourcePixel = ref Unsafe.Add(ref sourceRowRef, x);
+ TPixel dithered = this.dither.Dither(sourcePixel, x, y, this.bitDepth, this.scale);
+ sourcePixel = Unsafe.AsRef(this.processor).GetPaletteColor(dithered);
}
}
}
diff --git a/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherFactory.cs b/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherFactory.cs
index 48aaa22d6..62b16203e 100644
--- a/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherFactory.cs
+++ b/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherFactory.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor.cs b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor.cs
index 5ce7ccec0..1c4970710 100644
--- a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor{TPixel}.cs
index 254847f45..de5a7ec30 100644
--- a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor{TPixel}.cs
@@ -1,9 +1,11 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
+using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.ImageSharp.Processing.Processors.Quantization;
namespace SixLabors.ImageSharp.Processing.Processors.Dithering
{
@@ -14,11 +16,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
internal sealed class PaletteDitherProcessor : ImageProcessor
where TPixel : unmanaged, IPixel
{
- private readonly int paletteLength;
+ private readonly DitherProcessor ditherProcessor;
private readonly IDither dither;
- private readonly float ditherScale;
- private readonly ReadOnlyMemory sourcePalette;
- private IMemoryOwner palette;
+ private IMemoryOwner paletteOwner;
private bool isDisposed;
///
@@ -31,37 +31,23 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
public PaletteDitherProcessor(Configuration configuration, PaletteDitherProcessor definition, Image source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
{
- this.paletteLength = definition.Palette.Span.Length;
this.dither = definition.Dither;
- this.ditherScale = definition.DitherScale;
- this.sourcePalette = definition.Palette;
- }
- ///
- protected override void OnFrameApply(ImageFrame source)
- {
- var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
+ ReadOnlySpan sourcePalette = definition.Palette.Span;
+ this.paletteOwner = this.Configuration.MemoryAllocator.Allocate(sourcePalette.Length);
+ Color.ToPixel(this.Configuration, sourcePalette, this.paletteOwner.Memory.Span);
- this.dither.ApplyPaletteDither(
+ this.ditherProcessor = new DitherProcessor(
this.Configuration,
- this.palette.Memory,
- source,
- interest,
- this.ditherScale);
+ this.paletteOwner.Memory,
+ definition.DitherScale);
}
///
- protected override void BeforeFrameApply(ImageFrame source)
+ protected override void OnFrameApply(ImageFrame source)
{
- // Lazy init palettes:
- if (this.palette is null)
- {
- this.palette = this.Configuration.MemoryAllocator.Allocate(this.paletteLength);
- ReadOnlySpan sourcePalette = this.sourcePalette.Span;
- Color.ToPixel(this.Configuration, sourcePalette, this.palette.Memory.Span);
- }
-
- base.BeforeFrameApply(source);
+ var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
+ this.dither.ApplyPaletteDither(in this.ditherProcessor, source, interest);
}
///
@@ -72,15 +58,48 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
return;
}
+ this.isDisposed = true;
if (disposing)
{
- this.palette?.Dispose();
+ this.paletteOwner.Dispose();
}
- this.palette = null;
-
- this.isDisposed = true;
+ this.paletteOwner = null;
base.Dispose(disposing);
}
+
+ ///
+ /// Used to allow inlining of calls to
+ /// .
+ ///
+ private readonly struct DitherProcessor : IPaletteDitherImageProcessor
+ {
+ private readonly EuclideanPixelMap pixelMap;
+
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public DitherProcessor(
+ Configuration configuration,
+ ReadOnlyMemory palette,
+ float ditherScale)
+ {
+ this.Configuration = configuration;
+ this.pixelMap = new EuclideanPixelMap(configuration, palette);
+ this.Palette = palette;
+ this.DitherScale = ditherScale;
+ }
+
+ public Configuration Configuration { get; }
+
+ public ReadOnlyMemory Palette { get; }
+
+ public float DitherScale { get; }
+
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public TPixel GetPaletteColor(TPixel color)
+ {
+ this.pixelMap.GetClosestColor(color, out TPixel match);
+ return match;
+ }
+ }
}
}
diff --git a/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor.cs b/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor.cs
index 34a066049..81e99eecd 100644
--- a/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs b/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs
index fca896929..96e701760 100644
--- a/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs
+++ b/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Processing/Processors/Effects/IPixelRowDelegate.cs b/src/ImageSharp/Processing/Processors/Effects/IPixelRowDelegate.cs
index 626ffd716..280c6e87b 100644
--- a/src/ImageSharp/Processing/Processors/Effects/IPixelRowDelegate.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/IPixelRowDelegate.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs
index a816b0cb8..47e482c78 100644
--- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs
index 5ee1e40de..3a943b226 100644
--- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor.cs
index 3721afee3..5016657c1 100644
--- a/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor{TPixel,TDelegate}.cs b/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor{TPixel,TDelegate}.cs
index 71259a618..8a70f1b74 100644
--- a/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor{TPixel,TDelegate}.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor{TPixel,TDelegate}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs
index ba43ca617..127f0eaa5 100644
--- a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor{TPixel}.cs
index 60f5d29b0..b3f7d51ec 100644
--- a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Collections.Generic;
diff --git a/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor.cs
index 6822daa42..2373c98f0 100644
--- a/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Processing/Processors/Filters/AchromatomalyProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/AchromatomalyProcessor.cs
index 0e6653d99..01189f1b1 100644
--- a/src/ImageSharp/Processing/Processors/Filters/AchromatomalyProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/AchromatomalyProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/AchromatopsiaProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/AchromatopsiaProcessor.cs
index 10a201b1d..6a86b463d 100644
--- a/src/ImageSharp/Processing/Processors/Filters/AchromatopsiaProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/AchromatopsiaProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/BlackWhiteProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/BlackWhiteProcessor.cs
index 425ae511f..0e28c9846 100644
--- a/src/ImageSharp/Processing/Processors/Filters/BlackWhiteProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/BlackWhiteProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/BrightnessProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/BrightnessProcessor.cs
index 77862b3e3..1b5dc0582 100644
--- a/src/ImageSharp/Processing/Processors/Filters/BrightnessProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/BrightnessProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/ContrastProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/ContrastProcessor.cs
index 3fdeafde3..f4dd63ad6 100644
--- a/src/ImageSharp/Processing/Processors/Filters/ContrastProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/ContrastProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/DeuteranomalyProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/DeuteranomalyProcessor.cs
index 7e1c0ca50..71638f2da 100644
--- a/src/ImageSharp/Processing/Processors/Filters/DeuteranomalyProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/DeuteranomalyProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/DeuteranopiaProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/DeuteranopiaProcessor.cs
index e4ed44e74..730d71053 100644
--- a/src/ImageSharp/Processing/Processors/Filters/DeuteranopiaProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/DeuteranopiaProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs
index 5cae98568..148a34d95 100644
--- a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs
index 7da4eb1b1..a8c913a50 100644
--- a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using System;
using System.Numerics;
@@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
Span rowSpan = this.source.GetPixelRowSpan(y).Slice(this.startX, span.Length);
PixelOperations.Instance.ToVector4(this.configuration, rowSpan, span);
- Vector4Utils.Transform(span, ref Unsafe.AsRef(this.matrix));
+ Vector4Utilities.Transform(span, ref Unsafe.AsRef(this.matrix));
PixelOperations.Instance.FromVector4Destructive(this.configuration, span, rowSpan);
}
diff --git a/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt601Processor.cs b/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt601Processor.cs
index 153a1a17c..4dd2bb6af 100644
--- a/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt601Processor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt601Processor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs b/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs
index 71d3f9c9c..43d84b704 100644
--- a/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/HueProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/HueProcessor.cs
index 05d3cbdc7..bdb5a6c1a 100644
--- a/src/ImageSharp/Processing/Processors/Filters/HueProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/HueProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/InvertProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/InvertProcessor.cs
index 99b138033..343757929 100644
--- a/src/ImageSharp/Processing/Processors/Filters/InvertProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/InvertProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs
index 30484f059..96bdc59c7 100644
--- a/src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/LightnessProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/LightnessProcessor.cs
index 49be3b6a6..3b4685f28 100644
--- a/src/ImageSharp/Processing/Processors/Filters/LightnessProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/LightnessProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/LomographProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/LomographProcessor.cs
index 3c150d7eb..6dd6c783b 100644
--- a/src/ImageSharp/Processing/Processors/Filters/LomographProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/LomographProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
@@ -11,11 +11,18 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
///
/// Initializes a new instance of the class.
///
- public LomographProcessor()
+ /// Graphics options to use within the processor.
+ public LomographProcessor(GraphicsOptions graphicsOptions)
: base(KnownFilterMatrices.LomographFilter)
{
+ this.GraphicsOptions = graphicsOptions;
}
+ ///
+ /// Gets the options effecting blending and composition
+ ///
+ public GraphicsOptions GraphicsOptions { get; }
+
///
public override IImageProcessor CreatePixelSpecificProcessor(Configuration configuration, Image source, Rectangle sourceRectangle) =>
new LomographProcessor(configuration, this, source, sourceRectangle);
diff --git a/src/ImageSharp/Processing/Processors/Filters/LomographProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Filters/LomographProcessor{TPixel}.cs
index 5a19b7851..81ff899b3 100644
--- a/src/ImageSharp/Processing/Processors/Filters/LomographProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/LomographProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Overlays;
@@ -13,6 +13,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
where TPixel : unmanaged, IPixel
{
private static readonly Color VeryDarkGreen = Color.FromRgba(0, 10, 0, 255);
+ private readonly LomographProcessor definition;
///
/// Initializes a new instance of the class.
@@ -24,12 +25,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
public LomographProcessor(Configuration configuration, LomographProcessor definition, Image source, Rectangle sourceRectangle)
: base(configuration, definition, source, sourceRectangle)
{
+ this.definition = definition;
}
///
protected override void AfterImageApply()
{
- new VignetteProcessor(VeryDarkGreen).Execute(this.Configuration, this.Source, this.SourceRectangle);
+ new VignetteProcessor(this.definition.GraphicsOptions, VeryDarkGreen).Execute(this.Configuration, this.Source, this.SourceRectangle);
base.AfterImageApply();
}
}
diff --git a/src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs
index a537b8f60..eb1154181 100644
--- a/src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
diff --git a/src/ImageSharp/Processing/Processors/Filters/OpaqueProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Filters/OpaqueProcessor{TPixel}.cs
new file mode 100644
index 000000000..8c0765bc7
--- /dev/null
+++ b/src/ImageSharp/Processing/Processors/Filters/OpaqueProcessor{TPixel}.cs
@@ -0,0 +1,67 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the GNU Affero General Public License, Version 3.
+
+using System;
+using System.Numerics;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using SixLabors.ImageSharp.Advanced;
+using SixLabors.ImageSharp.PixelFormats;
+
+namespace SixLabors.ImageSharp.Processing.Processors.Filters
+{
+ internal sealed class OpaqueProcessor : ImageProcessor
+ where TPixel : unmanaged, IPixel
+ {
+ public OpaqueProcessor(
+ Configuration configuration,
+ Image source,
+ Rectangle sourceRectangle)
+ : base(configuration, source, sourceRectangle)
+ {
+ }
+
+ protected override void OnFrameApply(ImageFrame source)
+ {
+ var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
+
+ var operation = new OpaqueRowOperation(this.Configuration, source, interest);
+ ParallelRowIterator.IterateRows(this.Configuration, interest, in operation);
+ }
+
+ private readonly struct OpaqueRowOperation : IRowOperation
+ {
+ private readonly Configuration configuration;
+ private readonly ImageFrame target;
+ private readonly Rectangle bounds;
+
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public OpaqueRowOperation(
+ Configuration configuration,
+ ImageFrame target,
+ Rectangle bounds)
+ {
+ this.configuration = configuration;
+ this.target = target;
+ this.bounds = bounds;
+ }
+
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void Invoke(int y, Span span)
+ {
+ Span targetRowSpan = this.target.GetPixelRowSpan(y).Slice(this.bounds.X);
+ PixelOperations.Instance.ToVector4(this.configuration, targetRowSpan.Slice(0, span.Length), span, PixelConversionModifiers.Scale);
+ ref Vector4 baseRef = ref MemoryMarshal.GetReference(span);
+
+ for (int x = 0; x < this.bounds.Width; x++)
+ {
+ ref Vector4 v = ref Unsafe.Add(ref baseRef, x);
+ v.W = 1F;
+ }
+
+ PixelOperations.Instance.FromVector4Destructive(this.configuration, span, targetRowSpan, PixelConversionModifiers.Scale);
+ }
+ }
+ }
+}
diff --git a/src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs
index a5cf26862..e098762c2 100644
--- a/src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
@@ -11,11 +11,18 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
///
/// Initializes a new instance of the class.
///
- public PolaroidProcessor()
+ /// Graphics options to use within the processor.
+ public PolaroidProcessor(GraphicsOptions graphicsOptions)
: base(KnownFilterMatrices.PolaroidFilter)
{
+ this.GraphicsOptions = graphicsOptions;
}
+ ///
+ /// Gets the options effecting blending and composition
+ ///
+ public GraphicsOptions GraphicsOptions { get; }
+
///
public override IImageProcessor CreatePixelSpecificProcessor(Configuration configuration, Image source, Rectangle sourceRectangle) =>
new PolaroidProcessor(configuration, this, source, sourceRectangle);
diff --git a/src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor{TPixel}.cs
index 9f547be1c..3b4bafc59 100644
--- a/src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the GNU Affero General Public License, Version 3.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Overlays;
@@ -14,6 +14,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
private static readonly Color LightOrange = Color.FromRgba(255, 153, 102, 128);
private static readonly Color VeryDarkOrange = Color.FromRgb(102, 34, 0);
+ private readonly PolaroidProcessor definition;
///
/// Initializes a new instance of the