diff --git a/.gitignore b/.gitignore index 8034c8c89c..c2e6f7d536 100644 --- a/.gitignore +++ b/.gitignore @@ -158,7 +158,6 @@ AppPackages/ # Others *.[Cc]ache ClientBin/ -[Ss]tyle[Cc]op.* ~$* *~ *.dbmdl @@ -202,7 +201,8 @@ FakesAssemblies/ **/node_modules **/node_modules/* -**/TestOutput +**/Images/ActualOutput +**/Images/ReferenceOutput # ASP.NET 5 project.lock.json @@ -218,3 +218,4 @@ artifacts/ **/CodeCoverage/* docs/ /samples/AvatarWithRoundedCorner/output +/ImageSharp.Coverage.xml diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..ef3c3c1255 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "tests/Images/External"] + path = tests/Images/External + url = https://github.com/antonfirsov/Imagesharp.Tests.Images.git + branch = jpeg-lab diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..c9c7453f64 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceRoot}/samples/AvatarWithRoundedCorner/bin/Debug/netcoreapp1.1/AvatarWithRoundedCorner.dll", + "args": [], + "cwd": "${workspaceRoot}/samples/AvatarWithRoundedCorner", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/ImageSharp.ruleset b/ImageSharp.ruleset index 0bd9cd11ab..2149364b1b 100644 --- a/ImageSharp.ruleset +++ b/ImageSharp.ruleset @@ -2,10 +2,10 @@ - - - + \ No newline at end of file diff --git a/ImageSharp.sln b/ImageSharp.sln index a584c56868..60fcca80d7 100644 --- a/ImageSharp.sln +++ b/ImageSharp.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26430.14 +VisualStudioVersion = 15.0.26730.3 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{C317F1B1-D75E-4C6D-83EB-80367343E0D7}" ProjectSection(SolutionItems) = preProject @@ -30,28 +30,28 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{9E574A07-F879-4811-9C41-5CBDC6BAFDB7}" ProjectSection(SolutionItems) = preProject src\Shared\AssemblyInfo.Common.cs = src\Shared\AssemblyInfo.Common.cs - src\Shared\stylecop.json = src\Shared\stylecop.json EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp", "src\ImageSharp\ImageSharp.csproj", "{2AA31A1F-142C-43F4-8687-09ABCA4B3A26}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Drawing", "src\ImageSharp.Drawing\ImageSharp.Drawing.csproj", "{2E33181E-6E28-4662-A801-E2E7DC206029}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "build", "build\build.csproj", "{575A5002-DD9F-4335-AA47-1DD87FA13645}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Tests", "tests\ImageSharp.Tests\ImageSharp.Tests.csproj", "{EA3000E9-2A91-4EC4-8A68-E566DEBDC4F6}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Benchmarks", "tests\ImageSharp.Benchmarks\ImageSharp.Benchmarks.csproj", "{2BF743D8-2A06-412D-96D7-F448F00C5EA5}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Sandbox46", "tests\ImageSharp.Sandbox46\ImageSharp.Sandbox46.csproj", "{96188137-5FA6-4924-AB6E-4EFF79C6E0BB}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{7CC6D57E-B916-43B8-B315-A0BB92F260A2}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AvatarWithRoundedCorner", "samples\AvatarWithRoundedCorner\AvatarWithRoundedCorner.csproj", "{844FC582-4E78-4371-847D-EFD4D1103578}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChangeDefaultEncoderOptions", "samples\ChangeDefaultEncoderOptions\ChangeDefaultEncoderOptions.csproj", "{07EE511D-4BAB-4323-BAFC-3AF2BF9366F0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChangeDefaultEncoderOptions", "samples\ChangeDefaultEncoderOptions\ChangeDefaultEncoderOptions.csproj", "{07EE511D-4BAB-4323-BAFC-3AF2BF9366F0}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Sandbox46", "tests\ImageSharp.Sandbox46\ImageSharp.Sandbox46.csproj", "{561B880A-D9EE-44EF-90F5-817C54A9D9AB}" EndProject Global + GlobalSection(Performance) = preSolution + HasPerformanceSessions = true + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 @@ -85,18 +85,6 @@ Global {2E33181E-6E28-4662-A801-E2E7DC206029}.Release|x64.Build.0 = Release|Any CPU {2E33181E-6E28-4662-A801-E2E7DC206029}.Release|x86.ActiveCfg = Release|Any CPU {2E33181E-6E28-4662-A801-E2E7DC206029}.Release|x86.Build.0 = Release|Any CPU - {575A5002-DD9F-4335-AA47-1DD87FA13645}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {575A5002-DD9F-4335-AA47-1DD87FA13645}.Debug|Any CPU.Build.0 = Debug|Any CPU - {575A5002-DD9F-4335-AA47-1DD87FA13645}.Debug|x64.ActiveCfg = Debug|Any CPU - {575A5002-DD9F-4335-AA47-1DD87FA13645}.Debug|x64.Build.0 = Debug|Any CPU - {575A5002-DD9F-4335-AA47-1DD87FA13645}.Debug|x86.ActiveCfg = Debug|Any CPU - {575A5002-DD9F-4335-AA47-1DD87FA13645}.Debug|x86.Build.0 = Debug|Any CPU - {575A5002-DD9F-4335-AA47-1DD87FA13645}.Release|Any CPU.ActiveCfg = Release|Any CPU - {575A5002-DD9F-4335-AA47-1DD87FA13645}.Release|Any CPU.Build.0 = Release|Any CPU - {575A5002-DD9F-4335-AA47-1DD87FA13645}.Release|x64.ActiveCfg = Release|Any CPU - {575A5002-DD9F-4335-AA47-1DD87FA13645}.Release|x64.Build.0 = Release|Any CPU - {575A5002-DD9F-4335-AA47-1DD87FA13645}.Release|x86.ActiveCfg = Release|Any CPU - {575A5002-DD9F-4335-AA47-1DD87FA13645}.Release|x86.Build.0 = Release|Any CPU {EA3000E9-2A91-4EC4-8A68-E566DEBDC4F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EA3000E9-2A91-4EC4-8A68-E566DEBDC4F6}.Debug|Any CPU.Build.0 = Debug|Any CPU {EA3000E9-2A91-4EC4-8A68-E566DEBDC4F6}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -121,18 +109,6 @@ Global {2BF743D8-2A06-412D-96D7-F448F00C5EA5}.Release|x64.Build.0 = Release|Any CPU {2BF743D8-2A06-412D-96D7-F448F00C5EA5}.Release|x86.ActiveCfg = Release|Any CPU {2BF743D8-2A06-412D-96D7-F448F00C5EA5}.Release|x86.Build.0 = Release|Any CPU - {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Debug|x64.ActiveCfg = Debug|Any CPU - {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Debug|x64.Build.0 = Debug|Any CPU - {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Debug|x86.ActiveCfg = Debug|Any CPU - {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Debug|x86.Build.0 = Debug|Any CPU - {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Release|Any CPU.Build.0 = Release|Any CPU - {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Release|x64.ActiveCfg = Release|Any CPU - {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Release|x64.Build.0 = Release|Any CPU - {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Release|x86.ActiveCfg = Release|Any CPU - {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Release|x86.Build.0 = Release|Any CPU {844FC582-4E78-4371-847D-EFD4D1103578}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {844FC582-4E78-4371-847D-EFD4D1103578}.Debug|Any CPU.Build.0 = Debug|Any CPU {844FC582-4E78-4371-847D-EFD4D1103578}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -157,6 +133,18 @@ Global {07EE511D-4BAB-4323-BAFC-3AF2BF9366F0}.Release|x64.Build.0 = Release|Any CPU {07EE511D-4BAB-4323-BAFC-3AF2BF9366F0}.Release|x86.ActiveCfg = Release|Any CPU {07EE511D-4BAB-4323-BAFC-3AF2BF9366F0}.Release|x86.Build.0 = Release|Any CPU + {561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Debug|x64.ActiveCfg = Debug|Any CPU + {561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Debug|x64.Build.0 = Debug|Any CPU + {561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Debug|x86.ActiveCfg = Debug|Any CPU + {561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Debug|x86.Build.0 = Debug|Any CPU + {561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Release|Any CPU.Build.0 = Release|Any CPU + {561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Release|x64.ActiveCfg = Release|Any CPU + {561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Release|x64.Build.0 = Release|Any CPU + {561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Release|x86.ActiveCfg = Release|Any CPU + {561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -165,11 +153,13 @@ Global {9E574A07-F879-4811-9C41-5CBDC6BAFDB7} = {815C0625-CD3D-440F-9F80-2D83856AB7AE} {2AA31A1F-142C-43F4-8687-09ABCA4B3A26} = {815C0625-CD3D-440F-9F80-2D83856AB7AE} {2E33181E-6E28-4662-A801-E2E7DC206029} = {815C0625-CD3D-440F-9F80-2D83856AB7AE} - {575A5002-DD9F-4335-AA47-1DD87FA13645} = {E919DF0B-2607-4462-8FC0-5C98FE50F8C9} {EA3000E9-2A91-4EC4-8A68-E566DEBDC4F6} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC} {2BF743D8-2A06-412D-96D7-F448F00C5EA5} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC} - {96188137-5FA6-4924-AB6E-4EFF79C6E0BB} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC} {844FC582-4E78-4371-847D-EFD4D1103578} = {7CC6D57E-B916-43B8-B315-A0BB92F260A2} {07EE511D-4BAB-4323-BAFC-3AF2BF9366F0} = {7CC6D57E-B916-43B8-B315-A0BB92F260A2} + {561B880A-D9EE-44EF-90F5-817C54A9D9AB} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5F8B9D1F-CD8B-4CC5-8216-D531E25BD795} EndGlobalSection EndGlobal diff --git a/README.md b/README.md index 7113d6ba1a..a5e8d33e6d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Built against .Net Standard 1.1 ImageSharp can be used in device, cloud, and emb > **ImageSharp** has made excellent progress and contains many great features but is still considered by us to be still in early stages (alpha). As such, we cannot support its use on production environments until the library reaches release candidate status. > -> Pre-release downloads are available from the [MyGet package repository](https://www.myget.org/gallery/imagesharp). +> Pre-release downloads are available from the [MyGet package repository](https://www.myget.org/gallery/sixlabors). [![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/SixLabors/ImageSharp/master/APACHE-2.0-LICENSE.txt) [![GitHub issues](https://img.shields.io/github/issues/SixLabors/ImageSharp.svg)](https://github.com/SixLabors/ImageSharp/issues) @@ -31,20 +31,20 @@ At present the code is pre-release but when ready it will be available on [Nuget **Pre-release downloads** -We already have a [MyGet package repository](https://www.myget.org/gallery/imagesharp) - for bleeding-edge / development NuGet releases. +We already have a [MyGet package repository](https://www.myget.org/gallery/sixlabors) - for bleeding-edge / development NuGet releases. ### Packages The **ImageSharp** library is made up of multiple packages. Packages include: -- **ImageSharp** +- **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. -- **ImageSharp.Drawing** +- **SixLabors.ImageSharp.Drawing** - Brushes and various drawing algorithms, including drawing images. - Various vector drawing methods for drawing paths, polygons etc. - Text drawing. @@ -88,9 +88,10 @@ On platforms supporting netstandard 1.3+ // 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.Resize(image.Width / 2, image.Height / 2) - .Grayscale() - .Save("bar.jpg"); // automatic encoder selected based on extension. + image.Mutate(x=>x + .Resize(image.Width / 2, image.Height / 2) + .Grayscale()); + image.Save("bar.jpg"); // automatic encoder selected based on extension. } ``` on netstandard 1.1 - 1.2 @@ -100,9 +101,10 @@ using (FileStream stream = File.OpenRead("foo.jpg")) using (FileStream output = File.OpenWrite("bar.jpg")) using (Image image = Image.Load(stream)) { - image.Resize(image.Width / 2, image.Height / 2) - .Grayscale() - .Save(output); + image.Mutate(x=>x + .Resize(image.Width / 2, image.Height / 2) + .Grayscale()); + image.Save(output); } ``` diff --git a/appveyor.yml b/appveyor.yml index fdbe46b015..a44fe37c47 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,11 +1,13 @@ version: 1.0.0.{build} image: Visual Studio 2017 -# prevent the double build when a branch has an active PR -skip_branch_with_pr: true -init: - - ps: iex ((new-object net.webclient).DownloadString('https://gist.githubusercontent.com/PureKrome/0f79e25693d574807939/raw/8cf3160c9516ef1f4effc825c0a44acc918a0b5a/appveyor-build-info.ps')) +install: + - choco install gitversion.portable -pre -y + +before_build: + - cmd: dotnet --version + - ps: gitversion /l console /output buildserver build_script: - cmd: build.cmd @@ -13,16 +15,17 @@ build_script: test_script: - tests\CodeCoverage\CodeCoverage.cmd -artifacts: -- path: artifacts\bin\ImageSharp\**\*.nupkg +after_build: + - cmd: appveyor PushArtifact "artifacts\SixLabors.ImageSharp.%GitVersion_NuGetVersion%.nupkg" + - cmd: appveyor PushArtifact "artifacts\SixLabors.ImageSharp.Drawing.%GitVersion_NuGetVersion%.nupkg" deploy: # MyGet Deployment for builds & releases - - provider: NuGet - server: https://www.myget.org/F/imagesharp/api/v2/package - symbol_server: https://www.myget.org/F/imagesharp/symbols/api/v2/package - api_key: - secure: P2Fz82nty+itjL+kNRCsMQcqzngmVtkU0R4CZqgST7zgUaE6/1q9ekh5MKKlZLkD - artifact: /.*\.nupkg/ - on: - branch: master + - provider: NuGet + server: https://www.myget.org/F/sixlabors/api/v2/package + symbol_server: https://www.myget.org/F/sixlabors/symbols/api/v2/package + api_key: + secure: V/lEHP0UeMWIpWd0fiNlY2IgbCnJKQlGdRksECdJbOBdaE20Fl0RNL7WyqHe02o4 + artifact: /.*\.nupkg/ + on: + branch: master diff --git a/build.cmd b/build.cmd index e33a230bcd..662be648a2 100644 --- a/build.cmd +++ b/build.cmd @@ -1,2 +1,36 @@ @echo Off -call build\build.cmd \ No newline at end of file + +if not "%GitVersion_NuGetVersion%" == "" ( + SET versionCommand=/p:packageversion=%GitVersion_NuGetVersion% + @echo building with version set to '%GitVersion_NuGetVersion%' +) + +dotnet restore %versionCommand% + + +ECHO Building nuget packages +dotnet build -c Release %versionCommand% +if not "%errorlevel%"=="0" goto failure + +if not %CI% == "True" ( + dotnet test ./tests/ImageSharp.Tests/ImageSharp.Tests.csproj --no-build -c Release + if not "%errorlevel%"=="0" goto failure +) + +dotnet pack ./src/ImageSharp/ -c Release --output ../../artifacts --no-build %versionCommand% +if not "%errorlevel%"=="0" goto failure + +dotnet pack ./src/ImageSharp.Drawing/ -c Release --output ../../artifacts --no-build %versionCommand% +if not "%errorlevel%"=="0" goto failure + +:success +ECHO successfully built project +REM exit 0 +goto end + +:failure +ECHO failed to build. +REM exit -1 +goto end + +:end \ No newline at end of file diff --git a/build/Program.cs b/build/Program.cs deleted file mode 100644 index 4e59b22145..0000000000 --- a/build/Program.cs +++ /dev/null @@ -1,463 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ConsoleApplication -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Text; - using System.Xml; - using LibGit2Sharp; - using Microsoft.Build.Construction; - using Microsoft.Build.Evaluation; - using NuGet.Versioning; - - /// - /// This updates the version numbers for all the projects in the src folder. - /// The version number it will geneate is dependent on if this is a build from master or a branch/PR - /// - /// If its a build on master - /// We take the version number specified in project.json, - /// count how meny commits the repo has had that will affect this project or its dependencies since the version number of manually changed - /// If this is the first commit that effected this project since number change then leave the version number as defined i.e. will build 1.0.0 if thats in project.json - /// unless it is a preview build number in which case we always add the counter - /// - /// If the build is from a PR/branch - /// We take the version number specified in project.json, append a tag for the branch/PR (so we can determin how each package was built) - /// append number of commits effecting the project. - /// - /// - /// - /// for PR#123 and project.json version 2.0.1 and we have had 30 commits affecting the project - /// we would end up with version number 2.0.1-PR124-00030 - /// - /// for branch `fix-stuff` project.json version 2.0.1-alpha1 and we have had 832 commits affecting the project - /// we would end up with version number 2.0.1-alpha1-fix-stuff-00832 - /// - /// for `master` project.json version 2.0.1-alpha1 and we have had 832 commits affecting the project - /// we would end up with version number 2.0.1-alpha1-00832 - /// - /// for `master` project.json version 2.0.1 and we have had 132 commits affecting the project - /// we would end up with version number 2.0.1-CI-00132 - /// - /// for `master` project.json version 2.0.1 and we have had 1 commits affecting the project - /// we would end up with version number 2.0.1 - /// - /// for `master` project.json version 2.0.1-alpha1 and we have had 1 commits affecting the project - /// we would end up with version number 2.0.1-alpha1 - /// - /// - /// TODO Add the option for using this to update the version numbers in a project and its dependent references. - /// - public class Program - { - private const string FallbackTag = "CI"; - - /// - /// Main entry point. - /// - /// The arguments. - public static void Main(string[] args) - { - bool resetmode = args.Contains("reset"); - - // Find the project root - string root = Path.GetFullPath(Path.Combine(LibGit2Sharp.Repository.Discover("."), "..")); - - // Lets find the repo - Repository repo = new LibGit2Sharp.Repository(root); - - // Lets find all the project.json files in the src folder (don't care about versioning `tests`) - IEnumerable projectFiles = Directory.EnumerateFiles(Path.Combine(root, "src"), "*.csproj", SearchOption.AllDirectories); - - ResetProject(projectFiles); - - // Open them and convert them to source projects - List projects = projectFiles.Select(x => ProjectRootElement.Open(x, ProjectCollection.GlobalProjectCollection, true)) - .Select(x => new SourceProject(x, repo.Info.WorkingDirectory)) - .ToList(); - - if (!resetmode) - { - CaclulateProjectVersionNumber(projects, repo); - - UpdateVersionNumbers(projects); - - CreateBuildScript(projects, root); - - foreach (SourceProject p in projects) - { - Console.WriteLine($"{p.Name} {p.FinalVersionNumber}"); - } - } - } - - private static void CreateBuildScript(IEnumerable projects, string root) - { - string outputDir = Path.GetFullPath(Path.Combine(root, @"artifacts\bin\ImageSharp")); - - StringBuilder sb = new StringBuilder(); - foreach (SourceProject p in projects) - { - sb.AppendLine($@"dotnet pack --configuration Release --output ""{outputDir}"" ""{p.ProjectFilePath}"""); - } - - File.WriteAllText("build-inner.cmd", sb.ToString()); - } - - private static void UpdateVersionNumbers(IEnumerable projects) - { - foreach (SourceProject p in projects) - { - // create a backup file so we can rollback later without breaking formatting - File.Copy(p.FullProjectFilePath, $"{p.FullProjectFilePath}.bak", true); - } - - foreach (SourceProject p in projects) - { - // TODO force update of all dependent projects to point to the newest build. - // we skip the build number and standard CI prefix on first commits - string newVersion = p.FinalVersionNumber; - - p.UpdateVersion(newVersion); - } - } - - private static string CurrentBranch(Repository repo) - { - // lets build version friendly commit - string branch = repo.Head.FriendlyName; - - // lets see if we are running in appveyor and if we are use the environment variables instead of the head - string appveryorBranch = Environment.GetEnvironmentVariable("APPVEYOR_REPO_BRANCH"); - if (!string.IsNullOrWhiteSpace(appveryorBranch)) - { - branch = appveryorBranch; - } - - string prNumber = Environment.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_NUMBER"); - if (!string.IsNullOrWhiteSpace(prNumber)) - { - branch = $"PR{int.Parse(prNumber):000}"; - } - - // this will happen when checking out a comit directly and not a branch (like appveryor does when it builds) - if (branch == "(no branch)") - { - throw new Exception("unable to find branch"); - } - - // clean branch names (might need to be improved) - branch = branch.Replace("/", "-").Replace("--", "-"); - - return branch; - } - - private static void CaclulateProjectVersionNumber(List projects, Repository repo) - { - string branch = CurrentBranch(repo); - - // populate the dependency chains - projects.ForEach(x => x.PopulateDependencies(projects)); - - // update the final version based on the repo history and the currentr branch name - projects.ForEach(x => x.CalculateVersion(repo, branch)); - } - - private static void ResetProject(IEnumerable projectPaths) - { - if (File.Exists("build-inner.cmd")) - { - File.Delete("build-inner.cmd"); - } - - // revert the project.json change be reverting it but skipp all the git stuff as its not needed - foreach (string p in projectPaths) - { - if (File.Exists($"{p}.bak")) - { - File.Copy($"{p}.bak", p, true); - File.Delete($"{p}.bak"); - } - } - } - - /// - /// Project level logic - /// - public class SourceProject - { - private readonly IEnumerable dependencies; - private readonly ProjectRootElement project; - - /// - /// Initializes a new instance of the class. - /// - /// The project. - /// The root. - public SourceProject(ProjectRootElement project, string root) - { - this.Name = project.Properties.FirstOrDefault(x => x.Name == "AssemblyTitle").Value; - - this.ProjectDirectory = project.DirectoryPath.Substring(root.Length); - this.ProjectFilePath = project.ProjectFileLocation.File.Substring(root.Length); - this.FullProjectFilePath = Path.GetFullPath(project.ProjectFileLocation.File); - this.Version = new NuGetVersion(project.Properties.FirstOrDefault(x => x.Name == "VersionPrefix").Value); - this.dependencies = project.Items.Where(x => x.ItemType == "ProjectReference").Select(x => Path.GetFullPath(Path.Combine(project.DirectoryPath, x.Include))); - this.FinalVersionNumber = this.Version.ToFullString(); - this.project = project; - } - - /// - /// Gets the project directory. - /// - /// - /// The project directory. - /// - public string ProjectDirectory { get; } - - /// - /// Gets the version. - /// - /// - /// The version. - /// - public NuGetVersion Version { get; private set; } - - /// - /// Gets the dependent projects. - /// - /// - /// The dependent projects. - /// - public List DependentProjects { get; private set; } - - /// - /// Gets the name. - /// - /// - /// The name. - /// - public string Name { get; private set; } - - /// - /// Gets the project file path. - /// - /// - /// The project file path. - /// - public string ProjectFilePath { get; private set; } - - /// - /// Gets the commit count since version change. - /// - /// - /// The commit count since version change. - /// - public int CommitCountSinceVersionChange { get; private set; } = 0; - - /// - /// Gets the full project file path. - /// - /// - /// The full project file path. - /// - public string FullProjectFilePath { get; private set; } - - /// - /// Gets the final version number. - /// - /// - /// The final version number. - /// - public string FinalVersionNumber { get; private set; } - - /// - /// Populates the dependencies. - /// - /// The projects. - public void PopulateDependencies(IEnumerable projects) - { - this.DependentProjects = projects.Where(x => this.dependencies.Contains(x.FullProjectFilePath)).ToList(); - } - - /// - /// Update the version number in the project file - /// - /// the new version number to save. - internal void UpdateVersion(string versionnumber) - { - this.project.AddProperty("VersionPrefix", versionnumber); - this.Version = new NuGetVersion(versionnumber); - this.project.Save(); - } - - /// - /// Calculates the version. - /// - /// The repo. - /// The branch. - internal void CalculateVersion(Repository repo, string branch) - { - foreach (Commit c in repo.Commits) - { - if (!this.ApplyCommit(c, repo)) - { - // we have finished lets populate the final version number - this.FinalVersionNumber = this.CalculateVersionNumber(branch); - - return; - } - } - } - - private bool MatchPath(string path) - { - if (path.StartsWith(this.ProjectDirectory, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - if (this.DependentProjects.Any()) - { - return this.DependentProjects.Any(x => x.MatchPath(path)); - } - - return false; - } - - private bool ApplyCommitInternal(Commit commit, TreeChanges changes, Repository repo) - { - this.CommitCountSinceVersionChange++; - - // return false if this is a version number root - TreeEntryChanges projectFileChange = changes.Where(x => x.Path?.Equals(this.ProjectFilePath, StringComparison.OrdinalIgnoreCase) == true).FirstOrDefault(); - if (projectFileChange != null) - { - if (projectFileChange.Status == ChangeKind.Added) - { - // the version must have been set here - return false; - } - else - { - Blob blob = repo.Lookup(projectFileChange.Oid); - using (Stream s = blob.GetContentStream()) - { - using (XmlReader reader = XmlReader.Create(s)) - { - ProjectRootElement proj = ProjectRootElement.Create(reader); - NuGetVersion version = new NuGetVersion(proj.Properties.FirstOrDefault(x => x.Name == "VersionPrefix").Value); - if (version != this.Version) - { - // version changed - return false; - } - } - } - } - - // version must have been the same lets carry on - return true; - } - - return true; - } - - private bool ApplyCommit(Commit commit, Repository repo) - { - foreach (Commit parent in commit.Parents) - { - TreeChanges changes = repo.Diff.Compare(parent.Tree, commit.Tree); - - foreach (TreeEntryChanges change in changes) - { - if (!string.IsNullOrWhiteSpace(change.OldPath)) - { - if (this.MatchPath(change.OldPath)) - { - return this.ApplyCommitInternal(commit, changes, repo); - } - } - - if (!string.IsNullOrWhiteSpace(change.Path)) - { - if (this.MatchPath(change.Path)) - { - return this.ApplyCommitInternal(commit, changes, repo); - } - } - } - } - - return true; - } - - private string CalculateVersionNumber(string branch) - { - string version = this.Version.ToFullString(); - - // master only - if (this.CommitCountSinceVersionChange == 1 && branch == "master") - { - if (this.Version.IsPrerelease) - { - // prerelease always needs the build counter just not on a branch name - return $"{version}-{this.CommitCountSinceVersionChange:00000}"; - } - - // this is the full release happy path, first commit after changing the version number - return version; - } - - string rootSpecialVersion = string.Empty; - - if (this.Version.IsPrerelease) - { - // probably a much easy way for doing this but it work sell enough for a build script - string[] parts = version.Split(new[] { '-' }, 2); - version = parts[0]; - rootSpecialVersion = parts[1]; - } - - // if master and the version doesn't manually specify a prerelease tag force one on for CI builds - if (branch == "master") - { - if (!this.Version.IsPrerelease) - { - branch = FallbackTag; - } - else - { - branch = string.Empty; - } - } - - if (rootSpecialVersion.Length > 0) - { - rootSpecialVersion = "-" + rootSpecialVersion; - } - - if (branch.Length > 0) - { - branch = "-" + branch; - } - - int maxLength = 20; // dotnet will fail to populate the package if the tag is > 20 - maxLength -= rootSpecialVersion.Length; // this is a required tag - maxLength -= 7; // for the counter and dashes - - if (branch.Length > maxLength) - { - branch = branch.Substring(0, maxLength); - } - - return $"{version}{rootSpecialVersion}{branch}-{this.CommitCountSinceVersionChange:00000}"; - } - } - } -} diff --git a/build/Properties/launchSettings.json b/build/Properties/launchSettings.json deleted file mode 100644 index d175ae7547..0000000000 --- a/build/Properties/launchSettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "profiles": { - "build": { - "commandName": "Project", - "commandLineArgs": "reset" - } - } -} \ No newline at end of file diff --git a/build/build.cmd b/build/build.cmd deleted file mode 100644 index 14fc0bdaa9..0000000000 --- a/build/build.cmd +++ /dev/null @@ -1,18 +0,0 @@ -@echo Off -set buildRoot="%cd%" - -ECHO Restoring packages -dotnet restore - -ECHO Updating version numbers and generating build script -cd %~dp0 -dotnet run -- update -cd %buildRoot% - -ECHO Building package -call %~dp0build-inner.cmd - -ECHO Reset version numbers -cd %~dp0 -dotnet run -- reset -cd %buildRoot% \ No newline at end of file diff --git a/build/build.csproj b/build/build.csproj deleted file mode 100644 index dc431284ed..0000000000 --- a/build/build.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - netcoreapp1.1 - portable - true - build - Exe - build - ..\ImageSharp.ruleset - - - - - - - \ No newline at end of file diff --git a/build/reset-versions.cmd b/build/reset-versions.cmd deleted file mode 100644 index 31d1d24318..0000000000 --- a/build/reset-versions.cmd +++ /dev/null @@ -1,8 +0,0 @@ -@echo Off - -set buildRoot="%cd%" -cd %~dp0 - -dotnet run -- reset - -cd %buildRoot% \ No newline at end of file diff --git a/samples/AvatarWithRoundedCorner/Program.cs b/samples/AvatarWithRoundedCorner/Program.cs index b164c8d3bc..087bbc29d5 100644 --- a/samples/AvatarWithRoundedCorner/Program.cs +++ b/samples/AvatarWithRoundedCorner/Program.cs @@ -1,69 +1,109 @@ - +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Numerics; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.Primitives; +using SixLabors.Shapes; namespace AvatarWithRoundedCorner { - using System; - using System.Numerics; - using ImageSharp; - using SixLabors.Primitives; - using SixLabors.Shapes; - - class Program + static class Program { static void Main(string[] args) { System.IO.Directory.CreateDirectory("output"); + using (var img = Image.Load("fb.jpg")) + { + // as generate returns a new IImage make sure we dispose of it + using (Image destRound = img.Clone(x => x.ConvertToAvatar(new Size(200, 200), 20))) + { + destRound.Save("output/fb.png"); + } - GenerateAvatar("fb.jpg", "output/fb.png", new Size(200, 200), 20); - GenerateAvatar("fb.jpg", "output/fb-round.png", new Size(200, 200), 100); - GenerateAvatar("fb.jpg", "output/fb-rounder.png", new Size(200, 200), 150); + using (Image destRound = img.Clone(x => x.ConvertToAvatar(new Size(200, 200), 100))) + { + destRound.Save("output/fb-round.png"); + } + + using (Image destRound = img.Clone(x => x.ConvertToAvatar(new Size(200, 200), 150))) + { + destRound.Save("output/fb-rounder.png"); + } + + using (Image destRound = img.CloneAndConvertToAvatarWithoutApply(new Size(200, 200), 150)) + { + destRound.Save("output/fb-rounder-without-apply.png"); + } + + // the original `img` object has not been altered at all. + } } - private static void GenerateAvatar(string source, string destination, Size size, float cornerRadius) + // 1. The short way: + // Implements a full image mutating pipeline operating on IImageProcessingContext + // We need the dimensions of the resized image to deduce 'IPathCollection' needed to build the corners, + // so we implement an "inline" image processor by utilizing 'ImageExtensions.Apply()' + private static IImageProcessingContext ConvertToAvatar(this IImageProcessingContext processingContext, Size size, float cornerRadius) { - using (var image = Image.Load(source)) + return processingContext.Resize(new ResizeOptions { - image.Resize(new ImageSharp.Processing.ResizeOptions - { - Size = size, - Mode = ImageSharp.Processing.ResizeMode.Crop - }); + Size = size, + Mode = ResizeMode.Crop + }).Apply(i => ApplyRoundedCorners(i, cornerRadius)); + } - ApplyRoundedCourners(image, cornerRadius); - image.Save(destination); - } + // 2. A more verbose way, avoiding 'Apply()': + // First we create a resized clone of the image, then we draw the corners on that instance with Mutate(). + private static Image CloneAndConvertToAvatarWithoutApply(this Image image, Size size, float cornerRadius) + { + Image result = image.Clone( + ctx => ctx.Resize( + new ResizeOptions + { + Size = size, + Mode = ResizeMode.Crop + })); + + ApplyRoundedCorners(result, cornerRadius); + return result; } - public static void ApplyRoundedCourners(Image img, float cornerRadius) + // This method can be seen as an inline implementation of an `IImageProcessor`: + // (The combination of `IImageOperations.Apply()` + this could be replaced with an `IImageProcessor`) + public static void ApplyRoundedCorners(Image img, float cornerRadius) { - var corners = BuildCorners(img.Width, img.Height, cornerRadius); - // now we have our corners time to draw them - img.Fill(Rgba32.Transparent, corners, new GraphicsOptions(true) + IPathCollection corners = BuildCorners(img.Width, img.Height, cornerRadius); + + // mutating in here as we already have a cloned original + img.Mutate(x => x.Fill(Rgba32.Transparent, corners, new GraphicsOptions(true) { - BlenderMode = ImageSharp.PixelFormats.PixelBlenderMode.Src // enforces that any part of this shape that has color is punched out of the background - }); + BlenderMode = PixelBlenderMode.Src // enforces that any part of this shape that has color is punched out of the background + })); } - public static IPathCollection BuildCorners(int imageWidth, int imageHeight, float cornerRadius) + public static IPathCollection BuildCorners(int imageWidth, int imageHeight, float cornerRadius) { // first create a square - var rect = new SixLabors.Shapes.RectangularePolygon(-0.5f, -0.5f, cornerRadius, cornerRadius); + var rect = new RectangularePolygon(-0.5f, -0.5f, cornerRadius, cornerRadius); // then cut out of the square a circle so we are left with a corner - var cornerToptLeft = rect.Clip(new SixLabors.Shapes.EllipsePolygon(cornerRadius-0.5f, cornerRadius - 0.5f, cornerRadius)); + IPath cornerToptLeft = rect.Clip(new EllipsePolygon(cornerRadius - 0.5f, cornerRadius - 0.5f, cornerRadius)); // corner is now a corner shape positions top left - //lets make 3 more positioned correctly, we cando that by translating the orgional artound the center of the image - var center = new Vector2(imageWidth / 2, imageHeight / 2); - var angle = Math.PI / 2f; + //lets make 3 more positioned correctly, we can do that by translating the orgional artound the center of the image + var center = new Vector2(imageWidth / 2F, imageHeight / 2F); - float rightPos = imageWidth - cornerToptLeft.Bounds.Width +1; + float rightPos = imageWidth - cornerToptLeft.Bounds.Width + 1; float bottomPos = imageHeight - cornerToptLeft.Bounds.Height + 1; // move it across the widthof the image - the width of the shape - var cornerTopRight = cornerToptLeft.RotateDegree(90).Translate(rightPos, 0); - var cornerBottomLeft = cornerToptLeft.RotateDegree(-90).Translate(0, bottomPos); - var cornerBottomRight = cornerToptLeft.RotateDegree(180).Translate(rightPos, bottomPos); + IPath cornerTopRight = cornerToptLeft.RotateDegree(90).Translate(rightPos, 0); + IPath cornerBottomLeft = cornerToptLeft.RotateDegree(-90).Translate(0, bottomPos); + IPath cornerBottomRight = cornerToptLeft.RotateDegree(180).Translate(rightPos, bottomPos); return new PathCollection(cornerToptLeft, cornerBottomLeft, cornerTopRight, cornerBottomRight); } diff --git a/samples/ChangeDefaultEncoderOptions/Program.cs b/samples/ChangeDefaultEncoderOptions/Program.cs index dab8d445ca..d4541043f9 100644 --- a/samples/ChangeDefaultEncoderOptions/Program.cs +++ b/samples/ChangeDefaultEncoderOptions/Program.cs @@ -1,6 +1,9 @@ -using System; -using ImageSharp; -using ImageSharp.Formats; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Formats; namespace ChangeDefaultEncoderOptions { @@ -10,7 +13,7 @@ static void Main(string[] args) { // lets switch out the default encoder for jpeg to one // that saves at 90 quality and ignores the matadata - Configuration.Default.SetEncoder(ImageFormats.Jpeg, new ImageSharp.Formats.JpegEncoder() + Configuration.Default.SetEncoder(ImageFormats.Jpeg, new JpegEncoder() { Quality = 90, IgnoreMetadata = true diff --git a/src/ImageSharp.Drawing/Brushes/Brushes.cs b/src/ImageSharp.Drawing/Brushes/Brushes.cs index e39f3dd497..47e207e8c4 100644 --- a/src/ImageSharp.Drawing/Brushes/Brushes.cs +++ b/src/ImageSharp.Drawing/Brushes/Brushes.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing.Brushes -{ - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Drawing.Brushes +{ /// /// A collection of methods for creating generic brushes. /// diff --git a/src/ImageSharp.Drawing/Brushes/IBrush.cs b/src/ImageSharp.Drawing/Brushes/IBrush.cs index 33b516e5c2..80393a08c1 100644 --- a/src/ImageSharp.Drawing/Brushes/IBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/IBrush.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing -{ - using ImageSharp.PixelFormats; - using Processors; - using SixLabors.Primitives; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Drawing +{ /// /// Brush represents a logical configuration of a brush which can be used to source pixel colors /// diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs index 57fcd8ffa6..f04f16536d 100644 --- a/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing.Brushes -{ - using System; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Drawing.Brushes +{ /// /// Provides an implementation of an image brush for painting images within areas. /// diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs index 5fcb92bdc7..8d3f74d6c6 100644 --- a/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing.Brushes -{ - using System; - using System.Numerics; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using Processors; - using SixLabors.Primitives; +using System; +using System.Numerics; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Drawing.Brushes +{ /// /// Provides an implementation of a pattern brush for painting patterns. /// diff --git a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs index 29c625d7f8..34f4201457 100644 --- a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing.Processors -{ - using System; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Drawing.Processors +{ /// /// primitive that converts a point in to a color for discovering the fill color based on an implementation /// diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs index 27aa99b975..d0fa81db38 100644 --- a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing.Brushes -{ - using System; - using System.Numerics; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using Processors; - using SixLabors.Primitives; +using System; +using System.Numerics; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Drawing.Brushes +{ /// /// Provides an implementation of a brush that can recolor an image /// diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs index 21ebb88a04..22d8d805f5 100644 --- a/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing.Brushes -{ - using System; - using System.Numerics; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using Processors; - using SixLabors.Primitives; +using System; +using System.Numerics; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Drawing.Brushes +{ /// /// Provides an implementation of a solid brush for painting solid color areas. /// diff --git a/src/ImageSharp.Drawing/DrawImage.cs b/src/ImageSharp.Drawing/DrawImage.cs index 03eb7be289..d55e224162 100644 --- a/src/ImageSharp.Drawing/DrawImage.cs +++ b/src/ImageSharp.Drawing/DrawImage.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using Drawing.Processors; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,7 +22,7 @@ public static partial class ImageExtensions /// The location to draw the blended image. /// The options. /// The . - public static Image DrawImage(this Image source, Image image, Size size, Point location, GraphicsOptions options) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Size size, Point location, GraphicsOptions options) where TPixel : struct, IPixel { if (size == default(Size)) @@ -37,7 +35,7 @@ public static Image DrawImage(this Image source, Image(image, size, location, options), source.Bounds); + source.ApplyProcessor(new DrawImageProcessor(image, size, location, options)); return source; } @@ -49,7 +47,7 @@ public static Image DrawImage(this Image source, ImageThe image to blend with the currently processing image. /// The opacity of the image image to blend. Must be between 0 and 1. /// The . - public static Image Blend(this Image source, Image image, float percent) + public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, float percent) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -66,7 +64,7 @@ public static Image Blend(this Image source, ImageThe blending mode. /// The opacity of the image image to blend. Must be between 0 and 1. /// The . - public static Image Blend(this Image source, Image image, PixelBlenderMode blender, float percent) + public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float percent) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -83,7 +81,7 @@ public static Image Blend(this Image source, ImageThe image to blend with the currently processing image. /// The options, including the blending type and belnding amount. /// The . - public static Image Blend(this Image source, Image image, GraphicsOptions options) + public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, GraphicsOptions options) where TPixel : struct, IPixel { return DrawImage(source, image, default(Size), default(Point), options); @@ -99,7 +97,7 @@ public static Image Blend(this Image source, ImageThe size to draw the blended image. /// The location to draw the blended image. /// The . - public static Image DrawImage(this Image source, Image image, float percent, Size size, Point location) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, float percent, Size size, Point location) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -118,7 +116,7 @@ public static Image DrawImage(this Image source, ImageThe size to draw the blended image. /// The location to draw the blended image. /// The . - public static Image DrawImage(this Image source, Image image, PixelBlenderMode blender, float percent, Size size, Point location) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float percent, Size size, Point location) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; diff --git a/src/ImageSharp.Drawing/FillRegion.cs b/src/ImageSharp.Drawing/FillRegion.cs index b3ee2ed996..2e5d311c6d 100644 --- a/src/ImageSharp.Drawing/FillRegion.cs +++ b/src/ImageSharp.Drawing/FillRegion.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using Drawing; - using Drawing.Brushes; - using Drawing.Processors; - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -23,10 +21,10 @@ public static partial class ImageExtensions /// The details how to fill the region of interest. /// The graphics options. /// The . - public static Image Fill(this Image source, IBrush brush, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, GraphicsOptions options) where TPixel : struct, IPixel { - return source.Apply(new FillProcessor(brush, options)); + return source.ApplyProcessor(new FillProcessor(brush, options)); } /// @@ -36,7 +34,7 @@ public static Image Fill(this Image source, IBrushThe image this method extends. /// The details how to fill the region of interest. /// The . - public static Image Fill(this Image source, IBrush brush) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush) where TPixel : struct, IPixel { return source.Fill(brush, GraphicsOptions.Default); @@ -49,7 +47,7 @@ public static Image Fill(this Image source, IBrushThe image this method extends. /// The color. /// The . - public static Image Fill(this Image source, TPixel color) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color)); @@ -64,10 +62,10 @@ public static Image Fill(this Image source, TPixel color /// The region. /// The graphics options. /// The . - public static Image Fill(this Image source, IBrush brush, Region region, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region, GraphicsOptions options) where TPixel : struct, IPixel { - return source.Apply(new FillRegionProcessor(brush, region, options)); + return source.ApplyProcessor(new FillRegionProcessor(brush, region, options)); } /// @@ -78,7 +76,7 @@ public static Image Fill(this Image source, IBrushThe brush. /// The region. /// The . - public static Image Fill(this Image source, IBrush brush, Region region) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region) where TPixel : struct, IPixel { return source.Fill(brush, region, GraphicsOptions.Default); @@ -93,7 +91,7 @@ public static Image Fill(this Image source, IBrushThe region. /// The options. /// The . - public static Image Fill(this Image source, TPixel color, Region region, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Region region, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), region, options); @@ -107,7 +105,7 @@ public static Image Fill(this Image source, TPixel color /// The color. /// The region. /// The . - public static Image Fill(this Image source, TPixel color, Region region) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Region region) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), region); diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj index 10562b08ca..f25b6eaf70 100644 --- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj +++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj @@ -3,18 +3,18 @@ An extension to ImageSharp that allows the drawing of images, paths, and text. ImageSharp.Drawing 1.0.0-alpha9 - James Jackson-South and contributors + Six Labor and contributors netstandard1.1 true true - ImageSharp.Drawing - ImageSharp.Drawing + SixLabors.ImageSharp.Drawing + SixLabors.ImageSharp.Drawing Image Draw Shape Path Font - https://raw.githubusercontent.com/JimBobSquarePants/ImageSharp/master/build/icons/imagesharp-logo-128.png - https://github.com/JimBobSquarePants/ImageSharp + https://raw.githubusercontent.com/SixLabor/ImageSharp/master/build/icons/imagesharp-logo-128.png + https://github.com/SixLabors/ImageSharp http://www.apache.org/licenses/LICENSE-2.0 git - https://github.com/JimBobSquarePants/ImageSharp + https://github.com/SixLabor/ImageSharp false false false @@ -30,19 +30,21 @@ - + - - + + + All ..\..\ImageSharp.ruleset + SixLabors.ImageSharp.Drawing true diff --git a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs b/src/ImageSharp.Drawing/Paths/DrawBeziers.cs index 59bcf40363..de4fdd003b 100644 --- a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs +++ b/src/ImageSharp.Drawing/Paths/DrawBeziers.cs @@ -1,18 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Numerics; - using Drawing; - using Drawing.Brushes; - using Drawing.Pens; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using SixLabors.Shapes; +using System.Numerics; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +using SixLabors.Shapes; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -28,7 +26,7 @@ public static partial class ImageExtensions /// The points. /// The options. /// The . - public static Image DrawBeziers(this Image source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)), options); @@ -43,7 +41,7 @@ public static Image DrawBeziers(this Image source, IBrus /// The thickness. /// The points. /// The . - public static Image DrawBeziers(this Image source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points))); @@ -58,7 +56,7 @@ public static Image DrawBeziers(this Image source, IBrus /// The thickness. /// The points. /// The . - public static Image DrawBeziers(this Image source, TPixel color, float thickness, PointF[] points) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawBeziers(new SolidBrush(color), thickness, points); @@ -74,7 +72,7 @@ public static Image DrawBeziers(this Image source, TPixe /// The points. /// The options. /// The . - public static Image DrawBeziers(this Image source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawBeziers(new SolidBrush(color), thickness, points, options); @@ -89,7 +87,7 @@ public static Image DrawBeziers(this Image source, TPixe /// The points. /// The options. /// The . - public static Image DrawBeziers(this Image source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new CubicBezierLineSegment(points)), options); @@ -103,7 +101,7 @@ public static Image DrawBeziers(this Image source, IPen< /// The pen. /// The points. /// The . - public static Image DrawBeziers(this Image source, IPen pen, PointF[] points) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new CubicBezierLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/DrawLines.cs b/src/ImageSharp.Drawing/Paths/DrawLines.cs index 3ce0dc4da6..e5d9a1b3b4 100644 --- a/src/ImageSharp.Drawing/Paths/DrawLines.cs +++ b/src/ImageSharp.Drawing/Paths/DrawLines.cs @@ -1,18 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Numerics; - using Drawing; - using Drawing.Brushes; - using Drawing.Pens; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using SixLabors.Shapes; +using System.Numerics; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +using SixLabors.Shapes; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -28,7 +26,7 @@ public static partial class ImageExtensions /// The points. /// The options. /// The . - public static Image DrawLines(this Image source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); @@ -43,7 +41,7 @@ public static Image DrawLines(this Image source, IBrush< /// The thickness. /// The points. /// The . - public static Image DrawLines(this Image source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points))); @@ -58,7 +56,7 @@ public static Image DrawLines(this Image source, IBrush< /// The thickness. /// The points. /// The . - public static Image DrawLines(this Image source, TPixel color, float thickness, PointF[] points) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawLines(new SolidBrush(color), thickness, points); @@ -74,7 +72,7 @@ public static Image DrawLines(this Image source, TPixel /// The points. /// The options. /// The .> - public static Image DrawLines(this Image source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawLines(new SolidBrush(color), thickness, points, options); @@ -89,7 +87,7 @@ public static Image DrawLines(this Image source, TPixel /// The points. /// The options. /// The . - public static Image DrawLines(this Image source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new LinearLineSegment(points)), options); @@ -103,7 +101,7 @@ public static Image DrawLines(this Image source, IPenThe pen. /// The points. /// The . - public static Image DrawLines(this Image source, IPen pen, PointF[] points) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new LinearLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/DrawPath.cs b/src/ImageSharp.Drawing/Paths/DrawPath.cs index 1fba06370d..b6c821a60b 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPath.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPath.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using Drawing; - using Drawing.Brushes; - using Drawing.Pens; - using ImageSharp.PixelFormats; - using SixLabors.Shapes; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Shapes; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -25,7 +23,7 @@ public static partial class ImageExtensions /// The path. /// The options. /// The . - public static Image Draw(this Image source, IPen pen, IPath path, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(pen.StrokeFill, new ShapePath(path, pen), options); @@ -39,7 +37,7 @@ public static Image Draw(this Image source, IPen /// The pen. /// The path. /// The . - public static Image Draw(this Image source, IPen pen, IPath path) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path) where TPixel : struct, IPixel { return source.Draw(pen, path, GraphicsOptions.Default); @@ -55,7 +53,7 @@ public static Image Draw(this Image source, IPen /// The shape. /// The options. /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, IPath path, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), path, options); @@ -70,7 +68,7 @@ public static Image Draw(this Image source, IBrushThe thickness. /// The path. /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, IPath path) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPath path) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), path); @@ -86,7 +84,7 @@ public static Image Draw(this Image source, IBrushThe path. /// The options. /// The . - public static Image Draw(this Image source, TPixel color, float thickness, IPath path, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, path, options); @@ -101,7 +99,7 @@ public static Image Draw(this Image source, TPixel color /// The thickness. /// The path. /// The . - public static Image Draw(this Image source, TPixel color, float thickness, IPath path) + public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPath path) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, path); diff --git a/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs b/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs index 877737653d..a126663b05 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using Drawing; - using Drawing.Brushes; - using Drawing.Pens; - using ImageSharp.PixelFormats; - using SixLabors.Shapes; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Shapes; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -25,7 +23,7 @@ public static partial class ImageExtensions /// The paths. /// The options. /// The . - public static Image Draw(this Image source, IPen pen, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { foreach (IPath path in paths) @@ -44,7 +42,7 @@ public static Image Draw(this Image source, IPen /// The pen. /// The paths. /// The . - public static Image Draw(this Image source, IPen pen, IPathCollection paths) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(pen, paths, GraphicsOptions.Default); @@ -60,7 +58,7 @@ public static Image Draw(this Image source, IPen /// The shapes. /// The options. /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), paths, options); @@ -75,7 +73,7 @@ public static Image Draw(this Image source, IBrushThe thickness. /// The paths. /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, IPathCollection paths) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), paths); @@ -91,7 +89,7 @@ public static Image Draw(this Image source, IBrushThe paths. /// The options. /// The . - public static Image Draw(this Image source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, paths, options); @@ -106,7 +104,7 @@ public static Image Draw(this Image source, TPixel color /// The thickness. /// The paths. /// The . - public static Image Draw(this Image source, TPixel color, float thickness, IPathCollection paths) + public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, paths); diff --git a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs b/src/ImageSharp.Drawing/Paths/DrawPolygon.cs index 4fa469a496..771ea9e616 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPolygon.cs @@ -1,18 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Numerics; - using Drawing; - using Drawing.Brushes; - using Drawing.Pens; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using SixLabors.Shapes; +using System.Numerics; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +using SixLabors.Shapes; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -28,7 +26,7 @@ public static partial class ImageExtensions /// The points. /// The options. /// The . - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); @@ -43,7 +41,7 @@ public static Image DrawPolygon(this Image source, IBrus /// The thickness. /// The points. /// The . - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); @@ -58,7 +56,7 @@ public static Image DrawPolygon(this Image source, IBrus /// The thickness. /// The points. /// The . - public static Image DrawPolygon(this Image source, TPixel color, float thickness, PointF[] points) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawPolygon(new SolidBrush(color), thickness, points); @@ -74,7 +72,7 @@ public static Image DrawPolygon(this Image source, TPixe /// The points. /// The options. /// The . - public static Image DrawPolygon(this Image source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawPolygon(new SolidBrush(color), thickness, points, options); @@ -88,7 +86,7 @@ public static Image DrawPolygon(this Image source, TPixe /// The pen. /// The points. /// The . - public static Image DrawPolygon(this Image source, IPen pen, PointF[] points) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default); @@ -103,7 +101,7 @@ public static Image DrawPolygon(this Image source, IPen< /// The points. /// The options. /// The . - public static Image DrawPolygon(this Image source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options); diff --git a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs b/src/ImageSharp.Drawing/Paths/DrawRectangle.cs index b3f0e6fc3b..6b98d1f8e9 100644 --- a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs +++ b/src/ImageSharp.Drawing/Paths/DrawRectangle.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using Drawing; - using Drawing.Brushes; - using Drawing.Pens; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -25,7 +23,7 @@ public static partial class ImageExtensions /// The shape. /// The options. /// The . - public static Image Draw(this Image source, IPen pen, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); @@ -39,7 +37,7 @@ public static Image Draw(this Image source, IPen /// The pen. /// The shape. /// The . - public static Image Draw(this Image source, IPen pen, RectangleF shape) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(pen, shape, GraphicsOptions.Default); @@ -55,7 +53,7 @@ public static Image Draw(this Image source, IPen /// The shape. /// The options. /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), shape, options); @@ -70,7 +68,7 @@ public static Image Draw(this Image source, IBrushThe thickness. /// The shape. /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, RectangleF shape) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), shape); @@ -86,7 +84,7 @@ public static Image Draw(this Image source, IBrushThe shape. /// The options. /// The . - public static Image Draw(this Image source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, shape, options); @@ -101,7 +99,7 @@ public static Image Draw(this Image source, TPixel color /// The thickness. /// The shape. /// The . - public static Image Draw(this Image source, TPixel color, float thickness, RectangleF shape) + public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, shape); diff --git a/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs b/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs index abb5ef73a7..fff082f2d9 100644 --- a/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs +++ b/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using Drawing; - using Drawing.Brushes; - using ImageSharp.PixelFormats; - using SixLabors.Shapes; +using System; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Shapes; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -25,7 +23,7 @@ public static partial class ImageExtensions /// The shape. /// The graphics options. /// The . - public static Image Fill(this Image source, IBrush brush, Action path, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Action path, GraphicsOptions options) where TPixel : struct, IPixel { var pb = new PathBuilder(); @@ -42,7 +40,7 @@ public static Image Fill(this Image source, IBrushThe brush. /// The path. /// The . - public static Image Fill(this Image source, IBrush brush, Action path) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Action path) where TPixel : struct, IPixel { return source.Fill(brush, path, GraphicsOptions.Default); @@ -57,7 +55,7 @@ public static Image Fill(this Image source, IBrushThe path. /// The options. /// The . - public static Image Fill(this Image source, TPixel color, Action path, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Action path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path, options); @@ -71,7 +69,7 @@ public static Image Fill(this Image source, TPixel color /// The color. /// The path. /// The . - public static Image Fill(this Image source, TPixel color, Action path) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Action path) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path); diff --git a/src/ImageSharp.Drawing/Paths/FillPathCollection.cs b/src/ImageSharp.Drawing/Paths/FillPathCollection.cs index 3ea9fb94b8..b252b95d5b 100644 --- a/src/ImageSharp.Drawing/Paths/FillPathCollection.cs +++ b/src/ImageSharp.Drawing/Paths/FillPathCollection.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using Drawing; - using Drawing.Brushes; - using ImageSharp.PixelFormats; - using SixLabors.Shapes; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Shapes; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,7 +22,7 @@ public static partial class ImageExtensions /// The shapes. /// The graphics options. /// The . - public static Image Fill(this Image source, IBrush brush, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { foreach (IPath s in paths) @@ -43,7 +41,7 @@ public static Image Fill(this Image source, IBrushThe brush. /// The paths. /// The . - public static Image Fill(this Image source, IBrush brush, IPathCollection paths) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPathCollection paths) where TPixel : struct, IPixel { return source.Fill(brush, paths, GraphicsOptions.Default); @@ -58,7 +56,7 @@ public static Image Fill(this Image source, IBrushThe paths. /// The options. /// The . - public static Image Fill(this Image source, TPixel color, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), paths, options); @@ -72,7 +70,7 @@ public static Image Fill(this Image source, TPixel color /// The color. /// The paths. /// The . - public static Image Fill(this Image source, TPixel color, IPathCollection paths) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPathCollection paths) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), paths); diff --git a/src/ImageSharp.Drawing/Paths/FillPaths.cs b/src/ImageSharp.Drawing/Paths/FillPaths.cs index f579c4ad02..f554ed7581 100644 --- a/src/ImageSharp.Drawing/Paths/FillPaths.cs +++ b/src/ImageSharp.Drawing/Paths/FillPaths.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using Drawing; - using Drawing.Brushes; - using ImageSharp.PixelFormats; - using SixLabors.Shapes; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Shapes; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,7 +22,7 @@ public static partial class ImageExtensions /// The shape. /// The graphics options. /// The . - public static Image Fill(this Image source, IBrush brush, IPath path, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new ShapeRegion(path), options); @@ -38,7 +36,7 @@ public static Image Fill(this Image source, IBrushThe brush. /// The path. /// The . - public static Image Fill(this Image source, IBrush brush, IPath path) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPath path) where TPixel : struct, IPixel { return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default); @@ -53,7 +51,7 @@ public static Image Fill(this Image source, IBrushThe path. /// The options. /// The . - public static Image Fill(this Image source, TPixel color, IPath path, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path, options); @@ -67,7 +65,7 @@ public static Image Fill(this Image source, TPixel color /// The color. /// The path. /// The . - public static Image Fill(this Image source, TPixel color, IPath path) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPath path) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path); diff --git a/src/ImageSharp.Drawing/Paths/FillPolygon.cs b/src/ImageSharp.Drawing/Paths/FillPolygon.cs index 6266d3bd64..d8723bc31f 100644 --- a/src/ImageSharp.Drawing/Paths/FillPolygon.cs +++ b/src/ImageSharp.Drawing/Paths/FillPolygon.cs @@ -1,18 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Numerics; - using Drawing; - using Drawing.Brushes; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using SixLabors.Shapes; +using System; +using System.Numerics; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +using SixLabors.Shapes; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -27,7 +25,7 @@ public static partial class ImageExtensions /// The points. /// The options. /// The . - public static Image FillPolygon(this Image source, IBrush brush, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, IBrush brush, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); @@ -41,7 +39,7 @@ public static Image FillPolygon(this Image source, IBrus /// The brush. /// The points. /// The . - public static Image FillPolygon(this Image source, IBrush brush, PointF[] points) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, IBrush brush, PointF[] points) where TPixel : struct, IPixel { return source.Fill(brush, new Polygon(new LinearLineSegment(points))); @@ -56,7 +54,7 @@ public static Image FillPolygon(this Image source, IBrus /// The points. /// The options. /// The . - public static Image FillPolygon(this Image source, TPixel color, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, TPixel color, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); @@ -70,7 +68,7 @@ public static Image FillPolygon(this Image source, TPixe /// The color. /// The points. /// The . - public static Image FillPolygon(this Image source, TPixel color, PointF[] points) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, TPixel color, PointF[] points) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/FillRectangle.cs b/src/ImageSharp.Drawing/Paths/FillRectangle.cs index bd6460cf90..52578de178 100644 --- a/src/ImageSharp.Drawing/Paths/FillRectangle.cs +++ b/src/ImageSharp.Drawing/Paths/FillRectangle.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using Drawing; - using Drawing.Brushes; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,7 +22,7 @@ public static partial class ImageExtensions /// The shape. /// The options. /// The . - public static Image Fill(this Image source, IBrush brush, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); @@ -38,7 +36,7 @@ public static Image Fill(this Image source, IBrushThe brush. /// The shape. /// The . - public static Image Fill(this Image source, IBrush brush, RectangleF shape) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, RectangleF shape) where TPixel : struct, IPixel { return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height)); @@ -53,7 +51,7 @@ public static Image Fill(this Image source, IBrushThe shape. /// The options. /// The . - public static Image Fill(this Image source, TPixel color, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), shape, options); @@ -67,7 +65,7 @@ public static Image Fill(this Image source, TPixel color /// The color. /// The shape. /// The . - public static Image Fill(this Image source, TPixel color, RectangleF shape) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, RectangleF shape) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), shape); diff --git a/src/ImageSharp.Drawing/Paths/ShapePath.cs b/src/ImageSharp.Drawing/Paths/ShapePath.cs index ec4f222e09..61f1291c45 100644 --- a/src/ImageSharp.Drawing/Paths/ShapePath.cs +++ b/src/ImageSharp.Drawing/Paths/ShapePath.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing -{ - using System; - using System.Buffers; - using System.Numerics; - - using SixLabors.Shapes; +using System; +using System.Buffers; +using System.Numerics; +using SixLabors.Shapes; +namespace SixLabors.ImageSharp.Drawing +{ /// /// A mapping between a and a region. /// diff --git a/src/ImageSharp.Drawing/Paths/ShapeRegion.cs b/src/ImageSharp.Drawing/Paths/ShapeRegion.cs index a7a72c4f3c..a303179e83 100644 --- a/src/ImageSharp.Drawing/Paths/ShapeRegion.cs +++ b/src/ImageSharp.Drawing/Paths/ShapeRegion.cs @@ -1,17 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing -{ - using System; - using System.Buffers; - using System.Numerics; - using ImageSharp.Memory; - using SixLabors.Primitives; - using SixLabors.Shapes; +using System; +using System.Buffers; +using System.Numerics; +using SixLabors.ImageSharp.Memory; +using SixLabors.Primitives; +using SixLabors.Shapes; +namespace SixLabors.ImageSharp.Drawing +{ /// /// A mapping between a and a region. /// diff --git a/src/ImageSharp.Drawing/Pens/IPen.cs b/src/ImageSharp.Drawing/Pens/IPen.cs index 20ac53dafc..3a87bbeb47 100644 --- a/src/ImageSharp.Drawing/Pens/IPen.cs +++ b/src/ImageSharp.Drawing/Pens/IPen.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing.Pens -{ - using ImageSharp.PixelFormats; - using Processors; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Drawing.Pens +{ /// /// Interface representing a Pen /// diff --git a/src/ImageSharp.Drawing/Pens/Pens.cs b/src/ImageSharp.Drawing/Pens/Pens.cs index 364115cb77..c90e1b8329 100644 --- a/src/ImageSharp.Drawing/Pens/Pens.cs +++ b/src/ImageSharp.Drawing/Pens/Pens.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing.Pens -{ - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Drawing.Pens +{ /// /// Common Pen styles /// diff --git a/src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs b/src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs index 37cfff9e93..74e4c6596d 100644 --- a/src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs +++ b/src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing.Pens -{ - using System; - using System.Numerics; - - using ImageSharp.Drawing.Brushes; - using ImageSharp.PixelFormats; - using Processors; +using System; +using System.Numerics; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Drawing.Pens +{ /// /// Provides a pen that can apply a pattern to a line with a set brush and thickness /// diff --git a/src/ImageSharp.Drawing/PointInfo.cs b/src/ImageSharp.Drawing/PointInfo.cs index 7eff24fac8..bdc1917a7b 100644 --- a/src/ImageSharp.Drawing/PointInfo.cs +++ b/src/ImageSharp.Drawing/PointInfo.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing +namespace SixLabors.ImageSharp.Drawing { /// /// Returns details about how far away from the inside of a shape and the color the pixel could be. diff --git a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs index 62344b1012..221cd9e39e 100644 --- a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs @@ -1,19 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Drawing.Processors +{ /// /// Combines two images together by blending the pixels. /// @@ -68,13 +65,13 @@ protected override void OnApply(ImageBase source, Rectangle sourceRectan try { - if (targetImage.Bounds.Size != this.Size) + if (targetImage.Size() != this.Size) { - targetImage = disposableImage = new Image(this.Image).Resize(this.Size.Width, this.Size.Height); + targetImage = disposableImage = this.Image.Clone(x => x.Resize(this.Size.Width, this.Size.Height)); } // Align start/end positions. - Rectangle bounds = this.Image.Bounds; + Rectangle bounds = this.Image.Bounds(); int minX = Math.Max(this.Location.X, sourceRectangle.X); int maxX = Math.Min(this.Location.X + bounds.Width, sourceRectangle.Width); maxX = Math.Min(this.Location.X + this.Size.Width, maxX); diff --git a/src/ImageSharp.Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processors/FillProcessor.cs index 6eb12cf488..66463b590d 100644 --- a/src/ImageSharp.Drawing/Processors/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/FillProcessor.cs @@ -1,21 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using Drawing; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Drawing.Processors +{ /// /// Using the bursh as a source of pixels colors blends the brush color with source. /// diff --git a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs index c398824323..7f7faa1111 100644 --- a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs @@ -1,20 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing.Processors -{ - using System; - using System.Buffers; - using System.Runtime.CompilerServices; - using Drawing; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - using SixLabors.Primitives; +using System; +using System.Buffers; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Drawing.Processors +{ /// /// Usinf a brsuh and a shape fills shape with contents of brush the /// diff --git a/src/ImageSharp.Drawing/Properties/AssemblyInfo.cs b/src/ImageSharp.Drawing/Properties/AssemblyInfo.cs index fba25a9dba..2891598b9b 100644 --- a/src/ImageSharp.Drawing/Properties/AssemblyInfo.cs +++ b/src/ImageSharp.Drawing/Properties/AssemblyInfo.cs @@ -1,6 +1,4 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// // Common values read from `AssemblyInfo.Common.cs` diff --git a/src/ImageSharp.Drawing/Region.cs b/src/ImageSharp.Drawing/Region.cs index 23028b9a8f..5d4d471f18 100644 --- a/src/ImageSharp.Drawing/Region.cs +++ b/src/ImageSharp.Drawing/Region.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing -{ - using System; - using SixLabors.Primitives; +using System; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Drawing +{ /// /// Represents a region of an image. /// diff --git a/src/ImageSharp.Drawing/Text/DrawText.Path.cs b/src/ImageSharp.Drawing/Text/DrawText.Path.cs index 523813188a..274b592058 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.Path.cs +++ b/src/ImageSharp.Drawing/Text/DrawText.Path.cs @@ -1,19 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Numerics; - - using Drawing; - using Drawing.Brushes; - using Drawing.Pens; - using ImageSharp.PixelFormats; - using SixLabors.Fonts; - using SixLabors.Shapes; +using System.Numerics; +using SixLabors.Fonts; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Shapes; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -31,7 +28,7 @@ public static partial class ImageExtensions /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, TPixel color, IPath path) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, color, path, TextGraphicsOptions.Default); @@ -50,7 +47,7 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, Brushes.Solid(color), null, path, options); @@ -68,7 +65,7 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPath path) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, path, TextGraphicsOptions.Default); @@ -87,7 +84,7 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPath path, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, null, path, options); @@ -105,7 +102,7 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IPen pen, IPath path) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, pen, path, TextGraphicsOptions.Default); @@ -124,7 +121,7 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IPen pen, IPath path, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, null, pen, path, options); @@ -143,7 +140,7 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPen pen, IPath path) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default); @@ -163,16 +160,11 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPen pen, IPath path, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { float dpiX = DefaultTextDpi; float dpiY = DefaultTextDpi; - if (options.UseImageResolution) - { - dpiX = (float)source.MetaData.HorizontalResolution; - dpiY = (float)source.MetaData.VerticalResolution; - } var style = new RendererOptions(font, dpiX, dpiY) { diff --git a/src/ImageSharp.Drawing/Text/DrawText.cs b/src/ImageSharp.Drawing/Text/DrawText.cs index 6352836a9c..c0105011e9 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.cs +++ b/src/ImageSharp.Drawing/Text/DrawText.cs @@ -1,20 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Numerics; - - using Drawing; - using Drawing.Brushes; - using Drawing.Pens; - using ImageSharp.PixelFormats; - using SixLabors.Fonts; - using SixLabors.Primitives; - using SixLabors.Shapes; +using System.Numerics; +using SixLabors.Fonts; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +using SixLabors.Shapes; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -34,7 +31,7 @@ public static partial class ImageExtensions /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, TPixel color, PointF location) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, color, location, TextGraphicsOptions.Default); @@ -53,7 +50,7 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, Brushes.Solid(color), null, location, options); @@ -71,7 +68,7 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, PointF location) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, location, TextGraphicsOptions.Default); @@ -90,7 +87,7 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, PointF location, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, null, location, options); @@ -108,7 +105,7 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IPen pen, PointF location) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, pen, location, TextGraphicsOptions.Default); @@ -127,7 +124,7 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IPen pen, PointF location, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, null, pen, location, options); @@ -146,7 +143,7 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPen pen, PointF location) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default); @@ -166,16 +163,11 @@ public static Image DrawText(this Image source, string t /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPen pen, PointF location, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { float dpiX = DefaultTextDpi; float dpiY = DefaultTextDpi; - if (options.UseImageResolution) - { - dpiX = (float)source.MetaData.HorizontalResolution; - dpiY = (float)source.MetaData.VerticalResolution; - } var style = new RendererOptions(font, dpiX, dpiY, location) { diff --git a/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs b/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs index 593ac36d4f..c230a8c79e 100644 --- a/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs +++ b/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Drawing -{ - using ImageSharp.PixelFormats; - using SixLabors.Fonts; +using SixLabors.Fonts; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Drawing +{ /// /// Options for influencing the drawing functions. /// @@ -29,8 +27,6 @@ public struct TextGraphicsOptions private PixelBlenderMode blenderMode; - private bool? useImageResolution; - private float wrapTextWidth; private SixLabors.Fonts.HorizontalAlignment? horizontalAlignment; @@ -44,7 +40,6 @@ public TextGraphicsOptions(bool enableAntialiasing) { this.applyKerning = true; this.tabWidth = 4; - this.useImageResolution = false; this.wrapTextWidth = 0; this.horizontalAlignment = HorizontalAlignment.Left; this.verticalAlignment = VerticalAlignment.Top; @@ -89,12 +84,6 @@ public TextGraphicsOptions(bool enableAntialiasing) /// public float TabWidth { get => this.tabWidth ?? 4; set => this.tabWidth = value; } - /// - /// Gets or sets a value indicating whether to use the current image resultion to for point size scaling. - /// If this is [false] the text renders at 72dpi otherwise it renders at Image resolution - /// - public bool UseImageResolution { get => this.useImageResolution ?? false; set => this.useImageResolution = value; } - /// /// Gets or sets a value indicating if greater than zero determine the width at which text should wrap. /// diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs new file mode 100644 index 0000000000..1788332755 --- /dev/null +++ b/src/ImageSharp/ApplyProcessors.cs @@ -0,0 +1,103 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; + +namespace SixLabors.ImageSharp +{ + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Mutates the source image by applying the image operation to it. + /// + /// The pixel format. + /// The image to mutate. + /// The operation to perform on the source. + public static void Mutate(this Image source, Action> operation) + where TPixel : struct, IPixel + { + Guard.NotNull(operation, nameof(operation)); + Guard.NotNull(source, nameof(source)); + + IInternalImageProcessingContext operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageProcessingContext(source, true); + operation(operationsRunner); + operationsRunner.Apply(); + } + + /// + /// Mutates the source image by applying the operations to it. + /// + /// The pixel format. + /// The image to mutate. + /// The operations to perform on the source. + public static void Mutate(this Image source, params IImageProcessor[] operations) + where TPixel : struct, IPixel + { + Guard.NotNull(operations, nameof(operations)); + Guard.NotNull(source, nameof(source)); + + IInternalImageProcessingContext operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageProcessingContext(source, true); + operationsRunner.ApplyProcessors(operations); + operationsRunner.Apply(); + } + + /// + /// Creates a deep clone of the current image. The clone is then mutated by the given operation. + /// + /// The pixel format. + /// The image to clone. + /// The operation to perform on the clone. + /// The new + public static Image Clone(this Image source, Action> operation) + where TPixel : struct, IPixel + { + Guard.NotNull(operation, nameof(operation)); + Guard.NotNull(source, nameof(source)); + + IInternalImageProcessingContext operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageProcessingContext(source, false); + operation(operationsRunner); + return operationsRunner.Apply(); + } + + /// + /// Creates a deep clone of the current image. The clone is then mutated by the given operations. + /// + /// The pixel format. + /// The image to clone. + /// The operations to perform on the clone. + /// The new + public static Image Clone(this Image source, params IImageProcessor[] operations) + where TPixel : struct, IPixel + { + Guard.NotNull(operations, nameof(operations)); + Guard.NotNull(source, nameof(source)); + + IInternalImageProcessingContext operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageProcessingContext(source, false); + operationsRunner.ApplyProcessors(operations); + return operationsRunner.Apply(); + } + + /// + /// Applies the given collection against the context + /// + /// The pixel format. + /// The image processing context. + /// The operations to perform on the source. + /// The to allow chaining of operations. + public static IImageProcessingContext ApplyProcessors(this IImageProcessingContext source, params IImageProcessor[] operations) + where TPixel : struct, IPixel + { + foreach (IImageProcessor p in operations) + { + source = source.ApplyProcessor(p); + } + + return source; + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs index d382bbedb0..107be4cb2b 100644 --- a/src/ImageSharp/ColorSpaces/CieLab.cs +++ b/src/ImageSharp/ColorSpaces/CieLab.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Represents a CIE L*a*b* 1976 color. /// diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs index 03cf80bf12..834ef56a89 100644 --- a/src/ImageSharp/ColorSpaces/CieLch.cs +++ b/src/ImageSharp/ColorSpaces/CieLch.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Represents the CIE L*C*h°, cylindrical form of the CIE L*a*b* 1976 color. /// diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs index a4e8b424d7..f35914d641 100644 --- a/src/ImageSharp/ColorSpaces/CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Represents the CIE L*C*h°, cylindrical form of the CIE L*u*v* 1976 color. /// diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs index c3fd626e67..9b52517083 100644 --- a/src/ImageSharp/ColorSpaces/CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLuv.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// The CIE 1976 (L*, u*, v*) color space, commonly known by its abbreviation CIELUV, is a color space adopted by the International /// Commission on Illumination (CIE) in 1976, as a simple-to-compute transformation of the 1931 CIE XYZ color space, but which diff --git a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs index d9bfe88cd7..d9767d45ea 100644 --- a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs +++ b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Represents the coordinates of CIEXY chromaticity space /// diff --git a/src/ImageSharp/ColorSpaces/CieXyy.cs b/src/ImageSharp/ColorSpaces/CieXyy.cs index 1578f1ac3e..d5ef4b15d3 100644 --- a/src/ImageSharp/ColorSpaces/CieXyy.cs +++ b/src/ImageSharp/ColorSpaces/CieXyy.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Represents an CIE xyY 1931 color /// diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs index 8d3255e65d..908408000a 100644 --- a/src/ImageSharp/ColorSpaces/CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/CieXyz.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Represents an CIE XYZ 1931 color /// diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs index eeaef21bd5..2a58a5762a 100644 --- a/src/ImageSharp/ColorSpaces/Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Cmyk.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Represents an CMYK (cyan, magenta, yellow, keyline) color. /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/CieConstants.cs b/src/ImageSharp/ColorSpaces/Conversion/CieConstants.cs index 29200823e2..2bcdc5127f 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/CieConstants.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/CieConstants.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion +namespace SixLabors.ImageSharp.ColorSpaces.Conversion { /// /// Constants use for Cie conversion calculations diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs index acdb356a22..80f9e6789b 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using System; - - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion.Implementation.Rgb; +using System; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Performs chromatic adaptation on the various color spaces. /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs index 2c274c17a7..9268f3a70c 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion.Implementation.CieLab; - using ImageSharp.ColorSpaces.Conversion.Implementation.CieLch; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLabColorSapce; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs index e3b3975a4e..13dae4b174 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces.Conversion.Implementation.CieLch; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs index 7f2d184803..cef63e73d2 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuv; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuvColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs index dc63e7a67c..04aee4897b 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuv; - using ImageSharp.ColorSpaces.Conversion.Implementation.CieLuv; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuvColorSapce; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLuvColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs index 6c4b6ca533..31e1e218ea 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces.Conversion.Implementation.CieXyy; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieXyyColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs index ca8b31d03d..e6847beafe 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion.Implementation.CieLab; - using ImageSharp.ColorSpaces.Conversion.Implementation.CieLuv; - using ImageSharp.ColorSpaces.Conversion.Implementation.HunterLab; - using ImageSharp.ColorSpaces.Conversion.Implementation.Rgb; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLabColorSapce; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLuvColorSapce; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HunterLabColorSapce; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs index 9cfa8f0c3d..637c121ea0 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion.Implementation.Cmyk; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CmykColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs index 9e4a8d9c34..dbc31c52b8 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion.Implementation.Hsl; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HslColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs index 80b235894b..640461505b 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion.Implementation.Hsv; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HsvColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs index b6d9d4cb98..f5ab4d645c 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces.Conversion.Implementation.HunterLab; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HunterLabColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs index 5fcc2cd5e7..7b45704afc 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces.Conversion.Implementation.Rgb; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs index 8d888182f9..ac3adee639 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs index 1cfd565e80..de13b97eb8 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces.Conversion.Implementation.Rgb; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs index 6660f579a4..8da7dcb7ef 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion.Implementation.YCbCr; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.YCbCrColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Allows conversion to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs index a52207cb44..f86f505387 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using System.Numerics; - - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion.Implementation.Lms; +using System.Numerics; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.LmsColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Converts between color spaces ensuring that the color is adapted using chromatic adaptation. /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/IChromaticAdaptation.cs b/src/ImageSharp/ColorSpaces/Conversion/IChromaticAdaptation.cs index aead65e590..c5d91f9a05 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/IChromaticAdaptation.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/IChromaticAdaptation.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Chromatic adaptation. /// A linear transformation of a source color (XS, YS, ZS) into a destination color (XD, YD, ZD) by a linear transformation [M] diff --git a/src/ImageSharp/ColorSpaces/Conversion/IColorConversion.cs b/src/ImageSharp/ColorSpaces/Conversion/IColorConversion.cs index 920fba18fa..9ef24b38af 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/IColorConversion.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/IColorConversion.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion +namespace SixLabors.ImageSharp.ColorSpaces.Conversion { /// /// Converts color between two color spaces. diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieLabToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieLabToCieXyzConverter.cs index 71b1596cac..75689d997c 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieLabToCieXyzConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieLabToCieXyzConverter.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.CieLab -{ - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLabColorSapce +{ /// /// Converts from to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieXyzToCieLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieXyzToCieLabConverter.cs index 8d877503a2..33a8dc7c8d 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieXyzToCieLabConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieXyzToCieLabConverter.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.CieLab -{ - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLabColorSapce +{ /// /// Converts from to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CIeLchToCieLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CIeLchToCieLabConverter.cs index 5b63b167e7..3884d9480a 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CIeLchToCieLabConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CIeLchToCieLabConverter.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.CieLch -{ - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchColorSapce +{ /// /// Converts from to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CieLabToCieLchConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CieLabToCieLchConverter.cs index b93dce75a3..50332ebdcf 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CieLabToCieLchConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CieLabToCieLchConverter.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.CieLch -{ - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchColorSapce +{ /// /// Converts from to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLchuvToCieLuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLchuvToCieLuvConverter.cs index 3e399016a9..ceadb01957 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLchuvToCieLuvConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLchuvToCieLuvConverter.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuv -{ - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuvColorSapce +{ /// /// Converts from to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLuvToCieLchuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLuvToCieLchuvConverter.cs index 5339f1bcda..d301519208 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLuvToCieLchuvConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLuvToCieLchuvConverter.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuv -{ - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuvColorSapce +{ /// /// Converts from to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieLuvToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieLuvToCieXyzConverter.cs index 36c458828d..4fb8fdc809 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieLuvToCieXyzConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieLuvToCieXyzConverter.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.CieLuv -{ - using System.Runtime.CompilerServices; - using ImageSharp.ColorSpaces; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLuvColorSapce +{ /// /// Converts from to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieXyzToCieLuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieXyzToCieLuvConverter.cs index 3883f3a1ec..82b1b1d3f7 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieXyzToCieLuvConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieXyzToCieLuvConverter.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.CieLuv -{ - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLuvColorSapce +{ /// /// Converts from to . /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyy/CieXyzAndCieXyyConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyy/CieXyzAndCieXyyConverter.cs index dc4a5ccf4a..31868ec11a 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyy/CieXyzAndCieXyyConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyy/CieXyzAndCieXyyConverter.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.CieXyy -{ - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieXyyColorSapce +{ /// /// Color converter between CIE XYZ and CIE xyY /// for formulas. diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Cmyk/CmykAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Cmyk/CmykAndRgbConverter.cs index b50e89b18c..404bc811ff 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Cmyk/CmykAndRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Cmyk/CmykAndRgbConverter.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Cmyk -{ - using System; - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CmykColorSapce +{ /// /// Color converter between CMYK and Rgb /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsl/HslAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsl/HslAndRgbConverter.cs index 6c72cf294a..917cd3bf8a 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsl/HslAndRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsl/HslAndRgbConverter.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Hsl -{ - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HslColorSapce +{ /// /// Color converter between HSL and Rgb /// See for formulas. diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsv/HsvAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsv/HsvAndRgbConverter.cs index 54c8e405f0..6219533ca5 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsv/HsvAndRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsv/HsvAndRgbConverter.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Hsv -{ - using System; - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HsvColorSapce +{ /// /// Color converter between HSV and Rgb /// See for formulas. diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzAndHunterLabConverterBase.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzAndHunterLabConverterBase.cs index 19fc78e9a2..85b0efd16a 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzAndHunterLabConverterBase.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzAndHunterLabConverterBase.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.HunterLab -{ - using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HunterLabColorSapce +{ /// /// The base class for converting between and color spaces. /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzToHunterLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzToHunterLabConverter.cs index 7f2df8336e..8905a0a30f 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzToHunterLabConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzToHunterLabConverter.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.HunterLab -{ - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HunterLabColorSapce +{ /// /// Color converter between CieXyz and HunterLab /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/HunterLabToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/HunterLabToCieXyzConverter.cs index af7f4f3708..2cd379d853 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/HunterLabToCieXyzConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/HunterLabToCieXyzConverter.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.HunterLab -{ - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HunterLabColorSapce +{ /// /// Color converter between HunterLab and CieXyz /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Lms/CieXyzAndLmsConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Lms/CieXyzAndLmsConverter.cs index c856c7ff74..780c9e5a6e 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Lms/CieXyzAndLmsConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Lms/CieXyzAndLmsConverter.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Lms -{ - using System.Numerics; - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.LmsColorSapce +{ /// /// Color converter between CIE XYZ and LMS /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Lms/LmsAdaptationMatrix.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Lms/LmsAdaptationMatrix.cs index 279044baa7..1bd0c4ad50 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Lms/LmsAdaptationMatrix.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Lms/LmsAdaptationMatrix.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// + +using System.Numerics; // ReSharper disable InconsistentNaming -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Lms +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.LmsColorSapce { - using System.Numerics; - /// /// AdaptionMatrix3X3 used for transformation from XYZ to LMS, defining the cone response domain. /// Used in diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/CieXyzToLinearRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/CieXyzToLinearRgbConverter.cs index c5c6124091..fd76a30fb8 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/CieXyzToLinearRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/CieXyzToLinearRgbConverter.cs @@ -1,14 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Rgb -{ - using System.Numerics; - - using Rgb = ImageSharp.ColorSpaces.Rgb; +using System.Numerics; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce +{ /// /// Color converter between CieXyz and LinearRgb /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/GammaCompanding.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/GammaCompanding.cs index 08200ce6bd..21a80225ee 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/GammaCompanding.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/GammaCompanding.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Rgb -{ - using System; - using System.Runtime.CompilerServices; +using System; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce +{ /// /// Implements gamma companding /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LCompanding.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LCompanding.cs index bbf12ca005..c73a3486ed 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LCompanding.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LCompanding.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Rgb -{ - using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce +{ /// /// Implements L* companding /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbAndCieXyzConverterBase.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbAndCieXyzConverterBase.cs index 4c46e4d8c7..2ec79b353b 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbAndCieXyzConverterBase.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbAndCieXyzConverterBase.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Rgb -{ - using System.Numerics; +using System.Numerics; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce +{ /// /// Provides base methods for converting between Rgb and CieXyz color spaces. /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToCieXyzConverter.cs index 4a04185e84..19d4130373 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToCieXyzConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToCieXyzConverter.cs @@ -1,14 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Rgb -{ - using System.Numerics; - - using Rgb = ImageSharp.ColorSpaces.Rgb; +using System.Numerics; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce +{ /// /// Color converter between LinearRgb and CieXyz /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToRgbConverter.cs index cf4638ae71..29ea0f3148 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToRgbConverter.cs @@ -1,14 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Rgb -{ - using System.Numerics; - - using Rgb = ColorSpaces.Rgb; +using System.Numerics; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce +{ /// /// Color converter between LinearRgb and Rgb /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RGBPrimariesChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RGBPrimariesChromaticityCoordinates.cs index 0148b91d5f..d279aba850 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RGBPrimariesChromaticityCoordinates.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RGBPrimariesChromaticityCoordinates.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Rgb -{ - using System; +using System; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce +{ /// /// Represents the chromaticity coordinates of RGB primaries. /// One of the specifiers of . diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec2020Companding.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec2020Companding.cs index 630faedcae..f393b133ce 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec2020Companding.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec2020Companding.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Rgb -{ - using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce +{ /// /// Implements Rec. 2020 companding function (for 12-bits). /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec709Companding.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec709Companding.cs index 24dd6ca17b..ba1b1379ef 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec709Companding.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec709Companding.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Rgb -{ - using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce +{ /// /// Implements the Rec. 709 companding function /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbToLinearRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbToLinearRgbConverter.cs index 0d0d588288..e40ecc192e 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbToLinearRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbToLinearRgbConverter.cs @@ -1,14 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Rgb -{ - using System.Numerics; - - using Rgb = ColorSpaces.Rgb; +using System.Numerics; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce +{ /// /// Color converter between Rgb and LinearRgb /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs index 89e403e761..8a2c66a80c 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Rgb +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce { /// /// Trivial implementation of diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/SRgbCompanding.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/SRgbCompanding.cs index 18ec94c51d..1e49c11591 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/SRgbCompanding.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/SRgbCompanding.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.Rgb -{ - using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce +{ /// /// Implements sRGB companding /// diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/YCbCr/YCbCrAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/YCbCr/YCbCrAndRgbConverter.cs index e58da580d7..f552acbb48 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/YCbCr/YCbCrAndRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/YCbCr/YCbCrAndRgbConverter.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion.Implementation.YCbCr -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; - - using ImageSharp.ColorSpaces; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.YCbCrColorSapce +{ /// /// Color converter between YCbCr and Rgb /// See for formulas. diff --git a/src/ImageSharp/ColorSpaces/Conversion/VonKriesChromaticAdaptation.cs b/src/ImageSharp/ColorSpaces/Conversion/VonKriesChromaticAdaptation.cs index 55d1d65a3c..6edae93017 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/VonKriesChromaticAdaptation.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/VonKriesChromaticAdaptation.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces.Conversion -{ - using System.Numerics; - - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion.Implementation.Lms; +using System.Numerics; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.LmsColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces.Conversion +{ /// /// Basic implementation of the von Kries chromatic adaptation model /// diff --git a/src/ImageSharp/ColorSpaces/Hsl.cs b/src/ImageSharp/ColorSpaces/Hsl.cs index 5bbbeec308..cf880f1548 100644 --- a/src/ImageSharp/ColorSpaces/Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Hsl.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Represents a Hsl (hue, saturation, lightness) color. /// diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs index dcbb73692b..9f47393792 100644 --- a/src/ImageSharp/ColorSpaces/Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Hsv.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Represents a HSV (hue, saturation, value) color. Also known as HSB (hue, saturation, brightness). /// diff --git a/src/ImageSharp/ColorSpaces/HunterLab.cs b/src/ImageSharp/ColorSpaces/HunterLab.cs index 2b49ee944d..b5ba7c86c7 100644 --- a/src/ImageSharp/ColorSpaces/HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/HunterLab.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Represents an Hunter LAB color. /// diff --git a/src/ImageSharp/ColorSpaces/IAlmostEquatable.cs b/src/ImageSharp/ColorSpaces/IAlmostEquatable.cs index a67eaeb064..3f62f75acb 100644 --- a/src/ImageSharp/ColorSpaces/IAlmostEquatable.cs +++ b/src/ImageSharp/ColorSpaces/IAlmostEquatable.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; +using System; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Defines a generalized method that a value type or class implements to create /// a type-specific method for determining approximate equality of instances. diff --git a/src/ImageSharp/ColorSpaces/IColorVector.cs b/src/ImageSharp/ColorSpaces/IColorVector.cs index 08b70e4829..3903e1c098 100644 --- a/src/ImageSharp/ColorSpaces/IColorVector.cs +++ b/src/ImageSharp/ColorSpaces/IColorVector.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System.Numerics; +using System.Numerics; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Color represented as a vector in its color space /// diff --git a/src/ImageSharp/ColorSpaces/ICompanding.cs b/src/ImageSharp/ColorSpaces/ICompanding.cs index e4f0e4a4c2..2dfa575ed9 100644 --- a/src/ImageSharp/ColorSpaces/ICompanding.cs +++ b/src/ImageSharp/ColorSpaces/ICompanding.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces +namespace SixLabors.ImageSharp.ColorSpaces { /// /// Pair of companding functions for . diff --git a/src/ImageSharp/ColorSpaces/IRgbWorkingSpace.cs b/src/ImageSharp/ColorSpaces/IRgbWorkingSpace.cs index 2360854349..156e94ed3c 100644 --- a/src/ImageSharp/ColorSpaces/IRgbWorkingSpace.cs +++ b/src/ImageSharp/ColorSpaces/IRgbWorkingSpace.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - - using ImageSharp.ColorSpaces.Conversion.Implementation.Rgb; +using System; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Encasulates the RGB working color space /// diff --git a/src/ImageSharp/ColorSpaces/Illuminants.cs b/src/ImageSharp/ColorSpaces/Illuminants.cs index 224cf99392..85c4063bf4 100644 --- a/src/ImageSharp/ColorSpaces/Illuminants.cs +++ b/src/ImageSharp/ColorSpaces/Illuminants.cs @@ -1,4 +1,7 @@ -namespace ImageSharp.ColorSpaces +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.ImageSharp.ColorSpaces { /// /// The well known standard illuminants. diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs index fdfc0d2660..07889c3529 100644 --- a/src/ImageSharp/ColorSpaces/LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Represents an linear Rgb color with specified working space /// diff --git a/src/ImageSharp/ColorSpaces/Lms.cs b/src/ImageSharp/ColorSpaces/Lms.cs index c76d87253c..82c291de3d 100644 --- a/src/ImageSharp/ColorSpaces/Lms.cs +++ b/src/ImageSharp/ColorSpaces/Lms.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// LMS is a color space represented by the response of the three types of cones of the human eye, /// named after their responsivity (sensitivity) at long, medium and short wavelengths. diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs index 898c81730a..8ac8411b20 100644 --- a/src/ImageSharp/ColorSpaces/Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Rgb.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Represents an RGB color with specified working space /// diff --git a/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs b/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs index 20b9373948..098ca9a4a4 100644 --- a/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs +++ b/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// + +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce; // ReSharper disable InconsistentNaming -namespace ImageSharp.ColorSpaces +namespace SixLabors.ImageSharp.ColorSpaces { - using ImageSharp.ColorSpaces.Conversion.Implementation.Rgb; - /// /// Chromaticity coordinates taken from: /// diff --git a/src/ImageSharp/ColorSpaces/YCbCr.cs b/src/ImageSharp/ColorSpaces/YCbCr.cs index cbba023056..708a74308a 100644 --- a/src/ImageSharp/ColorSpaces/YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/YCbCr.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.ColorSpaces -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.ColorSpaces +{ /// /// Represents an YCbCr (luminance, blue chroma, red chroma) color as defined in the ITU-T T.871 specification for the JFIF use with Jpeg. /// diff --git a/src/ImageSharp/Common/Constants.cs b/src/ImageSharp/Common/Constants.cs index cf43951bc5..41f2bce247 100644 --- a/src/ImageSharp/Common/Constants.cs +++ b/src/ImageSharp/Common/Constants.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Common constants used throughout the project diff --git a/src/ImageSharp/Common/Exceptions/ImageFormatException.cs b/src/ImageSharp/Common/Exceptions/ImageFormatException.cs index 32a0854359..7a91756b62 100644 --- a/src/ImageSharp/Common/Exceptions/ImageFormatException.cs +++ b/src/ImageSharp/Common/Exceptions/ImageFormatException.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// The exception that is thrown when the library tries to load /// an image, which has an invalid format. diff --git a/src/ImageSharp/Common/Exceptions/ImageProcessingException.cs b/src/ImageSharp/Common/Exceptions/ImageProcessingException.cs index ef84a1e393..eb50d0b654 100644 --- a/src/ImageSharp/Common/Exceptions/ImageProcessingException.cs +++ b/src/ImageSharp/Common/Exceptions/ImageProcessingException.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// The exception that is thrown when an error occurs when applying a process to an image. /// diff --git a/src/ImageSharp/Common/Extensions/ByteExtensions.cs b/src/ImageSharp/Common/Extensions/ByteExtensions.cs index f1161eb6f6..f6c7207950 100644 --- a/src/ImageSharp/Common/Extensions/ByteExtensions.cs +++ b/src/ImageSharp/Common/Extensions/ByteExtensions.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Runtime.CompilerServices; - - using ImageSharp.PixelFormats; +using System; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the struct buffers. /// diff --git a/src/ImageSharp/Common/Extensions/ComparableExtensions.cs b/src/ImageSharp/Common/Extensions/ComparableExtensions.cs index d463301025..8bebb3de79 100644 --- a/src/ImageSharp/Common/Extensions/ComparableExtensions.cs +++ b/src/ImageSharp/Common/Extensions/ComparableExtensions.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Runtime.CompilerServices; +using System; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for classes that implement . /// diff --git a/src/ImageSharp/Common/Extensions/EnumerableExtensions.cs b/src/ImageSharp/Common/Extensions/EnumerableExtensions.cs index af8e50c7be..f20f1a63e0 100644 --- a/src/ImageSharp/Common/Extensions/EnumerableExtensions.cs +++ b/src/ImageSharp/Common/Extensions/EnumerableExtensions.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Collections.Generic; +using System; +using System.Collections.Generic; +namespace SixLabors.ImageSharp +{ /// /// Encapsulates a series of time saving extension methods to the interface. /// diff --git a/src/ImageSharp/Common/Extensions/ListExtensions.cs b/src/ImageSharp/Common/Extensions/ListExtensions.cs new file mode 100644 index 0000000000..2713896c02 --- /dev/null +++ b/src/ImageSharp/Common/Extensions/ListExtensions.cs @@ -0,0 +1,46 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Collections.Generic; + +namespace SixLabors.ImageSharp.Common.Extensions +{ + /// + /// Encapsulates a series of time saving extension methods to the class. + /// + internal static class ListExtensions + { + /// + /// Inserts an item at the given index automatically expanding the capacity if required. + /// + /// The type of object within the list + /// The list + /// The index + /// The item to insert + public static void SafeInsert(this List list, int index, T item) + { + if (index >= list.Count) + { + list.Add(item); + } + else + { + list[index] = item; + } + } + + /// + /// Removes the last element from a list and returns that element. This method changes the length of the list. + /// + /// The type of object within the list + /// The list + /// The last element in the specified sequence. + public static T Pop(this List list) + { + int last = list.Count - 1; + T item = list[last]; + list.RemoveAt(last); + return item; + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Common/Extensions/StreamExtensions.cs b/src/ImageSharp/Common/Extensions/StreamExtensions.cs index 6de94dd229..d8fd45440a 100644 --- a/src/ImageSharp/Common/Extensions/StreamExtensions.cs +++ b/src/ImageSharp/Common/Extensions/StreamExtensions.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Buffers; - using System.IO; +using System.Buffers; +using System.IO; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -27,7 +25,7 @@ public static void Skip(this Stream stream, int count) if (stream.CanSeek) { - stream.Position += count; + stream.Seek(count, SeekOrigin.Current); // Position += count; } else { diff --git a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs index fac33da140..5fbc3960a3 100644 --- a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs +++ b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Numerics; - using System.Runtime.CompilerServices; - using ImageSharp.PixelFormats; +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the struct. /// diff --git a/src/ImageSharp/Common/Helpers/DebugGuard.cs b/src/ImageSharp/Common/Helpers/DebugGuard.cs index f6941fc6fc..dc3cff7a2b 100644 --- a/src/ImageSharp/Common/Helpers/DebugGuard.cs +++ b/src/ImageSharp/Common/Helpers/DebugGuard.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Diagnostics; +using System; +using System.Diagnostics; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to protect against invalid parameters for a DEBUG build. /// diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs index 8e55c18af8..b0546bf9a9 100644 --- a/src/ImageSharp/Common/Helpers/Guard.cs +++ b/src/ImageSharp/Common/Helpers/Guard.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.Linq; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to protect against invalid parameters. /// diff --git a/src/ImageSharp/Common/Helpers/ImageMaths.cs b/src/ImageSharp/Common/Helpers/ImageMaths.cs index 367aa12d00..8cf220b300 100644 --- a/src/ImageSharp/Common/Helpers/ImageMaths.cs +++ b/src/ImageSharp/Common/Helpers/ImageMaths.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; - using System.Numerics; - using System.Runtime.CompilerServices; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Linq; +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Provides common mathematical methods. /// diff --git a/src/ImageSharp/Common/Helpers/MathF.cs b/src/ImageSharp/Common/Helpers/MathF.cs index 5ce5b5d5dd..7d2f8063fa 100644 --- a/src/ImageSharp/Common/Helpers/MathF.cs +++ b/src/ImageSharp/Common/Helpers/MathF.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Runtime.CompilerServices; +using System; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp +{ /// /// Provides single-precision floating point constants and static methods for trigonometric, logarithmic, and other common mathematical functions. /// diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index a9322467cb..8e70c77164 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -1,19 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Collections.Concurrent; - using System.Collections.Generic; - using System.Linq; - using System.Threading.Tasks; - - using Formats; - using ImageSharp.IO; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.IO; +namespace SixLabors.ImageSharp +{ /// /// Provides initialization code which allows extending the library. /// @@ -103,11 +100,16 @@ public Configuration(params IConfigurationModule[] configurationModules) #if !NETSTANDARD1_1 /// - /// Gets or sets the fielsystem helper for accessing the local file system. + /// Gets or sets the filesystem helper for accessing the local file system. /// internal IFileSystem FileSystem { get; set; } = new LocalFileSystem(); #endif + /// + /// Gets or sets the image operations provider factory. + /// + internal IImageProcessingContextFactory ImageOperationsProvider { get; set; } = new DefaultImageOperationsProviderFactory(); + /// /// Registers a new format provider. /// @@ -121,7 +123,7 @@ public void Configure(IConfigurationModule configuration) /// /// Registers a new format provider. /// - /// The format to register as a well know format. + /// The format to register as a known format. public void AddImageFormat(IImageFormat format) { Guard.NotNull(format, nameof(format)); @@ -135,7 +137,7 @@ public void AddImageFormat(IImageFormat format) /// /// The extension to discover /// The if found otherwise null - public IImageFormat FindFormatByFileExtensions(string extension) + public IImageFormat FindFormatByFileExtension(string extension) { return this.imageFormats.FirstOrDefault(x => x.FileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase)); } @@ -144,7 +146,7 @@ public IImageFormat FindFormatByFileExtensions(string extension) /// For the specified mime type find the . /// /// The mime-type to discover - /// The if found otherwise null + /// The if found; otherwise null public IImageFormat FindFormatByMimeType(string mimeType) { return this.imageFormats.FirstOrDefault(x => x.MimeTypes.Contains(mimeType, StringComparer.OrdinalIgnoreCase)); diff --git a/src/ImageSharp/DefaultInternalImageProcessorContext.cs b/src/ImageSharp/DefaultInternalImageProcessorContext.cs new file mode 100644 index 0000000000..8eb1c09fee --- /dev/null +++ b/src/ImageSharp/DefaultInternalImageProcessorContext.cs @@ -0,0 +1,76 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp +{ + /// + /// Performs processor application operations on the source image + /// + /// The pixel format + internal class DefaultInternalImageProcessorContext : IInternalImageProcessingContext + where TPixel : struct, IPixel + { + private readonly bool mutate; + private readonly Image source; + private Image destination; + + /// + /// Initializes a new instance of the class. + /// + /// The image. + /// The mutate. + public DefaultInternalImageProcessorContext(Image source, bool mutate) + { + this.mutate = mutate; + this.source = source; + if (this.mutate) + { + this.destination = source; + } + } + + /// + public Image Apply() + { + if (!this.mutate && this.destination == null) + { + // Ensure we have cloned it if we are not mutating as we might have failed to register any processors + this.destination = this.source.Clone(); + } + + return this.destination; + } + + /// + public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + { + if (!this.mutate && this.destination == null) + { + // This will only work if the first processor applied is the cloning one thus + // realistically for this optermissation to work the resize must the first processor + // applied any only up processors will take the douple data path. + var cloningImageProcessor = processor as ICloningImageProcessor; + if (cloningImageProcessor != null) + { + this.destination = cloningImageProcessor.CloneAndApply(this.source, rectangle); + return this; + } + + this.destination = this.source.Clone(); + } + + processor.Apply(this.destination, rectangle); + return this; + } + + /// + public IImageProcessingContext ApplyProcessor(IImageProcessor processor) + { + return this.ApplyProcessor(processor, this.source.Bounds()); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs index 629944ea15..dc15cdcd35 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering -{ - using ImageSharp.Memory; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp.Dithering +{ /// /// Applies error diffusion based dithering using the Atkinson image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs index 02d41c369e..66697aab76 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering -{ - using ImageSharp.Memory; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp.Dithering +{ /// /// Applies error diffusion based dithering using the Burks image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs b/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs index 408e6c383e..8d05bfcb64 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Dithering +{ /// /// The base class for performing error diffusion based dithering. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs b/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs index 6165da6344..5422d83bb8 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering -{ - using ImageSharp.Memory; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp.Dithering +{ /// /// Applies error diffusion based dithering using the Floyd–Steinberg image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs b/src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs index bc785e8971..57eea6b921 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering -{ - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Dithering +{ /// /// Encapsulates properties and methods required to perfom diffused error dithering on an image. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs b/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs index 6daeab32f7..637240a124 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering -{ - using ImageSharp.Memory; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp.Dithering +{ /// /// Applies error diffusion based dithering using the JarvisJudiceNinke image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs index 0c0944d0eb..db37b45afc 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering -{ - using ImageSharp.Memory; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp.Dithering +{ /// /// Applies error diffusion based dithering using the Sierra2 image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs index 2e22208462..f812fcdc30 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering -{ - using ImageSharp.Memory; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp.Dithering +{ /// /// Applies error diffusion based dithering using the Sierra3 image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs b/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs index fe4c933a9f..98af7b432b 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering -{ - using ImageSharp.Memory; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp.Dithering +{ /// /// Applies error diffusion based dithering using the SierraLite image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs index b04c164814..2f94639be8 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering -{ - using ImageSharp.Memory; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp.Dithering +{ /// /// Applies error diffusion based dithering using the Stucki image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/Ordered/Bayer.cs b/src/ImageSharp/Dithering/Ordered/Bayer.cs index ded17d1e10..cfbdb0888a 100644 --- a/src/ImageSharp/Dithering/Ordered/Bayer.cs +++ b/src/ImageSharp/Dithering/Ordered/Bayer.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering.Ordered -{ - using ImageSharp.Memory; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp.Dithering.Ordered +{ /// /// Applies error diffusion based dithering using the 4x4 Bayer dithering matrix. /// diff --git a/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs b/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs index c69cddefed..fbd51a2539 100644 --- a/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs +++ b/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering -{ - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Dithering +{ /// /// Encapsulates properties and methods required to perfom ordered dithering on an image. /// diff --git a/src/ImageSharp/Dithering/Ordered/Ordered.cs b/src/ImageSharp/Dithering/Ordered/Ordered.cs index 1fd39eb8ba..4b559c4e12 100644 --- a/src/ImageSharp/Dithering/Ordered/Ordered.cs +++ b/src/ImageSharp/Dithering/Ordered/Ordered.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering.Ordered -{ - using ImageSharp.Memory; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp.Dithering.Ordered +{ /// /// Applies error diffusion based dithering using the 4x4 ordered dithering matrix. /// diff --git a/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs b/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs index a180888f70..94292b7b51 100644 --- a/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs +++ b/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Dithering.Ordered -{ - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Dithering.Ordered +{ /// /// The base class for performing ordered ditheroing using a 4x4 matrix. /// diff --git a/src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs b/src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs index 330326acfc..5ea9baa164 100644 --- a/src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs +++ b/src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Enumerates the available bits per pixel for bitmap. diff --git a/src/ImageSharp/Formats/Bmp/BmpCompression.cs b/src/ImageSharp/Formats/Bmp/BmpCompression.cs index a9246d449e..e2a73639d1 100644 --- a/src/ImageSharp/Formats/Bmp/BmpCompression.cs +++ b/src/ImageSharp/Formats/Bmp/BmpCompression.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Defines how the compression type of the image data diff --git a/src/ImageSharp/Formats/Bmp/BmpConfigurationModule.cs b/src/ImageSharp/Formats/Bmp/BmpConfigurationModule.cs index f70ff1a56d..46340fa85f 100644 --- a/src/ImageSharp/Formats/Bmp/BmpConfigurationModule.cs +++ b/src/ImageSharp/Formats/Bmp/BmpConfigurationModule.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Registers the image encoders, decoders and mime type detectors for the bmp format. diff --git a/src/ImageSharp/Formats/Bmp/BmpConstants.cs b/src/ImageSharp/Formats/Bmp/BmpConstants.cs index d394b61f6e..15187e9691 100644 --- a/src/ImageSharp/Formats/Bmp/BmpConstants.cs +++ b/src/ImageSharp/Formats/Bmp/BmpConstants.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System.Collections.Generic; +using System.Collections.Generic; +namespace SixLabors.ImageSharp.Formats +{ /// /// Defines constants relating to BMPs /// diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs index 5baf1b1a5a..1b015f8e64 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Image decoder for generating an image out of a Windows bitmap stream. /// diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 817d00f7e7..f26476222f 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.IO; - using System.Runtime.CompilerServices; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.IO; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Performs the bmp decoding operation. /// diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs index dfba0b41c0..a0db29d7a0 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Image encoder for writing an image to a stream as a Windows bitmap. /// diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index e41c295012..67754a175a 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.IO; - - using ImageSharp.PixelFormats; - - using IO; +using System; +using System.IO; +using SixLabors.ImageSharp.IO; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Image encoder for writing an image to a stream as a Windows bitmap. /// diff --git a/src/ImageSharp/Formats/Bmp/BmpFileHeader.cs b/src/ImageSharp/Formats/Bmp/BmpFileHeader.cs index f9b20a48f8..7fe8cd458b 100644 --- a/src/ImageSharp/Formats/Bmp/BmpFileHeader.cs +++ b/src/ImageSharp/Formats/Bmp/BmpFileHeader.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Stores general information about the Bitmap file. diff --git a/src/ImageSharp/Formats/Bmp/BmpFormat.cs b/src/ImageSharp/Formats/Bmp/BmpFormat.cs index bd25eb9b75..447bf6cb0b 100644 --- a/src/ImageSharp/Formats/Bmp/BmpFormat.cs +++ b/src/ImageSharp/Formats/Bmp/BmpFormat.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System.Collections.Generic; +using System.Collections.Generic; +namespace SixLabors.ImageSharp.Formats +{ /// /// Registers the image encoders, decoders and mime type detectors for the bmp format. /// diff --git a/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs b/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs index 697ee0f981..6bd1f9d289 100644 --- a/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; +using System; +namespace SixLabors.ImageSharp.Formats +{ /// /// Detects bmp file headers /// diff --git a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs index dc6a489d34..d5c9213131 100644 --- a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs +++ b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs @@ -1,8 +1,6 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// This block of bytes tells the application detailed information diff --git a/src/ImageSharp/Formats/Bmp/IBmpDecoderOptions.cs b/src/ImageSharp/Formats/Bmp/IBmpDecoderOptions.cs index 9285b9cf7a..08b47c0e1c 100644 --- a/src/ImageSharp/Formats/Bmp/IBmpDecoderOptions.cs +++ b/src/ImageSharp/Formats/Bmp/IBmpDecoderOptions.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Image decoder options for decoding Windows bitmap streams. /// diff --git a/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs b/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs index dd17043fad..c89b2b25c0 100644 --- a/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs +++ b/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Configuration options for use during bmp encoding /// diff --git a/src/ImageSharp/Formats/Bmp/ImageExtensions.cs b/src/ImageSharp/Formats/Bmp/ImageExtensions.cs index aba24f9997..d80abb51e3 100644 --- a/src/ImageSharp/Formats/Bmp/ImageExtensions.cs +++ b/src/ImageSharp/Formats/Bmp/ImageExtensions.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.IO; - - using Formats; - - using ImageSharp.PixelFormats; +using System; +using System.IO; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,11 +20,20 @@ public static partial class ImageExtensions /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsBmp(this Image source, Stream stream) + public static void SaveAsBmp(this Image source, Stream stream) + where TPixel : struct, IPixel + => source.SaveAsBmp(stream, null); + + /// + /// Saves the image to the given stream with the bmp format. + /// + /// The pixel format. + /// The image this method extends. + /// The stream to save the image to. + /// The encoder to save the image with. + /// Thrown if the stream is null. + public static void SaveAsBmp(this Image source, Stream stream, BmpEncoder encoder) where TPixel : struct, IPixel - => source.Save(stream, new BmpEncoder()); + => source.Save(stream, encoder ?? source.Configuration.FindEncoder(ImageFormats.Bitmap)); } } diff --git a/src/ImageSharp/Formats/Gif/DisposalMethod.cs b/src/ImageSharp/Formats/Gif/DisposalMethod.cs index 80b5f3c6e7..94cf820882 100644 --- a/src/ImageSharp/Formats/Gif/DisposalMethod.cs +++ b/src/ImageSharp/Formats/Gif/DisposalMethod.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Provides enumeration for instructing the decoder what to do with the last image diff --git a/src/ImageSharp/Formats/Gif/GifConfigurationModule.cs b/src/ImageSharp/Formats/Gif/GifConfigurationModule.cs index ee134d66cd..676363bbeb 100644 --- a/src/ImageSharp/Formats/Gif/GifConfigurationModule.cs +++ b/src/ImageSharp/Formats/Gif/GifConfigurationModule.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Registers the image encoders, decoders and mime type detectors for the gif format. diff --git a/src/ImageSharp/Formats/Gif/GifConstants.cs b/src/ImageSharp/Formats/Gif/GifConstants.cs index 9bec6c48f9..e65d33c72c 100644 --- a/src/ImageSharp/Formats/Gif/GifConstants.cs +++ b/src/ImageSharp/Formats/Gif/GifConstants.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System.Collections.Generic; - using System.Text; +using System.Collections.Generic; +using System.Text; +namespace SixLabors.ImageSharp.Formats +{ /// /// Constants that define specific points within a gif. /// diff --git a/src/ImageSharp/Formats/Gif/GifDecoder.cs b/src/ImageSharp/Formats/Gif/GifDecoder.cs index 927289094f..9322cec8d0 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoder.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoder.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Text; - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Decoder for generating an image out of a gif encoded stream. /// diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index 948103fed2..1547046582 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -1,19 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Buffers; - using System.IO; - using System.Runtime.CompilerServices; - using System.Text; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Buffers; +using System.IO; +using System.Runtime.CompilerServices; +using System.Text; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Formats +{ /// /// Performs the gif decoding operation. /// diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs index b48db56356..2dde83d9fe 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoder.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs @@ -1,17 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Text; - using ImageSharp.PixelFormats; - using ImageSharp.Quantizers; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Quantizers; +namespace SixLabors.ImageSharp.Formats +{ /// /// Image encoder for writing image data to a stream in gif format. /// diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 81b3cfba4a..8105c695db 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -1,20 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Buffers; - using System.IO; - using System.Linq; - using System.Text; - using ImageSharp.PixelFormats; - - using IO; - using Quantizers; +using System; +using System.Buffers; +using System.IO; +using System.Linq; +using System.Text; +using SixLabors.ImageSharp.IO; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Quantizers; +namespace SixLabors.ImageSharp.Formats +{ /// /// Performs the gif encoding operation. /// diff --git a/src/ImageSharp/Formats/Gif/GifFormat.cs b/src/ImageSharp/Formats/Gif/GifFormat.cs index 744aadff9a..887081fc7a 100644 --- a/src/ImageSharp/Formats/Gif/GifFormat.cs +++ b/src/ImageSharp/Formats/Gif/GifFormat.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System.Collections.Generic; +using System.Collections.Generic; +namespace SixLabors.ImageSharp.Formats +{ /// /// Registers the image encoders, decoders and mime type detectors for the gif format. /// diff --git a/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs b/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs index 04fcfc516c..7f908ad983 100644 --- a/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; +using System; +namespace SixLabors.ImageSharp.Formats +{ /// /// Detects gif file headers /// diff --git a/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs b/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs index caaa8932bb..c5ba972de6 100644 --- a/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs +++ b/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Text; - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Decoder for generating an image out of a gif encoded stream. /// diff --git a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs index c38ec7e451..1b8cf166e8 100644 --- a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs +++ b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs @@ -1,17 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Text; - using ImageSharp.PixelFormats; - using ImageSharp.Quantizers; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Quantizers; +namespace SixLabors.ImageSharp.Formats +{ /// /// The configuration options used for encoding gifs /// diff --git a/src/ImageSharp/Formats/Gif/ImageExtensions.cs b/src/ImageSharp/Formats/Gif/ImageExtensions.cs index ea9c9b5047..cfdd544c71 100644 --- a/src/ImageSharp/Formats/Gif/ImageExtensions.cs +++ b/src/ImageSharp/Formats/Gif/ImageExtensions.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.IO; - - using Formats; - - using ImageSharp.PixelFormats; +using System; +using System.IO; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,14 +20,9 @@ public static partial class ImageExtensions /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsGif(this Image source, Stream stream) + public static void SaveAsGif(this Image source, Stream stream) where TPixel : struct, IPixel - { - return SaveAsGif(source, stream, null); - } + => source.SaveAsGif(stream, null); /// /// Saves the image to the given stream with the gif format. @@ -41,16 +32,8 @@ public static Image SaveAsGif(this Image source, Stream /// The stream to save the image to. /// The options for the encoder. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsGif(this Image source, Stream stream, GifEncoder encoder) + public static void SaveAsGif(this Image source, Stream stream, GifEncoder encoder) where TPixel : struct, IPixel - { - encoder = encoder ?? new GifEncoder(); - encoder.Encode(source, stream); - - return source; - } + => source.Save(stream, encoder ?? source.Configuration.FindEncoder(ImageFormats.Gif)); } } diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs index bc0e9717c6..fcc50fe5c4 100644 --- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Buffers; - using System.IO; +using System; +using System.Buffers; +using System.IO; +namespace SixLabors.ImageSharp.Formats +{ /// /// Decompresses and decodes data using the dynamic LZW algorithms. /// diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs index 69419444ff..e7865f9137 100644 --- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Buffers; - using System.IO; +using System; +using System.Buffers; +using System.IO; +namespace SixLabors.ImageSharp.Formats +{ /// /// Encodes and compresses the image data using dynamic Lempel-Ziv compression. /// diff --git a/src/ImageSharp/Formats/Gif/PackedField.cs b/src/ImageSharp/Formats/Gif/PackedField.cs index 21d8f91f29..d0489a13c7 100644 --- a/src/ImageSharp/Formats/Gif/PackedField.cs +++ b/src/ImageSharp/Formats/Gif/PackedField.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; +using System; +namespace SixLabors.ImageSharp.Formats +{ /// /// Represents a byte of data in a GIF data stream which contains a number /// of data items. diff --git a/src/ImageSharp/Formats/Gif/Sections/GifGraphicsControlExtension.cs b/src/ImageSharp/Formats/Gif/Sections/GifGraphicsControlExtension.cs index 503bd4fdf7..13a1fb6a8f 100644 --- a/src/ImageSharp/Formats/Gif/Sections/GifGraphicsControlExtension.cs +++ b/src/ImageSharp/Formats/Gif/Sections/GifGraphicsControlExtension.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// The Graphic Control Extension contains parameters used when diff --git a/src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs b/src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs index 12c13beaf0..8765c9deaf 100644 --- a/src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs +++ b/src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Each image in the Data Stream is composed of an Image Descriptor, diff --git a/src/ImageSharp/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs b/src/ImageSharp/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs index fc2cc974aa..28983fa3f7 100644 --- a/src/ImageSharp/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs +++ b/src/ImageSharp/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// The Logical Screen Descriptor contains the parameters diff --git a/src/ImageSharp/Formats/IImageDecoder.cs b/src/ImageSharp/Formats/IImageDecoder.cs index 66eabb1b82..86d5f5375b 100644 --- a/src/ImageSharp/Formats/IImageDecoder.cs +++ b/src/ImageSharp/Formats/IImageDecoder.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Encapsulates properties and methods required for decoding an image from a stream. /// diff --git a/src/ImageSharp/Formats/IImageEncoder.cs b/src/ImageSharp/Formats/IImageEncoder.cs index 4ad41ebc27..ac0b6e3119 100644 --- a/src/ImageSharp/Formats/IImageEncoder.cs +++ b/src/ImageSharp/Formats/IImageEncoder.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Encapsulates properties and methods required for encoding an image to a stream. /// diff --git a/src/ImageSharp/Formats/IImageFormat.cs b/src/ImageSharp/Formats/IImageFormat.cs index d6ddc0b0bb..15bdc73a84 100644 --- a/src/ImageSharp/Formats/IImageFormat.cs +++ b/src/ImageSharp/Formats/IImageFormat.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System.Collections.Generic; +using System.Collections.Generic; +namespace SixLabors.ImageSharp.Formats +{ /// /// Describes an image format. /// diff --git a/src/ImageSharp/Formats/IImageFormatDetector.cs b/src/ImageSharp/Formats/IImageFormatDetector.cs index a53da07e8b..8266439bdc 100644 --- a/src/ImageSharp/Formats/IImageFormatDetector.cs +++ b/src/ImageSharp/Formats/IImageFormatDetector.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.Text; +using System; +using System.Collections.Generic; +using System.Text; +namespace SixLabors.ImageSharp.Formats +{ /// /// Used for detecting mime types from a file header /// diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs b/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.Generated.cs similarity index 95% rename from src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs rename to src/ImageSharp/Formats/Jpeg/Common/Block8x8F.Generated.cs index f84dc977f1..19d07fc3f4 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.Generated.cs @@ -1,11 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// + // ReSharper disable InconsistentNaming // #pragma warning disable -namespace ImageSharp.Formats.Jpg +namespace SixLabors.ImageSharp.Formats.Jpeg.Common { using System.Numerics; using System.Runtime.CompilerServices; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt b/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.Generated.tt similarity index 98% rename from src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt rename to src/ImageSharp/Formats/Jpeg/Common/Block8x8F.Generated.tt index 03566acbbc..e5d5cbe156 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt +++ b/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.Generated.tt @@ -14,7 +14,7 @@ <# char[] coordz = {'X', 'Y', 'Z', 'W'}; #> -namespace ImageSharp.Formats.Jpg +namespace ImageSharp.Formats.Jpeg.Common { using System.Numerics; using System.Runtime.CompilerServices; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs similarity index 97% rename from src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs rename to src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs index 130b5856c0..7e381c0a97 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs @@ -1,16 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// + +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Utils; + // ReSharper disable InconsistentNaming -namespace ImageSharp.Formats.Jpg +namespace SixLabors.ImageSharp.Formats.Jpeg.Common { - using System; - using System.Buffers; - using System.Numerics; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - /// /// DCT code Ported from https://github.com/norishigefukushima/dct_simd /// diff --git a/src/ImageSharp/Formats/Jpeg/UnzigData.cs b/src/ImageSharp/Formats/Jpeg/Common/UnzigData.cs similarity index 88% rename from src/ImageSharp/Formats/Jpeg/UnzigData.cs rename to src/ImageSharp/Formats/Jpeg/Common/UnzigData.cs index e74dd5c73c..d781238278 100644 --- a/src/ImageSharp/Formats/Jpeg/UnzigData.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/UnzigData.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Runtime.InteropServices; +using System; +using System.Runtime.InteropServices; +namespace SixLabors.ImageSharp.Formats +{ /// /// Holds the Jpeg UnZig array in a value/stack type. /// Unzig maps from the zigzag ordering to the natural ordering. For example, diff --git a/src/ImageSharp/Formats/Jpeg/Components/BlockQuad.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/BlockQuad.cs similarity index 60% rename from src/ImageSharp/Formats/Jpeg/Components/BlockQuad.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/BlockQuad.cs index 63453da21a..4f1b8783a5 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/BlockQuad.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/BlockQuad.cs @@ -1,17 +1,18 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg.Components + +using Block8x8F = SixLabors.ImageSharp.Formats.Jpeg.Common.Block8x8F; + +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components { /// - /// Poor man's stackalloc: Contains a value-type buffer sized for 4 instances. + /// Poor man's stackalloc: Contains a value-type buffer sized for 4 instances. /// Useful for decoder/encoder operations allocating a block for each Jpeg component. /// internal unsafe struct BlockQuad { /// - /// The value-type buffer sized for 4 instances. + /// The value-type buffer sized for 4 instances. /// public fixed float Data[4 * Block8x8F.ScalarCount]; } diff --git a/src/ImageSharp/Formats/Jpeg/Components/DCT.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/DCT.cs similarity index 97% rename from src/ImageSharp/Formats/Jpeg/Components/DCT.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/DCT.cs index 5729fe46d6..881ef511da 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/DCT.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/DCT.cs @@ -1,14 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -// ReSharper disable InconsistentNaming -namespace ImageSharp.Formats.Jpg -{ - using System.Numerics; - using System.Runtime.CompilerServices; +using System.Numerics; +using System.Runtime.CompilerServices; +using Block8x8F = SixLabors.ImageSharp.Formats.Jpeg.Common.Block8x8F; +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components +{ /// /// Contains forward and inverse DCT implementations /// diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/Bits.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bits.cs similarity index 71% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/Bits.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bits.cs index 02f585be02..4aa72bf83e 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/Bits.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bits.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// Holds the unprocessed bits that have been taken from the byte-stream. /// The n least significant bits of a form the unread bits, to be read in MSB to @@ -40,7 +38,7 @@ internal struct Bits [MethodImpl(MethodImplOptions.AggressiveInlining)] public void EnsureNBits(int n, ref InputProcessor inputProcessor) { - DecoderErrorCode errorCode = this.EnsureNBitsUnsafe(n, ref inputProcessor); + OldDecoderErrorCode errorCode = this.EnsureNBitsUnsafe(n, ref inputProcessor); errorCode.EnsureNoError(); } @@ -48,17 +46,17 @@ public void EnsureNBits(int n, ref InputProcessor inputProcessor) /// Reads bytes from the byte buffer to ensure that bits.UnreadBits is at /// least n. For best performance (avoiding function calls inside hot loops), /// the caller is the one responsible for first checking that bits.UnreadBits < n. - /// This method does not throw. Returns instead. + /// This method does not throw. Returns instead. /// /// The number of bits to ensure. /// The /// Error code - public DecoderErrorCode EnsureNBitsUnsafe(int n, ref InputProcessor inputProcessor) + public OldDecoderErrorCode EnsureNBitsUnsafe(int n, ref InputProcessor inputProcessor) { while (true) { - DecoderErrorCode errorCode = this.EnsureBitsStepImpl(ref inputProcessor); - if (errorCode != DecoderErrorCode.NoError || this.UnreadBits >= n) + OldDecoderErrorCode errorCode = this.EnsureBitsStepImpl(ref inputProcessor); + if (errorCode != OldDecoderErrorCode.NoError || this.UnreadBits >= n) { return errorCode; } @@ -69,8 +67,8 @@ public DecoderErrorCode EnsureNBitsUnsafe(int n, ref InputProcessor inputProcess /// Unrolled version of for n==8 /// /// The - /// A - public DecoderErrorCode Ensure8BitsUnsafe(ref InputProcessor inputProcessor) + /// A + public OldDecoderErrorCode Ensure8BitsUnsafe(ref InputProcessor inputProcessor) { return this.EnsureBitsStepImpl(ref inputProcessor); } @@ -79,8 +77,8 @@ public DecoderErrorCode Ensure8BitsUnsafe(ref InputProcessor inputProcessor) /// Unrolled version of for n==1 /// /// The - /// A - public DecoderErrorCode Ensure1BitUnsafe(ref InputProcessor inputProcessor) + /// A + public OldDecoderErrorCode Ensure1BitUnsafe(ref InputProcessor inputProcessor) { return this.EnsureBitsStepImpl(ref inputProcessor); } @@ -95,7 +93,7 @@ public DecoderErrorCode Ensure1BitUnsafe(ref InputProcessor inputProcessor) public int ReceiveExtend(int t, ref InputProcessor inputProcessor) { int x; - DecoderErrorCode errorCode = this.ReceiveExtendUnsafe(t, ref inputProcessor, out x); + OldDecoderErrorCode errorCode = this.ReceiveExtendUnsafe(t, ref inputProcessor, out x); errorCode.EnsureNoError(); return x; } @@ -106,13 +104,13 @@ public int ReceiveExtend(int t, ref InputProcessor inputProcessor) /// Byte /// The /// Read bits value - /// The - public DecoderErrorCode ReceiveExtendUnsafe(int t, ref InputProcessor inputProcessor, out int x) + /// The + public OldDecoderErrorCode ReceiveExtendUnsafe(int t, ref InputProcessor inputProcessor, out int x) { if (this.UnreadBits < t) { - DecoderErrorCode errorCode = this.EnsureNBitsUnsafe(t, ref inputProcessor); - if (errorCode != DecoderErrorCode.NoError) + OldDecoderErrorCode errorCode = this.EnsureNBitsUnsafe(t, ref inputProcessor); + if (errorCode != OldDecoderErrorCode.NoError) { x = int.MaxValue; return errorCode; @@ -129,15 +127,15 @@ public DecoderErrorCode ReceiveExtendUnsafe(int t, ref InputProcessor inputProce x += ((-1) << t) + 1; } - return DecoderErrorCode.NoError; + return OldDecoderErrorCode.NoError; } - private DecoderErrorCode EnsureBitsStepImpl(ref InputProcessor inputProcessor) + private OldDecoderErrorCode EnsureBitsStepImpl(ref InputProcessor inputProcessor) { int c; - DecoderErrorCode errorCode = inputProcessor.Bytes.ReadByteStuffedByteUnsafe(inputProcessor.InputStream, out c); + OldDecoderErrorCode errorCode = inputProcessor.Bytes.ReadByteStuffedByteUnsafe(inputProcessor.InputStream, out c); - if (errorCode != DecoderErrorCode.NoError) + if (errorCode != OldDecoderErrorCode.NoError) { return errorCode; } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/Bytes.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs similarity index 76% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/Bytes.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs index 0e57e98d89..a64f10fe57 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/Bytes.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs @@ -1,14 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System; - using System.Buffers; - using System.IO; - using System.Runtime.CompilerServices; +using System; +using System.Buffers; +using System.IO; +using System.Runtime.CompilerServices; + +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// Bytes is a byte buffer, similar to a stream, except that it /// has to be able to unread more than 1 byte, due to byte stuffing. @@ -86,8 +85,8 @@ public void Dispose() /// /// Input stream /// The result byte as - /// The - public DecoderErrorCode ReadByteStuffedByteUnsafe(Stream inputStream, out int x) + /// The + public OldDecoderErrorCode ReadByteStuffedByteUnsafe(Stream inputStream, out int x) { // Take the fast path if bytes.buf contains at least two bytes. if (this.I + 2 <= this.J) @@ -95,50 +94,50 @@ public DecoderErrorCode ReadByteStuffedByteUnsafe(Stream inputStream, out int x) x = this.BufferAsInt[this.I]; this.I++; this.UnreadableBytes = 1; - if (x != JpegConstants.Markers.XFFInt) + if (x != OldJpegConstants.Markers.XFFInt) { - return DecoderErrorCode.NoError; + return OldDecoderErrorCode.NoError; } if (this.BufferAsInt[this.I] != 0x00) { - return DecoderErrorCode.MissingFF00; + return OldDecoderErrorCode.MissingFF00; } this.I++; this.UnreadableBytes = 2; - x = JpegConstants.Markers.XFF; - return DecoderErrorCode.NoError; + x = OldJpegConstants.Markers.XFF; + return OldDecoderErrorCode.NoError; } this.UnreadableBytes = 0; - DecoderErrorCode errorCode = this.ReadByteAsIntUnsafe(inputStream, out x); + OldDecoderErrorCode errorCode = this.ReadByteAsIntUnsafe(inputStream, out x); this.UnreadableBytes = 1; - if (errorCode != DecoderErrorCode.NoError) + if (errorCode != OldDecoderErrorCode.NoError) { return errorCode; } - if (x != JpegConstants.Markers.XFF) + if (x != OldJpegConstants.Markers.XFF) { - return DecoderErrorCode.NoError; + return OldDecoderErrorCode.NoError; } errorCode = this.ReadByteAsIntUnsafe(inputStream, out x); this.UnreadableBytes = 2; - if (errorCode != DecoderErrorCode.NoError) + if (errorCode != OldDecoderErrorCode.NoError) { return errorCode; } if (x != 0x00) { - return DecoderErrorCode.MissingFF00; + return OldDecoderErrorCode.MissingFF00; } - x = JpegConstants.Markers.XFF; - return DecoderErrorCode.NoError; + x = OldJpegConstants.Markers.XFF; + return OldDecoderErrorCode.NoError; } /// @@ -150,25 +149,25 @@ public DecoderErrorCode ReadByteStuffedByteUnsafe(Stream inputStream, out int x) public byte ReadByte(Stream inputStream) { byte result; - DecoderErrorCode errorCode = this.ReadByteUnsafe(inputStream, out result); + OldDecoderErrorCode errorCode = this.ReadByteUnsafe(inputStream, out result); errorCode.EnsureNoError(); return result; } /// /// Extracts the next byte, whether buffered or not buffered into the result out parameter. It does not care about byte stuffing. - /// This method does not throw on format error, it returns a instead. + /// This method does not throw on format error, it returns a instead. /// /// Input stream /// The result as out parameter - /// The - public DecoderErrorCode ReadByteUnsafe(Stream inputStream, out byte result) + /// The + public OldDecoderErrorCode ReadByteUnsafe(Stream inputStream, out byte result) { - DecoderErrorCode errorCode = DecoderErrorCode.NoError; + OldDecoderErrorCode errorCode = OldDecoderErrorCode.NoError; while (this.I == this.J) { errorCode = this.FillUnsafe(inputStream); - if (errorCode != DecoderErrorCode.NoError) + if (errorCode != OldDecoderErrorCode.NoError) { result = 0; return errorCode; @@ -186,15 +185,15 @@ public DecoderErrorCode ReadByteUnsafe(Stream inputStream, out byte result) /// /// The input stream /// The result - /// A + /// A [MethodImpl(MethodImplOptions.AggressiveInlining)] - public DecoderErrorCode ReadByteAsIntUnsafe(Stream inputStream, out int result) + public OldDecoderErrorCode ReadByteAsIntUnsafe(Stream inputStream, out int result) { - DecoderErrorCode errorCode = DecoderErrorCode.NoError; + OldDecoderErrorCode errorCode = OldDecoderErrorCode.NoError; while (this.I == this.J) { errorCode = this.FillUnsafe(inputStream); - if (errorCode != DecoderErrorCode.NoError) + if (errorCode != OldDecoderErrorCode.NoError) { result = 0; return errorCode; @@ -216,18 +215,18 @@ public DecoderErrorCode ReadByteAsIntUnsafe(Stream inputStream, out int result) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Fill(Stream inputStream) { - DecoderErrorCode errorCode = this.FillUnsafe(inputStream); + OldDecoderErrorCode errorCode = this.FillUnsafe(inputStream); errorCode.EnsureNoError(); } /// /// Fills up the bytes buffer from the underlying stream. /// It should only be called when there are no unread bytes in bytes. - /// This method does not throw , returns a instead! + /// This method does not throw , returns a instead! /// /// Input stream - /// The - public DecoderErrorCode FillUnsafe(Stream inputStream) + /// The + public OldDecoderErrorCode FillUnsafe(Stream inputStream) { if (this.I != this.J) { @@ -249,7 +248,7 @@ public DecoderErrorCode FillUnsafe(Stream inputStream) int n = inputStream.Read(this.Buffer, this.J, this.Buffer.Length - this.J); if (n == 0) { - return DecoderErrorCode.UnexpectedEndOfStream; + return OldDecoderErrorCode.UnexpectedEndOfStream; } this.J += n; @@ -259,7 +258,7 @@ public DecoderErrorCode FillUnsafe(Stream inputStream) this.BufferAsInt[i] = this.Buffer[i]; } - return DecoderErrorCode.NoError; + return OldDecoderErrorCode.NoError; } } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/DecodedBlock.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecodedBlock.cs similarity index 89% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/DecodedBlock.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecodedBlock.cs index 900d77ec46..504c1174ff 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/DecodedBlock.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecodedBlock.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System; +using Block8x8F = SixLabors.ImageSharp.Formats.Jpeg.Common.Block8x8F; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// A structure to store unprocessed instances and their coordinates while scanning the image. /// The is present in a "raw" decoded frequency-domain form. diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/DecoderThrowHelper.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecoderThrowHelper.cs similarity index 65% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/DecoderThrowHelper.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecoderThrowHelper.cs index 9ce5ea4146..29d3c97039 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/DecoderThrowHelper.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecoderThrowHelper.cs @@ -1,32 +1,30 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System; - using System.Runtime.CompilerServices; +using System; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// Encapsulates exception thrower methods for the Jpeg Encoder /// internal static class DecoderThrowHelper { /// - /// Throws an exception that belongs to the given + /// Throws an exception that belongs to the given /// - /// The + /// The [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowExceptionForErrorCode(this DecoderErrorCode errorCode) + public static void ThrowExceptionForErrorCode(this OldDecoderErrorCode errorCode) { switch (errorCode) { - case DecoderErrorCode.NoError: + case OldDecoderErrorCode.NoError: throw new ArgumentException("ThrowExceptionForErrorCode() called with NoError!", nameof(errorCode)); - case DecoderErrorCode.MissingFF00: + case OldDecoderErrorCode.MissingFF00: throw new MissingFF00Exception(); - case DecoderErrorCode.UnexpectedEndOfStream: + case OldDecoderErrorCode.UnexpectedEndOfStream: throw new EOFException(); default: throw new ArgumentOutOfRangeException(nameof(errorCode), errorCode, null); @@ -34,26 +32,26 @@ public static void ThrowExceptionForErrorCode(this DecoderErrorCode errorCode) } /// - /// Throws an exception if the given defines an error. + /// Throws an exception if the given defines an error. /// - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void EnsureNoError(this DecoderErrorCode errorCode) + public static void EnsureNoError(this OldDecoderErrorCode errorCode) { - if (errorCode != DecoderErrorCode.NoError) + if (errorCode != OldDecoderErrorCode.NoError) { ThrowExceptionForErrorCode(errorCode); } } /// - /// Throws an exception if the given is . + /// Throws an exception if the given is . /// - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void EnsureNoEOF(this DecoderErrorCode errorCode) + public static void EnsureNoEOF(this OldDecoderErrorCode errorCode) { - if (errorCode == DecoderErrorCode.UnexpectedEndOfStream) + if (errorCode == OldDecoderErrorCode.UnexpectedEndOfStream) { errorCode.ThrowExceptionForErrorCode(); } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/EOFException.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/EOFException.cs similarity index 75% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/EOFException.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/EOFException.cs index 5ed25ef049..60d9b1e1af 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/EOFException.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/EOFException.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System; +using System; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// The EOF (End of File exception). /// Thrown when the decoder encounters an EOF marker without a proceeding EOI (End Of Image) marker diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/InputProcessor.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs similarity index 78% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/InputProcessor.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs index 60042d36f8..8f39aa5425 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/InputProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System; - using System.IO; - using System.Runtime.CompilerServices; +using System; +using System.IO; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// - /// Encapsulates stream reading and processing data and operations for . + /// Encapsulates stream reading and processing data and operations for . /// It's a value type for imporved data locality, and reduced number of CALLVIRT-s /// internal struct InputProcessor : IDisposable @@ -29,7 +27,7 @@ internal struct InputProcessor : IDisposable /// Initializes a new instance of the struct. /// /// The input - /// Temporal buffer, same as + /// Temporal buffer, same as public InputProcessor(Stream inputStream, byte[] temp) { this.Bits = default(Bits); @@ -45,7 +43,7 @@ public InputProcessor(Stream inputStream, byte[] temp) public Stream InputStream { get; } /// - /// Gets the temporal buffer, same instance as + /// Gets the temporal buffer, same instance as /// public byte[] Temp { get; } @@ -58,11 +56,11 @@ public InputProcessor(Stream inputStream, byte[] temp) /// If errorCode indicates unexpected EOF, sets to true and returns false. /// Calls and returns true otherwise. /// - /// The + /// The /// indicating whether everything is OK - public bool CheckEOFEnsureNoError(DecoderErrorCode errorCode) + public bool CheckEOFEnsureNoError(OldDecoderErrorCode errorCode) { - if (errorCode == DecoderErrorCode.UnexpectedEndOfStream) + if (errorCode == OldDecoderErrorCode.UnexpectedEndOfStream) { this.UnexpectedEndOfStreamReached = true; return false; @@ -76,11 +74,11 @@ public bool CheckEOFEnsureNoError(DecoderErrorCode errorCode) /// If errorCode indicates unexpected EOF, sets to true and returns false. /// Returns true otherwise. /// - /// The + /// The /// indicating whether everything is OK - public bool CheckEOF(DecoderErrorCode errorCode) + public bool CheckEOF(OldDecoderErrorCode errorCode) { - if (errorCode == DecoderErrorCode.UnexpectedEndOfStream) + if (errorCode == OldDecoderErrorCode.UnexpectedEndOfStream) { this.UnexpectedEndOfStreamReached = true; return false; @@ -112,13 +110,13 @@ public byte ReadByte() /// TODO: This method (and also the usages) could be optimized by batching! /// /// The decoded bit as a - /// The - public DecoderErrorCode DecodeBitUnsafe(out bool result) + /// The + public OldDecoderErrorCode DecodeBitUnsafe(out bool result) { if (this.Bits.UnreadBits == 0) { - DecoderErrorCode errorCode = this.Bits.Ensure1BitUnsafe(ref this); - if (errorCode != DecoderErrorCode.NoError) + OldDecoderErrorCode errorCode = this.Bits.Ensure1BitUnsafe(ref this); + if (errorCode != OldDecoderErrorCode.NoError) { result = false; return errorCode; @@ -128,18 +126,18 @@ public DecoderErrorCode DecodeBitUnsafe(out bool result) result = (this.Bits.Accumulator & this.Bits.Mask) != 0; this.Bits.UnreadBits--; this.Bits.Mask >>= 1; - return DecoderErrorCode.NoError; + return OldDecoderErrorCode.NoError; } /// /// Reads exactly length bytes into data. It does not care about byte stuffing. - /// Does not throw on errors, returns instead! + /// Does not throw on errors, returns instead! /// /// The data to write to. /// The offset in the source buffer /// The number of bytes to read - /// The - public DecoderErrorCode ReadFullUnsafe(byte[] data, int offset, int length) + /// The + public OldDecoderErrorCode ReadFullUnsafe(byte[] data, int offset, int length) { // Unread the overshot bytes, if any. if (this.Bytes.UnreadableBytes != 0) @@ -152,7 +150,7 @@ public DecoderErrorCode ReadFullUnsafe(byte[] data, int offset, int length) this.Bytes.UnreadableBytes = 0; } - DecoderErrorCode errorCode = DecoderErrorCode.NoError; + OldDecoderErrorCode errorCode = OldDecoderErrorCode.NoError; while (length > 0) { if (this.Bytes.J - this.Bytes.I >= length) @@ -180,8 +178,8 @@ public DecoderErrorCode ReadFullUnsafe(byte[] data, int offset, int length) /// /// The number of bits to decode. /// The result - /// The - public DecoderErrorCode DecodeBitsUnsafe(int count, out int result) + /// The + public OldDecoderErrorCode DecodeBitsUnsafe(int count, out int result) { if (this.Bits.UnreadBits < count) { @@ -192,7 +190,7 @@ public DecoderErrorCode DecodeBitsUnsafe(int count, out int result) result = result & ((1 << count) - 1); this.Bits.UnreadBits -= count; this.Bits.Mask >>= count; - return DecoderErrorCode.NoError; + return OldDecoderErrorCode.NoError; } /// @@ -200,8 +198,8 @@ public DecoderErrorCode DecodeBitsUnsafe(int count, out int result) /// /// The huffman value /// The decoded - /// The - public DecoderErrorCode DecodeHuffmanUnsafe(ref HuffmanTree huffmanTree, out int result) + /// The + public OldDecoderErrorCode DecodeHuffmanUnsafe(ref OldHuffmanTree huffmanTree, out int result) { result = 0; @@ -212,11 +210,11 @@ public DecoderErrorCode DecodeHuffmanUnsafe(ref HuffmanTree huffmanTree, out int if (this.Bits.UnreadBits < 8) { - DecoderErrorCode errorCode = this.Bits.Ensure8BitsUnsafe(ref this); + OldDecoderErrorCode errorCode = this.Bits.Ensure8BitsUnsafe(ref this); - if (errorCode == DecoderErrorCode.NoError) + if (errorCode == OldDecoderErrorCode.NoError) { - int lutIndex = (this.Bits.Accumulator >> (this.Bits.UnreadBits - HuffmanTree.LutSizeLog2)) & 0xFF; + int lutIndex = (this.Bits.Accumulator >> (this.Bits.UnreadBits - OldHuffmanTree.LutSizeLog2)) & 0xFF; int v = huffmanTree.Lut[lutIndex]; if (v != 0) @@ -236,7 +234,7 @@ public DecoderErrorCode DecodeHuffmanUnsafe(ref HuffmanTree huffmanTree, out int } int code = 0; - for (int i = 0; i < HuffmanTree.MaxCodeLength; i++) + for (int i = 0; i < OldHuffmanTree.MaxCodeLength; i++) { if (this.Bits.UnreadBits == 0) { @@ -254,7 +252,7 @@ public DecoderErrorCode DecodeHuffmanUnsafe(ref HuffmanTree huffmanTree, out int if (code <= huffmanTree.MaxCodes[i]) { result = huffmanTree.GetValue(code, i); - return DecoderErrorCode.NoError; + return OldDecoderErrorCode.NoError; } code <<= 1; @@ -264,7 +262,7 @@ public DecoderErrorCode DecodeHuffmanUnsafe(ref HuffmanTree huffmanTree, out int DecoderThrowHelper.ThrowImageFormatException.BadHuffmanCode(); // DUMMY RETURN! C# doesn't know we have thrown an exception! - return DecoderErrorCode.NoError; + return OldDecoderErrorCode.NoError; } /// @@ -274,17 +272,17 @@ public DecoderErrorCode DecodeHuffmanUnsafe(ref HuffmanTree huffmanTree, out int [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Skip(int count) { - DecoderErrorCode errorCode = this.SkipUnsafe(count); + OldDecoderErrorCode errorCode = this.SkipUnsafe(count); errorCode.EnsureNoError(); } /// /// Skips the next n bytes. - /// Does not throw, returns instead! + /// Does not throw, returns instead! /// /// The number of bytes to ignore. - /// The - public DecoderErrorCode SkipUnsafe(int count) + /// The + public OldDecoderErrorCode SkipUnsafe(int count) { // Unread the overshot bytes, if any. if (this.Bytes.UnreadableBytes != 0) @@ -312,14 +310,14 @@ public DecoderErrorCode SkipUnsafe(int count) break; } - DecoderErrorCode errorCode = this.Bytes.FillUnsafe(this.InputStream); - if (errorCode != DecoderErrorCode.NoError) + OldDecoderErrorCode errorCode = this.Bytes.FillUnsafe(this.InputStream); + if (errorCode != OldDecoderErrorCode.NoError) { return errorCode; } } - return DecoderErrorCode.NoError; + return OldDecoderErrorCode.NoError; } /// @@ -331,7 +329,7 @@ public DecoderErrorCode SkipUnsafe(int count) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ReadFull(byte[] data, int offset, int length) { - DecoderErrorCode errorCode = this.ReadFullUnsafe(data, offset, length); + OldDecoderErrorCode errorCode = this.ReadFullUnsafe(data, offset, length); errorCode.EnsureNoError(); } @@ -359,8 +357,8 @@ public void UnreadByteStuffedByte() /// /// Byte /// Read bits value - /// The - public DecoderErrorCode ReceiveExtendUnsafe(int t, out int x) + /// The + public OldDecoderErrorCode ReceiveExtendUnsafe(int t, out int x) { return this.Bits.ReceiveExtendUnsafe(t, ref this, out x); } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockProcessor.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegBlockProcessor.cs similarity index 85% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockProcessor.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegBlockProcessor.cs index 71472c00fc..99148b92c8 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegBlockProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - - using ImageSharp.Memory; +using System.Runtime.InteropServices; +using SixLabors.ImageSharp.Memory; +using Block8x8F = SixLabors.ImageSharp.Formats.Jpeg.Common.Block8x8F; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// Encapsulates the implementation of processing "raw" -s into Jpeg image channels. /// @@ -44,10 +41,10 @@ public static void Init(JpegBlockProcessor* processor, int componentIndex) } /// - /// Dequantize, perform the inverse DCT and store the blocks to the into the corresponding instances. + /// Dequantize, perform the inverse DCT and store the blocks to the into the corresponding instances. /// - /// The instance - public void ProcessAllBlocks(JpegDecoderCore decoder) + /// The instance + public void ProcessAllBlocks(OldJpegDecoderCore decoder) { Buffer blockArray = decoder.DecodedBlocks[this.componentIndex]; for (int i = 0; i < blockArray.Length; i++) @@ -57,11 +54,11 @@ public void ProcessAllBlocks(JpegDecoderCore decoder) } /// - /// Dequantize, perform the inverse DCT and store decodedBlock.Block to the into the corresponding instance. + /// Dequantize, perform the inverse DCT and store decodedBlock.Block to the into the corresponding instance. /// - /// The + /// The /// The - private void ProcessBlockColors(JpegDecoderCore decoder, ref DecodedBlock decodedBlock) + private void ProcessBlockColors(OldJpegDecoderCore decoder, ref DecodedBlock decodedBlock) { this.data.Block = decodedBlock.Block; int qtIndex = decoder.ComponentArray[this.componentIndex].Selector; @@ -73,8 +70,8 @@ private void ProcessBlockColors(JpegDecoderCore decoder, ref DecodedBlock decode DCT.TransformIDCT(ref *b, ref *this.pointers.Temp1, ref *this.pointers.Temp2); - JpegPixelArea destChannel = decoder.GetDestinationChannel(this.componentIndex); - JpegPixelArea destArea = destChannel.GetOffsetedSubAreaForBlock(decodedBlock.Bx, decodedBlock.By); + OldJpegPixelArea destChannel = decoder.GetDestinationChannel(this.componentIndex); + OldJpegPixelArea destArea = destChannel.GetOffsetedSubAreaForBlock(decodedBlock.Bx, decodedBlock.By); destArea.LoadColorsFrom(this.pointers.Temp1, this.pointers.Temp2); } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.md b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegScanDecoder.md similarity index 100% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.md rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegScanDecoder.md diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/MissingFF00Exception.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/MissingFF00Exception.cs similarity index 55% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/MissingFF00Exception.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/MissingFF00Exception.cs index f8c157237d..005034b9dc 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/MissingFF00Exception.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/MissingFF00Exception.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System; +using System; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// The missing ff00 exception. /// diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/Component.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldComponent.cs similarity index 77% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/Component.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldComponent.cs index 5b53db1901..3f1f70b203 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/Component.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldComponent.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { /// /// Represents a single color component /// - internal struct Component + internal struct OldComponent { /// /// Gets or sets the horizontal sampling factor. diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentScan.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldComponentScan.cs similarity index 69% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentScan.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldComponentScan.cs index 89fc115ea3..5114ebd049 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentScan.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldComponentScan.cs @@ -1,17 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System.Runtime.InteropServices; +using System.Runtime.InteropServices; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// Represents a component scan /// [StructLayout(LayoutKind.Sequential)] - internal struct ComponentScan + internal struct OldComponentScan { /// /// Gets or sets the component index. diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/DecoderErrorCode.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldDecoderErrorCode.cs similarity index 70% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/DecoderErrorCode.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldDecoderErrorCode.cs index 8b82184faf..f4419fb620 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/DecoderErrorCode.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldDecoderErrorCode.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { /// /// Represents "recoverable" decoder errors. /// - internal enum DecoderErrorCode + internal enum OldDecoderErrorCode { /// /// NoError diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTree.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldHuffmanTree.cs similarity index 92% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTree.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldHuffmanTree.cs index 390e5dd150..21210c95da 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTree.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldHuffmanTree.cs @@ -1,16 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System; - using System.Buffers; +using System; +using System.Buffers; + +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// Represents a Huffman tree /// - internal struct HuffmanTree : IDisposable + internal struct OldHuffmanTree : IDisposable { /// /// The index of the AC table row @@ -99,12 +98,12 @@ internal struct HuffmanTree : IDisposable private static readonly ArrayPool CodesPool16 = ArrayPool.Create(MaxCodeLength, 50); /// - /// Creates and initializes an array of instances of size + /// Creates and initializes an array of instances of size /// - /// An array of instances representing the Huffman tables - public static HuffmanTree[] CreateHuffmanTrees() + /// An array of instances representing the Huffman tables + public static OldHuffmanTree[] CreateHuffmanTrees() { - HuffmanTree[] result = new HuffmanTree[NumberOfTrees]; + OldHuffmanTree[] result = new OldHuffmanTree[NumberOfTrees]; for (int i = 0; i < MaxTc + 1; i++) { for (int j = 0; j < MaxTh + 1; j++) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegPixelArea.cs similarity index 80% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegPixelArea.cs index 342ce299ce..9f8f8d71a7 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegPixelArea.cs @@ -1,25 +1,25 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System.Runtime.CompilerServices; - using ImageSharp.Memory; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Utils; +using SixLabors.ImageSharp.Memory; +using Block8x8F = SixLabors.ImageSharp.Formats.Jpeg.Common.Block8x8F; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// Represents an area of a Jpeg subimage (channel) /// - internal struct JpegPixelArea + internal struct OldJpegPixelArea { /// - /// Initializes a new instance of the struct from existing data. + /// Initializes a new instance of the struct from existing data. /// /// The pixel buffer /// The stride /// The offset - public JpegPixelArea(Buffer2D pixels, int stride, int offset) + public OldJpegPixelArea(Buffer2D pixels, int stride, int offset) { this.Stride = stride; this.Pixels = pixels; @@ -27,11 +27,11 @@ public JpegPixelArea(Buffer2D pixels, int stride, int offset) } /// - /// Initializes a new instance of the struct from existing buffer. + /// Initializes a new instance of the struct from existing buffer. /// will be set to of and will be set to 0. /// /// The pixel buffer - public JpegPixelArea(Buffer2D pixels) + public OldJpegPixelArea(Buffer2D pixels) : this(pixels, pixels.Width, 0) { } @@ -82,10 +82,10 @@ public JpegPixelArea(Buffer2D pixels) /// The block X index /// The block Y index /// The subarea offseted by block indices - public JpegPixelArea GetOffsetedSubAreaForBlock(int bx, int by) + public OldJpegPixelArea GetOffsetedSubAreaForBlock(int bx, int by) { int offset = this.Offset + (8 * ((by * this.Stride) + bx)); - return new JpegPixelArea(this.Pixels, this.Stride, offset); + return new OldJpegPixelArea(this.Pixels, this.Stride, offset); } /// diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.ComputationData.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegScanDecoder.ComputationData.cs similarity index 70% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.ComputationData.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegScanDecoder.ComputationData.cs index 7b910cdd24..268ae8cb52 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.ComputationData.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegScanDecoder.ComputationData.cs @@ -1,16 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System.Runtime.InteropServices; +using System.Runtime.InteropServices; +using Block8x8F = SixLabors.ImageSharp.Formats.Jpeg.Common.Block8x8F; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// Conains the definition of /// - internal unsafe partial struct JpegScanDecoder + internal unsafe partial struct OldJpegScanDecoder { /// /// Holds the "large" data blocks needed for computations. @@ -29,14 +28,14 @@ public struct ComputationData public UnzigData Unzig; /// - /// The buffer storing the -s for each component + /// The buffer storing the -s for each component /// - public fixed byte ScanData[3 * JpegDecoderCore.MaxComponents]; + public fixed byte ScanData[3 * OldJpegDecoderCore.MaxComponents]; /// /// The DC values for each component /// - public fixed int Dc[JpegDecoderCore.MaxComponents]; + public fixed int Dc[OldJpegDecoderCore.MaxComponents]; /// /// Creates and initializes a new instance diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.DataPointers.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegScanDecoder.DataPointers.cs similarity index 79% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.DataPointers.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegScanDecoder.DataPointers.cs index 52e25f3a81..485884ca35 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.DataPointers.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegScanDecoder.DataPointers.cs @@ -1,14 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg +using Block8x8F = SixLabors.ImageSharp.Formats.Jpeg.Common.Block8x8F; + +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { /// /// Conains the definition of /// - internal unsafe partial struct JpegScanDecoder + internal unsafe partial struct OldJpegScanDecoder { /// /// Contains pointers to the memory regions of so they can be easily passed around to pointer based utility methods of @@ -28,7 +28,7 @@ public struct DataPointers /// /// Pointer to as Scan* /// - public ComponentScan* ComponentScan; + public OldComponentScan* ComponentScan; /// /// Pointer to @@ -43,7 +43,7 @@ public DataPointers(ComputationData* basePtr) { this.Block = &basePtr->Block; this.Unzig = basePtr->Unzig.Data; - this.ComponentScan = (ComponentScan*)basePtr->ScanData; + this.ComponentScan = (OldComponentScan*)basePtr->ScanData; this.Dc = basePtr->Dc; } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegScanDecoder.cs similarity index 87% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegScanDecoder.cs index 7d2e6d4414..81e9a50349 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegScanDecoder.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -// ReSharper disable InconsistentNaming -namespace ImageSharp.Formats.Jpg -{ - using System; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - using ImageSharp.Memory; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using SixLabors.ImageSharp.Memory; +using Block8x8F = SixLabors.ImageSharp.Formats.Jpeg.Common.Block8x8F; +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// Encapsulates the impementation of Jpeg SOS Huffman decoding. See JpegScanDecoder.md! /// @@ -30,7 +28,7 @@ namespace ImageSharp.Formats.Jpg /// For baseline JPEGs, these parameters are hard-coded to 0/63/0/0. /// [StructLayout(LayoutKind.Sequential)] - internal unsafe partial struct JpegScanDecoder + internal unsafe partial struct OldJpegScanDecoder { // The JpegScanDecoder members should be ordered in a way that results in optimal memory layout. #pragma warning disable SA1202 // ElementsMustBeOrderedByAccess @@ -96,12 +94,12 @@ internal unsafe partial struct JpegScanDecoder private int eobRun; /// - /// Initializes a default-constructed instance for reading data from -s stream. + /// Initializes a default-constructed instance for reading data from -s stream. /// - /// Pointer to on the stack - /// The instance + /// Pointer to on the stack + /// The instance /// The remaining bytes in the segment block. - public static void InitStreamReading(JpegScanDecoder* p, JpegDecoderCore decoder, int remaining) + public static void InitStreamReading(OldJpegScanDecoder* p, OldJpegDecoderCore decoder, int remaining) { p->data = ComputationData.Create(); p->pointers = new DataPointers(&p->data); @@ -109,8 +107,8 @@ public static void InitStreamReading(JpegScanDecoder* p, JpegDecoderCore decoder } /// - /// Read Huffman data from Jpeg scans in , - /// and decode it as into . + /// Read Huffman data from Jpeg scans in , + /// and decode it as into . /// /// The blocks are traversed one MCU at a time. For 4:2:0 chroma /// subsampling, there are four Y 8x8 blocks in every 16x16 MCU. @@ -135,12 +133,12 @@ public static void InitStreamReading(JpegScanDecoder* p, JpegDecoderCore decoder /// 0 1 2 /// 3 4 5 /// - /// The instance - public void DecodeBlocks(JpegDecoderCore decoder) + /// The instance + public void DecodeBlocks(OldJpegDecoderCore decoder) { int blockCount = 0; int mcu = 0; - byte expectedRst = JpegConstants.Markers.RST0; + byte expectedRst = OldJpegConstants.Markers.RST0; for (int my = 0; my < decoder.MCUCountY; my++) { @@ -197,7 +195,7 @@ public void DecodeBlocks(JpegDecoderCore decoder) // but this one assumes well-formed input, and hence the restart marker follows immediately. if (!decoder.InputProcessor.UnexpectedEndOfStreamReached) { - DecoderErrorCode errorCode = decoder.InputProcessor.ReadFullUnsafe(decoder.Temp, 0, 2); + OldDecoderErrorCode errorCode = decoder.InputProcessor.ReadFullUnsafe(decoder.Temp, 0, 2); if (decoder.InputProcessor.CheckEOFEnsureNoError(errorCode)) { if (decoder.Temp[0] != 0xff || decoder.Temp[1] != expectedRst) @@ -206,9 +204,9 @@ public void DecodeBlocks(JpegDecoderCore decoder) } expectedRst++; - if (expectedRst == JpegConstants.Markers.RST7 + 1) + if (expectedRst == OldJpegConstants.Markers.RST7 + 1) { - expectedRst = JpegConstants.Markers.RST0; + expectedRst = OldJpegConstants.Markers.RST0; } } } @@ -230,15 +228,15 @@ public void DecodeBlocks(JpegDecoderCore decoder) private void ResetDc() { - Unsafe.InitBlock(this.pointers.Dc, default(byte), sizeof(int) * JpegDecoderCore.MaxComponents); + Unsafe.InitBlock(this.pointers.Dc, default(byte), sizeof(int) * OldJpegDecoderCore.MaxComponents); } /// /// The implementation part of as an instance method. /// - /// The + /// The /// The remaining bytes - private void InitStreamReadingImpl(JpegDecoderCore decoder, int remaining) + private void InitStreamReadingImpl(OldJpegDecoderCore decoder, int remaining) { if (decoder.ComponentCount == 0) { @@ -305,10 +303,10 @@ private void InitStreamReadingImpl(JpegDecoderCore decoder, int remaining) /// /// The decoder /// The index of the scan - private void DecodeBlock(JpegDecoderCore decoder, int scanIndex) + private void DecodeBlock(OldJpegDecoderCore decoder, int scanIndex) { Block8x8F* b = this.pointers.Block; - int huffmannIdx = (HuffmanTree.AcTableIndex * HuffmanTree.ThRowSize) + this.pointers.ComponentScan[scanIndex].AcTableSelector; + int huffmannIdx = (OldHuffmanTree.AcTableIndex * OldHuffmanTree.ThRowSize) + this.pointers.ComponentScan[scanIndex].AcTableSelector; if (this.ah != 0) { this.Refine(ref decoder.InputProcessor, ref decoder.HuffmanTrees[huffmannIdx], 1 << this.al); @@ -316,14 +314,14 @@ private void DecodeBlock(JpegDecoderCore decoder, int scanIndex) else { int zig = this.zigStart; - DecoderErrorCode errorCode; + OldDecoderErrorCode errorCode; if (zig == 0) { zig++; // Decode the DC coefficient, as specified in section F.2.2.1. int value; - int huffmanIndex = (HuffmanTree.DcTableIndex * HuffmanTree.ThRowSize) + this.pointers.ComponentScan[scanIndex].DcTableSelector; + int huffmanIndex = (OldHuffmanTree.DcTableIndex * OldHuffmanTree.ThRowSize) + this.pointers.ComponentScan[scanIndex].DcTableSelector; errorCode = decoder.InputProcessor.DecodeHuffmanUnsafe( ref decoder.HuffmanTrees[huffmanIndex], out value); @@ -411,30 +409,30 @@ private void DecodeBlock(JpegDecoderCore decoder, int scanIndex) } } - private DecoderErrorCode DecodeEobRun(int count, ref InputProcessor decoder) + private OldDecoderErrorCode DecodeEobRun(int count, ref InputProcessor decoder) { int bitsResult; - DecoderErrorCode errorCode = decoder.DecodeBitsUnsafe(count, out bitsResult); - if (errorCode != DecoderErrorCode.NoError) + OldDecoderErrorCode errorCode = decoder.DecodeBitsUnsafe(count, out bitsResult); + if (errorCode != OldDecoderErrorCode.NoError) { return errorCode; } this.eobRun |= bitsResult; - return DecoderErrorCode.NoError; + return OldDecoderErrorCode.NoError; } /// - /// Gets the block index used to retieve blocks from in + /// Gets the block index used to retieve blocks from in /// - /// The instance + /// The instance /// The index - private int GetBlockIndex(JpegDecoderCore decoder) + private int GetBlockIndex(OldJpegDecoderCore decoder) { return ((this.by * decoder.MCUCountX) * this.hi) + this.bx; } - private void InitComponentScan(JpegDecoderCore decoder, int i, ref ComponentScan currentComponentScan, ref int totalHv) + private void InitComponentScan(OldJpegDecoderCore decoder, int i, ref OldComponentScan currentComponentScan, ref int totalHv) { // Component selector. int cs = decoder.Temp[1 + (2 * i)]; @@ -459,11 +457,11 @@ private void InitComponentScan(JpegDecoderCore decoder, int i, ref ComponentScan } private void ProcessComponentImpl( - JpegDecoderCore decoder, + OldJpegDecoderCore decoder, int i, - ref ComponentScan currentComponentScan, + ref OldComponentScan currentComponentScan, ref int totalHv, - ref Component currentComponent) + ref OldComponent currentComponent) { // Section B.2.3 states that "the value of Cs_j shall be different from // the values of Cs_1 through Cs_(j-1)". Since we have previously @@ -481,13 +479,13 @@ private void ProcessComponentImpl( totalHv += currentComponent.HorizontalFactor * currentComponent.VerticalFactor; currentComponentScan.DcTableSelector = (byte)(decoder.Temp[2 + (2 * i)] >> 4); - if (currentComponentScan.DcTableSelector > HuffmanTree.MaxTh) + if (currentComponentScan.DcTableSelector > OldHuffmanTree.MaxTh) { throw new ImageFormatException("Bad DC table selector value"); } currentComponentScan.AcTableSelector = (byte)(decoder.Temp[2 + (2 * i)] & 0x0f); - if (currentComponentScan.AcTableSelector > HuffmanTree.MaxTh) + if (currentComponentScan.AcTableSelector > OldHuffmanTree.MaxTh) { throw new ImageFormatException("Bad AC table selector value"); } @@ -499,7 +497,7 @@ private void ProcessComponentImpl( /// The instance /// The Huffman tree /// The low transform offset - private void Refine(ref InputProcessor bp, ref HuffmanTree h, int delta) + private void Refine(ref InputProcessor bp, ref OldHuffmanTree h, int delta) { Block8x8F* b = this.pointers.Block; @@ -512,7 +510,7 @@ private void Refine(ref InputProcessor bp, ref HuffmanTree h, int delta) } bool bit; - DecoderErrorCode errorCode = bp.DecodeBitUnsafe(out bit); + OldDecoderErrorCode errorCode = bp.DecodeBitUnsafe(out bit); if (!bp.CheckEOFEnsureNoError(errorCode)) { return; @@ -542,7 +540,7 @@ private void Refine(ref InputProcessor bp, ref HuffmanTree h, int delta) int z = 0; int val; - DecoderErrorCode errorCode = bp.DecodeHuffmanUnsafe(ref h, out val); + OldDecoderErrorCode errorCode = bp.DecodeHuffmanUnsafe(ref h, out val); if (!bp.CheckEOF(errorCode)) { return; @@ -651,7 +649,7 @@ private int RefineNonZeroes(ref InputProcessor bp, int zig, int nz, int delta) } bool bit; - DecoderErrorCode errorCode = bp.DecodeBitUnsafe(out bit); + OldDecoderErrorCode errorCode = bp.DecodeBitUnsafe(out bit); if (!bp.CheckEOFEnsureNoError(errorCode)) { return int.MinValue; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrImage.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/YCbCrImage.cs similarity index 93% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrImage.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/YCbCrImage.cs index c9cc327b86..2fb5f3fa88 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrImage.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/YCbCrImage.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System; - using System.Buffers; - using ImageSharp.Memory; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.Memory; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// Represents an image made up of three color components (luminance, blue chroma, red chroma) /// @@ -18,17 +15,17 @@ internal class YCbCrImage : IDisposable // Complex value type field + mutable + available to other classes = the field MUST NOT be private :P #pragma warning disable SA1401 // FieldsMustBePrivate /// - /// Gets the luminance components channel as . + /// Gets the luminance components channel as . /// public Buffer2D YChannel; /// - /// Gets the blue chroma components channel as . + /// Gets the blue chroma components channel as . /// public Buffer2D CbChannel; /// - /// Gets an offseted to the Cr channel + /// Gets an offseted to the Cr channel /// public Buffer2D CrChannel; #pragma warning restore SA1401 diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrToRgbTables.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/YCbCrToRgbTables.cs similarity index 93% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrToRgbTables.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/YCbCrToRgbTables.cs index 5c9e8f9fc3..fe0cd6fc08 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrToRgbTables.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/YCbCrToRgbTables.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System.Runtime.CompilerServices; - using ImageSharp.PixelFormats; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// Provides 8-bit lookup tables for converting from YCbCr to Rgb colorspace. /// Methods to build the tables are based on libjpeg implementation. diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffIndex.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffIndex.cs similarity index 81% rename from src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffIndex.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffIndex.cs index 3875cc12fe..23fcda2964 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffIndex.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffIndex.cs @@ -1,8 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg + +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder { /// /// Enumerates the Huffman tables diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanLut.cs similarity index 92% rename from src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanLut.cs index d0003b919d..2fb01c5c8c 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanLut.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder { /// /// A compiled look-up table representation of a huffmanSpec. diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanSpec.cs similarity index 97% rename from src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanSpec.cs index a0eea6e718..8e40cb3689 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanSpec.cs @@ -1,8 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg + +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder { /// /// The Huffman encoding specifications. diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/QuantIndex.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/QuantIndex.cs similarity index 71% rename from src/ImageSharp/Formats/Jpeg/Components/Encoder/QuantIndex.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/QuantIndex.cs index 5a469e0e9d..459d29f91f 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/QuantIndex.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/QuantIndex.cs @@ -1,8 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg + +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder { /// /// Enumerates the quantization tables diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbToYCbCrTables.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/RgbToYCbCrTables.cs similarity index 95% rename from src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbToYCbCrTables.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/RgbToYCbCrTables.cs index 94173d3e43..02bd451b94 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbToYCbCrTables.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/RgbToYCbCrTables.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder +{ /// /// Provides 8-bit lookup tables for converting from Rgb to YCbCr colorspace. /// Methods to build the tables are based on libjpeg implementation. diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/JpegEncoderCore.cs similarity index 95% rename from src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/JpegEncoderCore.cs index d2b7d2d7c4..cb9d73bd0f 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/JpegEncoderCore.cs @@ -1,19 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System.Buffers; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Runtime.CompilerServices; - using ImageSharp.Formats.Jpg; - using ImageSharp.Formats.Jpg.Components; - using ImageSharp.PixelFormats; +using System.Buffers; +using System.IO; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Utils; +using SixLabors.ImageSharp.PixelFormats; +using Block8x8F = SixLabors.ImageSharp.Formats.Jpeg.Common.Block8x8F; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort +{ /// /// Image encoder for writing an image to a stream as a jpeg. /// @@ -57,7 +55,7 @@ internal sealed unsafe class JpegEncoderCore /// private static readonly byte[] SosHeaderYCbCr = { - JpegConstants.Markers.XFF, JpegConstants.Markers.SOS, + OldJpegConstants.Markers.XFF, OldJpegConstants.Markers.SOS, // Marker 0x00, 0x0c, @@ -196,7 +194,7 @@ public void Encode(Image image, Stream stream) Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); - ushort max = JpegConstants.MaxLength; + ushort max = OldJpegConstants.MaxLength; if (image.Width >= max || image.Height >= max) { throw new ImageFormatException($"Image is too large to encode at {image.Width}x{image.Height}."); @@ -245,8 +243,8 @@ public void Encode(Image image, Stream stream) } // Write the End Of Image marker. - this.buffer[0] = JpegConstants.Markers.XFF; - this.buffer[1] = JpegConstants.Markers.EOI; + this.buffer[0] = OldJpegConstants.Markers.XFF; + this.buffer[1] = OldJpegConstants.Markers.EOI; stream.Write(this.buffer, 0, 2); stream.Flush(); } @@ -507,12 +505,12 @@ private void Encode444(PixelAccessor pixels) private void WriteApplicationHeader(short horizontalResolution, short verticalResolution) { // Write the start of image marker. Markers are always prefixed with with 0xff. - this.buffer[0] = JpegConstants.Markers.XFF; - this.buffer[1] = JpegConstants.Markers.SOI; + this.buffer[0] = OldJpegConstants.Markers.XFF; + this.buffer[1] = OldJpegConstants.Markers.SOI; // Write the JFIF headers - this.buffer[2] = JpegConstants.Markers.XFF; - this.buffer[3] = JpegConstants.Markers.APP0; // Application Marker + this.buffer[2] = OldJpegConstants.Markers.XFF; + this.buffer[3] = OldJpegConstants.Markers.APP0; // Application Marker this.buffer[4] = 0x00; this.buffer[5] = 0x10; this.buffer[6] = 0x4a; // J @@ -626,7 +624,7 @@ private void WriteDefineHuffmanTables(int componentCount) markerlen += 1 + 16 + s.Values.Length; } - this.WriteMarkerHeader(JpegConstants.Markers.DHT, markerlen); + this.WriteMarkerHeader(OldJpegConstants.Markers.DHT, markerlen); for (int i = 0; i < specs.Length; i++) { HuffmanSpec spec = specs[i]; @@ -660,7 +658,7 @@ private void WriteDefineQuantizationTables() { // Marker + quantization table lengths int markerlen = 2 + (QuantizationTableCount * (1 + Block8x8F.ScalarCount)); - this.WriteMarkerHeader(JpegConstants.Markers.DQT, markerlen); + this.WriteMarkerHeader(OldJpegConstants.Markers.DQT, markerlen); // Loop through and collect the tables as one array. // This allows us to reduce the number of writes to the stream. @@ -698,8 +696,8 @@ private void WriteExifProfile(ExifProfile exifProfile) int length = data.Length + 2; - this.buffer[0] = JpegConstants.Markers.XFF; - this.buffer[1] = JpegConstants.Markers.APP1; // Application Marker + this.buffer[0] = OldJpegConstants.Markers.XFF; + this.buffer[1] = OldJpegConstants.Markers.APP1; // Application Marker this.buffer[2] = (byte)((length >> 8) & 0xFF); this.buffer[3] = (byte)(length & 0xFF); @@ -757,8 +755,8 @@ private void WriteIccProfile(IccProfile iccProfile) dataLength -= length; - this.buffer[0] = JpegConstants.Markers.XFF; - this.buffer[1] = JpegConstants.Markers.APP2; // Application Marker + this.buffer[0] = OldJpegConstants.Markers.XFF; + this.buffer[1] = OldJpegConstants.Markers.APP2; // Application Marker int markerLength = length + 16; this.buffer[2] = (byte)((markerLength >> 8) & 0xFF); this.buffer[3] = (byte)(markerLength & 0xFF); @@ -830,7 +828,7 @@ private void WriteStartOfFrame(int width, int height, int componentCount) // Length (high byte, low byte), 8 + components * 3. int markerlen = 8 + (3 * componentCount); - this.WriteMarkerHeader(JpegConstants.Markers.SOF0, markerlen); + this.WriteMarkerHeader(OldJpegConstants.Markers.SOF0, markerlen); this.buffer[0] = 8; // Data Precision. 8 for now, 12 and 16 bit jpegs not supported this.buffer[1] = (byte)(height >> 8); this.buffer[2] = (byte)(height & 0xff); // (2 bytes, Hi-Lo), must be > 0 if DNL not supported @@ -973,7 +971,7 @@ private void Encode420(PixelAccessor pixels) private void WriteMarkerHeader(byte marker, int length) { // Markers are always prefixed with with 0xff. - this.buffer[0] = JpegConstants.Markers.XFF; + this.buffer[0] = OldJpegConstants.Markers.XFF; this.buffer[1] = marker; this.buffer[2] = (byte)(length >> 8); this.buffer[3] = (byte)(length & 0xff); diff --git a/src/ImageSharp/Formats/Jpeg/JpegConstants.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/OldJpegConstants.cs similarity index 97% rename from src/ImageSharp/Formats/Jpeg/JpegConstants.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/OldJpegConstants.cs index 99c0399dcc..c2326cc4ff 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegConstants.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/OldJpegConstants.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System.Collections.Generic; +using System.Collections.Generic; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort +{ /// /// Defines jpeg constants defined in the specification. /// - internal static class JpegConstants + internal static class OldJpegConstants { /// /// The maximum allowable length in each dimension of a jpeg image. diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/OldJpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/OldJpegDecoder.cs new file mode 100644 index 0000000000..602cd70669 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/OldJpegDecoder.cs @@ -0,0 +1,29 @@ +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort +{ + using System.IO; + + using SixLabors.ImageSharp.PixelFormats; + + /// + /// Image decoder for generating an image out of a jpg stream. + /// + public sealed class OldJpegDecoder : IImageDecoder, IJpegDecoderOptions + { + /// + /// Gets or sets a value indicating whether the metadata should be ignored when the image is being decoded. + /// + public bool IgnoreMetadata { get; set; } + + /// + public Image Decode(Configuration configuration, Stream stream) + where TPixel : struct, IPixel + { + Guard.NotNull(stream, nameof(stream)); + + using (var decoder = new OldJpegDecoderCore(configuration, this)) + { + return decoder.Decode(stream); + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/OldJpegDecoderCore.cs similarity index 93% rename from src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/OldJpegDecoderCore.cs index 0ce927e516..dc6ff81476 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/OldJpegDecoderCore.cs @@ -1,24 +1,21 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Runtime.CompilerServices; - using System.Threading.Tasks; - - using ImageSharp.Formats.Jpg; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.IO; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using Block8x8F = SixLabors.ImageSharp.Formats.Jpeg.Common.Block8x8F; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort +{ /// /// Performs the jpeg decoding operation. /// - internal sealed unsafe class JpegDecoderCore : IDisposable + internal sealed unsafe class OldJpegDecoderCore : IDisposable { /// /// The maximum number of color components @@ -34,7 +31,7 @@ internal sealed unsafe class JpegDecoderCore : IDisposable #pragma warning disable SA1401 // FieldsMustBePrivate /// - /// Encapsulates stream reading and processing data and operations for . + /// Encapsulates stream reading and processing data and operations for . /// It's a value type for imporved data locality, and reduced number of CALLVIRT-s /// public InputProcessor InputProcessor; @@ -63,12 +60,12 @@ internal sealed unsafe class JpegDecoderCore : IDisposable /// /// The black image to decode to. /// - private JpegPixelArea blackImage; + private OldJpegPixelArea blackImage; /// /// A grayscale image to decode to. /// - private JpegPixelArea grayImage; + private OldJpegPixelArea grayImage; /// /// The horizontal resolution. Calculated if the image has a JFIF header. @@ -96,30 +93,30 @@ internal sealed unsafe class JpegDecoderCore : IDisposable private YCbCrImage ycbcrImage; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The configuration. /// The options. - public JpegDecoderCore(Configuration configuration, IJpegDecoderOptions options) + public OldJpegDecoderCore(Configuration configuration, IJpegDecoderOptions options) { this.IgnoreMetadata = options.IgnoreMetadata; this.configuration = configuration ?? Configuration.Default; - this.HuffmanTrees = HuffmanTree.CreateHuffmanTrees(); + this.HuffmanTrees = OldHuffmanTree.CreateHuffmanTrees(); this.QuantizationTables = new Block8x8F[MaxTq + 1]; this.Temp = new byte[2 * Block8x8F.ScalarCount]; - this.ComponentArray = new Component[MaxComponents]; + this.ComponentArray = new OldComponent[MaxComponents]; this.DecodedBlocks = new Buffer[MaxComponents]; } /// /// Gets the component array /// - public Component[] ComponentArray { get; } + public OldComponent[] ComponentArray { get; } /// /// Gets the huffman trees /// - public HuffmanTree[] HuffmanTrees { get; } + public OldHuffmanTree[] HuffmanTrees { get; } /// /// Gets the array of -s storing the "raw" frequency-domain decoded blocks. @@ -230,11 +227,11 @@ public void Dispose() } /// - /// Gets the representing the channel at a given component index + /// Gets the representing the channel at a given component index /// /// The component index - /// The of the channel - public JpegPixelArea GetDestinationChannel(int compIndex) + /// The of the channel + public OldJpegPixelArea GetDestinationChannel(int compIndex) { if (this.ComponentCount == 1) { @@ -245,11 +242,11 @@ public JpegPixelArea GetDestinationChannel(int compIndex) switch (compIndex) { case 0: - return new JpegPixelArea(this.ycbcrImage.YChannel); + return new OldJpegPixelArea(this.ycbcrImage.YChannel); case 1: - return new JpegPixelArea(this.ycbcrImage.CbChannel); + return new OldJpegPixelArea(this.ycbcrImage.CbChannel); case 2: - return new JpegPixelArea(this.ycbcrImage.CrChannel); + return new OldJpegPixelArea(this.ycbcrImage.CrChannel); case 3: return this.blackImage; default: @@ -271,7 +268,7 @@ private void ProcessStream(ImageMetaData metadata, Stream stream, bool metadataO // Check for the Start Of Image marker. this.InputProcessor.ReadFull(this.Temp, 0, 2); - if (this.Temp[0] != JpegConstants.Markers.XFF || this.Temp[1] != JpegConstants.Markers.SOI) + if (this.Temp[0] != OldJpegConstants.Markers.XFF || this.Temp[1] != OldJpegConstants.Markers.SOI) { throw new ImageFormatException("Missing SOI marker."); } @@ -321,12 +318,12 @@ private void ProcessStream(ImageMetaData metadata, Stream stream, bool metadataO } // End Of Image. - if (marker == JpegConstants.Markers.EOI) + if (marker == OldJpegConstants.Markers.EOI) { break; } - if (marker >= JpegConstants.Markers.RST0 && marker <= JpegConstants.Markers.RST7) + if (marker >= OldJpegConstants.Markers.RST0 && marker <= OldJpegConstants.Markers.RST7) { // Figures B.2 and B.16 of the specification suggest that restart markers should // only occur between Entropy Coded Segments and not after the final ECS. @@ -348,10 +345,10 @@ private void ProcessStream(ImageMetaData metadata, Stream stream, bool metadataO switch (marker) { - case JpegConstants.Markers.SOF0: - case JpegConstants.Markers.SOF1: - case JpegConstants.Markers.SOF2: - this.IsProgressive = marker == JpegConstants.Markers.SOF2; + case OldJpegConstants.Markers.SOF0: + case OldJpegConstants.Markers.SOF1: + case OldJpegConstants.Markers.SOF2: + this.IsProgressive = marker == OldJpegConstants.Markers.SOF2; this.ProcessStartOfFrameMarker(remaining); if (metadataOnly && this.isJfif) { @@ -359,7 +356,7 @@ private void ProcessStream(ImageMetaData metadata, Stream stream, bool metadataO } break; - case JpegConstants.Markers.DHT: + case OldJpegConstants.Markers.DHT: if (metadataOnly) { this.InputProcessor.Skip(remaining); @@ -370,7 +367,7 @@ private void ProcessStream(ImageMetaData metadata, Stream stream, bool metadataO } break; - case JpegConstants.Markers.DQT: + case OldJpegConstants.Markers.DQT: if (metadataOnly) { this.InputProcessor.Skip(remaining); @@ -381,7 +378,7 @@ private void ProcessStream(ImageMetaData metadata, Stream stream, bool metadataO } break; - case JpegConstants.Markers.SOS: + case OldJpegConstants.Markers.SOS: if (metadataOnly) { return; @@ -397,7 +394,7 @@ private void ProcessStream(ImageMetaData metadata, Stream stream, bool metadataO } break; - case JpegConstants.Markers.DRI: + case OldJpegConstants.Markers.DRI: if (metadataOnly) { this.InputProcessor.Skip(remaining); @@ -408,25 +405,25 @@ private void ProcessStream(ImageMetaData metadata, Stream stream, bool metadataO } break; - case JpegConstants.Markers.APP0: + case OldJpegConstants.Markers.APP0: this.ProcessApplicationHeader(remaining); break; - case JpegConstants.Markers.APP1: + case OldJpegConstants.Markers.APP1: this.ProcessApp1Marker(remaining, metadata); break; - case JpegConstants.Markers.APP2: + case OldJpegConstants.Markers.APP2: this.ProcessApp2Marker(remaining, metadata); break; - case JpegConstants.Markers.APP14: + case OldJpegConstants.Markers.APP14: this.ProcessApp14Marker(remaining); break; default: - if ((marker >= JpegConstants.Markers.APP0 && marker <= JpegConstants.Markers.APP15) - || marker == JpegConstants.Markers.COM) + if ((marker >= OldJpegConstants.Markers.APP0 && marker <= OldJpegConstants.Markers.APP15) + || marker == OldJpegConstants.Markers.COM) { this.InputProcessor.Skip(remaining); } - else if (marker < JpegConstants.Markers.SOF0) + else if (marker < OldJpegConstants.Markers.SOF0) { // See Table B.1 "Marker code assignments". throw new ImageFormatException("Unknown marker"); @@ -451,17 +448,17 @@ private void ProcessStream(ImageMetaData metadata, Stream stream, bool metadataO /// private void ProcessStartOfScan(int remaining) { - JpegScanDecoder scan = default(JpegScanDecoder); - JpegScanDecoder.InitStreamReading(&scan, this, remaining); + OldJpegScanDecoder scan = default(OldJpegScanDecoder); + OldJpegScanDecoder.InitStreamReading(&scan, this, remaining); this.InputProcessor.Bits = default(Bits); this.MakeImage(); scan.DecodeBlocks(this); } /// - /// Process the blocks in into Jpeg image channels ( and ) + /// Process the blocks in into Jpeg image channels ( and ) /// are in a "raw" frequency-domain form. We need to apply IDCT, dequantization and unzigging to transform them into color-space blocks. - /// We can copy these blocks into -s afterwards. + /// We can copy these blocks into -s afterwards. /// /// The pixel type private void ProcessBlocksIntoJpegImageChannels() @@ -479,7 +476,7 @@ private void ProcessBlocksIntoJpegImageChannels() } /// - /// Convert the pixel data in and/or into pixels of + /// Convert the pixel data in and/or into pixels of /// /// The pixel type /// The metadata for the image. @@ -507,11 +504,11 @@ private Image ConvertJpegPixelsToImagePixels(ImageMetaData metad // See http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html#Adobe // See https://docs.oracle.com/javase/8/docs/api/javax/imageio/metadata/doc-files/jpeg_metadata.html // TODO: YCbCrA? - if (this.adobeTransform == JpegConstants.Adobe.ColorTransformYcck) + if (this.adobeTransform == OldJpegConstants.Adobe.ColorTransformYcck) { this.ConvertFromYcck(image); } - else if (this.adobeTransform == JpegConstants.Adobe.ColorTransformUnknown) + else if (this.adobeTransform == OldJpegConstants.Adobe.ColorTransformUnknown) { // Assume CMYK this.ConvertFromCmyk(image); @@ -763,7 +760,7 @@ private bool IsRGB() return false; } - if (this.adobeTransformValid && this.adobeTransform == JpegConstants.Adobe.ColorTransformUnknown) + if (this.adobeTransformValid && this.adobeTransform == OldJpegConstants.Adobe.ColorTransformUnknown) { // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html#Adobe // says that 0 means Unknown (and in practice RGB) and 1 means YCbCr. @@ -787,7 +784,7 @@ private void MakeImage() if (this.ComponentCount == 1) { Buffer2D buffer = Buffer2D.CreateClean(8 * this.MCUCountX, 8 * this.MCUCountY); - this.grayImage = new JpegPixelArea(buffer); + this.grayImage = new OldJpegPixelArea(buffer); } else { @@ -827,7 +824,7 @@ private void MakeImage() int v3 = this.ComponentArray[3].VerticalFactor; Buffer2D buffer = Buffer2D.CreateClean(8 * h3 * this.MCUCountX, 8 * v3 * this.MCUCountY); - this.blackImage = new JpegPixelArea(buffer); + this.blackImage = new OldJpegPixelArea(buffer); } } } @@ -1061,18 +1058,18 @@ private void ProcessDefineHuffmanTablesMarker(int remaining) this.InputProcessor.ReadFull(this.Temp, 0, 17); int tc = this.Temp[0] >> 4; - if (tc > HuffmanTree.MaxTc) + if (tc > OldHuffmanTree.MaxTc) { throw new ImageFormatException("Bad Tc value"); } int th = this.Temp[0] & 0x0f; - if (th > HuffmanTree.MaxTh || (!this.IsProgressive && (th > 1))) + if (th > OldHuffmanTree.MaxTh || (!this.IsProgressive && (th > 1))) { throw new ImageFormatException("Bad Th value"); } - int huffTreeIndex = (tc * HuffmanTree.ThRowSize) + th; + int huffTreeIndex = (tc * OldHuffmanTree.ThRowSize) + th; this.HuffmanTrees[huffTreeIndex].ProcessDefineHuffmanTablesMarkerLoop( ref this.InputProcessor, this.Temp, diff --git a/src/ImageSharp/Formats/Jpeg/Utils/MutableSpan.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Utils/MutableSpan.cs similarity index 93% rename from src/ImageSharp/Formats/Jpeg/Utils/MutableSpan.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Utils/MutableSpan.cs index 99d1c3e04e..0b8248f553 100644 --- a/src/ImageSharp/Formats/Jpeg/Utils/MutableSpan.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Utils/MutableSpan.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Utils +{ /// /// Like corefxlab Span, but with an AddOffset() method for efficiency. /// TODO: When Span will be official, consider replacing this class! diff --git a/src/ImageSharp/Formats/Jpeg/Utils/MutableSpanExtensions.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Utils/MutableSpanExtensions.cs similarity index 95% rename from src/ImageSharp/Formats/Jpeg/Utils/MutableSpanExtensions.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Utils/MutableSpanExtensions.cs index 45ecfc0920..5119c88473 100644 --- a/src/ImageSharp/Formats/Jpeg/Utils/MutableSpanExtensions.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Utils/MutableSpanExtensions.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System.Numerics; - using System.Runtime.CompilerServices; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Utils +{ /// /// MutableSpan Extensions /// diff --git a/src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Utils/OldJpegUtils.cs similarity index 89% rename from src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Utils/OldJpegUtils.cs index afb8e07007..a6e9762587 100644 --- a/src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Utils/OldJpegUtils.cs @@ -1,19 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats.Jpg -{ - using System; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - using ImageSharp.PixelFormats; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Utils +{ /// /// Jpeg specific utilities and extension methods /// - internal static unsafe class JpegUtils + internal static unsafe class OldJpegUtils { /// /// Copy a region of an image into dest. De "outlier" area will be stretched out with pixels on the right and bottom of the image. diff --git a/src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs b/src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs index 6830e2e4a5..4cbd8379a7 100644 --- a/src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs +++ b/src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Image decoder for generating an image out of a jpg stream. /// diff --git a/src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs b/src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs index 947c98ee2a..7867056bfc 100644 --- a/src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs +++ b/src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Encoder for writing the data image to a stream in jpeg format. /// diff --git a/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs b/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs index 8fbf9e5a74..e0ae0c5a39 100644 --- a/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs +++ b/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.IO; - - using Formats; - - using ImageSharp.PixelFormats; +using System; +using System.IO; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,14 +20,9 @@ public static partial class ImageExtensions /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsJpeg(this Image source, Stream stream) + public static void SaveAsJpeg(this Image source, Stream stream) where TPixel : struct, IPixel - { - return SaveAsJpeg(source, stream, null); - } + => SaveAsJpeg(source, stream, null); /// /// Saves the image to the given stream with the jpeg format. @@ -41,16 +32,8 @@ public static Image SaveAsJpeg(this Image source, Stream /// The stream to save the image to. /// The options for the encoder. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsJpeg(this Image source, Stream stream, JpegEncoder encoder) + public static void SaveAsJpeg(this Image source, Stream stream, JpegEncoder encoder) where TPixel : struct, IPixel - { - encoder = encoder ?? new JpegEncoder(); - encoder.Encode(source, stream); - - return source; - } + => source.Save(stream, encoder ?? source.Configuration.FindEncoder(ImageFormats.Jpeg)); } } diff --git a/src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs b/src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs index bb8c4e83f2..43f56caecd 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Registers the image encoders, decoders and mime type detectors for the jpeg format. diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs index b3caddeca7..dd185f26a5 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs @@ -1,16 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - - using ImageSharp.PixelFormats; +using System.IO; +using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Image decoder for generating an image out of a jpg stream. /// @@ -25,12 +21,12 @@ public sealed class JpegDecoder : IImageDecoder, IJpegDecoderOptions public Image Decode(Configuration configuration, Stream stream) where TPixel : struct, IPixel { - Guard.NotNull(stream, "stream"); + Guard.NotNull(stream, nameof(stream)); - using (JpegDecoderCore decoder = new JpegDecoderCore(configuration, this)) + using (var decoder = new JpegDecoderCore(configuration, this)) { return decoder.Decode(stream); } } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs index 6c6561468f..f95ba002bd 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs @@ -1,16 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - - using ImageSharp.PixelFormats; +using System.IO; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Encoder for writing the data image to a stream in jpeg format. /// diff --git a/src/ImageSharp/Formats/Jpeg/JpegFormat.cs b/src/ImageSharp/Formats/Jpeg/JpegFormat.cs index 23cd5d8752..2b7cd79789 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegFormat.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegFormat.cs @@ -1,12 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System.Collections.Generic; +using System.Collections.Generic; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; +namespace SixLabors.ImageSharp.Formats +{ /// /// Registers the image encoders, decoders and mime type detectors for the jpeg format. /// @@ -19,9 +18,9 @@ internal sealed class JpegFormat : IImageFormat public string DefaultMimeType => "image/jpeg"; /// - public IEnumerable MimeTypes => JpegConstants.MimeTypes; + public IEnumerable MimeTypes => OldJpegConstants.MimeTypes; /// - public IEnumerable FileExtensions => JpegConstants.FileExtensions; + public IEnumerable FileExtensions => OldJpegConstants.FileExtensions; } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs b/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs index b72b290c04..32bd904f03 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; +using System; +namespace SixLabors.ImageSharp.Formats +{ /// /// Detects Jpeg file headers /// diff --git a/src/ImageSharp/Formats/Jpeg/JpegSubsample.cs b/src/ImageSharp/Formats/Jpeg/JpegSubsample.cs index 287323bdd4..971a749314 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegSubsample.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegSubsample.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Enumerates the chroma subsampling method applied to the image. diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/Adobe.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/Adobe.cs new file mode 100644 index 0000000000..fdc6ed2ca6 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/Adobe.cs @@ -0,0 +1,72 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; + +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// Provides information about the Adobe marker segment + /// + internal struct Adobe : IEquatable + { + /// + /// The DCT Encode Version + /// + public short DCTEncodeVersion; + + /// + /// 0x0 : (none) + /// Bit 15 : Encoded with Blend=1 downsampling + /// + public short APP14Flags0; + + /// + /// 0x0 : (none) + /// + public short APP14Flags1; + + /// + /// Determines the colorspace transform + /// 00 : Unknown (RGB or CMYK) + /// 01 : YCbCr + /// 02 : YCCK + /// + public byte ColorTransform; + + /// + public bool Equals(Adobe other) + { + return this.DCTEncodeVersion == other.DCTEncodeVersion + && this.APP14Flags0 == other.APP14Flags0 + && this.APP14Flags1 == other.APP14Flags1 + && this.ColorTransform == other.ColorTransform; + } + + /// + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + + return obj is Adobe && this.Equals((Adobe)obj); + } + + /// + public override int GetHashCode() + { + unchecked + { + // TODO: Merge and use HashCodeHelpers + int hashCode = this.DCTEncodeVersion.GetHashCode(); + hashCode = (hashCode * 397) ^ this.APP14Flags0.GetHashCode(); + hashCode = (hashCode * 397) ^ this.APP14Flags1.GetHashCode(); + hashCode = (hashCode * 397) ^ this.ColorTransform.GetHashCode(); + return hashCode; + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/Component.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/Component.cs new file mode 100644 index 0000000000..2f167c251c --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/Component.cs @@ -0,0 +1,42 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Numerics; +using SixLabors.ImageSharp.Memory; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// Represents a component block + /// + internal struct Component : IDisposable + { + /// + /// Gets or sets the output + /// + public Buffer Output; + + /// + /// Gets or sets the scaling factors + /// + public Vector2 Scale; + + /// + /// Gets or sets the number of blocks per line + /// + public int BlocksPerLine; + + /// + /// Gets or sets the number of blocks per column + /// + public int BlocksPerColumn; + + /// + public void Dispose() + { + this.Output?.Dispose(); + this.Output = null; + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ComponentBlocks.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ComponentBlocks.cs new file mode 100644 index 0000000000..ffcd321091 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ComponentBlocks.cs @@ -0,0 +1,32 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// Contains all the decoded component blocks + /// + internal sealed class ComponentBlocks : IDisposable + { + /// + /// Gets or sets the component blocks + /// + public Component[] Components { get; set; } + + /// + public void Dispose() + { + if (this.Components != null) + { + for (int i = 0; i < this.Components.Length; i++) + { + this.Components[i].Dispose(); + } + + this.Components = null; + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FileMarker.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FileMarker.cs new file mode 100644 index 0000000000..d0182b63aa --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FileMarker.cs @@ -0,0 +1,57 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// Represents a jpeg file marker + /// + internal struct FileMarker + { + /// + /// Initializes a new instance of the struct. + /// + /// The marker + /// The position within the stream + public FileMarker(ushort marker, long position) + { + this.Marker = marker; + this.Position = position; + this.Invalid = false; + } + + /// + /// Initializes a new instance of the struct. + /// + /// The marker + /// The position within the stream + /// Whether the current marker is invalid + public FileMarker(ushort marker, long position, bool invalid) + { + this.Marker = marker; + this.Position = position; + this.Invalid = invalid; + } + + /// + /// Gets or sets a value indicating whether the current marker is invalid + /// + public bool Invalid { get; set; } + + /// + /// Gets the position of the marker within a stream + /// + public ushort Marker { get; } + + /// + /// Gets the position of the marker within a stream + /// + public long Position { get; } + + /// + public override string ToString() + { + return this.Marker.ToString("X"); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/Frame.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/Frame.cs new file mode 100644 index 0000000000..e7eabcdc8b --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/Frame.cs @@ -0,0 +1,87 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// Represent a single jpeg frame + /// + internal sealed class Frame : IDisposable + { + /// + /// Gets or sets a value indicating whether the frame uses the extended specification + /// + public bool Extended { get; set; } + + /// + /// Gets or sets a value indicating whether the frame uses the progressive specification + /// + public bool Progressive { get; set; } + + /// + /// Gets or sets the precision + /// + public byte Precision { get; set; } + + /// + /// Gets or sets the number of scanlines within the frame + /// + public short Scanlines { get; set; } + + /// + /// Gets or sets the number of samples per scanline + /// + public short 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 + /// + public byte ComponentCount { get; set; } + + /// + /// Gets or sets the component id collection + /// + public byte[] ComponentIds { get; set; } + + /// + /// Gets or sets the frame component collection + /// + public FrameComponent[] Components { get; set; } + + /// + /// Gets or sets the maximum horizontal sampling factor + /// + public int MaxHorizontalFactor { get; set; } + + /// + /// Gets or sets the maximum vertical sampling factor + /// + public int MaxVerticalFactor { get; set; } + + /// + /// Gets or sets the number of MCU's per line + /// + public int McusPerLine { get; set; } + + /// + /// Gets or sets the number of MCU's per column + /// + public int McusPerColumn { get; set; } + + /// + public void Dispose() + { + if (this.Components != null) + { + for (int i = 0; i < this.Components.Length; i++) + { + this.Components[i].Dispose(); + } + + this.Components = null; + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FrameComponent.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FrameComponent.cs new file mode 100644 index 0000000000..1bb78a84db --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FrameComponent.cs @@ -0,0 +1,71 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.Memory; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// Represents a single frame component + /// + internal struct FrameComponent : IDisposable + { + /// + /// Gets or sets the component Id + /// + public byte Id; + + /// + /// TODO: What does pred stand for? + /// + public int Pred; + + /// + /// Gets or sets the horizontal sampling factor. + /// + public int HorizontalFactor; + + /// + /// Gets or sets the vertical sampling factor. + /// + public int VerticalFactor; + + /// + /// Gets or sets the identifier + /// + public byte QuantizationIdentifier; + + /// + /// Gets or sets the block data + /// + public Buffer BlockData; + + /// + /// Gets or sets the number of blocks per line + /// + public int BlocksPerLine; + + /// + /// Gets or sets the number of blocks per column + /// + public int BlocksPerColumn; + + /// + /// Gets the index for the DC Huffman table + /// + public int DCHuffmanTableId; + + /// + /// Gets the index for the AC Huffman table + /// + public int ACHuffmanTableId; + + /// + public void Dispose() + { + this.BlockData?.Dispose(); + this.BlockData = null; + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/HuffmanTable.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/HuffmanTable.cs new file mode 100644 index 0000000000..1c8a8fc428 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/HuffmanTable.cs @@ -0,0 +1,209 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Memory; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// Represents a Huffman Table + /// + internal struct HuffmanTable : IDisposable + { + private Buffer lookahead; + private Buffer valOffset; + private Buffer maxcode; + private Buffer huffval; + + /// + /// Initializes a new instance of the struct. + /// + /// The code lengths + /// The huffman values + public HuffmanTable(byte[] lengths, byte[] values) + { + this.lookahead = Buffer.CreateClean(256); + this.valOffset = Buffer.CreateClean(18); + this.maxcode = Buffer.CreateClean(18); + + using (var huffsize = Buffer.CreateClean(257)) + using (var huffcode = Buffer.CreateClean(257)) + { + GenerateSizeTable(lengths, huffsize); + GenerateCodeTable(huffsize, huffcode); + GenerateDecoderTables(lengths, huffcode, this.valOffset, this.maxcode); + GenerateLookaheadTables(lengths, values, this.lookahead); + } + + this.huffval = Buffer.CreateClean(values.Length); + Buffer.BlockCopy(values, 0, this.huffval.Array, 0, values.Length); + + this.MaxCode = this.maxcode.Array; + this.ValOffset = this.valOffset.Array; + this.HuffVal = this.huffval.Array; + this.Lookahead = this.lookahead.Array; + } + + /// + /// Gets the max code array + /// + public long[] MaxCode + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; + } + + /// + /// Gets the value offset array + /// + public short[] ValOffset + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; + } + + /// + /// Gets the huffman value array + /// + public byte[] HuffVal + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; + } + + /// + /// Gets the lookahead array + /// + public short[] Lookahead + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; + } + + /// + public void Dispose() + { + this.lookahead?.Dispose(); + this.valOffset?.Dispose(); + this.maxcode?.Dispose(); + this.huffval?.Dispose(); + + this.lookahead = null; + this.valOffset = null; + this.maxcode = null; + this.huffval = null; + } + + /// + /// Figure C.1: make table of Huffman code length for each symbol + /// + /// The code lengths + /// The huffman size span + private static void GenerateSizeTable(byte[] lengths, Span huffsize) + { + short index = 0; + for (short l = 1; l <= 16; l++) + { + byte i = lengths[l]; + for (short j = 0; j < i; j++) + { + huffsize[index] = l; + index++; + } + } + + huffsize[index] = 0; + } + + /// + /// Figure C.2: generate the codes themselves + /// + /// The huffman size span + /// The huffman code span + private static void GenerateCodeTable(Span huffsize, Span huffcode) + { + short k = 0; + short si = huffsize[0]; + short code = 0; + for (short i = 0; i < huffsize.Length; i++) + { + while (huffsize[k] == si) + { + huffcode[k] = code; + code++; + k++; + } + + code <<= 1; + si++; + } + } + + /// + /// Figure F.15: generate decoding tables for bit-sequential decoding + /// + /// The code lengths + /// The huffman code span + /// The value offset span + /// The max code span + private static void GenerateDecoderTables(byte[] lengths, Span huffcode, Span valOffset, Span maxcode) + { + short bitcount = 0; + for (int i = 1; i <= 16; i++) + { + if (lengths[i] != 0) + { + // valoffset[l] = huffval[] index of 1st symbol of code length i, + // minus the minimum code of length i + valOffset[i] = (short)(bitcount - huffcode[bitcount]); + bitcount += lengths[i]; + maxcode[i] = huffcode[bitcount - 1]; // maximum code of length i + } + else + { + maxcode[i] = -1; // -1 if no codes of this length + } + } + + valOffset[17] = 0; + maxcode[17] = 0xFFFFFL; + } + + /// + /// Generates lookup tables to speed up decoding + /// + /// The code lengths + /// The huffman value array + /// The lookahead span + private static void GenerateLookaheadTables(byte[] lengths, byte[] huffval, Span lookahead) + { + int x = 0, code = 0; + + for (int i = 0; i < 8; i++) + { + code <<= 1; + + for (int j = 0; j < lengths[i + 1]; j++) + { + // The codeLength is 1+i, so shift code by 8-(1+i) to + // calculate the high bits for every 8-bit sequence + // whose codeLength's high bits matches code. + // The high 8 bits of lutValue are the encoded value. + // The low 8 bits are 1 plus the codeLength. + byte base2 = (byte)(code << (7 - i)); + short lutValue = (short)((short)(huffval[x] << 8) | (short)(2 + i)); + + for (int k = 0; k < 1 << (7 - i); k++) + { + lookahead[base2 | k] = lutValue; + } + + code++; + x++; + } + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/HuffmanTables.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/HuffmanTables.cs new file mode 100644 index 0000000000..46487c0259 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/HuffmanTables.cs @@ -0,0 +1,40 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// Defines a pair of huffman tables + /// + internal sealed class HuffmanTables : IDisposable + { + private readonly HuffmanTable[] tables = new HuffmanTable[4]; + + /// + /// Gets or sets the table at the given index. + /// + /// The index + /// The + public ref HuffmanTable this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return ref this.tables[index]; + } + } + + /// + public void Dispose() + { + for (int i = 0; i < this.tables.Length; i++) + { + this.tables[i].Dispose(); + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/IDCT.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/IDCT.cs new file mode 100644 index 0000000000..7a1a2114fc --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/IDCT.cs @@ -0,0 +1,509 @@ +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + using System; + using System.Runtime.CompilerServices; + + /// + /// Performs the inverse Descrete Cosine Transform on each frame component. + /// + internal static class IDCT + { + /// + /// Precomputed values scaled up by 14 bits + /// + public static readonly short[] Aanscales = + { + 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, 22725, 31521, 29692, 26722, 22725, 17855, + 12299, 6270, 21407, 29692, 27969, 25172, 21407, 16819, 11585, + 5906, 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, + 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, 12873, + 17855, 16819, 15137, 12873, 10114, 6967, 3552, 8867, 12299, + 11585, 10426, 8867, 6967, 4799, 2446, 4520, 6270, 5906, 5315, + 4520, 3552, 2446, 1247 + }; + + private const int DctCos1 = 4017; // cos(pi/16) + private const int DctSin1 = 799; // sin(pi/16) + private const int DctCos3 = 3406; // cos(3*pi/16) + private const int DctSin3 = 2276; // sin(3*pi/16) + private const int DctCos6 = 1567; // cos(6*pi/16) + private const int DctSin6 = 3784; // sin(6*pi/16) + private const int DctSqrt2 = 5793; // sqrt(2) + private const int DctSqrt1D2 = 2896; // sqrt(2) / 2 + +#pragma warning disable SA1310 // Field names must not contain underscore + private const int FIX_1_082392200 = 277; // FIX(1.082392200) + private const int FIX_1_414213562 = 362; // FIX(1.414213562) + private const int FIX_1_847759065 = 473; // FIX(1.847759065) + private const int FIX_2_613125930 = 669; // FIX(2.613125930) +#pragma warning restore SA1310 // Field names must not contain underscore + + private const int ConstBits = 8; + private const int Pass1Bits = 2; // Factional bits in scale factors + private const int MaxJSample = 255; + private const int CenterJSample = 128; + private const int RangeCenter = (MaxJSample * 2) + 2; + + // First segment of range limit table: limit[x] = 0 for x < 0 + // allow negative subscripts of simple table + private const int TableOffset = 2 * (MaxJSample + 1); + private const int LimitOffset = TableOffset - (RangeCenter - CenterJSample); + + // Each IDCT routine is responsible for range-limiting its results and + // converting them to unsigned form (0..MaxJSample). The raw outputs could + // be quite far out of range if the input data is corrupt, so a bulletproof + // range-limiting step is required. We use a mask-and-table-lookup method + // to do the combined operations quickly, assuming that MaxJSample+1 + // is a power of 2. + private const int RangeMask = (MaxJSample * 4) + 3; // 2 bits wider than legal samples + + private static readonly byte[] Limit = new byte[5 * (MaxJSample + 1)]; + + static IDCT() + { + // Main part of range limit table: limit[x] = x + int i; + for (i = 0; i <= MaxJSample; i++) + { + Limit[TableOffset + i] = (byte)i; + } + + // End of range limit table: Limit[x] = MaxJSample for x > MaxJSample + for (; i < 3 * (MaxJSample + 1); i++) + { + Limit[TableOffset + i] = MaxJSample; + } + } + + /// + /// A port of Poppler's IDCT method which in turn is taken from: + /// Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz, + /// 'Practical Fast 1-D DCT Algorithms with 11 Multiplications', + /// IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989, 988-991. + /// + /// The fram component + /// The block buffer offset + /// The computational buffer for holding temp values + /// The quantization table + public static void QuantizeAndInverse(ref FrameComponent component, int blockBufferOffset, ref Span computationBuffer, ref Span quantizationTable) + { + Span blockData = component.BlockData.Slice(blockBufferOffset); + int v0, v1, v2, v3, v4, v5, v6, v7; + int p0, p1, p2, p3, p4, p5, p6, p7; + int t; + + // inverse DCT on rows + for (int row = 0; row < 64; row += 8) + { + // gather block data + p0 = blockData[row]; + p1 = blockData[row + 1]; + p2 = blockData[row + 2]; + p3 = blockData[row + 3]; + p4 = blockData[row + 4]; + p5 = blockData[row + 5]; + p6 = blockData[row + 6]; + p7 = blockData[row + 7]; + + // dequant p0 + p0 *= quantizationTable[row]; + + // check for all-zero AC coefficients + if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) == 0) + { + t = ((DctSqrt2 * p0) + 512) >> 10; + short st = (short)t; + computationBuffer[row] = st; + computationBuffer[row + 1] = st; + computationBuffer[row + 2] = st; + computationBuffer[row + 3] = st; + computationBuffer[row + 4] = st; + computationBuffer[row + 5] = st; + computationBuffer[row + 6] = st; + computationBuffer[row + 7] = st; + continue; + } + + // dequant p1 ... p7 + p1 *= quantizationTable[row + 1]; + p2 *= quantizationTable[row + 2]; + p3 *= quantizationTable[row + 3]; + p4 *= quantizationTable[row + 4]; + p5 *= quantizationTable[row + 5]; + p6 *= quantizationTable[row + 6]; + p7 *= quantizationTable[row + 7]; + + // stage 4 + v0 = ((DctSqrt2 * p0) + 128) >> 8; + v1 = ((DctSqrt2 * p4) + 128) >> 8; + v2 = p2; + v3 = p6; + v4 = ((DctSqrt1D2 * (p1 - p7)) + 128) >> 8; + v7 = ((DctSqrt1D2 * (p1 + p7)) + 128) >> 8; + v5 = p3 << 4; + v6 = p5 << 4; + + // stage 3 + v0 = (v0 + v1 + 1) >> 1; + v1 = v0 - v1; + t = ((v2 * DctSin6) + (v3 * DctCos6) + 128) >> 8; + v2 = ((v2 * DctCos6) - (v3 * DctSin6) + 128) >> 8; + v3 = t; + v4 = (v4 + v6 + 1) >> 1; + v6 = v4 - v6; + v7 = (v7 + v5 + 1) >> 1; + v5 = v7 - v5; + + // stage 2 + v0 = (v0 + v3 + 1) >> 1; + v3 = v0 - v3; + v1 = (v1 + v2 + 1) >> 1; + v2 = v1 - v2; + t = ((v4 * DctSin3) + (v7 * DctCos3) + 2048) >> 12; + v4 = ((v4 * DctCos3) - (v7 * DctSin3) + 2048) >> 12; + v7 = t; + t = ((v5 * DctSin1) + (v6 * DctCos1) + 2048) >> 12; + v5 = ((v5 * DctCos1) - (v6 * DctSin1) + 2048) >> 12; + v6 = t; + + // stage 1 + computationBuffer[row] = (short)(v0 + v7); + computationBuffer[row + 7] = (short)(v0 - v7); + computationBuffer[row + 1] = (short)(v1 + v6); + computationBuffer[row + 6] = (short)(v1 - v6); + computationBuffer[row + 2] = (short)(v2 + v5); + computationBuffer[row + 5] = (short)(v2 - v5); + computationBuffer[row + 3] = (short)(v3 + v4); + computationBuffer[row + 4] = (short)(v3 - v4); + } + + // inverse DCT on columns + for (int col = 0; col < 8; ++col) + { + p0 = computationBuffer[col]; + p1 = computationBuffer[col + 8]; + p2 = computationBuffer[col + 16]; + p3 = computationBuffer[col + 24]; + p4 = computationBuffer[col + 32]; + p5 = computationBuffer[col + 40]; + p6 = computationBuffer[col + 48]; + p7 = computationBuffer[col + 56]; + + // check for all-zero AC coefficients + if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) == 0) + { + t = ((DctSqrt2 * p0) + 8192) >> 14; + + // convert to 8 bit + t = (t < -2040) ? 0 : (t >= 2024) ? MaxJSample : (t + 2056) >> 4; + short st = (short)t; + + blockData[col] = st; + blockData[col + 8] = st; + blockData[col + 16] = st; + blockData[col + 24] = st; + blockData[col + 32] = st; + blockData[col + 40] = st; + blockData[col + 48] = st; + blockData[col + 56] = st; + continue; + } + + // stage 4 + v0 = ((DctSqrt2 * p0) + 2048) >> 12; + v1 = ((DctSqrt2 * p4) + 2048) >> 12; + v2 = p2; + v3 = p6; + v4 = ((DctSqrt1D2 * (p1 - p7)) + 2048) >> 12; + v7 = ((DctSqrt1D2 * (p1 + p7)) + 2048) >> 12; + v5 = p3; + v6 = p5; + + // stage 3 + // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when + // converting to UInt8 range later. + v0 = ((v0 + v1 + 1) >> 1) + 4112; + v1 = v0 - v1; + t = ((v2 * DctSin6) + (v3 * DctCos6) + 2048) >> 12; + v2 = ((v2 * DctCos6) - (v3 * DctSin6) + 2048) >> 12; + v3 = t; + v4 = (v4 + v6 + 1) >> 1; + v6 = v4 - v6; + v7 = (v7 + v5 + 1) >> 1; + v5 = v7 - v5; + + // stage 2 + v0 = (v0 + v3 + 1) >> 1; + v3 = v0 - v3; + v1 = (v1 + v2 + 1) >> 1; + v2 = v1 - v2; + t = ((v4 * DctSin3) + (v7 * DctCos3) + 2048) >> 12; + v4 = ((v4 * DctCos3) - (v7 * DctSin3) + 2048) >> 12; + v7 = t; + t = ((v5 * DctSin1) + (v6 * DctCos1) + 2048) >> 12; + v5 = ((v5 * DctCos1) - (v6 * DctSin1) + 2048) >> 12; + v6 = t; + + // stage 1 + p0 = v0 + v7; + p7 = v0 - v7; + p1 = v1 + v6; + p6 = v1 - v6; + p2 = v2 + v5; + p5 = v2 - v5; + p3 = v3 + v4; + p4 = v3 - v4; + + // convert to 8-bit integers + p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? MaxJSample : p0 >> 4; + p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? MaxJSample : p1 >> 4; + p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? MaxJSample : p2 >> 4; + p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? MaxJSample : p3 >> 4; + p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? MaxJSample : p4 >> 4; + p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? MaxJSample : p5 >> 4; + p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? MaxJSample : p6 >> 4; + p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? MaxJSample : p7 >> 4; + + // store block data + blockData[col] = (short)p0; + blockData[col + 8] = (short)p1; + blockData[col + 16] = (short)p2; + blockData[col + 24] = (short)p3; + blockData[col + 32] = (short)p4; + blockData[col + 40] = (short)p5; + blockData[col + 48] = (short)p6; + blockData[col + 56] = (short)p7; + } + } + + /// + /// A port of + /// A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT + /// on each row(or vice versa, but it's more convenient to emit a row at + /// a time). Direct algorithms are also available, but they are much more + /// complex and seem not to be any faster when reduced to code. + /// + /// This implementation is based on Arai, Agui, and Nakajima's algorithm for + /// scaled DCT.Their original paper (Trans.IEICE E-71(11):1095) is in + /// Japanese, but the algorithm is described in the Pennebaker & Mitchell + /// JPEG textbook(see REFERENCES section in file README.ijg). The following + /// code is based directly on figure 4-8 in P&M. + /// While an 8-point DCT cannot be done in less than 11 multiplies, it is + /// possible to arrange the computation so that many of the multiplies are + /// simple scalings of the final outputs.These multiplies can then be + /// folded into the multiplications or divisions by the JPEG quantization + /// table entries. The AA&N method leaves only 5 multiplies and 29 adds + /// to be done in the DCT itself. + /// The primary disadvantage of this method is that with fixed-point math, + /// accuracy is lost due to imprecise representation of the scaled + /// quantization values.The smaller the quantization table entry, the less + /// precise the scaled value, so this implementation does worse with high - + /// quality - setting files than with low - quality ones. + /// + /// The frame component + /// The block buffer offset + /// The computational buffer for holding temp values + /// The multiplier table + public static void QuantizeAndInverseFast(ref FrameComponent component, int blockBufferOffset, ref Span computationBuffer, ref Span multiplierTable) + { + Span blockData = component.BlockData.Slice(blockBufferOffset); + int p0, p1, p2, p3, p4, p5, p6, p7; + + for (int col = 0; col < 8; col++) + { + // Gather block data + p0 = blockData[col]; + p1 = blockData[col + 8]; + p2 = blockData[col + 16]; + p3 = blockData[col + 24]; + p4 = blockData[col + 32]; + p5 = blockData[col + 40]; + p6 = blockData[col + 48]; + p7 = blockData[col + 56]; + + int tmp0 = p0 * multiplierTable[col]; + + // Due to quantization, we will usually find that many of the input + // coefficients are zero, especially the AC terms. We can exploit this + // by short-circuiting the IDCT calculation for any column in which all + // the AC terms are zero. In that case each output is equal to the + // DC coefficient (with scale factor as needed). + // With typical images and quantization tables, half or more of the + // column DCT calculations can be simplified this way. + if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) == 0) + { + short dcval = (short)tmp0; + + computationBuffer[col] = dcval; + computationBuffer[col + 8] = dcval; + computationBuffer[col + 16] = dcval; + computationBuffer[col + 24] = dcval; + computationBuffer[col + 32] = dcval; + computationBuffer[col + 40] = dcval; + computationBuffer[col + 48] = dcval; + computationBuffer[col + 56] = dcval; + + continue; + } + + // Even part + int tmp1 = p2 * multiplierTable[col + 16]; + int tmp2 = p4 * multiplierTable[col + 32]; + int tmp3 = p6 * multiplierTable[col + 48]; + + int tmp10 = tmp0 + tmp2; // Phase 3 + int tmp11 = tmp0 - tmp2; + + int tmp13 = tmp1 + tmp3; // Phases 5-3 + int tmp12 = Multiply(tmp1 - tmp3, FIX_1_414213562) - tmp13; // 2*c4 + + tmp0 = tmp10 + tmp13; // Phase 2 + tmp3 = tmp10 - tmp13; + tmp1 = tmp11 + tmp12; + tmp2 = tmp11 - tmp12; + + // Odd Part + int tmp4 = p1 * multiplierTable[col + 8]; + int tmp5 = p3 * multiplierTable[col + 24]; + int tmp6 = p5 * multiplierTable[col + 40]; + int tmp7 = p7 * multiplierTable[col + 56]; + + int z13 = tmp6 + tmp5; // Phase 6 + int z10 = tmp6 - tmp5; + int z11 = tmp4 + tmp7; + int z12 = tmp4 - tmp7; + + tmp7 = z11 + z13; // Phase 5 + tmp11 = Multiply(z11 - z13, FIX_1_414213562); // 2*c4 + + int z5 = Multiply(z10 + z12, FIX_1_847759065); // 2*c2 + tmp10 = z5 - Multiply(z12, FIX_1_082392200); // 2*(c2-c6) + tmp12 = z5 - Multiply(z10, FIX_2_613125930); // 2*(c2+c6) + + tmp6 = tmp12 - tmp7; // Phase 2 + tmp5 = tmp11 - tmp6; + tmp4 = tmp10 - tmp5; + + computationBuffer[col] = (short)(tmp0 + tmp7); + computationBuffer[col + 56] = (short)(tmp0 - tmp7); + computationBuffer[col + 8] = (short)(tmp1 + tmp6); + computationBuffer[col + 48] = (short)(tmp1 - tmp6); + computationBuffer[col + 16] = (short)(tmp2 + tmp5); + computationBuffer[col + 40] = (short)(tmp2 - tmp5); + computationBuffer[col + 24] = (short)(tmp3 + tmp4); + computationBuffer[col + 32] = (short)(tmp3 - tmp4); + } + + // Pass 2: process rows from work array, store into output array. + // Note that we must descale the results by a factor of 8 == 2**3, + // and also undo the pass 1 bits scaling. + for (int row = 0; row < 64; row += 8) + { + p1 = computationBuffer[row + 1]; + p2 = computationBuffer[row + 2]; + p3 = computationBuffer[row + 3]; + p4 = computationBuffer[row + 4]; + p5 = computationBuffer[row + 5]; + p6 = computationBuffer[row + 6]; + p7 = computationBuffer[row + 7]; + + // Add range center and fudge factor for final descale and range-limit. + int z5 = computationBuffer[row] + (RangeCenter << (Pass1Bits + 3)) + (1 << (Pass1Bits + 2)); + + // Check for all-zero AC coefficients + if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) == 0) + { + byte dcval = Limit[LimitOffset + (RightShift(z5, Pass1Bits + 3) & RangeMask)]; + + blockData[row] = dcval; + blockData[row + 1] = dcval; + blockData[row + 2] = dcval; + blockData[row + 3] = dcval; + blockData[row + 4] = dcval; + blockData[row + 5] = dcval; + blockData[row + 6] = dcval; + blockData[row + 7] = dcval; + + continue; + } + + // Even part + int tmp10 = z5 + p4; + int tmp11 = z5 - p4; + + int tmp13 = p2 + p6; + int tmp12 = Multiply(p2 - p6, FIX_1_414213562) - tmp13; // 2*c4 + + int tmp0 = tmp10 + tmp13; + int tmp3 = tmp10 - tmp13; + int tmp1 = tmp11 + tmp12; + int tmp2 = tmp11 - tmp12; + + // Odd part + int z13 = p5 + p3; + int z10 = p5 - p3; + int z11 = p1 + p7; + int z12 = p1 - p7; + + int tmp7 = z11 + z13; // Phase 5 + tmp11 = Multiply(z11 - z13, FIX_1_414213562); // 2*c4 + + z5 = Multiply(z10 + z12, FIX_1_847759065); // 2*c2 + tmp10 = z5 - Multiply(z12, FIX_1_082392200); // 2*(c2-c6) + tmp12 = z5 - Multiply(z10, FIX_2_613125930); // 2*(c2+c6) + + int tmp6 = tmp12 - tmp7; // Phase 2 + int tmp5 = tmp11 - tmp6; + int tmp4 = tmp10 - tmp5; + + // Final output stage: scale down by a factor of 8, offset, and range-limit + blockData[row] = Limit[LimitOffset + (RightShift(tmp0 + tmp7, Pass1Bits + 3) & RangeMask)]; + blockData[row + 7] = Limit[LimitOffset + (RightShift(tmp0 - tmp7, Pass1Bits + 3) & RangeMask)]; + blockData[row + 1] = Limit[LimitOffset + (RightShift(tmp1 + tmp6, Pass1Bits + 3) & RangeMask)]; + blockData[row + 6] = Limit[LimitOffset + (RightShift(tmp1 - tmp6, Pass1Bits + 3) & RangeMask)]; + blockData[row + 2] = Limit[LimitOffset + (RightShift(tmp2 + tmp5, Pass1Bits + 3) & RangeMask)]; + blockData[row + 5] = Limit[LimitOffset + (RightShift(tmp2 - tmp5, Pass1Bits + 3) & RangeMask)]; + blockData[row + 3] = Limit[LimitOffset + (RightShift(tmp3 + tmp4, Pass1Bits + 3) & RangeMask)]; + blockData[row + 4] = Limit[LimitOffset + (RightShift(tmp3 - tmp4, Pass1Bits + 3) & RangeMask)]; + } + } + + /// + /// Descale and correctly round an int value that's scaled by bits. + /// We assume rounds towards minus infinity, so adding + /// the fudge factor is correct for either sign of . + /// + /// The value + /// The number of bits + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Descale(int value, int n) + { + return RightShift(value + (1 << (n - 1)), n); + } + + /// + /// Multiply a variable by an int constant, and immediately descale. + /// + /// The value + /// The multiplier + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int Multiply(int val, int c) + { + return Descale(val * c, ConstBits); + } + + /// + /// Right-shifts the value by the given amount + /// + /// The value + /// The amount to shift by + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int RightShift(int value, int shift) + { + return value >> shift; + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/JFif.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/JFif.cs new file mode 100644 index 0000000000..57f023c2b8 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/JFif.cs @@ -0,0 +1,77 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// Provides information about the JFIF marker segment + /// TODO: Thumbnail? + /// + internal struct JFif : IEquatable + { + /// + /// The major version + /// + public byte MajorVersion; + + /// + /// The minor version + /// + public byte MinorVersion; + + /// + /// Units for the following pixel density fields + /// 00 : No units; width:height pixel aspect ratio = Ydensity:Xdensity + /// 01 : Pixels per inch (2.54 cm) + /// 02 : Pixels per centimeter + /// + public byte DensityUnits; + + /// + /// Horizontal pixel density. Must not be zero. + /// + public short XDensity; + + /// + /// Vertical pixel density. Must not be zero. + /// + public short YDensity; + + /// + public bool Equals(JFif other) + { + return this.MajorVersion == other.MajorVersion + && this.MinorVersion == other.MinorVersion + && this.DensityUnits == other.DensityUnits + && this.XDensity == other.XDensity + && this.YDensity == other.YDensity; + } + + /// + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + + return obj is JFif && this.Equals((JFif)obj); + } + + /// + public override int GetHashCode() + { + unchecked + { + int hashCode = this.MajorVersion.GetHashCode(); + hashCode = (hashCode * 397) ^ this.MinorVersion.GetHashCode(); + hashCode = (hashCode * 397) ^ this.DensityUnits.GetHashCode(); + hashCode = (hashCode * 397) ^ this.XDensity.GetHashCode(); + hashCode = (hashCode * 397) ^ this.YDensity.GetHashCode(); + return hashCode; + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/JpegPixelArea.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/JpegPixelArea.cs new file mode 100644 index 0000000000..f04b7dadd4 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/JpegPixelArea.cs @@ -0,0 +1,145 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Diagnostics; +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Memory; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// Represents a section of the jpeg component data laid out in pixel order. + /// + internal struct JpegPixelArea : IDisposable + { + private readonly int imageWidth; + + private readonly int imageHeight; + + private Buffer componentData; + + private int rowStride; + + /// + /// Initializes a new instance of the struct. + /// + /// The image width + /// The image height + /// The number of components + public JpegPixelArea(int imageWidth, int imageHeight, int numberOfComponents) + { + this.imageWidth = imageWidth; + this.imageHeight = imageHeight; + this.Width = 0; + this.Height = 0; + this.NumberOfComponents = numberOfComponents; + this.componentData = null; + this.rowStride = 0; + } + + /// + /// Gets the number of components + /// + public int NumberOfComponents { get; } + + /// + /// Gets the width + /// + public int Width { get; private set; } + + /// + /// Gets the height + /// + public int Height { get; private set; } + + /// + /// Organsizes the decoded jpeg components into a linear array ordered by component. + /// This must be called before attempting to retrieve the data. + /// + /// The jpeg component blocks + /// The pixel area width + /// The pixel area height + public void LinearizeBlockData(ComponentBlocks components, int width, int height) + { + this.Width = width; + this.Height = height; + int numberOfComponents = this.NumberOfComponents; + this.rowStride = width * numberOfComponents; + var scale = new Vector2(this.imageWidth / (float)width, this.imageHeight / (float)height); + + this.componentData = new Buffer(width * height * numberOfComponents); + Span componentDataSpan = this.componentData; + const uint Mask3Lsb = 0xFFFFFFF8; // Used to clear the 3 LSBs + + using (var xScaleBlockOffset = new Buffer(width)) + { + Span xScaleBlockOffsetSpan = xScaleBlockOffset; + for (int i = 0; i < numberOfComponents; i++) + { + ref Component component = ref components.Components[i]; + Vector2 componentScale = component.Scale * scale; + int offset = i; + Span output = component.Output; + int blocksPerScanline = (component.BlocksPerLine + 1) << 3; + + // Precalculate the xScaleBlockOffset + int j; + for (int x = 0; x < width; x++) + { + j = (int)(x * componentScale.X); + xScaleBlockOffsetSpan[x] = (int)((j & Mask3Lsb) << 3) | (j & 7); + } + + // Linearize the blocks of the component + for (int y = 0; y < height; y++) + { + j = (int)(y * componentScale.Y); + int index = blocksPerScanline * (int)(j & Mask3Lsb) | ((j & 7) << 3); + for (int x = 0; x < width; x++) + { + componentDataSpan[offset] = (byte)output[index + xScaleBlockOffsetSpan[x]]; + offset += numberOfComponents; + } + } + } + } + } + + /// + /// Gets a representing the row 'y' beginning from the the first byte on that row. + /// + /// The y-coordinate of the pixel row. Must be greater than or equal to zero and less than the height of the pixel area. + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Span GetRowSpan(int y) + { + this.CheckCoordinates(y); + return this.componentData.Slice(y * this.rowStride, this.rowStride); + } + + /// + public void Dispose() + { + this.componentData?.Dispose(); + this.componentData = null; + } + + /// + /// Checks the coordinates to ensure they are within bounds. + /// + /// The y-coordinate of the row. Must be greater than zero and less than the height of the area. + /// + /// Thrown if the coordinates are not within the bounds of the image. + /// + [Conditional("DEBUG")] + private void CheckCoordinates(int y) + { + if (y < 0 || y >= this.Height) + { + throw new ArgumentOutOfRangeException(nameof(y), y, $"{y} is outwith the area bounds."); + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/QuantizationTables.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/QuantizationTables.cs new file mode 100644 index 0000000000..35dd0111a7 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/QuantizationTables.cs @@ -0,0 +1,64 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Memory; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// Contains the quantization tables. + /// + internal sealed class QuantizationTables : IDisposable + { + /// + /// Gets the ZigZag scan table + /// + public static byte[] DctZigZag + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; + } + + = + { + 0, + 1, 8, + 16, 9, 2, + 3, 10, 17, 24, + 32, 25, 18, 11, 4, + 5, 12, 19, 26, 33, 40, + 48, 41, 34, 27, 20, 13, 6, + 7, 14, 21, 28, 35, 42, 49, 56, + 57, 50, 43, 36, 29, 22, 15, + 23, 30, 37, 44, 51, 58, + 59, 52, 45, 38, 31, + 39, 46, 53, 60, + 61, 54, 47, + 55, 62, + 63 + }; + + /// + /// Gets or sets the quantization tables. + /// + public Buffer2D Tables + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; set; + } + + = new Buffer2D(64, 4); + + /// + public void Dispose() + { + if (this.Tables != null) + { + this.Tables.Dispose(); + this.Tables = null; + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ScanDecoder.cs new file mode 100644 index 0000000000..cb2e5ab9a8 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ScanDecoder.cs @@ -0,0 +1,943 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Diagnostics; +using System.IO; +using System.Runtime.CompilerServices; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// Provides the means to decode a spectral scan + /// + internal struct ScanDecoder + { + private byte[] markerBuffer; + + private int bitsData; + + private int bitsCount; + +#pragma warning disable 414 + private int bitsUnRead; + + private int accumulator; +#pragma warning restore 414 + + private int specStart; + + private int specEnd; + + private int eobrun; + + private int compIndex; + + private int successiveState; + + private int successiveACState; + + private int successiveACNextValue; + + private bool endOfStreamReached; + + private bool unexpectedMarkerReached; + + /// + /// Decodes the spectral scan + /// + /// The image frame + /// The input stream + /// The DC Huffman tables + /// The AC Huffman tables + /// The scan components + /// The component index within the array + /// The length of the components. Different to the array length + /// The reset interval + /// The spectral selection start + /// The spectral selection end + /// The successive approximation bit high end + /// The successive approximation bit low end + public void DecodeScan( + Frame frame, + Stream stream, + HuffmanTables dcHuffmanTables, + HuffmanTables acHuffmanTables, + FrameComponent[] components, + int componentIndex, + int componentsLength, + ushort resetInterval, + int spectralStart, + int spectralEnd, + int successivePrev, + int successive) + { + this.markerBuffer = new byte[2]; + this.compIndex = componentIndex; + this.specStart = spectralStart; + this.specEnd = spectralEnd; + this.successiveState = successive; + this.endOfStreamReached = false; + this.unexpectedMarkerReached = false; + + bool progressive = frame.Progressive; + int mcusPerLine = frame.McusPerLine; + + int mcu = 0; + int mcuExpected; + if (componentsLength == 1) + { + mcuExpected = components[this.compIndex].BlocksPerLine * components[this.compIndex].BlocksPerColumn; + } + else + { + mcuExpected = mcusPerLine * frame.McusPerColumn; + } + + FileMarker fileMarker; + while (mcu < mcuExpected) + { + // Reset interval stuff + int mcuToRead = resetInterval != 0 ? Math.Min(mcuExpected - mcu, resetInterval) : mcuExpected; + for (int i = 0; i < components.Length; i++) + { + ref FrameComponent c = ref components[i]; + c.Pred = 0; + } + + this.eobrun = 0; + + if (!progressive) + { + this.DecodeScanBaseline(dcHuffmanTables, acHuffmanTables, components, componentsLength, mcusPerLine, mcuToRead, ref mcu, stream); + } + else + { + if (this.specStart == 0) + { + if (successivePrev == 0) + { + this.DecodeScanDCFirst(dcHuffmanTables, components, componentsLength, mcusPerLine, mcuToRead, ref mcu, stream); + } + else + { + this.DecodeScanDCSuccessive(components, componentsLength, mcusPerLine, mcuToRead, ref mcu, stream); + } + } + else + { + if (successivePrev == 0) + { + this.DecodeScanACFirst(acHuffmanTables, components, componentsLength, mcusPerLine, mcuToRead, ref mcu, stream); + } + else + { + this.DecodeScanACSuccessive(acHuffmanTables, components, componentsLength, mcusPerLine, mcuToRead, ref mcu, stream); + } + } + } + + // Find marker + this.bitsCount = 0; + this.accumulator = 0; + this.bitsUnRead = 0; + fileMarker = JpegDecoderCore.FindNextFileMarker(this.markerBuffer, stream); + + // Some bad images seem to pad Scan blocks with e.g. zero bytes, skip past + // those to attempt to find a valid marker (fixes issue4090.pdf) in original code. + if (fileMarker.Invalid) + { +#if DEBUG + Debug.WriteLine($"DecodeScan - Unexpected MCU data at {stream.Position}, next marker is: {fileMarker.Marker:X}"); +#endif + } + + ushort marker = fileMarker.Marker; + + // RSTn - We've alread read the bytes and altered the position so no need to skip + if (marker >= JpegConstants.Markers.RST0 && marker <= JpegConstants.Markers.RST7) + { + continue; + } + + if (!fileMarker.Invalid) + { + // We've found a valid marker. + // Rewind the stream to the position of the marker and break + stream.Position = fileMarker.Position; + break; + } + } + + fileMarker = JpegDecoderCore.FindNextFileMarker(this.markerBuffer, stream); + + // Some images include more Scan blocks than expected, skip past those and + // attempt to find the next valid marker (fixes issue8182.pdf) in original code. + if (fileMarker.Invalid) + { +#if DEBUG + Debug.WriteLine($"DecodeScan - Unexpected MCU data at {stream.Position}, next marker is: {fileMarker.Marker:X}"); +#endif + } + else + { + // We've found a valid marker. + // Rewind the stream to the position of the marker + stream.Position = fileMarker.Position; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int GetBlockBufferOffset(FrameComponent component, int row, int col) + { + return 64 * (((component.BlocksPerLine + 1) * row) + col); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeScanBaseline( + HuffmanTables dcHuffmanTables, + HuffmanTables acHuffmanTables, + FrameComponent[] components, + int componentsLength, + int mcusPerLine, + int mcuToRead, + ref int mcu, + Stream stream) + { + if (componentsLength == 1) + { + ref FrameComponent component = ref components[this.compIndex]; + ref HuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId]; + ref HuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId]; + + for (int n = 0; n < mcuToRead; n++) + { + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + continue; + } + + this.DecodeBlockBaseline(ref dcHuffmanTable, ref acHuffmanTable, ref component, mcu, stream); + mcu++; + } + } + else + { + for (int n = 0; n < mcuToRead; n++) + { + for (int i = 0; i < componentsLength; i++) + { + ref FrameComponent component = ref components[i]; + ref HuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId]; + ref HuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId]; + int h = component.HorizontalFactor; + int v = component.VerticalFactor; + + for (int j = 0; j < v; j++) + { + for (int k = 0; k < h; k++) + { + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + continue; + } + + this.DecodeMcuBaseline(ref dcHuffmanTable, ref acHuffmanTable, ref component, mcusPerLine, mcu, j, k, stream); + } + } + } + + mcu++; + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeScanDCFirst( + HuffmanTables dcHuffmanTables, + FrameComponent[] components, + int componentsLength, + int mcusPerLine, + int mcuToRead, + ref int mcu, + Stream stream) + { + if (componentsLength == 1) + { + ref FrameComponent component = ref components[this.compIndex]; + ref HuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId]; + + for (int n = 0; n < mcuToRead; n++) + { + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + continue; + } + + this.DecodeBlockDCFirst(ref dcHuffmanTable, ref component, mcu, stream); + mcu++; + } + } + else + { + for (int n = 0; n < mcuToRead; n++) + { + for (int i = 0; i < componentsLength; i++) + { + ref FrameComponent component = ref components[i]; + ref HuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId]; + int h = component.HorizontalFactor; + int v = component.VerticalFactor; + + for (int j = 0; j < v; j++) + { + for (int k = 0; k < h; k++) + { + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + continue; + } + + this.DecodeMcuDCFirst(ref dcHuffmanTable, ref component, mcusPerLine, mcu, j, k, stream); + } + } + } + + mcu++; + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeScanDCSuccessive( + FrameComponent[] components, + int componentsLength, + int mcusPerLine, + int mcuToRead, + ref int mcu, + Stream stream) + { + if (componentsLength == 1) + { + ref FrameComponent component = ref components[this.compIndex]; + for (int n = 0; n < mcuToRead; n++) + { + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + continue; + } + + this.DecodeBlockDCSuccessive(ref component, mcu, stream); + mcu++; + } + } + else + { + for (int n = 0; n < mcuToRead; n++) + { + for (int i = 0; i < componentsLength; i++) + { + ref FrameComponent component = ref components[i]; + int h = component.HorizontalFactor; + int v = component.VerticalFactor; + for (int j = 0; j < v; j++) + { + for (int k = 0; k < h; k++) + { + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + continue; + } + + this.DecodeMcuDCSuccessive(ref component, mcusPerLine, mcu, j, k, stream); + } + } + } + + mcu++; + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeScanACFirst( + HuffmanTables acHuffmanTables, + FrameComponent[] components, + int componentsLength, + int mcusPerLine, + int mcuToRead, + ref int mcu, + Stream stream) + { + if (componentsLength == 1) + { + ref FrameComponent component = ref components[this.compIndex]; + ref HuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId]; + + for (int n = 0; n < mcuToRead; n++) + { + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + continue; + } + + this.DecodeBlockACFirst(ref acHuffmanTable, ref component, mcu, stream); + mcu++; + } + } + else + { + for (int n = 0; n < mcuToRead; n++) + { + for (int i = 0; i < componentsLength; i++) + { + ref FrameComponent component = ref components[i]; + ref HuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId]; + int h = component.HorizontalFactor; + int v = component.VerticalFactor; + + for (int j = 0; j < v; j++) + { + for (int k = 0; k < h; k++) + { + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + continue; + } + + this.DecodeMcuACFirst(ref acHuffmanTable, ref component, mcusPerLine, mcu, j, k, stream); + } + } + } + + mcu++; + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeScanACSuccessive( + HuffmanTables acHuffmanTables, + FrameComponent[] components, + int componentsLength, + int mcusPerLine, + int mcuToRead, + ref int mcu, + Stream stream) + { + if (componentsLength == 1) + { + ref FrameComponent component = ref components[this.compIndex]; + ref HuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId]; + + for (int n = 0; n < mcuToRead; n++) + { + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + continue; + } + + this.DecodeBlockACSuccessive(ref acHuffmanTable, ref component, mcu, stream); + mcu++; + } + } + else + { + for (int n = 0; n < mcuToRead; n++) + { + for (int i = 0; i < componentsLength; i++) + { + ref FrameComponent component = ref components[i]; + ref HuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId]; + int h = component.HorizontalFactor; + int v = component.VerticalFactor; + + for (int j = 0; j < v; j++) + { + for (int k = 0; k < h; k++) + { + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + continue; + } + + this.DecodeMcuACSuccessive(ref acHuffmanTable, ref component, mcusPerLine, mcu, j, k, stream); + } + } + } + + mcu++; + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeBlockBaseline(ref HuffmanTable dcHuffmanTable, ref HuffmanTable acHuffmanTable, ref FrameComponent component, int mcu, Stream stream) + { + int blockRow = mcu / component.BlocksPerLine; + int blockCol = mcu % component.BlocksPerLine; + int offset = GetBlockBufferOffset(component, blockRow, blockCol); + this.DecodeBaseline(ref component, offset, ref dcHuffmanTable, ref acHuffmanTable, stream); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeMcuBaseline(ref HuffmanTable dcHuffmanTable, ref HuffmanTable acHuffmanTable, ref FrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream) + { + int mcuRow = mcu / mcusPerLine; + int mcuCol = mcu % mcusPerLine; + int blockRow = (mcuRow * component.VerticalFactor) + row; + int blockCol = (mcuCol * component.HorizontalFactor) + col; + int offset = GetBlockBufferOffset(component, blockRow, blockCol); + this.DecodeBaseline(ref component, offset, ref dcHuffmanTable, ref acHuffmanTable, stream); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeBlockDCFirst(ref HuffmanTable dcHuffmanTable, ref FrameComponent component, int mcu, Stream stream) + { + int blockRow = mcu / component.BlocksPerLine; + int blockCol = mcu % component.BlocksPerLine; + int offset = GetBlockBufferOffset(component, blockRow, blockCol); + this.DecodeDCFirst(ref component, offset, ref dcHuffmanTable, stream); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeMcuDCFirst(ref HuffmanTable dcHuffmanTable, ref FrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream) + { + int mcuRow = mcu / mcusPerLine; + int mcuCol = mcu % mcusPerLine; + int blockRow = (mcuRow * component.VerticalFactor) + row; + int blockCol = (mcuCol * component.HorizontalFactor) + col; + int offset = GetBlockBufferOffset(component, blockRow, blockCol); + this.DecodeDCFirst(ref component, offset, ref dcHuffmanTable, stream); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeBlockDCSuccessive(ref FrameComponent component, int mcu, Stream stream) + { + int blockRow = mcu / component.BlocksPerLine; + int blockCol = mcu % component.BlocksPerLine; + int offset = GetBlockBufferOffset(component, blockRow, blockCol); + this.DecodeDCSuccessive(ref component, offset, stream); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeMcuDCSuccessive(ref FrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream) + { + int mcuRow = mcu / mcusPerLine; + int mcuCol = mcu % mcusPerLine; + int blockRow = (mcuRow * component.VerticalFactor) + row; + int blockCol = (mcuCol * component.HorizontalFactor) + col; + int offset = GetBlockBufferOffset(component, blockRow, blockCol); + this.DecodeDCSuccessive(ref component, offset, stream); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeBlockACFirst(ref HuffmanTable acHuffmanTable, ref FrameComponent component, int mcu, Stream stream) + { + int blockRow = mcu / component.BlocksPerLine; + int blockCol = mcu % component.BlocksPerLine; + int offset = GetBlockBufferOffset(component, blockRow, blockCol); + this.DecodeACFirst(ref component, offset, ref acHuffmanTable, stream); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeMcuACFirst(ref HuffmanTable acHuffmanTable, ref FrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream) + { + int mcuRow = mcu / mcusPerLine; + int mcuCol = mcu % mcusPerLine; + int blockRow = (mcuRow * component.VerticalFactor) + row; + int blockCol = (mcuCol * component.HorizontalFactor) + col; + int offset = GetBlockBufferOffset(component, blockRow, blockCol); + this.DecodeACFirst(ref component, offset, ref acHuffmanTable, stream); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeBlockACSuccessive(ref HuffmanTable acHuffmanTable, ref FrameComponent component, int mcu, Stream stream) + { + int blockRow = mcu / component.BlocksPerLine; + int blockCol = mcu % component.BlocksPerLine; + int offset = GetBlockBufferOffset(component, blockRow, blockCol); + this.DecodeACSuccessive(ref component, offset, ref acHuffmanTable, stream); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeMcuACSuccessive(ref HuffmanTable acHuffmanTable, ref FrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream) + { + int mcuRow = mcu / mcusPerLine; + int mcuCol = mcu % mcusPerLine; + int blockRow = (mcuRow * component.VerticalFactor) + row; + int blockCol = (mcuCol * component.HorizontalFactor) + col; + int offset = GetBlockBufferOffset(component, blockRow, blockCol); + this.DecodeACSuccessive(ref component, offset, ref acHuffmanTable, stream); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private int ReadBit(Stream stream) + { + // TODO: I wonder if we can do this two bytes at a time; libjpeg turbo seems to do that? + if (this.bitsCount > 0) + { + this.bitsCount--; + return (this.bitsData >> this.bitsCount) & 1; + } + + this.bitsData = stream.ReadByte(); + + if (this.bitsData == -0x1) + { + // We've encountered the end of the file stream which means there's no EOI marker in the image + this.endOfStreamReached = true; + } + + if (this.bitsData == JpegConstants.Markers.Prefix) + { + int nextByte = stream.ReadByte(); + if (nextByte != 0) + { +#if DEBUG + Debug.WriteLine($"DecodeScan - Unexpected marker {(this.bitsData << 8) | nextByte:X} at {stream.Position}"); +#endif + + // We've encountered an unexpected marker. Reverse the stream and exit. + this.unexpectedMarkerReached = true; + stream.Position -= 2; + } + + // Unstuff 0 + } + + this.bitsCount = 7; + + return this.bitsData >> 7; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private short DecodeHuffman(ref HuffmanTable tree, Stream stream) + { + short code = -1; + + // TODO: Adding this code introduces error into the decoder. + // NOTES # During investigation of the libjpeg implementation it appears that they pull 32bits at a time and operate on those bits + // using 3 methods: FillBits, PeekBits, and ReadBits. We should attempt to do the same. + // It doesn't appear to speed anything up either. + // if (this.bitsUnRead < 8) + // { + // if (this.bitsCount <= 0) + // { + // code = (short)this.ReadBit(stream); + // if (this.endOfStreamReached || this.unexpectedMarkerReached) + // { + // return -1; + // } + // + // this.bitsUnRead += 8; + // } + // + // this.accumulator = (this.accumulator << 8) | this.bitsData; + // int lutIndex = (this.accumulator >> (8 - this.bitsUnRead)) & 0xFF; + // int v = tree.Lookahead[lutIndex]; + // if (v != 0) + // { + // int nb = (v & 0xFF) - 1; + // this.bitsCount -= nb - 1; + // this.bitsUnRead -= nb; + // v = v >> 8; + // return (short)v; + // } + // } + if (code == -1) + { + code = (short)this.ReadBit(stream); + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + return -1; + } + } + + // "DECODE", section F.2.2.3, figure F.16, page 109 of T.81 + int i = 1; + + while (code > tree.MaxCode[i]) + { + code <<= 1; + code |= (short)this.ReadBit(stream); + + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + return -1; + } + + i++; + } + + int j = tree.ValOffset[i]; + return tree.HuffVal[(j + code) & 0xFF]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private int Receive(int length, Stream stream) + { + int n = 0; + while (length > 0) + { + int bit = this.ReadBit(stream); + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + return -1; + } + + n = (n << 1) | bit; + length--; + } + + return n; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private int ReceiveAndExtend(int length, Stream stream) + { + if (length == 1) + { + return this.ReadBit(stream) == 1 ? 1 : -1; + } + + int n = this.Receive(length, stream); + if (n >= 1 << (length - 1)) + { + return n; + } + + return n + (-1 << length) + 1; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeBaseline(ref FrameComponent component, int offset, ref HuffmanTable dcHuffmanTable, ref HuffmanTable acHuffmanTable, Stream stream) + { + int t = this.DecodeHuffman(ref dcHuffmanTable, stream); + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + return; + } + + int diff = t == 0 ? 0 : this.ReceiveAndExtend(t, stream); + component.BlockData[offset] = (short)(component.Pred += diff); + + int k = 1; + while (k < 64) + { + int rs = this.DecodeHuffman(ref acHuffmanTable, stream); + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + return; + } + + int s = rs & 15; + int r = rs >> 4; + + if (s == 0) + { + if (r < 15) + { + break; + } + + k += 16; + continue; + } + + k += r; + + if (k > 63) + { + break; + } + + byte z = QuantizationTables.DctZigZag[k]; + short re = (short)this.ReceiveAndExtend(s, stream); + component.BlockData[offset + z] = re; + k++; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeDCFirst(ref FrameComponent component, int offset, ref HuffmanTable dcHuffmanTable, Stream stream) + { + int t = this.DecodeHuffman(ref dcHuffmanTable, stream); + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + return; + } + + int diff = t == 0 ? 0 : this.ReceiveAndExtend(t, stream) << this.successiveState; + component.BlockData[offset] = (short)(component.Pred += diff); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeDCSuccessive(ref FrameComponent component, int offset, Stream stream) + { + int bit = this.ReadBit(stream); + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + return; + } + + component.BlockData[offset] |= (short)(bit << this.successiveState); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeACFirst(ref FrameComponent component, int offset, ref HuffmanTable acHuffmanTable, Stream stream) + { + if (this.eobrun > 0) + { + this.eobrun--; + return; + } + + Span componentBlockDataSpan = component.BlockData.Span; + int k = this.specStart; + int e = this.specEnd; + while (k <= e) + { + short rs = this.DecodeHuffman(ref acHuffmanTable, stream); + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + return; + } + + int s = rs & 15; + int r = rs >> 4; + + if (s == 0) + { + if (r < 15) + { + this.eobrun = this.Receive(r, stream) + (1 << r) - 1; + break; + } + + k += 16; + continue; + } + + k += r; + byte z = QuantizationTables.DctZigZag[k]; + componentBlockDataSpan[offset + z] = (short)(this.ReceiveAndExtend(s, stream) * (1 << this.successiveState)); + k++; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DecodeACSuccessive(ref FrameComponent component, int offset, ref HuffmanTable acHuffmanTable, Stream stream) + { + int k = this.specStart; + int e = this.specEnd; + int r = 0; + Span componentBlockDataSpan = component.BlockData.Span; + while (k <= e) + { + byte z = QuantizationTables.DctZigZag[k]; + switch (this.successiveACState) + { + case 0: // Initial state + short rs = this.DecodeHuffman(ref acHuffmanTable, stream); + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + return; + } + + int s = rs & 15; + r = rs >> 4; + if (s == 0) + { + if (r < 15) + { + this.eobrun = this.Receive(r, stream) + (1 << r); + this.successiveACState = 4; + } + else + { + r = 16; + this.successiveACState = 1; + } + } + else + { + if (s != 1) + { + throw new ImageFormatException("Invalid ACn encoding"); + } + + this.successiveACNextValue = this.ReceiveAndExtend(s, stream); + this.successiveACState = r > 0 ? 2 : 3; + } + + continue; + case 1: // Skipping r zero items + case 2: + if (componentBlockDataSpan[offset + z] != 0) + { + int bit = this.ReadBit(stream); + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + return; + } + + componentBlockDataSpan[offset + z] += (short)(bit << this.successiveState); + } + else + { + r--; + if (r == 0) + { + this.successiveACState = this.successiveACState == 2 ? 3 : 0; + } + } + + break; + case 3: // Set value for a zero item + if (componentBlockDataSpan[offset + z] != 0) + { + int bit = this.ReadBit(stream); + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + return; + } + + componentBlockDataSpan[offset + z] += (short)(bit << this.successiveState); + } + else + { + componentBlockDataSpan[offset + z] = (short)(this.successiveACNextValue << this.successiveState); + this.successiveACState = 0; + } + + break; + case 4: // Eob + if (componentBlockDataSpan[offset + z] != 0) + { + int bit = this.ReadBit(stream); + if (this.endOfStreamReached || this.unexpectedMarkerReached) + { + return; + } + + componentBlockDataSpan[offset + z] += (short)(bit << this.successiveState); + } + + break; + } + + k++; + } + + if (this.successiveACState == 4) + { + this.eobrun--; + if (this.eobrun == 0) + { + this.successiveACState = 0; + } + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/YCbCrToRgbTables.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/YCbCrToRgbTables.cs new file mode 100644 index 0000000000..9ed15cacb8 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/YCbCrToRgbTables.cs @@ -0,0 +1,129 @@ +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + using System.Runtime.CompilerServices; + + using SixLabors.ImageSharp.PixelFormats; + + /// + /// Provides 8-bit lookup tables for converting from YCbCr to Rgb colorspace. + /// Methods to build the tables are based on libjpeg implementation. + /// + internal struct YCbCrToRgbTables + { + /// + /// The red red-chrominance table + /// + public static int[] CrRTable = new int[256]; + + /// + /// The blue blue-chrominance table + /// + public static int[] CbBTable = new int[256]; + + /// + /// The green red-chrominance table + /// + public static int[] CrGTable = new int[256]; + + /// + /// The green blue-chrominance table + /// + public static int[] CbGTable = new int[256]; + + // Speediest right-shift on some machines and gives us enough accuracy at 4 decimal places. + private const int ScaleBits = 16; + + private const int Half = 1 << (ScaleBits - 1); + + private const int MinSample = 0; + + private const int HalfSample = 128; + + private const int MaxSample = 255; + + /// + /// Initializes the YCbCr tables + /// + public static void Create() + { + for (int i = 0, x = -128; i <= 255; i++, x++) + { + // i is the actual input pixel value, in the range 0..255 + // The Cb or Cr value we are thinking of is x = i - 128 + // Cr=>R value is nearest int to 1.402 * x + CrRTable[i] = RightShift((Fix(1.402F) * x) + Half); + + // Cb=>B value is nearest int to 1.772 * x + CbBTable[i] = RightShift((Fix(1.772F) * x) + Half); + + // Cr=>G value is scaled-up -0.714136286 + CrGTable[i] = (-Fix(0.714136286F)) * x; + + // Cb => G value is scaled - up - 0.344136286 * x + // We also add in Half so that need not do it in inner loop + CbGTable[i] = ((-Fix(0.344136286F)) * x) + Half; + } + } + + /// + /// Optimized method to pack bytes to the image from the YCbCr color space. + /// + /// The pixel format. + /// The packed pixel. + /// The y luminance component. + /// The cb chroma component. + /// The cr chroma component. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void PackYCbCr(ref TPixel packed, byte y, byte cb, byte cr) + where TPixel : struct, IPixel + { + byte r = (byte)(y + CrRTable[cr]).Clamp(0, 255); + + // The values for the G calculation are left scaled up, since we must add them together before rounding. + byte g = (byte)(y + RightShift(CbGTable[cb] + CrGTable[cr])).Clamp(0, 255); + + byte b = (byte)(y + CbBTable[cb]).Clamp(0, 255); + + packed.PackFromRgba32(new Rgba32(r, g, b, 255)); + } + + /// + /// Optimized method to pack bytes to the image from the YccK color space. + /// + /// The pixel format. + /// The packed pixel. + /// The y luminance component. + /// The cb chroma component. + /// The cr chroma component. + /// The keyline component. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void PackYccK(ref TPixel packed, byte y, byte cb, byte cr, byte k) + where TPixel : struct, IPixel + { + int c = (MaxSample - (y + CrRTable[cr])).Clamp(0, 255); + + // The values for the G calculation are left scaled up, since we must add them together before rounding. + int m = (MaxSample - (y + RightShift(CbGTable[cb] + CrGTable[cr]))).Clamp(0, 255); + + int cy = (MaxSample - (y + CbBTable[cb])).Clamp(0, 255); + + byte r = (byte)((c * k) / MaxSample); + byte g = (byte)((m * k) / MaxSample); + byte b = (byte)((cy * k) / MaxSample); + + packed.PackFromRgba32(new Rgba32(r, g, b, MaxSample)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int Fix(float x) + { + return (int)((x * (1L << ScaleBits)) + 0.5F); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int RightShift(int x) + { + return x >> ScaleBits; + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/JpegConstants.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/JpegConstants.cs new file mode 100644 index 0000000000..c23cb9e9b7 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/JpegConstants.cs @@ -0,0 +1,357 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort +{ + /// + /// Contains jpeg constant values + /// + internal static class JpegConstants + { + /// + /// Contains marker specific constants + /// + public static class Markers + { + /// + /// The prefix used for all markers. + /// + public const byte Prefix = 0xFF; + + /// + /// The Start of Image marker + /// + public const ushort SOI = 0xFFD8; + + /// + /// The End of Image marker + /// + public const ushort EOI = 0xFFD9; + + /// + /// Application specific marker for marking the jpeg format. + /// + /// + public const ushort APP0 = 0xFFE0; + + /// + /// Application specific marker for marking where to store metadata. + /// + public const ushort APP1 = 0xFFE1; + + /// + /// Application specific marker for marking where to store ICC profile information. + /// + public const ushort APP2 = 0xFFE2; + + /// + /// Application specific marker. + /// + public const ushort APP3 = 0xFFE3; + + /// + /// Application specific marker. + /// + public const ushort APP4 = 0xFFE4; + + /// + /// Application specific marker. + /// + public const ushort APP5 = 0xFFE5; + + /// + /// Application specific marker. + /// + public const ushort APP6 = 0xFFE6; + + /// + /// Application specific marker. + /// + public const ushort APP7 = 0xFFE7; + + /// + /// Application specific marker. + /// + public const ushort APP8 = 0xFFE8; + + /// + /// Application specific marker. + /// + public const ushort APP9 = 0xFFE9; + + /// + /// Application specific marker. + /// + public const ushort APP10 = 0xFFEA; + + /// + /// Application specific marker. + /// + public const ushort APP11 = 0xFFEB; + + /// + /// Application specific marker. + /// + public const ushort APP12 = 0xFFEC; + + /// + /// Application specific marker. + /// + public const ushort APP13 = 0xFFED; + + /// + /// Application specific marker used by Adobe for storing encoding information for DCT filters. + /// + public const ushort APP14 = 0xFFEE; + + /// + /// Application specific marker used by GraphicConverter to store JPEG quality. + /// + public const ushort APP15 = 0xFFEF; + + /// + /// The text comment marker + /// + public const ushort COM = 0xFFFE; + + /// + /// Define Quantization Table(s) marker + /// + /// Specifies one or more quantization tables. + /// + /// + public const ushort DQT = 0xFFDB; + + /// + /// Start of Frame (baseline DCT) + /// + /// Indicates that this is a baseline DCT-based JPEG, and specifies the width, height, number of components, + /// and component subsampling (e.g., 4:2:0). + /// + /// + public const ushort SOF0 = 0xFFC0; + + /// + /// Start Of Frame (Extended Sequential DCT) + /// + /// Indicates that this is a progressive DCT-based JPEG, and specifies the width, height, number of components, + /// and component subsampling (e.g., 4:2:0). + /// + /// + public const ushort SOF1 = 0xFFC1; + + /// + /// Start Of Frame (progressive DCT) + /// + /// Indicates that this is a progressive DCT-based JPEG, and specifies the width, height, number of components, + /// and component subsampling (e.g., 4:2:0). + /// + /// + public const ushort SOF2 = 0xFFC2; + + /// + /// Define Huffman Table(s) + /// + /// Specifies one or more Huffman tables. + /// + /// + public const ushort DHT = 0xFFC4; + + /// + /// Define Restart Interval + /// + /// Specifies the interval between RSTn markers, in macroblocks.This marker is followed by two bytes indicating the fixed size so it can be treated like any other variable size segment. + /// + /// + public const ushort DRI = 0xFFDD; + + /// + /// Start of Scan + /// + /// Begins a top-to-bottom scan of the image. In baseline DCT JPEG images, there is generally a single scan. + /// Progressive DCT JPEG images usually contain multiple scans. This marker specifies which slice of data it + /// will contain, and is immediately followed by entropy-coded data. + /// + /// + public const ushort SOS = 0xFFDA; + + /// + /// Define First Restart + /// + /// Inserted every r macroblocks, where r is the restart interval set by a DRI marker. + /// Not used if there was no DRI marker. The low three bits of the marker code cycle in value from 0 to 7. + /// + /// + public const ushort RST0 = 0xFFD0; + + /// + /// Define Eigth Restart + /// + /// Inserted every r macroblocks, where r is the restart interval set by a DRI marker. + /// Not used if there was no DRI marker. The low three bits of the marker code cycle in value from 0 to 7. + /// + /// + public const ushort RST7 = 0xFFD7; + + /// + /// Contains JFIF specific markers + /// + public static class JFif + { + /// + /// Represents J in ASCII + /// + public const byte J = 0x4A; + + /// + /// Represents F in ASCII + /// + public const byte F = 0x46; + + /// + /// Represents I in ASCII + /// + public const byte I = 0x49; + + /// + /// Represents the null "0" marker + /// + public const byte Null = 0x0; + } + + /// + /// Contains Adobe specific markers + /// + public static class Adobe + { + /// + /// Represents A in ASCII + /// + public const byte A = 0x41; + + /// + /// Represents d in ASCII + /// + public const byte D = 0x64; + + /// + /// Represents b in ASCII + /// + public const byte O = 0x6F; + + /// + /// Represents b in ASCII + /// + public const byte B = 0x62; + + /// + /// Represents e in ASCII + /// + public const byte E = 0x65; + + /// + /// The color transform is unknown.(RGB or CMYK) + /// + public const byte ColorTransformUnknown = 0; + + /// + /// The color transform is YCbCr (luminance, red chroma, blue chroma) + /// + public const byte ColorTransformYCbCr = 1; + + /// + /// The color transform is YCCK (luminance, red chroma, blue chroma, keyline) + /// + public const byte ColorTransformYcck = 2; + } + + /// + /// Contains EXIF specific markers + /// + public static class Exif + { + /// + /// Represents E in ASCII + /// + public const byte E = 0x45; + + /// + /// Represents x in ASCII + /// + public const byte X = 0x78; + + /// + /// Represents i in ASCII + /// + public const byte I = 0x69; + + /// + /// Represents f in ASCII + /// + public const byte F = 0x66; + + /// + /// Represents the null "0" marker + /// + public const byte Null = 0x0; + } + + /// + /// Contains ICC specific markers + /// + public static class ICC + { + /// + /// Represents I in ASCII + /// + public const byte I = 0x49; + + /// + /// Represents C in ASCII + /// + public const byte C = 0x43; + + /// + /// Represents _ in ASCII + /// + public const byte UnderScore = 0x5F; + + /// + /// Represents P in ASCII + /// + public const byte P = 0x50; + + /// + /// Represents R in ASCII + /// + public const byte R = 0x52; + + /// + /// Represents O in ASCII + /// + public const byte O = 0x4F; + + /// + /// Represents F in ASCII + /// + public const byte F = 0x46; + + /// + /// Represents L in ASCII + /// + public const byte L = 0x4C; + + /// + /// Represents E in ASCII + /// + public const byte E = 0x45; + + /// + /// Represents the null "0" marker + /// + public const byte Null = 0x0; + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/JpegDecoderCore.cs new file mode 100644 index 0000000000..dc8d477f01 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/JpegDecoderCore.cs @@ -0,0 +1,962 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.IO; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort +{ + /// + /// Performs the jpeg decoding operation. + /// Ported from with additional fixes to handle common encoding errors + /// + internal sealed class JpegDecoderCore : IDisposable + { + /// + /// The global configuration + /// + private readonly Configuration configuration; + + /// + /// Gets the temporary buffer used to store bytes read from the stream. + /// + private readonly byte[] temp = new byte[2 * 16 * 4]; + + private readonly byte[] markerBuffer = new byte[2]; + + private QuantizationTables quantizationTables; + + private HuffmanTables dcHuffmanTables; + + private HuffmanTables acHuffmanTables; + + private Frame frame; + + private ComponentBlocks components; + + private JpegPixelArea pixelArea; + + private ushort resetInterval; + + private int imageWidth; + + private int imageHeight; + + private int numberOfComponents; + + /// + /// Whether the image has a EXIF header + /// + private bool isExif; + + /// + /// Contains information about the JFIF marker + /// + private JFif jFif; + + /// + /// Contains information about the Adobe marker + /// + private Adobe adobe; + + /// + /// Initializes static members of the class. + /// + static JpegDecoderCore() + { + YCbCrToRgbTables.Create(); + } + + /// + /// Initializes a new instance of the class. + /// + /// The configuration. + /// The options. + public JpegDecoderCore(Configuration configuration, IJpegDecoderOptions options) + { + this.configuration = configuration ?? Configuration.Default; + this.IgnoreMetadata = options.IgnoreMetadata; + } + + /// + /// Gets the input stream. + /// + public Stream InputStream { get; private set; } + + /// + /// Gets a value indicating whether the metadata should be ignored when the image is being decoded. + /// + public bool IgnoreMetadata { get; } + + /// + /// Finds the next file marker within the byte stream. + /// + /// The buffer to read file markers to + /// The input stream + /// The + public static FileMarker FindNextFileMarker(byte[] marker, Stream stream) + { + int value = stream.Read(marker, 0, 2); + + if (value == 0) + { + return new FileMarker(JpegConstants.Markers.EOI, (int)stream.Length - 2); + } + + if (marker[0] == JpegConstants.Markers.Prefix) + { + // According to Section B.1.1.2: + // "Any marker may optionally be preceded by any number of fill bytes, which are bytes assigned code 0xFF." + while (marker[1] == JpegConstants.Markers.Prefix) + { + int suffix = stream.ReadByte(); + if (suffix == -1) + { + return new FileMarker(JpegConstants.Markers.EOI, (int)stream.Length - 2); + } + + marker[1] = (byte)value; + } + + return new FileMarker((ushort)((marker[0] << 8) | marker[1]), (int)(stream.Position - 2)); + } + + return new FileMarker((ushort)((marker[0] << 8) | marker[1]), (int)(stream.Position - 2), true); + } + + /// + /// Decodes the image from the specified and sets the data to image. + /// + /// The pixel format. + /// The stream, where the image should be. + /// The decoded image. + public Image Decode(Stream stream) + where TPixel : struct, IPixel + { + this.InputStream = stream; + + var metadata = new ImageMetaData(); + this.ParseStream(metadata, false); + + var image = new Image(this.configuration, this.imageWidth, this.imageHeight, metadata); + this.FillPixelData(image); + this.AssignResolution(image); + return image; + } + + /// + public void Dispose() + { + this.frame?.Dispose(); + this.components?.Dispose(); + this.quantizationTables?.Dispose(); + this.dcHuffmanTables?.Dispose(); + this.acHuffmanTables?.Dispose(); + this.pixelArea.Dispose(); + + // Set large fields to null. + this.frame = null; + this.components = null; + this.quantizationTables = null; + this.dcHuffmanTables = null; + this.acHuffmanTables = null; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int GetBlockBufferOffset(ref Component component, int row, int col) + { + return 64 * (((component.BlocksPerLine + 1) * row) + col); + } + + /// + /// Parses the input stream for file markers + /// + /// Contains the metadata for an image + /// Whether to decode metadata only. + private void ParseStream(ImageMetaData metaData, bool metadataOnly) + { + // TODO: metadata only logic + // Check for the Start Of Image marker. + var fileMarker = new FileMarker(this.ReadUint16(), 0); + if (fileMarker.Marker != JpegConstants.Markers.SOI) + { + throw new ImageFormatException("Missing SOI marker."); + } + + ushort marker = this.ReadUint16(); + fileMarker = new FileMarker(marker, (int)this.InputStream.Position - 2); + + this.quantizationTables = new QuantizationTables(); + this.dcHuffmanTables = new HuffmanTables(); + this.acHuffmanTables = new HuffmanTables(); + + while (fileMarker.Marker != JpegConstants.Markers.EOI) + { + // Get the marker length + int remaining = this.ReadUint16() - 2; + + switch (fileMarker.Marker) + { + case JpegConstants.Markers.APP0: + this.ProcessApplicationHeaderMarker(remaining); + break; + + case JpegConstants.Markers.APP1: + this.ProcessApp1Marker(remaining, metaData); + break; + + case JpegConstants.Markers.APP2: + this.ProcessApp2Marker(remaining, metaData); + break; + case JpegConstants.Markers.APP3: + case JpegConstants.Markers.APP4: + case JpegConstants.Markers.APP5: + case JpegConstants.Markers.APP6: + case JpegConstants.Markers.APP7: + case JpegConstants.Markers.APP8: + case JpegConstants.Markers.APP9: + case JpegConstants.Markers.APP10: + case JpegConstants.Markers.APP11: + case JpegConstants.Markers.APP12: + case JpegConstants.Markers.APP13: + this.InputStream.Skip(remaining); + break; + + case JpegConstants.Markers.APP14: + this.ProcessApp14Marker(remaining); + break; + + case JpegConstants.Markers.APP15: + case JpegConstants.Markers.COM: + this.InputStream.Skip(remaining); + break; + + case JpegConstants.Markers.DQT: + this.ProcessDefineQuantizationTablesMarker(remaining); + break; + + case JpegConstants.Markers.SOF0: + case JpegConstants.Markers.SOF1: + case JpegConstants.Markers.SOF2: + this.ProcessStartOfFrameMarker(remaining, fileMarker); + break; + + case JpegConstants.Markers.DHT: + this.ProcessDefineHuffmanTablesMarker(remaining); + break; + + case JpegConstants.Markers.DRI: + this.ProcessDefineRestartIntervalMarker(remaining); + break; + + case JpegConstants.Markers.SOS: + this.ProcessStartOfScanMarker(); + break; + } + + // Read on. + fileMarker = FindNextFileMarker(this.markerBuffer, this.InputStream); + } + + this.imageWidth = this.frame.SamplesPerLine; + this.imageHeight = this.frame.Scanlines; + this.components = new ComponentBlocks { Components = new Component[this.frame.ComponentCount] }; + + for (int i = 0; i < this.components.Components.Length; i++) + { + ref var frameComponent = ref this.frame.Components[i]; + var component = new Component + { + Scale = new System.Numerics.Vector2( + frameComponent.HorizontalFactor / (float)this.frame.MaxHorizontalFactor, + frameComponent.VerticalFactor / (float)this.frame.MaxVerticalFactor), + BlocksPerLine = frameComponent.BlocksPerLine, + BlocksPerColumn = frameComponent.BlocksPerColumn + }; + + this.BuildComponentData(ref component, ref frameComponent); + this.components.Components[i] = component; + } + + this.numberOfComponents = this.components.Components.Length; + } + + /// + /// Fills the given image with the color data + /// + /// The pixel format. + /// The image + private void FillPixelData(Image image) + where TPixel : struct, IPixel + { + if (this.numberOfComponents > 4) + { + throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.numberOfComponents}"); + } + + this.pixelArea = new JpegPixelArea(image.Width, image.Height, this.numberOfComponents); + this.pixelArea.LinearizeBlockData(this.components, image.Width, image.Height); + + if (this.numberOfComponents == 1) + { + this.FillGrayScaleImage(image); + return; + } + + if (this.numberOfComponents == 3) + { + if (this.adobe.Equals(default(Adobe)) || this.adobe.ColorTransform == JpegConstants.Markers.Adobe.ColorTransformYCbCr) + { + this.FillYCbCrImage(image); + } + else if (this.adobe.ColorTransform == JpegConstants.Markers.Adobe.ColorTransformUnknown) + { + this.FillRgbImage(image); + } + } + + if (this.numberOfComponents == 4) + { + if (this.adobe.ColorTransform == JpegConstants.Markers.Adobe.ColorTransformYcck) + { + this.FillYcckImage(image); + } + else + { + this.FillCmykImage(image); + } + } + } + + /// + /// Assigns the horizontal and vertical resolution to the image if it has a JFIF header or EXIF metadata. + /// + /// The pixel format. + /// The image to assign the resolution to. + private void AssignResolution(Image image) + where TPixel : struct, IPixel + { + if (this.isExif) + { + ExifValue horizontal = image.MetaData.ExifProfile.GetValue(ExifTag.XResolution); + ExifValue vertical = image.MetaData.ExifProfile.GetValue(ExifTag.YResolution); + double horizontalValue = horizontal != null ? ((Rational)horizontal.Value).ToDouble() : 0; + double verticalValue = vertical != null ? ((Rational)vertical.Value).ToDouble() : 0; + + if (horizontalValue > 0 && verticalValue > 0) + { + image.MetaData.HorizontalResolution = horizontalValue; + image.MetaData.VerticalResolution = verticalValue; + } + } + else if (this.jFif.XDensity > 0 && this.jFif.YDensity > 0) + { + image.MetaData.HorizontalResolution = this.jFif.XDensity; + image.MetaData.VerticalResolution = this.jFif.YDensity; + } + } + + /// + /// Processes the application header containing the JFIF identifier plus extra data. + /// + /// The remaining bytes in the segment block. + private void ProcessApplicationHeaderMarker(int remaining) + { + if (remaining < 5) + { + // Skip the application header length + this.InputStream.Skip(remaining); + return; + } + + this.InputStream.Read(this.temp, 0, 13); + remaining -= 13; + + bool isJfif = this.temp[0] == JpegConstants.Markers.JFif.J && + this.temp[1] == JpegConstants.Markers.JFif.F && + this.temp[2] == JpegConstants.Markers.JFif.I && + this.temp[3] == JpegConstants.Markers.JFif.F && + this.temp[4] == JpegConstants.Markers.JFif.Null; + + if (isJfif) + { + this.jFif = new JFif + { + MajorVersion = this.temp[5], + MinorVersion = this.temp[6], + DensityUnits = this.temp[7], + XDensity = (short)((this.temp[8] << 8) | this.temp[9]), + YDensity = (short)((this.temp[10] << 8) | this.temp[11]) + }; + } + + // TODO: thumbnail + if (remaining > 0) + { + this.InputStream.Skip(remaining); + } + } + + /// + /// Processes the App1 marker retrieving any stored metadata + /// + /// The remaining bytes in the segment block. + /// The image. + private void ProcessApp1Marker(int remaining, ImageMetaData metadata) + { + if (remaining < 6 || this.IgnoreMetadata) + { + // Skip the application header length + this.InputStream.Skip(remaining); + return; + } + + byte[] profile = new byte[remaining]; + this.InputStream.Read(profile, 0, remaining); + + if (profile[0] == JpegConstants.Markers.Exif.E && + profile[1] == JpegConstants.Markers.Exif.X && + profile[2] == JpegConstants.Markers.Exif.I && + profile[3] == JpegConstants.Markers.Exif.F && + profile[4] == JpegConstants.Markers.Exif.Null && + profile[5] == JpegConstants.Markers.Exif.Null) + { + this.isExif = true; + metadata.ExifProfile = new ExifProfile(profile); + } + } + + /// + /// Processes the App2 marker retrieving any stored ICC profile information + /// + /// The remaining bytes in the segment block. + /// The image. + private void ProcessApp2Marker(int remaining, ImageMetaData metadata) + { + // Length is 14 though we only need to check 12. + const int Icclength = 14; + if (remaining < Icclength || this.IgnoreMetadata) + { + this.InputStream.Skip(remaining); + return; + } + + byte[] identifier = new byte[Icclength]; + this.InputStream.Read(identifier, 0, Icclength); + remaining -= Icclength; // We have read it by this point + + if (identifier[0] == JpegConstants.Markers.ICC.I && + identifier[1] == JpegConstants.Markers.ICC.C && + identifier[2] == JpegConstants.Markers.ICC.C && + identifier[3] == JpegConstants.Markers.ICC.UnderScore && + identifier[4] == JpegConstants.Markers.ICC.P && + identifier[5] == JpegConstants.Markers.ICC.R && + identifier[6] == JpegConstants.Markers.ICC.O && + identifier[7] == JpegConstants.Markers.ICC.F && + identifier[8] == JpegConstants.Markers.ICC.I && + identifier[9] == JpegConstants.Markers.ICC.L && + identifier[10] == JpegConstants.Markers.ICC.E && + identifier[11] == JpegConstants.Markers.ICC.Null) + { + byte[] profile = new byte[remaining]; + this.InputStream.Read(profile, 0, remaining); + + if (metadata.IccProfile == null) + { + metadata.IccProfile = new IccProfile(profile); + } + else + { + metadata.IccProfile.Extend(profile); + } + } + else + { + // Not an ICC profile we can handle. Skip the remaining bytes so we can carry on and ignore this. + this.InputStream.Skip(remaining); + } + } + + /// + /// Processes the application header containing the Adobe identifier + /// which stores image encoding information for DCT filters. + /// + /// The remaining bytes in the segment block. + private void ProcessApp14Marker(int remaining) + { + if (remaining < 12) + { + // Skip the application header length + this.InputStream.Skip(remaining); + return; + } + + this.InputStream.Read(this.temp, 0, 12); + remaining -= 12; + + bool isAdobe = this.temp[0] == JpegConstants.Markers.Adobe.A && + this.temp[1] == JpegConstants.Markers.Adobe.D && + this.temp[2] == JpegConstants.Markers.Adobe.O && + this.temp[3] == JpegConstants.Markers.Adobe.B && + this.temp[4] == JpegConstants.Markers.Adobe.E; + + if (isAdobe) + { + this.adobe = new Adobe + { + DCTEncodeVersion = (short)((this.temp[5] << 8) | this.temp[6]), + APP14Flags0 = (short)((this.temp[7] << 8) | this.temp[8]), + APP14Flags1 = (short)((this.temp[9] << 8) | this.temp[10]), + ColorTransform = this.temp[11] + }; + } + + if (remaining > 0) + { + this.InputStream.Skip(remaining); + } + } + + /// + /// Processes the Define Quantization Marker and tables. Specified in section B.2.4.1. + /// + /// The remaining bytes in the segment block. + /// + /// Thrown if the tables do not match the header + /// + private void ProcessDefineQuantizationTablesMarker(int remaining) + { + while (remaining > 0) + { + bool done = false; + remaining--; + int quantizationTableSpec = this.InputStream.ReadByte(); + + switch (quantizationTableSpec >> 4) + { + case 0: + { + // 8 bit values + if (remaining < 64) + { + done = true; + break; + } + + this.InputStream.Read(this.temp, 0, 64); + remaining -= 64; + + Span tableSpan = this.quantizationTables.Tables.GetRowSpan(quantizationTableSpec & 15); + for (int j = 0; j < 64; j++) + { + tableSpan[QuantizationTables.DctZigZag[j]] = this.temp[j]; + } + } + + break; + case 1: + { + // 16 bit values + if (remaining < 128) + { + done = true; + break; + } + + this.InputStream.Read(this.temp, 0, 128); + remaining -= 128; + + Span tableSpan = this.quantizationTables.Tables.GetRowSpan(quantizationTableSpec & 15); + for (int j = 0; j < 64; j++) + { + tableSpan[QuantizationTables.DctZigZag[j]] = (short)((this.temp[2 * j] << 8) | this.temp[(2 * j) + 1]); + } + } + + break; + default: + throw new ImageFormatException("Bad Tq index value"); + } + + if (done) + { + break; + } + } + + if (remaining != 0) + { + throw new ImageFormatException("DQT has wrong length"); + } + } + + /// + /// Processes the Start of Frame marker. Specified in section B.2.2. + /// + /// The remaining bytes in the segment block. + /// The current frame marker. + private void ProcessStartOfFrameMarker(int remaining, FileMarker frameMarker) + { + if (this.frame != null) + { + throw new ImageFormatException("Multiple SOF markers. Only single frame jpegs supported."); + } + + this.InputStream.Read(this.temp, 0, remaining); + + this.frame = new Frame + { + 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]), + ComponentCount = this.temp[5] + }; + + int maxH = 0; + int maxV = 0; + int index = 6; + + // No need to pool this. They max out at 4 + this.frame.ComponentIds = new byte[this.frame.ComponentCount]; + this.frame.Components = new FrameComponent[this.frame.ComponentCount]; + + for (int i = 0; i < this.frame.Components.Length; i++) + { + int h = this.temp[index + 1] >> 4; + int v = this.temp[index + 1] & 15; + + if (maxH < h) + { + maxH = h; + } + + if (maxV < v) + { + maxV = v; + } + + ref var component = ref this.frame.Components[i]; + component.Id = this.temp[index]; + component.HorizontalFactor = h; + component.VerticalFactor = v; + component.QuantizationIdentifier = this.temp[index + 2]; + + this.frame.ComponentIds[i] = component.Id; + + index += 3; + } + + this.frame.MaxHorizontalFactor = maxH; + this.frame.MaxVerticalFactor = maxV; + this.PrepareComponents(); + } + + /// + /// Processes a Define Huffman Table marker, and initializes a huffman + /// struct from its contents. Specified in section B.2.4.2. + /// + /// The remaining bytes in the segment block. + private void ProcessDefineHuffmanTablesMarker(int remaining) + { + if (remaining < 17) + { + throw new ImageFormatException($"DHT has wrong length: {remaining}"); + } + + using (var huffmanData = Buffer.CreateClean(256)) + { + for (int i = 2; i < remaining;) + { + byte huffmanTableSpec = (byte)this.InputStream.ReadByte(); + this.InputStream.Read(huffmanData.Array, 0, 16); + + using (var codeLengths = Buffer.CreateClean(17)) + { + int codeLengthSum = 0; + + for (int j = 1; j < 17; j++) + { + codeLengthSum += codeLengths[j] = huffmanData[j - 1]; + } + + using (var huffmanValues = Buffer.CreateClean(256)) + { + this.InputStream.Read(huffmanValues.Array, 0, codeLengthSum); + + i += 17 + codeLengthSum; + + this.BuildHuffmanTable( + huffmanTableSpec >> 4 == 0 ? this.dcHuffmanTables : this.acHuffmanTables, + huffmanTableSpec & 15, + codeLengths.Array, + huffmanValues.Array); + } + } + } + } + } + + /// + /// Processes the DRI (Define Restart Interval Marker) Which specifies the interval between RSTn markers, in + /// macroblocks + /// + /// The remaining bytes in the segment block. + private void ProcessDefineRestartIntervalMarker(int remaining) + { + if (remaining != 2) + { + throw new ImageFormatException($"DRI has wrong length: {remaining}"); + } + + this.resetInterval = this.ReadUint16(); + } + + /// + /// Processes the SOS (Start of scan marker). + /// + private void ProcessStartOfScanMarker() + { + int selectorsCount = this.InputStream.ReadByte(); + int componentIndex = -1; + for (int i = 0; i < selectorsCount; i++) + { + componentIndex = -1; + int selector = this.InputStream.ReadByte(); + + for (int j = 0; j < this.frame.ComponentIds.Length; j++) + { + byte id = this.frame.ComponentIds[j]; + if (selector == id) + { + componentIndex = j; + } + } + + if (componentIndex < 0) + { + throw new ImageFormatException("Unknown component selector"); + } + + ref FrameComponent component = ref this.frame.Components[componentIndex]; + int tableSpec = this.InputStream.ReadByte(); + component.DCHuffmanTableId = tableSpec >> 4; + component.ACHuffmanTableId = tableSpec & 15; + } + + this.InputStream.Read(this.temp, 0, 3); + + int spectralStart = this.temp[0]; + int spectralEnd = this.temp[1]; + int successiveApproximation = this.temp[2]; + var scanDecoder = default(ScanDecoder); + + scanDecoder.DecodeScan( + this.frame, + this.InputStream, + this.dcHuffmanTables, + this.acHuffmanTables, + this.frame.Components, + componentIndex, + selectorsCount, + this.resetInterval, + spectralStart, + spectralEnd, + successiveApproximation >> 4, + successiveApproximation & 15); + } + + /// + /// Build the data for the given component + /// + /// The component + /// The frame component + private void BuildComponentData(ref Component component, ref FrameComponent frameComponent) + { + int blocksPerLine = component.BlocksPerLine; + int blocksPerColumn = component.BlocksPerColumn; + using (var computationBuffer = Buffer.CreateClean(64)) + using (var multiplicationBuffer = Buffer.CreateClean(64)) + { + Span quantizationTable = this.quantizationTables.Tables.GetRowSpan(frameComponent.QuantizationIdentifier); + Span computationBufferSpan = computationBuffer; + + // For AA&N IDCT method, multiplier are equal to quantization + // coefficients scaled by scalefactor[row]*scalefactor[col], where + // scalefactor[0] = 1 + // scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 + // For integer operation, the multiplier table is to be scaled by 12. + Span multiplierSpan = multiplicationBuffer; + + // for (int i = 0; i < 64; i++) + // { + // multiplierSpan[i] = (short)IDCT.Descale(quantizationTable[i] * IDCT.Aanscales[i], 12); + // } + for (int blockRow = 0; blockRow < blocksPerColumn; blockRow++) + { + for (int blockCol = 0; blockCol < blocksPerLine; blockCol++) + { + int offset = GetBlockBufferOffset(ref component, blockRow, blockCol); + IDCT.QuantizeAndInverse(ref frameComponent, offset, ref computationBufferSpan, ref quantizationTable); + } + } + } + + component.Output = frameComponent.BlockData; + } + + /// + /// Builds the huffman tables + /// + /// The tables + /// The table index + /// The codelengths + /// The values + private void BuildHuffmanTable(HuffmanTables tables, int index, byte[] codeLengths, byte[] values) + { + tables[index] = new HuffmanTable(codeLengths, values); + } + + /// + /// Allocates the frame component blocks + /// + private void PrepareComponents() + { + int mcusPerLine = (int)MathF.Ceiling(this.frame.SamplesPerLine / 8F / this.frame.MaxHorizontalFactor); + int mcusPerColumn = (int)MathF.Ceiling(this.frame.Scanlines / 8F / this.frame.MaxVerticalFactor); + + for (int i = 0; i < this.frame.ComponentCount; i++) + { + ref var component = ref this.frame.Components[i]; + int blocksPerLine = (int)MathF.Ceiling(MathF.Ceiling(this.frame.SamplesPerLine / 8F) * component.HorizontalFactor / this.frame.MaxHorizontalFactor); + int blocksPerColumn = (int)MathF.Ceiling(MathF.Ceiling(this.frame.Scanlines / 8F) * component.VerticalFactor / this.frame.MaxVerticalFactor); + int blocksPerLineForMcu = mcusPerLine * component.HorizontalFactor; + int blocksPerColumnForMcu = mcusPerColumn * component.VerticalFactor; + + int blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1); + + // Pooled. Disposed via frame disposal + component.BlockData = Buffer.CreateClean(blocksBufferSize); + component.BlocksPerLine = blocksPerLine; + component.BlocksPerColumn = blocksPerColumn; + } + + this.frame.McusPerLine = mcusPerLine; + this.frame.McusPerColumn = mcusPerColumn; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void FillGrayScaleImage(Image image) + where TPixel : struct, IPixel + { + for (int y = 0; y < image.Height; y++) + { + Span imageRowSpan = image.GetRowSpan(y); + Span areaRowSpan = this.pixelArea.GetRowSpan(y); + + for (int x = 0; x < image.Width; x++) + { + ref byte luminance = ref areaRowSpan[x]; + ref TPixel pixel = ref imageRowSpan[x]; + var rgba = new Rgba32(luminance, luminance, luminance); + pixel.PackFromRgba32(rgba); + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void FillYCbCrImage(Image image) + where TPixel : struct, IPixel + { + for (int y = 0; y < image.Height; y++) + { + Span imageRowSpan = image.GetRowSpan(y); + Span areaRowSpan = this.pixelArea.GetRowSpan(y); + for (int x = 0, o = 0; x < image.Width; x++, o += 3) + { + ref byte yy = ref areaRowSpan[o]; + ref byte cb = ref areaRowSpan[o + 1]; + ref byte cr = ref areaRowSpan[o + 2]; + ref TPixel pixel = ref imageRowSpan[x]; + YCbCrToRgbTables.PackYCbCr(ref pixel, yy, cb, cr); + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void FillYcckImage(Image image) + where TPixel : struct, IPixel + { + for (int y = 0; y < image.Height; y++) + { + Span imageRowSpan = image.GetRowSpan(y); + Span areaRowSpan = this.pixelArea.GetRowSpan(y); + for (int x = 0, o = 0; x < image.Width; x++, o += 4) + { + ref byte yy = ref areaRowSpan[o]; + ref byte cb = ref areaRowSpan[o + 1]; + ref byte cr = ref areaRowSpan[o + 2]; + ref byte k = ref areaRowSpan[o + 3]; + + ref TPixel pixel = ref imageRowSpan[x]; + YCbCrToRgbTables.PackYccK(ref pixel, yy, cb, cr, k); + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void FillCmykImage(Image image) + where TPixel : struct, IPixel + { + for (int y = 0; y < image.Height; y++) + { + Span imageRowSpan = image.GetRowSpan(y); + Span areaRowSpan = this.pixelArea.GetRowSpan(y); + for (int x = 0, o = 0; x < image.Width; x++, o += 4) + { + ref byte c = ref areaRowSpan[o]; + ref byte m = ref areaRowSpan[o + 1]; + ref byte cy = ref areaRowSpan[o + 2]; + ref byte k = ref areaRowSpan[o + 3]; + + byte r = (byte)((c * k) / 255); + byte g = (byte)((m * k) / 255); + byte b = (byte)((cy * k) / 255); + + ref TPixel pixel = ref imageRowSpan[x]; + var rgba = new Rgba32(r, g, b); + pixel.PackFromRgba32(rgba); + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void FillRgbImage(Image image) + where TPixel : struct, IPixel + { + for (int y = 0; y < image.Height; y++) + { + Span imageRowSpan = image.GetRowSpan(y); + Span areaRowSpan = this.pixelArea.GetRowSpan(y); + + PixelOperations.Instance.PackFromRgb24Bytes(areaRowSpan, imageRowSpan, image.Width); + } + } + + /// + /// Reads a from the stream advancing it by two bytes + /// + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private ushort ReadUint16() + { + this.InputStream.Read(this.markerBuffer, 0, 2); + return (ushort)((this.markerBuffer[0] << 8) | this.markerBuffer[1]); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs index db2189b3c4..061fea8a40 100644 --- a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Runtime.CompilerServices; +using System; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Formats +{ /// /// The Average filter uses the average of the two neighboring pixels (left and above) to predict /// the value of a pixel. diff --git a/src/ImageSharp/Formats/Png/Filters/FilterType.cs b/src/ImageSharp/Formats/Png/Filters/FilterType.cs index 0eddf08f20..33fc646568 100644 --- a/src/ImageSharp/Formats/Png/Filters/FilterType.cs +++ b/src/ImageSharp/Formats/Png/Filters/FilterType.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Provides enumeration of the various PNG filter types. diff --git a/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs b/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs index ee77d1a5eb..be3c06d70b 100644 --- a/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Runtime.CompilerServices; - - using ImageSharp.Memory; +using System; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp.Formats +{ /// /// The None filter, the scanline is transmitted unmodified; it is only necessary to /// insert a filter type byte before the data. diff --git a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs index ec12eca058..6db580534c 100644 --- a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Runtime.CompilerServices; +using System; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Formats +{ /// /// The Paeth filter computes a simple linear function of the three neighboring pixels (left, above, upper left), /// then chooses as predictor the neighboring pixel closest to the computed value. diff --git a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs index f81122ad24..62cc57718b 100644 --- a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Runtime.CompilerServices; +using System; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Formats +{ /// /// The Sub filter transmits the difference between each byte and the value of the corresponding byte /// of the prior pixel. diff --git a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs index b89a3c5fcc..a2051d33ff 100644 --- a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Runtime.CompilerServices; +using System; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Formats +{ /// /// The Up filter is just like the Sub filter except that the pixel immediately above the current pixel, /// rather than just to its left, is used as the predictor. diff --git a/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs b/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs index de163ba7e5..c612a7159b 100644 --- a/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs +++ b/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Text; - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// The optioas for decoding png images /// diff --git a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs index 8f0a4cd829..73d7a393b4 100644 --- a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs +++ b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System.Collections.Generic; - using System.IO; - - using ImageSharp.PixelFormats; - using ImageSharp.Quantizers; +using System.Collections.Generic; +using System.IO; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Quantizers; +namespace SixLabors.ImageSharp.Formats +{ /// /// The options availible for manipulating the encoder pipeline /// diff --git a/src/ImageSharp/Formats/Png/ImageExtensions.cs b/src/ImageSharp/Formats/Png/ImageExtensions.cs index c817385760..70815e0faf 100644 --- a/src/ImageSharp/Formats/Png/ImageExtensions.cs +++ b/src/ImageSharp/Formats/Png/ImageExtensions.cs @@ -1,16 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.IO; - - using Formats; - - using ImageSharp.PixelFormats; +using System.IO; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -23,14 +19,9 @@ public static partial class ImageExtensions /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsPng(this Image source, Stream stream) + public static void SaveAsPng(this Image source, Stream stream) where TPixel : struct, IPixel - { - return SaveAsPng(source, stream, null); - } + => SaveAsPng(source, stream, null); /// /// Saves the image to the given stream with the png format. @@ -40,16 +31,8 @@ public static Image SaveAsPng(this Image source, Stream /// The stream to save the image to. /// The options for the encoder. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsPng(this Image source, Stream stream, PngEncoder encoder) + public static void SaveAsPng(this Image source, Stream stream, PngEncoder encoder) where TPixel : struct, IPixel - { - encoder = encoder ?? new PngEncoder(); - encoder.Encode(source, stream); - - return source; - } + => source.Save(stream, encoder ?? source.Configuration.FindEncoder(ImageFormats.Png)); } } diff --git a/src/ImageSharp/Formats/Png/PngChunk.cs b/src/ImageSharp/Formats/Png/PngChunk.cs index 3d769057ca..9e7357f00a 100644 --- a/src/ImageSharp/Formats/Png/PngChunk.cs +++ b/src/ImageSharp/Formats/Png/PngChunk.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Stores header information about a chunk. diff --git a/src/ImageSharp/Formats/Png/PngChunkTypes.cs b/src/ImageSharp/Formats/Png/PngChunkTypes.cs index 72486b50d7..b501783d54 100644 --- a/src/ImageSharp/Formats/Png/PngChunkTypes.cs +++ b/src/ImageSharp/Formats/Png/PngChunkTypes.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Contains a list of possible chunk type identifiers. diff --git a/src/ImageSharp/Formats/Png/PngColorType.cs b/src/ImageSharp/Formats/Png/PngColorType.cs index 421e27ba33..093edaddd9 100644 --- a/src/ImageSharp/Formats/Png/PngColorType.cs +++ b/src/ImageSharp/Formats/Png/PngColorType.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Provides enumeration of available PNG color types. diff --git a/src/ImageSharp/Formats/Png/PngConfigurationModule.cs b/src/ImageSharp/Formats/Png/PngConfigurationModule.cs index bb1c2086cc..c362e19529 100644 --- a/src/ImageSharp/Formats/Png/PngConfigurationModule.cs +++ b/src/ImageSharp/Formats/Png/PngConfigurationModule.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Registers the image encoders, decoders and mime type detectors for the png format. diff --git a/src/ImageSharp/Formats/Png/PngConstants.cs b/src/ImageSharp/Formats/Png/PngConstants.cs index 84e76a3419..3c8992a540 100644 --- a/src/ImageSharp/Formats/Png/PngConstants.cs +++ b/src/ImageSharp/Formats/Png/PngConstants.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System.Collections.Generic; - using System.Text; +using System.Collections.Generic; +using System.Text; +namespace SixLabors.ImageSharp.Formats +{ /// /// Defines png constants defined in the specification. /// diff --git a/src/ImageSharp/Formats/Png/PngDecoder.cs b/src/ImageSharp/Formats/Png/PngDecoder.cs index 61a8cb2127..da3a2f139c 100644 --- a/src/ImageSharp/Formats/Png/PngDecoder.cs +++ b/src/ImageSharp/Formats/Png/PngDecoder.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Text; - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Formats +{ /// /// Encoder for generating an image out of a png encoded stream. /// diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index d9df44a091..75ca69684a 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -1,22 +1,19 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +using System; +using System.Buffers; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using static SixLabors.ImageSharp.ComparableExtensions; + +namespace SixLabors.ImageSharp.Formats { - using System; - using System.Buffers; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Runtime.CompilerServices; - using System.Text; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - - using static ComparableExtensions; - /// /// Performs the png decoding operation. /// diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs index bfd82a0748..583d77a8ab 100644 --- a/src/ImageSharp/Formats/Png/PngEncoder.cs +++ b/src/ImageSharp/Formats/Png/PngEncoder.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System.Collections.Generic; - using System.IO; - - using ImageSharp.PixelFormats; - using ImageSharp.Quantizers; +using System.Collections.Generic; +using System.IO; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Quantizers; +namespace SixLabors.ImageSharp.Formats +{ /// /// Image encoder for writing image data to a stream in png format. /// diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index cfbd0c4493..cee62fde36 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -1,23 +1,18 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +using System; +using System.Buffers; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Quantizers; +using static SixLabors.ImageSharp.ComparableExtensions; + +namespace SixLabors.ImageSharp.Formats { - using System; - using System.Buffers; - using System.IO; - using System.Linq; - using System.Runtime.CompilerServices; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - - using Quantizers; - - using static ComparableExtensions; - /// /// Performs the png encoding operation. /// diff --git a/src/ImageSharp/Formats/Png/PngFormat.cs b/src/ImageSharp/Formats/Png/PngFormat.cs index 6df2aa7c58..9cfa660126 100644 --- a/src/ImageSharp/Formats/Png/PngFormat.cs +++ b/src/ImageSharp/Formats/Png/PngFormat.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System.Collections.Generic; +using System.Collections.Generic; +namespace SixLabors.ImageSharp.Formats +{ /// /// Registers the image encoders, decoders and mime type detectors for the png format. /// diff --git a/src/ImageSharp/Formats/Png/PngHeader.cs b/src/ImageSharp/Formats/Png/PngHeader.cs index 9cf823fa19..3bbf10526a 100644 --- a/src/ImageSharp/Formats/Png/PngHeader.cs +++ b/src/ImageSharp/Formats/Png/PngHeader.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Represents the png header chunk. diff --git a/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs b/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs index fdea3eb8ae..bf4a91caf2 100644 --- a/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; +using System; +namespace SixLabors.ImageSharp.Formats +{ /// /// Detects png file headers /// diff --git a/src/ImageSharp/Formats/Png/PngInterlaceMode.cs b/src/ImageSharp/Formats/Png/PngInterlaceMode.cs index b43aff0b78..a39ccd6bed 100644 --- a/src/ImageSharp/Formats/Png/PngInterlaceMode.cs +++ b/src/ImageSharp/Formats/Png/PngInterlaceMode.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Provides enumeration of available PNG interlace modes. diff --git a/src/ImageSharp/Formats/Png/Zlib/Adler32.cs b/src/ImageSharp/Formats/Png/Zlib/Adler32.cs index 5f92cc9e09..d0ddd84405 100644 --- a/src/ImageSharp/Formats/Png/Zlib/Adler32.cs +++ b/src/ImageSharp/Formats/Png/Zlib/Adler32.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; +using System; +namespace SixLabors.ImageSharp.Formats +{ /// /// Computes Adler32 checksum for a stream of data. An Adler32 /// checksum is not as reliable as a CRC32 checksum, but a lot faster to diff --git a/src/ImageSharp/Formats/Png/Zlib/Crc32.cs b/src/ImageSharp/Formats/Png/Zlib/Crc32.cs index d940112a8d..7ca0f668b5 100644 --- a/src/ImageSharp/Formats/Png/Zlib/Crc32.cs +++ b/src/ImageSharp/Formats/Png/Zlib/Crc32.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; +using System; +namespace SixLabors.ImageSharp.Formats +{ /// /// 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. diff --git a/src/ImageSharp/Formats/Png/Zlib/IChecksum.cs b/src/ImageSharp/Formats/Png/Zlib/IChecksum.cs index cbd292dc4c..4b656ab9cd 100644 --- a/src/ImageSharp/Formats/Png/Zlib/IChecksum.cs +++ b/src/ImageSharp/Formats/Png/Zlib/IChecksum.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats +namespace SixLabors.ImageSharp.Formats { /// /// Interface to compute a data checksum used by checked input/output streams. diff --git a/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs b/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs index c1f04fa981..11ddb10730 100644 --- a/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs +++ b/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System; - using System.IO; - using System.IO.Compression; +using System; +using System.IO; +using System.IO.Compression; +namespace SixLabors.ImageSharp.Formats +{ /// /// Provides methods and properties for compressing streams by using the Zlib Deflate algorithm. /// diff --git a/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs b/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs index 136f919da7..d668ff4176 100644 --- a/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs +++ b/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs @@ -1,11 +1,14 @@ -namespace ImageSharp.Formats -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.IO.Compression; - using System.Text; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Text; +namespace SixLabors.ImageSharp.Formats +{ /// /// Provides methods and properties for deframing streams from PNGs. /// diff --git a/src/ImageSharp/GraphicsOptions.cs b/src/ImageSharp/GraphicsOptions.cs index f45582e1e6..114eaab2a6 100644 --- a/src/ImageSharp/GraphicsOptions.cs +++ b/src/ImageSharp/GraphicsOptions.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Options for influencing the drawing functions. /// diff --git a/src/ImageSharp/IConfigurationModule.cs b/src/ImageSharp/IConfigurationModule.cs index 95b92ed056..93c40497da 100644 --- a/src/ImageSharp/IConfigurationModule.cs +++ b/src/ImageSharp/IConfigurationModule.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Represents an interface that can register image encoders, decoders and image format detectors. diff --git a/src/ImageSharp/IImageProcessingContextFactory.cs b/src/ImageSharp/IImageProcessingContextFactory.cs new file mode 100644 index 0000000000..b7b935ecd5 --- /dev/null +++ b/src/ImageSharp/IImageProcessingContextFactory.cs @@ -0,0 +1,36 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp +{ + /// + /// Represents an interface that will create IInternalImageProcessingContext instances + /// + internal interface IImageProcessingContextFactory + { + /// + /// Called during mutate operations to generate the image operations provider. + /// + /// The pixel format + /// The source image. + /// A flag to determine whether image operations are allowed to mutate the source image. + /// A new IImageOPeration + IInternalImageProcessingContext CreateImageProcessingContext(Image source, bool mutate) + where TPixel : struct, IPixel; + } + + /// + /// The default implmentation of + /// + internal class DefaultImageOperationsProviderFactory : IImageProcessingContextFactory + { + /// + public IInternalImageProcessingContext CreateImageProcessingContext(Image source, bool mutate) + where TPixel : struct, IPixel + { + return new DefaultInternalImageProcessorContext(source, mutate); + } + } +} diff --git a/src/ImageSharp/IImageProcessingContext{TPixel}.cs b/src/ImageSharp/IImageProcessingContext{TPixel}.cs new file mode 100644 index 0000000000..552e8d579d --- /dev/null +++ b/src/ImageSharp/IImageProcessingContext{TPixel}.cs @@ -0,0 +1,46 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp +{ + /// + /// An interface to queue up image operations to apply to an image. + /// + /// The pixel format + public interface IImageProcessingContext + where TPixel : struct, IPixel + { + /// + /// Adds the processor to the current set of image operations to be applied. + /// + /// The processor to apply + /// The area to apply it to + /// The current operations class to allow chaining of operations. + IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle); + + /// + /// Adds the processor to the current set of image operations to be applied. + /// + /// The processor to apply + /// The current operations class to allow chaining of operations. + IImageProcessingContext ApplyProcessor(IImageProcessor processor); + } + + /// + /// An internal interface to queue up image operations and have a method to apply them to and return a result + /// + /// The pixel format + internal interface IInternalImageProcessingContext : IImageProcessingContext + where TPixel : struct, IPixel + { + /// + /// Adds the processors to the current image + /// + /// The current image or a new image depending on withere this is alloed to mutate the source image. + Image Apply(); + } +} \ No newline at end of file diff --git a/src/ImageSharp/IO/BigEndianBitConverter.cs b/src/ImageSharp/IO/BigEndianBitConverter.cs index debe1706c9..6b5cf3b9c7 100644 --- a/src/ImageSharp/IO/BigEndianBitConverter.cs +++ b/src/ImageSharp/IO/BigEndianBitConverter.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.IO +namespace SixLabors.ImageSharp.IO { /// /// Implementation of EndianBitConverter which converts to/from big-endian byte arrays. diff --git a/src/ImageSharp/IO/EndianBinaryReader.cs b/src/ImageSharp/IO/EndianBinaryReader.cs index e21d3d3db3..0d660c68d5 100644 --- a/src/ImageSharp/IO/EndianBinaryReader.cs +++ b/src/ImageSharp/IO/EndianBinaryReader.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.IO -{ - using System; - using System.IO; - using System.Text; +using System; +using System.IO; +using System.Text; +namespace SixLabors.ImageSharp.IO +{ /// /// Equivalent of , but with either endianness, depending on the it is constructed with. /// No data is buffered in the reader; the client may seek within the stream at will. diff --git a/src/ImageSharp/IO/EndianBinaryWriter.cs b/src/ImageSharp/IO/EndianBinaryWriter.cs index ef026f00c2..dd87faf455 100644 --- a/src/ImageSharp/IO/EndianBinaryWriter.cs +++ b/src/ImageSharp/IO/EndianBinaryWriter.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.IO -{ - using System; - using System.IO; - using System.Text; +using System; +using System.IO; +using System.Text; +namespace SixLabors.ImageSharp.IO +{ /// /// Equivalent of , but with either endianness, depending on /// the it is constructed with. diff --git a/src/ImageSharp/IO/EndianBitConverter.Conversion.cs b/src/ImageSharp/IO/EndianBitConverter.Conversion.cs index 0858acfedc..844c81cc9e 100644 --- a/src/ImageSharp/IO/EndianBitConverter.Conversion.cs +++ b/src/ImageSharp/IO/EndianBitConverter.Conversion.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.IO -{ - using System; +using System; +namespace SixLabors.ImageSharp.IO +{ /// /// Equivalent of , but with either endianness. /// diff --git a/src/ImageSharp/IO/EndianBitConverter.CopyBytes.cs b/src/ImageSharp/IO/EndianBitConverter.CopyBytes.cs index b46a453a4f..ea1d7aa5ac 100644 --- a/src/ImageSharp/IO/EndianBitConverter.CopyBytes.cs +++ b/src/ImageSharp/IO/EndianBitConverter.CopyBytes.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.IO -{ - using System; +using System; +namespace SixLabors.ImageSharp.IO +{ /// /// Equivalent of , but with either endianness. /// diff --git a/src/ImageSharp/IO/EndianBitConverter.GetBytes.cs b/src/ImageSharp/IO/EndianBitConverter.GetBytes.cs index b3e0133e43..5686c829c4 100644 --- a/src/ImageSharp/IO/EndianBitConverter.GetBytes.cs +++ b/src/ImageSharp/IO/EndianBitConverter.GetBytes.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.IO -{ - using System; +using System; +namespace SixLabors.ImageSharp.IO +{ /// /// Equivalent of , but with either endianness. /// diff --git a/src/ImageSharp/IO/EndianBitConverter.ToType.cs b/src/ImageSharp/IO/EndianBitConverter.ToType.cs index 93b49558ad..0c0e49911b 100644 --- a/src/ImageSharp/IO/EndianBitConverter.ToType.cs +++ b/src/ImageSharp/IO/EndianBitConverter.ToType.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.IO -{ - using System; +using System; +namespace SixLabors.ImageSharp.IO +{ /// /// Equivalent of , but with either endianness. /// diff --git a/src/ImageSharp/IO/EndianBitConverter.cs b/src/ImageSharp/IO/EndianBitConverter.cs index 06b88dbc90..b563a09cb8 100644 --- a/src/ImageSharp/IO/EndianBitConverter.cs +++ b/src/ImageSharp/IO/EndianBitConverter.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.IO -{ - using System; - using System.Runtime.CompilerServices; +using System; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.IO +{ /// /// Equivalent of , but with either endianness. /// diff --git a/src/ImageSharp/IO/Endianness.cs b/src/ImageSharp/IO/Endianness.cs index aefda6dc4b..59b2ae77c1 100644 --- a/src/ImageSharp/IO/Endianness.cs +++ b/src/ImageSharp/IO/Endianness.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.IO +namespace SixLabors.ImageSharp.IO { /// /// Endianness of a converter diff --git a/src/ImageSharp/IO/IFileSystem.cs b/src/ImageSharp/IO/IFileSystem.cs index ee1ef84d7b..072c05ea7f 100644 --- a/src/ImageSharp/IO/IFileSystem.cs +++ b/src/ImageSharp/IO/IFileSystem.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.IO -{ - using System.IO; +using System.IO; +namespace SixLabors.ImageSharp.IO +{ #if !NETSTANDARD1_1 /// /// A simple interface representing the filesystem. diff --git a/src/ImageSharp/IO/LittleEndianBitConverter.cs b/src/ImageSharp/IO/LittleEndianBitConverter.cs index 81ed8d55c2..712bfd97b1 100644 --- a/src/ImageSharp/IO/LittleEndianBitConverter.cs +++ b/src/ImageSharp/IO/LittleEndianBitConverter.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.IO +namespace SixLabors.ImageSharp.IO { /// /// Implementation of EndianBitConverter which converts to/from little-endian byte arrays. diff --git a/src/ImageSharp/IO/LocalFileSystem.cs b/src/ImageSharp/IO/LocalFileSystem.cs index 02a9914ead..9c419698ff 100644 --- a/src/ImageSharp/IO/LocalFileSystem.cs +++ b/src/ImageSharp/IO/LocalFileSystem.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.IO -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Text; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +namespace SixLabors.ImageSharp.IO +{ #if !NETSTANDARD1_1 /// /// A wrapper around the local File apis. diff --git a/src/ImageSharp/Image/ICloningImageProcessor.cs b/src/ImageSharp/Image/ICloningImageProcessor.cs new file mode 100644 index 0000000000..1e7d6e4f0a --- /dev/null +++ b/src/ImageSharp/Image/ICloningImageProcessor.cs @@ -0,0 +1,32 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing +{ + /// + /// Encapsulates methods to alter the pixels of a new image, cloned from the original image. + /// + /// The pixel format. + internal interface ICloningImageProcessor : IImageProcessor + where TPixel : struct, IPixel + { + /// + /// Applies the process to the specified portion of the specified . + /// + /// The source image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + /// + /// is null. + /// + /// + /// doesnt fit the dimension of the image. + /// + /// Returns the cloned image after thre processor has been applied to it. + Image CloneAndApply(Image source, Rectangle sourceRectangle); + } +} diff --git a/src/ImageSharp/Image/IImage.cs b/src/ImageSharp/Image/IImage.cs index b9e8e392a3..6e05757276 100644 --- a/src/ImageSharp/Image/IImage.cs +++ b/src/ImageSharp/Image/IImage.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using Formats; +using SixLabors.ImageSharp.Formats; +namespace SixLabors.ImageSharp +{ /// /// Encapsulates the basic properties and methods required to manipulate images. /// diff --git a/src/ImageSharp/Image/IImageBase.cs b/src/ImageSharp/Image/IImageBase.cs index 0e087aa4a3..9aea1517d6 100644 --- a/src/ImageSharp/Image/IImageBase.cs +++ b/src/ImageSharp/Image/IImageBase.cs @@ -1,22 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using SixLabors.Primitives; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Encapsulates the basic properties and methods required to manipulate images. /// public interface IImageBase { - /// - /// Gets the representing the bounds of the image. - /// - Rectangle Bounds { get; } - /// /// Gets the width in pixels. /// @@ -27,11 +20,6 @@ public interface IImageBase /// int Height { get; } - /// - /// Gets the pixel ratio made up of the width and height. - /// - double PixelRatio { get; } - /// /// Gets the configuration providing initialization code which allows extending the library. /// diff --git a/src/ImageSharp/Image/IImageBase{TPixel}.cs b/src/ImageSharp/Image/IImageBase{TPixel}.cs index 8b4977b7dc..a05867db3c 100644 --- a/src/ImageSharp/Image/IImageBase{TPixel}.cs +++ b/src/ImageSharp/Image/IImageBase{TPixel}.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using ImageSharp.PixelFormats; +using System; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Encapsulates the basic properties and methods required to manipulate images in varying formats. /// diff --git a/src/ImageSharp/Image/IImageFrame.cs b/src/ImageSharp/Image/IImageFrame.cs index bf3261d93c..3d23d6e09a 100644 --- a/src/ImageSharp/Image/IImageFrame.cs +++ b/src/ImageSharp/Image/IImageFrame.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Encapsulates the basic properties and methods required to manipulate images. diff --git a/src/ImageSharp/Image/IImageProcessor.cs b/src/ImageSharp/Image/IImageProcessor.cs index 8687766d5e..5eec31b478 100644 --- a/src/ImageSharp/Image/IImageProcessor.cs +++ b/src/ImageSharp/Image/IImageProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing -{ - using System; - using System.Threading.Tasks; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Threading.Tasks; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing +{ /// /// Encapsulates methods to alter the pixels of an image. /// @@ -42,6 +39,6 @@ public interface IImageProcessor /// /// doesnt fit the dimension of the image. /// - void Apply(ImageBase source, Rectangle sourceRectangle); + void Apply(Image source, Rectangle sourceRectangle); } } diff --git a/src/ImageSharp/Image/Image.Decode.cs b/src/ImageSharp/Image/Image.Decode.cs index 1013107062..b4ab712d05 100644 --- a/src/ImageSharp/Image/Image.Decode.cs +++ b/src/ImageSharp/Image/Image.Decode.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.IO; - using System.Linq; - using Formats; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System.IO; +using System.Linq; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Adds static methods allowing the decoding of new images. /// diff --git a/src/ImageSharp/Image/Image.FromBytes.cs b/src/ImageSharp/Image/Image.FromBytes.cs index c7023b860b..9da9c5e432 100644 --- a/src/ImageSharp/Image/Image.FromBytes.cs +++ b/src/ImageSharp/Image/Image.FromBytes.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.IO; - using Formats; - - using ImageSharp.PixelFormats; +using System.IO; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Adds static methods allowing the creation of new image from a byte array. /// diff --git a/src/ImageSharp/Image/Image.FromFile.cs b/src/ImageSharp/Image/Image.FromFile.cs index ca395ce088..0474a6d476 100644 --- a/src/ImageSharp/Image/Image.FromFile.cs +++ b/src/ImageSharp/Image/Image.FromFile.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ #if !NETSTANDARD1_1 - using System; - using System.IO; - using Formats; - using ImageSharp.PixelFormats; +using System; +using System.IO; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Adds static methods allowing the creation of new image from a given file. /// @@ -217,5 +215,5 @@ public static Image Load(Configuration config, string path, IIma } } } -#endif -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/ImageSharp/Image/Image.FromStream.cs b/src/ImageSharp/Image/Image.FromStream.cs index 29d93ae859..90fa12e3f5 100644 --- a/src/ImageSharp/Image/Image.FromStream.cs +++ b/src/ImageSharp/Image/Image.FromStream.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Text; - using Formats; - - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Adds static methods allowing the creation of new image from a given stream. /// diff --git a/src/ImageSharp/Image/Image.LoadPixelData.cs b/src/ImageSharp/Image/Image.LoadPixelData.cs index 7b6a4d6684..2438d9eec8 100644 --- a/src/ImageSharp/Image/Image.LoadPixelData.cs +++ b/src/ImageSharp/Image/Image.LoadPixelData.cs @@ -1,18 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.IO; - using System.Runtime.CompilerServices; - using System.Threading.Tasks; - using Formats; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.IO; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Adds static methods allowing the creation of new image from raw pixel data. /// diff --git a/src/ImageSharp/Image/ImageBase{TPixel}.cs b/src/ImageSharp/Image/ImageBase{TPixel}.cs index 20b891f2dd..db8964fa31 100644 --- a/src/ImageSharp/Image/ImageBase{TPixel}.cs +++ b/src/ImageSharp/Image/ImageBase{TPixel}.cs @@ -1,25 +1,21 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Diagnostics; - using System.Runtime.CompilerServices; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - using SixLabors.Primitives; +using System; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// The base class of all images. Encapsulates the basic properties and methods required to manipulate /// images in different pixel formats. /// /// The pixel format. - [DebuggerDisplay("Image: {Width}x{Height}")] public abstract class ImageBase : IImageBase where TPixel : struct, IPixel { @@ -105,12 +101,8 @@ protected ImageBase(ImageBase other) // Rent then copy the pixels. Unsafe.CopyBlock gives us a nice speed boost here. this.RentPixels(); - using (PixelAccessor sourcePixels = other.Lock()) - using (PixelAccessor target = this.Lock()) - { - // Check we can do this without crashing - sourcePixels.CopyTo(target); - } + + other.Pixels.CopyTo(this.Pixels); } /// @@ -122,12 +114,6 @@ protected ImageBase(ImageBase other) /// public int Height { get; private set; } - /// - public double PixelRatio => (double)this.Width / this.Height; - - /// - public Rectangle Bounds => new Rectangle(0, 0, this.Width, this.Height); - /// /// Gets the configuration providing initialization code which allows extending the library. /// @@ -195,13 +181,12 @@ public Span GetRowSpan(int x, int y) } /// - /// Applies the processor. + /// Clones the image /// - /// The processor. - /// The rectangle. - public virtual void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + /// A new items which is a clone of the original. + public ImageBase Clone() { - processor.Apply(this, rectangle); + return this.CloneInternal(); } /// @@ -256,6 +241,33 @@ internal void SwapPixelsBuffers(PixelAccessor pixelSource) this.PixelBuffer = newPixels; } + /// + /// Switches the buffers used by the image and the pixelSource meaning that the Image will "own" the buffer from the pixelSource and the pixelSource will now own the Images buffer. + /// + /// The pixel source. + internal void SwapPixelsData(ImageBase pixelSource) + { + Guard.NotNull(pixelSource, nameof(pixelSource)); + + int newWidth = pixelSource.Width; + int newHeight = pixelSource.Height; + TPixel[] newPixels = pixelSource.PixelBuffer; + + pixelSource.PixelBuffer = this.PixelBuffer; + pixelSource.Width = this.Width; + pixelSource.Height = this.Height; + + this.Width = newWidth; + this.Height = newHeight; + this.PixelBuffer = newPixels; + } + + /// + /// Clones the image + /// + /// A new items which is a clone of the original. + protected abstract ImageBase CloneInternal(); + /// /// Copies the properties from the other . /// diff --git a/src/ImageSharp/Image/ImageExtensions.cs b/src/ImageSharp/Image/ImageExtensions.cs new file mode 100644 index 0000000000..1c1d7b1475 --- /dev/null +++ b/src/ImageSharp/Image/ImageExtensions.cs @@ -0,0 +1,151 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp +{ + /// + /// Extension methods over Image{TPixel} + /// + public static partial class ImageExtensions + { + /// + /// Gets the bounds of the image. + /// + /// The Pixel format. + /// The source image + /// Returns the bounds of the image + public static Rectangle Bounds(this ImageBase source) + where TPixel : struct, IPixel + => new Rectangle(0, 0, source.Width, source.Height); + + /// + /// Gets the size of the image. + /// + /// The Pixel format. + /// The source image + /// Returns the bounds of the image + public static Size Size(this ImageBase source) + where TPixel : struct, IPixel + => new Size(source.Width, source.Height); + +#if !NETSTANDARD1_1 + /// + /// Saves the image to the given stream using the currently loaded image format. + /// + /// The Pixel 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) + where TPixel : struct, IPixel + { + Guard.NotNullOrEmpty(filePath, nameof(filePath)); + + string ext = Path.GetExtension(filePath).Trim('.'); + IImageFormat format = source.Configuration.FindFormatByFileExtension(ext); + if (format == null) + { + var stringBuilder = new StringBuilder(); + stringBuilder.AppendLine($"Can't find a format that is associated with the file extention '{ext}'. Registered formats with there extensions include:"); + foreach (IImageFormat fmt in source.Configuration.ImageFormats) + { + stringBuilder.AppendLine($" - {fmt.Name} : {string.Join(", ", fmt.FileExtensions)}"); + } + + throw new NotSupportedException(stringBuilder.ToString()); + } + + IImageEncoder encoder = source.Configuration.FindEncoder(format); + + if (encoder == null) + { + var stringBuilder = new StringBuilder(); + stringBuilder.AppendLine($"Can't find encoder for file extention '{ext}' using image format '{format.Name}'. Registered encoders include:"); + foreach (KeyValuePair enc in source.Configuration.ImageEncoders) + { + stringBuilder.AppendLine($" - {enc.Key} : {enc.Value.GetType().Name}"); + } + + throw new NotSupportedException(stringBuilder.ToString()); + } + + source.Save(filePath, encoder); + } + + /// + /// Saves the image to the given stream using the currently loaded image format. + /// + /// The Pixel format. + /// The source image + /// 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) + where TPixel : struct, IPixel + { + Guard.NotNull(encoder, nameof(encoder)); + using (Stream fs = source.Configuration.FileSystem.Create(filePath)) + { + source.Save(fs, encoder); + } + } +#endif + + /// + /// Saves the image to the given stream using the currently loaded image format. + /// + /// The Pixel format. + /// The source image + /// The stream to save the image to. + /// The format to save the image to. + /// Thrown if the stream is null. + public static void Save(this Image source, Stream stream, IImageFormat format) + where TPixel : struct, IPixel + { + Guard.NotNull(format, nameof(format)); + IImageEncoder encoder = source.Configuration.FindEncoder(format); + + if (encoder == null) + { + var stringBuilder = new StringBuilder(); + stringBuilder.AppendLine("Can't find encoder for provided mime type. Available encoded:"); + + foreach (KeyValuePair val in source.Configuration.ImageEncoders) + { + stringBuilder.AppendLine($" - {val.Key.Name} : {val.Value.GetType().Name}"); + } + + throw new NotSupportedException(stringBuilder.ToString()); + } + + source.Save(stream, encoder); + } + + /// + /// Returns a Base64 encoded string from the given image. + /// + /// + /// The Pixel format. + /// The source image + /// The format. + /// The + public static string ToBase64String(this Image source, IImageFormat format) + where TPixel : struct, IPixel + { + using (var stream = new MemoryStream()) + { + source.Save(stream, format); + stream.Flush(); + return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(stream.ToArray())}"; + } + } + } +} diff --git a/src/ImageSharp/Image/ImageFrame{TPixel}.cs b/src/ImageSharp/Image/ImageFrame{TPixel}.cs index 04b9902c67..333fd9c5f2 100644 --- a/src/ImageSharp/Image/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/Image/ImageFrame{TPixel}.cs @@ -1,77 +1,108 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Represents a single frame in a animation. /// /// The pixel format. - public class ImageFrame : ImageBase, IImageFrame + public sealed class ImageFrame : ImageBase, IImageFrame where TPixel : struct, IPixel { /// /// Initializes a new instance of the class. /// + /// + /// The configuration providing initialization code which allows extending the library. + /// /// The width of the image in pixels. /// The height of the image in pixels. + public ImageFrame(Configuration configuration, int width, int height) + : base(configuration, width, height) + { + this.MetaData = new ImageFrameMetaData(); + } + + /// + /// Initializes a new instance of the class. + /// /// /// The configuration providing initialization code which allows extending the library. /// - public ImageFrame(int width, int height, Configuration configuration = null) + /// The width of the image in pixels. + /// The height of the image in pixels. + /// The metadata of the frame. + public ImageFrame(Configuration configuration, int width, int height, ImageFrameMetaData metadata) : base(configuration, width, height) { + Guard.NotNull(metadata, nameof(metadata)); + this.MetaData = metadata; + } + + /// + /// Initializes a new instance of the class. + /// + /// The width of the image in pixels. + /// The height of the image in pixels. + public ImageFrame(int width, int height) + : this(null, width, height) + { + this.MetaData = new ImageFrameMetaData(); } /// /// Initializes a new instance of the class. /// /// The image to create the frame from. - public ImageFrame(ImageFrame image) + internal ImageFrame(ImageBase image) : base(image) { - this.CopyProperties(image); + this.MetaData = new ImageFrameMetaData(); } /// /// Initializes a new instance of the class. /// /// The image to create the frame from. - public ImageFrame(ImageBase image) + private ImageFrame(ImageFrame image) : base(image) { + this.CopyProperties(image); } /// /// Gets the meta data of the frame. /// - public ImageFrameMetaData MetaData { get; private set; } = new ImageFrameMetaData(); + public ImageFrameMetaData MetaData { get; private set; } /// public override string ToString() { - return $"ImageFrame: {this.Width}x{this.Height}"; + return $"ImageFrame<{typeof(TPixel).Name}>: {this.Width}x{this.Height}"; } /// /// Returns a copy of the image frame in the given pixel format. /// - /// A function that allows for the correction of vector scaling between unknown color formats. /// The pixel format. /// The - public ImageFrame To(Func scaleFunc = null) + public ImageFrame CloneAs() where TPixel2 : struct, IPixel { - scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); + if (typeof(TPixel2) == typeof(TPixel)) + { + return this.Clone() as ImageFrame; + } - ImageFrame target = new ImageFrame(this.Width, this.Height, this.Configuration); + Func scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(); + + var target = new ImageFrame(this.Configuration, this.Width, this.Height); target.CopyProperties(this); using (PixelAccessor pixels = this.Lock()) @@ -99,11 +130,17 @@ public ImageFrame To(Func scaleFunc = null) /// Clones the current instance. /// /// The - internal virtual ImageFrame Clone() + public new ImageFrame Clone() { return new ImageFrame(this); } + /// + protected override ImageBase CloneInternal() + { + return this.Clone(); + } + /// /// Copies the properties from the other . /// diff --git a/src/ImageSharp/Image/ImageProcessingExtensions.cs b/src/ImageSharp/Image/ImageProcessingExtensions.cs deleted file mode 100644 index 8eed103d10..0000000000 --- a/src/ImageSharp/Image/ImageProcessingExtensions.cs +++ /dev/null @@ -1,32 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - - /// - /// Extension methods for the type. - /// - public static partial class ImageExtensions - { - /// - /// Applies the processor to the image. - /// This method does not resize the target image. - /// - /// The pixel format. - /// The image this method extends. - /// The processor to apply to the image. - /// The . - public static Image Apply(this Image source, IImageProcessor processor) - where TPixel : struct, IPixel - { - source.ApplyProcessor(processor, source.Bounds); - return source; - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Image/Image{TPixel}.cs b/src/ImageSharp/Image/Image{TPixel}.cs index 5e8bcab31b..47ddfac210 100644 --- a/src/ImageSharp/Image/Image{TPixel}.cs +++ b/src/ImageSharp/Image/Image{TPixel}.cs @@ -1,29 +1,25 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp { - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.IO; - using System.Numerics; - using System.Text; - using System.Threading.Tasks; - - using Formats; - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - using SixLabors.Primitives; - /// /// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes. /// /// The pixel format. - [DebuggerDisplay("Image: {Width}x{Height}")] - public class Image : ImageBase, IImage + public sealed class Image : ImageBase, IImage where TPixel : struct, IPixel { /// @@ -51,20 +47,36 @@ public Image(int width, int height) { } + /// + /// Initializes a new instance of the class + /// with the height and the width of the image. + /// + /// + /// The configuration providing initialization code which allows extending the library. + /// + /// The width of the image in pixels. + /// The height of the image in pixels. + /// The images metadata. + internal Image(Configuration configuration, int width, int height, ImageMetaData metadata) + : base(configuration, width, height) + { + this.MetaData = metadata ?? new ImageMetaData(); + } + /// /// Initializes a new instance of the class /// by making a copy from another image. /// /// The other image, where the clone should be made from. /// is null. - public Image(Image other) + private Image(Image other) : base(other) { foreach (ImageFrame frame in other.Frames) { if (frame != null) { - this.Frames.Add(new ImageFrame(frame)); + this.Frames.Add(frame.Clone()); } } @@ -77,215 +89,66 @@ public Image(Image other) /// /// The other image, where the clone should be made from. /// is null. - public Image(ImageBase other) + private Image(ImageBase other) : base(other) { } - /// - /// Initializes a new instance of the class - /// with the height and the width of the image. - /// - /// - /// The configuration providing initialization code which allows extending the library. - /// - /// The width of the image in pixels. - /// The height of the image in pixels. - /// The images metadata. - internal Image(Configuration configuration, int width, int height, ImageMetaData metadata) - : base(configuration, width, height) - { - this.MetaData = metadata ?? new ImageMetaData(); - } - /// /// Gets the meta data of the image. /// public ImageMetaData MetaData { get; private set; } = new ImageMetaData(); /// - /// Gets the width of the image in inches. It is calculated as the width of the image - /// in pixels multiplied with the density. When the density is equals or less than zero - /// the default value is used. - /// - /// The width of the image in inches. - public double InchWidth => this.Width / this.MetaData.HorizontalResolution; - - /// - /// Gets the height of the image in inches. It is calculated as the height of the image - /// in pixels multiplied with the density. When the density is equals or less than zero - /// the default value is used. - /// - /// The height of the image in inches. - public double InchHeight => this.Height / this.MetaData.VerticalResolution; - - /// - /// Gets a value indicating whether this image is animated. - /// - /// - /// True if this image is animated; otherwise, false. - /// - public bool IsAnimated => this.Frames.Count > 0; - - /// - /// Gets the other frames for the animation. + /// Gets the other frames associated with this image. /// /// The list of frame images. public IList> Frames { get; } = new List>(); - /// - /// Applies the processor to the image. - /// - /// The processor to apply to the image. - /// The structure that specifies the portion of the image object to draw. - public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) - { - // we want to put this on on here as it gives us a really go place to test/verify processor settings - base.ApplyProcessor(processor, rectangle); - foreach (ImageFrame sourceFrame in this.Frames) - { - sourceFrame.ApplyProcessor(processor, rectangle); - } - } - - /// - /// Saves the image to the given stream using the currently loaded image format. - /// - /// The stream to save the image to. - /// The format to save the image to. - /// Thrown if the stream is null. - /// The - public Image Save(Stream stream, IImageFormat format) - { - Guard.NotNull(format, nameof(format)); - IImageEncoder encoder = this.Configuration.FindEncoder(format); - - if (encoder == null) - { - var stringBuilder = new StringBuilder(); - stringBuilder.AppendLine("Can't find encoder for provided mime type. Available encoded:"); - - foreach (KeyValuePair val in this.Configuration.ImageEncoders) - { - stringBuilder.AppendLine($" - {val.Key.Name} : {val.Value.GetType().Name}"); - } - - throw new NotSupportedException(stringBuilder.ToString()); - } - - return this.Save(stream, encoder); - } - /// /// Saves the image to the given stream using the given image encoder. /// /// The stream to save the image to. /// The encoder to save the image with. /// Thrown if the stream or encoder is null. - /// - /// The . - /// - public Image Save(Stream stream, IImageEncoder encoder) + public void Save(Stream stream, IImageEncoder encoder) { Guard.NotNull(stream, nameof(stream)); Guard.NotNull(encoder, nameof(encoder)); encoder.Encode(this, stream); - - return this; } -#if !NETSTANDARD1_1 /// - /// Saves the image to the given stream using the currently loaded image format. + /// Clones the current image /// - /// The file path to save the image to. - /// Thrown if the stream is null. - /// The - public Image Save(string filePath) + /// Returns a new image with all the same metadata as the original. + public new Image Clone() { - Guard.NotNullOrEmpty(filePath, nameof(filePath)); - - string ext = Path.GetExtension(filePath).Trim('.'); - var format = this.Configuration.FindFormatByFileExtensions(ext); - if (format == null) - { - var stringBuilder = new StringBuilder(); - stringBuilder.AppendLine($"Can't find a format that is associated with the file extention '{ext}'. Registered formats with there extensions include:"); - foreach (IImageFormat fmt in this.Configuration.ImageFormats) - { - stringBuilder.AppendLine($" - {fmt.Name} : {string.Join(", ", fmt.FileExtensions)}"); - } - - throw new NotSupportedException(stringBuilder.ToString()); - } - - IImageEncoder encoder = this.Configuration.FindEncoder(format); - - if (encoder == null) - { - var stringBuilder = new StringBuilder(); - stringBuilder.AppendLine($"Can't find encoder for file extention '{ext}' using image format '{format.Name}'. Registered encoders include:"); - foreach (KeyValuePair enc in this.Configuration.ImageEncoders) - { - stringBuilder.AppendLine($" - {enc.Key} : {enc.Value.GetType().Name}"); - } - - throw new NotSupportedException(stringBuilder.ToString()); - } - - return this.Save(filePath, encoder); + return new Image(this); } - /// - /// Saves the image to the given stream using the currently loaded image format. - /// - /// The file path to save the image to. - /// The encoder to save the image with. - /// Thrown if the encoder is null. - /// The - public Image Save(string filePath, IImageEncoder encoder) - { - Guard.NotNull(encoder, nameof(encoder)); - using (Stream fs = this.Configuration.FileSystem.Create(filePath)) - { - return this.Save(fs, encoder); - } - } -#endif - /// public override string ToString() { return $"Image<{typeof(TPixel).Name}>: {this.Width}x{this.Height}"; } - /// - /// Returns a Base64 encoded string from the given image. - /// - /// - /// The format. - /// The - public string ToBase64String(IImageFormat format) - { - using (var stream = new MemoryStream()) - { - this.Save(stream, format); - stream.Flush(); - return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(stream.ToArray())}"; - } - } - /// /// Returns a copy of the image in the given pixel format. /// - /// A function that allows for the correction of vector scaling between unknown color formats. /// The pixel format. /// The - public Image To(Func scaleFunc = null) + public Image CloneAs() where TPixel2 : struct, IPixel { - scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); + if (typeof(TPixel2) == typeof(TPixel)) + { + // short circuit when same pixel types + return this.Clone() as Image; + } + + Func scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(); var target = new Image(this.Configuration, this.Width, this.Height); target.CopyProperties(this); @@ -310,7 +173,7 @@ public Image To(Func scaleFunc = null) for (int i = 0; i < this.Frames.Count; i++) { - target.Frames.Add(this.Frames[i].To()); + target.Frames.Add(this.Frames[i].CloneAs()); } return target; @@ -320,7 +183,7 @@ public Image To(Func scaleFunc = null) /// Creates a new from this instance /// /// The - internal virtual ImageFrame ToFrame() + internal ImageFrame ToFrame() { return new ImageFrame(this); } @@ -337,6 +200,12 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } + /// + protected override ImageBase CloneInternal() + { + return this.Clone(); + } + /// /// Copies the properties from the other . /// diff --git a/src/ImageSharp/Image/PixelAccessor{TPixel}.cs b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs index 3902ba4255..84d7d04450 100644 --- a/src/ImageSharp/Image/PixelAccessor{TPixel}.cs +++ b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Diagnostics; - using System.Runtime.CompilerServices; - using System.Threading.Tasks; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Provides per-pixel access to generic pixels. /// diff --git a/src/ImageSharp/Image/PixelArea{TPixel}.cs b/src/ImageSharp/Image/PixelArea{TPixel}.cs index 4ddfcadb7b..e9924f8235 100644 --- a/src/ImageSharp/Image/PixelArea{TPixel}.cs +++ b/src/ImageSharp/Image/PixelArea{TPixel}.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Diagnostics; - using System.IO; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Diagnostics; +using System.IO; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Represents an area of generic pixels. /// diff --git a/src/ImageSharp/ImageFormats.cs b/src/ImageSharp/ImageFormats.cs index f79191eae6..d677839688 100644 --- a/src/ImageSharp/ImageFormats.cs +++ b/src/ImageSharp/ImageFormats.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using ImageSharp.Formats; +using SixLabors.ImageSharp.Formats; +namespace SixLabors.ImageSharp +{ /// /// The static collection of all the default image formats /// diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 8733131a74..4c103e59df 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -3,18 +3,18 @@ A cross-platform library for the processing of image files; written in C# ImageSharp 1.0.0-alpha9 - James Jackson-South and contributors + Six Labors and contributors netstandard1.3;netstandard1.1 true true - ImageSharp - ImageSharp + SixLabors.ImageSharp + SixLabors.ImageSharp Image Resize Crop Gif Jpg Jpeg Bitmap Png Core - https://raw.githubusercontent.com/JimBobSquarePants/ImageSharp/master/build/icons/imagesharp-logo-128.png - https://github.com/JimBobSquarePants/ImageSharp + https://raw.githubusercontent.com/SixLabor/ImageSharp/master/build/icons/imagesharp-logo-128.png + https://github.com/SixLabor/ImageSharp http://www.apache.org/licenses/LICENSE-2.0 git - https://github.com/JimBobSquarePants/ImageSharp + https://github.com/SixLabor/ImageSharp false false false @@ -31,28 +31,33 @@ - - + + All - - + + - - + + - + ..\..\ImageSharp.ruleset + SixLabors.ImageSharp true + + TextTemplatingFileGenerator + Block8x8F.Generated.cs + TextTemplatingFileGenerator Block8x8F.Generated.cs @@ -78,6 +83,11 @@ + + True + True + Block8x8F.Generated.tt + True True diff --git a/src/ImageSharp/Memory/Buffer.cs b/src/ImageSharp/Memory/Buffer.cs index 4b3681c744..bbe37b8594 100644 --- a/src/ImageSharp/Memory/Buffer.cs +++ b/src/ImageSharp/Memory/Buffer.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Memory -{ - using System; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +namespace SixLabors.ImageSharp.Memory +{ /// /// Manages a buffer of value type objects as a Disposable resource. /// The backing array is either pooled or comes from the outside. diff --git a/src/ImageSharp/Memory/Buffer2D.cs b/src/ImageSharp/Memory/Buffer2D.cs index 59cabb1bd4..d86eb5b267 100644 --- a/src/ImageSharp/Memory/Buffer2D.cs +++ b/src/ImageSharp/Memory/Buffer2D.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Memory -{ - using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Memory +{ /// /// Represents a buffer of value type objects /// interpreted as a 2D region of x elements. diff --git a/src/ImageSharp/Memory/Buffer2DExtensions.cs b/src/ImageSharp/Memory/Buffer2DExtensions.cs index 046bfd81fc..d9c6801a1d 100644 --- a/src/ImageSharp/Memory/Buffer2DExtensions.cs +++ b/src/ImageSharp/Memory/Buffer2DExtensions.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Memory -{ - using System; - using System.Runtime.CompilerServices; +using System; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Memory +{ /// /// Defines extension methods for . /// diff --git a/src/ImageSharp/Memory/Fast2DArray{T}.cs b/src/ImageSharp/Memory/Fast2DArray{T}.cs index 260c829e21..14ac58baf2 100644 --- a/src/ImageSharp/Memory/Fast2DArray{T}.cs +++ b/src/ImageSharp/Memory/Fast2DArray{T}.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Memory -{ - using System; - using System.Diagnostics; - using System.Runtime.CompilerServices; +using System; +using System.Diagnostics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Memory +{ /// /// Provides fast access to 2D arrays. /// @@ -106,11 +104,23 @@ public static implicit operator Fast2DArray(T[,] data) return new Fast2DArray(data); } + /// + /// Gets a representing the row beginning from the the first item on that row. + /// + /// The y-coordinate of the row. Must be greater than or equal to zero and less than the height of the 2D array. + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Span GetRowSpan(int row) + { + this.CheckCoordinates(row); + return new Span(this.Data, row * this.Width, this.Width); + } + /// /// Checks the coordinates to ensure they are within bounds. /// - /// The row-coordinate of the item. Must be greater than zero and smaller than the height of the array. - /// The column-coordinate of the item. Must be greater than zero and smaller than the width of the array. + /// The y-coordinate of the item. Must be greater than zero and smaller than the height of the array. + /// The x-coordinate of the item. Must be greater than zero and smaller than the width of the array. /// /// Thrown if the coordinates are not within the bounds of the array. /// @@ -127,5 +137,21 @@ private void CheckCoordinates(int row, int column) throw new ArgumentOutOfRangeException(nameof(column), column, $"{column} is outwith the array bounds."); } } + + /// + /// Checks the coordinates to ensure they are within bounds. + /// + /// The y-coordinate of the item. Must be greater than zero and smaller than the height of the array. + /// + /// Thrown if the coordinates are not within the bounds of the image. + /// + [Conditional("DEBUG")] + private void CheckCoordinates(int row) + { + if (row < 0 || row >= this.Height) + { + throw new ArgumentOutOfRangeException(nameof(row), row, $"{row} is outwith the array bounds."); + } + } } } \ No newline at end of file diff --git a/src/ImageSharp/Memory/IBuffer2D.cs b/src/ImageSharp/Memory/IBuffer2D.cs index 300c29a1ba..2f60fd02a0 100644 --- a/src/ImageSharp/Memory/IBuffer2D.cs +++ b/src/ImageSharp/Memory/IBuffer2D.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Memory -{ - using System; +using System; +namespace SixLabors.ImageSharp.Memory +{ /// /// An interface that represents a pinned buffer of value type objects /// interpreted as a 2D region of x elements. diff --git a/src/ImageSharp/Memory/PixelDataPool{T}.cs b/src/ImageSharp/Memory/PixelDataPool{T}.cs index 643f1c6ca3..6f4cef707a 100644 --- a/src/ImageSharp/Memory/PixelDataPool{T}.cs +++ b/src/ImageSharp/Memory/PixelDataPool{T}.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Memory -{ - using System.Buffers; - - using ImageSharp.PixelFormats; +using System.Buffers; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Memory +{ /// /// Provides a resource pool that enables reusing instances of value type arrays for image data . /// diff --git a/src/ImageSharp/Memory/SpanHelper.cs b/src/ImageSharp/Memory/SpanHelper.cs index 0e794e1b57..73bc5f55d8 100644 --- a/src/ImageSharp/Memory/SpanHelper.cs +++ b/src/ImageSharp/Memory/SpanHelper.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Memory -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.Memory +{ /// /// Utility methods for /// diff --git a/src/ImageSharp/MetaData/IMetaData.cs b/src/ImageSharp/MetaData/IMetaData.cs index 6daa04dd63..61a906c03d 100644 --- a/src/ImageSharp/MetaData/IMetaData.cs +++ b/src/ImageSharp/MetaData/IMetaData.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using ImageSharp.Formats; +using SixLabors.ImageSharp.Formats; +namespace SixLabors.ImageSharp +{ /// /// Encapsulates the metadata of an image frame. /// diff --git a/src/ImageSharp/MetaData/ImageFrameMetaData.cs b/src/ImageSharp/MetaData/ImageFrameMetaData.cs index b55bfd1ad1..71051d11af 100644 --- a/src/ImageSharp/MetaData/ImageFrameMetaData.cs +++ b/src/ImageSharp/MetaData/ImageFrameMetaData.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using ImageSharp.Formats; +using SixLabors.ImageSharp.Formats; +namespace SixLabors.ImageSharp +{ /// /// Encapsulates the metadata of an image frame. /// @@ -39,5 +37,14 @@ internal ImageFrameMetaData(ImageFrameMetaData other) /// public DisposalMethod DisposalMethod { get; set; } + + /// + /// Clones this ImageFrameMetaData. + /// + /// The cloned instance. + public ImageFrameMetaData Clone() + { + return new ImageFrameMetaData(this); + } } } diff --git a/src/ImageSharp/MetaData/ImageMetaData.cs b/src/ImageSharp/MetaData/ImageMetaData.cs index 5361b486d4..5e99f30239 100644 --- a/src/ImageSharp/MetaData/ImageMetaData.cs +++ b/src/ImageSharp/MetaData/ImageMetaData.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Collections.Generic; - using ImageSharp.Formats; +using System.Collections.Generic; +using SixLabors.ImageSharp.Formats; +namespace SixLabors.ImageSharp +{ /// /// Encapsulates the metadata of an image. /// @@ -132,6 +130,15 @@ public double VerticalResolution /// public ushort RepeatCount { get; set; } + /// + /// Clones this into a new instance + /// + /// The cloned metadata instance + public ImageMetaData Clone() + { + return new ImageMetaData(this); + } + /// /// Synchronizes the profiles with the current meta data. /// diff --git a/src/ImageSharp/MetaData/ImageProperty.cs b/src/ImageSharp/MetaData/ImageProperty.cs index 178794283c..0c575cf260 100644 --- a/src/ImageSharp/MetaData/ImageProperty.cs +++ b/src/ImageSharp/MetaData/ImageProperty.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// Stores meta information about a image, like the name of the author, /// the copyright information, the date, where the image was created diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifDataType.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifDataType.cs index f2d012c6c8..aa874df79a 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifDataType.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifDataType.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Specifies exif data types. diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifParts.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifParts.cs index 880a434534..3bfa3281a3 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifParts.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifParts.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// Specifies which parts will be written when the profile is added to an image. /// diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs index a7fd8fd6a8..fa18e96a23 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.IO; - - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Represents an EXIF profile providing access to the collection of values. /// @@ -82,9 +80,11 @@ public ExifProfile(ExifProfile other) this.values.Add(new ExifValue(value)); } } - else + + if (other.data != null) { - this.data = other.data; + this.data = new byte[other.data.Length]; + Buffer.BlockCopy(other.data, 0, this.data, 0, other.data.Length); } } @@ -131,7 +131,7 @@ public Image CreateThumbnail() return null; } - if (this.data.Length < (this.thumbnailOffset + this.thumbnailLength)) + if (this.data == null || this.data.Length < (this.thumbnailOffset + this.thumbnailLength)) { return null; } diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs index 53123bfc29..d7d4c8b114 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Linq; - using System.Text; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +namespace SixLabors.ImageSharp +{ /// /// Reads and parses EXIF data from a byte array /// diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifTag.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifTag.cs index 6f4b494857..c6a9740568 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifTag.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifTag.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// All exif tags from the Exif standard 2.2 diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifTagDescriptionAttribute.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifTagDescriptionAttribute.cs index e08bddd3ff..6135033254 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifTagDescriptionAttribute.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifTagDescriptionAttribute.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Reflection; +using System; +using System.Reflection; +namespace SixLabors.ImageSharp +{ /// /// Class that provides a description for an ExifTag value. /// diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs index a2965917b1..c20aa2cbc7 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Globalization; - using System.Text; +using System; +using System.Globalization; +using System.Text; +namespace SixLabors.ImageSharp +{ /// /// Represent the value of the EXIF profile. /// diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs index bf8f4caa26..2156240224 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Text; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; +namespace SixLabors.ImageSharp +{ /// /// Contains methods for writing EXIF metadata. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccCurveSegment.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccCurveSegment.cs index f34f006e7c..c1b30bc816 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccCurveSegment.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccCurveSegment.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// A segment of a curve /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccFormulaCurveElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccFormulaCurveElement.cs index ad03c8ff8a..44ec136d81 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccFormulaCurveElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccFormulaCurveElement.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// A formula based curve segment /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs index 3f6497cccf..377d5d0808 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// A one dimensional curve /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs index 14aaf153ef..870c994a8d 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// A parametric curve /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs index a5816e212e..435d014926 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; - using System.Numerics; +using System; +using System.Linq; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// A response curve /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccSampledCurveElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccSampledCurveElement.cs index 859d43338e..de3f348c75 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccSampledCurveElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccSampledCurveElement.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// A sampled curve segment /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs index ba32586fea..6ea81f9cc6 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Numerics; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to read ICC data types /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Lut.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Lut.cs index a34ee42fce..0c39cc7bfc 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Lut.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Lut.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to read ICC data types /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Matrix.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Matrix.cs index 23ad9feb22..c209741875 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Matrix.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Matrix.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Provides methods to read ICC data types diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.MultiProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.MultiProcessElement.cs index 371c5c42a6..fd41ec5b67 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.MultiProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.MultiProcessElement.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Provides methods to read ICC data types diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs index 44a892084c..c4642ed25e 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Numerics; +using System; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to read ICC data types /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs index 85d80c7a84..544a57c7ab 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Text; +using System; +using System.Text; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to read ICC data types /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs index 711de818b3..c988c9198d 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Globalization; - using System.Numerics; +using System; +using System.Globalization; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to read ICC data types /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs index cb1fe5b55e..8e269a474a 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Text; - using ImageSharp.IO; +using System; +using System.Text; +using SixLabors.ImageSharp.IO; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to read ICC data types /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs index 4b6e454a1d..6cbb7148af 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Numerics; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to write ICC data types /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs index f85d59714f..0cfae36fc2 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Provides methods to write ICC data types diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs index 13a15b4836..3f873d3b0f 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Numerics; - - using ImageSharp.Memory; +using System.Numerics; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to write ICC data types /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElement.cs index b3ddb538cd..2522aee805 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElement.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Provides methods to write ICC data types diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs index d90c1ff549..9f8d8d0579 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Numerics; +using System; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to write ICC data types /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs index fbb7065e6b..eb5f7eddb3 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Text; +using System; +using System.Text; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to write ICC data types /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs index b74f22054e..8c0640cbdd 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Linq; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to write ICC data types /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs index a9a65b80be..6a0ddf6399 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.IO; - using System.Text; +using System; +using System.IO; +using System.Text; +namespace SixLabors.ImageSharp +{ /// /// Provides methods to write ICC data types /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccClutDataType.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccClutDataType.cs index 066cbe8489..021051b256 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccClutDataType.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccClutDataType.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Color lookup table data type diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccColorSpaceType.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccColorSpaceType.cs index 3f57ded742..77967ad663 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccColorSpaceType.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccColorSpaceType.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Color Space Type diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccColorantEncoding.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccColorantEncoding.cs index 251a848b7b..22c29d31d1 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccColorantEncoding.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccColorantEncoding.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Colorant Encoding diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccCurveMeasurementEncodings.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccCurveMeasurementEncodings.cs index 14515c113a..6d5e1b6f74 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccCurveMeasurementEncodings.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccCurveMeasurementEncodings.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Curve Measurement Encodings diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccCurveSegmentSignature.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccCurveSegmentSignature.cs index 77ded0d1b5..d1c0f28434 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccCurveSegmentSignature.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccCurveSegmentSignature.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Curve Segment Signature diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccDataType.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccDataType.cs index a4ca4befab..4fcca3f249 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccDataType.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccDataType.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Enumerates the basic data types as defined in ICC.1:2010 version 4.3.0.0 diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccDeviceAttribute.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccDeviceAttribute.cs index c57cf4f977..131434cfdc 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccDeviceAttribute.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccDeviceAttribute.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// Device attributes. Can be combined with a logical OR /// The least-significant 32 bits are defined by the ICC, diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccFormulaCurveType.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccFormulaCurveType.cs index eacc1eb281..8810bbbb04 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccFormulaCurveType.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccFormulaCurveType.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Formula curve segment type diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccMeasurementGeometry.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccMeasurementGeometry.cs index fdfb78049d..dc8db74629 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccMeasurementGeometry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccMeasurementGeometry.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Measurement Geometry diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccMultiProcessElementSignature.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccMultiProcessElementSignature.cs index 8ab690b64f..80c74952ab 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccMultiProcessElementSignature.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccMultiProcessElementSignature.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Multi process element signature diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccParametricCurveType.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccParametricCurveType.cs index 823b413402..563a40c901 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccParametricCurveType.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccParametricCurveType.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Formula curve segment type diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccPrimaryPlatformType.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccPrimaryPlatformType.cs index 8fdeb3f418..ee6f719109 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccPrimaryPlatformType.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccPrimaryPlatformType.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Enumerates the primary platform/operating system framework for which the profile was created diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileClass.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileClass.cs index 9fb0b51f32..dbb6d61ed6 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileClass.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileClass.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Profile Class Name diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileFlag.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileFlag.cs index aa8df88bd8..f149415d81 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileFlag.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileFlag.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// Profile flags. Can be combined with a logical OR. /// The least-significant 16 bits are reserved for the ICC, diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileTag.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileTag.cs index 6eab5b3fe8..7c71fe9a54 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileTag.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileTag.cs @@ -1,10 +1,8 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// // ReSharper disable InconsistentNaming -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Enumerates the ICC Profile Tags as defined in ICC.1:2010 version 4.3.0.0 diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccRenderingIntent.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccRenderingIntent.cs index 10e0fbac99..cfcb8312eb 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccRenderingIntent.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccRenderingIntent.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Rendering intent diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccScreeningFlag.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccScreeningFlag.cs index 2938d44698..422b752023 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccScreeningFlag.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccScreeningFlag.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// Screening flags. Can be combined with a logical OR. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccScreeningSpotType.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccScreeningSpotType.cs index 0d24c3ae5b..02138be3b3 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccScreeningSpotType.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccScreeningSpotType.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Enumerates the screening spot types diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccSignatureName.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccSignatureName.cs index 5fc2fa228c..b929afd9a9 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccSignatureName.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccSignatureName.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Signature Name diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccStandardIlluminant.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccStandardIlluminant.cs index 3526887edc..c4482de1f1 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccStandardIlluminant.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccStandardIlluminant.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Standard Illuminant diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccStandardObserver.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccStandardObserver.cs index 0efc5fd406..cfbec77689 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccStandardObserver.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccStandardObserver.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Standard Observer diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccTypeSignature.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccTypeSignature.cs index a42cc8cd11..2249341af2 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccTypeSignature.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccTypeSignature.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Type Signature diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Exceptions/InvalidIccProfileException.cs b/src/ImageSharp/MetaData/Profiles/ICC/Exceptions/InvalidIccProfileException.cs index 54fe7c7641..13e20fd9d5 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Exceptions/InvalidIccProfileException.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Exceptions/InvalidIccProfileException.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// Represents an error that happened while reading or writing a corrupt/invalid ICC profile /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs index 978d5bc24f..7f8ba391d8 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs @@ -1,16 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Collections.Generic; +using System; +using System.Collections.Generic; + #if !NETSTANDARD1_1 - using System.Security.Cryptography; +using System.Security.Cryptography; #endif +namespace SixLabors.ImageSharp +{ /// /// Represents an ICC profile /// @@ -59,7 +58,11 @@ public IccProfile(IccProfile other) Guard.NotNull(other, nameof(other)); // TODO: Do we need to copy anything else? - this.data = other.data; + if (other.data != null) + { + this.data = new byte[other.data.Length]; + Buffer.BlockCopy(other.data, 0, this.data, 0, other.data.Length); + } } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccProfileHeader.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccProfileHeader.cs index 8237dc7a82..e08914a973 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccProfileHeader.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccProfileHeader.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Numerics; +using System; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// Contains all values of an ICC profile header /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs index b24c96f023..a01a0beac3 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System.Collections.Generic; +using System.Collections.Generic; +namespace SixLabors.ImageSharp +{ /// /// Reads and parses ICC data from a byte array /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs index 5db3d96eac..5bada6e772 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// The data of an ICC tag entry /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs index 19c00e8f55..c7f39aff4d 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Collections.Generic; - using System.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// Contains methods for writing ICC profiles. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccBAcsProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccBAcsProcessElement.cs index a20a52d8e6..566a9cff4e 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccBAcsProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccBAcsProcessElement.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// A placeholder (might be used for future ICC versions) /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccClutProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccClutProcessElement.cs index 7d5855168e..2c93796630 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccClutProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccClutProcessElement.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// A CLUT (color lookup table) element to process data /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccCurveSetProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccCurveSetProcessElement.cs index c16ca93d24..e081c084e8 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccCurveSetProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccCurveSetProcessElement.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// A set of curves to process data /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccEAcsProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccEAcsProcessElement.cs index 9219f52002..c4a49eeb3f 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccEAcsProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccEAcsProcessElement.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// A placeholder (might be used for future ICC versions) /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs index 259f714896..afe41c624c 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; - - using ImageSharp.Memory; +using System; +using System.Linq; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp +{ /// /// A matrix element to process data /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs index 205e61f011..ebac2912b4 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// An element to process data /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs index 85f40f5e41..a7a70c11bd 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// The chromaticity tag type provides basic chromaticity data /// and type of phosphors or colorants of a monitor to applications and utilities. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs index 9be5541a28..654af027eb 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This tag specifies the laydown order in which colorants /// will be printed on an n-colorant device. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs index 041f74f391..5adc7ca283 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// The purpose of this tag is to identify the colorants used in /// the profile by a unique name and set of PCSXYZ or PCSLAB values diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs index 73588bbf05..431ffa887c 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// This type contains the PostScript product name to which this profile /// corresponds and the names of the companion CRDs diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs index c14995748b..0ab80e5065 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// The type contains a one-dimensional table of double values. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs index 57f04b11ae..f39330d6cd 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; - using System.Text; +using System; +using System.Linq; +using System.Text; +namespace SixLabors.ImageSharp +{ /// /// The dataType is a simple data structure that contains /// either 7-bit ASCII or binary data, i.e. textType data or transparent bytes. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs index 7111913cbf..4dc935b9b5 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// This type is a representation of the time and date. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs index c91347d23f..d8d67465bb 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This type represents an array of doubles (from 32bit fixed point values). /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs index 45d7b3c50c..fec50e3e3a 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; - using System.Numerics; +using System; +using System.Linq; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// This structure represents a color transform using tables /// with 16-bit precision. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs index 538cf0505b..89e5e38949 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; - using System.Numerics; +using System; +using System.Linq; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// This structure represents a color transform using tables /// with 8-bit precision. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs index d440447cca..17720dd5dd 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; - using System.Numerics; +using System; +using System.Linq; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// This structure represents a color transform. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs index 9d63dd171f..51566c4b0f 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; - using System.Numerics; +using System; +using System.Linq; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// This structure represents a color transform. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs index 390a5ba54d..31278da621 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Numerics; +using System; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// The measurementType information refers only to the internal /// profile data and is meant to provide profile makers an alternative diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs index 573e77ed47..bdf9162018 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This tag structure contains a set of records each referencing /// a multilingual string associated with a profile. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs index e3e6ef1437..954096f44f 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This structure represents a color transform, containing /// a sequence of processing elements. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs index 17b7213b24..e7a13c28a8 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// The namedColor2Type is a count value and array of structures /// that provide color coordinates for color names. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs index 4264c0b24d..3791083710 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// The parametricCurveType describes a one-dimensional curve by /// specifying one of a predefined set of functions using the parameters. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs index 547483e233..e4f6b2e28e 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This type is an array of structures, each of which contains information /// from the header fields and tags from the original profiles which were diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs index 1a1b02c0bc..e980a9715c 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This type is an array of structures, each of which contains information /// for identification of a profile used in a sequence. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs index f4fc7fbd21..dd3f782957 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// The purpose of this tag type is to provide a mechanism to relate physical /// colorant amounts with the normalized device codes produced by lut8Type, lut16Type, diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs index 8c3a2d83b1..dad5d86587 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This type describes various screening parameters including /// screen frequency, screening angle, and spot shape. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs index 9ce2c1b9ae..a6367f55b8 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// Typically this type is used for registered tags that can /// be displayed on many development systems as a sequence of four characters. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs index 202220f93f..306ad2689f 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Globalization; +using System; +using System.Globalization; +namespace SixLabors.ImageSharp +{ /// /// The TextDescriptionType contains three types of text description. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs index 9e56a1cf8a..772782619b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// This is a simple text structure that contains a text string. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs index 2b7b4044d8..77f8e1c87e 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This type represents an array of doubles (from 32bit values). /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs index da77253102..c42d5338ce 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This type represents an array of unsigned shorts. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs index 0dabdecc12..d322d48a73 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This type represents an array of unsigned 32bit integers. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs index d62a4a8a79..5ff2b37b75 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This type represents an array of unsigned 64bit integers. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs index 30363df9dd..72f6dcc573 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This type represents an array of bytes. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs index e668e5cfdd..e189e9ae70 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This type contains curves representing the under color removal and black generation /// and a text string which is a general description of the method used for the UCR and BG. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs index 79549b7c81..7628a2e14d 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// This tag stores data of an unknown tag data entry /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs index 5f7406ef11..980f5b53bd 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Numerics; +using System; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// This type represents a set of viewing condition parameters. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs index 77f9ff7069..8b41cb5fba 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; - using System.Numerics; +using System; +using System.Linq; +using System.Numerics; +namespace SixLabors.ImageSharp +{ /// /// The XYZType contains an array of XYZ values. /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs index d527d4052e..d9d8dc9ee7 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// Color Lookup Table /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs index bd89550750..b9b43e9b2a 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// Entry of ICC colorant table /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLocalizedString.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLocalizedString.cs index 0e27729638..6ffc51dbbd 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLocalizedString.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLocalizedString.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Globalization; +using System; +using System.Globalization; +namespace SixLabors.ImageSharp +{ /// /// A string with a specific locale /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs index 9b86e11139..3777a96eb3 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// Lookup Table /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs index 5d51615684..b59778caf4 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// A specific color with a name /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs index 768aead0ef..9e58fd0281 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// Position of an object within an ICC profile /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs index 4f744631d8..2bb894d338 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// ICC Profile description /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs index fc4760d3f1..955fd89eb0 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// ICC Profile ID /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileSequenceIdentifier.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileSequenceIdentifier.cs index 65507bf6bf..7f5ab7d7fb 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileSequenceIdentifier.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileSequenceIdentifier.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Linq; +using System; +using System.Linq; +namespace SixLabors.ImageSharp +{ /// /// Description of a profile within a sequence /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs index 5c58aa1b16..4607857c68 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// Associates a normalized device code with a measurement value /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs index ac0e89bb05..dae6abb4da 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// A single channel of a /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs index 7937569991..4d900444fa 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; +using System; +namespace SixLabors.ImageSharp +{ /// /// Entry of ICC tag table /// diff --git a/src/ImageSharp/Numerics/LongRational.cs b/src/ImageSharp/Numerics/LongRational.cs index f56abc2899..48494d6466 100644 --- a/src/ImageSharp/Numerics/LongRational.cs +++ b/src/ImageSharp/Numerics/LongRational.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Globalization; - using System.Text; +using System; +using System.Globalization; +using System.Text; +namespace SixLabors.ImageSharp +{ /// /// Represents a number that can be expressed as a fraction /// diff --git a/src/ImageSharp/Numerics/Rational.cs b/src/ImageSharp/Numerics/Rational.cs index d219a54696..03941b90d8 100644 --- a/src/ImageSharp/Numerics/Rational.cs +++ b/src/ImageSharp/Numerics/Rational.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Globalization; +using System; +using System.Globalization; +namespace SixLabors.ImageSharp +{ /// /// Represents a number that can be expressed as a fraction. /// diff --git a/src/ImageSharp/Numerics/SignedRational.cs b/src/ImageSharp/Numerics/SignedRational.cs index bd2213dce0..8821bd28c6 100644 --- a/src/ImageSharp/Numerics/SignedRational.cs +++ b/src/ImageSharp/Numerics/SignedRational.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Globalization; +using System; +using System.Globalization; +namespace SixLabors.ImageSharp +{ /// /// Represents a number that can be expressed as a fraction. /// diff --git a/src/ImageSharp/Numerics/ValueSize.cs b/src/ImageSharp/Numerics/ValueSize.cs new file mode 100644 index 0000000000..659e0ebfe1 --- /dev/null +++ b/src/ImageSharp/Numerics/ValueSize.cs @@ -0,0 +1,129 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp +{ + /// + /// Represents a value in relation to a value on the image + /// + internal struct ValueSize : IEquatable + { + /// + /// Initializes a new instance of the struct. + /// + /// The value. + /// The type. + public ValueSize(float value, ValueSizeType type) + { + if (type != ValueSizeType.Absolute) + { + Guard.MustBeBetweenOrEqualTo(value, 0, 1, nameof(value)); + } + + this.Value = value; + this.Type = type; + } + + /// + /// The different vlaue types + /// + public enum ValueSizeType + { + /// + /// The value is the final return value + /// + Absolute, + + /// + /// The value is a percentage of the Images Width + /// + PercentageOfWidth, + + /// + /// The value is a percentage of the Images height + /// + PercentageOfHeight + } + + /// + /// Gets the value. + /// + public float Value { get; } + + /// + /// Gets the type. + /// + public ValueSizeType Type { get; } + + /// + /// Implicitly converts a float into an absolute value + /// + /// the vlaue to use as the absolute figure. + public static implicit operator ValueSize(float d) + => Absolute(d); + + /// + /// Create a new ValueSize with as a PercentageOfWidth type with value set to percentage. + /// + /// The percentage. + /// a Values size with type PercentageOfWidth + public static ValueSize PercentageOfWidth(float percentage) + { + return new ValueSize(percentage, ValueSizeType.PercentageOfWidth); + } + + /// + /// Create a new ValueSize with as a PercentageOfHeight type with value set to percentage. + /// + /// The percentage. + /// a Values size with type PercentageOfHeight + public static ValueSize PercentageOfHeight(float percentage) + { + return new ValueSize(percentage, ValueSizeType.PercentageOfHeight); + } + + /// + /// Create a new ValueSize with as a Absolute type with value set to value. + /// + /// The value. + /// a Values size with type Absolute( + public static ValueSize Absolute(float value) + { + return new ValueSize(value, ValueSizeType.Absolute); + } + + /// + /// Calculates the specified size. + /// + /// The size. + /// The calucalted value + public float Calculate(Size size) + { + switch (this.Type) + { + case ValueSizeType.PercentageOfWidth: + return this.Value * size.Width; + case ValueSizeType.PercentageOfHeight: + return this.Value * size.Height; + case ValueSizeType.Absolute: + default: + return this.Value; + } + } + + /// + public override string ToString() + { + return $"{this.Value} - {this.Type}"; + } + + /// + public bool Equals(ValueSize other) + { + return this.Type == other.Type && this.Value == other.Value; + } + } +} diff --git a/src/ImageSharp/PixelFormats/Alpha8.cs b/src/ImageSharp/PixelFormats/Alpha8.cs index 59934fdc64..c266035a6b 100644 --- a/src/ImageSharp/PixelFormats/Alpha8.cs +++ b/src/ImageSharp/PixelFormats/Alpha8.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing a single 8 bit normalized W values. /// diff --git a/src/ImageSharp/PixelFormats/Argb32.cs b/src/ImageSharp/PixelFormats/Argb32.cs index f389723dc3..33294838e6 100644 --- a/src/ImageSharp/PixelFormats/Argb32.cs +++ b/src/ImageSharp/PixelFormats/Argb32.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. /// The color components are stored in alpha, red, green, and blue order. diff --git a/src/ImageSharp/PixelFormats/Bgr24.cs b/src/ImageSharp/PixelFormats/Bgr24.cs index aaed5c3852..e210856b36 100644 --- a/src/ImageSharp/PixelFormats/Bgr24.cs +++ b/src/ImageSharp/PixelFormats/Bgr24.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Pixel type containing three 8-bit unsigned normalized values ranging from 0 to 255. /// The color components are stored in blue, green, red order. diff --git a/src/ImageSharp/PixelFormats/Bgr565.cs b/src/ImageSharp/PixelFormats/Bgr565.cs index af22b14a09..b4e7aad583 100644 --- a/src/ImageSharp/PixelFormats/Bgr565.cs +++ b/src/ImageSharp/PixelFormats/Bgr565.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing unsigned normalized values ranging from 0 to 1. The x and z components use 5 bits, and the y component uses 6 bits. /// diff --git a/src/ImageSharp/PixelFormats/Bgra32.cs b/src/ImageSharp/PixelFormats/Bgra32.cs index f1ac20b567..e8469414d3 100644 --- a/src/ImageSharp/PixelFormats/Bgra32.cs +++ b/src/ImageSharp/PixelFormats/Bgra32.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. /// The color components are stored in blue, green, red, and alpha order. diff --git a/src/ImageSharp/PixelFormats/Bgra4444.cs b/src/ImageSharp/PixelFormats/Bgra4444.cs index 746e1062ba..c51a872d1a 100644 --- a/src/ImageSharp/PixelFormats/Bgra4444.cs +++ b/src/ImageSharp/PixelFormats/Bgra4444.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing unsigned normalized values, ranging from 0 to 1, using 4 bits each for x, y, z, and w. /// diff --git a/src/ImageSharp/PixelFormats/Bgra5551.cs b/src/ImageSharp/PixelFormats/Bgra5551.cs index 198f911088..8be4ce82c9 100644 --- a/src/ImageSharp/PixelFormats/Bgra5551.cs +++ b/src/ImageSharp/PixelFormats/Bgra5551.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing unsigned normalized values ranging from 0 to 1. The x , y and z components use 5 bits, and the w component uses 1 bit. /// diff --git a/src/ImageSharp/PixelFormats/Byte4.cs b/src/ImageSharp/PixelFormats/Byte4.cs index 14053ba122..829937c8ad 100644 --- a/src/ImageSharp/PixelFormats/Byte4.cs +++ b/src/ImageSharp/PixelFormats/Byte4.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing four 8-bit unsigned integer values, ranging from 0 to 255. /// diff --git a/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs b/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs index 92fb006abf..c646d804ac 100644 --- a/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Globalization; +using System; +using System.Globalization; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// A set of named colors mapped to the provided Color space. /// diff --git a/src/ImageSharp/PixelFormats/ColorConstants.cs b/src/ImageSharp/PixelFormats/ColorConstants.cs index 236d3a889e..f97d3b190e 100644 --- a/src/ImageSharp/PixelFormats/ColorConstants.cs +++ b/src/ImageSharp/PixelFormats/ColorConstants.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Collections.Generic; +using System; +using System.Collections.Generic; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Provides useful color definitions. /// diff --git a/src/ImageSharp/PixelFormats/ComponentOrder.cs b/src/ImageSharp/PixelFormats/ComponentOrder.cs index 8f151b41d6..d7d35726c8 100644 --- a/src/ImageSharp/PixelFormats/ComponentOrder.cs +++ b/src/ImageSharp/PixelFormats/ComponentOrder.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats +namespace SixLabors.ImageSharp.PixelFormats { /// /// Enumerates the various component orders. diff --git a/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs b/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs index c042d76786..bbb6ff4d01 100644 --- a/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs +++ b/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs @@ -1,20 +1,16 @@ // -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats +namespace SixLabors.ImageSharp.PixelFormats { using System; - using System.Numerics; using System.Runtime.CompilerServices; - + public partial class PixelOperations { - - /// + /// /// Converts 'count' elements in 'source` span of data to a span of -s. /// /// The source of data. @@ -22,8 +18,8 @@ public partial class PixelOperations /// The number of pixels to convert. internal virtual void PackFromRgba32(Span source, Span destPixels, int count) { - GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); - + GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); + ref Rgba32 sourceRef = ref source.DangerousGetPinnableReference(); ref TPixel destRef = ref destPixels.DangerousGetPinnableReference(); @@ -33,11 +29,11 @@ internal virtual void PackFromRgba32(Span source, Span destPixel { ref TPixel dp = ref Unsafe.Add(ref destRef, i); rgba = Unsafe.Add(ref sourceRef, i); - dp.PackFromRgba32(rgba); + dp.PackFromRgba32(rgba); } } - - /// + + /// /// A helper for that expects a byte span. /// The layout of the data in 'sourceBytes' must be compatible with layout. /// @@ -49,8 +45,8 @@ internal void PackFromRgba32Bytes(Span sourceBytes, Span destPixel { this.PackFromRgba32(sourceBytes.NonPortableCast(), destPixels, count); } - - /// + + /// /// Converts 'count' pixels in 'sourcePixels` span to a span of -s. /// Bulk version of . /// @@ -72,20 +68,20 @@ internal virtual void ToRgba32(Span sourcePixels, Span dest, int } } - /// + /// /// A helper for that expects a byte span as destination. /// The layout of the data in 'destBytes' must be compatible with layout. /// /// The to the source colors. /// The to the destination bytes. /// The number of pixels to convert. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void ToRgba32Bytes(Span sourceColors, Span destBytes, int count) { this.ToRgba32(sourceColors, destBytes.NonPortableCast(), count); } - - /// + + /// /// Converts 'count' elements in 'source` span of data to a span of -s. /// /// The source of data. @@ -93,8 +89,8 @@ internal void ToRgba32Bytes(Span sourceColors, Span destBytes, int /// The number of pixels to convert. internal virtual void PackFromBgra32(Span source, Span destPixels, int count) { - GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); - + GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); + ref Bgra32 sourceRef = ref source.DangerousGetPinnableReference(); ref TPixel destRef = ref destPixels.DangerousGetPinnableReference(); @@ -104,11 +100,11 @@ internal virtual void PackFromBgra32(Span source, Span destPixel { ref TPixel dp = ref Unsafe.Add(ref destRef, i); rgba = Unsafe.Add(ref sourceRef, i).ToRgba32(); - dp.PackFromRgba32(rgba); + dp.PackFromRgba32(rgba); } } - - /// + + /// /// A helper for that expects a byte span. /// The layout of the data in 'sourceBytes' must be compatible with layout. /// @@ -120,8 +116,8 @@ internal void PackFromBgra32Bytes(Span sourceBytes, Span destPixel { this.PackFromBgra32(sourceBytes.NonPortableCast(), destPixels, count); } - - /// + + /// /// Converts 'count' pixels in 'sourcePixels` span to a span of -s. /// Bulk version of . /// @@ -143,20 +139,20 @@ internal virtual void ToBgra32(Span sourcePixels, Span dest, int } } - /// + /// /// A helper for that expects a byte span as destination. /// The layout of the data in 'destBytes' must be compatible with layout. /// /// The to the source colors. /// The to the destination bytes. /// The number of pixels to convert. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void ToBgra32Bytes(Span sourceColors, Span destBytes, int count) { this.ToBgra32(sourceColors, destBytes.NonPortableCast(), count); } - - /// + + /// /// Converts 'count' elements in 'source` span of data to a span of -s. /// /// The source of data. @@ -164,8 +160,8 @@ internal void ToBgra32Bytes(Span sourceColors, Span destBytes, int /// The number of pixels to convert. internal virtual void PackFromRgb24(Span source, Span destPixels, int count) { - GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); - + GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); + ref Rgb24 sourceRef = ref source.DangerousGetPinnableReference(); ref TPixel destRef = ref destPixels.DangerousGetPinnableReference(); @@ -175,11 +171,11 @@ internal virtual void PackFromRgb24(Span source, Span destPixels, { ref TPixel dp = ref Unsafe.Add(ref destRef, i); rgba.Rgb = Unsafe.Add(ref sourceRef, i); - dp.PackFromRgba32(rgba); + dp.PackFromRgba32(rgba); } } - - /// + + /// /// A helper for that expects a byte span. /// The layout of the data in 'sourceBytes' must be compatible with layout. /// @@ -191,8 +187,8 @@ internal void PackFromRgb24Bytes(Span sourceBytes, Span destPixels { this.PackFromRgb24(sourceBytes.NonPortableCast(), destPixels, count); } - - /// + + /// /// Converts 'count' pixels in 'sourcePixels` span to a span of -s. /// Bulk version of . /// @@ -214,20 +210,20 @@ internal virtual void ToRgb24(Span sourcePixels, Span dest, int c } } - /// + /// /// A helper for that expects a byte span as destination. /// The layout of the data in 'destBytes' must be compatible with layout. /// /// The to the source colors. /// The to the destination bytes. /// The number of pixels to convert. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void ToRgb24Bytes(Span sourceColors, Span destBytes, int count) { this.ToRgb24(sourceColors, destBytes.NonPortableCast(), count); } - - /// + + /// /// Converts 'count' elements in 'source` span of data to a span of -s. /// /// The source of data. @@ -235,8 +231,8 @@ internal void ToRgb24Bytes(Span sourceColors, Span destBytes, int /// The number of pixels to convert. internal virtual void PackFromBgr24(Span source, Span destPixels, int count) { - GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); - + GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); + ref Bgr24 sourceRef = ref source.DangerousGetPinnableReference(); ref TPixel destRef = ref destPixels.DangerousGetPinnableReference(); @@ -246,11 +242,11 @@ internal virtual void PackFromBgr24(Span source, Span destPixels, { ref TPixel dp = ref Unsafe.Add(ref destRef, i); rgba.Bgr = Unsafe.Add(ref sourceRef, i); - dp.PackFromRgba32(rgba); + dp.PackFromRgba32(rgba); } } - - /// + + /// /// A helper for that expects a byte span. /// The layout of the data in 'sourceBytes' must be compatible with layout. /// @@ -262,8 +258,8 @@ internal void PackFromBgr24Bytes(Span sourceBytes, Span destPixels { this.PackFromBgr24(sourceBytes.NonPortableCast(), destPixels, count); } - - /// + + /// /// Converts 'count' pixels in 'sourcePixels` span to a span of -s. /// Bulk version of . /// @@ -285,18 +281,18 @@ internal virtual void ToBgr24(Span sourcePixels, Span dest, int c } } - /// + /// /// A helper for that expects a byte span as destination. /// The layout of the data in 'destBytes' must be compatible with layout. /// /// The to the source colors. /// The to the destination bytes. /// The number of pixels to convert. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void ToBgr24Bytes(Span sourceColors, Span destBytes, int count) { this.ToBgr24(sourceColors, destBytes.NonPortableCast(), count); } - - } + + } } \ No newline at end of file diff --git a/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.tt b/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.tt index 16292489fc..4f64086c9e 100644 --- a/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.tt +++ b/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.tt @@ -102,7 +102,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.PixelFormats +namespace SixLabors.ImageSharp.PixelFormats { using System; using System.Numerics; diff --git a/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs index e42c575d89..e79f9fb19d 100644 --- a/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs @@ -1,20 +1,14 @@ // -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { using System; - using System.Numerics; using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; + using SixLabors.ImageSharp.PixelFormats; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - /// /// Provides optimized overrides for bulk operations. /// diff --git a/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt index 9c01fa9157..0492fa40ae 100644 --- a/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt @@ -66,15 +66,15 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace SixLabors.ImageSharp { using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Memory; + using SixLabors.ImageSharp.PixelFormats; /// /// Provides optimized overrides for bulk operations. diff --git a/src/ImageSharp/PixelFormats/HalfSingle.cs b/src/ImageSharp/PixelFormats/HalfSingle.cs index 3bdfc9f1cf..2394b1be88 100644 --- a/src/ImageSharp/PixelFormats/HalfSingle.cs +++ b/src/ImageSharp/PixelFormats/HalfSingle.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing a single 16 bit floating point value. /// diff --git a/src/ImageSharp/PixelFormats/HalfTypeHelper.cs b/src/ImageSharp/PixelFormats/HalfTypeHelper.cs index 740795adc6..4d6ef0fb40 100644 --- a/src/ImageSharp/PixelFormats/HalfTypeHelper.cs +++ b/src/ImageSharp/PixelFormats/HalfTypeHelper.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Helper methods for packing and unpacking floating point values /// diff --git a/src/ImageSharp/PixelFormats/HalfVector2.cs b/src/ImageSharp/PixelFormats/HalfVector2.cs index 7f1fe4ebdd..aa5f321908 100644 --- a/src/ImageSharp/PixelFormats/HalfVector2.cs +++ b/src/ImageSharp/PixelFormats/HalfVector2.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing two 16-bit floating-point values. /// diff --git a/src/ImageSharp/PixelFormats/HalfVector4.cs b/src/ImageSharp/PixelFormats/HalfVector4.cs index 062287dbe6..87a1c9a498 100644 --- a/src/ImageSharp/PixelFormats/HalfVector4.cs +++ b/src/ImageSharp/PixelFormats/HalfVector4.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing four 16-bit floating-point values. /// diff --git a/src/ImageSharp/PixelFormats/IPackedVector{TPacked}.cs b/src/ImageSharp/PixelFormats/IPackedVector{TPacked}.cs index ec283e6f2a..6775cbc589 100644 --- a/src/ImageSharp/PixelFormats/IPackedVector{TPacked}.cs +++ b/src/ImageSharp/PixelFormats/IPackedVector{TPacked}.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; +using System; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// This interface exists for ensuring signature compatibility to MonoGame and XNA packed color types. /// diff --git a/src/ImageSharp/PixelFormats/IPixel.cs b/src/ImageSharp/PixelFormats/IPixel.cs index 9090e1210c..37c505c848 100644 --- a/src/ImageSharp/PixelFormats/IPixel.cs +++ b/src/ImageSharp/PixelFormats/IPixel.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; +using System; +using System.Numerics; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// An interface that represents a generic pixel type. /// diff --git a/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs b/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs index 0b55dcbf91..45050de72e 100644 --- a/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats +namespace SixLabors.ImageSharp.PixelFormats { /// /// A set of named colors mapped to the provided color space. diff --git a/src/ImageSharp/PixelFormats/NormalizedByte2.cs b/src/ImageSharp/PixelFormats/NormalizedByte2.cs index 992986f92b..9a69f6ab36 100644 --- a/src/ImageSharp/PixelFormats/NormalizedByte2.cs +++ b/src/ImageSharp/PixelFormats/NormalizedByte2.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed packed pixel type containing two 8-bit signed normalized values, ranging from −1 to 1. /// diff --git a/src/ImageSharp/PixelFormats/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/NormalizedByte4.cs index 99f603f690..920f92cae7 100644 --- a/src/ImageSharp/PixelFormats/NormalizedByte4.cs +++ b/src/ImageSharp/PixelFormats/NormalizedByte4.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing four 8-bit signed normalized values, ranging from −1 to 1. /// diff --git a/src/ImageSharp/PixelFormats/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/NormalizedShort2.cs index a0615563f0..6d28f61c25 100644 --- a/src/ImageSharp/PixelFormats/NormalizedShort2.cs +++ b/src/ImageSharp/PixelFormats/NormalizedShort2.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing two 16-bit signed normalized values, ranging from −1 to 1. /// diff --git a/src/ImageSharp/PixelFormats/NormalizedShort4.cs b/src/ImageSharp/PixelFormats/NormalizedShort4.cs index f35fb63684..45f984da0b 100644 --- a/src/ImageSharp/PixelFormats/NormalizedShort4.cs +++ b/src/ImageSharp/PixelFormats/NormalizedShort4.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing four 16-bit signed normalized values, ranging from −1 to 1. /// diff --git a/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs b/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs index 29ef5675e7..0537ff514e 100644 --- a/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs +++ b/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; +using System; +using System.Numerics; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Assists with the conversion of known packed pixel formats from one to another. /// @@ -21,18 +19,11 @@ internal static class PackedPixelConverterHelper /// /// Returns the correct scaling function for the given types The compute scale function. /// - /// The scale function. /// The source pixel format. /// The target pixel format. /// The - public static Func ComputeScaleFunction(Func scaleFunc) + public static Func ComputeScaleFunction() { - // Custom type with a custom function. - if (scaleFunc != null) - { - return scaleFunc; - } - Type source = typeof(TPixel); Type target = typeof(TPixel2); diff --git a/src/ImageSharp/PixelFormats/PixelBlenderMode.cs b/src/ImageSharp/PixelFormats/PixelBlenderMode.cs index 1e48f71814..ae70cdee43 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenderMode.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenderMode.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Collections.Generic; - using System.Text; +using System; +using System.Collections.Generic; +using System.Text; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// The various blending modes. /// diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs index 915d9a9244..f0145b2d93 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs @@ -1,14 +1,13 @@ // -// -// Copyright (c) James Jackson-South and contributors. + +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats.PixelBlenders +namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { using System; using System.Numerics; - using ImageSharp.Memory; + using SixLabors.ImageSharp.Memory; /// @@ -25,7 +24,6 @@ namespace ImageSharp.PixelFormats.PixelBlenders internal static class DefaultPixelBlenders where TPixel : struct, IPixel { - internal class Normal : PixelBlender { diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt index 230b05499f..0dfe7101a1 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt @@ -16,11 +16,11 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.PixelFormats.PixelBlenders +namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { using System; using System.Numerics; - using ImageSharp.Memory; + using SixLabors.ImageSharp.Memory; /// diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs index 4213be0bae..10b5f69b54 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs @@ -1,10 +1,9 @@ // -// -// Copyright (c) James Jackson-South and contributors. + +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats.PixelBlenders +namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { using System.Numerics; using System.Runtime.CompilerServices; diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt index 53d22d8f38..4387caaf89 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt @@ -16,7 +16,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.PixelFormats.PixelBlenders +namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { using System.Numerics; using System.Runtime.CompilerServices; diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs index b1fca9520c..04c750255f 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats.PixelBlenders -{ - using System.Numerics; - using System.Runtime.CompilerServices; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders +{ /// /// Collection of Porter Duff alpha blending functions applying an the 'Over' composition model. /// diff --git a/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs index 1a1d1cd054..54cb09c28a 100644 --- a/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; +using System; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Abstract base class for calling pixel composition functions /// diff --git a/src/ImageSharp/PixelFormats/PixelConversionExtensions.cs b/src/ImageSharp/PixelFormats/PixelConversionExtensions.cs index 1ea2628951..37b225d2e0 100644 --- a/src/ImageSharp/PixelFormats/PixelConversionExtensions.cs +++ b/src/ImageSharp/PixelFormats/PixelConversionExtensions.cs @@ -1,8 +1,11 @@ -namespace ImageSharp.PixelFormats -{ - using System; - using System.Runtime.CompilerServices; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Extension methods for copying single pixel data into byte Spans. /// TODO: This utility class exists for legacy reasons. Need to do a lot of chore work to remove it (mostly in test classes). diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs index 5a3737dc66..154ec73738 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using ImageSharp.PixelFormats.PixelBlenders; +using SixLabors.ImageSharp.PixelFormats.PixelBlenders; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Provides access to pixel blenders /// diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs index a62d14527a..4f879fbdc7 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// A stateless class implementing Strategy Pattern for batched pixel-data conversion operations /// for pixel buffers of type . diff --git a/src/ImageSharp/PixelFormats/Rg32.cs b/src/ImageSharp/PixelFormats/Rg32.cs index 0575689a77..d2c296515f 100644 --- a/src/ImageSharp/PixelFormats/Rg32.cs +++ b/src/ImageSharp/PixelFormats/Rg32.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing two 16-bit unsigned normalized values ranging from 0 to 1. /// diff --git a/src/ImageSharp/PixelFormats/Rgb24.cs b/src/ImageSharp/PixelFormats/Rgb24.cs index b8cc8dc24f..5a12cff201 100644 --- a/src/ImageSharp/PixelFormats/Rgb24.cs +++ b/src/ImageSharp/PixelFormats/Rgb24.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Pixel type containing three 8-bit unsigned normalized values ranging from 0 to 255. /// The color components are stored in red, green, blue order. diff --git a/src/ImageSharp/PixelFormats/Rgba1010102.cs b/src/ImageSharp/PixelFormats/Rgba1010102.cs index e682aa4772..e6967d23ea 100644 --- a/src/ImageSharp/PixelFormats/Rgba1010102.cs +++ b/src/ImageSharp/PixelFormats/Rgba1010102.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed vector type containing unsigned normalized values ranging from 0 to 1. /// The x, y and z components use 10 bits, and the w component uses 2 bits. diff --git a/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs b/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs index ab4c2ea606..b5fed5a357 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Provides standardized deifinitions for named colors. /// diff --git a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs index 63e40e9cf7..a99c10d87d 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Provides optimized overrides for bulk operations. /// diff --git a/src/ImageSharp/PixelFormats/Rgba32.cs b/src/ImageSharp/PixelFormats/Rgba32.cs index 85322c7c5c..045332ccf8 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp +{ /// /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. /// The color components are stored in red, green, blue, and alpha order. diff --git a/src/ImageSharp/PixelFormats/Rgba64.cs b/src/ImageSharp/PixelFormats/Rgba64.cs index bdcf13763d..040ae15b1c 100644 --- a/src/ImageSharp/PixelFormats/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/Rgba64.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing four 16-bit unsigned normalized values ranging from 0 to 1. /// diff --git a/src/ImageSharp/PixelFormats/RgbaComponent.cs b/src/ImageSharp/PixelFormats/RgbaComponent.cs index ed85fb86bb..edadd5818e 100644 --- a/src/ImageSharp/PixelFormats/RgbaComponent.cs +++ b/src/ImageSharp/PixelFormats/RgbaComponent.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Enumerates the RGBA (red, green, blue, alpha) color components. diff --git a/src/ImageSharp/PixelFormats/RgbaVector.Definitions.cs b/src/ImageSharp/PixelFormats/RgbaVector.Definitions.cs index dc965f9ff5..2ef37c43ae 100644 --- a/src/ImageSharp/PixelFormats/RgbaVector.Definitions.cs +++ b/src/ImageSharp/PixelFormats/RgbaVector.Definitions.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats +namespace SixLabors.ImageSharp.PixelFormats { /// /// Provides operators and composition algorithms. diff --git a/src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs b/src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs index 00b7461661..1886df29f1 100644 --- a/src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - - using ImageSharp.Memory; +using System; +using System.Numerics; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Provides optimized overrides for bulk operations. /// diff --git a/src/ImageSharp/PixelFormats/RgbaVector.cs b/src/ImageSharp/PixelFormats/RgbaVector.cs index c6eed1122e..ba641d590c 100644 --- a/src/ImageSharp/PixelFormats/RgbaVector.cs +++ b/src/ImageSharp/PixelFormats/RgbaVector.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Unpacked pixel type containing four 16-bit floating-point values typically ranging from 0 to 1. /// The color components are stored in red, green, blue, and alpha order. diff --git a/src/ImageSharp/PixelFormats/Short2.cs b/src/ImageSharp/PixelFormats/Short2.cs index 0b3f4be934..1355a94135 100644 --- a/src/ImageSharp/PixelFormats/Short2.cs +++ b/src/ImageSharp/PixelFormats/Short2.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing two 16-bit signed integer values. /// diff --git a/src/ImageSharp/PixelFormats/Short4.cs b/src/ImageSharp/PixelFormats/Short4.cs index 9583009293..aecb4d2de8 100644 --- a/src/ImageSharp/PixelFormats/Short4.cs +++ b/src/ImageSharp/PixelFormats/Short4.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.PixelFormats -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +namespace SixLabors.ImageSharp.PixelFormats +{ /// /// Packed pixel type containing four 16-bit signed integer values. /// diff --git a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs b/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs index e37f80c25a..5a165659b8 100644 --- a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs +++ b/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,10 +20,11 @@ public static partial class ImageExtensions /// The image this method extends. /// The threshold to apply binarization of the image. Must be between 0 and 1. /// The . - public static Image BinaryThreshold(this Image source, float threshold) + public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold) where TPixel : struct, IPixel { - return BinaryThreshold(source, threshold, source.Bounds); + source.ApplyProcessor(new BinaryThresholdProcessor(threshold)); + return source; } /// @@ -40,7 +37,7 @@ public static Image BinaryThreshold(this Image source, f /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image BinaryThreshold(this Image source, float threshold, Rectangle rectangle) + public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new BinaryThresholdProcessor(threshold), rectangle); diff --git a/src/ImageSharp/Processing/Binarization/Dither.cs b/src/ImageSharp/Processing/Binarization/Dither.cs index efaf63b06c..f21ccf0bd3 100644 --- a/src/ImageSharp/Processing/Binarization/Dither.cs +++ b/src/ImageSharp/Processing/Binarization/Dither.cs @@ -1,22 +1,33 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.Dithering; - using ImageSharp.PixelFormats; - using ImageSharp.Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.Dithering; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// public static partial class ImageExtensions { + /// + /// Dithers the image reducing it to two colors using ordered dithering. + /// + /// The pixel format. + /// The image this method extends. + /// The ordered ditherer. + /// The . + public static IImageProcessingContext Dither(this IImageProcessingContext source, IOrderedDither dither) + where TPixel : struct, IPixel + { + source.ApplyProcessor(new OrderedDitherProcessor(dither, 0)); + return source; + } + /// /// Dithers the image reducing it to two colors using ordered dithering. /// @@ -25,10 +36,28 @@ public static partial class ImageExtensions /// The ordered ditherer. /// The component index to test the threshold against. Must range from 0 to 3. /// The . - public static Image Dither(this Image source, IOrderedDither dither, int index = 0) + public static IImageProcessingContext Dither(this IImageProcessingContext source, IOrderedDither dither, int index) + where TPixel : struct, IPixel + { + source.ApplyProcessor(new OrderedDitherProcessor(dither, index)); + return source; + } + + /// + /// Dithers the image reducing it to two colors using ordered dithering. + /// + /// The pixel format. + /// The image this method extends. + /// The ordered ditherer. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// The . + public static IImageProcessingContext Dither(this IImageProcessingContext source, IOrderedDither dither, Rectangle rectangle) where TPixel : struct, IPixel { - return Dither(source, dither, source.Bounds, index); + source.ApplyProcessor(new OrderedDitherProcessor(dither, 0), rectangle); + return source; } /// @@ -42,7 +71,7 @@ public static Image Dither(this Image source, IOrderedDi /// /// The component index to test the threshold against. Must range from 0 to 3. /// The . - public static Image Dither(this Image source, IOrderedDither dither, Rectangle rectangle, int index = 0) + public static IImageProcessingContext Dither(this IImageProcessingContext source, IOrderedDither dither, Rectangle rectangle, int index) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, index), rectangle); @@ -57,10 +86,11 @@ public static Image Dither(this Image source, IOrderedDi /// The diffusion algorithm to apply. /// The threshold to apply binarization of the image. Must be between 0 and 1. /// The . - public static Image Dither(this Image source, IErrorDiffuser diffuser, float threshold) + public static IImageProcessingContext Dither(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold) where TPixel : struct, IPixel { - return Dither(source, diffuser, threshold, source.Bounds); + source.ApplyProcessor(new ErrorDiffusionDitherProcessor(diffuser, threshold)); + return source; } /// @@ -74,7 +104,7 @@ public static Image Dither(this Image source, IErrorDiff /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Dither(this Image source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) + public static IImageProcessingContext Dither(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new ErrorDiffusionDitherProcessor(diffuser, threshold), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs b/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs index 6a4e3807ba..300c073818 100644 --- a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs +++ b/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,10 +20,11 @@ public static partial class ImageExtensions /// The pixel format. /// The image this method extends. /// The . - public static Image BlackWhite(this Image source) + public static IImageProcessingContext BlackWhite(this IImageProcessingContext source) where TPixel : struct, IPixel { - return BlackWhite(source, source.Bounds); + source.ApplyProcessor(new BlackWhiteProcessor()); + return source; } /// @@ -39,7 +36,7 @@ public static Image BlackWhite(this Image source) /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image BlackWhite(this Image source, Rectangle rectangle) + public static IImageProcessingContext BlackWhite(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new BlackWhiteProcessor(), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs b/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs index 14641afba1..ebfa9ffdcd 100644 --- a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs +++ b/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -25,10 +21,11 @@ public static partial class ImageExtensions /// The image this method extends. /// The type of color blindness simulator to apply. /// The . - public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness) + public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindness colorBlindness) where TPixel : struct, IPixel { - return ColorBlindness(source, colorBlindness, source.Bounds); + source.ApplyProcessor(GetProcessor(colorBlindness)); + return source; } /// @@ -41,48 +38,35 @@ public static Image ColorBlindness(this Image source, Co /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle) + public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindness colorBlindness, Rectangle rectangle) where TPixel : struct, IPixel { - IImageProcessor processor; + source.ApplyProcessor(GetProcessor(colorBlindness), rectangle); + return source; + } + private static IImageProcessor GetProcessor(ColorBlindness colorBlindness) + where TPixel : struct, IPixel + { switch (colorBlindness) { case ImageSharp.Processing.ColorBlindness.Achromatomaly: - processor = new AchromatomalyProcessor(); - break; - + return new AchromatomalyProcessor(); case ImageSharp.Processing.ColorBlindness.Achromatopsia: - processor = new AchromatopsiaProcessor(); - break; - + return new AchromatopsiaProcessor(); case ImageSharp.Processing.ColorBlindness.Deuteranomaly: - processor = new DeuteranomalyProcessor(); - break; - + return new DeuteranomalyProcessor(); case ImageSharp.Processing.ColorBlindness.Deuteranopia: - processor = new DeuteranopiaProcessor(); - break; - + return new DeuteranopiaProcessor(); case ImageSharp.Processing.ColorBlindness.Protanomaly: - processor = new ProtanomalyProcessor(); - break; - + return new ProtanomalyProcessor(); case ImageSharp.Processing.ColorBlindness.Protanopia: - processor = new ProtanopiaProcessor(); - break; - + return new ProtanopiaProcessor(); case ImageSharp.Processing.ColorBlindness.Tritanomaly: - processor = new TritanomalyProcessor(); - break; - + return new TritanomalyProcessor(); default: - processor = new TritanopiaProcessor(); - break; + return new TritanopiaProcessor(); } - - source.ApplyProcessor(processor, rectangle); - return source; } } } diff --git a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs b/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs index 635b6747a6..bcf48d3e2c 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -22,7 +19,7 @@ public static partial class ImageExtensions /// The pixel format. /// The image this method extends. /// The . - public static Image Grayscale(this Image source) + public static IImageProcessingContext Grayscale(this IImageProcessingContext source) where TPixel : struct, IPixel { return Grayscale(source, GrayscaleMode.Bt709); @@ -35,10 +32,15 @@ public static Image Grayscale(this Image source) /// The image this method extends. /// The formula to apply to perform the operation. /// The . - public static Image Grayscale(this Image source, GrayscaleMode mode) + public static IImageProcessingContext Grayscale(this IImageProcessingContext source, GrayscaleMode mode) where TPixel : struct, IPixel { - return Grayscale(source, mode, source.Bounds); + IImageProcessor processor = mode == GrayscaleMode.Bt709 + ? (IImageProcessor)new GrayscaleBt709Processor() + : new GrayscaleBt601Processor(); + + source.ApplyProcessor(processor); + return source; } /// @@ -50,13 +52,10 @@ public static Image Grayscale(this Image source, Graysca /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Grayscale(this Image source, Rectangle rectangle) + public static IImageProcessingContext Grayscale(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { - IImageProcessor processor = new GrayscaleBt709Processor(); - - source.ApplyProcessor(processor, rectangle); - return source; + return Grayscale(source, GrayscaleMode.Bt709, rectangle); } /// @@ -69,7 +68,7 @@ public static Image Grayscale(this Image source, Rectang /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Grayscale(this Image source, GrayscaleMode mode, Rectangle rectangle) + public static IImageProcessingContext Grayscale(this IImageProcessingContext source, GrayscaleMode mode, Rectangle rectangle) where TPixel : struct, IPixel { IImageProcessor processor = mode == GrayscaleMode.Bt709 diff --git a/src/ImageSharp/Processing/ColorMatrix/Hue.cs b/src/ImageSharp/Processing/ColorMatrix/Hue.cs index d218b3a104..bfc931977d 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Hue.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Hue.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -25,10 +21,11 @@ public static partial class ImageExtensions /// The image this method extends. /// The angle in degrees to adjust the image. /// The . - public static Image Hue(this Image source, float degrees) + public static IImageProcessingContext Hue(this IImageProcessingContext source, float degrees) where TPixel : struct, IPixel { - return Hue(source, degrees, source.Bounds); + source.ApplyProcessor(new HueProcessor(degrees)); + return source; } /// @@ -41,7 +38,7 @@ public static Image Hue(this Image source, float degrees /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Hue(this Image source, float degrees, Rectangle rectangle) + public static IImageProcessingContext Hue(this IImageProcessingContext source, float degrees, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new HueProcessor(degrees), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs b/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs index 09eb131907..d7845320ad 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,10 +20,11 @@ public static partial class ImageExtensions /// The pixel format. /// The image this method extends. /// The . - public static Image Kodachrome(this Image source) + public static IImageProcessingContext Kodachrome(this IImageProcessingContext source) where TPixel : struct, IPixel { - return Kodachrome(source, source.Bounds); + source.ApplyProcessor(new KodachromeProcessor()); + return source; } /// @@ -39,7 +36,7 @@ public static Image Kodachrome(this Image source) /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Kodachrome(this Image source, Rectangle rectangle) + public static IImageProcessingContext Kodachrome(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new KodachromeProcessor(), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs index bca4577e48..947e531578 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,10 +20,10 @@ public static partial class ImageExtensions /// The pixel format. /// The image this method extends. /// The . - public static Image Lomograph(this Image source) + public static IImageProcessingContext Lomograph(this IImageProcessingContext source) where TPixel : struct, IPixel { - return Lomograph(source, source.Bounds, GraphicsOptions.Default); + return Lomograph(source, GraphicsOptions.Default); } /// @@ -39,7 +35,7 @@ public static Image Lomograph(this Image source) /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Lomograph(this Image source, Rectangle rectangle) + public static IImageProcessingContext Lomograph(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { return Lomograph(source, rectangle, GraphicsOptions.Default); @@ -52,10 +48,11 @@ public static Image Lomograph(this Image source, Rectang /// The image this method extends. /// The options effecting pixel blending. /// The . - public static Image Lomograph(this Image source, GraphicsOptions options) + public static IImageProcessingContext Lomograph(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel { - return Lomograph(source, source.Bounds, options); + source.ApplyProcessor(new LomographProcessor(options)); + return source; } /// @@ -68,7 +65,7 @@ public static Image Lomograph(this Image source, Graphic /// /// The options effecting pixel blending. /// The . - public static Image Lomograph(this Image source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Lomograph(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new LomographProcessor(options), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Options/ColorBlindness.cs b/src/ImageSharp/Processing/ColorMatrix/Options/ColorBlindness.cs index def253234f..1b92029f6b 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Options/ColorBlindness.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Options/ColorBlindness.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// Enumerates the various types of defined color blindness filters. diff --git a/src/ImageSharp/Processing/ColorMatrix/Options/GrayscaleMode.cs b/src/ImageSharp/Processing/ColorMatrix/Options/GrayscaleMode.cs index f1294ffaff..370071b7ab 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Options/GrayscaleMode.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Options/GrayscaleMode.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// Enumerates the various types of defined Grayscale filters. diff --git a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs index b2d8515d6c..c96087d57e 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,7 +20,7 @@ public static partial class ImageExtensions /// The pixel format. /// The image this method extends. /// The . - public static Image Polaroid(this Image source) + public static IImageProcessingContext Polaroid(this IImageProcessingContext source) where TPixel : struct, IPixel { return Polaroid(source, GraphicsOptions.Default); @@ -39,7 +35,7 @@ public static Image Polaroid(this Image source) /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Polaroid(this Image source, Rectangle rectangle) + public static IImageProcessingContext Polaroid(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { return Polaroid(source, rectangle, GraphicsOptions.Default); @@ -52,10 +48,11 @@ public static Image Polaroid(this Image source, Rectangl /// The image this method extends. /// The options effecting pixel blending. /// The . - public static Image Polaroid(this Image source, GraphicsOptions options) + public static IImageProcessingContext Polaroid(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel { - return Polaroid(source, source.Bounds, options); + source.ApplyProcessor(new PolaroidProcessor(options)); + return source; } /// @@ -68,7 +65,7 @@ public static Image Polaroid(this Image source, Graphics /// /// The options effecting pixel blending. /// The . - public static Image Polaroid(this Image source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Polaroid(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new PolaroidProcessor(options), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Saturation.cs b/src/ImageSharp/Processing/ColorMatrix/Saturation.cs index 88f3b15296..26ca5ec204 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Saturation.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Saturation.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -25,10 +21,11 @@ public static partial class ImageExtensions /// The image this method extends. /// The new saturation of the image. Must be between -100 and 100. /// The . - public static Image Saturation(this Image source, int amount) + public static IImageProcessingContext Saturation(this IImageProcessingContext source, int amount) where TPixel : struct, IPixel { - return Saturation(source, amount, source.Bounds); + source.ApplyProcessor(new SaturationProcessor(amount)); + return source; } /// @@ -41,7 +38,7 @@ public static Image Saturation(this Image source, int am /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Saturation(this Image source, int amount, Rectangle rectangle) + public static IImageProcessingContext Saturation(this IImageProcessingContext source, int amount, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new SaturationProcessor(amount), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs index 000c0ffba8..d1116fac8b 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,11 +20,9 @@ public static partial class ImageExtensions /// The pixel format. /// The image this method extends. /// The . - public static Image Sepia(this Image source) + public static IImageProcessingContext Sepia(this IImageProcessingContext source) where TPixel : struct, IPixel - { - return Sepia(source, source.Bounds); - } + => source.ApplyProcessor(new SepiaProcessor()); /// /// Applies sepia toning to the image. @@ -39,11 +33,8 @@ public static Image Sepia(this Image source) /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Sepia(this Image source, Rectangle rectangle) + public static IImageProcessingContext Sepia(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new SepiaProcessor(), rectangle); - return source; - } + => source.ApplyProcessor(new SepiaProcessor(), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/BoxBlur.cs b/src/ImageSharp/Processing/Convolution/BoxBlur.cs index ad5e477dc9..b0c6ffc8d2 100644 --- a/src/ImageSharp/Processing/Convolution/BoxBlur.cs +++ b/src/ImageSharp/Processing/Convolution/BoxBlur.cs @@ -1,22 +1,28 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// public static partial class ImageExtensions { + /// + /// Applies a box blur to the image. + /// + /// The pixel format. + /// The image this method extends. + /// The . + public static IImageProcessingContext BoxBlur(this IImageProcessingContext source) + where TPixel : struct, IPixel + => source.ApplyProcessor(new BoxBlurProcessor(7)); + /// /// Applies a box blur to the image. /// @@ -24,11 +30,9 @@ public static partial class ImageExtensions /// The image this method extends. /// The 'radius' value representing the size of the area to sample. /// The . - public static Image BoxBlur(this Image source, int radius = 7) + public static IImageProcessingContext BoxBlur(this IImageProcessingContext source, int radius) where TPixel : struct, IPixel - { - return BoxBlur(source, radius, source.Bounds); - } + => source.ApplyProcessor(new BoxBlurProcessor(radius)); /// /// Applies a box blur to the image. @@ -40,11 +44,8 @@ public static Image BoxBlur(this Image source, int radiu /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image BoxBlur(this Image source, int radius, Rectangle rectangle) + public static IImageProcessingContext BoxBlur(this IImageProcessingContext source, int radius, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BoxBlurProcessor(radius), rectangle); - return source; - } + => source.ApplyProcessor(new BoxBlurProcessor(radius), rectangle); } } diff --git a/src/ImageSharp/Processing/Convolution/DetectEdges.cs b/src/ImageSharp/Processing/Convolution/DetectEdges.cs index 1cc8b693ff..79e7ac6cf4 100644 --- a/src/ImageSharp/Processing/Convolution/DetectEdges.cs +++ b/src/ImageSharp/Processing/Convolution/DetectEdges.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -25,10 +21,10 @@ public static partial class ImageExtensions /// The pixel format. /// The image this method extends. /// The . - public static Image DetectEdges(this Image source) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source) where TPixel : struct, IPixel { - return DetectEdges(source, source.Bounds, new SobelProcessor { Grayscale = true }); + return DetectEdges(source, new SobelProcessor { Grayscale = true }); } /// @@ -41,12 +37,23 @@ public static Image DetectEdges(this Image source) /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image DetectEdges(this Image source, Rectangle rectangle) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { return DetectEdges(source, rectangle, new SobelProcessor { Grayscale = true }); } + /// + /// Detects any edges within the image. + /// + /// The pixel format. + /// The image this method extends. + /// The filter for detecting edges. + /// The . + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, EdgeDetection filter) + where TPixel : struct, IPixel + => DetectEdges(source, GetProcessor(filter, true)); + /// /// Detects any edges within the image. /// @@ -55,11 +62,9 @@ public static Image DetectEdges(this Image source, Recta /// The filter for detecting edges. /// Whether to convert the image to Grayscale first. Defaults to true. /// The . - public static Image DetectEdges(this Image source, EdgeDetection filter, bool grayscale = true) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, EdgeDetection filter, bool grayscale) where TPixel : struct, IPixel - { - return DetectEdges(source, filter, source.Bounds, grayscale); - } + => DetectEdges(source, GetProcessor(filter, grayscale)); /// /// Detects any edges within the image. @@ -72,7 +77,41 @@ public static Image DetectEdges(this Image source, EdgeD /// /// Whether to convert the image to Grayscale first. Defaults to true. /// The . - public static Image DetectEdges(this Image source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) + where TPixel : struct, IPixel + => DetectEdges(source, rectangle, GetProcessor(filter, grayscale)); + + /// + /// Detects any edges within the image. + /// + /// The pixel format. + /// The image this method extends. + /// The filter for detecting edges. + /// The . + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, IEdgeDetectorProcessor filter) + where TPixel : struct, IPixel + { + return source.ApplyProcessor(filter); + } + + /// + /// Detects any edges within the image. + /// + /// The pixel format. + /// The image this method extends. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// The filter for detecting edges. + /// The . + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, Rectangle rectangle, IEdgeDetectorProcessor filter) + where TPixel : struct, IPixel + { + source.ApplyProcessor(filter, rectangle); + return source; + } + + private static IEdgeDetectorProcessor GetProcessor(EdgeDetection filter, bool grayscale) where TPixel : struct, IPixel { IEdgeDetectorProcessor processor; @@ -120,37 +159,7 @@ public static Image DetectEdges(this Image source, EdgeD break; } - return DetectEdges(source, rectangle, processor); - } - - /// - /// Detects any edges within the image. - /// - /// The pixel format. - /// The image this method extends. - /// The filter for detecting edges. - /// The . - public static Image DetectEdges(this Image source, IEdgeDetectorProcessor filter) - where TPixel : struct, IPixel - { - return DetectEdges(source, source.Bounds, filter); - } - - /// - /// Detects any edges within the image. - /// - /// The pixel format. - /// The image this method extends. - /// - /// The structure that specifies the portion of the image object to alter. - /// - /// The filter for detecting edges. - /// The . - public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorProcessor filter) - where TPixel : struct, IPixel - { - source.ApplyProcessor(filter, rectangle); - return source; + return processor; } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs index f9658fcb5d..9bca97242c 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs @@ -1,23 +1,29 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// public static partial class ImageExtensions { + /// + /// Applies a Gaussian blur to the image. + /// + /// The pixel format. + /// The image this method extends. + /// The . + public static IImageProcessingContext GaussianBlur(this IImageProcessingContext source) + where TPixel : struct, IPixel + => source.ApplyProcessor(new GaussianBlurProcessor(3f)); + /// /// Applies a Gaussian blur to the image. /// @@ -25,11 +31,9 @@ public static partial class ImageExtensions /// The image this method extends. /// The 'sigma' value representing the weight of the blur. /// The . - public static Image GaussianBlur(this Image source, float sigma = 3f) + public static IImageProcessingContext GaussianBlur(this IImageProcessingContext source, float sigma) where TPixel : struct, IPixel - { - return GaussianBlur(source, sigma, source.Bounds); - } + => source.ApplyProcessor(new GaussianBlurProcessor(sigma)); /// /// Applies a Gaussian blur to the image. @@ -41,11 +45,8 @@ public static Image GaussianBlur(this Image source, floa /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image GaussianBlur(this Image source, float sigma, Rectangle rectangle) + public static IImageProcessingContext GaussianBlur(this IImageProcessingContext source, float sigma, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new GaussianBlurProcessor(sigma), rectangle); - return source; - } + => source.ApplyProcessor(new GaussianBlurProcessor(sigma), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs index bb616cc67e..1cea2dae9b 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs @@ -1,23 +1,29 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// public static partial class ImageExtensions { + /// + /// Applies a Gaussian sharpening filter to the image. + /// + /// The pixel format. + /// The image this method extends. + /// The . + public static IImageProcessingContext GaussianSharpen(this IImageProcessingContext source) + where TPixel : struct, IPixel + => source.ApplyProcessor(new GaussianSharpenProcessor(3f)); + /// /// Applies a Gaussian sharpening filter to the image. /// @@ -25,11 +31,9 @@ public static partial class ImageExtensions /// The image this method extends. /// The 'sigma' value representing the weight of the blur. /// The . - public static Image GaussianSharpen(this Image source, float sigma = 3f) + public static IImageProcessingContext GaussianSharpen(this IImageProcessingContext source, float sigma) where TPixel : struct, IPixel - { - return GaussianSharpen(source, sigma, source.Bounds); - } + => source.ApplyProcessor(new GaussianSharpenProcessor(sigma)); /// /// Applies a Gaussian sharpening filter to the image. @@ -41,11 +45,8 @@ public static Image GaussianSharpen(this Image source, f /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image GaussianSharpen(this Image source, float sigma, Rectangle rectangle) + public static IImageProcessingContext GaussianSharpen(this IImageProcessingContext source, float sigma, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new GaussianSharpenProcessor(sigma), rectangle); - return source; - } + => source.ApplyProcessor(new GaussianSharpenProcessor(sigma), rectangle); } } diff --git a/src/ImageSharp/Processing/Convolution/Options/EdgeDetection.cs b/src/ImageSharp/Processing/Convolution/Options/EdgeDetection.cs index 809992f005..b01bb945cf 100644 --- a/src/ImageSharp/Processing/Convolution/Options/EdgeDetection.cs +++ b/src/ImageSharp/Processing/Convolution/Options/EdgeDetection.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// Enumerates the various types of defined edge detection filters. diff --git a/src/ImageSharp/Processing/Delegate.cs b/src/ImageSharp/Processing/Delegate.cs new file mode 100644 index 0000000000..b390e46ae9 --- /dev/null +++ b/src/ImageSharp/Processing/Delegate.cs @@ -0,0 +1,28 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; + +namespace SixLabors.ImageSharp +{ + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Applies the given operation to the mutable image. + /// Useful when we need to extract information like Width/Height to parameterize the next operation working on the chain. + /// To achieve this the method actually implements an "inline" with as it's processing logic. + /// + /// The pixel format. + /// The image to mutate. + /// The operation to perform on the source. + /// The to allow chaining of operations. + public static IImageProcessingContext Apply(this IImageProcessingContext source, Action> operation) + where TPixel : struct, IPixel + => source.ApplyProcessor(new DelegateProcessor(operation)); + } +} diff --git a/src/ImageSharp/Processing/Effects/Alpha.cs b/src/ImageSharp/Processing/Effects/Alpha.cs index a0d218651a..2fac64e1cf 100644 --- a/src/ImageSharp/Processing/Effects/Alpha.cs +++ b/src/ImageSharp/Processing/Effects/Alpha.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,11 +20,9 @@ public static partial class ImageExtensions /// The image this method extends. /// The new opacity of the image. Must be between 0 and 1. /// The . - public static Image Alpha(this Image source, float percent) + public static IImageProcessingContext Alpha(this IImageProcessingContext source, float percent) where TPixel : struct, IPixel - { - return Alpha(source, percent, source.Bounds); - } + => source.ApplyProcessor(new AlphaProcessor(percent)); /// /// Alters the alpha component of the image. @@ -40,11 +34,8 @@ public static Image Alpha(this Image source, float perce /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Alpha(this Image source, float percent, Rectangle rectangle) + public static IImageProcessingContext Alpha(this IImageProcessingContext source, float percent, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new AlphaProcessor(percent), rectangle); - return source; - } + => source.ApplyProcessor(new AlphaProcessor(percent), rectangle); } } diff --git a/src/ImageSharp/Processing/Effects/BackgroundColor.cs b/src/ImageSharp/Processing/Effects/BackgroundColor.cs index a1e04c8a3d..da00b4ddd0 100644 --- a/src/ImageSharp/Processing/Effects/BackgroundColor.cs +++ b/src/ImageSharp/Processing/Effects/BackgroundColor.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -25,11 +21,9 @@ public static partial class ImageExtensions /// The color to set as the background. /// The options effecting pixel blending. /// The . - public static Image BackgroundColor(this Image source, TPixel color, GraphicsOptions options) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel - { - return BackgroundColor(source, color, source.Bounds, options); - } + => source.ApplyProcessor(new BackgroundColorProcessor(color, options)); /// /// Replaces the background color of image with the given one. @@ -42,12 +36,9 @@ public static Image BackgroundColor(this Image source, T /// /// The options effecting pixel blending. /// The . - public static Image BackgroundColor(this Image source, TPixel color, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BackgroundColorProcessor(color, options), rectangle); - return source; - } + => source.ApplyProcessor(new BackgroundColorProcessor(color, options), rectangle); /// /// Replaces the background color of image with the given one. @@ -56,7 +47,7 @@ public static Image BackgroundColor(this Image source, T /// The image this method extends. /// The color to set as the background. /// The . - public static Image BackgroundColor(this Image source, TPixel color) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel { return BackgroundColor(source, color, GraphicsOptions.Default); @@ -72,7 +63,7 @@ public static Image BackgroundColor(this Image source, T /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image BackgroundColor(this Image source, TPixel color, Rectangle rectangle) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, Rectangle rectangle) where TPixel : struct, IPixel { return BackgroundColor(source, color, rectangle, GraphicsOptions.Default); diff --git a/src/ImageSharp/Processing/Effects/Brightness.cs b/src/ImageSharp/Processing/Effects/Brightness.cs index 165f897b80..5c76287858 100644 --- a/src/ImageSharp/Processing/Effects/Brightness.cs +++ b/src/ImageSharp/Processing/Effects/Brightness.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,11 +20,9 @@ public static partial class ImageExtensions /// The image this method extends. /// The new brightness of the image. Must be between -100 and 100. /// The . - public static Image Brightness(this Image source, int amount) - where TPixel : struct, IPixel - { - return Brightness(source, amount, source.Bounds); - } + public static IImageProcessingContext Brightness(this IImageProcessingContext source, int amount) + where TPixel : struct, IPixel + => source.ApplyProcessor(new BrightnessProcessor(amount)); /// /// Alters the brightness component of the image. @@ -40,11 +34,8 @@ public static Image Brightness(this Image source, int am /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Brightness(this Image source, int amount, Rectangle rectangle) + public static IImageProcessingContext Brightness(this IImageProcessingContext source, int amount, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BrightnessProcessor(amount), rectangle); - return source; - } + => source.ApplyProcessor(new BrightnessProcessor(amount), rectangle); } } diff --git a/src/ImageSharp/Processing/Effects/Contrast.cs b/src/ImageSharp/Processing/Effects/Contrast.cs index 0a55fd067b..562ab54dff 100644 --- a/src/ImageSharp/Processing/Effects/Contrast.cs +++ b/src/ImageSharp/Processing/Effects/Contrast.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,11 +20,9 @@ public static partial class ImageExtensions /// The image this method extends. /// The new contrast of the image. Must be between -100 and 100. /// The . - public static Image Contrast(this Image source, int amount) + public static IImageProcessingContext Contrast(this IImageProcessingContext source, int amount) where TPixel : struct, IPixel - { - return Contrast(source, amount, source.Bounds); - } + => source.ApplyProcessor(new ContrastProcessor(amount)); /// /// Alters the contrast component of the image. @@ -40,11 +34,8 @@ public static Image Contrast(this Image source, int amou /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Contrast(this Image source, int amount, Rectangle rectangle) + public static IImageProcessingContext Contrast(this IImageProcessingContext source, int amount, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new ContrastProcessor(amount), rectangle); - return source; - } + => source.ApplyProcessor(new ContrastProcessor(amount), rectangle); } } diff --git a/src/ImageSharp/Processing/Effects/Invert.cs b/src/ImageSharp/Processing/Effects/Invert.cs index d9a0695566..9c0a7d3772 100644 --- a/src/ImageSharp/Processing/Effects/Invert.cs +++ b/src/ImageSharp/Processing/Effects/Invert.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -23,11 +19,9 @@ public static partial class ImageExtensions /// The pixel format. /// The image this method extends. /// The . - public static Image Invert(this Image source) + public static IImageProcessingContext Invert(this IImageProcessingContext source) where TPixel : struct, IPixel - { - return Invert(source, source.Bounds); - } + => source.ApplyProcessor(new InvertProcessor()); /// /// Inverts the colors of the image. @@ -38,11 +32,8 @@ public static Image Invert(this Image source) /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Invert(this Image source, Rectangle rectangle) + public static IImageProcessingContext Invert(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new InvertProcessor(), rectangle); - return source; - } + => source.ApplyProcessor(new InvertProcessor(), rectangle); } } diff --git a/src/ImageSharp/Processing/Effects/OilPainting.cs b/src/ImageSharp/Processing/Effects/OilPainting.cs index 3b300e9197..0494c9a8b9 100644 --- a/src/ImageSharp/Processing/Effects/OilPainting.cs +++ b/src/ImageSharp/Processing/Effects/OilPainting.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,7 +20,7 @@ public static partial class ImageExtensions /// The pixel format. /// The image this method extends. /// The . - public static Image OilPaint(this Image source) + public static IImageProcessingContext OilPaint(this IImageProcessingContext source) where TPixel : struct, IPixel { return OilPaint(source, 10, 15); @@ -40,7 +36,7 @@ public static Image OilPaint(this Image source) /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image OilPaint(this Image source, Rectangle rectangle) + public static IImageProcessingContext OilPaint(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { return OilPaint(source, 10, 15, rectangle); @@ -54,11 +50,9 @@ public static Image OilPaint(this Image source, Rectangl /// The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image. /// The number of neighboring pixels used in calculating each individual pixel value. /// The . - public static Image OilPaint(this Image source, int levels, int brushSize) - where TPixel : struct, IPixel - { - return OilPaint(source, levels, brushSize, source.Bounds); - } + public static IImageProcessingContext OilPaint(this IImageProcessingContext source, int levels, int brushSize) + where TPixel : struct, IPixel + => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize)); /// /// Alters the colors of the image recreating an oil painting effect. @@ -71,18 +65,8 @@ public static Image OilPaint(this Image source, int leve /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image OilPaint(this Image source, int levels, int brushSize, Rectangle rectangle) + public static IImageProcessingContext OilPaint(this IImageProcessingContext source, int levels, int brushSize, Rectangle rectangle) where TPixel : struct, IPixel - { - Guard.MustBeGreaterThan(levels, 0, nameof(levels)); - - if (brushSize <= 0 || brushSize > source.Height || brushSize > source.Width) - { - throw new ArgumentOutOfRangeException(nameof(brushSize)); - } - - source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize), rectangle); - return source; - } + => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Effects/Pixelate.cs b/src/ImageSharp/Processing/Effects/Pixelate.cs index 07fdd50a35..29e348f6e6 100644 --- a/src/ImageSharp/Processing/Effects/Pixelate.cs +++ b/src/ImageSharp/Processing/Effects/Pixelate.cs @@ -1,22 +1,28 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// public static partial class ImageExtensions { + /// + /// Pixelates an image with the given pixel size. + /// + /// The pixel format. + /// The image this method extends. + /// The . + public static IImageProcessingContext Pixelate(this IImageProcessingContext source) + where TPixel : struct, IPixel + => source.ApplyProcessor(new PixelateProcessor(4)); + /// /// Pixelates an image with the given pixel size. /// @@ -24,11 +30,9 @@ public static partial class ImageExtensions /// The image this method extends. /// The size of the pixels. /// The . - public static Image Pixelate(this Image source, int size = 4) + public static IImageProcessingContext Pixelate(this IImageProcessingContext source, int size) where TPixel : struct, IPixel - { - return Pixelate(source, size, source.Bounds); - } + => source.ApplyProcessor(new PixelateProcessor(size)); /// /// Pixelates an image with the given pixel size. @@ -40,16 +44,8 @@ public static Image Pixelate(this Image source, int size /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Pixelate(this Image source, int size, Rectangle rectangle) + public static IImageProcessingContext Pixelate(this IImageProcessingContext source, int size, Rectangle rectangle) where TPixel : struct, IPixel - { - if (size <= 0 || size > source.Height || size > source.Width) - { - throw new ArgumentOutOfRangeException(nameof(size)); - } - - source.ApplyProcessor(new PixelateProcessor(size), rectangle); - return source; - } + => source.ApplyProcessor(new PixelateProcessor(size), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Overlays/Glow.cs b/src/ImageSharp/Processing/Overlays/Glow.cs index 84f6bf10ae..ee35963487 100644 --- a/src/ImageSharp/Processing/Overlays/Glow.cs +++ b/src/ImageSharp/Processing/Overlays/Glow.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using ImageSharp.PixelFormats; - - using Processing.Processors; - using SixLabors.Primitives; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -21,7 +18,7 @@ public static partial class ImageExtensions /// The pixel format. /// The image this method extends. /// The . - public static Image Glow(this Image source) + public static IImageProcessingContext Glow(this IImageProcessingContext source) where TPixel : struct, IPixel { return Glow(source, GraphicsOptions.Default); @@ -34,7 +31,7 @@ public static Image Glow(this Image source) /// The image this method extends. /// The color to set as the glow. /// The . - public static Image Glow(this Image source, TPixel color) + public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel { return Glow(source, color, GraphicsOptions.Default); @@ -47,7 +44,7 @@ public static Image Glow(this Image source, TPixel color /// The image this method extends. /// The the radius. /// The . - public static Image Glow(this Image source, float radius) + public static IImageProcessingContext Glow(this IImageProcessingContext source, float radius) where TPixel : struct, IPixel { return Glow(source, radius, GraphicsOptions.Default); @@ -62,11 +59,9 @@ public static Image Glow(this Image source, float radius /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Glow(this Image source, Rectangle rectangle) + public static IImageProcessingContext Glow(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel - { - return Glow(source, rectangle, GraphicsOptions.Default); - } + => source.Glow(rectangle, GraphicsOptions.Default); /// /// Applies a radial glow effect to an image. @@ -79,11 +74,9 @@ public static Image Glow(this Image source, Rectangle re /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Glow(this Image source, TPixel color, float radius, Rectangle rectangle) + public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, float radius, Rectangle rectangle) where TPixel : struct, IPixel - { - return Glow(source, color, radius, rectangle, GraphicsOptions.Default); - } + => source.Glow(color, ValueSize.Absolute(radius), rectangle, GraphicsOptions.Default); /// /// Applies a radial glow effect to an image. @@ -92,11 +85,9 @@ public static Image Glow(this Image source, TPixel color /// The image this method extends. /// The options effecting things like blending. /// The . - public static Image Glow(this Image source, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel - { - return Glow(source, NamedColors.Black, source.Bounds.Width * .5F, source.Bounds, options); - } + => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), options); /// /// Applies a radial glow effect to an image. @@ -106,11 +97,9 @@ public static Image Glow(this Image source, GraphicsOpti /// The color to set as the glow. /// The options effecting things like blending. /// The . - public static Image Glow(this Image source, TPixel color, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel - { - return Glow(source, color, source.Bounds.Width * .5F, source.Bounds, options); - } + => source.Glow(color, ValueSize.PercentageOfWidth(0.5f), options); /// /// Applies a radial glow effect to an image. @@ -120,11 +109,9 @@ public static Image Glow(this Image source, TPixel color /// The the radius. /// The options effecting things like blending. /// The . - public static Image Glow(this Image source, float radius, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, float radius, GraphicsOptions options) where TPixel : struct, IPixel - { - return Glow(source, NamedColors.Black, radius, source.Bounds, options); - } + => source.Glow(NamedColors.Black, ValueSize.Absolute(radius), options); /// /// Applies a radial glow effect to an image. @@ -136,11 +123,9 @@ public static Image Glow(this Image source, float radius /// /// The options effecting things like blending. /// The . - public static Image Glow(this Image source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - { - return Glow(source, NamedColors.Black, 0, rectangle, options); - } + => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), rectangle, options); /// /// Applies a radial glow effect to an image. @@ -154,12 +139,37 @@ public static Image Glow(this Image source, Rectangle re /// /// The options effecting things like blending. /// The . - public static Image Glow(this Image source, TPixel color, float radius, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, float radius, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - { - var processor = new GlowProcessor(color, options) { Radius = radius, }; - source.ApplyProcessor(processor, rectangle); - return source; - } + => source.Glow(color, ValueSize.Absolute(radius), rectangle, options); + + /// + /// Applies a radial glow effect to an image. + /// + /// The pixel format. + /// The image this method extends. + /// The color to set as the glow. + /// The the radius. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// The options effecting things like blending. + /// The . + private static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, ValueSize radius, Rectangle rectangle, GraphicsOptions options) + where TPixel : struct, IPixel + => source.ApplyProcessor(new GlowProcessor(color, radius, options), rectangle); + + /// + /// Applies a radial glow effect to an image. + /// + /// The pixel format. + /// The image this method extends. + /// The color to set as the glow. + /// The the radius. + /// The options effecting things like blending. + /// The . + private static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, ValueSize radius, GraphicsOptions options) + where TPixel : struct, IPixel + => source.ApplyProcessor(new GlowProcessor(color, radius, options)); } } diff --git a/src/ImageSharp/Processing/Overlays/Vignette.cs b/src/ImageSharp/Processing/Overlays/Vignette.cs index 75c4611a1e..cc93ccedc6 100644 --- a/src/ImageSharp/Processing/Overlays/Vignette.cs +++ b/src/ImageSharp/Processing/Overlays/Vignette.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using ImageSharp.PixelFormats; - - using Processing.Processors; - using SixLabors.Primitives; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -21,7 +18,7 @@ public static partial class ImageExtensions /// The pixel format. /// The image this method extends. /// The . - public static Image Vignette(this Image source) + public static IImageProcessingContext Vignette(this IImageProcessingContext source) where TPixel : struct, IPixel { return Vignette(source, GraphicsOptions.Default); @@ -34,7 +31,7 @@ public static Image Vignette(this Image source) /// The image this method extends. /// The color to set as the vignette. /// The . - public static Image Vignette(this Image source, TPixel color) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel { return Vignette(source, color, GraphicsOptions.Default); @@ -48,7 +45,7 @@ public static Image Vignette(this Image source, TPixel c /// The the x-radius. /// The the y-radius. /// The . - public static Image Vignette(this Image source, float radiusX, float radiusY) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, float radiusX, float radiusY) where TPixel : struct, IPixel { return Vignette(source, radiusX, radiusY, GraphicsOptions.Default); @@ -63,7 +60,7 @@ public static Image Vignette(this Image source, float ra /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Vignette(this Image source, Rectangle rectangle) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { return Vignette(source, rectangle, GraphicsOptions.Default); @@ -81,11 +78,9 @@ public static Image Vignette(this Image source, Rectangl /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Vignette(this Image source, TPixel color, float radiusX, float radiusY, Rectangle rectangle) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color, float radiusX, float radiusY, Rectangle rectangle) where TPixel : struct, IPixel - { - return Vignette(source, color, radiusX, radiusY, rectangle, GraphicsOptions.Default); - } + => source.Vignette(color, radiusX, radiusY, rectangle, GraphicsOptions.Default); /// /// Applies a radial vignette effect to an image. @@ -94,11 +89,9 @@ public static Image Vignette(this Image source, TPixel c /// The image this method extends. /// The options effecting pixel blending. /// The . - public static Image Vignette(this Image source, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel - { - return Vignette(source, NamedColors.Black, source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds, options); - } + => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); /// /// Applies a radial vignette effect to an image. @@ -108,11 +101,9 @@ public static Image Vignette(this Image source, Graphics /// The color to set as the vignette. /// The options effecting pixel blending. /// The . - public static Image Vignette(this Image source, TPixel color, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel - { - return Vignette(source, color, source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds, options); - } + => source.VignetteInternal(color, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); /// /// Applies a radial vignette effect to an image. @@ -123,11 +114,9 @@ public static Image Vignette(this Image source, TPixel c /// The the y-radius. /// The options effecting pixel blending. /// The . - public static Image Vignette(this Image source, float radiusX, float radiusY, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, float radiusX, float radiusY, GraphicsOptions options) where TPixel : struct, IPixel - { - return Vignette(source, NamedColors.Black, radiusX, radiusY, source.Bounds, options); - } + => source.VignetteInternal(NamedColors.Black, radiusX, radiusY, options); /// /// Applies a radial vignette effect to an image. @@ -139,11 +128,9 @@ public static Image Vignette(this Image source, float ra /// /// The options effecting pixel blending. /// The . - public static Image Vignette(this Image source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - { - return Vignette(source, NamedColors.Black, 0, 0, rectangle, options); - } + => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), rectangle, options); /// /// Applies a radial vignette effect to an image. @@ -158,12 +145,16 @@ public static Image Vignette(this Image source, Rectangl /// /// The options effecting pixel blending. /// The . - public static Image Vignette(this Image source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - { - var processor = new VignetteProcessor(color, options) { RadiusX = radiusX, RadiusY = radiusY }; - source.ApplyProcessor(processor, rectangle); - return source; - } + => source.VignetteInternal(color, radiusX, radiusY, rectangle, options); + + private static IImageProcessingContext VignetteInternal(this IImageProcessingContext source, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle, GraphicsOptions options) + where TPixel : struct, IPixel + => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options), rectangle); + + private static IImageProcessingContext VignetteInternal(this IImageProcessingContext source, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) + where TPixel : struct, IPixel + => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs index ea1b759ab5..7070c993ef 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Threading.Tasks; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Threading.Tasks; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// An to perform binary threshold filtering against an /// . The image will be converted to grayscale before thresholding occurs. diff --git a/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs index 85522e2886..2590aa6a00 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - - using ImageSharp.Dithering; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.Dithering; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// An that dithers an image using error diffusion. /// diff --git a/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs index a190bcd61b..b71ea97cf7 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Buffers; - - using ImageSharp.Dithering; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Buffers; +using SixLabors.ImageSharp.Dithering; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// An that dithers an image using error diffusion. /// diff --git a/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs b/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs new file mode 100644 index 0000000000..b4324a9ae3 --- /dev/null +++ b/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs @@ -0,0 +1,163 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Threading.Tasks; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing +{ + /// + /// Allows the application of processors to images. + /// + /// The pixel format. + internal abstract class CloningImageProcessor : IImageProcessor, ICloningImageProcessor + where TPixel : struct, IPixel + { + /// + public virtual ParallelOptions ParallelOptions { get; set; } + + /// + public virtual bool Compand { get; set; } = false; + + /// + public Image CloneAndApply(Image source, Rectangle sourceRectangle) + { + if (this.ParallelOptions == null) + { + this.ParallelOptions = source.Configuration.ParallelOptions; + } + + try + { + Image clone = this.CreateDestination(source, sourceRectangle); + + if (clone.Frames.Count != source.Frames.Count) + { + throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. The processor changed the number of frames."); + } + + this.BeforeImageApply(source, clone, sourceRectangle); + + this.BeforeApply(source, clone, sourceRectangle); + this.OnApply(source, clone, sourceRectangle); + this.AfterApply(source, clone, sourceRectangle); + + for (int i = 0; i < source.Frames.Count; i++) + { + ImageFrame sourceFrame = source.Frames[i]; + ImageFrame clonedFrame = clone.Frames[i]; + + this.BeforeApply(sourceFrame, clonedFrame, sourceRectangle); + + this.OnApply(sourceFrame, clonedFrame, sourceRectangle); + this.AfterApply(sourceFrame, clonedFrame, sourceRectangle); + } + + this.AfterImageApply(source, clone, sourceRectangle); + + return clone; + } +#if DEBUG + catch (Exception) + { + throw; +#else + catch (Exception ex) + { + throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex); +#endif + } + } + + /// + public void Apply(Image source, Rectangle sourceRectangle) + { + using (Image cloned = this.CloneAndApply(source, sourceRectangle)) + { + // we now need to move the pixel data/size data from one image base to another + if (cloned.Frames.Count != source.Frames.Count) + { + throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. The processor changed the number of frames."); + } + + source.SwapPixelsData(cloned); + for (int i = 0; i < source.Frames.Count; i++) + { + source.Frames[i].SwapPixelsData(cloned.Frames[i]); + } + } + } + + /// + /// Generates a deep clone of the source image that operatinos should be applied to. + /// + /// The source image. Cannot be null. + /// The source rectangle. + /// The cloned image. + protected virtual Image CreateDestination(Image source, Rectangle sourceRectangle) + { + return source.Clone(); + } + + /// + /// This method is called before the process is applied to prepare the processor. + /// + /// The source image. Cannot be null. + /// The cloned/destination image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected virtual void BeforeImageApply(Image source, Image destination, Rectangle sourceRectangle) + { + } + + /// + /// This method is called before the process is applied to prepare the processor. + /// + /// The source image. Cannot be null. + /// The cloned/destination image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected virtual void BeforeApply(ImageBase source, ImageBase destination, Rectangle sourceRectangle) + { + } + + /// + /// Applies the process to the specified portion of the specified at the specified location + /// and with the specified size. + /// + /// The source image. Cannot be null. + /// The cloned/destination image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected abstract void OnApply(ImageBase source, ImageBase destination, Rectangle sourceRectangle); + + /// + /// This method is called after the process is applied to prepare the processor. + /// + /// The source image. Cannot be null. + /// The cloned/destination image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected virtual void AfterApply(ImageBase source, ImageBase destination, Rectangle sourceRectangle) + { + } + + /// + /// This method is called after the process is applied to prepare the processor. + /// + /// The source image. Cannot be null. + /// The cloned/destination image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected virtual void AfterImageApply(Image source, Image destination, Rectangle sourceRectangle) + { + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/BlackWhiteProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/BlackWhiteProcessor.cs index d37d119a41..d8b6ab9514 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/BlackWhiteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/BlackWhiteProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image to their black and white equivalent. /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs index a91bd19467..1366a8fe1b 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness. /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs index d543c4edca..d1925e04df 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image recreating Achromatopsia (Monochrome) color blindness. /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs index ea73d0c662..964921d262 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness. /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs index 4b5129a8bf..f35d25a287 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image recreating Deuteranopia (Green-Blind) color blindness. /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs index 14eea08126..4c43ad0e21 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image recreating Protanopia (Red-Weak) color blindness. /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs index 39cb715bde..3a18ed91e2 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness. /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs index 2b402197bc..0c337af2d0 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image recreating Tritanomaly (Blue-Weak) color blindness. /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs index 5d228afa79..76c9f98e74 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image recreating Tritanopia (Blue-Blind) color blindness. /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs index 1bac145bc9..45ee1de59e 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// The color matrix filter. Inherit from this class to perform operation involving color matrices. /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt601Processor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt601Processor.cs index 65de8a66d2..a7033cfc95 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt601Processor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt601Processor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image to Grayscale applying the formula as specified by ITU-R Recommendation BT.601 /// . diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt709Processor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt709Processor.cs index 5f71e357b7..db7077620a 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt709Processor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt709Processor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image to Grayscale applying the formula as specified by ITU-R Recommendation BT.709 /// . diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs index f286839776..a222f195e9 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// An to change the hue of an . /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/IColorMatrixFilter.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/IColorMatrixFilter.cs index 0c29c65a10..d7785045fb 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/IColorMatrixFilter.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/IColorMatrixFilter.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Encapsulates properties and methods for creating processors that utilize a matrix to /// alter the image pixels. diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/KodachromeProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/KodachromeProcessor.cs index 18514236f7..e2ab32a70a 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/KodachromeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/KodachromeProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image recreating an old Kodachrome camera effect. /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs index bb33e51513..7ce96fa355 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image recreating an old Lomograph effect. /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs index 9e54574df9..96fb084cfd 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image recreating an old Polaroid effect. /// @@ -53,7 +50,7 @@ public PolaroidProcessor(GraphicsOptions options) protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) { new VignetteProcessor(veryDarkOrange, this.options).Apply(source, sourceRectangle); - new GlowProcessor(lightOrange, this.options) { Radius = source.Width / 4F }.Apply(source, sourceRectangle); + new GlowProcessor(lightOrange, source.Width / 4F, this.options).Apply(source, sourceRectangle); } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs index 3adfb83114..38788d9f9e 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// An to change the saturation of an . /// @@ -26,6 +23,7 @@ internal class SaturationProcessor : ColorMatrixProcessor /// public SaturationProcessor(int saturation) { + this.Amount = saturation; Guard.MustBeBetweenOrEqualTo(saturation, -100, 100, nameof(saturation)); float saturationFactor = saturation / 100F; @@ -58,6 +56,11 @@ public SaturationProcessor(int saturation) this.Matrix = matrix4X4; } + /// + /// Gets the amount to apply. + /// + public int Amount { get; } + /// public override Matrix4x4 Matrix { get; } } diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/SepiaProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/SepiaProcessor.cs index 89be3acad5..610b3d5f1c 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/SepiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/SepiaProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Converts the colors of the image to their sepia equivalent. /// The formula used matches the svg specification. diff --git a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs index 0a2162fb05..3c95d29974 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Applies a Box blur sampler to the image. /// @@ -31,11 +28,17 @@ internal class BoxBlurProcessor : ImageProcessor /// public BoxBlurProcessor(int radius = 7) { + this.Radius = radius; this.kernelSize = (radius * 2) + 1; this.KernelX = this.CreateBoxKernel(true); this.KernelY = this.CreateBoxKernel(false); } + /// + /// Gets the Radius + /// + public int Radius { get; } + /// /// Gets the horizontal gradient operator. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs index 708b6c6fd8..1fe31be448 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Defines a sampler that uses two one-dimensional matrices to perform convolution against an image. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs index ceb985b0b7..16b8075fcf 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Defines a sampler that uses two one-dimensional matrices to perform two-pass convolution against an image. /// @@ -50,7 +47,7 @@ protected override void OnApply(ImageBase source, Rectangle sourceRectan using (var firstPassPixels = new PixelAccessor(width, height)) using (PixelAccessor sourcePixels = source.Lock()) { - this.ApplyConvolution(firstPassPixels, sourcePixels, source.Bounds, this.KernelX); + this.ApplyConvolution(firstPassPixels, sourcePixels, source.Bounds(), this.KernelX); this.ApplyConvolution(sourcePixels, firstPassPixels, sourceRectangle, this.KernelY); } } diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs index cd2eb27004..9e256975e3 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Defines a sampler that uses a 2 dimensional matrix to perform convolution against an image. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs index ab0b459076..af7a5e276e 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Defines a sampler that detects edges within an image using two one-dimensional matrices. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs index 367c288fca..38bffe0c3c 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Defines a sampler that detects edges within an image using a eight two dimensional matrices. /// @@ -89,7 +86,7 @@ protected override void OnApply(ImageBase source, Rectangle sourceRectan int maxY = Math.Min(source.Height, endY); // we need a clean copy for each pass to start from - using (ImageBase cleanCopy = new Image(source)) + using (ImageBase cleanCopy = source.Clone()) { new ConvolutionProcessor(kernels[0]).Apply(source, sourceRectangle); @@ -116,7 +113,7 @@ protected override void OnApply(ImageBase source, Rectangle sourceRectan // ReSharper disable once ForCanBeConvertedToForeach for (int i = 1; i < kernels.Length; i++) { - using (ImageBase pass = new Image(cleanCopy)) + using (ImageBase pass = cleanCopy.Clone()) { new ConvolutionProcessor(kernels[i]).Apply(pass, sourceRectangle); diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs index 1400b6317a..b8e5106b7f 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Defines a sampler that detects edges within an image using a single two dimensional matrix. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs index c7c126794d..1561072c82 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - - using ImageSharp.PixelFormats; +using System; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Provides properties and methods allowing the detection of edges within an image. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs index b1361b514f..8e4cdd6b5a 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Diagnostics.CodeAnalysis; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Diagnostics.CodeAnalysis; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// The Kayyali operator filter. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs index af4700bb97..c0a3b35954 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Diagnostics.CodeAnalysis; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Diagnostics.CodeAnalysis; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// The Kirsch operator filter. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs index 5f58d56f8c..1b5c563187 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Diagnostics.CodeAnalysis; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Diagnostics.CodeAnalysis; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// The Laplacian 3 x 3 operator filter. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs index 2e365374cf..11438fe8db 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Diagnostics.CodeAnalysis; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Diagnostics.CodeAnalysis; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// The Laplacian 5 x 5 operator filter. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs index de2594653d..424c01137e 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Diagnostics.CodeAnalysis; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Diagnostics.CodeAnalysis; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// The Laplacian of Gaussian operator filter. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs index 1b2d5f50ed..0d2e9b2066 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Diagnostics.CodeAnalysis; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Diagnostics.CodeAnalysis; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// The Prewitt operator filter. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs index d1b9614b62..09aa8ecb6c 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Diagnostics.CodeAnalysis; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Diagnostics.CodeAnalysis; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// The Roberts Cross operator filter. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs index bc687f6743..18f8cbf18c 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Diagnostics.CodeAnalysis; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Diagnostics.CodeAnalysis; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// The Kirsch operator filter. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs index 339b9741fc..e299d3f807 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Diagnostics.CodeAnalysis; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Diagnostics.CodeAnalysis; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// The Scharr operator filter. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs index b9060ecbca..e975e4ff6c 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Diagnostics.CodeAnalysis; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +using System; +using System.Diagnostics.CodeAnalysis; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// The Sobel operator filter. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs index ef6ddaa6a7..583d38bf7f 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Applies a Gaussian blur sampler to the image. /// @@ -72,6 +69,11 @@ public GaussianBlurProcessor(float sigma, int radius) this.KernelY = this.CreateGaussianKernel(false); } + /// + /// Gets the sigma + /// + public float Sigma => this.sigma; + /// /// Gets the horizontal gradient operator. /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs index 594dda8cab..e22904ae1c 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Applies a Gaussian sharpening sampler to the image. /// @@ -74,6 +71,11 @@ public GaussianSharpenProcessor(float sigma, int radius) this.KernelY = this.CreateGaussianKernel(false); } + /// + /// Gets the sigma + /// + public float Sigma => this.sigma; + /// /// Gets the horizontal gradient operator. /// diff --git a/src/ImageSharp/Processing/Processors/DelegateProcessor.cs b/src/ImageSharp/Processing/Processors/DelegateProcessor.cs new file mode 100644 index 0000000000..e1bd8c5265 --- /dev/null +++ b/src/ImageSharp/Processing/Processors/DelegateProcessor.cs @@ -0,0 +1,45 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing +{ + /// + /// Allows the application of processors to images. + /// + /// The pixel format. + internal class DelegateProcessor : ImageProcessor + where TPixel : struct, IPixel + { + private readonly Action> action; + + /// + /// Initializes a new instance of the class. + /// + /// The action. + public DelegateProcessor(Action> action) + { + this.action = action; + } + + /// + /// Gets the action that will be applied to the image. + /// + internal Action> Action => this.action; + + /// + protected override void BeforeImageApply(Image source, Rectangle sourceRectangle) + { + this.action?.Invoke(source); + } + + /// + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + { + // NOP, we did all we wanted to do inside BeforeImageApply + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs index 0efca43b26..ce0998a3c1 100644 --- a/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// An to change the alpha component of an . /// diff --git a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs index 96fcf4d630..21cc22bc9c 100644 --- a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Threading.Tasks; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Sets the background color of the image. /// @@ -32,6 +29,11 @@ public BackgroundColorProcessor(TPixel color, GraphicsOptions options) this.options = options; } + /// + /// Gets the Graphics options to alter how processor is applied. + /// + public GraphicsOptions GraphicsOptions => this.options; + /// /// Gets the background color value. /// diff --git a/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs index 3fbe1742ed..096f6b7abd 100644 --- a/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// An to change the brightness of an . /// diff --git a/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs index e40f8d5de5..ba4c8b4dcb 100644 --- a/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// An to change the contrast of an . /// diff --git a/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs index 07a57db54a..683433e28e 100644 --- a/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// An to invert the colors of an . /// diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs index f484c8eec8..35b2bd2536 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs @@ -1,17 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// An to apply an oil painting effect to an . /// @@ -51,31 +49,27 @@ public OilPaintingProcessor(int levels, int brushSize) /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { + if (this.BrushSize <= 0 || this.BrushSize > source.Height || this.BrushSize > source.Width) + { + throw new ArgumentOutOfRangeException(nameof(this.BrushSize)); + } + int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; int startX = sourceRectangle.X; int endX = sourceRectangle.Right; + int maxY = endY - 1; + int maxX = endX - 1; + int radius = this.BrushSize >> 1; int levels = this.Levels; - // Align start/end positions. - int minX = Math.Max(0, startX); - int maxX = Math.Min(source.Width, endX); - int minY = Math.Max(0, startY); - int maxY = Math.Min(source.Height, endY); - - // Reset offset if necessary. - if (minX > 0) - { - startX = 0; - } - using (var targetPixels = new PixelAccessor(source.Width, source.Height)) { source.CopyTo(targetPixels); Parallel.For( - minY, + startY, maxY, this.ParallelOptions, y => diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs index ff83117c5f..7050e5eeb7 100644 --- a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Collections.Generic; - using System.Threading.Tasks; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// An to pixelate the colors of an . /// @@ -29,23 +26,28 @@ internal class PixelateProcessor : ImageProcessor public PixelateProcessor(int size) { Guard.MustBeGreaterThan(size, 0, nameof(size)); - this.Value = size; + this.Size = size; } /// /// Gets or the pixel size. /// - public int Value { get; } + public int Size { get; } /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { + if (this.Size <= 0 || this.Size > source.Height || this.Size > source.Width) + { + throw new ArgumentOutOfRangeException(nameof(this.Size)); + } + int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; int startX = sourceRectangle.X; int endX = sourceRectangle.Right; - int size = this.Value; - int offset = this.Value / 2; + int size = this.Size; + int offset = this.Size / 2; // Align start/end positions. int minX = Math.Max(0, startX); diff --git a/src/ImageSharp/Processing/ImageProcessor.cs b/src/ImageSharp/Processing/Processors/ImageProcessor.cs similarity index 52% rename from src/ImageSharp/Processing/ImageProcessor.cs rename to src/ImageSharp/Processing/Processors/ImageProcessor.cs index dd2a93bc52..84ad7f8993 100644 --- a/src/ImageSharp/Processing/ImageProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ImageProcessor.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing -{ - using System; - using System.Threading.Tasks; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Threading.Tasks; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing +{ /// /// Allows the application of processors to images. /// @@ -25,7 +22,7 @@ internal abstract class ImageProcessor : IImageProcessor public virtual bool Compand { get; set; } = false; /// - public void Apply(ImageBase source, Rectangle sourceRectangle) + public void Apply(Image source, Rectangle sourceRectangle) { if (this.ParallelOptions == null) { @@ -34,10 +31,50 @@ public void Apply(ImageBase source, Rectangle sourceRectangle) try { - this.BeforeApply(source, sourceRectangle); + this.BeforeImageApply(source, sourceRectangle); + this.BeforeApply(source, sourceRectangle); this.OnApply(source, sourceRectangle); + this.AfterApply(source, sourceRectangle); + + foreach (ImageFrame sourceFrame in source.Frames) + { + this.BeforeApply(sourceFrame, sourceRectangle); + + this.OnApply(sourceFrame, sourceRectangle); + this.AfterApply(sourceFrame, sourceRectangle); + } + + this.AfterImageApply(source, sourceRectangle); + } +#if DEBUG + catch (Exception) + { + throw; +#else + catch (Exception ex) + { + throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex); +#endif + } + } + /// + /// Applies the processor to just a single ImageBase + /// + /// the source image + /// the target + public void Apply(ImageBase source, Rectangle sourceRectangle) + { + if (this.ParallelOptions == null) + { + this.ParallelOptions = source.Configuration.ParallelOptions; + } + + try + { + this.BeforeApply(source, sourceRectangle); + this.OnApply(source, sourceRectangle); this.AfterApply(source, sourceRectangle); } #if DEBUG @@ -52,6 +89,17 @@ public void Apply(ImageBase source, Rectangle sourceRectangle) } } + /// + /// This method is called before the process is applied to prepare the processor. + /// + /// The source image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected virtual void BeforeImageApply(Image source, Rectangle sourceRectangle) + { + } + /// /// This method is called before the process is applied to prepare the processor. /// @@ -83,5 +131,16 @@ protected virtual void BeforeApply(ImageBase source, Rectangle sourceRec protected virtual void AfterApply(ImageBase source, Rectangle sourceRectangle) { } + + /// + /// This method is called after the process is applied to prepare the processor. + /// + /// The source image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected virtual void AfterImageApply(Image source, Rectangle sourceRectangle) + { + } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs index 8a13eabca8..99300eb964 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// An that applies a radial glow effect an . /// @@ -27,14 +24,21 @@ internal class GlowProcessor : ImageProcessor /// Initializes a new instance of the class. /// /// The color or the glow. + /// The radius of the glow. /// The options effecting blending and composition. - public GlowProcessor(TPixel color, GraphicsOptions options) + public GlowProcessor(TPixel color, ValueSize radius, GraphicsOptions options) { this.options = options; this.GlowColor = color; + this.Radius = radius; this.blender = PixelOperations.Instance.GetPixelBlender(this.options.BlenderMode); } + /// + /// Gets the Graphics options to alter how processor is applied. + /// + public GraphicsOptions GraphicsOptions => this.options; + /// /// Gets or sets the glow color to apply. /// @@ -43,7 +47,7 @@ public GlowProcessor(TPixel color, GraphicsOptions options) /// /// Gets or sets the the radius. /// - public float Radius { get; set; } + public ValueSize Radius { get; set; } /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) @@ -54,7 +58,10 @@ protected override void OnApply(ImageBase source, Rectangle sourceRectan int endX = sourceRectangle.Right; TPixel glowColor = this.GlowColor; Vector2 centre = Rectangle.Center(sourceRectangle); - float maxDistance = this.Radius > 0 ? MathF.Min(this.Radius, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; + + var finalRadius = this.Radius.Calculate(source.Size()); + + float maxDistance = finalRadius > 0 ? MathF.Min(finalRadius, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; // Align start/end positions. int minX = Math.Max(0, startX); diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs index 8cb58739b0..58e579509a 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// An that applies a radial vignette effect to an . /// @@ -27,15 +24,35 @@ internal class VignetteProcessor : ImageProcessor /// Initializes a new instance of the class. /// /// The color of the vignette. + /// The x-radius. + /// The y-radius. /// The options effecting blending and composition. - public VignetteProcessor(TPixel color, GraphicsOptions options) + public VignetteProcessor(TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) { this.VignetteColor = color; + this.RadiusX = radiusX; + this.RadiusY = radiusY; + this.options = options; + this.blender = PixelOperations.Instance.GetPixelBlender(this.options.BlenderMode); + } + /// + /// Initializes a new instance of the class. + /// + /// The color of the vignette. + /// The options effecting blending and composition. + public VignetteProcessor(TPixel color, GraphicsOptions options) + { + this.VignetteColor = color; this.options = options; this.blender = PixelOperations.Instance.GetPixelBlender(this.options.BlenderMode); } + /// + /// Gets the Graphics options to alter how processor is applied. + /// + public GraphicsOptions GraphicsOptions => this.options; + /// /// Gets or sets the vignette color to apply. /// @@ -44,12 +61,12 @@ public VignetteProcessor(TPixel color, GraphicsOptions options) /// /// Gets or sets the the x-radius. /// - public float RadiusX { get; set; } + public ValueSize RadiusX { get; set; } /// /// Gets or sets the the y-radius. /// - public float RadiusY { get; set; } + public ValueSize RadiusY { get; set; } /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) @@ -60,8 +77,11 @@ protected override void OnApply(ImageBase source, Rectangle sourceRectan int endX = sourceRectangle.Right; TPixel vignetteColor = this.VignetteColor; Vector2 centre = Rectangle.Center(sourceRectangle); - float rX = this.RadiusX > 0 ? MathF.Min(this.RadiusX, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; - float rY = this.RadiusY > 0 ? MathF.Min(this.RadiusY, sourceRectangle.Height * .5F) : sourceRectangle.Height * .5F; + + var finalradiusX = this.RadiusX.Calculate(source.Size()); + var finalradiusY = this.RadiusY.Calculate(source.Size()); + float rX = finalradiusX > 0 ? MathF.Min(finalradiusX, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; + float rY = finalradiusY > 0 ? MathF.Min(finalradiusY, sourceRectangle.Height * .5F) : sourceRectangle.Height * .5F; float maxDistance = MathF.Sqrt((rX * rX) + (rY * rY)); // Align start/end positions. diff --git a/src/ImageSharp/Processing/Processors/Transforms/AutoRotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/AutoRotateProcessor.cs new file mode 100644 index 0000000000..e568bdea83 --- /dev/null +++ b/src/ImageSharp/Processing/Processors/Transforms/AutoRotateProcessor.cs @@ -0,0 +1,109 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing.Processors +{ + /// + /// Adjusts an image so that its orientation is suitable for viewing. Adjustments are based on EXIF metadata embedded in the image. + /// + /// The pixel format. + internal class AutoRotateProcessor : ImageProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + public AutoRotateProcessor() + { + } + + /// + protected override void OnApply(ImageBase sourceBase, Rectangle sourceRectangle) + { + // can only apply to the origional image + var source = sourceBase as Image; + if (source != null) + { + Orientation orientation = GetExifOrientation(source); + + switch (orientation) + { + case Orientation.TopRight: + new FlipProcessor(FlipType.Horizontal).Apply(source, sourceRectangle); + break; + + case Orientation.BottomRight: + new RotateProcessor() { Angle = (int)RotateType.Rotate180, Expand = false }.Apply(source, sourceRectangle); + break; + + case Orientation.BottomLeft: + new FlipProcessor(FlipType.Vertical).Apply(source, sourceRectangle); + break; + + case Orientation.LeftTop: + new RotateProcessor() { Angle = (int)RotateType.Rotate90, Expand = false }.Apply(source, sourceRectangle); + new FlipProcessor(FlipType.Horizontal).Apply(source, sourceRectangle); + break; + + case Orientation.RightTop: + new RotateProcessor() { Angle = (int)RotateType.Rotate90, Expand = false }.Apply(source, sourceRectangle); + break; + + case Orientation.RightBottom: + new FlipProcessor(FlipType.Vertical).Apply(source, sourceRectangle); + new RotateProcessor() { Angle = (int)RotateType.Rotate270, Expand = false }.Apply(source, sourceRectangle); + break; + + case Orientation.LeftBottom: + new RotateProcessor() { Angle = (int)RotateType.Rotate270, Expand = false }.Apply(source, sourceRectangle); + break; + + case Orientation.Unknown: + case Orientation.TopLeft: + default: + break; + } + } + } + + /// + /// Returns the current EXIF orientation + /// + /// The image to auto rotate. + /// The + private static Orientation GetExifOrientation(Image source) + { + if (source.MetaData.ExifProfile == null) + { + return Orientation.Unknown; + } + + ExifValue value = source.MetaData.ExifProfile.GetValue(ExifTag.Orientation); + if (value == null) + { + return Orientation.Unknown; + } + + Orientation orientation; + if (value.DataType == ExifDataType.Short) + { + orientation = (Orientation)value.Value; + } + else + { + orientation = (Orientation)Convert.ToUInt16(value.Value); + source.MetaData.ExifProfile.RemoveValue(ExifTag.Orientation); + } + + source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)Orientation.TopLeft); + + return orientation; + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs index 37f8867755..d68c289db1 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Threading.Tasks; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Provides methods to allow the cropping of an image. /// diff --git a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs index 16f74f218b..89e22a7e6b 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Provides methods to allow the cropping of an image to preserve areas of highest /// entropy. @@ -28,24 +25,24 @@ internal class EntropyCropProcessor : ImageProcessor public EntropyCropProcessor(float threshold) { Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold)); - this.Value = threshold; + this.Threshold = threshold; } /// /// Gets the threshold value. /// - public float Value { get; } + public float Threshold { get; } /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - using (ImageBase temp = new Image(source)) + using (ImageBase temp = source.Clone()) { // Detect the edges. new SobelProcessor().Apply(temp, sourceRectangle); // Apply threshold binarization filter. - new BinaryThresholdProcessor(this.Value).Apply(temp, sourceRectangle); + new BinaryThresholdProcessor(this.Threshold).Apply(temp, sourceRectangle); // Search for the first white pixels Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0); diff --git a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs index cba60f928e..f0173a6666 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Threading.Tasks; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Provides methods that allow the flipping of an image around its center point. /// diff --git a/src/ImageSharp/Processing/Processors/Transforms/Matrix3x2Processor.cs b/src/ImageSharp/Processing/Processors/Transforms/Matrix3x2Processor.cs index d1a35659b3..54724ee782 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Matrix3x2Processor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Matrix3x2Processor.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System.Numerics; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Provides methods to transform an image using a . /// diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs index 8aef87ec85..1169d2eadc 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; - - using ImageSharp.Memory; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Memory; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Conains the definition of and . /// diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs index 0186a8fa8e..8d5eeded15 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs @@ -1,22 +1,19 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Runtime.CompilerServices; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Provides methods that allow the resizing of images using various algorithms. /// Adapted from /// /// The pixel format. - internal abstract partial class ResamplingWeightedProcessor : ImageProcessor + internal abstract partial class ResamplingWeightedProcessor : CloningImageProcessor where TPixel : struct, IPixel { /// @@ -46,19 +43,19 @@ protected ResamplingWeightedProcessor(IResampler sampler, int width, int height, public IResampler Sampler { get; } /// - /// Gets the width. + /// Gets or sets the width. /// - public int Width { get; } + public int Width { get; protected set; } /// - /// Gets the height. + /// Gets or sets the height. /// - public int Height { get; } + public int Height { get; protected set; } /// - /// Gets the resize rectangle. + /// Gets or sets the resize rectangle. /// - public Rectangle ResizeRectangle { get; } + public Rectangle ResizeRectangle { get; protected set; } /// /// Gets or sets the horizontal weights. @@ -140,7 +137,7 @@ internal unsafe WeightsBuffer PrecomputeWeights(int destinationSize, int sourceS } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, ImageBase destination, Rectangle sourceRectangle) { if (!(this.Sampler is NearestNeighborResampler)) { @@ -155,9 +152,9 @@ protected override void BeforeApply(ImageBase source, Rectangle sourceRe } /// - protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) + protected override void AfterApply(ImageBase source, ImageBase destination, Rectangle sourceRectangle) { - base.AfterApply(source, sourceRectangle); + base.AfterApply(source, destination, sourceRectangle); this.HorizontalWeights?.Dispose(); this.HorizontalWeights = null; this.VerticalWeights?.Dispose(); diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs index be1680cf1c..592e8d2e34 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Provides methods that allow the resizing of images using various algorithms. /// @@ -46,11 +43,32 @@ public ResizeProcessor(IResampler sampler, int width, int height, Rectangle resi } /// - protected override unsafe void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override Image CreateDestination(Image source, Rectangle sourceRectangle) + { + // We will always be creating the clone even for mutate because thats the way this base processor works + // ------------ + // For resize we know we are going to populate every pixel with fresh data and we want a different target size so + // let's manually clone an empty set of images at the correct target and then have the base class processs them in turn. + var image = new Image(source.Configuration, this.Width, this.Height, source.MetaData.Clone()); + + // Now 'clone' the ImageFrames + foreach (ImageFrame sourceFrame in source.Frames) + { + var targetFrame = new ImageFrame(sourceFrame.Configuration, this.Width, this.Height, sourceFrame.MetaData.Clone()); + image.Frames.Add(targetFrame); + } + + return image; + } + + /// + protected override unsafe void OnApply(ImageBase source, ImageBase cloned, Rectangle sourceRectangle) { // Jump out, we'll deal with that later. - if (source.Width == this.Width && source.Height == this.Height && sourceRectangle == this.ResizeRectangle) + if (source.Width == cloned.Width && source.Height == cloned.Height && sourceRectangle == this.ResizeRectangle) { + // the cloned will be blank here copy all the pixel data over + source.Pixels.CopyTo(cloned.Pixels); return; } @@ -74,113 +92,102 @@ protected override unsafe void OnApply(ImageBase source, Rectangle sourc float widthFactor = sourceRectangle.Width / (float)this.ResizeRectangle.Width; float heightFactor = sourceRectangle.Height / (float)this.ResizeRectangle.Height; - using (var targetPixels = new PixelAccessor(width, height)) - { - Parallel.For( - minY, - maxY, - this.ParallelOptions, - y => + Parallel.For( + minY, + maxY, + this.ParallelOptions, + y => + { + // Y coordinates of source points + Span sourceRow = source.GetRowSpan((int)(((y - startY) * heightFactor) + sourceY)); + Span targetRow = cloned.GetRowSpan(y); + + for (int x = minX; x < maxX; x++) { - // Y coordinates of source points - Span sourceRow = source.GetRowSpan((int)(((y - startY) * heightFactor) + sourceY)); - Span targetRow = targetPixels.GetRowSpan(y); - - for (int x = minX; x < maxX; x++) - { - // X coordinates of source points - targetRow[x] = sourceRow[(int)(((x - startX) * widthFactor) + sourceX)]; - } - }); + // X coordinates of source points + targetRow[x] = sourceRow[(int)(((x - startX) * widthFactor) + sourceX)]; + } + }); - // Break out now. - source.SwapPixelsBuffers(targetPixels); - return; - } + return; } // Interpolate the image using the calculated weights. // A 2-pass 1D algorithm appears to be faster than splitting a 1-pass 2D algorithm // First process the columns. Since we are not using multiple threads startY and endY // are the upper and lower bounds of the source rectangle. - // TODO: Using a transposed variant of 'firstPassPixels' could eliminate the need for the WeightsWindow.ComputeWeightedColumnSum() method, and improve speed! - using (var targetPixels = new PixelAccessor(width, height)) + using (var firstPassPixels = new Buffer2D(width, source.Height)) { - using (var firstPassPixels = new Buffer2D(width, source.Height)) - { - firstPassPixels.Clear(); - - Parallel.For( - 0, - sourceRectangle.Bottom, - this.ParallelOptions, - y => + firstPassPixels.Clear(); + + Parallel.For( + 0, + sourceRectangle.Bottom, + this.ParallelOptions, + y => + { + // TODO: Without Parallel.For() this buffer object could be reused: + using (var tempRowBuffer = new Buffer(source.Width)) { - // TODO: Without Parallel.For() this buffer object could be reused: - using (var tempRowBuffer = new Buffer(source.Width)) - { - Span firstPassRow = firstPassPixels.GetRowSpan(y); - Span sourceRow = source.GetRowSpan(y); - PixelOperations.Instance.ToVector4(sourceRow, tempRowBuffer, sourceRow.Length); + Span firstPassRow = firstPassPixels.GetRowSpan(y); + Span sourceRow = source.GetRowSpan(y); + PixelOperations.Instance.ToVector4(sourceRow, tempRowBuffer, sourceRow.Length); - if (this.Compand) + if (this.Compand) + { + for (int x = minX; x < maxX; x++) { - for (int x = minX; x < maxX; x++) - { - WeightsWindow window = this.HorizontalWeights.Weights[x - startX]; - firstPassRow[x] = window.ComputeExpandedWeightedRowSum(tempRowBuffer, sourceX); - } + WeightsWindow window = this.HorizontalWeights.Weights[x - startX]; + firstPassRow[x] = window.ComputeExpandedWeightedRowSum(tempRowBuffer, sourceX); } - else + } + else + { + for (int x = minX; x < maxX; x++) { - for (int x = minX; x < maxX; x++) - { - WeightsWindow window = this.HorizontalWeights.Weights[x - startX]; - firstPassRow[x] = window.ComputeWeightedRowSum(tempRowBuffer, sourceX); - } + WeightsWindow window = this.HorizontalWeights.Weights[x - startX]; + firstPassRow[x] = window.ComputeWeightedRowSum(tempRowBuffer, sourceX); } } - }); - - // Now process the rows. - Parallel.For( - minY, - maxY, - this.ParallelOptions, - y => - { - // Ensure offsets are normalised for cropping and padding. - WeightsWindow window = this.VerticalWeights.Weights[y - startY]; - Span targetRow = targetPixels.GetRowSpan(y); + } + }); - if (this.Compand) + // Now process the rows. + Parallel.For( + minY, + maxY, + this.ParallelOptions, + y => + { + // Ensure offsets are normalised for cropping and padding. + WeightsWindow window = this.VerticalWeights.Weights[y - startY]; + Span targetRow = cloned.GetRowSpan(y); + + if (this.Compand) + { + for (int x = 0; x < width; x++) { - for (int x = 0; x < width; x++) - { - // Destination color components - Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); - destination = destination.Compress(); + // Destination color components + Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); + destination = destination.Compress(); - ref TPixel pixel = ref targetRow[x]; - pixel.PackFromVector4(destination); - } + ref TPixel pixel = ref targetRow[x]; + pixel.PackFromVector4(destination); } - else + } + else + { + for (int x = 0; x < width; x++) { - for (int x = 0; x < width; x++) - { - // Destination color components - Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); + // Destination color components + Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); - ref TPixel pixel = ref targetRow[x]; - pixel.PackFromVector4(destination); - } + ref TPixel pixel = ref targetRow[x]; + pixel.PackFromVector4(destination); } - }); - } - - source.SwapPixelsBuffers(targetPixels); + } + }); } } } diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs index d563d072aa..b8341d4027 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs @@ -1,17 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Provides methods that allow the rotating of images. /// @@ -45,6 +43,7 @@ protected override void OnApply(ImageBase source, Rectangle sourceRectan int height = this.CanvasRectangle.Height; int width = this.CanvasRectangle.Width; Matrix3x2 matrix = this.GetCenteredMatrix(source, this.processMatrix); + Rectangle sourceBounds = source.Bounds(); using (var targetPixels = new PixelAccessor(width, height)) { @@ -60,7 +59,7 @@ protected override void OnApply(ImageBase source, Rectangle sourceRectan { var transformedPoint = Point.Rotate(new Point(x, y), matrix); - if (source.Bounds.Contains(transformedPoint.X, transformedPoint.Y)) + if (sourceBounds.Contains(transformedPoint.X, transformedPoint.Y)) { targetRow[x] = source[transformedPoint.X, transformedPoint.Y]; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs index 9766caa696..bd84e483f5 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs @@ -1,17 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing.Processors -{ - using System; - using System.Numerics; - using System.Threading.Tasks; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing.Processors +{ /// /// Provides methods that allow the skewing of images. /// @@ -45,6 +43,7 @@ protected override void OnApply(ImageBase source, Rectangle sourceRectan int height = this.CanvasRectangle.Height; int width = this.CanvasRectangle.Width; Matrix3x2 matrix = this.GetCenteredMatrix(source, this.processMatrix); + Rectangle sourceBounds = source.Bounds(); using (var targetPixels = new PixelAccessor(width, height)) { @@ -60,7 +59,7 @@ protected override void OnApply(ImageBase source, Rectangle sourceRectan { var transformedPoint = Point.Skew(new Point(x, y), matrix); - if (source.Bounds.Contains(transformedPoint.X, transformedPoint.Y)) + if (sourceBounds.Contains(transformedPoint.X, transformedPoint.Y)) { targetRow[x] = source[transformedPoint.X, transformedPoint.Y]; } @@ -74,7 +73,7 @@ protected override void OnApply(ImageBase source, Rectangle sourceRectan /// protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { - this.processMatrix = Matrix3x2Extensions.CreateSkew(-this.AngleX, -this.AngleY, new Point(0, 0)); + this.processMatrix = Matrix3x2Extensions.CreateSkewDegrees(-this.AngleX, -this.AngleY, new Point(0, 0)); if (this.Expand) { this.CreateNewCanvas(sourceRectangle, this.processMatrix); diff --git a/src/ImageSharp/Processing/Transforms/AutoOrient.cs b/src/ImageSharp/Processing/Transforms/AutoOrient.cs index 7e7c66460c..186c3b2236 100644 --- a/src/ImageSharp/Processing/Transforms/AutoOrient.cs +++ b/src/ImageSharp/Processing/Transforms/AutoOrient.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -21,77 +18,8 @@ public static partial class ImageExtensions /// The pixel format. /// The image to auto rotate. /// The - public static Image AutoOrient(this Image source) + public static IImageProcessingContext AutoOrient(this IImageProcessingContext source) where TPixel : struct, IPixel - { - Orientation orientation = GetExifOrientation(source); - - switch (orientation) - { - case Orientation.TopRight: - return source.Flip(FlipType.Horizontal); - - case Orientation.BottomRight: - return source.Rotate(RotateType.Rotate180); - - case Orientation.BottomLeft: - return source.Flip(FlipType.Vertical); - - case Orientation.LeftTop: - return source.Rotate(RotateType.Rotate90) - .Flip(FlipType.Horizontal); - - case Orientation.RightTop: - return source.Rotate(RotateType.Rotate90); - - case Orientation.RightBottom: - return source.Flip(FlipType.Vertical) - .Rotate(RotateType.Rotate270); - - case Orientation.LeftBottom: - return source.Rotate(RotateType.Rotate270); - - case Orientation.Unknown: - case Orientation.TopLeft: - default: - return source; - } - } - - /// - /// Returns the current EXIF orientation - /// - /// The pixel format. - /// The image to auto rotate. - /// The - private static Orientation GetExifOrientation(Image source) - where TPixel : struct, IPixel - { - if (source.MetaData.ExifProfile == null) - { - return Orientation.Unknown; - } - - ExifValue value = source.MetaData.ExifProfile.GetValue(ExifTag.Orientation); - if (value == null) - { - return Orientation.Unknown; - } - - Orientation orientation; - if (value.DataType == ExifDataType.Short) - { - orientation = (Orientation)value.Value; - } - else - { - orientation = (Orientation)Convert.ToUInt16(value.Value); - source.MetaData.ExifProfile.RemoveValue(ExifTag.Orientation); - } - - source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)Orientation.TopLeft); - - return orientation; - } + => source.ApplyProcessor(new Processing.Processors.AutoRotateProcessor()); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Crop.cs b/src/ImageSharp/Processing/Transforms/Crop.cs index 94e9ba1f49..3fa59c2483 100644 --- a/src/ImageSharp/Processing/Transforms/Crop.cs +++ b/src/ImageSharp/Processing/Transforms/Crop.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -25,11 +21,9 @@ public static partial class ImageExtensions /// The target image width. /// The target image height. /// The - public static Image Crop(this Image source, int width, int height) + public static IImageProcessingContext Crop(this IImageProcessingContext source, int width, int height) where TPixel : struct, IPixel - { - return Crop(source, new Rectangle(0, 0, width, height)); - } + => Crop(source, new Rectangle(0, 0, width, height)); /// /// Crops an image to the given rectangle. @@ -40,13 +34,8 @@ public static Image Crop(this Image source, int width, i /// The structure that specifies the portion of the image object to retain. /// /// The - public static Image Crop(this Image source, Rectangle cropRectangle) + public static IImageProcessingContext Crop(this IImageProcessingContext source, Rectangle cropRectangle) where TPixel : struct, IPixel - { - CropProcessor processor = new CropProcessor(cropRectangle); - - source.ApplyProcessor(processor, source.Bounds); - return source; - } + => source.ApplyProcessor(new CropProcessor(cropRectangle)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs index 2f4a8e3833..cbd2b46599 100644 --- a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs +++ b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs @@ -1,16 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using Processing.Processors; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -23,13 +19,8 @@ public static partial class ImageExtensions /// The image to crop. /// The threshold for entropic density. /// The - public static Image EntropyCrop(this Image source, float threshold = .5f) + public static IImageProcessingContext EntropyCrop(this IImageProcessingContext source, float threshold = .5f) where TPixel : struct, IPixel - { - EntropyCropProcessor processor = new EntropyCropProcessor(threshold); - - source.ApplyProcessor(processor, source.Bounds); - return source; - } + => source.ApplyProcessor(new EntropyCropProcessor(threshold)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Flip.cs b/src/ImageSharp/Processing/Transforms/Flip.cs index 1c8baebf13..e153e89f28 100644 --- a/src/ImageSharp/Processing/Transforms/Flip.cs +++ b/src/ImageSharp/Processing/Transforms/Flip.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,13 +20,8 @@ public static partial class ImageExtensions /// The image to rotate, flip, or both. /// The to perform the flip. /// The - public static Image Flip(this Image source, FlipType flipType) + public static IImageProcessingContext Flip(this IImageProcessingContext source, FlipType flipType) where TPixel : struct, IPixel - { - FlipProcessor processor = new FlipProcessor(flipType); - - source.ApplyProcessor(processor, source.Bounds); - return source; - } + => source.ApplyProcessor(new FlipProcessor(flipType)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Options/AnchorPosition.cs b/src/ImageSharp/Processing/Transforms/Options/AnchorPosition.cs index 67010a777f..263af14ccd 100644 --- a/src/ImageSharp/Processing/Transforms/Options/AnchorPosition.cs +++ b/src/ImageSharp/Processing/Transforms/Options/AnchorPosition.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// Enumerated anchor positions to apply to resized images. diff --git a/src/ImageSharp/Processing/Transforms/Options/FlipType.cs b/src/ImageSharp/Processing/Transforms/Options/FlipType.cs index 3c66da697f..0129891f66 100644 --- a/src/ImageSharp/Processing/Transforms/Options/FlipType.cs +++ b/src/ImageSharp/Processing/Transforms/Options/FlipType.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// Provides enumeration over how a image should be flipped. diff --git a/src/ImageSharp/Processing/Transforms/Options/Orientation.cs b/src/ImageSharp/Processing/Transforms/Options/Orientation.cs index b8147348f7..9c8d96a71c 100644 --- a/src/ImageSharp/Processing/Transforms/Options/Orientation.cs +++ b/src/ImageSharp/Processing/Transforms/Options/Orientation.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// Enumerates the available orientation values supplied by EXIF metadata. diff --git a/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs b/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs index 7eae89eac0..90f50ec3dc 100644 --- a/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs +++ b/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing -{ - using System.Linq; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; +using System.Linq; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing +{ /// /// Provides methods to help calculate the target rectangle when resizing using the /// enumeration. diff --git a/src/ImageSharp/Processing/Transforms/Options/ResizeMode.cs b/src/ImageSharp/Processing/Transforms/Options/ResizeMode.cs index dc6092de84..c88808f758 100644 --- a/src/ImageSharp/Processing/Transforms/Options/ResizeMode.cs +++ b/src/ImageSharp/Processing/Transforms/Options/ResizeMode.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// Enumerated resize modes to apply to resized images. diff --git a/src/ImageSharp/Processing/Transforms/Options/ResizeOptions.cs b/src/ImageSharp/Processing/Transforms/Options/ResizeOptions.cs index 2ca2b1c39d..8f2d3db0a9 100644 --- a/src/ImageSharp/Processing/Transforms/Options/ResizeOptions.cs +++ b/src/ImageSharp/Processing/Transforms/Options/ResizeOptions.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing -{ - using System.Collections.Generic; - using System.Linq; - using SixLabors.Primitives; +using System.Collections.Generic; +using System.Linq; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Processing +{ /// /// The resize options for resizing images against certain modes. /// diff --git a/src/ImageSharp/Processing/Transforms/Options/RotateType.cs b/src/ImageSharp/Processing/Transforms/Options/RotateType.cs index 9f09cec280..9f6d45f2bf 100644 --- a/src/ImageSharp/Processing/Transforms/Options/RotateType.cs +++ b/src/ImageSharp/Processing/Transforms/Options/RotateType.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// Provides enumeration over how the image should be rotated. diff --git a/src/ImageSharp/Processing/Transforms/Pad.cs b/src/ImageSharp/Processing/Transforms/Pad.cs index 8138fd7654..eb0f2e9c27 100644 --- a/src/ImageSharp/Processing/Transforms/Pad.cs +++ b/src/ImageSharp/Processing/Transforms/Pad.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -26,7 +22,7 @@ public static partial class ImageExtensions /// The new width. /// The new height. /// The . - public static Image Pad(this Image source, int width, int height) + public static IImageProcessingContext Pad(this IImageProcessingContext source, int width, int height) where TPixel : struct, IPixel { ResizeOptions options = new ResizeOptions diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/BicubicResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/BicubicResampler.cs index e40bf59f92..be9de9edaa 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/BicubicResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/BicubicResampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The function implements the bicubic kernel algorithm W(x) as described on diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/BoxResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/BoxResampler.cs index f174ef48bd..5aab0d07fa 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/BoxResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/BoxResampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The function implements the box algorithm. Similar to nearest neighbor when upscaling. diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/CatmullRomResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/CatmullRomResampler.cs index 0725ecb537..1c84676188 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/CatmullRomResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/CatmullRomResampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The Catmull-Rom filter is a well known standard Cubic Filter often used as a interpolation function. diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/HermiteResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/HermiteResampler.cs index 66cc36a21f..33435059f1 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/HermiteResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/HermiteResampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The Hermite filter is type of smoothed triangular interpolation Filter, diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/IResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/IResampler.cs index 6339d9d8ea..9a128a05be 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/IResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/IResampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// Encapsulates an interpolation algorithm for resampling images. diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs index a46f38df42..deaa0ccb95 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The function implements the Lanczos kernel algorithm as described on diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs index 3ad01b2b7b..2673c34914 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The function implements the Lanczos kernel algorithm as described on diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs index 9bb8bdd16f..c52670e2d0 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The function implements the Lanczos kernel algorithm as described on diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs index af8c2c111c..552d3065b4 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The function implements the Lanczos kernel algorithm as described on diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/MitchellNetravaliResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/MitchellNetravaliResampler.cs index 38ca614c4a..df351d9505 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/MitchellNetravaliResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/MitchellNetravaliResampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The function implements the mitchell algorithm as described on diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/NearestNeighborResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/NearestNeighborResampler.cs index f1e5ab8fdb..7a7785be36 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/NearestNeighborResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/NearestNeighborResampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The function implements the nearest neighbor algorithm. This uses an unscaled filter diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxResampler.cs index 1b060e6e3f..bd28d8da46 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxResampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The function implements the Robidoux algorithm. diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxSharpResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxSharpResampler.cs index 86c7b0517c..a345da3f42 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxSharpResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxSharpResampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The function implements the Robidoux Sharp algorithm. diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/SplineResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/SplineResampler.cs index abd5b835c6..ac5e2dedba 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/SplineResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/SplineResampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The function implements the spline algorithm. diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/TriangleResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/TriangleResampler.cs index bf88b65df8..842da87e06 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/TriangleResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/TriangleResampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The function implements the triangle (bilinear) algorithm. diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs index 33a2cc825e..e154d5483b 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing { /// /// The function implements the welch algorithm. diff --git a/src/ImageSharp/Processing/Transforms/Resize.cs b/src/ImageSharp/Processing/Transforms/Resize.cs index e00faf10ea..dc23eb4fba 100644 --- a/src/ImageSharp/Processing/Transforms/Resize.cs +++ b/src/ImageSharp/Processing/Transforms/Resize.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; - using SixLabors.Primitives; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,23 +21,27 @@ public static partial class ImageExtensions /// The resize options. /// The /// Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, ResizeOptions options) + public static IImageProcessingContext Resize(this IImageProcessingContext source, ResizeOptions options) where TPixel : struct, IPixel { - // Ensure size is populated across both dimensions. - if (options.Size.Width == 0 && options.Size.Height > 0) + return source.Apply(img => { - options.Size = new Size((int)MathF.Round(source.Width * options.Size.Height / (float)source.Height), options.Size.Height); - } - - if (options.Size.Height == 0 && options.Size.Width > 0) - { - options.Size = new Size(options.Size.Width, (int)MathF.Round(source.Height * options.Size.Width / (float)source.Width)); - } - - Rectangle targetRectangle = ResizeHelper.CalculateTargetLocationAndBounds(source, options); - - return Resize(source, options.Size.Width, options.Size.Height, options.Sampler, source.Bounds, targetRectangle, options.Compand); + // Cheat and bound through a run, inside here we should just be mutating, this really needs moving over to a processor + // Ensure size is populated across both dimensions. + if (options.Size.Width == 0 && options.Size.Height > 0) + { + options.Size = new Size((int)MathF.Round(img.Width * options.Size.Height / (float)img.Height), options.Size.Height); + } + + if (options.Size.Height == 0 && options.Size.Width > 0) + { + options.Size = new Size(options.Size.Width, (int)MathF.Round(img.Height * options.Size.Width / (float)img.Width)); + } + + Rectangle targetRectangle = ResizeHelper.CalculateTargetLocationAndBounds(img, options); + + img.Mutate(x => Resize(x, options.Size.Width, options.Size.Height, options.Sampler, targetRectangle, options.Compand)); + }); } /// @@ -51,7 +52,7 @@ public static Image Resize(this Image source, ResizeOpti /// The target image size. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, Size size) + public static IImageProcessingContext Resize(this IImageProcessingContext source, Size size) where TPixel : struct, IPixel { return Resize(source, size.Width, size.Height, new BicubicResampler(), false); @@ -66,7 +67,7 @@ public static Image Resize(this Image source, Size size) /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, Size size, bool compand) + public static IImageProcessingContext Resize(this IImageProcessingContext source, Size size, bool compand) where TPixel : struct, IPixel { return Resize(source, size.Width, size.Height, new BicubicResampler(), compand); @@ -81,7 +82,7 @@ public static Image Resize(this Image source, Size size, /// The target image height. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height) + public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height) where TPixel : struct, IPixel { return Resize(source, width, height, new BicubicResampler(), false); @@ -97,7 +98,7 @@ public static Image Resize(this Image source, int width, /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, bool compand) + public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, bool compand) where TPixel : struct, IPixel { return Resize(source, width, height, new BicubicResampler(), compand); @@ -113,12 +114,28 @@ public static Image Resize(this Image source, int width, /// The to perform the resampling. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, IResampler sampler) + public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, IResampler sampler) where TPixel : struct, IPixel { return Resize(source, width, height, sampler, false); } + /// + /// Resizes an image to the given width and height with the given sampler. + /// + /// The pixel format. + /// The image to resize. + /// The target image size. + /// The to perform the resampling. + /// Whether to compress and expand the image color-space to gamma correct the image during processing. + /// The + /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image + public static IImageProcessingContext Resize(this IImageProcessingContext source, Size size, IResampler sampler, bool compand) + where TPixel : struct, IPixel + { + return Resize(source, size.Width, size.Height, sampler, new Rectangle(0, 0, size.Width, size.Height), compand); + } + /// /// Resizes an image to the given width and height with the given sampler. /// @@ -130,10 +147,10 @@ public static Image Resize(this Image source, int width, /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, IResampler sampler, bool compand) + public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, IResampler sampler, bool compand) where TPixel : struct, IPixel { - return Resize(source, width, height, sampler, source.Bounds, new Rectangle(0, 0, width, height), compand); + return Resize(source, width, height, sampler, new Rectangle(0, 0, width, height), compand); } /// @@ -154,28 +171,69 @@ public static Image Resize(this Image source, int width, /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand) + public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel { - if (width == 0 && height > 0) + return source.Apply(img => { - width = (int)MathF.Round(source.Width * height / (float)source.Height); - targetRectangle.Width = width; - } + // TODO : Stop cheating here and move this stuff into the processors itself + if (width == 0 && height > 0) + { + width = (int)MathF.Round(img.Width * height / (float)img.Height); + targetRectangle.Width = width; + } + + if (height == 0 && width > 0) + { + height = (int)MathF.Round(img.Height * width / (float)img.Width); + targetRectangle.Height = height; + } + + Guard.MustBeGreaterThan(width, 0, nameof(width)); + Guard.MustBeGreaterThan(height, 0, nameof(height)); + + img.Mutate(x => x.ApplyProcessor(new ResizeProcessor(sampler, width, height, targetRectangle) { Compand = compand }, sourceRectangle)); + }); + } - if (height == 0 && width > 0) + /// + /// Resizes an image to the given width and height with the given sampler and + /// source rectangle. + /// + /// The pixel format. + /// The image to resize. + /// The target image width. + /// The target image height. + /// The to perform the resampling. + /// + /// The structure that specifies the portion of the target image object to draw to. + /// + /// Whether to compress and expand the image color-space to gamma correct the image during processing. + /// The + /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image + public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, IResampler sampler, Rectangle targetRectangle, bool compand) + where TPixel : struct, IPixel + { + return source.Apply(img => { - height = (int)MathF.Round(source.Height * width / (float)source.Width); - targetRectangle.Height = height; - } - - Guard.MustBeGreaterThan(width, 0, nameof(width)); - Guard.MustBeGreaterThan(height, 0, nameof(height)); - - var processor = new ResizeProcessor(sampler, width, height, targetRectangle) { Compand = compand }; - - source.ApplyProcessor(processor, sourceRectangle); - return source; + // TODO : stop cheating here and move this stuff into the processors itself + if (width == 0 && height > 0) + { + width = (int)MathF.Round(img.Width * height / (float)img.Height); + targetRectangle.Width = width; + } + + if (height == 0 && width > 0) + { + height = (int)MathF.Round(img.Height * width / (float)img.Width); + targetRectangle.Height = height; + } + + Guard.MustBeGreaterThan(width, 0, nameof(width)); + Guard.MustBeGreaterThan(height, 0, nameof(height)); + + img.Mutate(x => x.ApplyProcessor(new ResizeProcessor(sampler, width, height, targetRectangle) { Compand = compand })); + }); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Rotate.cs b/src/ImageSharp/Processing/Transforms/Rotate.cs index af7c06a27e..7b35a879bc 100644 --- a/src/ImageSharp/Processing/Transforms/Rotate.cs +++ b/src/ImageSharp/Processing/Transforms/Rotate.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - using Processing.Processors; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,7 +20,7 @@ public static partial class ImageExtensions /// The image to rotate. /// The angle in degrees to perform the rotation. /// The - public static Image Rotate(this Image source, float degrees) + public static IImageProcessingContext Rotate(this IImageProcessingContext source, float degrees) where TPixel : struct, IPixel { return Rotate(source, degrees, true); @@ -37,11 +33,9 @@ public static Image Rotate(this Image source, float degr /// The image to rotate. /// The to perform the rotation. /// The - public static Image Rotate(this Image source, RotateType rotateType) + public static IImageProcessingContext Rotate(this IImageProcessingContext source, RotateType rotateType) where TPixel : struct, IPixel - { - return Rotate(source, (float)rotateType, false); - } + => Rotate(source, (float)rotateType, false); /// /// Rotates an image by the given angle in degrees. @@ -51,13 +45,8 @@ public static Image Rotate(this Image source, RotateType /// The angle in degrees to perform the rotation. /// Whether to expand the image to fit the rotated result. /// The - public static Image Rotate(this Image source, float degrees, bool expand) + public static IImageProcessingContext Rotate(this IImageProcessingContext source, float degrees, bool expand) where TPixel : struct, IPixel - { - RotateProcessor processor = new RotateProcessor { Angle = degrees, Expand = expand }; - - source.ApplyProcessor(processor, source.Bounds); - return source; - } + => source.ApplyProcessor(new RotateProcessor { Angle = degrees, Expand = expand }); } } diff --git a/src/ImageSharp/Processing/Transforms/RotateFlip.cs b/src/ImageSharp/Processing/Transforms/RotateFlip.cs index 805deb8d16..2ddcb151b2 100644 --- a/src/ImageSharp/Processing/Transforms/RotateFlip.cs +++ b/src/ImageSharp/Processing/Transforms/RotateFlip.cs @@ -1,16 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,7 +20,7 @@ public static partial class ImageExtensions /// The to perform the rotation. /// The to perform the flip. /// The - public static Image RotateFlip(this Image source, RotateType rotateType, FlipType flipType) + public static IImageProcessingContext RotateFlip(this IImageProcessingContext source, RotateType rotateType, FlipType flipType) where TPixel : struct, IPixel { return source.Rotate(rotateType).Flip(flipType); diff --git a/src/ImageSharp/Processing/Transforms/Skew.cs b/src/ImageSharp/Processing/Transforms/Skew.cs index d42d79225b..00411946d9 100644 --- a/src/ImageSharp/Processing/Transforms/Skew.cs +++ b/src/ImageSharp/Processing/Transforms/Skew.cs @@ -1,16 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - - using ImageSharp.PixelFormats; - - using Processing.Processors; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,7 +20,7 @@ public static partial class ImageExtensions /// The angle in degrees to perform the rotation along the x-axis. /// The angle in degrees to perform the rotation along the y-axis. /// The - public static Image Skew(this Image source, float degreesX, float degreesY) + public static IImageProcessingContext Skew(this IImageProcessingContext source, float degreesX, float degreesY) where TPixel : struct, IPixel { return Skew(source, degreesX, degreesY, true); @@ -39,13 +35,8 @@ public static Image Skew(this Image source, float degree /// The angle in degrees to perform the rotation along the y-axis. /// Whether to expand the image to fit the skewed result. /// The - public static Image Skew(this Image source, float degreesX, float degreesY, bool expand) + public static IImageProcessingContext Skew(this IImageProcessingContext source, float degreesX, float degreesY, bool expand) where TPixel : struct, IPixel - { - SkewProcessor processor = new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Expand = expand }; - - source.ApplyProcessor(processor, source.Bounds); - return source; - } + => source.ApplyProcessor(new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Expand = expand }); } } diff --git a/src/ImageSharp/Properties/AssemblyInfo.cs b/src/ImageSharp/Properties/AssemblyInfo.cs index e791dff5a5..7b8f933b0c 100644 --- a/src/ImageSharp/Properties/AssemblyInfo.cs +++ b/src/ImageSharp/Properties/AssemblyInfo.cs @@ -1,8 +1,6 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// using System.Runtime.CompilerServices; // Ensure the other projects can see the internal helpers -[assembly: InternalsVisibleTo("ImageSharp.Drawing")] \ No newline at end of file +[assembly: InternalsVisibleTo("SixLabors.ImageSharp.Drawing")] \ No newline at end of file diff --git a/src/ImageSharp/Quantizers/Box.cs b/src/ImageSharp/Quantizers/Box.cs index 7f2a320873..4a1e17753f 100644 --- a/src/ImageSharp/Quantizers/Box.cs +++ b/src/ImageSharp/Quantizers/Box.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Quantizers +namespace SixLabors.ImageSharp.Quantizers { /// /// Represents a box color cube. diff --git a/src/ImageSharp/Quantizers/IQuantizer{TPixel}.cs b/src/ImageSharp/Quantizers/IQuantizer{TPixel}.cs index b7cf2d469a..1e992c894d 100644 --- a/src/ImageSharp/Quantizers/IQuantizer{TPixel}.cs +++ b/src/ImageSharp/Quantizers/IQuantizer{TPixel}.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Quantizers -{ - using ImageSharp.Dithering; - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Dithering; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Quantizers +{ /// /// Provides methods for for allowing quantization of images pixels with configurable dithering. /// diff --git a/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs index 8ebea85334..f41bcd04de 100644 --- a/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs +++ b/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Quantizers -{ - using System; - using System.Collections.Generic; - using System.Runtime.CompilerServices; - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Quantizers +{ /// /// Encapsulates methods to calculate the color palette if an image using an Octree pattern. /// diff --git a/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs b/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs index d121dc6ae7..56ecf7c900 100644 --- a/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs +++ b/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Quantizers -{ - using System; - using System.Collections.Generic; - using System.Runtime.CompilerServices; - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Quantizers +{ /// /// Encapsulates methods to create a quantized image based upon the given palette. /// diff --git a/src/ImageSharp/Quantizers/Quantization.cs b/src/ImageSharp/Quantizers/Quantization.cs index 039404384d..df55d3e87a 100644 --- a/src/ImageSharp/Quantizers/Quantization.cs +++ b/src/ImageSharp/Quantizers/Quantization.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp +namespace SixLabors.ImageSharp { /// /// Provides enumeration over how an image should be quantized. diff --git a/src/ImageSharp/Quantizers/Quantize.cs b/src/ImageSharp/Quantizers/Quantize.cs index a235092787..ad166f6065 100644 --- a/src/ImageSharp/Quantizers/Quantize.cs +++ b/src/ImageSharp/Quantizers/Quantize.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp -{ - using System; - using System.Threading.Tasks; - - using ImageSharp.PixelFormats; - using ImageSharp.Quantizers; +using System; +using System.Threading.Tasks; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Quantizers; +namespace SixLabors.ImageSharp +{ /// /// Extension methods for the type. /// @@ -24,7 +21,7 @@ public static partial class ImageExtensions /// The quantization mode to apply to perform the operation. /// The maximum number of colors to return. Defaults to 256. /// The . - public static Image Quantize(this Image source, Quantization mode = Quantization.Octree, int maxColors = 256) + public static IImageProcessingContext Quantize(this IImageProcessingContext source, Quantization mode = Quantization.Octree, int maxColors = 256) where TPixel : struct, IPixel { IQuantizer quantizer; @@ -54,31 +51,34 @@ public static Image Quantize(this Image source, Quantiza /// The quantizer to apply to perform the operation. /// The maximum number of colors to return. /// The . - public static Image Quantize(this Image source, IQuantizer quantizer, int maxColors) + public static IImageProcessingContext Quantize(this IImageProcessingContext source, IQuantizer quantizer, int maxColors) where TPixel : struct, IPixel { - QuantizedImage quantized = quantizer.Quantize(source, maxColors); - int palleteCount = quantized.Palette.Length - 1; - - using (PixelAccessor pixels = new PixelAccessor(quantized.Width, quantized.Height)) + return source.Apply(img => { - Parallel.For( - 0, - pixels.Height, - source.Configuration.ParallelOptions, - y => - { - for (int x = 0; x < pixels.Width; x++) + // TODO : move helper logic into the processor + QuantizedImage quantized = quantizer.Quantize(img, maxColors); + int palleteCount = quantized.Palette.Length - 1; + + using (var pixels = new PixelAccessor(quantized.Width, quantized.Height)) + { + Parallel.For( + 0, + pixels.Height, + img.Configuration.ParallelOptions, + y => { - int i = x + (y * pixels.Width); - TPixel color = quantized.Palette[Math.Min(palleteCount, quantized.Pixels[i])]; - pixels[x, y] = color; - } - }); + for (int x = 0; x < pixels.Width; x++) + { + int i = x + (y * pixels.Width); + TPixel color = quantized.Palette[Math.Min(palleteCount, quantized.Pixels[i])]; + pixels[x, y] = color; + } + }); - source.SwapPixelsBuffers(pixels); - return source; - } + img.SwapPixelsBuffers(pixels); + } + }); } } } \ No newline at end of file diff --git a/src/ImageSharp/Quantizers/QuantizedImage{TPixel}.cs b/src/ImageSharp/Quantizers/QuantizedImage{TPixel}.cs index c8b2c7df60..52cf1a8d9a 100644 --- a/src/ImageSharp/Quantizers/QuantizedImage{TPixel}.cs +++ b/src/ImageSharp/Quantizers/QuantizedImage{TPixel}.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Quantizers -{ - using System; - using ImageSharp.PixelFormats; +using System; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Quantizers +{ /// /// Represents a quantized image where the pixels indexed by a color palette. /// diff --git a/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs b/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs index 2e3ea7a543..c658917755 100644 --- a/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs +++ b/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs @@ -1,17 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Quantizers -{ - using System; - using System.Collections.Generic; - using System.Numerics; - using System.Runtime.CompilerServices; - using ImageSharp.Dithering; - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Dithering; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Quantizers +{ /// /// Encapsulates methods to calculate the color palette of an image. /// @@ -70,7 +68,7 @@ public virtual QuantizedImage Quantize(ImageBase image, int maxC if (this.Dither) { // We clone the image as we don't want to alter the original. - using (var clone = new Image(image)) + using (ImageBase clone = image.Clone()) { this.SecondPass(clone, quantizedPixels, width, height); } diff --git a/src/ImageSharp/Quantizers/WuArrayPool.cs b/src/ImageSharp/Quantizers/WuArrayPool.cs index bd8ee9d6b9..04a70637b6 100644 --- a/src/ImageSharp/Quantizers/WuArrayPool.cs +++ b/src/ImageSharp/Quantizers/WuArrayPool.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Quantizers -{ - using System.Buffers; +using System.Buffers; +namespace SixLabors.ImageSharp.Quantizers +{ /// /// Provides array pooling for the . /// This is a separate class so that the pools can be shared accross multiple generic quantizer instaces. diff --git a/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs b/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs index aecca771c1..4bb9028176 100644 --- a/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs +++ b/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs @@ -1,17 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Quantizers -{ - using System; - using System.Buffers; - using System.Collections.Generic; - using System.Numerics; - using System.Runtime.CompilerServices; - using ImageSharp.PixelFormats; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Quantizers +{ /// /// An implementation of Wu's color quantizer with alpha channel. /// diff --git a/src/Shared/AssemblyInfo.Common.cs b/src/Shared/AssemblyInfo.Common.cs index 252ef3eae0..08d7768a05 100644 --- a/src/Shared/AssemblyInfo.Common.cs +++ b/src/Shared/AssemblyInfo.Common.cs @@ -1,7 +1,5 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// using System.Reflection; using System.Resources; @@ -12,9 +10,9 @@ // associated with an assembly. [assembly: AssemblyDescription("A cross-platform library for processing of image files; written in C#")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("James Jackson-South")] -[assembly: AssemblyProduct("ImageSharp")] -[assembly: AssemblyCopyright("Copyright (c) James Jackson-South and contributors.")] +[assembly: AssemblyCompany("Six Labors")] +[assembly: AssemblyProduct("SixLabors.ImageSharp")] +[assembly: AssemblyCopyright("Copyright (c) Six Labors and contributors.")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: NeutralResourcesLanguage("en")] @@ -34,7 +32,9 @@ [assembly: AssemblyInformationalVersion("1.0.0.0")] // Ensure the internals can be built and tested. -[assembly: InternalsVisibleTo("ImageSharp.Drawing")] -[assembly: InternalsVisibleTo("ImageSharp.Benchmarks")] -[assembly: InternalsVisibleTo("ImageSharp.Tests")] -[assembly: InternalsVisibleTo("ImageSharp.Sandbox46")] \ No newline at end of file +[assembly: InternalsVisibleTo("SixLabors.ImageSharp.Drawing")] +[assembly: InternalsVisibleTo("SixLabors.ImageSharp.Benchmarks")] +[assembly: InternalsVisibleTo("SixLabors.ImageSharp.Tests")] +[assembly: InternalsVisibleTo("SixLabors.ImageSharp.Sandbox46")] + +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] \ No newline at end of file diff --git a/src/Shared/stylecop.json b/src/Shared/stylecop.json deleted file mode 100644 index df8f120a5b..0000000000 --- a/src/Shared/stylecop.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", - "settings": { - "documentationRules": { - "companyName": "James Jackson-South", - "copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0." - } - } -} \ No newline at end of file diff --git a/stylecop.json b/stylecop.json new file mode 100644 index 0000000000..485ab604a5 --- /dev/null +++ b/stylecop.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "orderingRules": { + "usingDirectivesPlacement": "outsideNamespace", + "elementOrder": [ + "kind" + ] + }, + "documentationRules": { + "xmlHeader": false, + "documentInternalElements": false, + "copyrightText": "Copyright (c) Six Labors and contributors.\nLicensed under the Apache License, Version 2.0." + } + } +} \ No newline at end of file diff --git a/tests/CodeCoverage/CodeCoverage.cmd b/tests/CodeCoverage/CodeCoverage.cmd index 1e16d5c14a..2c13cfc144 100644 --- a/tests/CodeCoverage/CodeCoverage.cmd +++ b/tests/CodeCoverage/CodeCoverage.cmd @@ -9,9 +9,8 @@ cd .. cd .. dotnet restore ImageSharp.sln -dotnet build ImageSharp.sln --no-incremental -c release /p:codecov=true rem The -threshold options prevents this taking ages... -tests\CodeCoverage\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test tests\ImageSharp.Tests\ImageSharp.Tests.csproj --no-build -c release /p:codecov=true" -register:user -threshold:10 -oldStyle -safemode:off -output:.\ImageSharp.Coverage.xml -hideskipped:All -returntargetcode -filter:"+[ImageSharp*]*" +tests\CodeCoverage\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test tests\ImageSharp.Tests\ImageSharp.Tests.csproj -c Release /p:codecov=true" -register:user -threshold:10 -oldStyle -safemode:off -output:.\ImageSharp.Coverage.xml -hideskipped:All -returntargetcode -filter:"+[SixLabors.ImageSharp*]*" if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/tests/ImageSharp.Benchmarks/BenchmarkBase.cs b/tests/ImageSharp.Benchmarks/BenchmarkBase.cs index 41574d109f..6db03a4486 100644 --- a/tests/ImageSharp.Benchmarks/BenchmarkBase.cs +++ b/tests/ImageSharp.Benchmarks/BenchmarkBase.cs @@ -1,6 +1,6 @@ -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { - using ImageSharp.Formats; + using SixLabors.ImageSharp.Formats; /// /// The image benchmark base class. diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs index 78bdfd1599..b4f6ea9c06 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs @@ -1,12 +1,12 @@ -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using System.Numerics; using System.Runtime.CompilerServices; using BenchmarkDotNet.Attributes; - using ImageSharp; - using ImageSharp.Memory; + using SixLabors.ImageSharp; + using SixLabors.ImageSharp.Memory; /// /// Compares two implementation candidates for general BulkPixelOperations.ToVector4(): diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs index 7b151989ea..5c3648c2d8 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs @@ -1,10 +1,10 @@ // ReSharper disable InconsistentNaming -namespace ImageSharp.Benchmarks.Color.Bulk +namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Memory; + using SixLabors.ImageSharp.PixelFormats; public abstract class PackFromXyzw where TPixel : struct, IPixel diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs index 9976faa8c3..2bf4e0da67 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs @@ -1,12 +1,12 @@ // ReSharper disable InconsistentNaming -namespace ImageSharp.Benchmarks.Color.Bulk +namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk { using System.Numerics; using BenchmarkDotNet.Attributes; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Memory; + using SixLabors.ImageSharp.PixelFormats; public abstract class ToVector4 where TPixel : struct, IPixel diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs index 061a5bd37b..e1f5e6106d 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs @@ -1,10 +1,10 @@ // ReSharper disable InconsistentNaming -namespace ImageSharp.Benchmarks.Color.Bulk +namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Memory; + using SixLabors.ImageSharp.PixelFormats; public abstract class ToXyz where TPixel : struct, IPixel diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs index f4bcce1152..6032897634 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs @@ -4,12 +4,12 @@ using System.Threading.Tasks; // ReSharper disable InconsistentNaming -namespace ImageSharp.Benchmarks.Color.Bulk +namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Memory; + using SixLabors.ImageSharp.PixelFormats; public abstract class ToXyzw where TPixel : struct, IPixel diff --git a/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs b/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs index a641baafe5..02017cbb7d 100644 --- a/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs +++ b/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs @@ -3,11 +3,11 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using BenchmarkDotNet.Attributes; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.PixelFormats; using SystemColor = System.Drawing.Color; diff --git a/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToCieLabConvert.cs b/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToCieLabConvert.cs index b29fdc25b6..c5792f5476 100644 --- a/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToCieLabConvert.cs +++ b/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToCieLabConvert.cs @@ -1,12 +1,12 @@ -namespace ImageSharp.Benchmarks.Color +namespace SixLabors.ImageSharp.Benchmarks.Color { using BenchmarkDotNet.Attributes; using Colourful; using Colourful.Conversion; - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; + using SixLabors.ImageSharp.ColorSpaces; + using SixLabors.ImageSharp.ColorSpaces.Conversion; public class ColorspaceCieXyzToCieLabConvert { diff --git a/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToHunterLabConvert.cs b/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToHunterLabConvert.cs index 3e7d609727..7528f75f80 100644 --- a/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToHunterLabConvert.cs +++ b/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToHunterLabConvert.cs @@ -1,12 +1,12 @@ -namespace ImageSharp.Benchmarks.Color +namespace SixLabors.ImageSharp.Benchmarks.Color { using BenchmarkDotNet.Attributes; using Colourful; using Colourful.Conversion; - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; + using SixLabors.ImageSharp.ColorSpaces; + using SixLabors.ImageSharp.ColorSpaces.Conversion; public class ColorspaceCieXyzToHunterLabConvert { diff --git a/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToLmsConvert.cs b/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToLmsConvert.cs index f472dd2923..a4da780908 100644 --- a/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToLmsConvert.cs +++ b/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToLmsConvert.cs @@ -1,12 +1,12 @@ -namespace ImageSharp.Benchmarks.Color +namespace SixLabors.ImageSharp.Benchmarks.Color { using BenchmarkDotNet.Attributes; using Colourful; using Colourful.Conversion; - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; + using SixLabors.ImageSharp.ColorSpaces; + using SixLabors.ImageSharp.ColorSpaces.Conversion; public class ColorspaceCieXyzToLmsConvert { diff --git a/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToRgbConvert.cs b/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToRgbConvert.cs index eeea86c6eb..dab0e7a515 100644 --- a/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToRgbConvert.cs +++ b/tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToRgbConvert.cs @@ -1,12 +1,12 @@ -namespace ImageSharp.Benchmarks.Color +namespace SixLabors.ImageSharp.Benchmarks.Color { using BenchmarkDotNet.Attributes; using Colourful; using Colourful.Conversion; - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; + using SixLabors.ImageSharp.ColorSpaces; + using SixLabors.ImageSharp.ColorSpaces.Conversion; public class ColorspaceCieXyzToRgbConvert { diff --git a/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.LookupTables.cs b/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.LookupTables.cs index 18c8cb3728..335ecf4789 100644 --- a/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.LookupTables.cs +++ b/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.LookupTables.cs @@ -1,4 +1,4 @@ -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { public partial class RgbToYCbCr { diff --git a/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs b/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs index 2efd9bc429..51be951c1b 100644 --- a/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs +++ b/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs @@ -1,4 +1,4 @@ -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using System; using System.Buffers; @@ -7,7 +7,7 @@ using BenchmarkDotNet.Attributes; - using ImageSharp.Formats.Jpg; + using SixLabors.ImageSharp.Formats.Jpg; public partial class RgbToYCbCr { diff --git a/tests/ImageSharp.Benchmarks/Color/RgbWorkingSpaceAdapt.cs b/tests/ImageSharp.Benchmarks/Color/RgbWorkingSpaceAdapt.cs index 21d040e5c1..f4e0fd65f6 100644 --- a/tests/ImageSharp.Benchmarks/Color/RgbWorkingSpaceAdapt.cs +++ b/tests/ImageSharp.Benchmarks/Color/RgbWorkingSpaceAdapt.cs @@ -1,12 +1,12 @@ -namespace ImageSharp.Benchmarks.Color +namespace SixLabors.ImageSharp.Benchmarks.Color { using BenchmarkDotNet.Attributes; using Colourful; using Colourful.Conversion; - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; + using SixLabors.ImageSharp.ColorSpaces; + using SixLabors.ImageSharp.ColorSpaces.Conversion; public class RgbWorkingSpaceAdapt { diff --git a/tests/ImageSharp.Benchmarks/Color/YcbCrToRgb.cs b/tests/ImageSharp.Benchmarks/Color/YcbCrToRgb.cs index dad32626d3..2e3307d298 100644 --- a/tests/ImageSharp.Benchmarks/Color/YcbCrToRgb.cs +++ b/tests/ImageSharp.Benchmarks/Color/YcbCrToRgb.cs @@ -1,4 +1,4 @@ -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using System.Numerics; diff --git a/tests/ImageSharp.Benchmarks/Config.cs b/tests/ImageSharp.Benchmarks/Config.cs index 8e278330bd..694f01f70a 100644 --- a/tests/ImageSharp.Benchmarks/Config.cs +++ b/tests/ImageSharp.Benchmarks/Config.cs @@ -5,7 +5,7 @@ using BenchmarkDotNet.Configs; -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using BenchmarkDotNet.Jobs; diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs index 66104944ea..ce1a88599a 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using System.Drawing; using System.Drawing.Drawing2D; @@ -12,7 +12,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.PixelFormats; public class DrawBeziers : BenchmarkBase { @@ -47,7 +47,7 @@ public void DrawLinesCore() { using (Image image = new Image(800, 800)) { - image.DrawBeziers( + image.Mutate(x => x.DrawBeziers( Rgba32.HotPink, 10, new SixLabors.Primitives.PointF[] { @@ -55,7 +55,7 @@ public void DrawLinesCore() new Vector2(30, 10), new Vector2(240, 30), new Vector2(300, 500) - }); + })); using (MemoryStream ms = new MemoryStream()) { diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs index a6af5a9769..4f40c001d9 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using System.Drawing; using System.Drawing.Drawing2D; @@ -12,7 +12,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.PixelFormats; public class DrawLines : BenchmarkBase { @@ -45,14 +45,14 @@ public void DrawLinesCore() { using (Image image = new Image(800, 800)) { - image.DrawLines( + image.Mutate(x => x.DrawLines( Rgba32.HotPink, 10, new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(550, 50), new Vector2(200, 400) - }); + })); using (MemoryStream ms = new MemoryStream()) { diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs index 3abd3b889d..fd8e4ad285 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using System.Drawing; using System.Drawing.Drawing2D; @@ -13,7 +13,7 @@ namespace ImageSharp.Benchmarks using System.IO; using System.Numerics; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.PixelFormats; public class DrawPolygon : BenchmarkBase { @@ -47,14 +47,14 @@ public void DrawPolygonCore() { using (Image image = new Image(800, 800)) { - image.DrawPolygon( + image.Mutate(x => x.DrawPolygon( Rgba32.HotPink, 10, new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(550, 50), new Vector2(200, 400) - }); + })); using (MemoryStream ms = new MemoryStream()) { diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs index b7d1b96b74..f948c4921f 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using System.Drawing; using System.Drawing.Drawing2D; @@ -13,7 +13,7 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.PixelFormats; public class FillPolygon : BenchmarkBase { @@ -55,13 +55,13 @@ public void DrawSolidPolygonCore() { using (Image image = new Image(800, 800)) { - image.FillPolygon( + image.Mutate(x => x.FillPolygon( Rgba32.HotPink, new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(550, 50), new Vector2(200, 400) - }); + })); using (MemoryStream ms = new MemoryStream()) { @@ -75,9 +75,9 @@ public void DrawSolidPolygonCoreCahced() { using (Image image = new Image(800, 800)) { - image.Fill( + image.Mutate(x => x.Fill( Rgba32.HotPink, - this.shape); + this.shape)); using (MemoryStream ms = new MemoryStream()) { diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs index 0738812a1c..b3890c101e 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using System.Drawing; using System.Drawing.Drawing2D; @@ -14,7 +14,7 @@ namespace ImageSharp.Benchmarks using System.Numerics; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.PixelFormats; public class FillRectangle : BenchmarkBase { @@ -39,7 +39,7 @@ public CoreSize FillRactangleCore() { using (Image image = new Image(800, 800)) { - image.Fill(Rgba32.HotPink, new CoreRectangle(10, 10, 190, 140)); + image.Mutate(x => x.Fill(Rgba32.HotPink, new CoreRectangle(10, 10, 190, 140))); return new CoreSize(image.Width, image.Height); } @@ -50,13 +50,13 @@ public CoreSize FillPolygonCore() { using (Image image = new Image(800, 800)) { - image.FillPolygon( + image.Mutate(x => x.FillPolygon( Rgba32.HotPink, new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 10), new Vector2(200, 150), - new Vector2(10, 150) }); + new Vector2(10, 150) })); return new CoreSize(image.Width, image.Height); } diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs index aa97efe00b..46d02e4197 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using System.Drawing; using System.Drawing.Drawing2D; @@ -11,9 +11,9 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using ImageSharp.Drawing.Brushes; + using SixLabors.ImageSharp.Drawing.Brushes; using CoreBrushes = ImageSharp.Drawing.Brushes.Brushes; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.PixelFormats; public class FillWithPattern { @@ -40,7 +40,7 @@ public void DrawPatternPolygon3Core() { using (Image image = new Image(800, 800)) { - image.Fill(CoreBrushes.BackwardDiagonal(Rgba32.HotPink)); + image.Mutate(x => x.Fill(CoreBrushes.BackwardDiagonal(Rgba32.HotPink))); using (MemoryStream ms = new MemoryStream()) { diff --git a/tests/ImageSharp.Benchmarks/General/Abs.cs b/tests/ImageSharp.Benchmarks/General/Abs.cs index b5b4494670..a67f3f1078 100644 --- a/tests/ImageSharp.Benchmarks/General/Abs.cs +++ b/tests/ImageSharp.Benchmarks/General/Abs.cs @@ -1,4 +1,4 @@ -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using System; diff --git a/tests/ImageSharp.Benchmarks/General/Array2D.cs b/tests/ImageSharp.Benchmarks/General/Array2D.cs index b7ac2cd867..02df1a19e2 100644 --- a/tests/ImageSharp.Benchmarks/General/Array2D.cs +++ b/tests/ImageSharp.Benchmarks/General/Array2D.cs @@ -3,13 +3,13 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using System; using BenchmarkDotNet.Attributes; - using ImageSharp.Memory; + using SixLabors.ImageSharp.Memory; public class Array2D { diff --git a/tests/ImageSharp.Benchmarks/General/ArrayCopy.cs b/tests/ImageSharp.Benchmarks/General/ArrayCopy.cs index dd0ebd413e..ddfa0f08b1 100644 --- a/tests/ImageSharp.Benchmarks/General/ArrayCopy.cs +++ b/tests/ImageSharp.Benchmarks/General/ArrayCopy.cs @@ -2,7 +2,7 @@ // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using System; using System.Runtime.CompilerServices; diff --git a/tests/ImageSharp.Benchmarks/General/ArrayReverse.cs b/tests/ImageSharp.Benchmarks/General/ArrayReverse.cs index 27341b146f..45a8519a9c 100644 --- a/tests/ImageSharp.Benchmarks/General/ArrayReverse.cs +++ b/tests/ImageSharp.Benchmarks/General/ArrayReverse.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using System; diff --git a/tests/ImageSharp.Benchmarks/General/Clamp.cs b/tests/ImageSharp.Benchmarks/General/Clamp.cs index ae53de9d3a..ef6bc3c402 100644 --- a/tests/ImageSharp.Benchmarks/General/Clamp.cs +++ b/tests/ImageSharp.Benchmarks/General/Clamp.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using System; using System.Runtime.CompilerServices; diff --git a/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs b/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs index c3a309bb8a..0ac1413be0 100644 --- a/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs +++ b/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs @@ -1,12 +1,12 @@ // ReSharper disable InconsistentNaming -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using System; using System.Runtime.CompilerServices; using BenchmarkDotNet.Attributes; - using ImageSharp.Memory; + using SixLabors.ImageSharp.Memory; public unsafe class ClearBuffer { diff --git a/tests/ImageSharp.Benchmarks/General/IterateArray.cs b/tests/ImageSharp.Benchmarks/General/IterateArray.cs index cc8d99b418..48ee266fe0 100644 --- a/tests/ImageSharp.Benchmarks/General/IterateArray.cs +++ b/tests/ImageSharp.Benchmarks/General/IterateArray.cs @@ -1,11 +1,11 @@ -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using System.Numerics; using System.Runtime.CompilerServices; using BenchmarkDotNet.Attributes; - using ImageSharp.Memory; + using SixLabors.ImageSharp.Memory; public class IterateArray { diff --git a/tests/ImageSharp.Benchmarks/General/Modulus.cs b/tests/ImageSharp.Benchmarks/General/Modulus.cs index aa3e461e1c..e6d5ccce62 100644 --- a/tests/ImageSharp.Benchmarks/General/Modulus.cs +++ b/tests/ImageSharp.Benchmarks/General/Modulus.cs @@ -1,4 +1,4 @@ -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using BenchmarkDotNet.Attributes; diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromRgba32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromRgba32.cs index e096fd828c..a1db525a69 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromRgba32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromRgba32.cs @@ -1,5 +1,5 @@ // ReSharper disable InconsistentNaming -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -142,7 +142,7 @@ public void RunFromBytesConversion() [Params(32)] public int Count { get; set; } - [Setup] + [GlobalSetup] public void Setup() { this.compatibleMemLayoutRunner = new ConversionRunner(this.Count); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromVector4.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromVector4.cs index 721ac121a3..5b059e2e65 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromVector4.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromVector4.cs @@ -1,5 +1,5 @@ // ReSharper disable InconsistentNaming -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using System.Numerics; using System.Runtime.CompilerServices; @@ -108,7 +108,7 @@ public void RunByValConversion() [Params(32)] public int Count { get; set; } - [Setup] + [GlobalSetup] public void Setup() { this.nonVectorRunner = new ConversionRunner(this.Count); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertToRgba32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertToRgba32.cs index 0c9a8af3fd..782c792393 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertToRgba32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertToRgba32.cs @@ -1,5 +1,5 @@ // ReSharper disable InconsistentNaming -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -111,7 +111,7 @@ public void RunCopyToConversion() [Params(128)] public int Count { get; set; } - [Setup] + [GlobalSetup] public void Setup() { this.compatibleMemoryLayoutRunner = new ConversionRunner(this.Count); diff --git a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs index bd2bf599c4..0e21caffbc 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs @@ -1,11 +1,11 @@ -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using System.Numerics; using System.Runtime.CompilerServices; using BenchmarkDotNet.Attributes; - using ImageSharp.Memory; + using SixLabors.ImageSharp.Memory; // Pixel indexing benchmarks compare different methods for getting/setting all pixel values in a subsegment of a single pixel row. public abstract unsafe class PixelIndexing diff --git a/tests/ImageSharp.Benchmarks/General/RoundSinglePrecisionBlocks.cs b/tests/ImageSharp.Benchmarks/General/RoundSinglePrecisionBlocks.cs index f998290340..a4e5f358c5 100644 --- a/tests/ImageSharp.Benchmarks/General/RoundSinglePrecisionBlocks.cs +++ b/tests/ImageSharp.Benchmarks/General/RoundSinglePrecisionBlocks.cs @@ -1,11 +1,11 @@ -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using System.Numerics; using System.Runtime.CompilerServices; using BenchmarkDotNet.Attributes; - using ImageSharp.Formats.Jpg; + using SixLabors.ImageSharp.Formats.Jpg; /// /// The goal of this benchmark is to measure the following Jpeg-related scenario: diff --git a/tests/ImageSharp.Benchmarks/General/Vector4Constants.cs b/tests/ImageSharp.Benchmarks/General/Vector4Constants.cs index 820789ee7c..ae11806f32 100644 --- a/tests/ImageSharp.Benchmarks/General/Vector4Constants.cs +++ b/tests/ImageSharp.Benchmarks/General/Vector4Constants.cs @@ -1,4 +1,4 @@ -namespace ImageSharp.Benchmarks.General +namespace SixLabors.ImageSharp.Benchmarks.General { using System; using System.Numerics; diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/BitwiseOrUint32.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/BitwiseOrUint32.cs index b882403c85..d189411b5d 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/BitwiseOrUint32.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/BitwiseOrUint32.cs @@ -1,4 +1,4 @@ -namespace ImageSharp.Benchmarks.General.Vectorization +namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization { using System.Numerics; diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/DivFloat.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/DivFloat.cs index caadaaa347..6378467478 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/DivFloat.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/DivFloat.cs @@ -1,4 +1,4 @@ -namespace ImageSharp.Benchmarks.General.Vectorization +namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization { using System.Numerics; diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/DivUInt32.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/DivUInt32.cs index 6b3edb192b..49ada2f368 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/DivUInt32.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/DivUInt32.cs @@ -1,4 +1,4 @@ -namespace ImageSharp.Benchmarks.General.Vectorization +namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization { using System.Numerics; diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/Divide.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/Divide.cs new file mode 100644 index 0000000000..b384295570 --- /dev/null +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/Divide.cs @@ -0,0 +1,69 @@ +namespace ImageSharp.Benchmarks.General.Vectorization +{ + using System; + using System.Numerics; + + using BenchmarkDotNet.Attributes; + + public class DivFloat : SIMDBenchmarkBase.Divide + { + protected override float GetTestValue() => 42; + + [Benchmark(Baseline = true)] + public void Standard() + { + float v = this.testValue; + for (int i = 0; i < this.input.Length; i++) + { + this.result[i] = this.input[i] / v; + } + } + } + + public class Divide : SIMDBenchmarkBase.Divide + { + protected override uint GetTestValue() => 42; + + [Benchmark(Baseline = true)] + public void Standard() + { + uint v = this.testValue; + for (int i = 0; i < this.input.Length; i++) + { + this.result[i] = this.input[i] / v; + } + } + } + + public class DivInt32 : SIMDBenchmarkBase.Divide + { + protected override int GetTestValue() => 42; + + [Benchmark(Baseline = true)] + public void Standard() + { + int v = this.testValue; + for (int i = 0; i < this.input.Length; i++) + { + this.result[i] = this.input[i] / v; + } + } + } + + public class DivInt16 : SIMDBenchmarkBase.Divide + { + protected override short GetTestValue() => 42; + + protected override Vector GetTestVector() => new Vector(new short[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}); + + [Benchmark(Baseline = true)] + public void Standard() + { + short v = this.testValue; + for (int i = 0; i < this.input.Length; i++) + { + this.result[i] = (short)(this.input[i] / v); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs index e5ae49b2a6..8c5f568181 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs @@ -1,4 +1,4 @@ -namespace ImageSharp.Benchmarks.General.Vectorization +namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization { using System.Numerics; diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/MulUInt32.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/MulUInt32.cs index 532acc02d5..913d4ce3c7 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/MulUInt32.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/MulUInt32.cs @@ -1,4 +1,4 @@ -namespace ImageSharp.Benchmarks.General.Vectorization +namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization { using System.Numerics; diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/Multiply.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/Multiply.cs new file mode 100644 index 0000000000..d1b70f21b3 --- /dev/null +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/Multiply.cs @@ -0,0 +1,50 @@ +namespace ImageSharp.Benchmarks.General.Vectorization +{ + using System.Numerics; + using BenchmarkDotNet.Attributes; + + public class MulUInt32 : SIMDBenchmarkBase.Multiply + { + protected override uint GetTestValue() => 42u; + + [Benchmark(Baseline = true)] + public void Standard() + { + uint v = this.testValue; + for (int i = 0; i < this.input.Length; i++) + { + this.result[i] = this.input[i] * v; + } + } + } + + public class MulInt32 : SIMDBenchmarkBase.Multiply + { + [Benchmark(Baseline = true)] + public void Standard() + { + int v = this.testValue; + for (int i = 0; i < this.input.Length; i++) + { + this.result[i] = this.input[i] * v; + } + } + } + + public class MulInt16 : SIMDBenchmarkBase.Multiply + { + protected override short GetTestValue() => 42; + + protected override Vector GetTestVector() => new Vector(new short[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }); + + [Benchmark(Baseline = true)] + public void Standard() + { + short v = this.testValue; + for (int i = 0; i < this.input.Length; i++) + { + this.result[i] = (short)(this.input[i] * v); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/ReinterpretUInt32AsFloat.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/ReinterpretUInt32AsFloat.cs index 30443fad9d..f3853a8b1f 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/ReinterpretUInt32AsFloat.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/ReinterpretUInt32AsFloat.cs @@ -1,4 +1,4 @@ -namespace ImageSharp.Benchmarks.General.Vectorization +namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization { using System.Numerics; using System.Runtime.InteropServices; diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs new file mode 100644 index 0000000000..76987dbd21 --- /dev/null +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs @@ -0,0 +1,70 @@ +namespace ImageSharp.Benchmarks.General.Vectorization +{ + using System.Numerics; + using System.Runtime.CompilerServices; + + using BenchmarkDotNet.Attributes; + + public abstract class SIMDBenchmarkBase + where T : struct + { + protected T[] input; + + protected T[] result; + + protected T testValue; + + protected Vector testVector; + + protected virtual T GetTestValue() => default(T); + + protected virtual Vector GetTestVector() => new Vector(this.GetTestValue()); + + + [Params(32)] + public int InputSize { get; set; } + + [GlobalSetup] + public virtual void Setup() + { + this.input = new T[this.InputSize]; + this.result = new T[this.InputSize]; + this.testValue = this.GetTestValue(); + this.testVector = this.GetTestVector(); + } + + public abstract class Multiply : SIMDBenchmarkBase + { + [Benchmark] + public void Simd() + { + Vector v = this.testVector; + + for (int i = 0; i < this.input.Length; i += Vector.Count) + { + Vector a = Unsafe.As>(ref this.input[i]); + a = a * v; + Unsafe.As>(ref this.result[i]) = a; + } + } + } + + public abstract class Divide : SIMDBenchmarkBase + { + [Benchmark] + public void Simd() + { + Vector v = this.testVector; + + for (int i = 0; i < this.input.Length; i += Vector.Count) + { + Vector a = Unsafe.As>(ref this.input[i]); + a = a / v; + Unsafe.As>(ref this.result[i]) = a; + } + } + } + + + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs index 73fc886487..147f66f8f7 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs @@ -1,11 +1,11 @@ -namespace ImageSharp.Benchmarks.General.Vectorization +namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization { using System; using System.Numerics; using System.Runtime.CompilerServices; using BenchmarkDotNet.Attributes; - using ImageSharp.Memory; + using SixLabors.ImageSharp.Memory; /// /// This benchmark compares different methods for fetching memory data into diff --git a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs index 1d4ed11936..7569d56f23 100644 --- a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs +++ b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs @@ -3,14 +3,14 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; - using ImageSharp.Memory; + using SixLabors.ImageSharp.Memory; public class CopyPixels : BenchmarkBase { diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs b/tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs index 6f3a38b7fd..142675fa7a 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; using System.IO; diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs b/tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs index ae1add172d..e295aee732 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs @@ -3,13 +3,13 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.IO; using BenchmarkDotNet.Attributes; - using ImageSharp; + using SixLabors.ImageSharp; using SixLabors.Primitives; using CoreImage = ImageSharp.Image; diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeGif.cs b/tests/ImageSharp.Benchmarks/Image/DecodeGif.cs index 3f908d3622..a65c9f9298 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeGif.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeGif.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; using System.IO; diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs b/tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs index ece93f912e..4f44d46cd3 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; using System.IO; @@ -14,6 +14,7 @@ namespace ImageSharp.Benchmarks.Image using CoreSize = SixLabors.Primitives.Size; + [Config(typeof(Config))] public class DecodeJpeg : BenchmarkBase { private byte[] jpegBytes; @@ -23,21 +24,21 @@ public void ReadImages() { if (this.jpegBytes == null) { - this.jpegBytes = File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Jpg/Baseline/Calliphora.jpg"); + this.jpegBytes = File.ReadAllBytes("../../../../../../../../ImageSharp.Tests/TestImages/Formats/Jpg/Baseline/Calliphora.jpg"); } } - [Benchmark(Baseline = true, Description = "System.Drawing Jpeg")] - public Size JpegSystemDrawing() - { - using (MemoryStream memoryStream = new MemoryStream(this.jpegBytes)) - { - using (Image image = Image.FromStream(memoryStream)) - { - return image.Size; - } - } - } + //[Benchmark(Baseline = true, Description = "System.Drawing Jpeg")] + //public Size JpegSystemDrawing() + //{ + // using (MemoryStream memoryStream = new MemoryStream(this.jpegBytes)) + // { + // using (Image image = Image.FromStream(memoryStream)) + // { + // return image.Size; + // } + // } + //} [Benchmark(Description = "ImageSharp Jpeg")] public CoreSize JpegCore() diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs b/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs index 44c90d253d..a4d9ea05bd 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs @@ -3,11 +3,17 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Collections.Generic; + using System.IO; + using BenchmarkDotNet.Attributes; + using ImageSharp.Formats; + using ImageSharp.Formats.Jpeg.GolangPort; + using ImageSharp.PixelFormats; + using CoreImage = ImageSharp.Image; [Config(typeof(Config.Short))] @@ -20,14 +26,23 @@ public class DecodeJpegMultiple : MultiImageBenchmarkBase protected override IEnumerable SearchPatterns => new[] { "*.jpg" }; - [Benchmark(Description = "DecodeJpegMultiple - ImageSharp")] - public void DecodeJpegImageSharp() + [Benchmark(Description = "DecodeJpegMultiple - ImageSharp NEW")] + public void DecodeJpegImageSharpNwq() { this.ForEachStream( ms => CoreImage.Load(ms) ); } + + [Benchmark(Description = "DecodeJpegMultiple - ImageSharp Original")] + public void DecodeJpegImageSharpOriginal() + { + this.ForEachStream( + ms => CoreImage.Load(ms, new OriginalJpegDecoder()) + ); + } + [Benchmark(Baseline = true, Description = "DecodeJpegMultiple - System.Drawing")] public void DecodeJpegSystemDrawing() { @@ -36,5 +51,25 @@ public void DecodeJpegSystemDrawing() ); } + + public sealed class OriginalJpegDecoder : IImageDecoder, IJpegDecoderOptions + { + /// + /// Gets or sets a value indicating whether the metadata should be ignored when the image is being decoded. + /// + public bool IgnoreMetadata { get; set; } + + /// + public Image Decode(Configuration configuration, Stream stream) + where TPixel : struct, IPixel + { + Guard.NotNull(stream, "stream"); + + using (var decoder = new OldJpegDecoderCore(configuration, this)) + { + return decoder.Decode(stream); + } + } + } } } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Image/DecodePng.cs b/tests/ImageSharp.Benchmarks/Image/DecodePng.cs index be1633c044..b9a9d5cfa2 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodePng.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodePng.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; using System.IO; diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs b/tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs index 4941e17cba..86994f2d35 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; using System.Drawing.Imaging; diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeBmpMultiple.cs b/tests/ImageSharp.Benchmarks/Image/EncodeBmpMultiple.cs index 852e175725..791e812ffc 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeBmpMultiple.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeBmpMultiple.cs @@ -3,14 +3,14 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Collections.Generic; using System.Drawing.Imaging; using BenchmarkDotNet.Attributes; - using ImageSharp.Formats; + using SixLabors.ImageSharp.Formats; [Config(typeof(Config.Short))] public class EncodeBmpMultiple : MultiImageBenchmarkBase.WithImagesPreloaded diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeGif.cs b/tests/ImageSharp.Benchmarks/Image/EncodeGif.cs index e6600594f0..7a6ddd79d7 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeGif.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeGif.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; using System.Drawing.Imaging; diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeGifMultiple.cs b/tests/ImageSharp.Benchmarks/Image/EncodeGifMultiple.cs index 8d1d147466..244ff58828 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeGifMultiple.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeGifMultiple.cs @@ -1,4 +1,4 @@ -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Collections.Generic; using System.Drawing.Imaging; @@ -6,7 +6,7 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Jobs; - using ImageSharp.Formats; + using SixLabors.ImageSharp.Formats; [Config(typeof(SingleRunConfig))] public class EncodeGifMultiple : MultiImageBenchmarkBase.WithImagesPreloaded diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs index 02e3211a76..7c48dbae28 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs @@ -3,15 +3,15 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.IO; using BenchmarkDotNet.Attributes; - using ImageSharp; - using ImageSharp.Formats; - using ImageSharp.Quantizers; + using SixLabors.ImageSharp; + using SixLabors.ImageSharp.Formats; + using SixLabors.ImageSharp.Quantizers; using CoreImage = ImageSharp.Image; diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeJpeg.cs b/tests/ImageSharp.Benchmarks/Image/EncodeJpeg.cs index 07c2560fd8..48fd6e9e7f 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeJpeg.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeJpeg.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; using System.Drawing.Imaging; diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeJpegMultiple.cs b/tests/ImageSharp.Benchmarks/Image/EncodeJpegMultiple.cs index bbf838a9e1..38b97f0043 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeJpegMultiple.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeJpegMultiple.cs @@ -3,14 +3,14 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Collections.Generic; using System.Drawing.Imaging; using BenchmarkDotNet.Attributes; - using ImageSharp.Formats; + using SixLabors.ImageSharp.Formats; [Config(typeof(Config.Short))] // It's long enough to iterate through multiple files diff --git a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs index 81bb235eea..0401132fca 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; using System.Drawing.Imaging; @@ -11,8 +11,8 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; - using ImageSharp.Formats; - using ImageSharp.Quantizers; + using SixLabors.ImageSharp.Formats; + using SixLabors.ImageSharp.Quantizers; using CoreImage = ImageSharp.Image; diff --git a/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs b/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs index 28616213b2..f9469e5fea 100644 --- a/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs +++ b/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs @@ -3,13 +3,13 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; using BenchmarkDotNet.Attributes; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.PixelFormats; using SystemColor = System.Drawing.Color; diff --git a/tests/ImageSharp.Benchmarks/Image/ImageBenchmarkTests.cs b/tests/ImageSharp.Benchmarks/Image/ImageBenchmarkTests.cs index f68f4a418f..8b25ba6fed 100644 --- a/tests/ImageSharp.Benchmarks/Image/ImageBenchmarkTests.cs +++ b/tests/ImageSharp.Benchmarks/Image/ImageBenchmarkTests.cs @@ -12,7 +12,7 @@ #if TEST // ReSharper disable InconsistentNaming -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System; using System.Collections.Generic; diff --git a/tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs b/tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs index e01a5951ef..3e4f2ea37d 100644 --- a/tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs +++ b/tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs @@ -4,7 +4,7 @@ // -namespace ImageSharp.Benchmarks.Image +namespace SixLabors.ImageSharp.Benchmarks.Image { using System; using System.Collections.Generic; @@ -39,7 +39,7 @@ public enum InputImageCategory [Params(InputImageCategory.AllImages, InputImageCategory.SmallImagesOnly, InputImageCategory.LargeImagesOnly)] public virtual InputImageCategory InputCategory { get; set; } - protected virtual string BaseFolder => "../ImageSharp.Tests/TestImages/Formats/"; + protected virtual string BaseFolder => "../../../../../../../../ImageSharp.Tests/TestImages/Formats/"; protected virtual IEnumerable SearchPatterns => new[] { "*.*" }; diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj index 72593a0da4..0db2fe569f 100644 --- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj +++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj @@ -3,6 +3,8 @@ netcoreapp1.1;net461 Exe True + SixLabors.ImageSharp.Benchmarks + SixLabors.ImageSharp.Benchmarks win7-x64 @@ -10,13 +12,13 @@ - + - + diff --git a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs index 19904a5ad2..5a3131f796 100644 --- a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs +++ b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs @@ -3,17 +3,17 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using System; using BenchmarkDotNet.Attributes; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.PixelFormats; using CoreSize = SixLabors.Primitives.Size; using System.Numerics; - using ImageSharp.Memory; - using ImageSharp.PixelFormats.PixelBlenders; + using SixLabors.ImageSharp.Memory; + using SixLabors.ImageSharp.PixelFormats.PixelBlenders; public class PorterDuffBulkVsPixel : BenchmarkBase { diff --git a/tests/ImageSharp.Benchmarks/Program.cs b/tests/ImageSharp.Benchmarks/Program.cs index 789068426b..4dd63067ac 100644 --- a/tests/ImageSharp.Benchmarks/Program.cs +++ b/tests/ImageSharp.Benchmarks/Program.cs @@ -3,11 +3,11 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using BenchmarkDotNet.Running; - using ImageSharp.Formats; + using SixLabors.ImageSharp.Formats; using System.Reflection; public class Program diff --git a/tests/ImageSharp.Benchmarks/Samplers/Crop.cs b/tests/ImageSharp.Benchmarks/Samplers/Crop.cs index cb13378a13..3681ff6f20 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Crop.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Crop.cs @@ -3,14 +3,14 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using System.Drawing; using System.Drawing.Drawing2D; using BenchmarkDotNet.Attributes; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.PixelFormats; using CoreSize = SixLabors.Primitives.Size; @@ -41,7 +41,7 @@ public CoreSize CropResizeCore() { using (Image image = new Image(800, 800)) { - image.Crop(100, 100); + image.Mutate(x => x.Crop(100, 100)); return new CoreSize(image.Width, image.Height); } } diff --git a/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs b/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs index 1f69030a00..f65957128c 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs @@ -3,13 +3,13 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using System.IO; using BenchmarkDotNet.Attributes; - using ImageSharp.Processing; + using SixLabors.ImageSharp.Processing; using CoreImage = ImageSharp.Image; @@ -38,17 +38,17 @@ public void Cleanup() [Benchmark(Description = "ImageSharp DetectEdges")] public void ImageProcessorCoreDetectEdges() { - this.image.DetectEdges(EdgeDetection.Kayyali); - this.image.DetectEdges(EdgeDetection.Kayyali); - this.image.DetectEdges(EdgeDetection.Kirsch); - this.image.DetectEdges(EdgeDetection.Lapacian3X3); - this.image.DetectEdges(EdgeDetection.Lapacian5X5); - this.image.DetectEdges(EdgeDetection.LaplacianOfGaussian); - this.image.DetectEdges(EdgeDetection.Prewitt); - this.image.DetectEdges(EdgeDetection.RobertsCross); - this.image.DetectEdges(EdgeDetection.Robinson); - this.image.DetectEdges(EdgeDetection.Scharr); - this.image.DetectEdges(EdgeDetection.Sobel); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Kayyali)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Kayyali)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Kirsch)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Lapacian3X3)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Lapacian5X5)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.LaplacianOfGaussian)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Prewitt)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.RobertsCross)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Robinson)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Scharr)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Sobel)); } } } diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs index 2aa8df96ca..b6dd7f4e76 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs @@ -3,19 +3,19 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using BenchmarkDotNet.Attributes; - using ImageSharp.PixelFormats; - using ImageSharp.Processing.Processors; + using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Processing.Processors; using CoreSize = SixLabors.Primitives.Size; - using ImageSharp.Processing; + using SixLabors.ImageSharp.Processing; using System.Numerics; using System; using System.Threading.Tasks; - using ImageSharp.Memory; + using SixLabors.ImageSharp.Memory; using SixLabors.Primitives; public class Glow : BenchmarkBase @@ -26,7 +26,7 @@ public class Glow : BenchmarkBase [GlobalSetup] public void Setup() { - this.bulk = new GlowProcessor(NamedColors.Beige, GraphicsOptions.Default) { Radius = 800 * .5f, }; + this.bulk = new GlowProcessor(NamedColors.Beige, 800 * .5f, GraphicsOptions.Default); this.parallel = new GlowProcessorParallel(NamedColors.Beige) { Radius = 800 * .5f, }; } @@ -35,7 +35,7 @@ public CoreSize GlowBulk() { using (Image image = new Image(800, 800)) { - image.ApplyProcessor(bulk, image.Bounds); + bulk.Apply(image, image.Bounds()); return new CoreSize(image.Width, image.Height); } } @@ -45,7 +45,7 @@ public CoreSize GLowSimple() { using (Image image = new Image(800, 800)) { - image.ApplyProcessor(parallel, image.Bounds); + parallel.Apply(image, image.Bounds()); return new CoreSize(image.Width, image.Height); } } diff --git a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs index 3873400698..6e7e2c8c48 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs @@ -3,14 +3,14 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Benchmarks +namespace SixLabors.ImageSharp.Benchmarks { using System.Drawing; using System.Drawing.Drawing2D; using BenchmarkDotNet.Attributes; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.PixelFormats; using CoreSize = SixLabors.Primitives.Size; @@ -41,7 +41,7 @@ public CoreSize ResizeCore() { using (Image image = new Image(2000, 2000)) { - image.Resize(400, 400); + image.Mutate(x => x.Resize(400, 400)); return new CoreSize(image.Width, image.Height); } } diff --git a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj index b9124afc6a..6b1f112363 100644 --- a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj +++ b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj @@ -5,11 +5,12 @@ win7-x64 True false - ImageSharp.Sandbox46 + SixLabors.ImageSharp.Sandbox46 A cross-platform library for processing of image files written in C# Copyright © James Jackson-South and contributors. James Jackson-South and contributors James Jackson-South + SixLabors.ImageSharp.Sandbox46 @@ -18,7 +19,8 @@ - + + diff --git a/tests/ImageSharp.Sandbox46/Program.cs b/tests/ImageSharp.Sandbox46/Program.cs index 6f93df16e5..f4f6ccabd2 100644 --- a/tests/ImageSharp.Sandbox46/Program.cs +++ b/tests/ImageSharp.Sandbox46/Program.cs @@ -3,15 +3,16 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Sandbox46 +namespace SixLabors.ImageSharp.Sandbox46 { using System; using System.Runtime.DesignerServices; - using ImageSharp.Tests; - using ImageSharp.Tests.Colors; - using ImageSharp.Tests.PixelFormats; - using ImageSharp.Tests.Processing.Transforms; + using SixLabors.ImageSharp.Tests; + using SixLabors.ImageSharp.Tests.Colors; + using SixLabors.ImageSharp.Tests.PixelFormats; + using SixLabors.ImageSharp.Tests.Processing.Processors.Transforms; + using SixLabors.ImageSharp.Tests.Processing.Transforms; using Xunit.Abstractions; @@ -39,10 +40,10 @@ public void WriteLine(string format, params object[] args) /// public static void Main(string[] args) { - // RunDecodeJpegProfilingTests(); + RunDecodeJpegProfilingTests(); // RunToVector4ProfilingTest(); - RunResizeProfilingTest(); + //RunResizeProfilingTest(); Console.ReadLine(); } diff --git a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs new file mode 100644 index 0000000000..37696987cc --- /dev/null +++ b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs @@ -0,0 +1,47 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.Text; +using SixLabors.ImageSharp.Processing; +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests +{ + public abstract class BaseImageOperationsExtensionTest + { + protected readonly IImageProcessingContext operations; + private readonly FakeImageOperationsProvider.FakeImageOperations internalOperations; + protected readonly Rectangle rect; + protected readonly GraphicsOptions options; + + public BaseImageOperationsExtensionTest() + { + this.options = new GraphicsOptions(false) { }; + this.rect = new Rectangle(91, 123, 324, 56); // make this random? + this.internalOperations = new FakeImageOperationsProvider.FakeImageOperations(null, false); + this.operations = this.internalOperations; + } + + public T Verify(int index = 0) + { + Assert.InRange(index, 0, this.internalOperations.applied.Count - 1); + + var operation = this.internalOperations.applied[index]; + + return Assert.IsType(operation.Processor); + } + + public T Verify(Rectangle rect, int index = 0) + { + Assert.InRange(index, 0, this.internalOperations.applied.Count - 1); + + var operation = this.internalOperations.applied[index]; + + Assert.Equal(rect, operation.Rectangle); + return Assert.IsType(operation.Processor); + } + } +} diff --git a/tests/ImageSharp.Tests/Colorspaces/CieLabAndCieLchConversionTests.cs b/tests/ImageSharp.Tests/Colorspaces/CieLabAndCieLchConversionTests.cs index f2d8c92d28..4269459893 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieLabAndCieLchConversionTests.cs +++ b/tests/ImageSharp.Tests/Colorspaces/CieLabAndCieLchConversionTests.cs @@ -1,11 +1,13 @@ -namespace ImageSharp.Tests.Colorspaces -{ - using System.Collections.Generic; - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ /// /// Tests - conversions. /// @@ -28,7 +30,6 @@ public class CieLabAndCieLchConversionTests [InlineData(100, 0, 0, 100, 0, 0)] [InlineData(100, 50, 180, 100, -50, 0)] [InlineData(10, 36.0555, 56.3099, 10, 20, 30)] - [InlineData(10, 36.0555, 56.3099, 10, 20, 30)] [InlineData(10, 36.0555, 123.6901, 10, -20, 30)] [InlineData(10, 36.0555, 303.6901, 10, 20, -30)] [InlineData(10, 36.0555, 236.3099, 10, -20, -30)] @@ -55,7 +56,6 @@ public void Convert_Lch_to_Lab(float l, float c, float h, float l2, float a, flo [InlineData(100, 0, 0, 100, 0, 0)] [InlineData(100, -50, 0, 100, 50, 180)] [InlineData(10, 20, 30, 10, 36.0555, 56.3099)] - [InlineData(10, 20, 30, 10, 36.0555, 56.3099)] [InlineData(10, -20, 30, 10, 36.0555, 123.6901)] [InlineData(10, 20, -30, 10, 36.0555, 303.6901)] [InlineData(10, -20, -30, 10, 36.0555, 236.3099)] diff --git a/tests/ImageSharp.Tests/Colorspaces/CieLuvAndCieLchuvConversionTests.cs b/tests/ImageSharp.Tests/Colorspaces/CieLuvAndCieLchuvConversionTests.cs index d263bbe18e..17fd1db50f 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieLuvAndCieLchuvConversionTests.cs +++ b/tests/ImageSharp.Tests/Colorspaces/CieLuvAndCieLchuvConversionTests.cs @@ -1,11 +1,13 @@ -namespace ImageSharp.Tests.Colorspaces -{ - using System.Collections.Generic; - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ /// /// Tests - conversions. /// @@ -28,7 +30,6 @@ public class CieLuvAndCieLchuvuvConversionTests [InlineData(100, 0, 0, 100, 0, 0)] [InlineData(100, 50, 180, 100, -50, 0)] [InlineData(10, 36.0555, 56.3099, 10, 20, 30)] - [InlineData(10, 36.0555, 56.3099, 10, 20, 30)] [InlineData(10, 36.0555, 123.6901, 10, -20, 30)] [InlineData(10, 36.0555, 303.6901, 10, 20, -30)] [InlineData(10, 36.0555, 236.3099, 10, -20, -30)] @@ -55,7 +56,6 @@ public void Convert_Lchuv_to_Luv(float l, float c, float h, float l2, float u, f [InlineData(100, 0, 0, 100, 0, 0)] [InlineData(100, -50, 0, 100, 50, 180)] [InlineData(10, 20, 30, 10, 36.0555, 56.3099)] - [InlineData(10, 20, 30, 10, 36.0555, 56.3099)] [InlineData(10, -20, 30, 10, 36.0555, 123.6901)] [InlineData(10, 20, -30, 10, 36.0555, 303.6901)] [InlineData(10, -20, -30, 10, 36.0555, 236.3099)] diff --git a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLabConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLabConversionTest.cs index 9bd8b17c79..76d76f236c 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLabConversionTest.cs +++ b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLabConversionTest.cs @@ -1,11 +1,13 @@ -namespace ImageSharp.Tests.Colorspaces -{ - using System.Collections.Generic; - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ /// /// Tests - conversions. /// diff --git a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLuvConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLuvConversionTest.cs index 5589e9753e..b18bd56dcb 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLuvConversionTest.cs +++ b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLuvConversionTest.cs @@ -1,11 +1,13 @@ -namespace ImageSharp.Tests.Colorspaces -{ - using System.Collections.Generic; - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ /// /// Tests - conversions. /// diff --git a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieXyyConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieXyyConversionTest.cs index 9b441f4526..1652c53923 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieXyyConversionTest.cs +++ b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieXyyConversionTest.cs @@ -1,12 +1,13 @@ -namespace ImageSharp.Tests.Colorspaces -{ - using System.Collections.Generic; - - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ /// /// Tests - conversions. /// diff --git a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndHunterLabConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndHunterLabConversionTest.cs index 5ad224eaf0..1c48d00ff2 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndHunterLabConversionTest.cs +++ b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndHunterLabConversionTest.cs @@ -1,11 +1,13 @@ -namespace ImageSharp.Tests.Colorspaces -{ - using System.Collections.Generic; - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ /// /// Tests - conversions. /// diff --git a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndLmsConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndLmsConversionTest.cs index 868d429757..f63c542122 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndLmsConversionTest.cs +++ b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndLmsConversionTest.cs @@ -1,11 +1,13 @@ -namespace ImageSharp.Tests.Colorspaces -{ - using System.Collections.Generic; - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ /// /// Tests - conversions. /// diff --git a/tests/ImageSharp.Tests/Colorspaces/ColorConverterAdaptTest.cs b/tests/ImageSharp.Tests/Colorspaces/ColorConverterAdaptTest.cs index 02095b31f2..87dc59907b 100644 --- a/tests/ImageSharp.Tests/Colorspaces/ColorConverterAdaptTest.cs +++ b/tests/ImageSharp.Tests/Colorspaces/ColorConverterAdaptTest.cs @@ -1,13 +1,14 @@ -namespace ImageSharp.Tests.Colorspaces -{ - using System.Collections.Generic; - - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; - using ImageSharp.ColorSpaces.Conversion.Implementation.Lms; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.LmsColorSapce; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ /// /// Tests methods. /// Test data generated using: diff --git a/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs b/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs index da58ddcda8..7fdebcac49 100644 --- a/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs +++ b/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// + +using System; +using System.Numerics; +using SixLabors.ImageSharp.ColorSpaces; +using Xunit; // ReSharper disable InconsistentNaming -namespace ImageSharp.Tests.Colorspaces +namespace SixLabors.ImageSharp.Tests.Colorspaces { - using System; - using System.Numerics; - using Xunit; - - using ImageSharp.ColorSpaces; - /// /// Test implementations of IEquatable and IAlmostEquatable in our colorspaces /// diff --git a/tests/ImageSharp.Tests/Colorspaces/RgbAndCieXyzConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/RgbAndCieXyzConversionTest.cs index 7a4520a57e..ee71eefc17 100644 --- a/tests/ImageSharp.Tests/Colorspaces/RgbAndCieXyzConversionTest.cs +++ b/tests/ImageSharp.Tests/Colorspaces/RgbAndCieXyzConversionTest.cs @@ -1,11 +1,13 @@ -namespace ImageSharp.Tests.Colorspaces -{ - using System.Collections.Generic; - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ /// /// Tests - conversions. /// diff --git a/tests/ImageSharp.Tests/Colorspaces/RgbAndCmykConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/RgbAndCmykConversionTest.cs index 8fe64e915b..6c3d579b4e 100644 --- a/tests/ImageSharp.Tests/Colorspaces/RgbAndCmykConversionTest.cs +++ b/tests/ImageSharp.Tests/Colorspaces/RgbAndCmykConversionTest.cs @@ -1,12 +1,13 @@ -namespace ImageSharp.Tests.Colorspaces -{ - using System.Collections.Generic; - - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ /// /// Tests - conversions. /// diff --git a/tests/ImageSharp.Tests/Colorspaces/RgbAndHslConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/RgbAndHslConversionTest.cs index fa02f887f2..a7071e883d 100644 --- a/tests/ImageSharp.Tests/Colorspaces/RgbAndHslConversionTest.cs +++ b/tests/ImageSharp.Tests/Colorspaces/RgbAndHslConversionTest.cs @@ -1,12 +1,13 @@ -namespace ImageSharp.Tests.Colorspaces -{ - using System.Collections.Generic; - - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ /// /// Tests - conversions. /// diff --git a/tests/ImageSharp.Tests/Colorspaces/RgbAndHsvConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/RgbAndHsvConversionTest.cs index f8d8c773a5..0dc58a0a3e 100644 --- a/tests/ImageSharp.Tests/Colorspaces/RgbAndHsvConversionTest.cs +++ b/tests/ImageSharp.Tests/Colorspaces/RgbAndHsvConversionTest.cs @@ -1,12 +1,13 @@ -namespace ImageSharp.Tests.Colorspaces -{ - using System.Collections.Generic; - - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ /// /// Tests - conversions. /// diff --git a/tests/ImageSharp.Tests/Colorspaces/RgbAndYCbCrConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/RgbAndYCbCrConversionTest.cs index 3f741ea3d9..0eb1f620bf 100644 --- a/tests/ImageSharp.Tests/Colorspaces/RgbAndYCbCrConversionTest.cs +++ b/tests/ImageSharp.Tests/Colorspaces/RgbAndYCbCrConversionTest.cs @@ -1,12 +1,13 @@ -namespace ImageSharp.Tests.Colorspaces -{ - using System.Collections.Generic; - - using ImageSharp.ColorSpaces; - using ImageSharp.ColorSpaces.Conversion; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ /// /// Tests - conversions. /// diff --git a/tests/ImageSharp.Tests/Common/Buffer2DTests.cs b/tests/ImageSharp.Tests/Common/Buffer2DTests.cs index 5f44a132d7..2f275b7547 100644 --- a/tests/ImageSharp.Tests/Common/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Common/Buffer2DTests.cs @@ -1,15 +1,14 @@ -// ReSharper disable InconsistentNaming -namespace ImageSharp.Tests.Common -{ - using System; - using System.Runtime.CompilerServices; - - using ImageSharp.Memory; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; - - using static TestStructs; +using System; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Memory; +using Xunit; +using static SixLabors.ImageSharp.Tests.Common.TestStructs; +namespace SixLabors.ImageSharp.Tests.Common +{ public unsafe class Buffer2DTests { // ReSharper disable once ClassNeverInstantiated.Local diff --git a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs index af33a981ba..fb51880f3e 100644 --- a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs +++ b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs @@ -1,19 +1,16 @@ -// ReSharper disable ObjectCreationAsStatement -// ReSharper disable InconsistentNaming - -namespace ImageSharp.Tests.Common +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +using static SixLabors.ImageSharp.Tests.Common.TestStructs; + +namespace SixLabors.ImageSharp.Tests.Common { - using System; - using System.Numerics; - using System.Runtime.CompilerServices; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - - using Xunit; - - using static TestStructs; - public unsafe class SpanTests { // ReSharper disable once ClassNeverInstantiated.Local diff --git a/tests/ImageSharp.Tests/Common/BufferTests.cs b/tests/ImageSharp.Tests/Common/BufferTests.cs index 25ef173d4c..e1883ec7fd 100644 --- a/tests/ImageSharp.Tests/Common/BufferTests.cs +++ b/tests/ImageSharp.Tests/Common/BufferTests.cs @@ -1,17 +1,16 @@ -// ReSharper disable InconsistentNaming -namespace ImageSharp.Tests.Common +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using Xunit; +using static SixLabors.ImageSharp.Tests.Common.TestStructs; + +namespace SixLabors.ImageSharp.Tests.Common { - using System; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - using System.Threading.Tasks; - - using ImageSharp.Memory; - - using Xunit; - - using static TestStructs; - public unsafe class BufferTests { // ReSharper disable once ClassNeverInstantiated.Local diff --git a/tests/ImageSharp.Tests/Common/ConstantsTests.cs b/tests/ImageSharp.Tests/Common/ConstantsTests.cs index be4addf913..48ecbbbc91 100644 --- a/tests/ImageSharp.Tests/Common/ConstantsTests.cs +++ b/tests/ImageSharp.Tests/Common/ConstantsTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Common -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Common +{ public class ConstantsTests { [Fact] diff --git a/tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs b/tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs index efdcaa8484..88d8a73e8a 100644 --- a/tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs +++ b/tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs @@ -1,16 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Common -{ - using System; - - using ImageSharp.Memory; - - using Xunit; +using System; +using SixLabors.ImageSharp.Memory; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Common +{ public class Fast2DArrayTests { private static readonly float[,] FloydSteinbergMatrix = diff --git a/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs b/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs index 21e86d434c..7b3d337ba1 100644 --- a/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs +++ b/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// + +using System.Linq; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; // ReSharper disable InconsistentNaming -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { - using System.Linq; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - - using Xunit; - /// /// Tests the class. /// diff --git a/tests/ImageSharp.Tests/Common/TestStructs.cs b/tests/ImageSharp.Tests/Common/TestStructs.cs index f7f09bea20..87cf9a6325 100644 --- a/tests/ImageSharp.Tests/Common/TestStructs.cs +++ b/tests/ImageSharp.Tests/Common/TestStructs.cs @@ -1,7 +1,10 @@ -namespace ImageSharp.Tests.Common -{ - using Xunit; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using Xunit; +namespace SixLabors.ImageSharp.Tests.Common +{ public static class TestStructs { public struct Foo diff --git a/tests/ImageSharp.Tests/ConfigurationTests.cs b/tests/ImageSharp.Tests/ConfigurationTests.cs index 417588180a..ad631863f4 100644 --- a/tests/ImageSharp.Tests/ConfigurationTests.cs +++ b/tests/ImageSharp.Tests/ConfigurationTests.cs @@ -1,21 +1,18 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.IO; +using SixLabors.ImageSharp.PixelFormats; +using Moq; +using Xunit; + +namespace SixLabors.ImageSharp.Tests { - using System; - using System.Collections.Generic; - using System.IO; - using System.Linq; - - using ImageSharp.Formats; - using ImageSharp.IO; - using ImageSharp.PixelFormats; - using Moq; - using Xunit; - /// /// Tests the configuration class. /// diff --git a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs index 7ddc2de5a4..0b0a474834 100644 --- a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs @@ -1,21 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Drawing -{ - using Drawing; - using ImageSharp.Drawing; - using System; - using System.Diagnostics.CodeAnalysis; - using System.IO; - using System.Numerics; - - using ImageSharp.PixelFormats; - - using Xunit; +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Numerics; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.Drawing; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Drawing +{ public class Beziers : FileTestBase { [Fact] @@ -24,15 +20,15 @@ public void ImageShouldBeOverlayedByBezierLine() string path = this.CreateOutputDirectory("Drawing", "BezierLine"); using (Image image = new Image(500, 500)) { - image.BackgroundColor(Rgba32.Blue) + image.Mutate(x => x.BackgroundColor(Rgba32.Blue) .DrawBeziers(Rgba32.HotPink, 5, new SixLabors.Primitives.PointF[] { new Vector2(10, 400), new Vector2(30, 10), new Vector2(240, 30), new Vector2(300, 400) - }) - .Save($"{path}/Simple.png"); + })); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -63,7 +59,7 @@ public void ImageShouldBeOverlayedBezierLineWithOpacity() using (Image image = new Image(500, 500)) { - image.BackgroundColor(Rgba32.Blue) + image.Mutate(x => x.BackgroundColor(Rgba32.Blue) .DrawBeziers(color, 10, new SixLabors.Primitives.PointF[]{ @@ -71,8 +67,8 @@ public void ImageShouldBeOverlayedBezierLineWithOpacity() new Vector2(30, 10), new Vector2(240, 30), new Vector2(300, 400) - }) - .Save($"{path}/Opacity.png"); + })); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); diff --git a/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs b/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs index 40a1cb3d3c..df029d2d72 100644 --- a/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs +++ b/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs @@ -1,18 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Drawing -{ - using System; - using System.Linq; - using System.Collections.Generic; - using System.Text; - using ImageSharp.PixelFormats; - using Xunit; - using SixLabors.Primitives; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Drawing +{ public class BlendedShapes { public static IEnumerable modes = ((PixelBlenderMode[])Enum.GetValues(typeof(PixelBlenderMode))) @@ -27,11 +25,12 @@ public void DrawBlendedValues(TestImageProvider provider, PixelB { var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); - img.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)); - img.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) - { - BlenderMode = mode - }); + img.Mutate(x=>x + .Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)) + .Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) + { + BlenderMode = mode + })); img.DebugSave(provider, new { mode }); } } @@ -45,15 +44,15 @@ public void DrawBlendedValues_transparent(TestImageProvider prov { var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); - img.Fill(NamedColors.DarkBlue, new Rectangle(0* scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)); - img.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) + img.Mutate(x=>x.Fill(NamedColors.DarkBlue, new Rectangle(0* scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY))); + img.Mutate(x => x.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) { BlenderMode = mode - }); - img.Fill(NamedColors.Transparent, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true) + })); + img.Mutate(x => x.Fill(NamedColors.Transparent, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true) { BlenderMode = mode - }); + })); img.DebugSave(provider, new { mode }); } } @@ -67,20 +66,20 @@ public void DrawBlendedValues_transparent50Percent(TestImageProvider.DarkBlue, new Rectangle(0 * scaleX, 40, 100 * scaleX, 20* scaleY)); - img.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) + img.Mutate(x=>x.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40, 100 * scaleX, 20* scaleY))); + img.Mutate(x => x.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) { BlenderMode = mode - }); + })); var c = NamedColors.Red.ToVector4(); c.W *= 0.5f; TPixel pixel = default(TPixel); pixel.PackFromVector4(c); - img.Fill(pixel, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true) + img.Mutate(x => x.Fill(pixel, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true) { BlenderMode = mode - }); + })); img.DebugSave(provider, new { mode }); } } @@ -96,16 +95,11 @@ public void DrawBlendedValues_doldidEllips(TestImageProvider pro { var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); - img.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40* scaleY, 100 * scaleX, 20 * scaleY)); - //img.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) - //{ - // BlenderMode = mode - //}); - - img.Fill(NamedColors.Black, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true) + img.Mutate(x => x.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40* scaleY, 100 * scaleX, 20 * scaleY))); + img.Mutate(x => x.Fill(NamedColors.Black, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true) { BlenderMode = mode - }); + })); img.DebugSave(provider, new { mode }); } } diff --git a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs index 728ed749a2..94dd903b43 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System.IO; - using System.Linq; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using System.IO; +using System.Linq; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ public class DrawImageTest : FileTestBase { private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32; @@ -40,8 +38,8 @@ public void ImageShouldApplyDrawImage(TestImageProvider provider using (Image image = provider.GetImage()) using (Image blend = Image.Load(TestFile.Create(TestImages.Bmp.Car).Bytes)) { - image.DrawImage(blend, mode, .75f, new Size(image.Width / 2, image.Height / 2), new Point(image.Width / 4, image.Height / 4)) - .DebugSave(provider, new { mode }); + image.Mutate(x => x.DrawImage(blend, mode, .75f, new Size(image.Width / 2, image.Height / 2), new Point(image.Width / 4, image.Height / 4))); + image.DebugSave(provider, new { mode }); } } } diff --git a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs index da5028f04f..10d31a0d18 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs @@ -1,20 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Drawing -{ - using ShapePath = SixLabors.Shapes.Path; - using SixLabors.Shapes; - using System.IO; - using System.Numerics; - - using ImageSharp.PixelFormats; - - using Xunit; - using ImageSharp.Drawing.Pens; +using System.IO; +using System.Numerics; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Shapes; +using Xunit; +using ShapePath = SixLabors.Shapes.Path; +namespace SixLabors.ImageSharp.Tests.Drawing +{ public class DrawPathTests : FileTestBase { [Fact] @@ -34,10 +30,10 @@ public void ImageShouldBeOverlayedByPath() ShapePath p = new ShapePath(linerSegemnt, bazierSegment); - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(Rgba32.HotPink, 5, p) - .Save($"{path}/Simple.png"); + .Draw(Rgba32.HotPink, 5, p)); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -74,10 +70,10 @@ public void ImageShouldBeOverlayedPathWithOpacity() using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(color, 10, p) - .Save($"{path}/Opacity.png"); + .Draw(color, 10, p)); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); @@ -101,12 +97,12 @@ public void PathExtendingOffEdgeOfImageShouldNotBeCropped() string path = this.CreateOutputDirectory("Drawing", "Path"); using (var image = new Image(256, 256)) { - image.Fill(Rgba32.Black); + image.Mutate(x => x.Fill(Rgba32.Black)); var pen = Pens.Solid(Rgba32.White, 5f); for (int i = 0; i < 300; i += 20) { - image.DrawLines(pen, new SixLabors.Primitives.PointF[] { new Vector2(100, 2), new Vector2(-10, i) }); + image.Mutate(x => x.DrawLines(pen, new SixLabors.Primitives.PointF[] { new Vector2(100, 2), new Vector2(-10, i) })); } image diff --git a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs index bbabdf0ea6..10988e9d13 100644 --- a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs @@ -1,19 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Drawing -{ - using System; - using System.IO; - - using ImageSharp.Drawing; - using ImageSharp.Drawing.Brushes; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using Xunit; +using System; +using System.IO; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Drawing +{ public class FillPatternBrushTests : FileTestBase { private void Test(string name, Rgba32 background, IBrush brush, Rgba32[,] expectedPattern) @@ -21,9 +18,9 @@ private void Test(string name, Rgba32 background, IBrush brush, Rgba32[, string path = this.CreateOutputDirectory("Fill", "PatternBrush"); using (Image image = new Image(20, 20)) { - image + image.Mutate(x => x .Fill(background) - .Fill(brush); + .Fill(brush)); image.Save($"{path}/{name}.png"); @@ -51,7 +48,8 @@ private void Test(string name, Rgba32 background, IBrush brush, Rgba32[, } } } - image.Resize(80, 80).Save($"{path}/{name}x4.png"); + image.Mutate(x => x.Resize(80, 80)); + image.Save($"{path}/{name}x4.png"); } } diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs index b04a413857..fbdd04e64e 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs @@ -1,17 +1,18 @@ - -namespace ImageSharp.Tests.Drawing -{ - using ImageSharp; - using Xunit; - using ImageSharp.Drawing; - using ImageSharp.Drawing.Processors; - using Moq; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using ImageSharp.PixelFormats; - using System; - using ImageSharp.Drawing.Pens; - using System.Numerics; +using System; +using System.Numerics; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.PixelFormats; +using Moq; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Drawing +{ public class FillRegionProcessorTests { [Theory] @@ -71,18 +72,16 @@ public void FillOffCanvas() processor.Apply(img, bounds); } - - [Fact] public void DrawOffCanvas() { using (var img = new Image(10, 10)) { - img.DrawLines(new Pen(Rgba32.Black, 10), new SixLabors.Primitives.PointF[] { + img.Mutate(x => x.DrawLines(new Pen(Rgba32.Black, 10), new SixLabors.Primitives.PointF[] { new Vector2(-10, 5), new Vector2(20, 5), - }); + })); } } } diff --git a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs index ce127cfe03..9d64d63191 100644 --- a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs @@ -1,21 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Drawing -{ - using Drawing; - using ImageSharp.Drawing; - using System; - using System.Diagnostics.CodeAnalysis; - using System.IO; - using System.Numerics; - - using ImageSharp.PixelFormats; - - using Xunit; +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Numerics; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.Drawing; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Drawing +{ public class FillSolidBrushTests : FileTestBase { [Fact] @@ -24,8 +20,9 @@ public void ImageShouldBeFloodFilledWithColorOnDefaultBackground() string path = this.CreateOutputDirectory("Fill", "SolidBrush"); using (Image image = new Image(500, 500)) { + image.Mutate(x => x + .Fill(Rgba32.HotPink)); image - .Fill(Rgba32.HotPink) .Save($"{path}/DefaultBack.png"); using (PixelAccessor sourcePixels = image.Lock()) @@ -43,10 +40,10 @@ public void ImageShouldBeFloodFilledWithColor() string path = this.CreateOutputDirectory("Fill", "SolidBrush"); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink) - .Save($"{path}/Simple.png"); + .Fill(Rgba32.HotPink)); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -65,10 +62,10 @@ public void ImageShouldBeFloodFilledWithColorOpacity() { Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(color) - .Save($"{path}/Opacity.png"); + .Fill(color)); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); diff --git a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs index e058572fb3..3fe67a5aa1 100644 --- a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs @@ -1,20 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Drawing -{ - using System.IO; - using Xunit; - using Drawing; - using ImageSharp.Drawing; - using System.Numerics; - using ImageSharp.Drawing.Pens; - using ImageSharp.PixelFormats; - - using SixLabors.Shapes; +using System.IO; +using System.Numerics; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.Drawing; +using SixLabors.Shapes; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Drawing +{ public class LineComplexPolygonTests : FileTestBase { [Fact] @@ -34,10 +31,10 @@ public void ImageShouldBeOverlayedByPolygonOutline() using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1)) - .Save($"{path}/Simple.png"); + .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1))); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -81,10 +78,10 @@ public void ImageShouldBeOverlayedByPolygonOutlineNoOverlapping() using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1)) - .Save($"{path}/SimpleVanishHole.png"); + .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1))); + image.Save($"{path}/SimpleVanishHole.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -129,10 +126,10 @@ public void ImageShouldBeOverlayedByPolygonOutlineOverlapping() using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1)) - .Save($"{path}/SimpleOverlapping.png"); + .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1))); + image.Save($"{path}/SimpleOverlapping.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -172,10 +169,10 @@ public void ImageShouldBeOverlayedByPolygonOutlineDashed() using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(Pens.Dash(Rgba32.HotPink, 5), simplePath.Clip(hole1)) - .Save($"{path}/Dashed.png"); + .Draw(Pens.Dash(Rgba32.HotPink, 5), simplePath.Clip(hole1))); + image.Save($"{path}/Dashed.png"); } } @@ -197,10 +194,10 @@ public void ImageShouldBeOverlayedPolygonOutlineWithOpacity() using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(color, 5, simplePath.Clip(hole1)) - .Save($"{path}/Opacity.png"); + .Draw(color, 5, simplePath.Clip(hole1))); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); diff --git a/tests/ImageSharp.Tests/Drawing/LineTests.cs b/tests/ImageSharp.Tests/Drawing/LineTests.cs index f47d566967..c2d60d4adb 100644 --- a/tests/ImageSharp.Tests/Drawing/LineTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineTests.cs @@ -1,20 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Drawing -{ - using ImageSharp.Drawing; - using ImageSharp.Drawing.Pens; - - using System.IO; - using System.Numerics; - - using ImageSharp.PixelFormats; - - using Xunit; +using System.IO; +using System.Numerics; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Drawing +{ public class LineTests : FileTestBase { [Fact] @@ -23,15 +18,15 @@ public void ImageShouldBeOverlayedByPath() string path = this.CreateOutputDirectory("Drawing", "Lines"); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Rgba32.HotPink, 5, new SixLabors.Primitives.PointF[]{ new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/Simple.png"); + })); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -50,7 +45,7 @@ public void ImageShouldBeOverlayedByPath_NoAntialias() string path = this.CreateOutputDirectory("Drawing", "Lines"); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Rgba32.HotPink, 5, new SixLabors.Primitives.PointF[] { @@ -58,8 +53,8 @@ public void ImageShouldBeOverlayedByPath_NoAntialias() new Vector2(200, 150), new Vector2(50, 300) }, - new GraphicsOptions(false)) - .Save($"{path}/Simple_noantialias.png"); + new GraphicsOptions(false))); + image.Save($"{path}/Simple_noantialias.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -78,17 +73,17 @@ public void ImageShouldBeOverlayedByPathDashed() string path = this.CreateOutputDirectory("Drawing", "Lines"); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Pens.Dash(Rgba32.HotPink, 5), new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/Dashed.png"); - } + })); + image.Save($"{path}/Dashed.png"); } + } [Fact] public void ImageShouldBeOverlayedByPathDotted() @@ -96,17 +91,17 @@ public void ImageShouldBeOverlayedByPathDotted() string path = this.CreateOutputDirectory("Drawing", "Lines"); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Pens.Dot(Rgba32.HotPink, 5), new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/Dot.png"); - } + })); + image.Save($"{path}/Dot.png"); } + } [Fact] public void ImageShouldBeOverlayedByPathDashDot() @@ -114,17 +109,17 @@ public void ImageShouldBeOverlayedByPathDashDot() string path = this.CreateOutputDirectory("Drawing", "Lines"); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Pens.DashDot(Rgba32.HotPink, 5), new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/DashDot.png"); - } + })); + image.Save($"{path}/DashDot.png"); } + } [Fact] public void ImageShouldBeOverlayedByPathDashDotDot() @@ -132,15 +127,15 @@ public void ImageShouldBeOverlayedByPathDashDotDot() string path = this.CreateOutputDirectory("Drawing", "Lines"); Image image = new Image(500, 500); - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Pens.DashDotDot(Rgba32.HotPink, 5), new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/DashDotDot.png"); - } + })); + image.Save($"{path}/DashDotDot.png"); + } [Fact] public void ImageShouldBeOverlayedPathWithOpacity() @@ -151,27 +146,27 @@ public void ImageShouldBeOverlayedPathWithOpacity() Image image = new Image(500, 500); - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(color, 10, new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/Opacity.png"); + })); + image.Save($"{path}/Opacity.png"); - //shift background color towards forground color by the opacity amount - Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); + //shift background color towards forground color by the opacity amount + Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) - { - Assert.Equal(mergedColor, sourcePixels[11, 11]); + using (PixelAccessor sourcePixels = image.Lock()) + { + Assert.Equal(mergedColor, sourcePixels[11, 11]); - Assert.Equal(mergedColor, sourcePixels[199, 149]); + Assert.Equal(mergedColor, sourcePixels[199, 149]); - Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); - } + Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); } + } [Fact] public void ImageShouldBeOverlayedByPathOutline() @@ -180,27 +175,27 @@ public void ImageShouldBeOverlayedByPathOutline() Image image = new Image(500, 500); - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Rgba32.HotPink, 10, new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 10), new Vector2(200, 150), new Vector2(10, 150) - }) - .Save($"{path}/Rectangle.png"); + })); + image.Save($"{path}/Rectangle.png"); - using (PixelAccessor sourcePixels = image.Lock()) - { - Assert.Equal(Rgba32.HotPink, sourcePixels[11, 11]); + using (PixelAccessor sourcePixels = image.Lock()) + { + Assert.Equal(Rgba32.HotPink, sourcePixels[11, 11]); - Assert.Equal(Rgba32.HotPink, sourcePixels[198, 10]); + Assert.Equal(Rgba32.HotPink, sourcePixels[198, 10]); - Assert.Equal(Rgba32.Blue, sourcePixels[10, 50]); + Assert.Equal(Rgba32.Blue, sourcePixels[10, 50]); - Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); - } + Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); } - } + } +} diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs index 3a2b66c3c2..a88a5b09cd 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs @@ -1,17 +1,19 @@ - -namespace ImageSharp.Tests.Drawing.Paths +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Numerics; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Shapes; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Drawing.Paths { - using System; - using ImageSharp; - using ImageSharp.Drawing.Brushes; - using Xunit; - using ImageSharp.Drawing; - using System.Numerics; - using SixLabors.Shapes; - using ImageSharp.Drawing.Processors; - using ImageSharp.PixelFormats; - - public class FillPath : IDisposable + public class FillPath : BaseImageOperationsExtensionTest { GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; @@ -22,25 +24,12 @@ public class FillPath : IDisposable new Vector2(20,10), new Vector2(30,10), })); - private ProcessorWatchingImage img; - - public FillPath() - { - this.img = new ProcessorWatchingImage(10, 10); - } - - public void Dispose() - { - img.Dispose(); - } [Fact] public void CorrectlySetsBrushAndPath() { - img.Fill(brush, path); - - Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + this.operations.Fill(brush, path); + var processor = this.Verify>(); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -56,10 +45,8 @@ public void CorrectlySetsBrushAndPath() [Fact] public void CorrectlySetsBrushPathOptions() { - img.Fill(brush, path, noneDefault); - - Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + this.operations.Fill(brush, path, noneDefault); + var processor = this.Verify>(); Assert.Equal(noneDefault, processor.Options); @@ -73,10 +60,8 @@ public void CorrectlySetsBrushPathOptions() [Fact] public void CorrectlySetsColorAndPath() { - img.Fill(color, path); - - Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + this.operations.Fill(color, path); + var processor = this.Verify>(); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -91,10 +76,8 @@ public void CorrectlySetsColorAndPath() [Fact] public void CorrectlySetsColorPathAndOptions() { - img.Fill(color, path, noneDefault); - - Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + this.operations.Fill(color, path, noneDefault); + var processor = this.Verify>(); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs index 24efa976e8..e8fad9d125 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs @@ -1,17 +1,19 @@ - -namespace ImageSharp.Tests.Drawing.Paths +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Numerics; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Shapes; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Drawing.Paths { - using System; - using ImageSharp; - using ImageSharp.Drawing.Brushes; - using Xunit; - using ImageSharp.Drawing; - using System.Numerics; - using SixLabors.Shapes; - using ImageSharp.Drawing.Processors; - using ImageSharp.PixelFormats; - - public class FillPathCollection : IDisposable + public class FillPathCollection : BaseImageOperationsExtensionTest { GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; @@ -30,29 +32,20 @@ public class FillPathCollection : IDisposable })); IPathCollection pathCollection; - - private ProcessorWatchingImage img; - + public FillPathCollection() { this.pathCollection = new PathCollection(path1, path2); - this.img = new ProcessorWatchingImage(10, 10); - } - - public void Dispose() - { - img.Dispose(); } [Fact] public void CorrectlySetsBrushAndPath() { - img.Fill(brush, pathCollection); + this.operations.Fill(brush, pathCollection); - Assert.Equal(2, img.ProcessorApplications.Count); for (var i = 0; i < 2; i++) { - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[i].processor); + FillRegionProcessor processor = this.Verify>(i); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -69,12 +62,11 @@ public void CorrectlySetsBrushAndPath() [Fact] public void CorrectlySetsBrushPathOptions() { - img.Fill(brush, pathCollection, noneDefault); + this.operations.Fill(brush, pathCollection, noneDefault); - Assert.Equal(2, img.ProcessorApplications.Count); for (var i = 0; i < 2; i++) { - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[i].processor); + FillRegionProcessor processor = this.Verify>(i); Assert.Equal(noneDefault, processor.Options); @@ -89,12 +81,11 @@ public void CorrectlySetsBrushPathOptions() [Fact] public void CorrectlySetsColorAndPath() { - img.Fill(color, pathCollection); + this.operations.Fill(color, pathCollection); - Assert.Equal(2, img.ProcessorApplications.Count); for (var i = 0; i < 2; i++) { - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[i].processor); + FillRegionProcessor processor = this.Verify>(i); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -110,12 +101,11 @@ public void CorrectlySetsColorAndPath() [Fact] public void CorrectlySetsColorPathAndOptions() { - img.Fill(color, pathCollection, noneDefault); + this.operations.Fill(color, pathCollection, noneDefault); - Assert.Equal(2, img.ProcessorApplications.Count); for (var i = 0; i < 2; i++) { - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[i].processor); + FillRegionProcessor processor = this.Verify>(i); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs index b46d3d0d9c..b390c31069 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs @@ -1,17 +1,19 @@ - -namespace ImageSharp.Tests.Drawing.Paths +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Numerics; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Shapes; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Drawing.Paths { - using System; - using ImageSharp; - using ImageSharp.Drawing.Brushes; - using Xunit; - using ImageSharp.Drawing; - using System.Numerics; - using SixLabors.Shapes; - using ImageSharp.Drawing.Processors; - using ImageSharp.PixelFormats; - - public class FillPolygon : IDisposable + public class FillPolygon : BaseImageOperationsExtensionTest { GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; @@ -22,25 +24,14 @@ public class FillPolygon : IDisposable new Vector2(20,10), new Vector2(30,10), }; - private ProcessorWatchingImage img; - public FillPolygon() - { - this.img = new Paths.ProcessorWatchingImage(10, 10); - } - - public void Dispose() - { - img.Dispose(); - } [Fact] public void CorrectlySetsBrushAndPath() { - img.FillPolygon(brush, path); + this.operations.FillPolygon(brush, path); - Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = this.Verify>(); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -54,10 +45,8 @@ public void CorrectlySetsBrushAndPath() [Fact] public void CorrectlySetsBrushPathAndOptions() { - img.FillPolygon(brush, path, noneDefault); - - Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + this.operations.FillPolygon(brush, path, noneDefault); + FillRegionProcessor processor = this.Verify>(); Assert.Equal(noneDefault, processor.Options); @@ -71,10 +60,9 @@ public void CorrectlySetsBrushPathAndOptions() [Fact] public void CorrectlySetsColorAndPath() { - img.FillPolygon(color, path); + this.operations.FillPolygon(color, path); + FillRegionProcessor processor = this.Verify>(); - Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -89,10 +77,9 @@ public void CorrectlySetsColorAndPath() [Fact] public void CorrectlySetsColorPathAndOptions() { - img.FillPolygon(color, path, noneDefault); + this.operations.FillPolygon(color, path, noneDefault); + FillRegionProcessor processor = this.Verify>(); - Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs index 7e6a3deee5..05e6bb29b3 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs @@ -1,41 +1,27 @@ - -namespace ImageSharp.Tests.Drawing.Paths -{ - using System; - - using ImageSharp.Drawing.Brushes; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; - using ImageSharp.Drawing; - using ImageSharp.Drawing.Processors; - using ImageSharp.PixelFormats; +using System; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; - public class FillRectangle : IDisposable +namespace SixLabors.ImageSharp.Tests.Drawing.Paths +{ + public class FillRectangle : BaseImageOperationsExtensionTest { GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; SolidBrush brush = Brushes.Solid(Rgba32.HotPink); SixLabors.Primitives.Rectangle rectangle = new SixLabors.Primitives.Rectangle(10, 10, 77, 76); - private ProcessorWatchingImage img; - - public FillRectangle() - { - this.img = new Paths.ProcessorWatchingImage(10, 10); - } - - public void Dispose() - { - img.Dispose(); - } - [Fact] public void CorrectlySetsBrushAndRectangle() { - img.Fill(brush, rectangle); - - Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + this.operations.Fill(brush, rectangle); + FillRegionProcessor processor = this.Verify>(); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -52,10 +38,8 @@ public void CorrectlySetsBrushAndRectangle() [Fact] public void CorrectlySetsBrushRectangleAndOptions() { - img.Fill(brush, rectangle, noneDefault); - - Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + this.operations.Fill(brush, rectangle, noneDefault); + FillRegionProcessor processor = this.Verify>(); Assert.Equal(noneDefault, processor.Options); @@ -72,11 +56,9 @@ public void CorrectlySetsBrushRectangleAndOptions() [Fact] public void CorrectlySetsColorAndRectangle() { - img.Fill(color, rectangle); - - Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); - + this.operations.Fill(color, rectangle); + FillRegionProcessor processor = this.Verify>(); + Assert.Equal(GraphicsOptions.Default, processor.Options); ShapeRegion region = Assert.IsType(processor.Region); @@ -93,10 +75,8 @@ public void CorrectlySetsColorAndRectangle() [Fact] public void CorrectlySetsColorRectangleAndOptions() { - img.Fill(color, rectangle, noneDefault); - - Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + this.operations.Fill(color, rectangle, noneDefault); + FillRegionProcessor processor = this.Verify>(); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs b/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs deleted file mode 100644 index 1670b33520..0000000000 --- a/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs +++ /dev/null @@ -1,40 +0,0 @@ - -namespace ImageSharp.Tests.Drawing.Paths -{ - using System; - using System.IO; - using ImageSharp; - using ImageSharp.Processing; - using System.Collections.Generic; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - - /// - /// Watches but does not actually run the processors against the image. - /// - /// - public class ProcessorWatchingImage : Image - { - public List ProcessorApplications { get; } = new List(); - - public ProcessorWatchingImage(int width, int height) - : base(Configuration.CreateDefaultInstance(), width, height) - { - } - - public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) - { - this.ProcessorApplications.Add(new ProcessorDetails - { - processor = processor, - rectangle = rectangle - }); - } - - public struct ProcessorDetails - { - public IImageProcessor processor; - public Rectangle rectangle; - } - } -} diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs index e791a2bfb7..5d2e93e877 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs @@ -1,21 +1,23 @@ - -namespace ImageSharp.Tests.Drawing.Paths -{ - using System; - using System.IO; - using ImageSharp; - using ImageSharp.Drawing.Brushes; - using ImageSharp.Processing; - using System.Collections.Generic; - using Xunit; - using ImageSharp.Drawing; - using System.Numerics; - using SixLabors.Shapes; - using ImageSharp.Drawing.Processors; - using ImageSharp.Drawing.Pens; - using Moq; - using System.Collections.Immutable; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.IO; +using System.Numerics; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.Processing; +using Moq; +using SixLabors.Shapes; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Drawing.Paths +{ public class ShapePathTests { // TODO readd these back in diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs index df183a8aff..41fb5643f0 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs @@ -1,22 +1,24 @@ - -namespace ImageSharp.Tests.Drawing.Paths +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.IO; +using System.Numerics; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.Processing; +using Moq; +using SixLabors.Primitives; +using SixLabors.Shapes; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Drawing.Paths { - using System; - using System.IO; - using ImageSharp; - using ImageSharp.Drawing.Brushes; - using ImageSharp.Processing; - using System.Collections.Generic; - using Xunit; - using ImageSharp.Drawing; - using System.Numerics; - using SixLabors.Shapes; - using ImageSharp.Drawing.Processors; - using ImageSharp.Drawing.Pens; - using Moq; - using System.Collections.Immutable; - using SixLabors.Primitives; - public class ShapeRegionTests { private readonly Mock pathMock; diff --git a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs index 501b10e4af..996387d14c 100644 --- a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs @@ -1,21 +1,18 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Drawing +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Numerics; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.Drawing; +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Drawing { - using System; - using System.Diagnostics.CodeAnalysis; - using System.IO; - using Xunit; - using Drawing; - using ImageSharp.Drawing; - using System.Numerics; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - public class PolygonTests : FileTestBase { [Fact] @@ -25,15 +22,15 @@ public void ImageShouldBeOverlayedByPolygonOutline() using (Image image = new Image(500, 500)) { - image - .BackgroundColor(Rgba32.Blue) - .DrawPolygon(Rgba32.HotPink, 5, - new SixLabors.Primitives.PointF[] { + image.Mutate(x => x + .BackgroundColor(Rgba32.Blue) + .DrawPolygon(Rgba32.HotPink, 5, + new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/Simple.png"); + })); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -62,10 +59,10 @@ public void ImageShouldBeOverlayedPolygonOutlineWithOpacity() using (Image image = new Image(500, 500)) { - image - .BackgroundColor(Rgba32.Blue) - .DrawPolygon(color, 10, simplePath) - .Save($"{path}/Opacity.png"); + image.Mutate(x => x + .BackgroundColor(Rgba32.Blue) + .DrawPolygon(color, 10, simplePath)); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); @@ -90,10 +87,10 @@ public void ImageShouldBeOverlayedByRectangleOutline() using (Image image = new Image(500, 500)) { - image - .BackgroundColor(Rgba32.Blue) - .Draw(Rgba32.HotPink, 10, new Rectangle(10, 10, 190, 140)) - .Save($"{path}/Rectangle.png"); + image.Mutate(x => x + .BackgroundColor(Rgba32.Blue) + .Draw(Rgba32.HotPink, 10, new Rectangle(10, 10, 190, 140))); + image.Save($"{path}/Rectangle.png"); using (PixelAccessor sourcePixels = image.Lock()) { diff --git a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs index 9c62e860a8..d2bbdbb052 100644 --- a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs @@ -1,19 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using ImageSharp.Drawing.Brushes; - using System.IO; - using System.Linq; - - using ImageSharp.PixelFormats; - - using Xunit; - using SixLabors.Primitives; +using System.IO; +using System.Linq; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ public class RecolorImageTest : FileTestBase { [Fact] @@ -27,8 +23,8 @@ public void ImageShouldRecolorYellowToHotPink() { using (Image image = file.CreateImage()) { - image.Fill(brush) - .Save($"{path}/{file.FileName}"); + image.Mutate(x => x.Fill(brush)); + image.Save($"{path}/{file.FileName}"); } } } @@ -45,8 +41,8 @@ public void ImageShouldRecolorYellowToHotPinkInARectangle() using (Image image = file.CreateImage()) { int imageHeight = image.Height; - image.Fill(brush, new Rectangle(0, imageHeight / 2 - imageHeight / 4, image.Width, imageHeight / 2)) - .Save($"{path}/Shaped_{file.FileName}"); + image.Mutate(x => x.Fill(brush, new Rectangle(0, imageHeight / 2 - imageHeight / 4, image.Width, imageHeight / 2))); + image.Save($"{path}/Shaped_{file.FileName}"); } } } diff --git a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs index ba904cb3f2..0ddd99712e 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs @@ -1,19 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Drawing -{ - using System.IO; - using System.Numerics; - - using ImageSharp.PixelFormats; - - using SixLabors.Shapes; - - using Xunit; +using System.IO; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Shapes; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Drawing +{ public class SolidBezierTests : FileTestBase { [Fact] @@ -28,10 +23,10 @@ public void ImageShouldBeOverlayedByFilledPolygon() }; using (Image image = new Image(500, 500)) { - image - .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink, new Polygon(new CubicBezierLineSegment(simplePath))) - .Save($"{path}/Simple.png"); + image.Mutate(x => x + .BackgroundColor(Rgba32.Blue) + .Fill(Rgba32.HotPink, new Polygon(new CubicBezierLineSegment(simplePath)))); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -60,10 +55,10 @@ public void ImageShouldBeOverlayedByFilledPolygonOpacity() using (Image image = new Image(500, 500)) { - image - .BackgroundColor(Rgba32.Blue) - .Fill(color, new Polygon(new CubicBezierLineSegment(simplePath))) - .Save($"{path}/Opacity.png"); + image.Mutate(x => x + .BackgroundColor(Rgba32.Blue) + .Fill(color, new Polygon(new CubicBezierLineSegment(simplePath)))); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); diff --git a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs index c3af3d5c28..8bad1a6b06 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs @@ -1,20 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Drawing -{ - using System.IO; - using Xunit; - using Drawing; - using ImageSharp.Drawing; - using System.Numerics; - - using ImageSharp.PixelFormats; - - using SixLabors.Shapes; +using System.IO; +using System.Numerics; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.Drawing; +using SixLabors.Shapes; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Drawing +{ public class SolidComplexPolygonTests : FileTestBase { [Fact] @@ -34,10 +30,10 @@ public void ImageShouldBeOverlayedByPolygonOutline() // var clipped = new Rectangle(10, 10, 100, 100).Clip(new Rectangle(20, 0, 20, 20)); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink, clipped) - .Save($"{path}/Simple.png"); + .Fill(Rgba32.HotPink, clipped)); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -66,10 +62,10 @@ public void ImageShouldBeOverlayedPolygonOutlineWithOverlap() using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink, simplePath.Clip(hole1)) - .Save($"{path}/SimpleOverlapping.png"); + .Fill(Rgba32.HotPink, simplePath.Clip(hole1))); + image.Save($"{path}/SimpleOverlapping.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -98,10 +94,10 @@ public void ImageShouldBeOverlayedPolygonOutlineWithOpacity() using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(color, simplePath.Clip(hole1)) - .Save($"{path}/Opacity.png"); + .Fill(color, simplePath.Clip(hole1))); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); diff --git a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs index 793bcfc9f0..10625dedbf 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs @@ -1,22 +1,19 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Drawing +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Numerics; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.Drawing; +using SixLabors.Shapes; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Drawing { - using Drawing; - using ImageSharp.Drawing; - using System; - using System.Diagnostics.CodeAnalysis; - using System.IO; - using System.Numerics; - using Xunit; - using ImageSharp.Drawing.Brushes; - using ImageSharp.PixelFormats; - - using SixLabors.Shapes; - public class SolidPolygonTests : FileTestBase { [Fact] @@ -31,9 +28,9 @@ public void ImageShouldBeOverlayedByFilledPolygon() using (Image image = new Image(500, 500)) { - image - .FillPolygon(Rgba32.HotPink, simplePath, new GraphicsOptions(true)) - .Save($"{path}/Simple.png"); + image.Mutate(x => x + .FillPolygon(Rgba32.HotPink, simplePath, new GraphicsOptions(true))); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -54,9 +51,9 @@ public void ImageShouldBeOverlayedByFilledPolygonWithPattern() using (Image image = new Image(500, 500)) { - image - .FillPolygon(Brushes.Horizontal(Rgba32.HotPink), simplePath, new GraphicsOptions(true)) - .Save($"{path}/Pattern.png"); + image.Mutate(x => x + .FillPolygon(Brushes.Horizontal(Rgba32.HotPink), simplePath, new GraphicsOptions(true))); + image.Save($"{path}/Pattern.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -77,10 +74,10 @@ public void ImageShouldBeOverlayedByFilledPolygonNoAntialias() using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .FillPolygon(Rgba32.HotPink, simplePath, new GraphicsOptions(false)) - .Save($"{path}/Simple_NoAntialias.png"); + .FillPolygon(Rgba32.HotPink, simplePath, new GraphicsOptions(false))); + image.Save($"{path}/Simple_NoAntialias.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -110,10 +107,10 @@ public void ImageShouldBeOverlayedByFilledPolygonImage() { ImageBrush brush = new ImageBrush(brushImage); - image - .BackgroundColor(Rgba32.Blue) - .FillPolygon(brush, simplePath) - .Save($"{path}/Image.png"); + image.Mutate(x => x + .BackgroundColor(Rgba32.Blue) + .FillPolygon(brush, simplePath)); + image.Save($"{path}/Image.png"); } } @@ -130,10 +127,10 @@ public void ImageShouldBeOverlayedByFilledPolygonOpacity() using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .FillPolygon(color, simplePath) - .Save($"{path}/Opacity.png"); + .FillPolygon(color, simplePath)); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); @@ -152,10 +149,10 @@ public void ImageShouldBeOverlayedByFilledRectangle() using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink, new SixLabors.Shapes.RectangularePolygon(10, 10, 190, 140)) - .Save($"{path}/Rectangle.png"); + .Fill(Rgba32.HotPink, new SixLabors.Shapes.RectangularePolygon(10, 10, 190, 140))); + image.Save($"{path}/Rectangle.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -179,10 +176,10 @@ public void ImageShouldBeOverlayedByFilledTriangle() using (Image image = new Image(100, 100)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink, new RegularPolygon(50, 50, 3, 30)) - .Save($"{path}/Triangle.png"); + .Fill(Rgba32.HotPink, new RegularPolygon(50, 50, 3, 30))); + image.Save($"{path}/Triangle.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -202,10 +199,10 @@ public void ImageShouldBeOverlayedByFilledSeptagon() config.ParallelOptions.MaxDegreeOfParallelism = 1; using (Image image = new Image(config, 100, 100)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink, new RegularPolygon(50, 50, 7, 30, -(float)Math.PI)) - .Save($"{path}/Septagon.png"); + .Fill(Rgba32.HotPink, new RegularPolygon(50, 50, 7, 30, -(float)Math.PI))); + image.Save($"{path}/Septagon.png"); } } @@ -218,11 +215,11 @@ public void ImageShouldBeOverlayedByFilledEllipse() config.ParallelOptions.MaxDegreeOfParallelism = 1; using (Image image = new Image(config, 100, 100)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .Fill(Rgba32.HotPink, new EllipsePolygon(50, 50, 30, 50) - .Rotate((float)(Math.PI / 3))) - .Save($"{path}/ellipse.png"); + .Rotate((float)(Math.PI / 3)))); + image.Save($"{path}/ellipse.png"); } } @@ -235,7 +232,7 @@ public void ImageShouldBeOverlayedBySquareWithCornerClipped() config.ParallelOptions.MaxDegreeOfParallelism = 1; using (Image image = new Image(config, 200, 200)) { - image + image.Mutate(x => x .Fill(Rgba32.Blue) .FillPolygon(Rgba32.HotPink, new SixLabors.Primitives.PointF[] { @@ -245,8 +242,8 @@ public void ImageShouldBeOverlayedBySquareWithCornerClipped() new Vector2( 120, 64 ), new Vector2( 120, 120 ), new Vector2( 8, 120 ) - }) - .Save($"{path}/clipped-corner.png"); + })); + image.Save($"{path}/clipped-corner.png"); } } } diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs index 05a1f1e363..3f138248eb 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs @@ -1,26 +1,21 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Drawing.Text +using System; +using System.Numerics; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.Drawing.Paths; +using SixLabors.Fonts; +using SixLabors.Shapes; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Drawing.Text { - using System; - using System.Numerics; - - using ImageSharp.Drawing; - using ImageSharp.Drawing.Brushes; - using ImageSharp.Drawing.Pens; - using ImageSharp.Drawing.Processors; - using ImageSharp.PixelFormats; - using ImageSharp.Tests.Drawing.Paths; - - using SixLabors.Fonts; - using SixLabors.Shapes; - - using Xunit; - - public class DrawText_Path : IDisposable + public class DrawText_Path : BaseImageOperationsExtensionTest { Rgba32 color = Rgba32.HotPink; @@ -30,8 +25,6 @@ public class DrawText_Path : IDisposable new LinearLineSegment( new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(20, 10), new Vector2(20, 10), new Vector2(30, 10), })); - private ProcessorWatchingImage img; - private readonly FontCollection FontCollection; private readonly Font Font; @@ -40,18 +33,12 @@ public DrawText_Path() { this.FontCollection = new FontCollection(); this.Font = this.FontCollection.Install(TestFontUtilities.GetPath("SixLaborsSampleAB.woff")).CreateFont(12); - this.img = new ProcessorWatchingImage(10, 10); - } - - public void Dispose() - { - this.img.Dispose(); } [Fact] public void FillsForEachACharachterWhenBrushSetAndNotPen() { - this.img.DrawText( + this.operations.DrawText( "123", this.Font, Brushes.Solid(Rgba32.Red), @@ -59,50 +46,49 @@ public void FillsForEachACharachterWhenBrushSetAndNotPen() path, new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void FillsForEachACharachterWhenBrushSetAndNotPenDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, path); + this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, path); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void FillsForEachACharachterWhenBrushSet() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path, new TextGraphicsOptions(true)); + this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path, new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void FillsForEachACharachterWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path); + this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void FillsForEachACharachterWhenColorSet() { - this.img.DrawText("123", this.Font, Rgba32.Red, path, new TextGraphicsOptions(true)); + this.operations.DrawText("123", this.Font, Rgba32.Red, path, new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); - FillRegionProcessor processor = - Assert.IsType>(this.img.ProcessorApplications[0].processor); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(Rgba32.Red, brush.Color); @@ -111,13 +97,11 @@ public void FillsForEachACharachterWhenColorSet() [Fact] public void FillsForEachACharachterWhenColorSetDefaultOptions() { - this.img.DrawText("123", this.Font, Rgba32.Red, path); + this.operations.DrawText("123", this.Font, Rgba32.Red, path); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - FillRegionProcessor processor = - Assert.IsType>(this.img.ProcessorApplications[0].processor); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(Rgba32.Red, brush.Color); @@ -126,7 +110,7 @@ public void FillsForEachACharachterWhenColorSetDefaultOptions() [Fact] public void DrawForEachACharachterWhenPenSetAndNotBrush() { - this.img.DrawText( + this.operations.DrawText( "123", this.Font, null, @@ -134,45 +118,45 @@ public void DrawForEachACharachterWhenPenSetAndNotBrush() path, new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions() { - this.img.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), path); + this.operations.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), path); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void DrawForEachACharachterWhenPenSet() { - this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path, new TextGraphicsOptions(true)); + this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path, new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void DrawForEachACharachterWhenPenSetDefaultOptions() { - this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path); + this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet() { - this.img.DrawText( + this.operations.DrawText( "123", this.Font, Brushes.Solid(Rgba32.Red), @@ -180,72 +164,49 @@ public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet() path, new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(6, this.img.ProcessorApplications.Count); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); + this.Verify>(3); + this.Verify>(4); + this.Verify>(5); } [Fact] public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path); + this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(6, this.img.ProcessorApplications.Count); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); + this.Verify>(3); + this.Verify>(4); + this.Verify>(5); } [Fact] public void BrushAppliesBeforPen() { - this.img.DrawText( + this.operations.DrawText( "1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path, - new TextGraphicsOptions(true)); + new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(2, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); + var processor = this.Verify>(0); + this.Verify>(1); } [Fact] public void BrushAppliesBeforPenDefaultOptions() { - this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path); - - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(2, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); - } + this.operations.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path); - [Fact] - public void GlyphHeightChangesBasedOnuseImageResolutionFlag() - { - this.img.MetaData.VerticalResolution = 1; - this.img.MetaData.HorizontalResolution = 1; - this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), path, new TextGraphicsOptions(true) { - UseImageResolution = false - }); - - this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), path, new TextGraphicsOptions(true) - { - UseImageResolution = true - }); - - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(2, this.img.ProcessorApplications.Count); - FillRegionProcessor ownResolution = Assert.IsType>(this.img.ProcessorApplications[0].processor); - FillRegionProcessor imgResolution = Assert.IsType>(this.img.ProcessorApplications[1].processor); - - ShapeRegion ownRegion = Assert.IsType(ownResolution.Region); - ShapeRegion imgRegion = Assert.IsType(imgResolution.Region); - - // magic numbers based on the font used at well known resolutions - Assert.Equal(7.44, ownRegion.Shape.Bounds.Height, 2); - Assert.Equal(0.1, imgRegion.Shape.Bounds.Height, 2); + var processor = this.Verify>(0); + this.Verify>(1); } } } diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs index 1c8c9f1d16..d9fe1a76db 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs @@ -1,26 +1,21 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Drawing.Text +using System; +using System.Numerics; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.Drawing.Paths; +using SixLabors.Fonts; +using SixLabors.Shapes; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Drawing.Text { - using System; - using System.Numerics; - - using ImageSharp.Drawing; - using ImageSharp.Drawing.Brushes; - using ImageSharp.Drawing.Pens; - using ImageSharp.Drawing.Processors; - using ImageSharp.PixelFormats; - using ImageSharp.Tests.Drawing.Paths; - - using SixLabors.Fonts; - using SixLabors.Shapes; - - using Xunit; - - public class DrawText : IDisposable + public class DrawText : BaseImageOperationsExtensionTest { Rgba32 color = Rgba32.HotPink; @@ -30,8 +25,6 @@ public class DrawText : IDisposable new LinearLineSegment( new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(20, 10), new Vector2(20, 10), new Vector2(30, 10), })); - private ProcessorWatchingImage img; - private readonly FontCollection FontCollection; private readonly Font Font; @@ -40,18 +33,12 @@ public DrawText() { this.FontCollection = new FontCollection(); this.Font = this.FontCollection.Install(TestFontUtilities.GetPath("SixLaborsSampleAB.woff")).CreateFont(12); - this.img = new ProcessorWatchingImage(10, 10); - } - - public void Dispose() - { - this.img.Dispose(); } [Fact] public void FillsForEachACharachterWhenBrushSetAndNotPen() { - this.img.DrawText( + this.operations.DrawText( "123", this.Font, Brushes.Solid(Rgba32.Red), @@ -59,50 +46,49 @@ public void FillsForEachACharachterWhenBrushSetAndNotPen() Vector2.Zero, new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void FillsForEachACharachterWhenBrushSetAndNotPenDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, Vector2.Zero); + this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, Vector2.Zero); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void FillsForEachACharachterWhenBrushSet() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true)); + this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void FillsForEachACharachterWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero); + this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void FillsForEachACharachterWhenColorSet() { - this.img.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero, new TextGraphicsOptions(true)); + this.operations.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero, new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); - FillRegionProcessor processor = - Assert.IsType>(this.img.ProcessorApplications[0].processor); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(Rgba32.Red, brush.Color); @@ -111,13 +97,11 @@ public void FillsForEachACharachterWhenColorSet() [Fact] public void FillsForEachACharachterWhenColorSetDefaultOptions() { - this.img.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero); + this.operations.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - FillRegionProcessor processor = - Assert.IsType>(this.img.ProcessorApplications[0].processor); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(Rgba32.Red, brush.Color); @@ -126,7 +110,7 @@ public void FillsForEachACharachterWhenColorSetDefaultOptions() [Fact] public void DrawForEachACharachterWhenPenSetAndNotBrush() { - this.img.DrawText( + this.operations.DrawText( "123", this.Font, null, @@ -134,45 +118,45 @@ public void DrawForEachACharachterWhenPenSetAndNotBrush() Vector2.Zero, new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions() { - this.img.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), Vector2.Zero); + this.operations.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), Vector2.Zero); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void DrawForEachACharachterWhenPenSet() { - this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); + this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void DrawForEachACharachterWhenPenSetDefaultOptions() { - this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero); + this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); } [Fact] public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet() { - this.img.DrawText( + this.operations.DrawText( "123", this.Font, Brushes.Solid(Rgba32.Red), @@ -180,23 +164,32 @@ public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet() Vector2.Zero, new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(6, this.img.ProcessorApplications.Count); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); + + this.Verify>(3); + this.Verify>(4); + this.Verify>(5); } [Fact] public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero); + this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(6, this.img.ProcessorApplications.Count); + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); + this.Verify>(3); + this.Verify>(4); + this.Verify>(5); } [Fact] public void BrushAppliesBeforPen() { - this.img.DrawText( + this.operations.DrawText( "1", this.Font, Brushes.Solid(Rgba32.Red), @@ -204,48 +197,17 @@ public void BrushAppliesBeforPen() Vector2.Zero, new TextGraphicsOptions(true)); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(2, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); + var processor = this.Verify>(0); + this.Verify>(1); } [Fact] public void BrushAppliesBeforPenDefaultOptions() { - this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero); - - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(2, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); - } + this.operations.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero); - [Fact] - public void GlyphHeightChangesBasedOnuseImageResolutionFlag() - { - this.img.MetaData.VerticalResolution = 1; - this.img.MetaData.HorizontalResolution = 1; - this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true) { - UseImageResolution = false - }); - - this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true) - { - UseImageResolution = true - }); - - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(2, this.img.ProcessorApplications.Count); - FillRegionProcessor ownResolution = Assert.IsType>(this.img.ProcessorApplications[0].processor); - FillRegionProcessor imgResolution = Assert.IsType>(this.img.ProcessorApplications[1].processor); - - ShapeRegion ownRegion = Assert.IsType(ownResolution.Region); - ShapeRegion imgRegion = Assert.IsType(imgResolution.Region); - - // magic numbers based on the font used at well known resolutions - Assert.Equal(7.44, ownRegion.Shape.Bounds.Height, 2); - Assert.Equal(0.1, imgRegion.Shape.Bounds.Height, 2); + var processor = this.Verify>(0); + this.Verify>(1); } } } diff --git a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs index ce2a5becf9..07041956d6 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs @@ -1,22 +1,23 @@ - -namespace ImageSharp.Tests.Drawing.Text -{ - using System; - using System.IO; - using ImageSharp; - using ImageSharp.Drawing.Brushes; - using ImageSharp.Processing; - using System.Collections.Generic; - using Xunit; - using ImageSharp.Drawing; - using System.Numerics; - using SixLabors.Shapes; - using ImageSharp.Drawing.Processors; - using ImageSharp.Drawing.Pens; - using ImageSharp.PixelFormats; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using SixLabors.Fonts; +using System; +using System.Collections.Generic; +using System.IO; +using System.Numerics; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Drawing; +using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.Drawing.Pens; +using SixLabors.ImageSharp.Drawing.Processors; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.Fonts; +using SixLabors.Shapes; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Drawing.Text +{ public class OutputText : FileTestBase { private readonly FontCollection FontCollection; @@ -34,8 +35,8 @@ public void DrawAB() //draws 2 overlapping triangle glyphs twice 1 set on each line using (Image img = new Image(100, 200)) { - img.Fill(Rgba32.DarkBlue) - .DrawText("AB\nAB", new Font(this.Font, 50), Rgba32.Red, new Vector2(0, 0)); + img.Mutate(x => x.Fill(Rgba32.DarkBlue) + .DrawText("AB\nAB", new Font(this.Font, 50), Rgba32.Red, new Vector2(0, 0))); img.Save($"{this.CreateOutputDirectory("Drawing", "Text")}/AB.png"); } } diff --git a/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs b/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs index 1a26bcfedc..975622e43d 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs @@ -1,15 +1,17 @@ - -namespace ImageSharp.Tests.Drawing.Text -{ - using ImageSharp.Drawing; - using SixLabors.Fonts; - using System; - using System.Collections.Generic; - using System.Linq; - using System.Numerics; - using System.Threading.Tasks; - using Xunit; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Drawing; +using SixLabors.Fonts; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Drawing.Text +{ public class TextGraphicsOptionsTests { [Fact] diff --git a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs new file mode 100644 index 0000000000..f750bfcfad --- /dev/null +++ b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs @@ -0,0 +1,94 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Tests +{ + internal class FakeImageOperationsProvider : IImageProcessingContextFactory + { + private List ImageOperators = new List(); + + public bool HasCreated(Image source) + where TPixel : struct, IPixel + { + return Created(source).Any(); + } + public IEnumerable> Created(Image source) where TPixel : struct, IPixel + { + return this.ImageOperators.OfType>() + .Where(x => x.source == source); + } + + public IEnumerable.AppliedOpperation> AppliedOperations(Image source) where TPixel : struct, IPixel + { + return Created(source) + .SelectMany(x => x.applied); + } + + public IInternalImageProcessingContext CreateImageProcessingContext(Image source, bool mutate) where TPixel : struct, IPixel + { + var op = new FakeImageOperations(source, mutate); + this.ImageOperators.Add(op); + return op; + } + + + public class FakeImageOperations : IInternalImageProcessingContext + where TPixel : struct, IPixel + { + public Image source; + + public List applied = new List(); + public bool mutate; + + public FakeImageOperations(Image source, bool mutate) + { + this.mutate = mutate; + if (mutate) + { + this.source = source; + } + else + { + this.source = source?.Clone(); + } + } + + public Image Apply() + { + return source; + } + + public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + { + applied.Add(new AppliedOpperation + { + Processor = processor, + Rectangle = rectangle + }); + return this; + } + + public IImageProcessingContext ApplyProcessor(IImageProcessor processor) + { + applied.Add(new AppliedOpperation + { + Processor = processor + }); + return this; + } + public struct AppliedOpperation + { + public Rectangle? Rectangle { get; set; } + public IImageProcessor Processor { get; set; } + } + } + } +} diff --git a/tests/ImageSharp.Tests/FileTestBase.cs b/tests/ImageSharp.Tests/FileTestBase.cs index 08ed69f3e2..13a94a8b8f 100644 --- a/tests/ImageSharp.Tests/FileTestBase.cs +++ b/tests/ImageSharp.Tests/FileTestBase.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System.Collections.Generic; +using System.Collections.Generic; +namespace SixLabors.ImageSharp.Tests +{ /// /// The test base class for reading and writing to files. /// @@ -49,6 +47,11 @@ public abstract class FileTestBase : TestBase /// public const PixelTypes DefaultPixelType = PixelTypes.Rgba32; + /// + /// A few other pixel types to prove that a processor is not bound to a single one. + /// + public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector; + public static class Extensions { public const string Bmp = "bmp"; @@ -70,7 +73,9 @@ public static class Extensions // TestFile.Create(TestImages.Jpeg.Baseline.Ycck), // Perf: Enable for local testing only // TestFile.Create(TestImages.Jpeg.Baseline.Cmyk), // Perf: Enable for local testing only // TestFile.Create(TestImages.Jpeg.Baseline.Floorplan), // Perf: Enable for local testing only + // TestFile.Create(TestImages.Jpeg.Progressive.Festzug), // Perf: Enable for local testing only // TestFile.Create(TestImages.Jpeg.Baseline.Bad.MissingEOF), // Perf: Enable for local testing only + // TestFile.Create(TestImages.Jpeg.Baseline.Bad.ExifUndefType), // Perf: Enable for local testing only // TestFile.Create(TestImages.Jpeg.Progressive.Fb), // Perf: Enable for local testing only // TestFile.Create(TestImages.Jpeg.Progressive.Progress), // Perf: Enable for local testing only // TestFile.Create(TestImages.Jpeg.Baseline.GammaDalaiLamaGray), // Perf: Enable for local testing only diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs index e5af28d8b4..c3ab62b0da 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs @@ -1,16 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -using ImageSharp.Formats; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { - using ImageSharp.PixelFormats; - - using Xunit; - public class BmpEncoderTests : FileTestBase { public static readonly TheoryData BitsPerPixel diff --git a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index 4ef8fe0612..d275decfb7 100644 --- a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs +++ b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System.IO; - using ImageSharp.Formats; - using ImageSharp.PixelFormats; - - using Xunit; +using System.IO; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ public class GeneralFormatTests : FileTestBase { [Theory] @@ -22,7 +19,7 @@ public void ResolutionShouldChange(TestImageProvider provider) { image.MetaData.VerticalResolution = 150; image.MetaData.HorizontalResolution = 150; - image.DebugSave(provider, null, Extensions.Bmp); + image.DebugSave(provider); } } @@ -50,7 +47,7 @@ public void DecodeThenEncodeImageFromStreamShouldSucceed() { using (Image image = file.CreateImage()) { - image.Save($"{path}/{file.FileName}"); + image.Save($"{path}/{file.FileName}"); } } } @@ -64,31 +61,31 @@ public void QuantizeImageShouldPreserveMaximumColorPrecision() { using (Image srcImage = Image.Load(file.Bytes, out var mimeType)) { - using (Image image = new Image(srcImage)) + using (Image image = srcImage.Clone()) { using (FileStream output = File.OpenWrite($"{path}/Octree-{file.FileName}")) { - image.Quantize(Quantization.Octree) - .Save(output, mimeType); + image.Mutate(x => x.Quantize(Quantization.Octree)); + image.Save(output, mimeType); } } - using (Image image = new Image(srcImage)) + using (Image image = srcImage.Clone()) { using (FileStream output = File.OpenWrite($"{path}/Wu-{file.FileName}")) { - image.Quantize(Quantization.Wu) - .Save(output, mimeType); + image.Mutate(x => x.Quantize(Quantization.Wu)); + image.Save(output, mimeType); } } - using (Image image = new Image(srcImage)) + using (Image image = srcImage.Clone()) { using (FileStream output = File.OpenWrite($"{path}/Palette-{file.FileName}")) { - image.Quantize(Quantization.Palette) - .Save(output, mimeType); + image.Mutate(x => x.Quantize(Quantization.Palette)); + image.Save(output, mimeType); } } } diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs index 06bfd8990d..9cc2ebec49 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs @@ -1,17 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// + +using System.Text; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +using Xunit; // ReSharper disable InconsistentNaming -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { - using System.Text; - using Xunit; - - using ImageSharp.Formats; - using ImageSharp.PixelFormats; - public class GifDecoderTests { private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32; @@ -29,7 +27,20 @@ public void DecodeAndReSave(TestImageProvider imageProvider) imageProvider.Utility.SaveTestOutputFile(image, "gif"); } } - + [Theory] + [WithFileCollection(nameof(TestFiles), PixelTypes)] + public void DecodeResizeAndSave(TestImageProvider imageProvider) + where TPixel : struct, IPixel + { + using (Image image = imageProvider.GetImage()) + { + image.Mutate(x => x.Resize(new Size(image.Width / 2, image.Height / 2))); + + imageProvider.Utility.SaveTestOutputFile(image, "bmp"); + imageProvider.Utility.SaveTestOutputFile(image, "gif"); + } + } + [Fact] public void Decode_IgnoreMetadataIsFalse_CommentsAreRead() { diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs index c365396863..fb806e244d 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System.IO; - using Xunit; - - using ImageSharp.Formats; - using ImageSharp.PixelFormats; +using System.IO; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ public class GifEncoderTests { private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs index dc6985dd34..bf6b4476cc 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs @@ -1,25 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; using Xunit; using Xunit.Abstractions; + // ReSharper disable InconsistentNaming -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { - using System.Numerics; - - using ImageSharp.Formats.Jpg; - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - public class BadEOFJpegTests : MeasureFixture { public BadEOFJpegTests(ITestOutputHelper output) @@ -35,7 +24,7 @@ public void LoadBaselineImage(TestImageProvider provider) using (Image image = provider.GetImage()) { Assert.NotNull(image); - provider.Utility.SaveTestOutputFile(image, "bmp"); + image.DebugSave(provider); } } @@ -47,7 +36,7 @@ public void LoadProgressiveImage(TestImageProvider provider) using (Image image = provider.GetImage()) { Assert.NotNull(image); - provider.Utility.SaveTestOutputFile(image, "bmp"); + image.DebugSave(provider); } } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs index 01501a33d4..3a5dd9c06e 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs @@ -1,24 +1,23 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// + +using System.Diagnostics; + +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Utils; + +using Xunit; +using Xunit.Abstractions; // Uncomment this to turn unit tests into benchmarks: //#define BENCHMARKING // ReSharper disable InconsistentNaming -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { - using System.Diagnostics; - using System.Numerics; - - using ImageSharp.Formats; - using ImageSharp.Formats.Jpg; - - using Xunit; - using Xunit.Abstractions; - public class Block8x8FTests : JpegUtilityTestFixture { #if BENCHMARKING diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 9401d098de..277554586f 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -1,20 +1,28 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// + +using System; +using System.IO; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; // ReSharper disable InconsistentNaming -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { using System; using System.IO; + using System.Linq; - using ImageSharp.Formats; - using ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Formats; + using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; + using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using Xunit; + using Xunit.Abstractions; - public class JpegDecoderTests : TestBase + public class JpegDecoderTests { public static string[] BaselineTestJpegs = { @@ -25,35 +33,117 @@ public class JpegDecoderTests : TestBase public static string[] ProgressiveTestJpegs = TestImages.Jpeg.Progressive.All; + // TODO: We should make this comparer less tolerant ... + private static readonly ImageComparer VeryTolerantJpegComparer = + ImageComparer.Tolerant(0.005f, pixelThresholdInPixelByteSum: 4); + + public JpegDecoderTests(ITestOutputHelper output) + { + this.Output = output; + } + + private ITestOutputHelper Output { get; } + + private static IImageDecoder OriginalDecoder => new OldJpegDecoder(); + + private static IImageDecoder PdfJsDecoder => new JpegDecoder(); + + private float GetDifferenceInPercents(Image image, TestImageProvider provider) + where TPixel : struct, IPixel + { + var reportingComparer = ImageComparer.Tolerant(0, 0); + + ImageSimilarityReport report = image.GetReferenceOutputSimilarityReports( + provider, + reportingComparer, + appendPixelTypeToFileName: false).SingleOrDefault(); + + if (report != null && report.TotalNormalizedDifference.HasValue) + { + return report.TotalNormalizedDifference.Value * 100; + } + + return 0; + } + + [Theory] + [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] + public void CompareJpegDecoders(TestImageProvider provider) + where TPixel : struct, IPixel + { + this.Output.WriteLine(provider.SourceFileOrDescription); + provider.Utility.TestName = nameof(this.DecodeBaselineJpeg); + + using (Image image = provider.GetImage(OriginalDecoder)) + { + double d = this.GetDifferenceInPercents(image, provider); + this.Output.WriteLine($"Difference using ORIGINAL decoder: {d:0.0000}%"); + } + + using (Image image = provider.GetImage(PdfJsDecoder)) + { + double d = this.GetDifferenceInPercents(image, provider); + this.Output.WriteLine($"Difference using PDFJS decoder: {d:0.0000}%"); + } + } + [Theory] [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32 | PixelTypes.Rgba32 | PixelTypes.Argb32)] - public void OpenBaselineJpeg_SaveBmp(TestImageProvider provider) + public void DecodeBaselineJpeg(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage(OriginalDecoder)) { - provider.Utility.SaveTestOutputFile(image, "bmp"); + image.DebugSave(provider); + image.CompareToReferenceOutput(provider, VeryTolerantJpegComparer, appendPixelTypeToFileName: false); + } + } + + [Theory] + [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32 | PixelTypes.Rgba32 | PixelTypes.Argb32)] + public void DecodeBaselineJpeg_PdfJs(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage(PdfJsDecoder)) + { + image.DebugSave(provider); + + provider.Utility.TestName = nameof(this.DecodeBaselineJpeg); + image.CompareToReferenceOutput(provider, VeryTolerantJpegComparer, appendPixelTypeToFileName: false); } } [Theory] [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32 | PixelTypes.Rgba32 | PixelTypes.Argb32)] - public void OpenProgressiveJpeg_SaveBmp(TestImageProvider provider) + public void DecodeProgressiveJpeg(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage(OriginalDecoder)) { - provider.Utility.SaveTestOutputFile(image, "bmp"); + image.DebugSave(provider, VeryTolerantJpegComparer); } } + + [Theory] + [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32 | PixelTypes.Rgba32 | PixelTypes.Argb32)] + public void DecodeProgressiveJpeg_PdfJs(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage(PdfJsDecoder)) + { + image.DebugSave(provider, VeryTolerantJpegComparer); + } + } + + [Theory] [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio420, 75)] [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio420, 100)] [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio444, 75)] [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio444, 100)] [WithSolidFilledImages(8, 8, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio444, 100)] - public void DecodeGenerated_SaveBmp( + public void DecodeGenerated( TestImageProvider provider, JpegSubsample subsample, int quality) @@ -62,45 +152,19 @@ public void DecodeGenerated_SaveBmp( byte[] data; using (Image image = provider.GetImage()) { - JpegEncoder encoder = new JpegEncoder { Subsample = subsample, Quality = quality }; + var encoder = new JpegEncoder { Subsample = subsample, Quality = quality }; data = new byte[65536]; - using (MemoryStream ms = new MemoryStream(data)) + using (var ms = new MemoryStream(data)) { image.Save(ms, encoder); } } - // TODO: Automatic image comparers could help here a lot :P - Image mirror = provider.Factory.CreateImage(data); - provider.Utility.TestName += $"_{subsample}_Q{quality}"; - provider.Utility.SaveTestOutputFile(mirror, "bmp"); - } - - [Theory] - [WithSolidFilledImages(42, 88, 255, 0, 0, PixelTypes.Rgba32)] - public void DecodeGenerated_MetadataOnly( - TestImageProvider provider) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - using (MemoryStream ms = new MemoryStream()) - { - image.Save(ms, new JpegEncoder()); - ms.Seek(0, SeekOrigin.Begin); - - using (JpegDecoderCore decoder = new JpegDecoderCore(null, new JpegDecoder())) - { - Image mirror = decoder.Decode(ms); - - Assert.Equal(decoder.ImageWidth, image.Width); - Assert.Equal(decoder.ImageHeight, image.Height); - } - } - } + var mirror = Image.Load(data); + mirror.DebugSave(provider, $"_{subsample}_Q{quality}"); } - + [Fact] public void Decoder_Reads_Correct_Resolution_From_Jfif() { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs index 86faeee232..aab03627b2 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs @@ -1,24 +1,21 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using ImageSharp.Formats; + +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.Primitives; + using Xunit; using Xunit.Abstractions; + // ReSharper disable InconsistentNaming -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { - using ImageSharp.Formats.Jpg; - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - using SixLabors.Primitives; - public class JpegEncoderTests : MeasureFixture { public static IEnumerable AllBmpFiles => TestImages.Bmp.All; @@ -36,8 +33,9 @@ public JpegEncoderTests(ITestOutputHelper output) public void LoadResizeSave(TestImageProvider provider, int quality, JpegSubsample subsample) where TPixel : struct, IPixel { - using (Image image = provider.GetImage().Resize(new ResizeOptions { Size = new Size(150, 100), Mode = ResizeMode.Max })) + using (Image image = provider.GetImage(x=>x.Resize(new ResizeOptions { Size = new Size(150, 100), Mode = ResizeMode.Max }))) { + image.MetaData.ExifProfile = null; // Reduce the size of the file JpegEncoder options = new JpegEncoder { Subsample = subsample, Quality = quality }; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs index daf8da6a38..4afb77eeae 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs @@ -1,21 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.IO; - using System.Linq; - using System.Numerics; - - using ImageSharp.Formats; - using ImageSharp.PixelFormats; - - using Xunit; - using Xunit.Abstractions; +using System; +using System.IO; +using System.Linq; +using System.Numerics; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +using Xunit.Abstractions; +namespace SixLabors.ImageSharp.Tests +{ public class JpegProfilingBenchmarks : MeasureFixture { public JpegProfilingBenchmarks(ITestOutputHelper output) @@ -44,7 +40,7 @@ public void DecodeJpeg(string fileName) throw new Exception("Vector.IsHardwareAccelerated == false! ('prefer32 bit' enabled?)"); } - string path = TestFile.GetPath(fileName); + string path = TestFile.GetInputFileFullPath(fileName); byte[] bytes = File.ReadAllBytes(path); this.Measure( diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilityTestFixture.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilityTestFixture.cs index 252b01138b..feca197233 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilityTestFixture.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilityTestFixture.cs @@ -1,20 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// +using System; +using System.Diagnostics; using System.Text; - +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Utils; using Xunit.Abstractions; + // ReSharper disable InconsistentNaming -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { - using System; - using System.Diagnostics; - - using ImageSharp.Formats.Jpg; - public class JpegUtilityTestFixture : MeasureFixture { public JpegUtilityTestFixture(ITestOutputHelper output) : base(output) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs index f681e1d8f9..60036c1767 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs @@ -1,34 +1,31 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -// ReSharper disable InconsistentNaming -namespace ImageSharp.Tests -{ - using System; - using System.Numerics; +using System.Numerics; - using ImageSharp.Formats.Jpg; - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Utils; +using SixLabors.ImageSharp.PixelFormats; - using Xunit; +using Xunit; +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Tests +{ public class JpegUtilsTests : TestBase { - public static Image CreateTestImage(GenericFactory factory) + public static Image CreateTestImage() where TPixel : struct, IPixel { - Image image = factory.CreateImage(10, 10); + var image = new Image(10, 10); using (PixelAccessor pixels = image.Lock()) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { - Vector4 v = new Vector4(i / 10f, j / 10f, 0, 1); + var v = new Vector4(i / 10f, j / 10f, 0, 1); - TPixel color = default(TPixel); + var color = default(TPixel); color.PackFromVector4(v); pixels[i, j] = color; @@ -45,7 +42,7 @@ public void CopyStretchedRGBTo_FromOrigo(TestImageProvider provi where TPixel : struct, IPixel { using (Image src = provider.GetImage()) - using (Image dest = provider.Factory.CreateImage(8, 8)) + using (Image dest = new Image(8,8)) using (PixelArea area = new PixelArea(8, 8, ComponentOrder.Xyz)) using (PixelAccessor s = src.Lock()) using (PixelAccessor d = dest.Lock()) @@ -68,7 +65,7 @@ public void CopyStretchedRGBTo_WithOffset(TestImageProvider prov { using (Image src = provider.GetImage()) using (PixelArea area = new PixelArea(8, 8, ComponentOrder.Xyz)) - using (Image dest = provider.Factory.CreateImage(8, 8)) + using (Image dest = new Image(8, 8)) using (PixelAccessor s = src.Lock()) using (PixelAccessor d = dest.Lock()) { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs index e76a11cec9..30a6719b3d 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs @@ -1,19 +1,18 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -// ReSharper disable InconsistentNaming +using System; +using System.Numerics; +using System.Runtime.CompilerServices; -namespace ImageSharp.Tests -{ - using System; - using System.Numerics; - using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Utils; - using ImageSharp.Formats; - using ImageSharp.Formats.Jpg; +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Tests +{ /// /// This class contains simplified (unefficient) reference implementations to produce verification data for unit tests /// Floating point DCT code Ported from https://github.com/norishigefukushima/dct_simd diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.cs index 50b94bc24c..21744cbfbe 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -// ReSharper disable InconsistentNaming -namespace ImageSharp.Tests.Formats.Jpg -{ - using ImageSharp.Formats.Jpg; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Utils; - using Xunit; - using Xunit.Abstractions; +using Xunit; +using Xunit.Abstractions; +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Tests.Formats.Jpg +{ public class ReferenceImplementationsTests : JpegUtilityTestFixture { public ReferenceImplementationsTests(ITestOutputHelper output) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/YCbCrImageTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/YCbCrImageTests.cs index b911e11846..9d0bcb2d4f 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/YCbCrImageTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/YCbCrImageTests.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using ImageSharp.Formats.Jpg; - using SixLabors.Primitives; - using Xunit; - using Xunit.Abstractions; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder; +using SixLabors.Primitives; +using Xunit; +using Xunit.Abstractions; +namespace SixLabors.ImageSharp.Tests +{ public class YCbCrImageTests { public YCbCrImageTests(ITestOutputHelper output) @@ -64,7 +62,7 @@ internal void Create(YCbCrImage.YCbCrSubsampleRatio ratioValue, int expectedCStr Assert.Equal(img.CrChannel.Width, 400 / expectedCStrideDiv); } - private void PrintChannel(string name, JpegPixelArea channel) + private void PrintChannel(string name, OldJpegPixelArea channel) { this.Output.WriteLine($"{name}: Stride={channel.Stride}"); } diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index 3c335441ab..5e4885d351 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -1,17 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// using System.IO; using System.IO.Compression; using System.Text; -using ImageSharp.Formats; -using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; using Xunit; -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + public class PngDecoderTests { private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32; @@ -19,17 +19,19 @@ public class PngDecoderTests public static readonly string[] TestFiles = { TestImages.Png.Splash, TestImages.Png.Indexed, TestImages.Png.Interlaced, TestImages.Png.FilterVar, - TestImages.Png.Bad.ChunkLength1, TestImages.Png.Bad.ChunkLength2, TestImages.Png.Rgb48Bpp, TestImages.Png.Rgb48BppInterlaced + TestImages.Png.Bad.ChunkLength1, TestImages.Png.Bad.ChunkLength2, TestImages.Png.Rgb48Bpp, + TestImages.Png.Rgb48BppInterlaced, TestImages.Png.SnakeGame }; [Theory] [WithFileCollection(nameof(TestFiles), PixelTypes)] - public void DecodeAndReSave(TestImageProvider imageProvider) + public void Decode(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image image = imageProvider.GetImage()) + using (Image image = provider.GetImage(new PngDecoder())) { - imageProvider.Utility.SaveTestOutputFile(image, "bmp"); + image.DebugSave(provider); + image.CompareToOriginal(provider, ImageComparer.Exact); } } diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index 24907cfdb7..c17a1c3b02 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -1,21 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -using ImageSharp.Formats; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.IO; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Threading.Tasks; - using ImageSharp.IO; - using ImageSharp.PixelFormats; - - using Xunit; - public class PngEncoderTests : FileTestBase { private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32; diff --git a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs index c977f5fb55..738d3de686 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs @@ -1,22 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Formats.Png -{ - using System; - using System.Collections.Generic; - using System.Text; - using System.IO; - using Xunit; - using ImageSharp.Formats; - using System.Linq; - using ImageSharp.IO; - using System.Numerics; - - using ImageSharp.PixelFormats; +using System.IO; +using Xunit; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; +namespace SixLabors.ImageSharp.Tests.Formats.Png +{ public class PngSmokeTests { [Theory] @@ -34,8 +26,8 @@ public void GeneralTest(TestImageProvider provider) ms.Position = 0; using (Image img2 = Image.Load(ms, new PngDecoder())) { + ImageComparer.Tolerant().VerifySimilarity(image, img2); // img2.Save(provider.Utility.GetTestOutputFileName("bmp", "_loaded"), new BmpEncoder()); - ImageComparer.CheckSimilarity(image, img2); } } } @@ -56,8 +48,7 @@ public void GeneralTest(TestImageProvider provider) // ms.Position = 0; // using (Image img2 = Image.Load(ms, new PngDecoder())) // { - // // img2.Save(provider.Utility.GetTestOutputFileName("bmp", "_loaded"), new BmpEncoder()); - // ImageComparer.CheckSimilarity(image, img2, 0.03f); + // ImageComparer.VerifySimilarity(image, img2, 0.03f); // } // } //} @@ -115,14 +106,14 @@ public void Resize(TestImageProvider provider) using (MemoryStream ms = new MemoryStream()) { // image.Save(provider.Utility.GetTestOutputFileName("png")); - image.Resize(100, 100); + image.Mutate(x => x.Resize(100, 100)); // image.Save(provider.Utility.GetTestOutputFileName("png", "resize")); image.Save(ms, new PngEncoder()); ms.Position = 0; using (Image img2 = Image.Load(ms, new PngDecoder())) { - ImageComparer.CheckSimilarity(image, img2); + ImageComparer.Tolerant().VerifySimilarity(image, img2); } } } diff --git a/tests/ImageSharp.Tests/GlobalSuppressions.cs b/tests/ImageSharp.Tests/GlobalSuppressions.cs new file mode 100644 index 0000000000..106d34d0bc --- /dev/null +++ b/tests/ImageSharp.Tests/GlobalSuppressions.cs @@ -0,0 +1,9 @@ + +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Assertions", "xUnit2013:Do not use equality check to check for collection size.")] + diff --git a/tests/ImageSharp.Tests/Helpers/GuardTests.cs b/tests/ImageSharp.Tests/Helpers/GuardTests.cs index ba6d5687ce..83075dc83e 100644 --- a/tests/ImageSharp.Tests/Helpers/GuardTests.cs +++ b/tests/ImageSharp.Tests/Helpers/GuardTests.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Helpers -{ - using System; - using System.Diagnostics.CodeAnalysis; - - using Xunit; +using System; +using System.Diagnostics.CodeAnalysis; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Helpers +{ /// /// Tests the helper. /// diff --git a/tests/ImageSharp.Tests/Helpers/MathFTests.cs b/tests/ImageSharp.Tests/Helpers/MathFTests.cs index 62a971f9f5..f865353c4d 100644 --- a/tests/ImageSharp.Tests/Helpers/MathFTests.cs +++ b/tests/ImageSharp.Tests/Helpers/MathFTests.cs @@ -1,9 +1,11 @@ -namespace ImageSharp.Tests.Helpers -{ - using System; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Helpers +{ public class MathFTests { [Fact] diff --git a/tests/ImageSharp.Tests/IO/BigEndianBitConverter.CopyBytesTests.cs b/tests/ImageSharp.Tests/IO/BigEndianBitConverter.CopyBytesTests.cs index 4cdf9122a9..254cfa2dc4 100644 --- a/tests/ImageSharp.Tests/IO/BigEndianBitConverter.CopyBytesTests.cs +++ b/tests/ImageSharp.Tests/IO/BigEndianBitConverter.CopyBytesTests.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.IO -{ - using System; - using ImageSharp.IO; - using Xunit; +using System; +using SixLabors.ImageSharp.IO; +using Xunit; +namespace SixLabors.ImageSharp.Tests.IO +{ /// /// The tests. /// diff --git a/tests/ImageSharp.Tests/IO/BigEndianBitConverter.GetBytesTests.cs b/tests/ImageSharp.Tests/IO/BigEndianBitConverter.GetBytesTests.cs index 06962e0106..d8408523ba 100644 --- a/tests/ImageSharp.Tests/IO/BigEndianBitConverter.GetBytesTests.cs +++ b/tests/ImageSharp.Tests/IO/BigEndianBitConverter.GetBytesTests.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.IO -{ - using ImageSharp.IO; - using Xunit; +using SixLabors.ImageSharp.IO; +using Xunit; +namespace SixLabors.ImageSharp.Tests.IO +{ /// /// The tests. /// diff --git a/tests/ImageSharp.Tests/IO/BigEndianBitConverter.ToTypeTests.cs b/tests/ImageSharp.Tests/IO/BigEndianBitConverter.ToTypeTests.cs index a69727d457..65963918cb 100644 --- a/tests/ImageSharp.Tests/IO/BigEndianBitConverter.ToTypeTests.cs +++ b/tests/ImageSharp.Tests/IO/BigEndianBitConverter.ToTypeTests.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.IO -{ - using System; - using ImageSharp.IO; - using Xunit; +using System; +using SixLabors.ImageSharp.IO; +using Xunit; +namespace SixLabors.ImageSharp.Tests.IO +{ /// /// The tests. /// diff --git a/tests/ImageSharp.Tests/IO/EndianBinaryReaderTests.cs b/tests/ImageSharp.Tests/IO/EndianBinaryReaderTests.cs index ffd9cdedcc..87adead338 100644 --- a/tests/ImageSharp.Tests/IO/EndianBinaryReaderTests.cs +++ b/tests/ImageSharp.Tests/IO/EndianBinaryReaderTests.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.IO -{ - using System; - using System.IO; - using System.Text; - - using ImageSharp.IO; - - using Xunit; +using System; +using System.IO; +using System.Text; +using SixLabors.ImageSharp.IO; +using Xunit; +namespace SixLabors.ImageSharp.Tests.IO +{ /// /// The endian binary reader tests. /// @@ -49,8 +45,7 @@ public void ReadCharsBeyondInternalBufferSize() [Fact] public void ReadCharsBeyondProvidedBufferSize() { - Assert.Throws( - typeof(ArgumentException), + Assert.Throws( () => { MemoryStream stream = new MemoryStream(TestBytes); diff --git a/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.CopyBytesTests.cs b/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.CopyBytesTests.cs index 5ff47409b0..97d9275ad1 100644 --- a/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.CopyBytesTests.cs +++ b/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.CopyBytesTests.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.IO -{ - using System; - using ImageSharp.IO; - using Xunit; +using System; +using SixLabors.ImageSharp.IO; +using Xunit; +namespace SixLabors.ImageSharp.Tests.IO +{ /// /// The tests. /// diff --git a/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.GetBytesTests.cs b/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.GetBytesTests.cs index 7fd7a97d43..eae8ca2919 100644 --- a/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.GetBytesTests.cs +++ b/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.GetBytesTests.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.IO -{ - using ImageSharp.IO; - using Xunit; +using SixLabors.ImageSharp.IO; +using Xunit; +namespace SixLabors.ImageSharp.Tests.IO +{ /// /// The tests. /// diff --git a/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.ToTypeTests.cs b/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.ToTypeTests.cs index c46c011a14..f358362576 100644 --- a/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.ToTypeTests.cs +++ b/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.ToTypeTests.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.IO -{ - using System; - using ImageSharp.IO; - using Xunit; +using System; +using SixLabors.ImageSharp.IO; +using Xunit; +namespace SixLabors.ImageSharp.Tests.IO +{ /// /// The tests. /// diff --git a/tests/ImageSharp.Tests/IO/LocalFileSystem.cs b/tests/ImageSharp.Tests/IO/LocalFileSystem.cs index 472d643cd3..3fa94d6711 100644 --- a/tests/ImageSharp.Tests/IO/LocalFileSystem.cs +++ b/tests/ImageSharp.Tests/IO/LocalFileSystem.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.IO -{ - using System; - using System.IO; - using ImageSharp.IO; - - using Xunit; +using System; +using System.IO; +using SixLabors.ImageSharp.IO; +using Xunit; +namespace SixLabors.ImageSharp.Tests.IO +{ public class LocalFileSystemTests { [Fact] diff --git a/tests/ImageSharp.Tests/Image/ImageDiscoverMimeType.cs b/tests/ImageSharp.Tests/Image/ImageDiscoverMimeType.cs index d34fa22e25..3b66579935 100644 --- a/tests/ImageSharp.Tests/Image/ImageDiscoverMimeType.cs +++ b/tests/ImageSharp.Tests/Image/ImageDiscoverMimeType.cs @@ -1,19 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.IO; - - using ImageSharp.Formats; - using ImageSharp.IO; - using ImageSharp.PixelFormats; - using Moq; - using Xunit; +using System; +using System.IO; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.IO; +using SixLabors.ImageSharp.PixelFormats; +using Moq; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ /// /// Tests the class. /// diff --git a/tests/ImageSharp.Tests/Image/ImageEqualTests.cs b/tests/ImageSharp.Tests/Image/ImageEqualTests.cs index 3990060127..ac6ea888f5 100644 --- a/tests/ImageSharp.Tests/Image/ImageEqualTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageEqualTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ public class ImageEqualTests { [Fact] diff --git a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs index 4573d0d9de..1f58b0a3b4 100644 --- a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.IO; - - using ImageSharp.Formats; - using ImageSharp.IO; - using Moq; - using Xunit; +using System; +using System.IO; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.IO; +using Moq; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ /// /// Tests the class. /// diff --git a/tests/ImageSharp.Tests/Image/ImageRotationTests.cs b/tests/ImageSharp.Tests/Image/ImageRotationTests.cs index 56cec42192..bc9c28898f 100644 --- a/tests/ImageSharp.Tests/Image/ImageRotationTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageRotationTests.cs @@ -1,7 +1,10 @@ -using SixLabors.Primitives; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.Primitives; using Xunit; -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { public class ImageRotationTests { @@ -42,12 +45,12 @@ public void RotateImageBy360Degrees() private static (Size original, Size rotated) Rotate(int angle) { - TestFile file = TestFile.Create(TestImages.Bmp.Car); - using (Image image = Image.Load(file.FilePath)) + var file = TestFile.Create(TestImages.Bmp.Car); + using (var image = Image.Load(file.FilePath)) { - Size original = image.Bounds.Size; - image.Rotate(angle); - return (original, image.Bounds.Size); + Size original = image.Bounds().Size; + image.Mutate(x => x.Rotate(angle)); + return (original, image.Bounds().Size); } } } diff --git a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs index ad8a5cc7d5..dd7a0eae59 100644 --- a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs @@ -1,20 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.IO; - using System.Linq; - using ImageSharp.Formats; - using ImageSharp.IO; - using ImageSharp.PixelFormats; - - using Moq; - using Xunit; +using System; +using System.IO; +using System.Linq; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.IO; +using SixLabors.ImageSharp.PixelFormats; +using Moq; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ /// /// Tests the class. /// diff --git a/tests/ImageSharp.Tests/Image/ImageTests.cs b/tests/ImageSharp.Tests/Image/ImageTests.cs index 217bf37fe8..d560900a6b 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.cs @@ -1,21 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - - using ImageSharp.Formats; - using ImageSharp.PixelFormats; - - using Xunit; +using System; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ /// /// Tests the class. /// - public class ImageTests + public class ImageTests : FileTestBase { [Fact] public void ConstructorByteArray() @@ -67,8 +63,9 @@ public void ConstructorFileSystem_NullPath() [Fact] public void Save_DetecedEncoding() { - string file = TestFile.GetPath("../../TestOutput/Save_DetecedEncoding.png"); - System.IO.DirectoryInfo dir = System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(file)); + string dir = this.CreateOutputDirectory(nameof(ImageTests)); + string file = System.IO.Path.Combine(dir, "Save_DetecedEncoding.png"); + using (Image image = new Image(10, 10)) { image.Save(file); @@ -81,9 +78,11 @@ public void Save_DetecedEncoding() } [Fact] - public void Save_UnknownExtensionsEncoding() + public void Save_WhenExtensionIsUnknown_Throws() { - string file = TestFile.GetPath("../../TestOutput/Save_DetecedEncoding.tmp"); + string dir = this.CreateOutputDirectory(nameof(ImageTests)); + string file = System.IO.Path.Combine(dir, "Save_UnknownExtensionsEncoding_Throws.tmp"); + NotSupportedException ex = Assert.Throws( () => { @@ -97,8 +96,9 @@ public void Save_UnknownExtensionsEncoding() [Fact] public void Save_SetEncoding() { - string file = TestFile.GetPath("../../TestOutput/Save_SetEncoding.dat"); - System.IO.DirectoryInfo dir = System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(file)); + string dir = this.CreateOutputDirectory(nameof(ImageTests)); + string file = System.IO.Path.Combine(dir, "Save_SetEncoding.dat"); + using (Image image = new Image(10, 10)) { image.Save(file, new PngEncoder()); diff --git a/tests/ImageSharp.Tests/Image/NoneSeekableStream.cs b/tests/ImageSharp.Tests/Image/NoneSeekableStream.cs index bc36b60eb2..10a531eafe 100644 --- a/tests/ImageSharp.Tests/Image/NoneSeekableStream.cs +++ b/tests/ImageSharp.Tests/Image/NoneSeekableStream.cs @@ -1,7 +1,10 @@ -using System; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; using System.IO; -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { internal class NoneSeekableStream : Stream { diff --git a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs index 0eeb468f03..50aec35d6b 100644 --- a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs +++ b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs @@ -1,36 +1,33 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ /// /// Tests the class. /// public class PixelAccessorTests { - public static Image CreateTestImage(GenericFactory factory) + public static Image CreateTestImage() where TPixel : struct, IPixel { - Image image = factory.CreateImage(10, 10); + var image = new Image(10, 10); using (PixelAccessor pixels = image.Lock()) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { - Vector4 v = new Vector4(i, j, 0, 1); + var v = new Vector4(i, j, 0, 1); v /= 10; - TPixel color = default(TPixel); + var color = default(TPixel); color.PackFromVector4(v); pixels[i, j] = color; @@ -82,7 +79,7 @@ public void CopyToThenCopyFromWithOffset(TestImageProvider provi { using (Image srcImage = provider.GetImage()) { - srcImage.Fill(NamedColors.Red, new Rectangle(4, 4, 8, 8)); + srcImage.Mutate(x => x.Fill(NamedColors.Red, new Rectangle(4, 4, 8, 8))); using (PixelAccessor srcPixels = srcImage.Lock()) { using (PixelArea area = new PixelArea(8, 8, order)) @@ -100,8 +97,9 @@ public void CopyToThenCopyFromWithOffset(TestImageProvider provi provider.Utility.SourceFileOrDescription = order.ToString(); provider.Utility.SaveTestOutputFile(destImage, "bmp"); - using (Image expectedImage = new Image(8, 8).Fill(NamedColors.Red)) + using (Image expectedImage = new Image(8, 8)) { + expectedImage.Mutate(x => x.Fill(NamedColors.Red)); Assert.True(destImage.IsEquivalentTo(expectedImage)); } } diff --git a/tests/ImageSharp.Tests/ImageComparer.cs b/tests/ImageSharp.Tests/ImageComparer.cs deleted file mode 100644 index 6cd80e9e83..0000000000 --- a/tests/ImageSharp.Tests/ImageComparer.cs +++ /dev/null @@ -1,160 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Tests -{ - using System; - using ImageSharp; - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; - - /// - /// Class to perform simple image comparisons. - /// - public static class ImageComparer - { - const int DefaultScalingFactor = 32; // This is means the images get scaled into a 32x32 image to sample pixels - const int DefaultSegmentThreshold = 3; // The greyscale difference between 2 segements my be > 3 before it influences the overall difference - const float DefaultImageThreshold = 0.000F; // After segment thresholds the images must have no differences - - /// - /// Fills the bounded area with a solid color and does a visual comparison between 2 images asserting the difference outwith - /// that area is less then a configurable threshold. - /// - /// The color of the expected image - /// The color type fo the the actual image - /// The expected image - /// The actual image - /// The bounds within the image has been altered - /// - /// The threshold for the percentage difference where the images are asumed to be the same. - /// The default/undefined value is - /// - /// - /// The threshold of the individual segments before it acumulates towards the overall difference. - /// The default undefined value is - /// - /// - /// This is a sampling factor we sample a grid of average pixels width by high - /// The default undefined value is - /// - public static void EnsureProcessorChangesAreConstrained(Image expected, Image actual, Rectangle bounds, float imageTheshold = DefaultImageThreshold, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor) - where TPixelA : struct, IPixel - where TPixelB : struct, IPixel - { - // Draw identical shapes over the bounded and compare to ensure changes are constrained. - expected.Fill(NamedColors.HotPink, bounds); - actual.Fill(NamedColors.HotPink, bounds); - - CheckSimilarity(expected, actual, imageTheshold, segmentThreshold, scalingFactor); - } - - /// - /// Does a visual comparison between 2 images and then asserts the difference is less then a configurable threshold - /// - /// The color of the expected image - /// The color type fo the the actual image - /// The expected image - /// The actual image - /// - /// The threshold for the percentage difference where the images are asumed to be the same. - /// The default/undefined value is - /// - /// - /// The threshold of the individual segments before it acumulates towards the overall difference. - /// The default undefined value is - /// - /// - /// This is a sampling factor we sample a grid of average pixels width by high - /// The default undefined value is - /// - public static void CheckSimilarity(Image expected, Image actual, float imageTheshold = DefaultImageThreshold, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor) - where TPixelA : struct, IPixel - where TPixelB : struct, IPixel - { - float percentage = expected.PercentageDifference(actual, segmentThreshold, scalingFactor); - - Assert.InRange(percentage, 0, imageTheshold); - } - - /// - /// Does a visual comparison between 2 images and then and returns the percentage diffence between the 2 - /// - /// The color of the source image - /// The color type for the target image - /// The source image - /// The target image - /// - /// The threshold of the individual segments before it acumulates towards the overall difference. - /// The default undefined value is - /// - /// - /// This is a sampling factor we sample a grid of average pixels width by high - /// The default undefined value is - /// - /// Returns a number from 0 - 1 which represents the difference focter between the images. - public static float PercentageDifference(this Image source, Image target, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor) - where TPixelA : struct, IPixel - where TPixelB : struct, IPixel - { - // code adapted from https://www.codeproject.com/Articles/374386/Simple-image-comparison-in-NET - Fast2DArray differences = GetDifferences(source, target, scalingFactor); - - int diffPixels = 0; - - foreach (byte b in differences.Data) - { - if (b > segmentThreshold) { diffPixels++; } - } - - return diffPixels / (float)(scalingFactor * scalingFactor); - } - - private static Fast2DArray GetDifferences(Image source, Image target, int scalingFactor) - where TPixelA : struct, IPixel - where TPixelB : struct, IPixel - { - var differences = new Fast2DArray(scalingFactor, scalingFactor); - Fast2DArray firstGray = source.GetGrayScaleValues(scalingFactor); - Fast2DArray secondGray = target.GetGrayScaleValues(scalingFactor); - - for (int y = 0; y < scalingFactor; y++) - { - for (int x = 0; x < scalingFactor; x++) - { - int diff = firstGray[x, y] - secondGray[x, y]; - differences[x, y] = (byte)Math.Abs(diff); - } - } - - return differences; - } - - private static Fast2DArray GetGrayScaleValues(this Image source, int scalingFactor) - where TPixelA : struct, IPixel - { - byte[] buffer = new byte[3]; - using (Image img = new Image(source).Resize(scalingFactor, scalingFactor).Grayscale()) - { - using (PixelAccessor pixels = img.Lock()) - { - var grayScale = new Fast2DArray(scalingFactor, scalingFactor); - for (int y = 0; y < scalingFactor; y++) - { - for (int x = 0; x < scalingFactor; x++) - { - pixels[x, y].ToXyzBytes(buffer, 0); - grayScale[x, y] = buffer[0]; - } - } - - return grayScale; - } - } - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/ImageOperationTests.cs b/tests/ImageSharp.Tests/ImageOperationTests.cs new file mode 100644 index 0000000000..59722a84d2 --- /dev/null +++ b/tests/ImageSharp.Tests/ImageOperationTests.cs @@ -0,0 +1,104 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.IO; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using Moq; +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests +{ + /// + /// Tests the configuration class. + /// + public class ImageOperationTests : IDisposable + { + private readonly Image image; + private readonly FakeImageOperationsProvider provider; + private readonly IImageProcessor processor; + + public Configuration Configuration { get; private set; } + + public ImageOperationTests() + { + this.provider = new FakeImageOperationsProvider(); + this.processor = new Mock>().Object; + this.image = new Image(new Configuration() + { + ImageOperationsProvider = this.provider + }, 1, 1); + } + + [Fact] + public void MutateCallsImageOperationsProvider_Func_OriginalImage() + { + this.image.Mutate(x => x.ApplyProcessor(this.processor)); + + Assert.True(this.provider.HasCreated(this.image)); + Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x=>x.Processor)); + } + + [Fact] + public void MutateCallsImageOperationsProvider_ListOfProcessors_OriginalImage() + { + this.image.Mutate(this.processor); + + Assert.True(this.provider.HasCreated(this.image)); + Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.Processor)); + } + + [Fact] + public void CloneCallsImageOperationsProvider_Func_WithDuplicateImage() + { + var returned = this.image.Clone(x => x.ApplyProcessor(this.processor)); + + Assert.True(this.provider.HasCreated(returned)); + Assert.Contains(this.processor, this.provider.AppliedOperations(returned).Select(x => x.Processor)); + } + + [Fact] + public void CloneCallsImageOperationsProvider_ListOfProcessors_WithDuplicateImage() + { + var returned = this.image.Clone(this.processor); + + Assert.True(this.provider.HasCreated(returned)); + Assert.Contains(this.processor, this.provider.AppliedOperations(returned).Select(x => x.Processor)); + } + + [Fact] + public void CloneCallsImageOperationsProvider_Func_NotOnOrigional() + { + var returned = this.image.Clone(x => x.ApplyProcessor(this.processor)); + Assert.False(this.provider.HasCreated(this.image)); + Assert.DoesNotContain(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.Processor)); + } + + [Fact] + public void CloneCallsImageOperationsProvider_ListOfProcessors_NotOnOrigional() + { + var returned = this.image.Clone(this.processor); + Assert.False(this.provider.HasCreated(this.image)); + Assert.DoesNotContain(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.Processor)); + } + + [Fact] + public void ApplyProcessors_ListOfProcessors_AppliesAllProcessorsToOperation() + { + var operations = new FakeImageOperationsProvider.FakeImageOperations(null, false); + operations.ApplyProcessors(this.processor); + Assert.Contains(this.processor, operations.applied.Select(x => x.Processor)); + } + + public void Dispose() + { + this.image.Dispose(); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index b0429d9ede..bf4a061095 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -5,17 +5,32 @@ full portable True + SixLabors.ImageSharp.Tests + SixLabors.ImageSharp.Tests + + + true + + - - + + + + + + + + @@ -27,4 +42,7 @@ PreserveNewest + + + \ No newline at end of file diff --git a/tests/ImageSharp.Tests/MetaData/ImageFrameMetaDataTests.cs b/tests/ImageSharp.Tests/MetaData/ImageFrameMetaDataTests.cs index da2bb41561..8b42d4f515 100644 --- a/tests/ImageSharp.Tests/MetaData/ImageFrameMetaDataTests.cs +++ b/tests/ImageSharp.Tests/MetaData/ImageFrameMetaDataTests.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using ImageSharp.Formats; - using Xunit; +using SixLabors.ImageSharp.Formats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ /// /// Tests the class. /// diff --git a/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs b/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs index c60c8978ce..09a05a2544 100644 --- a/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs +++ b/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using ImageSharp.Formats; - using ImageSharp.PixelFormats; - - using Xunit; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ /// /// Tests the class. /// diff --git a/tests/ImageSharp.Tests/MetaData/ImagePropertyTests.cs b/tests/ImageSharp.Tests/MetaData/ImagePropertyTests.cs index 3b224014da..63a51e8638 100644 --- a/tests/ImageSharp.Tests/MetaData/ImagePropertyTests.cs +++ b/tests/ImageSharp.Tests/MetaData/ImagePropertyTests.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using Xunit; +using System; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ /// /// Tests the class. /// diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs index db22300fa5..845fbd8fa4 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs @@ -1,20 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Collections; - using System.IO; - using System.Linq; - using System.Text; - - using ImageSharp.PixelFormats; - - using Xunit; +using System; +using System.Collections; +using System.IO; +using System.Linq; +using System.Text; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ public class ExifProfileTests { [Fact] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifReaderTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifReaderTests.cs index dc62f1cbf3..802f856e42 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifReaderTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifReaderTests.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System.Collections.ObjectModel; - using Xunit; +using System.Collections.ObjectModel; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ public class ExifReaderTests { [Fact] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifTagDescriptionAttributeTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifTagDescriptionAttributeTests.cs index 1d36de5ef3..a2b2c6e70c 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifTagDescriptionAttributeTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifTagDescriptionAttributeTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ public class ExifDescriptionAttributeTests { [Fact] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifValueTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifValueTests.cs index 473af77121..3fbd1d9f0b 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifValueTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifValueTests.cs @@ -1,16 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System.Linq; - - using ImageSharp.PixelFormats; - - using Xunit; +using System.Linq; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ public class ExifValueTests { private static ExifValue GetExifValue() diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.CurvesTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.CurvesTests.cs index 2bde125435..6a08c98e54 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.CurvesTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.CurvesTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataReaderCurvesTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.LutTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.LutTests.cs index 52c67ba539..1271fc2680 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.LutTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.LutTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataReaderLutTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.MatrixTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.MatrixTests.cs index 9d148ec94a..8395f70158 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.MatrixTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.MatrixTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataReaderMatrixTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.MultiProcessElementTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.MultiProcessElementTests.cs index c02ef40e37..610efaf6a7 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.MultiProcessElementTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.MultiProcessElementTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataReaderMultiProcessElementTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitivesTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitivesTests.cs index e3593bfa9e..0c33ad9fe1 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitivesTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitivesTests.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using System; - using System.Numerics; - using Xunit; +using System; +using System.Numerics; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataReaderNonPrimitivesTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.PrimitivesTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.PrimitivesTests.cs index b9b0c6655c..7975da04c3 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.PrimitivesTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.PrimitivesTests.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using System; - using Xunit; +using System; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataReaderPrimitivesTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntryTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntryTests.cs index 76bb1cda19..c75f6b96f4 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntryTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntryTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataReaderTagDataEntryTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReaderTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReaderTests.cs index 635ce6168d..3c66d9a4ad 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReaderTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReaderTests.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using System; - using Xunit; +using System; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataReaderTests { [Fact] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.CurvesTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.CurvesTests.cs index c04401f6d0..85d091ec76 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.CurvesTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.CurvesTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataWriterCurvesTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.LutTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.LutTests.cs index 4fcc55d016..6bbdb80386 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.LutTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.LutTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataWriterLutTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs index 61b5d57ffd..20c7c3bead 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs @@ -1,16 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using System.Numerics; - - using ImageSharp.Memory; - - using Xunit; +using System.Numerics; +using SixLabors.ImageSharp.Memory; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataWriterMatrixTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElementTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElementTests.cs index e3bc375744..bf80b53701 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElementTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElementTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataWriterMultiProcessElementTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitivesTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitivesTests.cs index ae83458051..d97e32de89 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitivesTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitivesTests.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using System; - using System.Numerics; - using Xunit; +using System; +using System.Numerics; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataWriterNonPrimitivesTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.PrimitivesTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.PrimitivesTests.cs index 8d0cd32ab4..76ada231e2 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.PrimitivesTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.PrimitivesTests.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using System; - using Xunit; +using System; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataWriterPrimitivesTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntryTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntryTests.cs index ea85bd16df..a026cb8a0c 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntryTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntryTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataWriterTagDataEntryTests { [Theory] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriterTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriterTests.cs index 5239d7cd51..2d0aa920b0 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriterTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriterTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccDataWriterTests { [Fact] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccReaderTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccReaderTests.cs index 34aa24fa66..6c11182e09 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccReaderTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccReaderTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccReaderTests { [Fact] diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccWriterTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccWriterTests.cs index 7e3f8c0c94..e845535304 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccWriterTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccWriterTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Icc -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Icc +{ public class IccWriterTests { [Fact] diff --git a/tests/ImageSharp.Tests/Numerics/RationalTests.cs b/tests/ImageSharp.Tests/Numerics/RationalTests.cs index 3d80b88fe7..c6c59915d6 100644 --- a/tests/ImageSharp.Tests/Numerics/RationalTests.cs +++ b/tests/ImageSharp.Tests/Numerics/RationalTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ /// /// Tests the struct. /// diff --git a/tests/ImageSharp.Tests/Numerics/SignedRationalTests.cs b/tests/ImageSharp.Tests/Numerics/SignedRationalTests.cs index cb7e21db0b..d4b3421518 100644 --- a/tests/ImageSharp.Tests/Numerics/SignedRationalTests.cs +++ b/tests/ImageSharp.Tests/Numerics/SignedRationalTests.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using Xunit; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ /// /// Tests the struct. /// diff --git a/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs index 76001ed3a0..ca59cea725 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs @@ -1,12 +1,12 @@ -// ReSharper disable InconsistentNaming -namespace ImageSharp.Tests -{ - using System.Numerics; - - using ImageSharp.PixelFormats; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ public class Bgr24Tests { public static readonly TheoryData ColorData = diff --git a/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs index 1928d51f69..e3cf868257 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs @@ -1,12 +1,12 @@ -// ReSharper disable InconsistentNaming -namespace ImageSharp.Tests -{ - using System.Numerics; - - using ImageSharp.PixelFormats; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ public class Bgra32Tests { public static readonly TheoryData ColorData = diff --git a/tests/ImageSharp.Tests/PixelFormats/ColorConstructorTests.cs b/tests/ImageSharp.Tests/PixelFormats/ColorConstructorTests.cs index eac0644d9a..b0d5929f49 100644 --- a/tests/ImageSharp.Tests/PixelFormats/ColorConstructorTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/ColorConstructorTests.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Colors -{ - using System.Collections.Generic; - using System.Numerics; - - using ImageSharp.PixelFormats; - - using Xunit; +using System.Collections.Generic; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colors +{ public class ColorConstructorTests { public static IEnumerable Vector4Data diff --git a/tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs b/tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs index db5b4a4c91..af4181cde2 100644 --- a/tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System.Collections.Generic; - using System.Linq; - using System.Reflection; - - using ImageSharp.PixelFormats; - - using Xunit; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ public class ColorDefinitionTests { public static TheoryData ColorNames diff --git a/tests/ImageSharp.Tests/PixelFormats/ColorEqualityTests.cs b/tests/ImageSharp.Tests/PixelFormats/ColorEqualityTests.cs index 2967e7c864..d3815f2eb6 100644 --- a/tests/ImageSharp.Tests/PixelFormats/ColorEqualityTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/ColorEqualityTests.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Colors -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; - - using Xunit; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colors +{ /// /// Test implementations of IEquatable /// diff --git a/tests/ImageSharp.Tests/PixelFormats/ColorPackingTests.cs b/tests/ImageSharp.Tests/PixelFormats/ColorPackingTests.cs index 563b6be3c4..ad8297fbb5 100644 --- a/tests/ImageSharp.Tests/PixelFormats/ColorPackingTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/ColorPackingTests.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Colors -{ - using System.Collections.Generic; - using System.Numerics; - - using ImageSharp.PixelFormats; - - using Xunit; +using System.Collections.Generic; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colors +{ public class ColorPackingTests { public static IEnumerable Vector4PackData diff --git a/tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs b/tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs index 773bfa513d..303905baf0 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs @@ -1,18 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Colors -{ - using System; - using System.Diagnostics; - using System.Numerics; - - using ImageSharp.PixelFormats; - - using Xunit; +using System; +using System.Diagnostics; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colors +{ /// /// The packed pixel tests. /// diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs index 97d5505923..9aa2e01a67 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs @@ -1,18 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.PixelFormats.PixelBlenders -{ - using System; - using System.Collections.Generic; - using System.Numerics; - using System.Text; - using ImageSharp.PixelFormats.PixelBlenders; - using ImageSharp.Tests.TestUtilities; - using Xunit; +using System; +using System.Collections.Generic; +using System.Numerics; +using System.Text; +using SixLabors.ImageSharp.PixelFormats.PixelBlenders; +using SixLabors.ImageSharp.Tests.TestUtilities; +using Xunit; +namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders +{ public class PorterDuffFunctionsTests { public static TheoryData NormalBlendFunctionData = new TheoryData() { diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs index b2a663d074..b95f8fdf61 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs @@ -1,19 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.PixelFormats.PixelBlenders -{ - using System; - using System.Collections.Generic; - using System.Numerics; - using System.Text; - using ImageSharp.PixelFormats; - using ImageSharp.PixelFormats.PixelBlenders; - using ImageSharp.Tests.TestUtilities; - using Xunit; +using System; +using System.Collections.Generic; +using System.Numerics; +using System.Text; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats.PixelBlenders; +using SixLabors.ImageSharp.Tests.TestUtilities; +using Xunit; +namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders +{ public class PorterDuffFunctionsTests_TPixel { private static Span AsSpan(T value) diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs index 6bcada0ff5..681aa6f0d1 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs @@ -1,18 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.PixelFormats -{ - using System; - using System.Collections.Generic; - using System.Text; - using ImageSharp.PixelFormats; - using ImageSharp.PixelFormats.PixelBlenders; - using ImageSharp.Tests.TestUtilities; - using Xunit; +using System; +using System.Collections.Generic; +using System.Text; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats.PixelBlenders; +using SixLabors.ImageSharp.Tests.TestUtilities; +using Xunit; +namespace SixLabors.ImageSharp.Tests.PixelFormats +{ public partial class PixelOperationsTests { diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs index 0a121cfce9..6a108503bf 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs @@ -1,16 +1,15 @@ -// ReSharper disable InconsistentNaming -// ReSharper disable AccessToDisposedClosure -namespace ImageSharp.Tests.PixelFormats -{ - using System; - using System.Numerics; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; - using Xunit.Abstractions; +using System; +using System.Numerics; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +using Xunit.Abstractions; +namespace SixLabors.ImageSharp.Tests.PixelFormats +{ public partial class PixelOperationsTests { diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs index 1d0d024fbb..4e85fe7e32 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs @@ -1,13 +1,13 @@ -// ReSharper disable InconsistentNaming -namespace ImageSharp.Tests -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ public class Rgb24Tests { public static readonly TheoryData ColorData = diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs index 5509cbddcf..a8d38b9381 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Numerics; - - using ImageSharp.PixelFormats; - - using Xunit; +using System; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ /// /// Tests the struct. /// diff --git a/tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs b/tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs index 1f5df6d880..1dd280bee4 100644 --- a/tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs @@ -1,17 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System.Numerics; - using System.Runtime.CompilerServices; - - using ImageSharp.PixelFormats; - - using Xunit; +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ /// /// Tests the struct. /// diff --git a/tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs b/tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs index 25a61453b2..b5d46ba769 100644 --- a/tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs @@ -1,11 +1,12 @@ -namespace ImageSharp.Tests.Colors -{ - using System.Numerics; - - using ImageSharp.PixelFormats; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. - using Xunit; +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +namespace SixLabors.ImageSharp.Tests.Colors +{ public class UnPackedPixelTests { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs index 642df598a3..221b4a9bff 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs @@ -1,51 +1,30 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Binarization -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class BinaryThresholdTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Binarization +{ + public class BinaryThresholdTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData BinaryThresholdValues - = new TheoryData - { - .25F, - .75F - }; - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(BinaryThresholdValues), DefaultPixelType)] - public void ImageShouldApplyBinaryThresholdFilter(TestImageProvider provider, float value) - where TPixel : struct, IPixel + [Fact] + public void BinaryThreshold_CorrectProcessor() { - using (Image image = provider.GetImage()) - { - image.BinaryThreshold(value) - .DebugSave(provider, value, Extensions.Bmp); - } + this.operations.BinaryThreshold(.23f); + var p = this.Verify>(); + Assert.Equal(.23f, p.Threshold); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(BinaryThresholdValues), DefaultPixelType)] - public void ImageShouldApplyBinaryThresholdInBox(TestImageProvider provider, float value) - where TPixel : struct, IPixel + [Fact] + public void BinaryThreshold_rect_CorrectProcessor() { - - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.BinaryThreshold(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); - - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + this.operations.BinaryThreshold(.93f, this.rect); + var p = this.Verify>(this.rect); + Assert.Equal(.93f, p.Threshold); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs index a06397c864..8aef37d4d1 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs @@ -1,92 +1,78 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Binarization -{ - using ImageSharp.Dithering; - using ImageSharp.Dithering.Ordered; - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.Dithering; +using SixLabors.ImageSharp.Dithering.Ordered; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using Moq; +using SixLabors.Primitives; +using Xunit; - public class DitherTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Binarization +{ + public class DitherTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData Ditherers = new TheoryData - { - { "Ordered", new Ordered() }, - { "Bayer", new Bayer() } - }; + private readonly IOrderedDither orderedDither; + private readonly IErrorDiffuser errorDiffuser; - public static readonly TheoryData ErrorDiffusers = new TheoryData + public DitherTest() { - { "Atkinson", new Atkinson() }, - { "Burks", new Burks() }, - { "FloydSteinberg", new FloydSteinberg() }, - { "JarvisJudiceNinke", new JarvisJudiceNinke() }, - { "Sierra2", new Sierra2() }, - { "Sierra3", new Sierra3() }, - { "SierraLite", new SierraLite() }, - { "Stucki", new Stucki() }, - }; - - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(Ditherers), DefaultPixelType)] - public void ImageShouldApplyDitherFilter(TestImageProvider provider, string name, IOrderedDither ditherer) - where TPixel : struct, IPixel + this.orderedDither = new Mock().Object; + this.errorDiffuser = new Mock().Object; + } + [Fact] + public void Dither_CorrectProcessor() { - using (Image image = provider.GetImage()) - { - image.Dither(ditherer) - .DebugSave(provider, name, Extensions.Bmp); - } + this.operations.Dither(orderedDither); + var p = this.Verify>(); + Assert.Equal(this.orderedDither, p.Dither); + Assert.Equal(0, p.Index); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(Ditherers), DefaultPixelType)] - public void ImageShouldApplyDitherFilterInBox(TestImageProvider provider, string name, IOrderedDither ditherer) - where TPixel : struct, IPixel + [Fact] + public void Dither_rect_CorrectProcessor() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Dither(ditherer, bounds) - .DebugSave(provider, name, Extensions.Bmp); - - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + this.operations.Dither(orderedDither, this.rect); + var p = this.Verify>(this.rect); + Assert.Equal(this.orderedDither, p.Dither); + Assert.Equal(0, p.Index); } - - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(ErrorDiffusers), DefaultPixelType)] - public void ImageShouldApplyDiffusionFilter(TestImageProvider provider, string name, IErrorDiffuser diffuser) - where TPixel : struct, IPixel + [Fact] + public void Dither_index_CorrectProcessor() { - using (Image image = provider.GetImage()) - { - image.Dither(diffuser, .5F) - .DebugSave(provider, name, Extensions.Bmp); - } + this.operations.Dither(orderedDither, 2); + var p = this.Verify>(); + Assert.Equal(this.orderedDither, p.Dither); + Assert.Equal(2, p.Index); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(ErrorDiffusers), DefaultPixelType)] - public void ImageShouldApplyDiffusionFilterInBox(TestImageProvider provider, string name, IErrorDiffuser diffuser) - where TPixel : struct, IPixel + [Fact] + public void Dither_index_rect_CorrectProcessor() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + this.operations.Dither(orderedDither, this.rect, 2); + var p = this.Verify>(this.rect); + Assert.Equal(this.orderedDither, p.Dither); + Assert.Equal(2, p.Index); + } + - image.Dither(diffuser,.5F, bounds) - .DebugSave(provider, name, Extensions.Bmp); + [Fact] + public void Dither_ErrorDifuser_CorrectProcessor() + { + this.operations.Dither(errorDiffuser, 4); + var p = this.Verify>(); + Assert.Equal(this.errorDiffuser, p.Diffuser); + Assert.Equal(4, p.Threshold); + } - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + [Fact] + public void Dither_ErrorDifuser_rect_CorrectProcessor() + { + this.operations.Dither(this.errorDiffuser, 3, this.rect); + var p = this.Verify>(this.rect); + Assert.Equal(this.errorDiffuser, p.Diffuser); + Assert.Equal(3, p.Threshold); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs index 4dc70fb0f5..f6efdc9a99 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs @@ -1,43 +1,27 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.ColorMatrix -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class BlackWhiteTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.ColorMatrix +{ + public class BlackWhiteTest : BaseImageOperationsExtensionTest { - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyBlackWhiteFilter(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void BlackWhite_CorrectProcessor() { - using (Image image = provider.GetImage()) - { - image.BlackWhite() - .DebugSave(provider, null, Extensions.Bmp); - } + this.operations.BlackWhite(); + var p = this.Verify>(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyBlackWhiteFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void BlackWhite_rect_CorrectProcessor() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.BlackWhite(bounds) - .DebugSave(provider, null, Extensions.Bmp); - - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + this.operations.BlackWhite( this.rect); + var p = this.Verify>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs index bc1c8ad226..cc80e32d58 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs @@ -1,57 +1,44 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.ColorMatrix -{ - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - using SixLabors.Primitives; - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Tests.TestUtilities; +using SixLabors.Primitives; +using Xunit; - public class ColorBlindnessTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.ColorMatrix +{ + public class ColorBlindnessTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData ColorBlindnessFilters - = new TheoryData - { - ColorBlindness.Achromatomaly, - ColorBlindness.Achromatopsia, - ColorBlindness.Deuteranomaly, - ColorBlindness.Deuteranopia, - ColorBlindness.Protanomaly, - ColorBlindness.Protanopia, - ColorBlindness.Tritanomaly, - ColorBlindness.Tritanopia + public static IEnumerable TheoryData = new[] { + new object[]{ new TestType>(), ColorBlindness.Achromatomaly }, + new object[]{ new TestType>(), ColorBlindness.Achromatopsia }, + new object[]{ new TestType>(), ColorBlindness.Deuteranomaly }, + new object[]{ new TestType>(), ColorBlindness.Deuteranopia }, + new object[]{ new TestType>(), ColorBlindness.Protanomaly }, + new object[]{ new TestType>(), ColorBlindness.Protanopia }, + new object[]{ new TestType>(), ColorBlindness.Tritanomaly }, + new object[]{ new TestType>(), ColorBlindness.Tritanopia } }; [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(ColorBlindnessFilters), DefaultPixelType)] - public void ImageShouldApplyColorBlindnessFilter(TestImageProvider provider, ColorBlindness colorBlindness) - where TPixel : struct, IPixel + [MemberData(nameof(TheoryData))] + public void ColorBlindness_CorrectProcessor(TestType testType, ColorBlindness colorBlindness) + where T : IImageProcessor { - using (Image image = provider.GetImage()) - { - image.ColorBlindness(colorBlindness) - .DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp); - } + this.operations.ColorBlindness(colorBlindness); + var p = this.Verify(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(ColorBlindnessFilters), DefaultPixelType)] - public void ImageShouldApplyColorBlindnessFilterInBox(TestImageProvider provider, ColorBlindness colorBlindness) - where TPixel : struct, IPixel + [MemberData(nameof(TheoryData))] + public void ColorBlindness_rect_CorrectProcessor(TestType testType, ColorBlindness colorBlindness) + where T : IImageProcessor { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.ColorBlindness(colorBlindness, bounds) - .DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp); - - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + this.operations.ColorBlindness(colorBlindness, this.rect); + var p = this.Verify(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs index 9bf55a6d25..14697c6234 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs @@ -1,61 +1,47 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.ColorMatrix -{ - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - using SixLabors.Primitives; - using Xunit; +using System.Collections; +using System.Collections.Generic; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Tests.TestUtilities; +using SixLabors.Primitives; +using Xunit; - public class GrayscaleTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.ColorMatrix +{ + public class GrayscaleTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData GrayscaleModeTypes - = new TheoryData - { - GrayscaleMode.Bt601, - GrayscaleMode.Bt709 - }; + public static IEnumerable ModeTheoryData = new[] { + new object[]{ new TestType>(), GrayscaleMode.Bt709 } + }; - /// - /// Use test patterns over loaded images to save decode time. - /// [Theory] - [WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)] - public void ImageShouldApplyGrayscaleFilterAll(TestImageProvider provider, GrayscaleMode value) - where TPixel : struct, IPixel + [MemberData(nameof(ModeTheoryData))] + public void Grayscale_mode_CorrectProcessor(TestType testType, GrayscaleMode mode) + where T : IImageProcessor { - using (Image image = provider.GetImage()) - { - image.Grayscale(value); - byte[] data = new byte[3]; - for (int i = 0; i < image.Pixels.Length; i++) - { - image.Pixels[i].ToXyzBytes(data, 0); - Assert.Equal(data[0], data[1]); - Assert.Equal(data[1], data[2]); - } + this.operations.Grayscale(mode); + var p = this.Verify(); - image.DebugSave(provider, value.ToString()); - } } [Theory] - [WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)] - public void ImageShouldApplyGrayscaleFilterInBox(TestImageProvider provider, GrayscaleMode value) - where TPixel : struct, IPixel + [MemberData(nameof(ModeTheoryData))] + public void Grayscale_mode_rect_CorrectProcessor(TestType testType, GrayscaleMode mode) + where T : IImageProcessor { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); - image.Grayscale(value, bounds) - .DebugSave(provider, value.ToString()); + this.operations.Grayscale(mode, this.rect); + this.Verify(this.rect); + } - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + [Fact] + public void Grayscale_rect_CorrectProcessor() + { + this.operations.Grayscale(this.rect); + this.Verify>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs index ba1cf2b8f7..0ec03dfdd5 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs @@ -1,50 +1,31 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.ColorMatrix -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class HueTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.ColorMatrix +{ + public class HueTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData HueValues - = new TheoryData + [Fact] + public void Hue_amount_HueProcessorDefaultsSet() { - 180, - -180 - }; + this.operations.Hue(34f); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(HueValues), DefaultPixelType)] - public void ImageShouldApplyHueFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - image.Hue(value) - .DebugSave(provider, value, Extensions.Bmp); - } + Assert.Equal(34f, processor.Angle); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(HueValues), DefaultPixelType)] - public void ImageShouldApplyHueFilterInBox(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void Hue_amount_rect_HueProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Hue(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + this.operations.Hue(5f, this.rect); + var processor = this.Verify>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(5f, processor.Angle); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs index 971cdb6d81..61a4124c9e 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs @@ -1,43 +1,27 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.ColorMatrix -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class KodachromeTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.ColorMatrix +{ + public class KodachromeTest : BaseImageOperationsExtensionTest { - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyKodachromeFilter(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Kodachrome_amount_KodachromeProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Kodachrome() - .DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Kodachrome(); + var processor = this.Verify>(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyKodachromeFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Kodachrome_amount_rect_KodachromeProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Kodachrome(bounds) - .DebugSave(provider, null, Extensions.Bmp); - - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + this.operations.Kodachrome(this.rect); + var processor = this.Verify>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs index 5b41cdb3b7..32107cb716 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs @@ -1,45 +1,28 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System.IO; - - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using System.IO; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class LomographTest : FileTestBase +namespace SixLabors.ImageSharp.Tests +{ + public class LomographTest : BaseImageOperationsExtensionTest { - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyLomographFilter(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Lomograph_amount_LomographProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Lomograph() - .DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Lomograph(); + var processor = this.Verify>(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyLomographFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Lomograph_amount_rect_LomographProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Lomograph(bounds) - .DebugSave(provider, null, Extensions.Bmp); - - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + this.operations.Lomograph(this.rect); + var processor = this.Verify>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs index 48f7a6c0a8..10433aa9b1 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs @@ -1,43 +1,27 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.ColorMatrix -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class PolaroidTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.ColorMatrix +{ + public class PolaroidTest : BaseImageOperationsExtensionTest { - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyPolaroidFilter(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Polaroid_amount_PolaroidProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Polaroid() - .DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Polaroid(); + var processor = this.Verify>(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyPolaroidFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Polaroid_amount_rect_PolaroidProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Polaroid(bounds) - .DebugSave(provider, null, Extensions.Bmp); - - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + this.operations.Polaroid(this.rect); + var processor = this.Verify>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs index a4a4f3bb51..5a44023293 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs @@ -1,50 +1,32 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.ColorMatrix -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class SaturationTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.ColorMatrix +{ + public class SaturationTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData SaturationValues - = new TheoryData - { - 50 , - -50 , - }; - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(SaturationValues), DefaultPixelType)] - public void ImageShouldApplySaturationFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void Saturation_amount_SaturationProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Saturation(value) - .DebugSave(provider, value, Extensions.Bmp); - } + this.operations.Saturation(34); + var processor = this.Verify>(); + + Assert.Equal(34, processor.Amount); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(SaturationValues), DefaultPixelType)] - public void ImageShouldApplySaturationFilterInBox(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void Saturation_amount_rect_SaturationProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Saturation(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + this.operations.Saturation(5, this.rect); + var processor = this.Verify>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(5, processor.Amount); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs index af554e30d8..b2117b94a2 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs @@ -1,43 +1,27 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.ColorMatrix -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class SepiaTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.ColorMatrix +{ + public class SepiaTest : BaseImageOperationsExtensionTest { - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplySepiaFilter(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Sepia_amount_SepiaProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Sepia() - .DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Sepia(); + var processor = this.Verify>(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplySepiaFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Sepia_amount_rect_SepiaProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Sepia(bounds) - .DebugSave(provider, null, Extensions.Bmp); - - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + this.operations.Sepia(this.rect); + var processor = this.Verify>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs index ef049a539a..cd0e8e5ab0 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs @@ -1,50 +1,40 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Convolution -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class BoxBlurTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Convolution +{ + public class BoxBlurTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData BoxBlurValues - = new TheoryData + [Fact] + public void BoxBlur_BoxBlurProcessorDefaultsSet() { - 3, - 5 - }; + this.operations.BoxBlur(); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(BoxBlurValues), DefaultPixelType)] - public void ImageShouldApplyBoxBlurFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - image.BoxBlur(value) - .DebugSave(provider, value, Extensions.Bmp); - } + Assert.Equal(7, processor.Radius); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(BoxBlurValues), DefaultPixelType)] - public void ImageShouldApplyBoxBlurFilterInBox(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void BoxBlur_amount_BoxBlurProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + this.operations.BoxBlur(34); + var processor = this.Verify>(); - image.BoxBlur(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + Assert.Equal(34, processor.Radius); + } + + [Fact] + public void BoxBlur_amount_rect_BoxBlurProcessorDefaultsSet() + { + this.operations.BoxBlur(5, this.rect); + var processor = this.Verify>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(5, processor.Radius); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs index d5817ab14f..5a711bd04e 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs @@ -1,59 +1,70 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Convolution -{ - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - using SixLabors.Primitives; - using Xunit; +using System.Collections.Generic; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Tests.TestUtilities; +using SixLabors.Primitives; +using Xunit; - public class DetectEdgesTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Convolution +{ + public class DetectEdgesTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData DetectEdgesFilters - = new TheoryData + + [Fact] + public void DetectEdges_SobelProcessorDefaultsSet() { - EdgeDetection.Kayyali, - EdgeDetection.Kirsch, - EdgeDetection.Lapacian3X3, - EdgeDetection.Lapacian5X5, - EdgeDetection.LaplacianOfGaussian, - EdgeDetection.Prewitt, - EdgeDetection.RobertsCross, - EdgeDetection.Robinson, - EdgeDetection.Scharr, - EdgeDetection.Sobel + this.operations.DetectEdges(); + var processor = this.Verify>(); + + Assert.True(processor.Grayscale); + } + + [Fact] + public void DetectEdges_Rect_SobelProcessorDefaultsSet() + { + this.operations.DetectEdges(this.rect); + var processor = this.Verify>(this.rect); + + Assert.True(processor.Grayscale); + } + public static IEnumerable EdgeDetectionTheoryData => new[] { + new object[]{ new TestType>(), EdgeDetection.Kayyali }, + new object[]{ new TestType>(), EdgeDetection.Kirsch }, + new object[]{ new TestType>(), EdgeDetection.Lapacian3X3 }, + new object[]{ new TestType>(), EdgeDetection.Lapacian5X5 }, + new object[]{ new TestType>(), EdgeDetection.LaplacianOfGaussian }, + new object[]{ new TestType>(), EdgeDetection.Prewitt }, + new object[]{ new TestType>(), EdgeDetection.RobertsCross }, + new object[]{ new TestType>(), EdgeDetection.Robinson }, + new object[]{ new TestType>(), EdgeDetection.Scharr }, + new object[]{ new TestType>(), EdgeDetection.Sobel }, }; [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)] - public void ImageShouldApplyDetectEdgesFilter(TestImageProvider provider, EdgeDetection detector) - where TPixel : struct, IPixel + [MemberData(nameof(EdgeDetectionTheoryData))] + public void DetectEdges_filter_SobelProcessorDefaultsSet(TestType type, EdgeDetection filter) + where TProcessor : IEdgeDetectorProcessor { - using (Image image = provider.GetImage()) - { - image.DetectEdges(detector) - .DebugSave(provider, detector.ToString(), Extensions.Bmp); - } + this.operations.DetectEdges(filter); + var processor = this.Verify(); + + Assert.True(processor.Grayscale); } [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)] - public void ImageShouldApplyDetectEdgesFilterInBox(TestImageProvider provider, EdgeDetection detector) - where TPixel : struct, IPixel + [MemberData(nameof(EdgeDetectionTheoryData))] + public void DetectEdges_filter_grayscale_SobelProcessorDefaultsSet(TestType type, EdgeDetection filter) + where TProcessor : IEdgeDetectorProcessor { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.DetectEdges(detector, bounds) - .DebugSave(provider, detector.ToString(), Extensions.Bmp); + var grey = (int)filter % 2 == 0; + this.operations.DetectEdges(filter, grey); + var processor = this.Verify(); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(grey, processor.Grayscale); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs index fa4e4b0b6b..d0773a0bfe 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs @@ -1,50 +1,40 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Convolution -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class GaussianBlurTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Convolution +{ + public class GaussianBlurTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData GaussianBlurValues - = new TheoryData + [Fact] + public void GaussianBlur_GaussianBlurProcessorDefaultsSet() { - 3, - 5 - }; + this.operations.GaussianBlur(); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(GaussianBlurValues), DefaultPixelType)] - public void ImageShouldApplyGaussianBlurFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - image.GaussianBlur(value) - .DebugSave(provider, value, Extensions.Bmp); - } + Assert.Equal(3f, processor.Sigma); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(GaussianBlurValues), DefaultPixelType)] - public void ImageShouldApplyGaussianBlurFilterInBox(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void GaussianBlur_amount_GaussianBlurProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + this.operations.GaussianBlur(0.2f); + var processor = this.Verify>(); - image.GaussianBlur(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + Assert.Equal(.2f, processor.Sigma); + } + + [Fact] + public void GaussianBlur_amount_rect_GaussianBlurProcessorDefaultsSet() + { + this.operations.GaussianBlur(0.6f, this.rect); + var processor = this.Verify>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(.6f, processor.Sigma); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs index d15042ee69..c7c78a21a6 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs @@ -1,50 +1,40 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Convolution -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class GaussianSharpenTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Convolution +{ + public class GaussianSharpenTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData GaussianSharpenValues - = new TheoryData + [Fact] + public void GaussianSharpen_GaussianSharpenProcessorDefaultsSet() { - 3, - 5 - }; + this.operations.GaussianSharpen(); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)] - public void ImageShouldApplyGaussianSharpenFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - image.GaussianSharpen(value) - .DebugSave(provider, value, Extensions.Bmp); - } + Assert.Equal(3f, processor.Sigma); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)] - public void ImageShouldApplyGaussianSharpenFilterInBox(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void GaussianSharpen_amount_GaussianSharpenProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + this.operations.GaussianSharpen(0.2f); + var processor = this.Verify>(); - image.GaussianSharpen(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + Assert.Equal(.2f, processor.Sigma); + } + + [Fact] + public void GaussianSharpen_amount_rect_GaussianSharpenProcessorDefaultsSet() + { + this.operations.GaussianSharpen(0.6f, this.rect); + var processor = this.Verify>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(.6f, processor.Sigma); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/DelegateTest.cs b/tests/ImageSharp.Tests/Processing/DelegateTest.cs new file mode 100644 index 0000000000..518a28bea0 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/DelegateTest.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing +{ + public class DelegateTest : BaseImageOperationsExtensionTest + { + [Fact] + public void Run_CreatedDelegateProcessor() + { + Action> action = (i) => { }; + this.operations.Apply(action); + + DelegateProcessor processor = this.Verify>(); + Assert.Equal(action, processor.Action); + } + } +} diff --git a/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs b/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs index 34a24e70be..9840d71c7a 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs @@ -1,50 +1,31 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Effects -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class AlphaTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Effects +{ + public class AlphaTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData AlphaValues - = new TheoryData + [Fact] + public void Alpha_amount_AlphaProcessorDefaultsSet() { - 20/100F, - 80/100F - }; + this.operations.Alpha(0.2f); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(AlphaValues), DefaultPixelType)] - public void ImageShouldApplyAlphaFilter(TestImageProvider provider, float value) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - image.Alpha(value) - .DebugSave(provider, value, Extensions.Png); - } + Assert.Equal(.2f, processor.Value); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(AlphaValues), DefaultPixelType)] - public void ImageShouldApplyAlphaFilterInBox(TestImageProvider provider, float value) - where TPixel : struct, IPixel + [Fact] + public void Alpha_amount_rect_AlphaProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Alpha(value, bounds) - .DebugSave(provider, value, Extensions.Png); + this.operations.Alpha(0.6f, this.rect); + var processor = this.Verify>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(.6f, processor.Value); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs index 63efbf3e73..a24b8a4d47 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs @@ -1,43 +1,53 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Effects -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class BackgroundColorTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Effects +{ + public class BackgroundColorTest : BaseImageOperationsExtensionTest { - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyBackgroundColorFilter(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void BackgroundColor_amount_BackgroundColorProcessorDefaultsSet() + { + this.operations.BackgroundColor(Rgba32.BlanchedAlmond); + var processor = this.Verify>(); + + Assert.Equal(GraphicsOptions.Default, processor.GraphicsOptions); + Assert.Equal(Rgba32.BlanchedAlmond, processor.Value); + } + + [Fact] + public void BackgroundColor_amount_rect_BackgroundColorProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.BackgroundColor(NamedColors.HotPink) - .DebugSave(provider, null, Extensions.Bmp); - } + this.operations.BackgroundColor(Rgba32.BlanchedAlmond, this.rect); + var processor = this.Verify>(this.rect); + + Assert.Equal(GraphicsOptions.Default, processor.GraphicsOptions); + Assert.Equal(Rgba32.BlanchedAlmond, processor.Value); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyBackgroundColorFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void BackgroundColor_amount_options_BackgroundColorProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + this.operations.BackgroundColor(Rgba32.BlanchedAlmond, this.options); + var processor = this.Verify>(); - image.BackgroundColor(NamedColors.HotPink, bounds) - .DebugSave(provider, null, Extensions.Bmp); + Assert.Equal(this.options, processor.GraphicsOptions); + Assert.Equal(Rgba32.BlanchedAlmond, processor.Value); + } + + [Fact] + public void BackgroundColor_amount_rect_options_BackgroundColorProcessorDefaultsSet() + { + this.operations.BackgroundColor(Rgba32.BlanchedAlmond, this.rect, this.options); + var processor = this.Verify>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(this.options, processor.GraphicsOptions); + Assert.Equal(Rgba32.BlanchedAlmond, processor.Value); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs index c3b37705a9..d057f9233a 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs @@ -1,50 +1,31 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Effects -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class BrightnessTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Effects +{ + public class BrightnessTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData BrightnessValues - = new TheoryData + [Fact] + public void Brightness_amount_BrightnessProcessorDefaultsSet() { - 50, - -50 - }; + this.operations.Brightness(23); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(BrightnessValues), DefaultPixelType)] - public void ImageShouldApplyBrightnessFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - image.Brightness(value) - .DebugSave(provider, value, Extensions.Bmp); - } + Assert.Equal(23, processor.Value); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(BrightnessValues), DefaultPixelType)] - public void ImageShouldApplyBrightnessFilterInBox(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void Brightness_amount_rect_BrightnessProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Brightness(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + this.operations.Brightness(23, this.rect); + var processor = this.Verify>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); ; - } + Assert.Equal(23, processor.Value); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs index 892eb93622..374937ea38 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs @@ -1,50 +1,31 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Effects -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class ContrastTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Effects +{ + public class ContrastTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData ContrastValues - = new TheoryData + [Fact] + public void Contrast_amount_ContrastProcessorDefaultsSet() { - 50, - -50 - }; + this.operations.Contrast(23); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(ContrastValues), DefaultPixelType)] - public void ImageShouldApplyContrastFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - image.Contrast(value) - .DebugSave(provider, value, Extensions.Bmp); - } + Assert.Equal(23, processor.Value); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(ContrastValues), DefaultPixelType)] - public void ImageShouldApplyContrastFilterInBox(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void Contrast_amount_rect_ContrastProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Contrast(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + this.operations.Contrast(23, this.rect); + var processor = this.Verify>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(23, processor.Value); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs index 3d8b3d1a1f..ad74b3c909 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs @@ -1,43 +1,27 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Effects -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class InvertTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Effects +{ + public class InvertTest : BaseImageOperationsExtensionTest { - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyInvertFilter(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Invert_InvertProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Invert() - .DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Invert(); + var processor = this.Verify>(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyInvertFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Pixelate_rect_PixelateProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Invert(bounds) - .DebugSave(provider, null, Extensions.Bmp); - - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + this.operations.Invert(this.rect); + var processor = this.Verify>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs index 3d0e8f1177..36de67188f 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs @@ -1,50 +1,52 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class OilPaintTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Effects +{ + public class OilPaintTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData OilPaintValues - = new TheoryData - { - { 15, 10 }, - { 6, 5 } - }; - - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)] - public void ImageShouldApplyOilPaintFilter(TestImageProvider provider, int levels, int brushSize) - where TPixel : struct, IPixel + [Fact] + public void OilPaint_OilPaintingProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.OilPaint(levels, brushSize) - .DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp); - } + this.operations.OilPaint(); + var processor = this.Verify>(); + + Assert.Equal(10, processor.Levels); + Assert.Equal(15, processor.BrushSize); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)] - public void ImageShouldApplyOilPaintFilterInBox(TestImageProvider provider, int levels, int brushSize) - where TPixel : struct, IPixel + [Fact] + public void OilPaint_rect_OilPaintingProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + this.operations.OilPaint(this.rect); + var processor = this.Verify>(this.rect); - image.OilPaint(levels, brushSize, bounds) - .DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp); + Assert.Equal(10, processor.Levels); + Assert.Equal(15, processor.BrushSize); + } + [Fact] + public void OilPaint_Levels_Brsuh_OilPaintingProcessorDefaultsSet() + { + this.operations.OilPaint(34, 65); + var processor = this.Verify>(); + + Assert.Equal(34, processor.Levels); + Assert.Equal(65, processor.BrushSize); + } + + [Fact] + public void OilPaint_Levels_Brsuh_rect_OilPaintingProcessorDefaultsSet() + { + this.operations.OilPaint(54, 43, this.rect); + var processor = this.Verify>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds, 0.001F); - } + Assert.Equal(54, processor.Levels); + Assert.Equal(43, processor.BrushSize); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs index 253f1f4598..8b50e14861 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs @@ -1,84 +1,40 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Effects -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class PixelateTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Effects +{ + public class PixelateTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData PixelateValues - = new TheoryData - { - 4 , - 8 - }; - - [Theory] - [WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)] - public void ImageShouldApplyPixelateFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void Pixelate_PixelateProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Pixelate(value) - .DebugSave(provider, value, Extensions.Bmp); + this.operations.Pixelate(); + var processor = this.Verify>(); - // Test the neigbouring pixels - for (int y = 0; y < image.Height; y += value) - { - for (int x = 0; x < image.Width; x += value) - { - TPixel source = image[x, y]; - for (int pixY = y; pixY < y + value && pixY < image.Height; pixY++) - { - for (int pixX = x; pixX < x + value && pixX < image.Width; pixX++) - { - Assert.Equal(source, image[pixX, pixY]); - } - } - } - } - } + Assert.Equal(4, processor.Size); } - [Theory] - [WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)] - public void ImageShouldApplyPixelateFilterInBox(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void Pixelate_Size_PixelateProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); + this.operations.Pixelate(12); + var processor = this.Verify>(); - image.Pixelate(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); - - for (int y = 0; y < image.Height; y++) - { - for (int x = 0; x < image.Width; x++) - { - int tx = x; - int ty = y; - TPixel sourceColor = source[tx, ty]; - if (bounds.Contains(tx, ty)) - { - int sourceX = tx - ((tx - bounds.Left) % value) + (value / 2); - int sourceY = ty - ((ty - bounds.Top) % value) + (value / 2); + Assert.Equal(12, processor.Size); + } - sourceColor = image[sourceX, sourceY]; - } - Assert.Equal(sourceColor, image[tx, ty]); - } - } + [Fact] + public void Pixelate_Size_rect_PixelateProcessorDefaultsSet() + { + this.operations.Pixelate(23, this.rect); + var processor = this.Verify>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(23, processor.Size); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs index d0633dca59..9e7a046507 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs @@ -1,67 +1,59 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Overlays -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; - public class GlowTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Overlays +{ + public class GlowTest : BaseImageOperationsExtensionTest { - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyGlowFilter(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Glow_GlowProcessorWithDefaultValues() { - using (Image image = provider.GetImage()) - { - image.Glow() - .DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Glow(); + var p = this.Verify>(); + + Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(Rgba32.Black, p.GlowColor); + Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyGlowFilterColor(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Glow_Color_GlowProcessorWithDefaultValues() { - using (Image image = provider.GetImage()) - { - image.Glow(NamedColors.Orange) - .DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Glow(Rgba32.Aquamarine); + var p = this.Verify>(); + + Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(Rgba32.Aquamarine, p.GlowColor); + Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyGlowFilterRadius(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Glow_Radux_GlowProcessorWithDefaultValues() { - using (Image image = provider.GetImage()) - { - image.Glow(image.Width / 4F) - .DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Glow(3.5f); + var p = this.Verify>(); + + Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(Rgba32.Black, p.GlowColor); + Assert.Equal(ValueSize.Absolute(3.5f), p.Radius); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyGlowFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Glow_Rect_GlowProcessorWithDefaultValues() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Glow(bounds) - .DebugSave(provider, null, Extensions.Bmp); + var rect = new Rectangle(12, 123, 43, 65); + this.operations.Glow(rect); + var p = this.Verify>(rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(Rgba32.Black, p.GlowColor); + Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs index 56fcf0ee0d..e082e42cd7 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs @@ -1,67 +1,64 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Overlays -{ - using ImageSharp.PixelFormats; - using SixLabors.Primitives; - using Xunit; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Tests.TestUtilities; +using SixLabors.Primitives; +using Xunit; - public class VignetteTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Overlays +{ + public class VignetteTest : BaseImageOperationsExtensionTest { - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyVignetteFilter(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Vignette_VignetteProcessorWithDefaultValues() { - using (Image image = provider.GetImage()) - { - image.Vignette() - .DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Vignette(); + var p = this.Verify>(); + + Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(Rgba32.Black, p.VignetteColor); + Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX); + Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyVignetteFilterColor(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Vignette_Color_VignetteProcessorWithDefaultValues() { - using (Image image = provider.GetImage()) - { - image.Vignette(NamedColors.Orange) - .DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Vignette(Rgba32.Aquamarine); + var p = this.Verify>(); + + Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(Rgba32.Aquamarine, p.VignetteColor); + Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX); + Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyVignetteFilterRadius(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Vignette_Radux_VignetteProcessorWithDefaultValues() { - using (Image image = provider.GetImage()) - { - image.Vignette(image.Width / 4F, image.Height / 4F) - .DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Vignette(3.5f, 12123f); + var p = this.Verify>(); + + Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(Rgba32.Black, p.VignetteColor); + Assert.Equal(ValueSize.Absolute(3.5f), p.RadiusX); + Assert.Equal(ValueSize.Absolute(12123f), p.RadiusY); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyVignetteFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Vignette_Rect_VignetteProcessorWithDefaultValues() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Vignette(bounds) - .DebugSave(provider, null, Extensions.Bmp); + var rect = new Rectangle(12, 123, 43, 65); + this.operations.Vignette(rect); + var p = this.Verify>(rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(Rgba32.Black, p.VignetteColor); + Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX); + Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs new file mode 100644 index 0000000000..86a66eab04 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs @@ -0,0 +1,51 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization +{ + public class BinaryThresholdTest : FileTestBase + { + public static readonly TheoryData BinaryThresholdValues + = new TheoryData + { + .25F, + .75F + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(BinaryThresholdValues), DefaultPixelType)] + public void ImageShouldApplyBinaryThresholdFilter(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.BinaryThreshold(value)); + image.DebugSave(provider, value); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(BinaryThresholdValues), DefaultPixelType)] + public void ImageShouldApplyBinaryThresholdInBox(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.BinaryThreshold(value, bounds)); + image.DebugSave(provider, value); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs new file mode 100644 index 0000000000..4b5c8fb091 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs @@ -0,0 +1,92 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Dithering; +using SixLabors.ImageSharp.Dithering.Ordered; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization +{ + public class DitherTest : FileTestBase + { + public static readonly TheoryData Ditherers = new TheoryData + { + { "Ordered", new Ordered() }, + { "Bayer", new Bayer() } + }; + + public static readonly TheoryData ErrorDiffusers = new TheoryData + { + { "Atkinson", new Atkinson() }, + { "Burks", new Burks() }, + { "FloydSteinberg", new FloydSteinberg() }, + { "JarvisJudiceNinke", new JarvisJudiceNinke() }, + { "Sierra2", new Sierra2() }, + { "Sierra3", new Sierra3() }, + { "SierraLite", new SierraLite() }, + { "Stucki", new Stucki() }, + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(Ditherers), DefaultPixelType)] + public void ImageShouldApplyDitherFilter(TestImageProvider provider, string name, IOrderedDither ditherer) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Dither(ditherer)); + image.DebugSave(provider, name); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(Ditherers), DefaultPixelType)] + public void ImageShouldApplyDitherFilterInBox(TestImageProvider provider, string name, IOrderedDither ditherer) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Dither(ditherer, bounds)); + image.DebugSave(provider, name); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(ErrorDiffusers), DefaultPixelType)] + public void ImageShouldApplyDiffusionFilter(TestImageProvider provider, string name, IErrorDiffuser diffuser) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Dither(diffuser, .5F)); + image.DebugSave(provider, name); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(ErrorDiffusers), DefaultPixelType)] + public void ImageShouldApplyDiffusionFilterInBox(TestImageProvider provider, string name, IErrorDiffuser diffuser) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Dither(diffuser, .5F, bounds)); + image.DebugSave(provider, name); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs new file mode 100644 index 0000000000..d796a62aaa --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs @@ -0,0 +1,43 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix +{ + public class BlackWhiteTest : FileTestBase + { + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyBlackWhiteFilter(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.BlackWhite()); + image.DebugSave(provider); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyBlackWhiteFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.BlackWhite(bounds)); + image.DebugSave(provider); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs new file mode 100644 index 0000000000..cdfbf4abdf --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs @@ -0,0 +1,57 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix +{ + public class ColorBlindnessTest : FileTestBase + { + public static readonly TheoryData ColorBlindnessFilters + = new TheoryData + { + ColorBlindness.Achromatomaly, + ColorBlindness.Achromatopsia, + ColorBlindness.Deuteranomaly, + ColorBlindness.Deuteranopia, + ColorBlindness.Protanomaly, + ColorBlindness.Protanopia, + ColorBlindness.Tritanomaly, + ColorBlindness.Tritanopia + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(ColorBlindnessFilters), DefaultPixelType)] + public void ImageShouldApplyColorBlindnessFilter(TestImageProvider provider, ColorBlindness colorBlindness) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.ColorBlindness(colorBlindness)); + image.DebugSave(provider, colorBlindness.ToString()); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(ColorBlindnessFilters), DefaultPixelType)] + public void ImageShouldApplyColorBlindnessFilterInBox(TestImageProvider provider, ColorBlindness colorBlindness) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.ColorBlindness(colorBlindness, bounds)); + image.DebugSave(provider, colorBlindness.ToString()); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs new file mode 100644 index 0000000000..93c053bdde --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs @@ -0,0 +1,61 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix +{ + public class GrayscaleTest : FileTestBase + { + public static readonly TheoryData GrayscaleModeTypes + = new TheoryData + { + GrayscaleMode.Bt601, + GrayscaleMode.Bt709 + }; + + /// + /// Use test patterns over loaded images to save decode time. + /// + [Theory] + [WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)] + public void ImageShouldApplyGrayscaleFilterAll(TestImageProvider provider, GrayscaleMode value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Grayscale(value)); + byte[] data = new byte[3]; + for (int i = 0; i < image.Pixels.Length; i++) + { + image.Pixels[i].ToXyzBytes(data, 0); + Assert.Equal(data[0], data[1]); + Assert.Equal(data[1], data[2]); + } + + image.DebugSave(provider, value.ToString()); + } + } + + [Theory] + [WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)] + public void ImageShouldApplyGrayscaleFilterInBox(TestImageProvider provider, GrayscaleMode value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); + image.Mutate(x => x.Grayscale(value, bounds)); + image.DebugSave(provider, value.ToString()); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs new file mode 100644 index 0000000000..1cc146af25 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs @@ -0,0 +1,50 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix +{ + public class HueTest : FileTestBase + { + public static readonly TheoryData HueValues + = new TheoryData + { + 180, + -180 + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(HueValues), DefaultPixelType)] + public void ImageShouldApplyHueFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Hue(value)); + image.DebugSave(provider, value); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(HueValues), DefaultPixelType)] + public void ImageShouldApplyHueFilterInBox(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Hue(value, bounds)); + image.DebugSave(provider, value); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs new file mode 100644 index 0000000000..dec41da547 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs @@ -0,0 +1,43 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix +{ + public class KodachromeTest : FileTestBase + { + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyKodachromeFilter(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Kodachrome()); + image.DebugSave(provider); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyKodachromeFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Kodachrome(bounds)); + image.DebugSave(provider); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs new file mode 100644 index 0000000000..5f662a7619 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs @@ -0,0 +1,43 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix +{ + public class LomographTest : FileTestBase + { + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyLomographFilter(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Lomograph()); + image.DebugSave(provider); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyLomographFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Lomograph(bounds)); + image.DebugSave(provider); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs new file mode 100644 index 0000000000..de66422542 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs @@ -0,0 +1,43 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix +{ + public class PolaroidTest : FileTestBase + { + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyPolaroidFilter(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Polaroid()); + image.DebugSave(provider); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyPolaroidFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Polaroid(bounds)); + image.DebugSave(provider); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs new file mode 100644 index 0000000000..5cbb1ba814 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs @@ -0,0 +1,50 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix +{ + public class SaturationTest : FileTestBase + { + public static readonly TheoryData SaturationValues + = new TheoryData + { + 50 , + -50 , + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(SaturationValues), DefaultPixelType)] + public void ImageShouldApplySaturationFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Saturation(value)); + image.DebugSave(provider, value); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(SaturationValues), DefaultPixelType)] + public void ImageShouldApplySaturationFilterInBox(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Saturation(value, bounds)); + image.DebugSave(provider, value); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs new file mode 100644 index 0000000000..fbdaee82c1 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs @@ -0,0 +1,43 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix +{ + public class SepiaTest : FileTestBase + { + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplySepiaFilter(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Sepia()); + image.DebugSave(provider); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplySepiaFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Sepia(bounds)); + image.DebugSave(provider); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs new file mode 100644 index 0000000000..c6150c5ba8 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs @@ -0,0 +1,50 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution +{ + public class BoxBlurTest : FileTestBase + { + public static readonly TheoryData BoxBlurValues + = new TheoryData + { + 3, + 5 + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(BoxBlurValues), DefaultPixelType)] + public void ImageShouldApplyBoxBlurFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.BoxBlur(value)); + image.DebugSave(provider, value); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(BoxBlurValues), DefaultPixelType)] + public void ImageShouldApplyBoxBlurFilterInBox(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.BoxBlur(value, bounds)); + image.DebugSave(provider, value); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs new file mode 100644 index 0000000000..54686cb4cc --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs @@ -0,0 +1,89 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution +{ + public class DetectEdgesTest : FileTestBase + { + public static readonly string[] CommonTestImages = { TestImages.Png.Bike }; + + public static readonly TheoryData DetectEdgesFilters = new TheoryData + { + EdgeDetection.Kayyali, + EdgeDetection.Kirsch, + EdgeDetection.Lapacian3X3, + EdgeDetection.Lapacian5X5, + EdgeDetection.LaplacianOfGaussian, + EdgeDetection.Prewitt, + EdgeDetection.RobertsCross, + EdgeDetection.Robinson, + EdgeDetection.Scharr, + EdgeDetection.Sobel + }; + + [Theory] + [WithTestPatternImages(nameof(DetectEdgesFilters), 100, 100, DefaultPixelType)] + [WithFileCollection(nameof(CommonTestImages), nameof(DetectEdgesFilters), DefaultPixelType)] + public void DetectEdges_WorksWithAllFilters(TestImageProvider provider, EdgeDetection detector) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.DetectEdges(detector)); + image.DebugSave(provider, detector.ToString()); + image.CompareToReferenceOutput(provider, detector.ToString()); + } + } + + [Theory] + [WithFileCollection(nameof(CommonTestImages), CommonNonDefaultPixelTypes)] + public void DetectEdges_IsNotBoundToSinglePixelType(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.DetectEdges()); + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [WithFile(TestImages.Gif.Giphy, DefaultPixelType)] + public void DetectEdges_IsAppliedToAllFrames(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.DetectEdges()); + image.DebugSave(provider, extension: "gif"); + } + } + + [Theory] + [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] + public void DetectEdges_InBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.DetectEdges(bounds)); + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + + // TODO: We don't need this any longer after switching to ReferenceImages + //ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs new file mode 100644 index 0000000000..b97ab7f602 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs @@ -0,0 +1,50 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution +{ + public class GaussianBlurTest : FileTestBase + { + public static readonly TheoryData GaussianBlurValues + = new TheoryData + { + 3, + 5 + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(GaussianBlurValues), DefaultPixelType)] + public void ImageShouldApplyGaussianBlurFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.GaussianBlur(value)); + image.DebugSave(provider, value); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(GaussianBlurValues), DefaultPixelType)] + public void ImageShouldApplyGaussianBlurFilterInBox(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.GaussianBlur(value, bounds)); + image.DebugSave(provider, value); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs new file mode 100644 index 0000000000..5d9db0b811 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs @@ -0,0 +1,50 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution +{ + public class GaussianSharpenTest : FileTestBase + { + public static readonly TheoryData GaussianSharpenValues + = new TheoryData + { + 3, + 5 + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)] + public void ImageShouldApplyGaussianSharpenFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.GaussianSharpen(value)); + image.DebugSave(provider, value); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)] + public void ImageShouldApplyGaussianSharpenFilterInBox(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.GaussianSharpen(value, bounds)); + image.DebugSave(provider, value); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs new file mode 100644 index 0000000000..66514e540f --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs @@ -0,0 +1,50 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects +{ + public class AlphaTest : FileTestBase + { + public static readonly TheoryData AlphaValues + = new TheoryData + { + 20/100F, + 80/100F + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(AlphaValues), DefaultPixelType)] + public void ImageShouldApplyAlphaFilter(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Alpha(value)); + image.DebugSave(provider, value); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(AlphaValues), DefaultPixelType)] + public void ImageShouldApplyAlphaFilterInBox(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Alpha(value, bounds)); + image.DebugSave(provider, value); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs new file mode 100644 index 0000000000..bea9bfffc4 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs @@ -0,0 +1,43 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects +{ + public class BackgroundColorTest : FileTestBase + { + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyBackgroundColorFilter(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.BackgroundColor(NamedColors.HotPink)); + image.DebugSave(provider); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyBackgroundColorFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.BackgroundColor(NamedColors.HotPink, bounds)); + image.DebugSave(provider); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs new file mode 100644 index 0000000000..2d039e9019 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs @@ -0,0 +1,50 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects +{ + public class BrightnessTest : FileTestBase + { + public static readonly TheoryData BrightnessValues + = new TheoryData + { + 50, + -50 + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(BrightnessValues), DefaultPixelType)] + public void ImageShouldApplyBrightnessFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Brightness(value)); + image.DebugSave(provider, value); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(BrightnessValues), DefaultPixelType)] + public void ImageShouldApplyBrightnessFilterInBox(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Brightness(value, bounds)); + image.DebugSave(provider, value); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs new file mode 100644 index 0000000000..8ae054c382 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs @@ -0,0 +1,50 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects +{ + public class ContrastTest : FileTestBase + { + public static readonly TheoryData ContrastValues + = new TheoryData + { + 50, + -50 + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(ContrastValues), DefaultPixelType)] + public void ImageShouldApplyContrastFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Contrast(value)); + image.DebugSave(provider, value); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(ContrastValues), DefaultPixelType)] + public void ImageShouldApplyContrastFilterInBox(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Contrast(value, bounds)); + image.DebugSave(provider, value); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs new file mode 100644 index 0000000000..ec93a92119 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs @@ -0,0 +1,43 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects +{ + public class InvertTest : FileTestBase + { + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyInvertFilter(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Invert()); + image.DebugSave(provider); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyInvertFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Invert(bounds)); + image.DebugSave(provider); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs new file mode 100644 index 0000000000..1a45c6eb5d --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs @@ -0,0 +1,50 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects +{ + public class OilPaintTest : FileTestBase + { + public static readonly TheoryData OilPaintValues + = new TheoryData + { + { 15, 10 }, + { 6, 5 } + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)] + public void ApplyOilPaintFilter(TestImageProvider provider, int levels, int brushSize) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.OilPaint(levels, brushSize)); + image.DebugSave(provider, string.Join("-", levels, brushSize)); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)] + public void ApplyOilPaintFilterInBox(TestImageProvider provider, int levels, int brushSize) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (Image image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.OilPaint(levels, brushSize, bounds)); + image.DebugSave(provider, string.Join("-", levels, brushSize)); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs new file mode 100644 index 0000000000..ef7cfe0adf --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs @@ -0,0 +1,84 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects +{ + public class PixelateTest : FileTestBase + { + public static readonly TheoryData PixelateValues + = new TheoryData + { + 4 , + 8 + }; + + [Theory] + [WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)] + public void ImageShouldApplyPixelateFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Pixelate(value)); + image.DebugSave(provider, value); + + // Test the neigbouring pixels + for (int y = 0; y < image.Height; y += value) + { + for (int x = 0; x < image.Width; x += value) + { + TPixel source = image[x, y]; + for (int pixY = y; pixY < y + value && pixY < image.Height; pixY++) + { + for (int pixX = x; pixX < x + value && pixX < image.Width; pixX++) + { + Assert.Equal(source, image[pixX, pixY]); + } + } + } + } + } + } + + [Theory] + [WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)] + public void ImageShouldApplyPixelateFilterInBox(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Pixelate(value, bounds)); + image.DebugSave(provider, value); + + for (int y = 0; y < image.Height; y++) + { + for (int x = 0; x < image.Width; x++) + { + int tx = x; + int ty = y; + TPixel sourceColor = source[tx, ty]; + if (bounds.Contains(tx, ty)) + { + int sourceX = tx - ((tx - bounds.Left) % value) + (value / 2); + int sourceY = ty - ((ty - bounds.Top) % value) + (value / 2); + + sourceColor = image[sourceX, sourceY]; + } + Assert.Equal(sourceColor, image[tx, ty]); + } + } + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs new file mode 100644 index 0000000000..0b0d5e0a24 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs @@ -0,0 +1,67 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays +{ + public class GlowTest : FileTestBase + { + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyGlowFilter(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Glow()); + image.DebugSave(provider); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyGlowFilterColor(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Glow(NamedColors.Orange)); + image.DebugSave(provider); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyGlowFilterRadius(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Glow(image.Width / 4F)); + image.DebugSave(provider); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyGlowFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Glow(bounds)); + image.DebugSave(provider); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs new file mode 100644 index 0000000000..f968b50f97 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs @@ -0,0 +1,67 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays +{ + public class VignetteTest : FileTestBase + { + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyVignetteFilter(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Vignette()); + image.DebugSave(provider); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyVignetteFilterColor(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Vignette(NamedColors.Orange)); + image.DebugSave(provider); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyVignetteFilterRadius(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Vignette(image.Width / 4F, image.Height / 4F)); + image.DebugSave(provider); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyVignetteFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = source.Clone()) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Vignette(bounds)); + image.DebugSave(provider); + + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs new file mode 100644 index 0000000000..cb9414b958 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs @@ -0,0 +1,81 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms +{ + public class AutoOrientTests : FileTestBase + { + public static readonly string[] FlipFiles = { TestImages.Bmp.F }; + + public static readonly TheoryData OrientationValues + = new TheoryData + { + { RotateType.None, FlipType.None, 0 }, + { RotateType.None, FlipType.None, 1 }, + { RotateType.None, FlipType.Horizontal, 2 }, + { RotateType.Rotate180, FlipType.None, 3 }, + { RotateType.Rotate180, FlipType.Horizontal, 4 }, + { RotateType.Rotate90, FlipType.Horizontal, 5 }, + { RotateType.Rotate270, FlipType.None, 6 }, + { RotateType.Rotate90, FlipType.Vertical, 7 }, + { RotateType.Rotate90, FlipType.None, 8 }, + }; + + public static readonly TheoryData InvalidOrientationValues + = new TheoryData + { + { ExifDataType.Byte, new byte[] { 1 } }, + { ExifDataType.SignedByte, new byte[] { 2 } }, + { ExifDataType.SignedShort, BitConverter.GetBytes((short) 3) }, + { ExifDataType.Long, BitConverter.GetBytes((uint) 4) }, + { ExifDataType.SignedLong, BitConverter.GetBytes((int) 5) } + }; + + [Theory] + [WithFileCollection(nameof(FlipFiles), nameof(OrientationValues), DefaultPixelType)] + public void ImageShouldAutoRotate(TestImageProvider provider, RotateType rotateType, FlipType flipType, ushort orientation) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.MetaData.ExifProfile = new ExifProfile(); + image.MetaData.ExifProfile.SetValue(ExifTag.Orientation, orientation); + + image.Mutate(x => x.RotateFlip(rotateType, flipType)); + image.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "1_before")); + + image.Mutate(x => x.AutoOrient()); + image.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "2_after")); + } + } + + [Theory] + [WithFileCollection(nameof(FlipFiles), nameof(InvalidOrientationValues), DefaultPixelType)] + public void ImageShouldAutoRotateInvalidValues(TestImageProvider provider, ExifDataType dataType, byte[] orientation) + where TPixel : struct, IPixel + { + var profile = new ExifProfile(); + profile.SetValue(ExifTag.JPEGTables, orientation); + + byte[] bytes = profile.ToByteArray(); + // Change the tag into ExifTag.Orientation + bytes[16] = 18; + bytes[17] = 1; + // Change the data type + bytes[18] = (byte)dataType; + // Change the number of components + bytes[20] = 1; + + using (Image image = provider.GetImage()) + { + image.MetaData.ExifProfile = new ExifProfile(bytes); + image.Mutate(x=>x.AutoOrient()); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs new file mode 100644 index 0000000000..aa18feac2d --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms +{ + public class CropTest : FileTestBase + { + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldCrop(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Crop(image.Width / 2, image.Height / 2)); + image.DebugSave(provider); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs new file mode 100644 index 0000000000..57341560e3 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs @@ -0,0 +1,30 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms +{ + public class EntropyCropTest : FileTestBase + { + public static readonly TheoryData EntropyCropValues + = new TheoryData + { + .25F, + .75F + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(EntropyCropValues), DefaultPixelType)] + public void ImageShouldEntropyCrop(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.EntropyCrop(value)); + image.DebugSave(provider, value); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs new file mode 100644 index 0000000000..d4de4c3d2e --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs @@ -0,0 +1,34 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms +{ + public class FlipTests : FileTestBase + { + public static readonly string[] FlipFiles = { TestImages.Bmp.F }; + + public static readonly TheoryData FlipValues + = new TheoryData + { + { FlipType.None }, + { FlipType.Vertical }, + { FlipType.Horizontal }, + }; + + [Theory] + [WithFileCollection(nameof(FlipFiles), nameof(FlipValues), DefaultPixelType)] + public void ImageShouldFlip(TestImageProvider provider, FlipType flipType) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Flip(flipType)); + image.DebugSave(provider, flipType, Extensions.Bmp); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs new file mode 100644 index 0000000000..b5f26b4883 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs @@ -0,0 +1,32 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms +{ + public class PadTest : FileTestBase + { + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldPad(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Pad(image.Width + 50, image.Height + 50)); + image.DebugSave(provider); + + // Check pixels are empty + for (int y = 0; y < 25; y++) + { + for (int x = 0; x < 25; x++) + { + Assert.Equal(default(TPixel), image[x, y]); + } + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs similarity index 78% rename from tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs rename to tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs index a300672e85..963b849d2a 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs @@ -1,20 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Transforms -{ - using System; - using System.IO; - using System.Text; - - using ImageSharp.Processing; - using ImageSharp.Processing.Processors; - - using Xunit; - using Xunit.Abstractions; +using System; +using System.IO; +using System.Text; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using Xunit; +using Xunit.Abstractions; +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms +{ public class ResizeProfilingBenchmarks : MeasureFixture { public ResizeProfilingBenchmarks(ITestOutputHelper output) @@ -34,7 +30,7 @@ public void ResizeBicubic(int width, int height) { using (var image = new Image(width, height)) { - image.Resize(width / 4, height / 4); + image.Mutate(x => x.Resize(width / 4, height / 4)); } }); } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs new file mode 100644 index 0000000000..99520d887e --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -0,0 +1,334 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; + +using SixLabors.Primitives; +using Xunit; + +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms +{ + public class ResizeTests : FileTestBase + { + public static readonly string[] CommonTestImages = { TestImages.Png.CalliphoraPartial }; + + public static readonly TheoryData AllReSamplers = + new TheoryData + { + { "Bicubic", new BicubicResampler() }, + { "Triangle", new TriangleResampler() }, + { "NearestNeighbor", new NearestNeighborResampler() }, + { "Box", new BoxResampler() }, + { "Lanczos3", new Lanczos3Resampler() }, + { "Lanczos5", new Lanczos5Resampler() }, + { "MitchellNetravali", new MitchellNetravaliResampler() }, + { "Lanczos8", new Lanczos8Resampler() }, + { "Hermite", new HermiteResampler() }, + { "Spline", new SplineResampler() }, + { "Robidoux", new RobidouxResampler() }, + { "RobidouxSharp", new RobidouxSharpResampler() }, + { "Welch", new WelchResampler() } + }; + + [Theory] + [WithTestPatternImages(nameof(AllReSamplers), 100, 100, DefaultPixelType, 0.5f)] + [WithFileCollection(nameof(CommonTestImages), nameof(AllReSamplers), DefaultPixelType, 0.5f)] + [WithFileCollection(nameof(CommonTestImages), nameof(AllReSamplers), DefaultPixelType, 0.3f)] + public void Resize_WorksWithAllResamplers(TestImageProvider provider, string name, IResampler sampler, float ratio) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + SizeF newSize = image.Size() * ratio; + image.Mutate(x => x.Resize((Size)newSize, sampler, false)); + string details = $"{name}-{ratio}"; + + image.DebugSave(provider, details); + image.CompareToReferenceOutput(provider, details); + } + } + + [Theory] + [WithTestPatternImages(100, 100, DefaultPixelType)] + public void Resize_Compand(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Resize(image.Size() / 2, true)); + + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [WithTestPatternImages(50, 50, CommonNonDefaultPixelTypes)] + public void Resize_IsNotBoundToSinglePixelType(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, true)); + + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [WithFile(TestImages.Gif.Giphy, DefaultPixelType)] + public void Resize_IsAppliedToAllFrames(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, true)); + + // Comparer fights decoder with gif-s. Could not use CompareToReferenceOutput here :( + image.DebugSave(provider, extension: Extensions.Gif); + } + } + + [Theory] + [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] + public void ResizeFromSourceRectangle(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + var sourceRectangle = new Rectangle(image.Width / 8, image.Height / 8, image.Width / 4, image.Height / 4); + var destRectangle = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Resize(image.Width, image.Height, new BicubicResampler(), sourceRectangle, destRectangle, false)); + + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] + public void ResizeWidthAndKeepAspect(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Resize(image.Width / 3, 0, false)); + + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] + public void ResizeHeightAndKeepAspect(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Resize(0, image.Height / 3, false)); + + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] + public void ResizeWithCropWidthMode(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + var options = new ResizeOptions + { + Size = new Size(image.Width / 2, image.Height) + }; + + image.Mutate(x => x.Resize(options)); + + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] + public void ResizeWithCropHeightMode(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + var options = new ResizeOptions + { + Size = new Size(image.Width, image.Height / 2) + }; + + image.Mutate(x => x.Resize(options)); + + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] + public void ResizeWithPadMode(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + var options = new ResizeOptions + { + Size = new Size(image.Width + 200, image.Height), + Mode = ResizeMode.Pad + }; + + image.Mutate(x => x.Resize(options)); + + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] + public void ResizeWithBoxPadMode(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + var options = new ResizeOptions + { + Size = new Size(image.Width + 200, image.Height + 200), + Mode = ResizeMode.BoxPad + }; + + image.Mutate(x => x.Resize(options)); + + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] + public void ResizeWithMaxMode(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + var options = new ResizeOptions + { + Size = new Size(300, 300), + Mode = ResizeMode.Max + }; + + image.Mutate(x => x.Resize(options)); + + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] + public void ResizeWithMinMode(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + var options = new ResizeOptions + { + Size = new Size((int)MathF.Round(image.Width * .75F), (int)MathF.Round(image.Height * .95F)), + Mode = ResizeMode.Min + }; + + image.Mutate(x => x.Resize(options)); + + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] + public void ResizeWithStretchMode(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + var options = new ResizeOptions + { + Size = new Size(image.Width / 2, image.Height), + Mode = ResizeMode.Stretch + }; + + image.Mutate(x => x.Resize(options)); + + image.DebugSave(provider); + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [InlineData(-2, 0)] + [InlineData(-1, 0)] + [InlineData(0, 1)] + [InlineData(1, 0)] + [InlineData(2, 0)] + public static void BicubicWindowOscillatesCorrectly(float x, float expected) + { + var sampler = new BicubicResampler(); + float result = sampler.GetValue(x); + + Assert.Equal(result, expected); + } + + [Theory] + [InlineData(-2, 0)] + [InlineData(-1, 0)] + [InlineData(0, 1)] + [InlineData(1, 0)] + [InlineData(2, 0)] + public static void TriangleWindowOscillatesCorrectly(float x, float expected) + { + var sampler = new TriangleResampler(); + float result = sampler.GetValue(x); + + Assert.Equal(result, expected); + } + + [Theory] + [InlineData(-2, 0)] + [InlineData(-1, 0)] + [InlineData(0, 1)] + [InlineData(1, 0)] + [InlineData(2, 0)] + public static void Lanczos3WindowOscillatesCorrectly(float x, float expected) + { + var sampler = new Lanczos3Resampler(); + float result = sampler.GetValue(x); + + Assert.Equal(result, expected); + } + + [Theory] + [InlineData(-4, 0)] + [InlineData(-2, 0)] + [InlineData(0, 1)] + [InlineData(2, 0)] + [InlineData(4, 0)] + public static void Lanczos5WindowOscillatesCorrectly(float x, float expected) + { + var sampler = new Lanczos5Resampler(); + float result = sampler.GetValue(x); + + Assert.Equal(result, expected); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs new file mode 100644 index 0000000000..e7415e1619 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs @@ -0,0 +1,37 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms +{ + public class RotateFlipTests : FileTestBase + { + public static readonly string[] FlipFiles = { TestImages.Bmp.F }; + + public static readonly TheoryData RotateFlipValues + = new TheoryData + { + { RotateType.None, FlipType.Vertical }, + { RotateType.None, FlipType.Horizontal }, + { RotateType.Rotate90, FlipType.None }, + { RotateType.Rotate180, FlipType.None }, + { RotateType.Rotate270, FlipType.None }, + }; + + [Theory] + [WithTestPatternImages(nameof(RotateFlipValues), 100, 50, DefaultPixelType)] + [WithTestPatternImages(nameof(RotateFlipValues), 50, 100, DefaultPixelType)] + public void RotateFlip(TestImageProvider provider, RotateType rotateType, FlipType flipType) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.RotateFlip(rotateType, flipType)); + image.DebugSave(provider, string.Join("_", rotateType, flipType)); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs new file mode 100644 index 0000000000..161af43c91 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs @@ -0,0 +1,55 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using Xunit; + +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms +{ + public class RotateTests : FileTestBase + { + public static readonly TheoryData RotateFloatValues + = new TheoryData + { + 170, + -170 + }; + + public static readonly TheoryData RotateEnumValues + = new TheoryData + { + RotateType.None, + RotateType.Rotate90, + RotateType.Rotate180, + RotateType.Rotate270 + }; + + [Theory] + [WithTestPatternImages(nameof(RotateFloatValues), 100, 50, DefaultPixelType)] + [WithTestPatternImages(nameof(RotateFloatValues), 50, 100, DefaultPixelType)] + public void Rotate(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Rotate(value)); + image.DebugSave(provider, value); + } + } + + [Theory] + [WithTestPatternImages(nameof(RotateEnumValues), 100, 50, DefaultPixelType)] + [WithTestPatternImages(nameof(RotateEnumValues), 50, 100, DefaultPixelType)] + public void Rotate_WithRotateTypeEnum(TestImageProvider provider, RotateType value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Rotate(value)); + image.DebugSave(provider, value); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs new file mode 100644 index 0000000000..5e83fa620d --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs @@ -0,0 +1,30 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms +{ + public class SkewTest : FileTestBase + { + public static readonly TheoryData SkewValues + = new TheoryData + { + { 20, 10 }, + { -20, -10 } + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(SkewValues), DefaultPixelType)] + public void ImageShouldSkew(TestImageProvider provider, float x, float y) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(i => i.Skew(x, y)); + image.DebugSave(provider, string.Join("_", x, y)); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs index 0646dc9376..dbb2d8415e 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs @@ -1,83 +1,21 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Transforms -{ - using System; - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - - using Xunit; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using Xunit; - public class AutoOrientTests : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Transforms +{ + public class AutoOrientTests : BaseImageOperationsExtensionTest { - public static readonly string[] FlipFiles = { TestImages.Bmp.F }; - - public static readonly TheoryData OrientationValues - = new TheoryData - { - { RotateType.None, FlipType.None, 0 }, - { RotateType.None, FlipType.None, 1 }, - { RotateType.None, FlipType.Horizontal, 2 }, - { RotateType.Rotate180, FlipType.None, 3 }, - { RotateType.Rotate180, FlipType.Horizontal, 4 }, - { RotateType.Rotate90, FlipType.Horizontal, 5 }, - { RotateType.Rotate270, FlipType.None, 6 }, - { RotateType.Rotate90, FlipType.Vertical, 7 }, - { RotateType.Rotate90, FlipType.None, 8 }, - }; - - public static readonly TheoryData InvalidOrientationValues - = new TheoryData - { - { ExifDataType.Byte, new byte[] { 1 } }, - { ExifDataType.SignedByte, new byte[] { 2 } }, - { ExifDataType.SignedShort, BitConverter.GetBytes((short) 3) }, - { ExifDataType.Long, BitConverter.GetBytes((uint) 4) }, - { ExifDataType.SignedLong, BitConverter.GetBytes((int) 5) } - }; - - [Theory] - [WithFileCollection(nameof(FlipFiles), nameof(OrientationValues), DefaultPixelType)] - public void ImageShouldAutoRotate(TestImageProvider provider, RotateType rotateType, FlipType flipType, ushort orientation) - where TPixel : struct, IPixel + [Fact] + public void AutoOrient_AutoRotateProcessor() { - using (Image image = provider.GetImage()) - { - image.MetaData.ExifProfile = new ExifProfile(); - image.MetaData.ExifProfile.SetValue(ExifTag.Orientation, orientation); - - image.RotateFlip(rotateType, flipType) - .DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "1_before"), Extensions.Bmp) - .AutoOrient() - .DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "2_after"), Extensions.Bmp); - } - } - - [Theory] - [WithFileCollection(nameof(FlipFiles), nameof(InvalidOrientationValues), DefaultPixelType)] - public void ImageShouldAutoRotateInvalidValues(TestImageProvider provider, ExifDataType dataType, byte[] orientation) - where TPixel : struct, IPixel - { - var profile = new ExifProfile(); - profile.SetValue(ExifTag.JPEGTables, orientation); - - byte[] bytes = profile.ToByteArray(); - // Change the tag into ExifTag.Orientation - bytes[16] = 18; - bytes[17] = 1; - // Change the data type - bytes[18] = (byte)dataType; - // Change the number of components - bytes[20] = 1; - - using (Image image = provider.GetImage()) - { - image.MetaData.ExifProfile = new ExifProfile(bytes); - image.AutoOrient(); - } + this.operations.AutoOrient(); + this.Verify>(); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs index ca20abf790..a001efc417 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs @@ -1,26 +1,37 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Transforms +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Transforms { - using ImageSharp.PixelFormats; + public class CropTest : BaseImageOperationsExtensionTest + { + [Theory] + [InlineData(10, 10)] + [InlineData(12, 123)] + public void Crop_Width_height_CropProcessorWithRectangleSet(int width, int height) + { + this.operations.Crop(width, height); + var processor = this.Verify>(); - using Xunit; + Assert.Equal(new Rectangle(0, 0, width, height), processor.CropRectangle); + } - public class CropTest : FileTestBase - { [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldCrop(TestImageProvider provider) - where TPixel : struct, IPixel + [InlineData(10, 10, 2, 6)] + [InlineData(12, 123, 6, 2)] + public void Crop_Rectangle_CropProcessorWithRectangleSet(int x, int y, int width, int height) { - using (Image image = provider.GetImage()) - { - image.Crop(image.Width / 2, image.Height / 2) - .DebugSave(provider, null, Extensions.Bmp); - } + var rect = new Rectangle(x, y, width, height); + this.operations.Crop(rect); + var processor = this.Verify>(); + + Assert.Equal(rect, processor.CropRectangle); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs index 24febd5b2f..c1cde48794 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs @@ -1,33 +1,25 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Transforms -{ - using ImageSharp.PixelFormats; - - using Xunit; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using Xunit; - public class EntropyCropTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Transforms +{ + public class EntropyCropTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData EntropyCropValues - = new TheoryData - { - .25F, - .75F - }; [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(EntropyCropValues), DefaultPixelType)] - public void ImageShouldEntropyCrop(TestImageProvider provider, float value) - where TPixel : struct, IPixel + [InlineData(0.5f)] + [InlineData(.2f)] + public void EntropyCrop_threasholdFloat_EntropyCropProcessorWithThreshold(float threashold) { - using (Image image = provider.GetImage()) - { - image.EntropyCrop(value) - .DebugSave(provider, value, Extensions.Bmp); - } + this.operations.EntropyCrop(threashold); + var processor = this.Verify>(); + + Assert.Equal(threashold, processor.Threshold); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs index 45ab1e5f8b..4b3e97d106 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs @@ -1,37 +1,27 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Transforms -{ - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - - using Xunit; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using Xunit; - public class FlipTests : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Transforms +{ + public class FlipTests : BaseImageOperationsExtensionTest { - public static readonly string[] FlipFiles = { TestImages.Bmp.F }; - - public static readonly TheoryData FlipValues - = new TheoryData - { - { FlipType.None }, - { FlipType.Vertical }, - { FlipType.Horizontal }, - }; [Theory] - [WithFileCollection(nameof(FlipFiles), nameof(FlipValues), DefaultPixelType)] - public void ImageShouldFlip(TestImageProvider provider, FlipType flipType) - where TPixel : struct, IPixel + [InlineData(FlipType.None)] + [InlineData(FlipType.Horizontal)] + [InlineData(FlipType.Vertical)] + public void Flip_degreesFloat_RotateProcessorWithAnglesSetAndExpandTrue(FlipType flip) { - using (Image image = provider.GetImage()) - { - image.Flip(flipType) - .DebugSave(provider, flipType, Extensions.Bmp); - } + this.operations.Flip(flip); + var flipProcessor = this.Verify>(); + + Assert.Equal(flip, flipProcessor.FlipType); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs index 7caa1e7c0e..58fc7fa802 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs @@ -1,35 +1,20 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Transforms -{ - using ImageSharp.PixelFormats; - - using Xunit; +using System; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; - public class PadTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Transforms +{ + public class PadTest : BaseImageOperationsExtensionTest { - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldPad(TestImageProvider provider) - where TPixel : struct, IPixel +#pragma warning disable xUnit1004 // Test methods should not be skipped + [Fact(Skip = "Skip this is a helper around resize, skip until resize can be refactord")] +#pragma warning restore xUnit1004 // Test methods should not be skipped + public void Pad_width_height_ResizeProcessorWithCorrectOPtionsSet() { - using (Image image = provider.GetImage()) - { - image.Pad(image.Width + 50, image.Height + 50) - .DebugSave(provider, null, Extensions.Bmp); - - // Check pixels are empty - for (int y = 0; y < 25; y++) - { - for (int x = 0; x < 25; x++) - { - Assert.Equal(default(TPixel), image[x, y]); - } - } - } + throw new NotImplementedException("Write test here"); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs index fb195254e3..d2f5cb2c3d 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs @@ -1,273 +1,23 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Transforms -{ - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - using SixLabors.Primitives; - using Xunit; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.Primitives; +using Xunit; - public class ResizeTests : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Transforms +{ + public class ResizeTests : BaseImageOperationsExtensionTest { - public static readonly string[] ResizeFiles = { TestImages.Jpeg.Baseline.Calliphora }; - - public static readonly TheoryData ReSamplers = - new TheoryData - { - { "Bicubic", new BicubicResampler() }, - { "Triangle", new TriangleResampler() }, - { "NearestNeighbor", new NearestNeighborResampler() }, - { "Box", new BoxResampler() }, - { "Lanczos3", new Lanczos3Resampler() }, - { "Lanczos5", new Lanczos5Resampler() }, - { "MitchellNetravali", new MitchellNetravaliResampler() }, - { "Lanczos8", new Lanczos8Resampler() }, - { "Hermite", new HermiteResampler() }, - { "Spline", new SplineResampler() }, - { "Robidoux", new RobidouxResampler() }, - { "RobidouxSharp", new RobidouxSharpResampler() }, - { "Welch", new WelchResampler() } - }; - - [Theory] - [WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] - public void ImageShouldResize(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - image.Resize(image.Width / 2, image.Height / 2, sampler, true) - .DebugSave(provider, name, Extensions.Bmp); - } - } - - [Theory] - [WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] - public void ImageShouldResizeFromSourceRectangle(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - var sourceRectangle = new Rectangle(image.Width / 8, image.Height / 8, image.Width / 4, image.Height / 4); - var destRectangle = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); - - image.Resize(image.Width, image.Height, sampler, sourceRectangle, destRectangle, false) - .DebugSave(provider, name, Extensions.Bmp); - } - } - - [Theory] - [WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] - public void ImageShouldResizeWidthAndKeepAspect(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - image.Resize(image.Width / 3, 0, sampler, false) - .DebugSave(provider, name, Extensions.Bmp); - } - } - - [Theory] - [WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] - public void ImageShouldResizeHeightAndKeepAspect(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - image.Resize(0, image.Height / 3, sampler, false) - .DebugSave(provider, name, Extensions.Bmp); - } - } - - [Theory] - [WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] - public void ImageShouldResizeWithCropWidthMode(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - var options = new ResizeOptions - { - Sampler = sampler, - Size = new Size(image.Width / 2, image.Height) - }; - - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); - } - } - - [Theory] - [WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] - public void ImageShouldResizeWithCropHeightMode(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - var options = new ResizeOptions - { - Sampler = sampler, - Size = new Size(image.Width, image.Height / 2) - }; - - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); - } - } - - [Theory] - [WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] - public void ImageShouldResizeWithPadMode(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - var options = new ResizeOptions - { - Sampler = sampler, - Size = new Size(image.Width + 200, image.Height), - Mode = ResizeMode.Pad - }; - - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); - } - } - - [Theory] - [WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] - public void ImageShouldResizeWithBoxPadMode(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel +#pragma warning disable xUnit1004 // Test methods should not be skipped + [Fact(Skip = "Skip resize tests as they need refactoring to be simpler and just pass data into the resize processor.")] +#pragma warning restore xUnit1004 // Test methods should not be skipped + public void TestMissing() { - using (Image image = provider.GetImage()) - { - var options = new ResizeOptions - { - Sampler = sampler, - Size = new Size(image.Width + 200, image.Height + 200), - Mode = ResizeMode.BoxPad - }; - - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); - } - } - - [Theory] - [WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] - public void ImageShouldResizeWithMaxMode(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - var options = new ResizeOptions - { - Sampler = sampler, - Size = new Size(300, 300), - Mode = ResizeMode.Max - }; - - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); - } - } - - [Theory] - [WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] - public void ImageShouldResizeWithMinMode(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - var options = new ResizeOptions - { - Sampler = sampler, - Size = new Size((int)MathF.Round(image.Width * .75F), (int)MathF.Round(image.Height * .95F)), - Mode = ResizeMode.Min - }; - - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); - } - } - - [Theory] - [WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] - public void ImageShouldResizeWithStretchMode(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage()) - { - var options = new ResizeOptions - { - Sampler = sampler, - Size = new Size(image.Width / 2, image.Height), - Mode = ResizeMode.Stretch - }; - - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); - } - } - - [Theory] - [InlineData(-2, 0)] - [InlineData(-1, 0)] - [InlineData(0, 1)] - [InlineData(1, 0)] - [InlineData(2, 0)] - public static void BicubicWindowOscillatesCorrectly(float x, float expected) - { - var sampler = new BicubicResampler(); - float result = sampler.GetValue(x); - - Assert.Equal(result, expected); - } - - [Theory] - [InlineData(-2, 0)] - [InlineData(-1, 0)] - [InlineData(0, 1)] - [InlineData(1, 0)] - [InlineData(2, 0)] - public static void TriangleWindowOscillatesCorrectly(float x, float expected) - { - var sampler = new TriangleResampler(); - float result = sampler.GetValue(x); - - Assert.Equal(result, expected); - } - - [Theory] - [InlineData(-2, 0)] - [InlineData(-1, 0)] - [InlineData(0, 1)] - [InlineData(1, 0)] - [InlineData(2, 0)] - public static void Lanczos3WindowOscillatesCorrectly(float x, float expected) - { - var sampler = new Lanczos3Resampler(); - float result = sampler.GetValue(x); - - Assert.Equal(result, expected); - } - - [Theory] - [InlineData(-4, 0)] - [InlineData(-2, 0)] - [InlineData(0, 1)] - [InlineData(2, 0)] - [InlineData(4, 0)] - public static void Lanczos5WindowOscillatesCorrectly(float x, float expected) - { - var sampler = new Lanczos5Resampler(); - float result = sampler.GetValue(x); - - Assert.Equal(result, expected); + // + throw new NotImplementedException("Write test here"); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs index f85ef6f13a..67602131b0 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs @@ -1,39 +1,39 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Transforms -{ - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - - using Xunit; +using System; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using Xunit; - public class RotateFlipTests : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Transforms +{ + public class RotateFlipTests : BaseImageOperationsExtensionTest { - public static readonly string[] FlipFiles = { TestImages.Bmp.F }; - - public static readonly TheoryData RotateFlipValues - = new TheoryData - { - { RotateType.None, FlipType.Vertical }, - { RotateType.None, FlipType.Horizontal }, - { RotateType.Rotate90, FlipType.None }, - { RotateType.Rotate180, FlipType.None }, - { RotateType.Rotate270, FlipType.None }, - }; [Theory] - [WithFileCollection(nameof(FlipFiles), nameof(RotateFlipValues), DefaultPixelType)] - public void ImageShouldRotateFlip(TestImageProvider provider, RotateType rotateType, FlipType flipType) - where TPixel : struct, IPixel + [InlineData(RotateType.None, FlipType.None, 0)] + [InlineData(RotateType.Rotate90, FlipType.None, 90)] + [InlineData(RotateType.Rotate180, FlipType.None, 180)] + [InlineData(RotateType.Rotate270, FlipType.None, 270)] + [InlineData(RotateType.None, FlipType.Horizontal, 0)] + [InlineData(RotateType.Rotate90, FlipType.Horizontal, 90)] + [InlineData(RotateType.Rotate180, FlipType.Horizontal, 180)] + [InlineData(RotateType.Rotate270, FlipType.Horizontal, 270)] + [InlineData(RotateType.None, FlipType.Vertical, 0)] + [InlineData(RotateType.Rotate90, FlipType.Vertical, 90)] + [InlineData(RotateType.Rotate180, FlipType.Vertical, 180)] + [InlineData(RotateType.Rotate270, FlipType.Vertical, 270)] + public void Rotate_degreesFloat_RotateProcessorWithAnglesSetAndExpandTrue(RotateType angle, FlipType flip, float expectedAngle) { - using (Image image = provider.GetImage()) - { - image.RotateFlip(rotateType, flipType) - .DebugSave(provider, string.Join("_", rotateType, flipType), Extensions.Bmp); - } + this.operations.RotateFlip(angle, flip); + var rotateProcessor = this.Verify>(0); + var flipProcessor = this.Verify>(1); + + Assert.Equal(expectedAngle, rotateProcessor.Angle); + Assert.False(rotateProcessor.Expand); + Assert.Equal(flip, flipProcessor.FlipType); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs index 1f18564290..80eccd00cd 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs @@ -1,55 +1,55 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Transforms -{ - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; +using Xunit; - public class RotateTests : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Transforms +{ + public class RotateTests : BaseImageOperationsExtensionTest { - public static readonly TheoryData RotateFloatValues - = new TheoryData - { - 170, - -170 - }; - public static readonly TheoryData RotateEnumValues - = new TheoryData + [Theory] + [InlineData(85.6f)] + [InlineData(21)] + public void Rotate_degreesFloat_RotateProcessorWithAnglesSetAndExpandTrue(float angle) { - RotateType.None, - RotateType.Rotate90, - RotateType.Rotate180, - RotateType.Rotate270 - }; + this.operations.Rotate(angle); + var processor = this.Verify>(); + + Assert.Equal(angle, processor.Angle); + Assert.True(processor.Expand); + } + [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(RotateFloatValues), DefaultPixelType)] - public void ImageShouldRotate(TestImageProvider provider, float value) - where TPixel : struct, IPixel + [InlineData(RotateType.None, 0)] + [InlineData(RotateType.Rotate90, 90)] + [InlineData(RotateType.Rotate180, 180)] + [InlineData(RotateType.Rotate270, 270)] + public void Rotate_RotateType_RotateProcessorWithAnglesConvertedFromEnumAndExpandTrue(RotateType angle, float expectedangle) { - using (Image image = provider.GetImage()) - { - image.Rotate(value) - .DebugSave(provider, value, Extensions.Bmp); - } + this.operations.Rotate(angle); // is this api needed ??? + var processor = this.Verify>(); + + Assert.Equal(expectedangle, processor.Angle); + Assert.False(processor.Expand); } + [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(RotateEnumValues), DefaultPixelType)] - public void ImageShouldRotateEnum(TestImageProvider provider, RotateType value) - where TPixel : struct, IPixel + [InlineData(85.6f, false)] + [InlineData(21, true)] + [InlineData(21, false)] + public void Rotate_degreesFloat_expand_RotateProcessorWithAnglesSetAndExpandSet(float angle, bool expand) { - using (Image image = provider.GetImage()) - { - image.Rotate(value) - .DebugSave(provider, value, Extensions.Bmp); - } + this.operations.Rotate(angle, expand); + var processor = this.Verify>(); + + Assert.Equal(angle, processor.Angle); + Assert.Equal(expand, processor.Expand); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs index f2c2d7cbd2..28a0e0d8f8 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs @@ -1,33 +1,34 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests.Processing.Transforms -{ - using ImageSharp.PixelFormats; - - using Xunit; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using Xunit; - public class SkewTest : FileTestBase +namespace SixLabors.ImageSharp.Tests.Processing.Transforms +{ + public class SkewTest : BaseImageOperationsExtensionTest { - public static readonly TheoryData SkewValues - = new TheoryData + [Fact] + public void Skew_x_y_CreateSkewProcessorWithAnglesSetAndExpandTrue() { - { 20, 10 }, - { -20, -10 } - }; + this.operations.Skew(10, 20); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(SkewValues), DefaultPixelType)] - public void ImageShouldSkew(TestImageProvider provider, float x, float y) - where TPixel : struct, IPixel + Assert.Equal(10, processor.AngleX); + Assert.Equal(20, processor.AngleY); + Assert.True(processor.Expand); + } + + [Fact] + public void Skew_x_y_expand_CreateSkewProcessorWithAnglesSetAndExpandTrue() { - using (Image image = provider.GetImage()) - { - image.Skew(x, y) - .DebugSave(provider, string.Join("_", x, y), Extensions.Bmp); - } + this.operations.Skew(10, 20, false); + var processor = this.Verify>(); + + Assert.Equal(10, processor.AngleX); + Assert.Equal(20, processor.AngleY); + Assert.False(processor.Expand); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestBase.cs b/tests/ImageSharp.Tests/TestBase.cs index c7514d5aee..f83c428fc2 100644 --- a/tests/ImageSharp.Tests/TestBase.cs +++ b/tests/ImageSharp.Tests/TestBase.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System.IO; - using System.Reflection; - - using ImageSharp.Formats; +using System.IO; +using System.Reflection; +using SixLabors.ImageSharp.Formats; +namespace SixLabors.ImageSharp.Tests +{ /// /// The test base class. Inherit from this class for any image manipulation tests. /// @@ -25,9 +22,7 @@ public abstract class TestBase /// protected string CreateOutputDirectory(string path, params string[] pathParts) { - string assemblyLocation = typeof(TestFile).GetTypeInfo().Assembly.Location; - assemblyLocation = Path.GetDirectoryName(assemblyLocation); - path = Path.GetFullPath(Path.Combine(assemblyLocation, "../../../TestOutput", path)); + path = Path.Combine(TestEnvironment.ActualOutputDirectoryFullPath, path); if (pathParts != null && pathParts.Length > 0) { diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataArray.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataArray.cs index a14433f1e1..4fd798f345 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataArray.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataArray.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { internal static class IccTestDataArray { diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataCurves.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataCurves.cs index c8d517aac6..2b13e5bad2 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataCurves.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataCurves.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System.Numerics; +using System.Numerics; +namespace SixLabors.ImageSharp.Tests +{ internal static class IccTestDataCurves { #region Response diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataLut.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataLut.cs index cc2dfc6e97..b4a512bd1e 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataLut.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataLut.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { internal static class IccTestDataLut { diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs index 78e493829c..8e4b7d3d5b 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs @@ -1,14 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// using System.Numerics; +using SixLabors.ImageSharp.Memory; -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { - using ImageSharp.Memory; - internal static class IccTestDataMatrix { #region 2D diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMultiProcessElements.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMultiProcessElements.cs index 49e9550df5..d29906d426 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMultiProcessElements.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMultiProcessElements.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { internal static class IccTestDataMultiProcessElement { diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs index fdbcb31271..370b881682 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs @@ -1,9 +1,12 @@ -namespace ImageSharp.Tests -{ - using System; - using System.Globalization; - using System.Numerics; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Globalization; +using System.Numerics; +namespace SixLabors.ImageSharp.Tests +{ internal static class IccTestDataNonPrimitives { #region DateTime diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataPrimitives.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataPrimitives.cs index fcfa2d0d79..b24e3f24a4 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataPrimitives.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataPrimitives.cs @@ -1,9 +1,7 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { internal static class IccTestDataPrimitives { diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs index 32a4a8e57b..ee32aa934f 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// using System; using System.Numerics; -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { internal static class IccTestDataProfiles { diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataTagDataEntry.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataTagDataEntry.cs index 05942ab618..240bd4fa53 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataTagDataEntry.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataTagDataEntry.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System.Globalization; - using System.Numerics; +using System.Globalization; +using System.Numerics; +namespace SixLabors.ImageSharp.Tests +{ internal static class IccTestDataTagDataEntry { #region TagDataEntry Header diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs index 7373b70c52..71ab16ccf6 100644 --- a/tests/ImageSharp.Tests/TestFile.cs +++ b/tests/ImageSharp.Tests/TestFile.cs @@ -1,19 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Collections.Concurrent; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Reflection; - using ImageSharp.Formats; - using ImageSharp.PixelFormats; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Tests +{ /// /// A test image file. /// @@ -25,14 +23,20 @@ public class TestFile private static readonly ConcurrentDictionary Cache = new ConcurrentDictionary(); /// - /// The formats directory, as lazy value + /// The "Formats" directory, as lazy value /// - private static readonly Lazy formatsDirectory = new Lazy(GetFormatsDirectory); + // ReSharper disable once InconsistentNaming + private static readonly Lazy inputImagesDirectory = new Lazy(() => TestEnvironment.InputImagesDirectoryFullPath); /// - /// The image. + /// The image (lazy initialized value) /// - private readonly Image image; + private Image image; + + /// + /// The image bytes + /// + private byte[] bytes; /// /// The file. @@ -46,15 +50,12 @@ public class TestFile private TestFile(string file) { this.file = file; - - this.Bytes = File.ReadAllBytes(file); - this.image = Image.Load(this.Bytes); } /// - /// Gets the bytes. + /// Gets the image bytes. /// - public byte[] Bytes { get; } + public byte[] Bytes => this.bytes ?? (this.bytes = File.ReadAllBytes(this.file)); /// /// The file name. @@ -72,12 +73,16 @@ private TestFile(string file) public string FileNameWithoutExtension => Path.GetFileNameWithoutExtension(this.file); /// - /// Gets the "Formats" test file directory. + /// Gets the image with lazy initialization. + /// + private Image Image => this.image ?? (this.image = ImageSharp.Image.Load(this.Bytes)); + + /// /// - private static string FormatsDirectory => formatsDirectory.Value; + private static string InputImagesDirectory => inputImagesDirectory.Value; /// - /// Gets the full qualified path to the file. + /// Gets the full qualified path to the input test file. /// /// /// The file path. @@ -85,9 +90,9 @@ private TestFile(string file) /// /// The . /// - public static string GetPath(string file) + public static string GetInputFileFullPath(string file) { - return Path.Combine(FormatsDirectory, file); + return Path.Combine(InputImagesDirectory, file); } /// @@ -99,7 +104,7 @@ public static string GetPath(string file) /// public static TestFile Create(string file) { - return Cache.GetOrAdd(file, (string fileName) => new TestFile(GetPath(file))); + return Cache.GetOrAdd(file, (string fileName) => new TestFile(GetInputFileFullPath(file))); } /// @@ -130,74 +135,22 @@ public string GetFileNameWithoutExtension(object value) /// Creates a new image. /// /// - /// The . + /// The . /// public Image CreateImage() { - return new Image(this.image); + return this.Image.Clone(); } /// /// Creates a new image. /// /// - /// The . + /// The . /// public Image CreateImage(IImageDecoder decoder) { - return Image.Load(this.image.Configuration, this.Bytes, decoder); - } - - /// - /// Gets the correct path to the formats directory. - /// - /// - /// The . - /// - private static string GetFormatsDirectory() - { - List directories = new List< string > { - "TestImages/Formats/", // Here for code coverage tests. - "tests/ImageSharp.Tests/TestImages/Formats/", // from travis/build script - "../../../../../ImageSharp.Tests/TestImages/Formats/", // from Sandbox46 - "../../../../TestImages/Formats/", - "../../../TestImages/Formats/" - }; - - directories = directories.SelectMany(x => new[] - { - Path.GetFullPath(x) - }).ToList(); - - AddFormatsDirectoryFromTestAssebmlyPath(directories); - - string directory = directories.FirstOrDefault(x => Directory.Exists(x)); - - if(directory != null) - { - return directory; - } - - throw new System.Exception($"Unable to find Formats directory at any of these locations [{string.Join(", ", directories)}]"); - } - - /// - /// The path returned by Path.GetFullPath(x) can be relative to dotnet framework directory - /// in certain scenarios like dotTrace test profiling. - /// This method calculates and adds the format directory based on the ImageSharp.Tests assembly location. - /// - /// The directories list - private static void AddFormatsDirectoryFromTestAssebmlyPath(List directories) - { - string assemblyLocation = typeof(TestFile).GetTypeInfo().Assembly.Location; - assemblyLocation = Path.GetDirectoryName(assemblyLocation); - - if (assemblyLocation != null) - { - string dirFromAssemblyLocation = Path.Combine(assemblyLocation, "../../../TestImages/Formats/"); - dirFromAssemblyLocation = Path.GetFullPath(dirFromAssemblyLocation); - directories.Add(dirFromAssemblyLocation); - } + return ImageSharp.Image.Load(this.Image.Configuration, this.Bytes, decoder); } } } diff --git a/tests/ImageSharp.Tests/TestFileSystem.cs b/tests/ImageSharp.Tests/TestFileSystem.cs index d43b989f10..304e8dcb86 100644 --- a/tests/ImageSharp.Tests/TestFileSystem.cs +++ b/tests/ImageSharp.Tests/TestFileSystem.cs @@ -1,19 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Collections.Concurrent; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Reflection; - using ImageSharp.Formats; - using Xunit; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using SixLabors.ImageSharp.Formats; +using Xunit; +namespace SixLabors.ImageSharp.Tests +{ /// /// A test image file. /// diff --git a/tests/ImageSharp.Tests/TestFont.cs b/tests/ImageSharp.Tests/TestFont.cs index 7e5b6c370d..6f805e3676 100644 --- a/tests/ImageSharp.Tests/TestFont.cs +++ b/tests/ImageSharp.Tests/TestFont.cs @@ -1,17 +1,15 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Collections.Concurrent; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Reflection; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +namespace SixLabors.ImageSharp.Tests +{ /// /// A test image file. /// diff --git a/tests/ImageSharp.Tests/TestFormat.cs b/tests/ImageSharp.Tests/TestFormat.cs index 5a3cd102e7..2683d47524 100644 --- a/tests/ImageSharp.Tests/TestFormat.cs +++ b/tests/ImageSharp.Tests/TestFormat.cs @@ -1,21 +1,18 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; + +namespace SixLabors.ImageSharp.Tests { - using System; - using System.Collections.Concurrent; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Reflection; - using ImageSharp.Formats; - using ImageSharp.PixelFormats; - - using Xunit; - /// /// A test image file. /// diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 46887d721d..64c08b7e4e 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// + +using System.Linq; // ReSharper disable MemberHidesStaticFromOuterClass -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { - using System.Linq; - /// /// Class that contains all the relative test image paths in the TestImages/Formats directory. /// Use with , or . @@ -26,7 +24,12 @@ public static class Png public const string SplashInterlaced = "Png/splash-interlaced.png"; public const string Interlaced = "Png/interlaced.png"; public const string Rgb48Bpp = "Png/rgb-48bpp.png"; + public const string CalliphoraPartial = "Png/CalliphoraPartial.png"; + public const string CalliphoraPartialGrayscale = "Png/CalliphoraPartialGrayscale.png"; + public const string Bike = "Png/Bike.png"; + public const string BikeGrayscale = "Png/BikeGrayscale.png"; public const string Rgb48BppInterlaced = "Png/rgb-48bpp-interlaced.png"; + public const string SnakeGame = "Png/SnakeGame.png"; // Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html public const string Filter0 = "Png/filter0.png"; diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/ycck.jpg b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/ycck - Copy.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/ycck.jpg rename to tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/ycck - Copy.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/jpeg.htm b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/jpeg.htm new file mode 100644 index 0000000000..72a5e448b3 --- /dev/null +++ b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/jpeg.htm @@ -0,0 +1,63 @@ + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/jpg.js b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/jpg.js new file mode 100644 index 0000000000..6ebf71a697 --- /dev/null +++ b/tests/ImageSharp.Tests/TestImages/Formats/Jpg/jpg.js @@ -0,0 +1,1205 @@ +/* Copyright 2014 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* eslint-disable no-multi-spaces */ + +// import { error, warn } from '../shared/util'; + +/** + * This code was forked from https://github.com/notmasteryet/jpgjs. + * The original version was created by GitHub user notmasteryet. + * + * - The JPEG specification can be found in the ITU CCITT Recommendation T.81 + * (www.w3.org/Graphics/JPEG/itu-t81.pdf) + * - The JFIF specification can be found in the JPEG File Interchange Format + * (www.w3.org/Graphics/JPEG/jfif3.pdf) + * - The Adobe Application-Specific JPEG markers in the + * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116 + * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf) + */ + +var error = function(val){ + console.log(val); +} + +var warn = function(val){ + console.log(val); +} + +var JpegImage = (function JpegImageClosure() { + var dctZigZag = new Uint8Array([ + 0, + 1, 8, + 16, 9, 2, + 3, 10, 17, 24, + 32, 25, 18, 11, 4, + 5, 12, 19, 26, 33, 40, + 48, 41, 34, 27, 20, 13, 6, + 7, 14, 21, 28, 35, 42, 49, 56, + 57, 50, 43, 36, 29, 22, 15, + 23, 30, 37, 44, 51, 58, + 59, 52, 45, 38, 31, + 39, 46, 53, 60, + 61, 54, 47, + 55, 62, + 63 + ]); + + var dctCos1 = 4017; // cos(pi/16) + var dctSin1 = 799; // sin(pi/16) + var dctCos3 = 3406; // cos(3*pi/16) + var dctSin3 = 2276; // sin(3*pi/16) + var dctCos6 = 1567; // cos(6*pi/16) + var dctSin6 = 3784; // sin(6*pi/16) + var dctSqrt2 = 5793; // sqrt(2) + var dctSqrt1d2 = 2896; // sqrt(2) / 2 + + function JpegImage() { + this.decodeTransform = null; + this.colorTransform = -1; + } + + function buildHuffmanTable(codeLengths, values) { + console.log(codeLengths); + console.log(values); + + var k = 0, code = [], i, j, length = 16; + while (length > 0 && !codeLengths[length - 1]) { + length--; + } + + code.push({ children: [], index: 0, }); + var p = code[0], q; + for (i = 0; i < length; i++) { + for (j = 0; j < codeLengths[i]; j++) { + p = code.pop(); + p.children[p.index] = values[k]; + + while (p.index > 0) { + p = code.pop(); + } + p.index++; + code.push(p); + while (code.length <= i) { + code.push(q = { children: [], index: 0, }); + p.children[p.index] = q.children; + p = q; + } + k++; + } + if (i + 1 < length) { + // p here points to last code + code.push(q = { children: [], index: 0, }); + p.children[p.index] = q.children; + p = q; + } + } + console.log(code[0].children); + console.log(k); + return code[0].children; + } + + function getBlockBufferOffset(component, row, col) { + return 64 * ((component.blocksPerLine + 1) * row + col); + } + + function decodeScan(data, offset, frame, components, resetInterval, + spectralStart, spectralEnd, successivePrev, successive) { + var mcusPerLine = frame.mcusPerLine; + var progressive = frame.progressive; + var startOffset = offset, bitsData = 0, bitsCount = 0; + + function readBit() { + if (bitsCount > 0) { + bitsCount--; + return (bitsData >> bitsCount) & 1; + } + bitsData = data[offset++]; + if (bitsData === 0xFF) { + var nextByte = data[offset++]; + if (nextByte) { + error('JPEG error: unexpected marker ' + + ((bitsData << 8) | nextByte).toString(16)); + } + // unstuff 0 + } + bitsCount = 7; + return bitsData >>> 7; + } + + function decodeHuffman(tree) { + var node = tree; + while (true) { + node = node[readBit()]; + if (typeof node === 'number') { + return node; + } + if (typeof node !== 'object') { + error('JPEG error: invalid huffman sequence'); + } + } + } + + function receive(length) { + var n = 0; + while (length > 0) { + n = (n << 1) | readBit(); + length--; + } + return n; + } + + function receiveAndExtend(length) { + if (length === 1) { + return readBit() === 1 ? 1 : -1; + } + var n = receive(length); + if (n >= 1 << (length - 1)) { + return n; + } + return n + (-1 << length) + 1; + } + + function decodeBaseline(component, offset) { + var t = decodeHuffman(component.huffmanTableDC); + var diff = t === 0 ? 0 : receiveAndExtend(t); + component.blockData[offset] = (component.pred += diff); + // console.log("component"); + // console.log(component); + + if(offset === 0){ + console.log("component at 0"); + console.log(component.blockData[offset]) + } + + var k = 1; + while (k < 64) { + var rs = decodeHuffman(component.huffmanTableAC); + var s = rs & 15, r = rs >> 4; + if (s === 0) { + if (r < 15) { + break; + } + k += 16; + continue; + } + k += r; + var z = dctZigZag[k]; + component.blockData[offset + z] = receiveAndExtend(s); + k++; + } + } + + function decodeDCFirst(component, offset) { + var t = decodeHuffman(component.huffmanTableDC); + var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive); + component.blockData[offset] = (component.pred += diff); + } + + function decodeDCSuccessive(component, offset) { + component.blockData[offset] |= readBit() << successive; + } + + var eobrun = 0; + function decodeACFirst(component, offset) { + if (eobrun > 0) { + eobrun--; + return; + } + var k = spectralStart, e = spectralEnd; + while (k <= e) { + var rs = decodeHuffman(component.huffmanTableAC); + var s = rs & 15, r = rs >> 4; + if (s === 0) { + if (r < 15) { + eobrun = receive(r) + (1 << r) - 1; + break; + } + k += 16; + continue; + } + k += r; + var z = dctZigZag[k]; + component.blockData[offset + z] = + receiveAndExtend(s) * (1 << successive); + k++; + } + } + + var successiveACState = 0, successiveACNextValue; + function decodeACSuccessive(component, offset) { + var k = spectralStart; + var e = spectralEnd; + var r = 0; + var s; + var rs; + while (k <= e) { + var z = dctZigZag[k]; + switch (successiveACState) { + case 0: // initial state + rs = decodeHuffman(component.huffmanTableAC); + s = rs & 15; + r = rs >> 4; + if (s === 0) { + if (r < 15) { + eobrun = receive(r) + (1 << r); + successiveACState = 4; + } else { + r = 16; + successiveACState = 1; + } + } else { + if (s !== 1) { + error('JPEG error: invalid ACn encoding'); + } + successiveACNextValue = receiveAndExtend(s); + successiveACState = r ? 2 : 3; + } + continue; + case 1: // skipping r zero items + case 2: + if (component.blockData[offset + z]) { + component.blockData[offset + z] += (readBit() << successive); + } else { + r--; + if (r === 0) { + successiveACState = successiveACState === 2 ? 3 : 0; + } + } + break; + case 3: // set value for a zero item + if (component.blockData[offset + z]) { + component.blockData[offset + z] += (readBit() << successive); + } else { + component.blockData[offset + z] = + successiveACNextValue << successive; + successiveACState = 0; + } + break; + case 4: // eob + if (component.blockData[offset + z]) { + component.blockData[offset + z] += (readBit() << successive); + } + break; + } + k++; + } + if (successiveACState === 4) { + eobrun--; + if (eobrun === 0) { + successiveACState = 0; + } + } + } + + function decodeMcu(component, decode, mcu, row, col) { + var mcuRow = (mcu / mcusPerLine) | 0; + var mcuCol = mcu % mcusPerLine; + var blockRow = mcuRow * component.v + row; + var blockCol = mcuCol * component.h + col; + var offset = getBlockBufferOffset(component, blockRow, blockCol); + + // console.log("MCU Offset: " + offset); + decode(component, offset); + } + + function decodeBlock(component, decode, mcu) { + var blockRow = (mcu / component.blocksPerLine) | 0; + var blockCol = mcu % component.blocksPerLine; + var offset = getBlockBufferOffset(component, blockRow, blockCol); + decode(component, offset); + } + + var componentsLength = components.length; + var component, i, j, k, n; + var decodeFn; + if (progressive) { + if (spectralStart === 0) { + decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive; + console.log(successivePrev === 0 ? "decodeDCFirst" : "decodeDCSuccessive"); + } else { + decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive; + console.log(successivePrev === 0 ? "decodeACFirst" : "decodeACSuccessive"); + } + } else { + decodeFn = decodeBaseline; + } + + var mcu = 0, fileMarker; + var mcuExpected; + if (componentsLength === 1) { + mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn; + } else { + mcuExpected = mcusPerLine * frame.mcusPerColumn; + } + + console.log("mcuExpected = "+ mcuExpected); + + var h, v; + while (mcu < mcuExpected) { + // reset interval stuff + var mcuToRead = resetInterval ? + Math.min(mcuExpected - mcu, resetInterval) : mcuExpected; + for (i = 0; i < componentsLength; i++) { + components[i].pred = 0; + } + eobrun = 0; + + if (componentsLength === 1) { + component = components[0]; + + for (n = 0; n < mcuToRead; n++) { + decodeBlock(component, decodeFn, mcu); + mcu++; + } + } else { + for (n = 0; n < mcuToRead; n++) { + for (i = 0; i < componentsLength; i++) { + component = components[i]; + h = component.h; + v = component.v; + for (j = 0; j < v; j++) { + for (k = 0; k < h; k++) { + decodeMcu(component, decodeFn, mcu, j, k); + } + } + } + mcu++; + } + } + + // find marker + bitsCount = 0; + fileMarker = findNextFileMarker(data, offset); + // Some bad images seem to pad Scan blocks with e.g. zero bytes, skip past + // those to attempt to find a valid marker (fixes issue4090.pdf). + if (fileMarker && fileMarker.invalid) { + warn('decodeScan - unexpected MCU data, next marker is: ' + + fileMarker.invalid); + offset = fileMarker.offset; + } + var marker = fileMarker && fileMarker.marker; + if (!marker || marker <= 0xFF00) { + error('JPEG error: marker was not found'); + } + + if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx + offset += 2; + } else { + break; + } + } + + fileMarker = findNextFileMarker(data, offset); + // Some images include more Scan blocks than expected, skip past those and + // attempt to find the next valid marker (fixes issue8182.pdf). + if (fileMarker && fileMarker.invalid) { + warn('decodeScan - unexpected Scan data, next marker is: ' + + fileMarker.invalid); + offset = fileMarker.offset; + } + + return offset - startOffset; + } + + // A port of poppler's IDCT method which in turn is taken from: + // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz, + // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications', + // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989, + // 988-991. + function quantizeAndInverse(component, blockBufferOffset, p) { + var qt = component.quantizationTable, blockData = component.blockData; + var v0, v1, v2, v3, v4, v5, v6, v7; + var p0, p1, p2, p3, p4, p5, p6, p7; + var t; + + if (!qt) { + error('JPEG error: missing required Quantization Table.'); + } + + // inverse DCT on rows + for (var row = 0; row < 64; row += 8) { + // gather block data + p0 = blockData[blockBufferOffset + row]; + p1 = blockData[blockBufferOffset + row + 1]; + p2 = blockData[blockBufferOffset + row + 2]; + p3 = blockData[blockBufferOffset + row + 3]; + p4 = blockData[blockBufferOffset + row + 4]; + p5 = blockData[blockBufferOffset + row + 5]; + p6 = blockData[blockBufferOffset + row + 6]; + p7 = blockData[blockBufferOffset + row + 7]; + + // dequant p0 + p0 *= qt[row]; + + // check for all-zero AC coefficients + if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) { + t = (dctSqrt2 * p0 + 512) >> 10; + p[row] = t; + p[row + 1] = t; + p[row + 2] = t; + p[row + 3] = t; + p[row + 4] = t; + p[row + 5] = t; + p[row + 6] = t; + p[row + 7] = t; + continue; + } + // dequant p1 ... p7 + p1 *= qt[row + 1]; + p2 *= qt[row + 2]; + p3 *= qt[row + 3]; + p4 *= qt[row + 4]; + p5 *= qt[row + 5]; + p6 *= qt[row + 6]; + p7 *= qt[row + 7]; + + // stage 4 + v0 = (dctSqrt2 * p0 + 128) >> 8; + v1 = (dctSqrt2 * p4 + 128) >> 8; + v2 = p2; + v3 = p6; + v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8; + v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8; + v5 = p3 << 4; + v6 = p5 << 4; + + // stage 3 + v0 = (v0 + v1 + 1) >> 1; + v1 = v0 - v1; + t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8; + v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8; + v3 = t; + v4 = (v4 + v6 + 1) >> 1; + v6 = v4 - v6; + v7 = (v7 + v5 + 1) >> 1; + v5 = v7 - v5; + + // stage 2 + v0 = (v0 + v3 + 1) >> 1; + v3 = v0 - v3; + v1 = (v1 + v2 + 1) >> 1; + v2 = v1 - v2; + t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12; + v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12; + v7 = t; + t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12; + v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12; + v6 = t; + + // stage 1 + p[row] = v0 + v7; + p[row + 7] = v0 - v7; + p[row + 1] = v1 + v6; + p[row + 6] = v1 - v6; + p[row + 2] = v2 + v5; + p[row + 5] = v2 - v5; + p[row + 3] = v3 + v4; + p[row + 4] = v3 - v4; + } + + // inverse DCT on columns + for (var col = 0; col < 8; ++col) { + p0 = p[col]; + p1 = p[col + 8]; + p2 = p[col + 16]; + p3 = p[col + 24]; + p4 = p[col + 32]; + p5 = p[col + 40]; + p6 = p[col + 48]; + p7 = p[col + 56]; + + // check for all-zero AC coefficients + if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) { + t = (dctSqrt2 * p0 + 8192) >> 14; + // convert to 8 bit + t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4; + blockData[blockBufferOffset + col] = t; + blockData[blockBufferOffset + col + 8] = t; + blockData[blockBufferOffset + col + 16] = t; + blockData[blockBufferOffset + col + 24] = t; + blockData[blockBufferOffset + col + 32] = t; + blockData[blockBufferOffset + col + 40] = t; + blockData[blockBufferOffset + col + 48] = t; + blockData[blockBufferOffset + col + 56] = t; + continue; + } + + // stage 4 + v0 = (dctSqrt2 * p0 + 2048) >> 12; + v1 = (dctSqrt2 * p4 + 2048) >> 12; + v2 = p2; + v3 = p6; + v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12; + v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12; + v5 = p3; + v6 = p5; + + // stage 3 + // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when + // converting to UInt8 range later. + v0 = ((v0 + v1 + 1) >> 1) + 4112; + v1 = v0 - v1; + t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12; + v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12; + v3 = t; + v4 = (v4 + v6 + 1) >> 1; + v6 = v4 - v6; + v7 = (v7 + v5 + 1) >> 1; + v5 = v7 - v5; + + // stage 2 + v0 = (v0 + v3 + 1) >> 1; + v3 = v0 - v3; + v1 = (v1 + v2 + 1) >> 1; + v2 = v1 - v2; + t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12; + v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12; + v7 = t; + t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12; + v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12; + v6 = t; + + // stage 1 + p0 = v0 + v7; + p7 = v0 - v7; + p1 = v1 + v6; + p6 = v1 - v6; + p2 = v2 + v5; + p5 = v2 - v5; + p3 = v3 + v4; + p4 = v3 - v4; + + // convert to 8-bit integers + p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4; + p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4; + p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4; + p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4; + p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4; + p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4; + p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4; + p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4; + + // store block data + blockData[blockBufferOffset + col] = p0; + blockData[blockBufferOffset + col + 8] = p1; + blockData[blockBufferOffset + col + 16] = p2; + blockData[blockBufferOffset + col + 24] = p3; + blockData[blockBufferOffset + col + 32] = p4; + blockData[blockBufferOffset + col + 40] = p5; + blockData[blockBufferOffset + col + 48] = p6; + blockData[blockBufferOffset + col + 56] = p7; + } + } + + function buildComponentData(frame, component) { + var blocksPerLine = component.blocksPerLine; + var blocksPerColumn = component.blocksPerColumn; + var computationBuffer = new Int16Array(64); + console.log("qt"); + console.log(component.quantizationTable); + for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) { + for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) { + var offset = getBlockBufferOffset(component, blockRow, blockCol); + quantizeAndInverse(component, offset, computationBuffer); + } + } + + console.log("component.blockData"); + console.log(component.blockData); + return component.blockData; + } + + function clamp0to255(a) { + return a <= 0 ? 0 : a >= 255 ? 255 : a; + } + + function findNextFileMarker(data, currentPos, startPos) { + function peekUint16(pos) { + return (data[pos] << 8) | data[pos + 1]; + } + + var maxPos = data.length - 1; + var newPos = startPos < currentPos ? startPos : currentPos; + + if (currentPos >= maxPos) { + return null; // Don't attempt to read non-existent data and just return. + } + var currentMarker = peekUint16(currentPos); + if (currentMarker >= 0xFFC0 && currentMarker <= 0xFFFE) { + return { + invalid: null, + marker: currentMarker, + offset: currentPos, + }; + } + var newMarker = peekUint16(newPos); + while (!(newMarker >= 0xFFC0 && newMarker <= 0xFFFE)) { + if (++newPos >= maxPos) { + return null; // Don't attempt to read non-existent data and just return. + } + newMarker = peekUint16(newPos); + } + return { + invalid: currentMarker.toString(16), + marker: newMarker, + offset: newPos, + }; + } + + JpegImage.prototype = { + parse: function parse(data) { + + function readUint16() { + var value = (data[offset] << 8) | data[offset + 1]; + offset += 2; + return value; + } + + function readDataBlock() { + var length = readUint16(); + var endOffset = offset + length - 2; + + var fileMarker = findNextFileMarker(data, endOffset, offset); + if (fileMarker && fileMarker.invalid) { + warn('readDataBlock - incorrect length, next marker is: ' + + fileMarker.invalid); + endOffset = fileMarker.offset; + } + + var array = data.subarray(offset, endOffset); + offset += array.length; + return array; + } + + function prepareComponents(frame) { + var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH); + var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV); + for (var i = 0; i < frame.components.length; i++) { + component = frame.components[i]; + var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * + component.h / frame.maxH); + var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * + component.v / frame.maxV); + var blocksPerLineForMcu = mcusPerLine * component.h; + var blocksPerColumnForMcu = mcusPerColumn * component.v; + + var blocksBufferSize = 64 * blocksPerColumnForMcu * + (blocksPerLineForMcu + 1); + component.blockData = new Int16Array(blocksBufferSize); + component.blocksPerLine = blocksPerLine; + component.blocksPerColumn = blocksPerColumn; + } + frame.mcusPerLine = mcusPerLine; + frame.mcusPerColumn = mcusPerColumn; + } + + var offset = 0; + var jfif = null; + var adobe = null; + var frame, resetInterval; + var quantizationTables = []; + var huffmanTablesAC = [], huffmanTablesDC = []; + var fileMarker = readUint16(); + if (fileMarker !== 0xFFD8) { // SOI (Start of Image) + error('JPEG error: SOI not found'); + } + + fileMarker = readUint16(); + while (fileMarker !== 0xFFD9) { // EOI (End of image) + var i, j, l; + switch (fileMarker) { + case 0xFFE0: // APP0 (Application Specific) + case 0xFFE1: // APP1 + case 0xFFE2: // APP2 + case 0xFFE3: // APP3 + case 0xFFE4: // APP4 + case 0xFFE5: // APP5 + case 0xFFE6: // APP6 + case 0xFFE7: // APP7 + case 0xFFE8: // APP8 + case 0xFFE9: // APP9 + case 0xFFEA: // APP10 + case 0xFFEB: // APP11 + case 0xFFEC: // APP12 + case 0xFFED: // APP13 + case 0xFFEE: // APP14 + case 0xFFEF: // APP15 + case 0xFFFE: // COM (Comment) + var appData = readDataBlock(); + + if (fileMarker === 0xFFE0) { + if (appData[0] === 0x4A && appData[1] === 0x46 && + appData[2] === 0x49 && appData[3] === 0x46 && + appData[4] === 0) { // 'JFIF\x00' + jfif = { + version: { major: appData[5], minor: appData[6], }, + densityUnits: appData[7], + xDensity: (appData[8] << 8) | appData[9], + yDensity: (appData[10] << 8) | appData[11], + thumbWidth: appData[12], + thumbHeight: appData[13], + thumbData: appData.subarray(14, 14 + + 3 * appData[12] * appData[13]), + }; + } + } + // TODO APP1 - Exif + if (fileMarker === 0xFFEE) { + if (appData[0] === 0x41 && appData[1] === 0x64 && + appData[2] === 0x6F && appData[3] === 0x62 && + appData[4] === 0x65) { // 'Adobe' + adobe = { + version: (appData[5] << 8) | appData[6], + flags0: (appData[7] << 8) | appData[8], + flags1: (appData[9] << 8) | appData[10], + transformCode: appData[11], + }; + } + } + break; + + case 0xFFDB: // DQT (Define Quantization Tables) + var quantizationTablesLength = readUint16(); + var quantizationTablesEnd = quantizationTablesLength + offset - 2; + var z; + while (offset < quantizationTablesEnd) { + var quantizationTableSpec = data[offset++]; + var tableData = new Uint16Array(64); + if ((quantizationTableSpec >> 4) === 0) { // 8 bit values + for (j = 0; j < 64; j++) { + z = dctZigZag[j]; + tableData[z] = data[offset++]; + } + } else if ((quantizationTableSpec >> 4) === 1) { // 16 bit values + for (j = 0; j < 64; j++) { + z = dctZigZag[j]; + tableData[z] = readUint16(); + } + } else { + error('JPEG error: DQT - invalid table spec'); + } + quantizationTables[quantizationTableSpec & 15] = tableData; + } + break; + + case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT) + case 0xFFC1: // SOF1 (Start of Frame, Extended DCT) + case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT) + if (frame) { + error('JPEG error: Only single frame JPEGs supported'); + } + console.log("filemarker"); + console.log(fileMarker); + console.log(offset); + readUint16(); // skip data length + frame = {}; + frame.extended = (fileMarker === 0xFFC1); + frame.progressive = (fileMarker === 0xFFC2); + frame.precision = data[offset++]; + frame.scanLines = readUint16(); + frame.samplesPerLine = readUint16(); + frame.components = []; + frame.componentIds = {}; + var componentsCount = data[offset++], componentId; + var maxH = 0, maxV = 0; + for (i = 0; i < componentsCount; i++) { + componentId = data[offset]; + var h = data[offset + 1] >> 4; + var v = data[offset + 1] & 15; + if (maxH < h) { + maxH = h; + } + if (maxV < v) { + maxV = v; + } + var qId = data[offset + 2]; + l = frame.components.push({ + h, + v, + quantizationId: qId, + quantizationTable: null, // See comment below. + }); + frame.componentIds[componentId] = l - 1; + offset += 3; + } + + frame.maxH = maxH; + frame.maxV = maxV; + prepareComponents(frame); + break; + + case 0xFFC4: // DHT (Define Huffman Tables) + var huffmanLength = readUint16(); + for (i = 2; i < huffmanLength;) { + console.log("offset= " + offset); + var huffmanTableSpec = data[offset++]; + console.log("huffmanTableSpec= " + huffmanTableSpec); + + var codeLengths = new Uint8Array(16); + var codeLengthSum = 0; + for (j = 0; j < 16; j++, offset++) { + codeLengthSum += (codeLengths[j] = data[offset]); + } + console.log("codelengthsum = " + codeLengthSum); + console.log("offset = " + offset); + var huffmanValues = new Uint8Array(codeLengthSum); + for (j = 0; j < codeLengthSum; j++, offset++) { + huffmanValues[j] = data[offset]; + } + i += 17 + codeLengthSum; + + + console.log((huffmanTableSpec >> 4) === 0 ? "DC":"AC"); + ((huffmanTableSpec >> 4) === 0 + ? huffmanTablesDC + : huffmanTablesAC)[huffmanTableSpec & 15] = + buildHuffmanTable(codeLengths, huffmanValues); + } + break; + + case 0xFFDD: // DRI (Define Restart Interval) + readUint16(); // skip data length + resetInterval = readUint16(); + break; + + case 0xFFDA: // SOS (Start of Scan) + readUint16(); // scanLength + var selectorsCount = data[offset++]; + var components = [], component; + for (i = 0; i < selectorsCount; i++) { + var ci = data[offset++]; + console.log("ci= " + ci); + console.log("offset= " + offset); + + var componentIndex = frame.componentIds[ci]; + console.log("componentIndex= " + componentIndex); + component = frame.components[componentIndex]; + var tableSpec = data[offset++]; + component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4]; + component.huffmanTableAC = huffmanTablesAC[tableSpec & 15]; + components.push(component); + } + console.log("components= " + components); + + var spectralStart = data[offset++]; + var spectralEnd = data[offset++]; + var successiveApproximation = data[offset++]; + + console.log(frame.componentIds); + console.log("spectralStart= " + spectralStart); + console.log("spectralEnd= " + spectralEnd); + console.log("successiveApproximation= " + successiveApproximation); + // console.log("components before") + // console.log(components) + var processed = decodeScan(data, offset, + frame, components, resetInterval, + spectralStart, spectralEnd, + successiveApproximation >> 4, successiveApproximation & 15); + offset += processed; + console.log("components after"); + // console.log(frame); + for (var i = 0; i < 3; i++){ + for (var j = 0; j < 10; j++){ + console.log("component ["+ i +"] : value ["+j+"] ="+ frame.components[i].blockData[j]+"]"); + } + } + break; + + case 0xFFFF: // Fill bytes + if (data[offset] !== 0xFF) { // Avoid skipping a valid marker. + offset--; + } + break; + + default: + if (data[offset - 3] === 0xFF && + data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) { + // could be incorrect encoding -- last 0xFF byte of the previous + // block was eaten by the encoder + offset -= 3; + break; + } + + // TODO: Delete this after testing + fileMarker = 0xFFD9; + // error('JPEG error: unknown marker ' + fileMarker.toString(16)); + } + fileMarker = readUint16(); + } + + console.log("quantizationTables"); + console.log(quantizationTables); + + this.width = frame.samplesPerLine; + this.height = frame.scanLines; + this.jfif = jfif; + this.adobe = adobe; + this.components = []; + for (i = 0; i < frame.components.length; i++) { + component = frame.components[i]; + + // Prevent errors when DQT markers are placed after SOF{n} markers, + // by assigning the `quantizationTable` entry after the entire image + // has been parsed (fixes issue7406.pdf). + var quantizationTable = quantizationTables[component.quantizationId]; + if (quantizationTable) { + component.quantizationTable = quantizationTable; + } + + this.components.push({ + output: buildComponentData(frame, component), + scaleX: component.h / frame.maxH, + scaleY: component.v / frame.maxV, + blocksPerLine: component.blocksPerLine, + blocksPerColumn: component.blocksPerColumn, + }); + } + + console.log("components"); + console.log(this.components); + this.numComponents = this.components.length; + }, + + _getLinearizedBlockData: function getLinearizedBlockData(width, height) { + var scaleX = this.width / width, scaleY = this.height / height; + + var component, componentScaleX, componentScaleY, blocksPerScanline; + var x, y, i, j, k; + var index; + var offset = 0; + var output; + var numComponents = this.components.length; + var dataLength = width * height * numComponents; + var data = new Uint8Array(dataLength); + var xScaleBlockOffset = new Uint32Array(width); + var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs + + for (i = 0; i < numComponents; i++) { + component = this.components[i]; + componentScaleX = component.scaleX * scaleX; + componentScaleY = component.scaleY * scaleY; + offset = i; + output = component.output; + blocksPerScanline = (component.blocksPerLine + 1) << 3; + // precalculate the xScaleBlockOffset + for (x = 0; x < width; x++) { + j = 0 | (x * componentScaleX); + xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7); + } + // linearize the blocks of the component + for (y = 0; y < height; y++) { + j = 0 | (y * componentScaleY); + index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3); + for (x = 0; x < width; x++) { + data[offset] = output[index + xScaleBlockOffset[x]]; + offset += numComponents; + } + } + } + + // decodeTransform contains pairs of multiplier (-256..256) and additive + var transform = this.decodeTransform; + if (transform) { + for (i = 0; i < dataLength;) { + for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) { + data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1]; + } + } + } + return data; + }, + + _isColorConversionNeeded: function isColorConversionNeeded() { + if (this.adobe && this.adobe.transformCode) { + // The adobe transform marker overrides any previous setting + return true; + } else if (this.numComponents === 3) { + if (!this.adobe && this.colorTransform === 0) { + // If the Adobe transform marker is not present and the image + // dictionary has a 'ColorTransform' entry, explicitly set to `0`, + // then the colours should *not* be transformed. + return false; + } + return true; + } + // `this.numComponents !== 3` + if (!this.adobe && this.colorTransform === 1) { + // If the Adobe transform marker is not present and the image + // dictionary has a 'ColorTransform' entry, explicitly set to `1`, + // then the colours should be transformed. + return true; + } + return false; + }, + + _convertYccToRgb: function convertYccToRgb(data) { + var Y, Cb, Cr; + for (var i = 0, length = data.length; i < length; i += 3) { + Y = data[i ]; + Cb = data[i + 1]; + Cr = data[i + 2]; + data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr); + data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr); + data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb); + } + return data; + }, + + _convertYcckToRgb: function convertYcckToRgb(data) { + var Y, Cb, Cr, k; + var offset = 0; + for (var i = 0, length = data.length; i < length; i += 4) { + Y = data[i]; + Cb = data[i + 1]; + Cr = data[i + 2]; + k = data[i + 3]; + + var r = -122.67195406894 + + Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr - + 5.4080610064599e-5 * Y + 0.00048449797120281 * k - + 0.154362151871126) + + Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y - + 0.00477271405408747 * k + 1.53380253221734) + + Y * (0.000961250184130688 * Y - 0.00266257332283933 * k + + 0.48357088451265) + + k * (-0.000336197177618394 * k + 0.484791561490776); + + var g = 107.268039397724 + + Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr + + 0.000659397001245577 * Y + 0.000426105652938837 * k - + 0.176491792462875) + + Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y + + 0.000770482631801132 * k - 0.151051492775562) + + Y * (0.00126935368114843 * Y - 0.00265090189010898 * k + + 0.25802910206845) + + k * (-0.000318913117588328 * k - 0.213742400323665); + + var b = -20.810012546947 + + Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr + + 0.0020741088115012 * Y - 0.00288260236853442 * k + + 0.814272968359295) + + Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y + + 0.000560833691242812 * k - 0.195152027534049) + + Y * (0.00174418132927582 * Y - 0.00255243321439347 * k + + 0.116935020465145) + + k * (-0.000343531996510555 * k + 0.24165260232407); + + data[offset++] = clamp0to255(r); + data[offset++] = clamp0to255(g); + data[offset++] = clamp0to255(b); + } + return data; + }, + + _convertYcckToCmyk: function convertYcckToCmyk(data) { + var Y, Cb, Cr; + for (var i = 0, length = data.length; i < length; i += 4) { + Y = data[i]; + Cb = data[i + 1]; + Cr = data[i + 2]; + data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr); + data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr); + data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb); + // K in data[i + 3] is unchanged + } + return data; + }, + + _convertCmykToRgb: function convertCmykToRgb(data) { + var c, m, y, k; + var offset = 0; + var min = -255 * 255 * 255; + var scale = 1 / 255 / 255; + for (var i = 0, length = data.length; i < length; i += 4) { + c = data[i]; + m = data[i + 1]; + y = data[i + 2]; + k = data[i + 3]; + + var r = + c * (-4.387332384609988 * c + 54.48615194189176 * m + + 18.82290502165302 * y + 212.25662451639585 * k - + 72734.4411664936) + + m * (1.7149763477362134 * m - 5.6096736904047315 * y - + 17.873870861415444 * k - 1401.7366389350734) + + y * (-2.5217340131683033 * y - 21.248923337353073 * k + + 4465.541406466231) - + k * (21.86122147463605 * k + 48317.86113160301); + var g = + c * (8.841041422036149 * c + 60.118027045597366 * m + + 6.871425592049007 * y + 31.159100130055922 * k - + 20220.756542821975) + + m * (-15.310361306967817 * m + 17.575251261109482 * y + + 131.35250912493976 * k - 48691.05921601825) + + y * (4.444339102852739 * y + 9.8632861493405 * k - + 6341.191035517494) - + k * (20.737325471181034 * k + 47890.15695978492); + var b = + c * (0.8842522430003296 * c + 8.078677503112928 * m + + 30.89978309703729 * y - 0.23883238689178934 * k - + 3616.812083916688) + + m * (10.49593273432072 * m + 63.02378494754052 * y + + 50.606957656360734 * k - 28620.90484698408) + + y * (0.03296041114873217 * y + 115.60384449646641 * k - + 49363.43385999684) - + k * (22.33816807309886 * k + 45932.16563550634); + + data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0; + data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0; + data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0; + } + return data; + }, + + getData: function getData(width, height, forceRGBoutput) { + if (this.numComponents > 4) { + error('JPEG error: Unsupported color mode'); + } + // type of data: Uint8Array(width * height * numComponents) + var data = this._getLinearizedBlockData(width, height); + + if (this.numComponents === 1 && forceRGBoutput) { + var dataLength = data.length; + var rgbData = new Uint8Array(dataLength * 3); + var offset = 0; + for (var i = 0; i < dataLength; i++) { + var grayColor = data[i]; + rgbData[offset++] = grayColor; + rgbData[offset++] = grayColor; + rgbData[offset++] = grayColor; + } + return rgbData; + } else if (this.numComponents === 3 && this._isColorConversionNeeded()) { + return this._convertYccToRgb(data); + } else if (this.numComponents === 4) { + if (this._isColorConversionNeeded()) { + if (forceRGBoutput) { + return this._convertYcckToRgb(data); + } + return this._convertYcckToCmyk(data); + } else if (forceRGBoutput) { + return this._convertCmykToRgb(data); + } + } + return data; + }, + }; + + return JpegImage; +})(); + +// export { +// JpegImage, +// }; diff --git a/tests/ImageSharp.Tests/TestUtilities/ApproximateFloatComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ApproximateFloatComparer.cs index 333b645dea..6b3f6ccd21 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ApproximateFloatComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ApproximateFloatComparer.cs @@ -1,9 +1,12 @@ -namespace ImageSharp.Tests -{ - using System; - using System.Collections.Generic; - using System.Numerics; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.Numerics; +namespace SixLabors.ImageSharp.Tests +{ internal struct ApproximateFloatComparer : IEqualityComparer, IEqualityComparer { private readonly float Eps; diff --git a/tests/ImageSharp.Tests/TestUtilities/ArrayHelper.cs b/tests/ImageSharp.Tests/TestUtilities/ArrayHelper.cs index d3b4da9b92..e342f7029f 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ArrayHelper.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ArrayHelper.cs @@ -1,12 +1,10 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System.Linq; +using System.Linq; +namespace SixLabors.ImageSharp.Tests +{ public static class ArrayHelper { /// diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs index 05e8c61360..ec3254921f 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs @@ -1,17 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reflection; - - using Xunit.Sdk; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Xunit.Sdk; +namespace SixLabors.ImageSharp.Tests +{ /// /// Base class for Theory Data attributes which pass an instance of to the test case. /// @@ -54,7 +51,7 @@ public override IEnumerable GetData(MethodInfo testMethod) if (!string.IsNullOrWhiteSpace(this.MemberName)) { Type type = this.MemberType ?? testMethod.DeclaringType; - Func accessor = this.GetPropertyAccessor(type) ?? this.GetFieldAccessor(type); + Func accessor = this.GetPropertyAccessor(type, this.MemberName) ?? this.GetFieldAccessor(type, this.MemberName); if (accessor != null) { @@ -156,12 +153,12 @@ protected virtual object[] GetFactoryMethodArgs(MethodInfo testMethod, Type fact /// /// Gets the field accessor for the given type. /// - Func GetFieldAccessor(Type type) + protected Func GetFieldAccessor(Type type, string memberName) { FieldInfo fieldInfo = null; for (Type reflectionType = type; reflectionType != null; reflectionType = reflectionType.GetTypeInfo().BaseType) { - fieldInfo = reflectionType.GetRuntimeField(this.MemberName); + fieldInfo = reflectionType.GetRuntimeField(memberName); if (fieldInfo != null) break; } @@ -175,12 +172,12 @@ Func GetFieldAccessor(Type type) /// /// Gets the property accessor for the given type. /// - Func GetPropertyAccessor(Type type) + protected Func GetPropertyAccessor(Type type, string memberName) { PropertyInfo propInfo = null; for (Type reflectionType = type; reflectionType != null; reflectionType = reflectionType.GetTypeInfo().BaseType) { - propInfo = reflectionType.GetRuntimeProperty(this.MemberName); + propInfo = reflectionType.GetRuntimeProperty(memberName); if (propInfo != null) { break; diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithBlankImageAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithBlankImageAttribute.cs index 72be5abc29..796cba8554 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithBlankImageAttribute.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithBlankImageAttribute.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Reflection; +using System; +using System.Reflection; +namespace SixLabors.ImageSharp.Tests +{ /// /// Triggers passing instances which produce a blank image of size width * height. /// One instance will be passed for each the pixel format defined by the pixelTypes parameter diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileAttribute.cs index ec8421853e..e896c18546 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileAttribute.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileAttribute.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Reflection; +using System; +using System.Reflection; +namespace SixLabors.ImageSharp.Tests +{ /// /// Triggers passing instances which read an image from the given file /// One instance will be passed for each the pixel format defined by the pixelTypes parameter diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs index 1b37c45a92..1702513898 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs @@ -1,15 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reflection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +namespace SixLabors.ImageSharp.Tests +{ /// /// Triggers passing instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName /// instances will be passed for each the pixel format defined by the pixelTypes parameter @@ -38,18 +36,18 @@ public WithFileCollectionAttribute( /// Triggers passing instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName /// instances will be passed for each the pixel format defined by the pixelTypes parameter /// - /// The name of the static test class field/property enumerating the files + /// The name of the static test class field/property enumerating the files /// The member name for enumerating method parameters /// The requested pixel types /// Additional theory parameter values public WithFileCollectionAttribute( - string enumeratorMemberName, + string fileEnumeratorMemberName, string memberName, PixelTypes pixelTypes, params object[] additionalParameters) : base(memberName, pixelTypes, additionalParameters) { - this.fileEnumeratorMemberName = enumeratorMemberName; + this.fileEnumeratorMemberName = fileEnumeratorMemberName; } /// @@ -60,8 +58,8 @@ public WithFileCollectionAttribute( /// The protected override IEnumerable GetAllFactoryMethodArgs(MethodInfo testMethod, Type factoryType) { - Func accessor = this.GetPropertyAccessor(testMethod.DeclaringType); - accessor = accessor ?? this.GetFieldAccessor(testMethod.DeclaringType); + Func accessor = this.GetPropertyAccessor(testMethod.DeclaringType, this.fileEnumeratorMemberName); + accessor = accessor ?? this.GetFieldAccessor(testMethod.DeclaringType, this.fileEnumeratorMemberName); var files = (IEnumerable)accessor(); return files.Select(f => new object[] { f }); @@ -69,52 +67,5 @@ protected override IEnumerable GetAllFactoryMethodArgs(MethodInfo test /// protected override string GetFactoryMethodName(MethodInfo testMethod) => "File"; - - /// - /// Gets the field accessor for the given type. - /// - private Func GetFieldAccessor(Type type) - { - FieldInfo fieldInfo = null; - for (Type reflectionType = type; - reflectionType != null; - reflectionType = reflectionType.GetTypeInfo().BaseType) - { - fieldInfo = reflectionType.GetRuntimeField(this.fileEnumeratorMemberName); - if (fieldInfo != null) - { - break; - } - } - - if (fieldInfo == null || !fieldInfo.IsStatic) - { - return null; - } - - return () => fieldInfo.GetValue(null); - } - - /// - /// Gets the property accessor for the given type. - /// - private Func GetPropertyAccessor(Type type) - { - PropertyInfo propInfo = null; - for (Type reflectionType = type; - reflectionType != null; - reflectionType = reflectionType.GetTypeInfo().BaseType) - { - propInfo = reflectionType.GetRuntimeProperty(this.fileEnumeratorMemberName); - if (propInfo != null) break; - } - - if (propInfo?.GetMethod == null || !propInfo.GetMethod.IsStatic) - { - return null; - } - - return () => propInfo.GetValue(null, null); - } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs index 6c6198c38d..cdf5fcb089 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Linq; - using System.Reflection; +using System; +using System.Linq; +using System.Reflection; +namespace SixLabors.ImageSharp.Tests +{ /// /// Triggers passing instances which return the image produced by the given test class member method /// instances will be passed for each the pixel format defined by the pixelTypes parameter @@ -39,9 +37,8 @@ protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type fac Type colorType = args.Single(); Type imgType = typeof(Image<>).MakeGenericType(colorType); - Type genericFactoryType = (typeof(GenericFactory<>)).MakeGenericType(colorType); - Type funcType = typeof(Func<,>).MakeGenericType(genericFactoryType, imgType); + Type funcType = typeof(Func<>).MakeGenericType(imgType); MethodInfo genericMethod = m.MakeGenericMethod(args); diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithSolidFilledImagesAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithSolidFilledImagesAttribute.cs index 9a8538e78b..f787a35916 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithSolidFilledImagesAttribute.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithSolidFilledImagesAttribute.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Reflection; +using System; +using System.Reflection; +namespace SixLabors.ImageSharp.Tests +{ /// /// Triggers passing instances which produce an image of size width * height filled with the requested color. /// One instance will be passed for each the pixel format defined by the pixelTypes parameter diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithTestPatternImageAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithTestPatternImageAttribute.cs index f6ab65f714..585bb8f066 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithTestPatternImageAttribute.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithTestPatternImageAttribute.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Reflection; +using System; +using System.Reflection; +namespace SixLabors.ImageSharp.Tests +{ /// /// Triggers passing instances which produce a blank image of size width * height. /// One instance will be passed for each the pixel format defined by the pixelTypes parameter diff --git a/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs b/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs deleted file mode 100644 index 4a0950788d..0000000000 --- a/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs +++ /dev/null @@ -1,34 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Tests -{ - using System; - - using ImageSharp.PixelFormats; - - /// - /// Utility class to create specialized subclasses of generic classes (eg. ) - /// Used as parameter for -based factory methods - /// - public class GenericFactory - where TPixel : struct, IPixel - { - public virtual Image CreateImage(int width, int height) - { - return new Image(width, height); - } - - public virtual Image CreateImage(byte[] bytes) - { - return Image.Load(bytes); - } - - public virtual Image CreateImage(Image other) - { - return new Image(other); - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs deleted file mode 100644 index 20af430a5f..0000000000 --- a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Tests -{ - using ImageSharp.PixelFormats; - - public class ImageFactory : GenericFactory - { - public override Image CreateImage(byte[] bytes) => Image.Load(bytes); - - public override Image CreateImage(int width, int height) => new Image(width, height); - - public override Image CreateImage(Image other) - { - return new Image(other); - } - } -} diff --git a/tests/ImageSharp.Tests/TestUtilities/FloatRoundingComparer.cs b/tests/ImageSharp.Tests/TestUtilities/FloatRoundingComparer.cs index dd3ef3a4f9..f7732fce53 100644 --- a/tests/ImageSharp.Tests/TestUtilities/FloatRoundingComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/FloatRoundingComparer.cs @@ -1,9 +1,12 @@ -namespace ImageSharp.Tests -{ - using System; - using System.Collections.Generic; - using System.Numerics; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.Numerics; +namespace SixLabors.ImageSharp.Tests +{ /// /// Allows the comparison of single-precision floating point values by precision. /// diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs new file mode 100644 index 0000000000..cb87b9e907 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs @@ -0,0 +1,56 @@ +namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison +{ + using System; + using System.Collections.Generic; + + using SixLabors.ImageSharp.PixelFormats; + + using SixLabors.Primitives; + + public class ExactImageComparer : ImageComparer + { + public static ExactImageComparer Instance { get; } = new ExactImageComparer(); + + public override ImageSimilarityReport CompareImagesOrFrames( + ImageBase expected, + ImageBase actual) + { + if (expected.Size() != actual.Size()) + { + throw new InvalidOperationException("Calling ImageComparer is invalid when dimensions mismatch!"); + } + + int width = actual.Width; + + // TODO: Comparing through Rgba32 is not robust enough because of the existance of super high precision pixel types. + + Rgba32[] aBuffer = new Rgba32[width]; + Rgba32[] bBuffer = new Rgba32[width]; + + var differences = new List(); + + for (int y = 0; y < actual.Height; y++) + { + Span aSpan = expected.GetRowSpan(y); + Span bSpan = actual.GetRowSpan(y); + + PixelOperations.Instance.ToRgba32(aSpan, aBuffer, width); + PixelOperations.Instance.ToRgba32(bSpan, bBuffer, width); + + for (int x = 0; x < width; x++) + { + Rgba32 aPixel = aBuffer[x]; + Rgba32 bPixel = bBuffer[x]; + + if (aPixel != bPixel) + { + var diff = new PixelDifference(new Point(x, y), aPixel, bPixel); + differences.Add(diff); + } + } + } + + return new ImageSimilarityReport(expected, actual, differences); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDimensionsMismatchException.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDimensionsMismatchException.cs new file mode 100644 index 0000000000..e8f60ade31 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDimensionsMismatchException.cs @@ -0,0 +1,20 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison +{ + public class ImageDimensionsMismatchException : ImagesSimilarityException + { + public ImageDimensionsMismatchException(Size expectedSize, Size actualSize) + : base((string)$"The image dimensions {actualSize} do not match the expected {expectedSize}!") + { + this.ExpectedSize = expectedSize; + this.ActualSize = actualSize; + } + + public Size ExpectedSize { get; } + public Size ActualSize { get; } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImagePixelsAreDifferentException.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImagePixelsAreDifferentException.cs new file mode 100644 index 0000000000..56bf6e90b2 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImagePixelsAreDifferentException.cs @@ -0,0 +1,34 @@ +namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + + public class ImagePixelsAreDifferentException : ImagesSimilarityException + { + public ImageSimilarityReport[] Reports { get; } + + public ImagePixelsAreDifferentException(IEnumerable reports) + : base("Images are not similar enough!" + StringifyReports(reports)) + { + this.Reports = reports.ToArray(); + } + + private static string StringifyReports(IEnumerable reports) + { + StringBuilder sb = new StringBuilder(); + sb.Append(Environment.NewLine); + + int i = 0; + foreach (ImageSimilarityReport r in reports) + { + sb.Append($"Report{i}: "); + sb.Append(r); + sb.Append(Environment.NewLine); + i++; + } + return sb.ToString(); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImagesSimilarityException.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImagesSimilarityException.cs new file mode 100644 index 0000000000..bbdb6b5815 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImagesSimilarityException.cs @@ -0,0 +1,12 @@ +namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison +{ + using System; + + public class ImagesSimilarityException : Exception + { + public ImagesSimilarityException(string message) + : base(message) + { + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs new file mode 100644 index 0000000000..a95d231bbe --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs @@ -0,0 +1,110 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.Linq; + +using SixLabors.ImageSharp.PixelFormats; + +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison +{ + public abstract class ImageComparer + { + public static ImageComparer Exact { get; } = Tolerant(0, 0); + + public static ImageComparer Tolerant( + float imageThreshold = TolerantImageComparer.DefaultImageThreshold, + int pixelThresholdInPixelByteSum = 0) + { + return new TolerantImageComparer(imageThreshold, pixelThresholdInPixelByteSum); + } + + public abstract ImageSimilarityReport CompareImagesOrFrames( + ImageBase expected, + ImageBase actual) + where TPixelA : struct, IPixel where TPixelB : struct, IPixel; + } + + public static class ImageComparerExtensions + { + public static IEnumerable CompareImages( + this ImageComparer comparer, + Image expected, + Image actual) + where TPixelA : struct, IPixel where TPixelB : struct, IPixel + { + var result = new List(); + ImageSimilarityReport report = comparer.CompareImagesOrFrames(expected, actual); + + if (!report.IsEmpty) + { + result.Add(report); + } + + if (expected.Frames.Count != actual.Frames.Count) + { + throw new Exception("Frame count does not match!"); + } + for (int i = 0; i < expected.Frames.Count; i++) + { + report = comparer.CompareImagesOrFrames(expected.Frames[i], actual.Frames[i]); + if (!report.IsEmpty) + { + result.Add(report); + } + } + return result; + } + + public static void VerifySimilarity( + this ImageComparer comparer, + Image expected, + Image actual) + where TPixelA : struct, IPixel where TPixelB : struct, IPixel + { + if (expected.Size() != actual.Size()) + { + throw new ImageDimensionsMismatchException(expected.Size(), actual.Size()); + } + + if (expected.Frames.Count != actual.Frames.Count) + { + throw new ImagesSimilarityException("Image frame count does not match!"); + } + + IEnumerable reports = comparer.CompareImages(expected, actual); + if (reports.Any()) + { + throw new ImagePixelsAreDifferentException(reports); + } + } + + /// + /// Fills the bounded area with a solid color and does a visual comparison between 2 images asserting the difference outwith + /// that area is less then a configurable threshold. + /// + /// The color of the expected image + /// The color type fo the the actual image + /// The to use + /// The expected image + /// The actual image + /// The bounds within the image has been altered + public static void EnsureProcessorChangesAreConstrained( + this ImageComparer comparer, + Image expected, + Image actual, + Rectangle bounds) + where TPixelA : struct, IPixel + where TPixelB : struct, IPixel + { + // Draw identical shapes over the bounded and compare to ensure changes are constrained. + expected.Mutate(x => x.Fill(NamedColors.HotPink, bounds)); + actual.Mutate(x => x.Fill(NamedColors.HotPink, bounds)); + + comparer.VerifySimilarity(expected, actual); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs new file mode 100644 index 0000000000..e0e847a837 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs @@ -0,0 +1,64 @@ +namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + + public class ImageSimilarityReport + { + public ImageSimilarityReport( + IImageBase expectedImage, + IImageBase actualImage, + IEnumerable differences, + float? totalNormalizedDifference = null) + { + this.ExpectedImage = expectedImage; + this.ActualImage = actualImage; + this.TotalNormalizedDifference = totalNormalizedDifference; + this.Differences = differences.ToArray(); + } + + public static ImageSimilarityReport Empty => + new ImageSimilarityReport(null, null, Enumerable.Empty(), null); + + public float? TotalNormalizedDifference { get; } + + public IImageBase ExpectedImage { get; } + + public IImageBase ActualImage { get; } + + public PixelDifference[] Differences { get; } + + public bool IsEmpty => this.Differences.Length == 0; + + public override string ToString() + { + return this.IsEmpty ? "[SimilarImages]" : this.PrintDifference(); + } + + private string PrintDifference() + { + var sb = new StringBuilder(); + if (this.TotalNormalizedDifference.HasValue) + { + sb.AppendLine($"Total difference: {this.TotalNormalizedDifference.Value * 100:0.0000}%"); + } + int max = Math.Min(5, this.Differences.Length); + + for (int i = 0; i < max; i++) + { + sb.Append(this.Differences[i]); + if (i < max - 1) + { + sb.Append("; "); + } + } + if (this.Differences.Length >= 5) + { + sb.Append("..."); + } + return sb.ToString(); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/PixelDifference.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/PixelDifference.cs new file mode 100644 index 0000000000..fcfb31d682 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/PixelDifference.cs @@ -0,0 +1,40 @@ +namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison +{ + using SixLabors.Primitives; + + public struct PixelDifference + { + public PixelDifference( + Point position, + int redDifference, + int greenDifference, + int blueDifference, + int alphaDifference) + { + this.Position = position; + this.RedDifference = redDifference; + this.GreenDifference = greenDifference; + this.BlueDifference = blueDifference; + this.AlphaDifference = alphaDifference; + } + + public PixelDifference(Point position, Rgba32 expected, Rgba32 actual) + : this(position, + (int)actual.R - (int)expected.R, + (int)actual.G - (int)expected.G, + (int)actual.B - (int)expected.B, + (int)actual.A - (int)expected.A) + { + } + + public Point Position { get; } + + public int RedDifference { get; } + public int GreenDifference { get; } + public int BlueDifference { get; } + public int AlphaDifference { get; } + + public override string ToString() => + $"[Δ({this.RedDifference},{this.GreenDifference},{this.BlueDifference},{this.AlphaDifference}) @ ({this.Position.X},{this.Position.Y})]"; + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs new file mode 100644 index 0000000000..c015a4b2f4 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs @@ -0,0 +1,103 @@ +namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison +{ + using System; + using System.Collections.Generic; + using System.Runtime.CompilerServices; + + using SixLabors.ImageSharp.PixelFormats; + + using SixLabors.Primitives; + + public class TolerantImageComparer : ImageComparer + { + public const float DefaultImageThreshold = 1.0f / (100 * 100 * 255); + + public TolerantImageComparer(float imageThreshold, int pixelThresholdInPixelByteSum = 0) + { + this.ImageThreshold = imageThreshold; + this.PixelThresholdInPixelByteSum = pixelThresholdInPixelByteSum; + } + + /// + /// The maximal tolerated difference represented by a value between 0.0 and 1.0. + /// Examples of percentage differences on a single pixel: + /// 1. PixelA = (255,255,255,0) PixelB =(0,0,0,255) leads to 100% difference on a single pixel + /// 2. PixelA = (255,255,255,0) PixelB =(255,255,255,255) leads to 25% difference on a single pixel + /// 3. PixelA = (255,255,255,0) PixelB =(128,128,128,128) leads to 50% difference on a single pixel + /// + /// The total differences is the sum of all pixel differences normalized by image dimensions! + /// + /// ImageThresholdInPercents = 1.0/255 means that we allow one byte difference per channel on a 1x1 image + /// ImageThresholdInPercents = 1.0/(100*100*255) means that we allow only one byte difference per channel on a 100x100 image + /// + public float ImageThreshold { get; } + + /// + /// The threshold of the individual pixels before they acumulate towards the overall difference. + /// For an individual pixel the value it's calculated as: pixel.R + pixel.G + pixel.B + pixel.A + /// + public int PixelThresholdInPixelByteSum { get; } + + public override ImageSimilarityReport CompareImagesOrFrames(ImageBase expected, ImageBase actual) + { + if (expected.Size() != actual.Size()) + { + throw new InvalidOperationException("Calling ImageComparer is invalid when dimensions mismatch!"); + } + + int width = actual.Width; + + // TODO: Comparing through Rgba32 is not robust enough because of the existance of super high precision pixel types. + + Rgba32[] aBuffer = new Rgba32[width]; + Rgba32[] bBuffer = new Rgba32[width]; + + float totalDifference = 0.0f; + + var differences = new List(); + + for (int y = 0; y < actual.Height; y++) + { + Span aSpan = expected.GetRowSpan(y); + Span bSpan = actual.GetRowSpan(y); + + PixelOperations.Instance.ToRgba32(aSpan, aBuffer, width); + PixelOperations.Instance.ToRgba32(bSpan, bBuffer, width); + + for (int x = 0; x < width; x++) + { + int d = GetHammingDistanceInRgbaSpace(ref aBuffer[x], ref bBuffer[x]); + + if (d > this.PixelThresholdInPixelByteSum) + { + var diff = new PixelDifference(new Point(x, y), aBuffer[x], bBuffer[x]); + differences.Add(diff); + + totalDifference += d; + } + } + } + + float normalizedDifference = totalDifference / ((float)actual.Width * (float)actual.Height); + normalizedDifference /= 4.0f * 255.0f; + + if (normalizedDifference > this.ImageThreshold) + { + return new ImageSimilarityReport(expected, actual, differences, normalizedDifference); + } + else + { + return ImageSimilarityReport.Empty; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int GetHammingDistanceInRgbaSpace(ref Rgba32 a, ref Rgba32 b) + { + return Diff(a.R, b.R) + Diff(a.G, b.G) + Diff(a.B, b.B) + Diff(a.A, b.A); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int Diff(byte a, byte b) => Math.Abs(a - b); + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs index 4252a60b5e..78821aac15 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; +using System; - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; - using Xunit.Abstractions; +using Xunit.Abstractions; +namespace SixLabors.ImageSharp.Tests +{ public abstract partial class TestImageProvider where TPixel : struct, IPixel { @@ -33,7 +31,7 @@ public BlankProvider() protected int Width { get; private set; } - public override Image GetImage() => this.Factory.CreateImage(this.Width, this.Height); + public override Image GetImage() => new Image(this.Width, this.Height); public override void Deserialize(IXunitSerializationInfo info) diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs index 16eecd2fc7..8ff532b2f4 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs @@ -1,17 +1,18 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Collections.Concurrent; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Reflection; - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; - using Xunit.Abstractions; +using Xunit.Abstractions; +namespace SixLabors.ImageSharp.Tests +{ public abstract partial class TestImageProvider where TPixel : struct, IPixel { @@ -19,47 +20,130 @@ private class FileProvider : TestImageProvider, IXunitSerializable { // Need PixelTypes in the dictionary key, because result images of TestImageProvider.FileProvider // are shared between PixelTypes.Color & PixelTypes.Rgba32 - private class Key : Tuple + private class Key : IEquatable { - public Key(PixelTypes item1, string item2) - : base(item1, item2) + private Tuple commonValues; + + private Dictionary decoderParameters; + + public Key(PixelTypes pixelType, string filePath, IImageDecoder customDecoder) + { + Type customType = customDecoder?.GetType(); + this.commonValues = new Tuple(pixelType, filePath, customType); + this.decoderParameters = GetDecoderParameters(customDecoder); + } + + private static Dictionary GetDecoderParameters(IImageDecoder customDecoder) + { + Type type = customDecoder.GetType(); + + var data = new Dictionary(); + + while (type != null && type != typeof(object)) + { + PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); + foreach (PropertyInfo p in properties) + { + string key = $"{type.FullName}.{p.Name}"; + object value = p.GetValue(customDecoder); + data[key] = value; + } + type = type.GetTypeInfo().BaseType; + } + return data; + } + + public bool Equals(Key other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + if (!this.commonValues.Equals(other.commonValues)) return false; + + if (this.decoderParameters.Count != other.decoderParameters.Count) + { + return false; + } + + foreach (KeyValuePair kv in this.decoderParameters) + { + object otherVal; + if (!other.decoderParameters.TryGetValue(kv.Key, out otherVal)) + { + return false; + } + if (!object.Equals(kv.Value, otherVal)) + { + return false; + } + } + return true; + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != this.GetType()) return false; + return this.Equals((Key)obj); + } + + public override int GetHashCode() + { + return this.commonValues.GetHashCode(); + } + + public static bool operator ==(Key left, Key right) + { + return Equals(left, right); + } + + public static bool operator !=(Key left, Key right) { + return !Equals(left, right); } } private static readonly ConcurrentDictionary> cache = new ConcurrentDictionary>(); - private string filePath; - public FileProvider(string filePath) { - this.filePath = filePath; + this.FilePath = filePath; } public FileProvider() { } - public override string SourceFileOrDescription => this.filePath; + public string FilePath { get; private set; } + + public override string SourceFileOrDescription => this.FilePath; public override Image GetImage() { - Key key = new Key(this.PixelType, this.filePath); + IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(this.FilePath); + return this.GetImage(decoder); + } + + public override Image GetImage(IImageDecoder decoder) + { + Guard.NotNull(decoder, nameof(decoder)); + + Key key = new Key(this.PixelType, this.FilePath, decoder); Image cachedImage = cache.GetOrAdd( key, fn => { - TestFile testFile = TestFile.Create(this.filePath); - return this.Factory.CreateImage(testFile.Bytes); + TestFile testFile = TestFile.Create(this.FilePath); + return Image.Load(testFile.Bytes, decoder); }); - return this.Factory.CreateImage(cachedImage); + return cachedImage.Clone(); } public override void Deserialize(IXunitSerializationInfo info) { - this.filePath = info.GetValue("path"); + this.FilePath = info.GetValue("path"); base.Deserialize(info); // must be called last } @@ -67,8 +151,14 @@ public override void Deserialize(IXunitSerializationInfo info) public override void Serialize(IXunitSerializationInfo info) { base.Serialize(info); - info.AddValue("path", this.filePath); + info.AddValue("path", this.FilePath); } } + + public static string GetFilePathOrNull(ITestImageProvider provider) + { + var fileProvider = provider as FileProvider; + return fileProvider?.FilePath; + } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs index 30e7a63b50..5bd53a4c0c 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; +using System; - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Tests +{ /// /// Provides instances for parametric unit tests. /// @@ -18,14 +16,14 @@ public abstract partial class TestImageProvider { private class LambdaProvider : TestImageProvider { - private readonly Func, Image> creator; + private readonly Func> factoryFunc; - public LambdaProvider(Func, Image> creator) + public LambdaProvider(Func> factoryFunc) { - this.creator = creator; + this.factoryFunc = factoryFunc; } - public override Image GetImage() => this.creator(this.Factory); + public override Image GetImage() => this.factoryFunc(); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs index 0caded4201..32860d2a4d 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs @@ -1,16 +1,14 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; +using System; - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; - using Xunit.Abstractions; +using Xunit.Abstractions; +namespace SixLabors.ImageSharp.Tests +{ /// /// Provides instances for parametric unit tests. /// @@ -18,7 +16,7 @@ namespace ImageSharp.Tests public abstract partial class TestImageProvider where TPixel : struct, IPixel { - private class SolidProvider : BlankProvider + private class SolidProvider : BlankProvider { private byte a; @@ -55,9 +53,10 @@ public override Image GetImage() TPixel color = default(TPixel); color.PackFromRgba32(new Rgba32(this.r, this.g, this.b, this.a)); - return image.Fill(color); + image.Mutate(x => x.Fill(color)); + return image; } - + public override void Serialize(IXunitSerializationInfo info) { info.AddValue("red", this.r); diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs index 03a685d34f..91bbd32efe 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs @@ -1,16 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Reflection; +using System; +using System.Reflection; + +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; - using ImageSharp.PixelFormats; +using Xunit.Abstractions; - using Xunit.Abstractions; +namespace SixLabors.ImageSharp.Tests +{ public interface ITestImageProvider { PixelTypes PixelType { get; } @@ -32,7 +32,6 @@ public abstract partial class TestImageProvider : ITestImageProvider /// public ImagingTestCaseUtility Utility { get; private set; } - public GenericFactory Factory { get; private set; } = new GenericFactory(); public string TypeName { get; private set; } public string MethodName { get; private set; } @@ -59,10 +58,10 @@ public static TestImageProvider File( } public static TestImageProvider Lambda( - Func, Image> func, + Func> factoryFunc, MethodInfo testMethod = null, PixelTypes pixelTypeOverride = PixelTypes.Undefined) - => new LambdaProvider(func).Init(testMethod, pixelTypeOverride); + => new LambdaProvider(factoryFunc).Init(testMethod, pixelTypeOverride); public static TestImageProvider Solid( int width, @@ -82,6 +81,21 @@ public static TestImageProvider Solid( /// public abstract Image GetImage(); + public virtual Image GetImage(IImageDecoder decoder) + { + throw new NotSupportedException($"Decoder specific GetImage() is not supported with {this.GetType().Name}!"); + } + + /// + /// Returns an instance to the test case with the necessary traits. + /// + public Image GetImage(Action> operationsToApply) + { + var img = GetImage(); + img.Mutate(operationsToApply); + return img; + } + public virtual void Deserialize(IXunitSerializationInfo info) { PixelTypes pixelType = info.GetValue("PixelType"); @@ -106,12 +120,7 @@ protected TestImageProvider Init(string typeName, string methodName, Pix } this.TypeName = typeName; this.MethodName = methodName; - - if (pixelTypeOverride == PixelTypes.Rgba32) - { - this.Factory = new ImageFactory() as GenericFactory; - } - + this.Utility = new ImagingTestCaseUtility { SourceFileOrDescription = this.SourceFileOrDescription, diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs index 96d38fc401..6cee83566a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs @@ -1,18 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Collections.Generic; - using System.Numerics; +using System; +using System.Collections.Generic; +using System.Numerics; - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; - using Xunit.Abstractions; +using Xunit.Abstractions; +namespace SixLabors.ImageSharp.Tests +{ public abstract partial class TestImageProvider where TPixel : struct, IPixel { @@ -49,7 +47,7 @@ public override Image GetImage() } } - return new Image(testImages[this.SourceFileOrDescription]); + return testImages[this.SourceFileOrDescription].Clone(); } /// @@ -62,7 +60,7 @@ private static void DrawTestPattern(Image image) using (PixelAccessor pixels = image.Lock()) { BlackWhiteChecker(pixels); // top left - VirticalBars(pixels); // top right + VerticalBars(pixels); // top right TransparentGradients(pixels); // bottom left Rainbow(pixels); // bottom right } @@ -71,7 +69,7 @@ private static void DrawTestPattern(Image image) /// Fills the top right quadrant with alternating solid vertical bars. /// /// - private static void VirticalBars(PixelAccessor pixels) + private static void VerticalBars(PixelAccessor pixels) { // topLeft int left = pixels.Width / 2; @@ -80,9 +78,9 @@ private static void VirticalBars(PixelAccessor pixels) int bottom = pixels.Height / 2; int stride = pixels.Width / 12; TPixel[] c = { - NamedColors.HotPink, - NamedColors.Blue - }; + NamedColors.HotPink, + NamedColors.Blue + }; int p = 0; for (int y = top; y < bottom; y++) { @@ -111,9 +109,9 @@ private static void BlackWhiteChecker(PixelAccessor pixels) int bottom = pixels.Height / 2; int stride = pixels.Width / 6; TPixel[] c = { - NamedColors.Black, - NamedColors.White - }; + NamedColors.Black, + NamedColors.White + }; int p = 0; for (int y = top; y < bottom; y++) @@ -199,14 +197,14 @@ private static void Rainbow(PixelAccessor pixels) Rgba32 t = new Rgba32(0); for (int x = left; x < right; x++) - for (int y = top; y < bottom; y++) - { - t.PackedValue += stepsPerPixel; - Vector4 v = t.ToVector4(); - //v.W = (x - left) / (float)left; - c.PackFromVector4(v); - pixels[x, y] = c; - } + for (int y = top; y < bottom; y++) + { + t.PackedValue += stepsPerPixel; + Vector4 v = t.ToVector4(); + //v.W = (x - left) / (float)left; + c.PackFromVector4(v); + pixels[x, y] = c; + } } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs index 47085cf5f4..d0626c87e2 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs @@ -1,18 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.IO; - using System.Linq; - using System.Reflection; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; - using ImageSharp.Formats; - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Tests +{ /// /// Utility class to provide information about the test image & the test case for the test code, /// and help managing IO. @@ -39,13 +38,8 @@ public class ImagingTestCaseUtility : TestBase /// The name of the test case (by default) /// public string TestName { get; set; } = string.Empty; - - /// - /// Gets the recommended file name for the output of the test - /// - /// - /// The required extension - public string GetTestOutputFileName(string extension = null, string tag = null) + + private string GetTestOutputFileNameImpl(string extension, string details, bool appendPixelTypeToFileName) { string fn = string.Empty; @@ -65,6 +59,7 @@ public string GetTestOutputFileName(string extension = null, string tag = null) { extension = ".bmp"; } + extension = extension.ToLower(); if (extension[0] != '.') { @@ -73,22 +68,62 @@ public string GetTestOutputFileName(string extension = null, string tag = null) if (fn != string.Empty) fn = '_' + fn; - string pixName = this.PixelTypeName; - if (pixName != string.Empty) + string pixName = ""; + + if (appendPixelTypeToFileName) { - pixName = '_' + pixName; + pixName = this.PixelTypeName; + + if (pixName != string.Empty) + { + pixName = '_' + pixName; + } } - tag = tag ?? string.Empty; - if (tag != string.Empty) + details = details ?? string.Empty; + if (details != string.Empty) { - tag = '_' + tag; + details = '_' + details; } + return $"{this.GetTestOutputDir()}/{this.TestName}{pixName}{fn}{details}{extension}"; + } - return $"{this.GetTestOutputDir()}/{this.TestName}{pixName}{fn}{tag}{extension}"; + /// + /// Gets the recommended file name for the output of the test + /// + /// The required extension + /// The settings modifying the output path + /// A boolean indicating whether to append the pixel type to output file name. + /// The file test name + public string GetTestOutputFileName(string extension = null, object testOutputDetails = null, bool appendPixelTypeToFileName = true) + { + string detailsString = null; + string s = testOutputDetails as string; + + if (s != null) + { + detailsString = s; + } + else if (testOutputDetails != null) + { + Type type = testOutputDetails.GetType(); + TypeInfo info = type.GetTypeInfo(); + if (info.IsPrimitive || info.IsEnum || type == typeof(decimal)) + { + detailsString = testOutputDetails.ToString(); + } + else + { + IEnumerable properties = testOutputDetails.GetType().GetRuntimeProperties(); + + detailsString = String.Join("_", properties.ToDictionary(x => x.Name, x => x.GetValue(testOutputDetails)).Select(x => $"{x.Key}-{x.Value}")); + } + } + return this.GetTestOutputFileNameImpl(extension, detailsString, appendPixelTypeToFileName); } + /// /// Encodes image by the format matching the required extension, than saves it to the recommended output file. /// @@ -96,20 +131,33 @@ public string GetTestOutputFileName(string extension = null, string tag = null) /// The image instance /// The requested extension /// Optional encoder - /// Optional encoder options - public void SaveTestOutputFile(Image image, string extension = null, IImageEncoder encoder = null, string tag = null) + public void SaveTestOutputFile( + Image image, + string extension = null, + IImageEncoder encoder = null, + object testOutputDetails = null, + bool appendPixelTypeToFileName = true) where TPixel : struct, IPixel { - string path = this.GetTestOutputFileName(extension: extension, tag:tag); - extension = Path.GetExtension(path); - encoder = encoder ?? GetImageFormatByExtension(extension); - + string path = this.GetTestOutputFileName(extension, testOutputDetails, appendPixelTypeToFileName); + encoder = encoder ?? TestEnvironment.GetReferenceEncoder(path); + using (FileStream stream = File.OpenWrite(path)) { image.Save(stream, encoder); } } + internal string GetReferenceOutputFileName( + string extension, + object settings, + bool appendPixelTypeToFileName) + { + return TestEnvironment.GetReferenceOutputFileName( + this.GetTestOutputFileName(extension, settings, appendPixelTypeToFileName) + ); + } + internal void Init(string typeName, string methodName) { this.TestGroupName = typeName; @@ -121,17 +169,78 @@ internal void Init(MethodInfo method) this.Init(method.DeclaringType.Name, method.Name); } - private static IImageEncoder GetImageFormatByExtension(string extension) - { - extension = extension?.TrimStart('.'); - var format = Configuration.Default.FindFormatByFileExtensions(extension); - return Configuration.Default.FindEncoder(format); - } + //private static IImageEncoder GetEncoderByExtension(string extension, bool grayscale) + //{ + // extension = extension?.TrimStart('.'); + // var format = Configuration.Default.FindFormatByFileExtension(extension); + // IImageEncoder encoder = Configuration.Default.FindEncoder(format); + // PngEncoder pngEncoder = encoder as PngEncoder; + // if (pngEncoder != null) + // { + // pngEncoder = new PngEncoder(); + // encoder = pngEncoder; + // pngEncoder.CompressionLevel = 9; + + // if (grayscale) + // { + // pngEncoder.PngColorType = PngColorType.Grayscale; + // } + // } + + // return encoder; + //} private string GetTestOutputDir() { string testGroupName = Path.GetFileNameWithoutExtension(this.TestGroupName); - return CreateOutputDirectory(testGroupName); + return this.CreateOutputDirectory(testGroupName); + } + + public static void ModifyPixel(ImageBase img, int x, int y, byte perChannelChange) + where TPixel : struct, IPixel + { + TPixel pixel = img[x, y]; + var rgbaPixel = default(Rgba32); + pixel.ToRgba32(ref rgbaPixel); + + if (rgbaPixel.R + perChannelChange <= 255) + { + rgbaPixel.R += perChannelChange; + } + else + { + rgbaPixel.R -= perChannelChange; + } + + if (rgbaPixel.G + perChannelChange <= 255) + { + rgbaPixel.G += perChannelChange; + } + else + { + rgbaPixel.G -= perChannelChange; + } + + if (rgbaPixel.B + perChannelChange <= 255) + { + rgbaPixel.B += perChannelChange; + } + else + { + rgbaPixel.B -= perChannelChange; + } + + if (rgbaPixel.A + perChannelChange <= 255) + { + rgbaPixel.A += perChannelChange; + } + else + { + rgbaPixel.A -= perChannelChange; + } + + pixel.PackFromRgba32(rgbaPixel); + img[x, y] = pixel; } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/MeasureFixture.cs b/tests/ImageSharp.Tests/TestUtilities/MeasureFixture.cs index 1a6bf5d8b8..50974cef86 100644 --- a/tests/ImageSharp.Tests/TestUtilities/MeasureFixture.cs +++ b/tests/ImageSharp.Tests/TestUtilities/MeasureFixture.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Diagnostics; - using System.Runtime.CompilerServices; - - using Xunit.Abstractions; +using System; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using Xunit.Abstractions; +namespace SixLabors.ImageSharp.Tests +{ /// /// Utility class to measure the execution of an operation. It can be used either by inheritance or by composition. /// diff --git a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs index 645a4dc596..a8f7acb406 100644 --- a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs +++ b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs @@ -1,18 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; +using System; +namespace SixLabors.ImageSharp.Tests +{ /// /// Flags that are mapped to PackedPixel types. /// They trigger the desired parametrization for . /// [Flags] - public enum PixelTypes : uint + public enum PixelTypes { Undefined = 0, @@ -52,11 +50,11 @@ public enum PixelTypes : uint Short4 = 1 << 17, - Rgb24 = 18, + Rgb24 = 1 << 18, - Bgr24 = 19, + Bgr24 = 1 << 19, - Bgra32 = 20, + Bgra32 = 1 << 20, // TODO: Add multi-flag entries by rules defined in PackedPixelConverterHelper diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs new file mode 100644 index 0000000000..474569c4ce --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs @@ -0,0 +1,127 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Drawing.Imaging; + +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs +{ + public static class SystemDrawingBridge + { + // TODO: It would be nice to have this method in PixelOperations + private static void ToArgb32(Span source, Span dest) + where TPixel : struct, IPixel + { + int length = source.Length; + Guard.MustBeSizedAtLeast(dest, length, nameof(dest)); + + using (var rgbaBuffer = new Buffer(length)) + { + PixelOperations.Instance.ToRgba32(source, rgbaBuffer, length); + + for (int i = 0; i < length; i++) + { + ref Rgba32 s = ref rgbaBuffer[i]; + ref Argb32 d = ref dest[i]; + + d.PackFromRgba32(s); + } + } + } + + private static void FromArgb32(Span source, Span dest) + where TPixel : struct, IPixel + { + int length = source.Length; + Guard.MustBeSizedAtLeast(dest, length, nameof(dest)); + + using (var rgbaBuffer = new Buffer(length)) + { + PixelOperations.Instance.ToRgba32(source, rgbaBuffer, length); + + for (int i = 0; i < length; i++) + { + ref Rgba32 s = ref rgbaBuffer[i]; + ref TPixel d = ref dest[i]; + + d.PackFromRgba32(s); + } + } + } + + internal static unsafe Image FromSystemDrawingBitmap(System.Drawing.Bitmap bmp) + where TPixel : struct, IPixel + { + int w = bmp.Width; + int h = bmp.Height; + + var fullRect = new System.Drawing.Rectangle(0, 0, w, h); + + if (bmp.PixelFormat != PixelFormat.Format32bppArgb) + { + throw new ArgumentException("FromSystemDrawingBitmap(): pixel format not supported", nameof(bmp)); + } + + BitmapData data = bmp.LockBits(fullRect, ImageLockMode.ReadWrite, bmp.PixelFormat); + byte* sourcePtrBase = (byte*)data.Scan0; + + long sourceRowByteCount = data.Stride; + long destRowByteCount = w * sizeof(Argb32); + + var image = new Image(w, h); + + using (var workBuffer = new Buffer(w)) + { + var destPtr = (Argb32*)workBuffer.Pin(); + for (int y = 0; y < h; y++) + { + Span row = image.GetRowSpan(y); + + byte* sourcePtr = sourcePtrBase + data.Stride * y; + + Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount); + + FromArgb32(workBuffer, row); + } + } + + return image; + } + + internal static unsafe System.Drawing.Bitmap ToSystemDrawingBitmap(Image image) + where TPixel : struct, IPixel + { + int w = image.Width; + int h = image.Height; + + var resultBitmap = new System.Drawing.Bitmap(w, h, PixelFormat.Format32bppArgb); + var fullRect = new System.Drawing.Rectangle(0, 0, w, h); + BitmapData data = resultBitmap.LockBits(fullRect, ImageLockMode.ReadWrite, resultBitmap.PixelFormat); + byte* destPtrBase = (byte*)data.Scan0; + + long destRowByteCount = data.Stride; + long sourceRowByteCount = w * sizeof(Argb32); + + using (var workBuffer = new Buffer(w)) + { + var sourcePtr = (Argb32*)workBuffer.Pin(); + + for (int y = 0; y < h; y++) + { + Span row = image.GetRowSpan(y); + ToArgb32(row, workBuffer); + byte* destPtr = destPtrBase + data.Stride * y; + + Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount); + } + } + + resultBitmap.UnlockBits(data); + + return resultBitmap; + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs new file mode 100644 index 0000000000..789012ec4a --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs @@ -0,0 +1,47 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.IO; + +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs +{ + public class SystemDrawingReferenceDecoder : IImageDecoder + { + public static SystemDrawingReferenceDecoder Instance { get; } = new SystemDrawingReferenceDecoder(); + + public Image Decode(Configuration configuration, Stream stream) + where TPixel : struct, IPixel + { + using (var sourceBitmap = new System.Drawing.Bitmap(stream)) + { + if (sourceBitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb) + { + return SystemDrawingBridge.FromSystemDrawingBitmap(sourceBitmap); + } + + using (var convertedBitmap = new System.Drawing.Bitmap( + sourceBitmap.Width, + sourceBitmap.Height, + System.Drawing.Imaging.PixelFormat.Format32bppArgb)) + { + using (var g = Graphics.FromImage(convertedBitmap)) + { + g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; + g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; + g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; + g.PixelOffsetMode = PixelOffsetMode.HighQuality; + + g.DrawImage(sourceBitmap, 0, 0, sourceBitmap.Width, sourceBitmap.Height); + } + return SystemDrawingBridge.FromSystemDrawingBitmap(convertedBitmap); + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs new file mode 100644 index 0000000000..e1ef68fa62 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs @@ -0,0 +1,35 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Collections.Generic; +using System.Text; + +using System.Drawing.Imaging; +using System.IO; + +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs +{ + public class SystemDrawingReferenceEncoder : IImageEncoder + { + private readonly System.Drawing.Imaging.ImageFormat imageFormat; + + public SystemDrawingReferenceEncoder(ImageFormat imageFormat) + { + this.imageFormat = imageFormat; + } + + public static SystemDrawingReferenceEncoder Png { get; } = new SystemDrawingReferenceEncoder(System.Drawing.Imaging.ImageFormat.Png); + + public void Encode(Image image, Stream stream) + where TPixel : struct, IPixel + { + using (System.Drawing.Bitmap sdBitmap = SystemDrawingBridge.ToSystemDrawingBitmap(image)) + { + sdBitmap.Save(stream, this.imageFormat); + } + } + } +} diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs new file mode 100644 index 0000000000..f72e2d3a46 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs @@ -0,0 +1,133 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.IO; +using System.Linq; +using System.Reflection; + +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; + +namespace SixLabors.ImageSharp.Tests +{ + public static class TestEnvironment + { + private const string ImageSharpSolutionFileName = "ImageSharp.sln"; + + private const string InputImagesRelativePath = @"tests\Images\Input"; + + private const string ActualOutputDirectoryRelativePath = @"tests\Images\ActualOutput"; + + private const string ReferenceOutputDirectoryRelativePath = @"tests\Images\External\ReferenceOutput"; + + private static Lazy solutionDirectoryFullPath = new Lazy(GetSolutionDirectoryFullPathImpl); + + private static Lazy runsOnCi = new Lazy( + () => + { + bool isCi; + return bool.TryParse(Environment.GetEnvironmentVariable("CI"), out isCi) && isCi; + }); + + private static Lazy configuration = new Lazy(CreateDefaultConfiguration); + + // ReSharper disable once InconsistentNaming + /// + /// Gets a value indicating whether test execution runs on CI. + /// + internal static bool RunsOnCI => runsOnCi.Value; + + internal static string SolutionDirectoryFullPath => solutionDirectoryFullPath.Value; + + internal static Configuration Configuration => configuration.Value; + + private static Configuration CreateDefaultConfiguration() + { + var configuration = new Configuration( + new PngConfigurationModule(), + new JpegConfigurationModule(), + new GifConfigurationModule(), + new BmpConfigurationModule() + ); + + configuration.SetDecoder(ImageFormats.Png, SystemDrawingReferenceDecoder.Instance); + configuration.SetEncoder(ImageFormats.Png, SystemDrawingReferenceEncoder.Png); + configuration.AddImageFormatDetector(new PngImageFormatDetector()); + + return configuration; + } + + private static string GetSolutionDirectoryFullPathImpl() + { + string assemblyLocation = typeof(TestFile).GetTypeInfo().Assembly.Location; + + var assemblyFile = new FileInfo(assemblyLocation); + + DirectoryInfo directory = assemblyFile.Directory; + + while (!directory.EnumerateFiles(ImageSharpSolutionFileName).Any()) + { + try + { + directory = directory.Parent; + } + catch (Exception ex) + { + throw new Exception( + $"Unable to find ImageSharp solution directory from {assemblyLocation} because of {ex.GetType().Name}!", + ex); + } + if (directory == null) + { + throw new Exception($"Unable to find ImageSharp solution directory from {assemblyLocation}!"); + } + } + + return directory.FullName; + } + + /// + /// Gets the correct full path to the Input Images directory. + /// + internal static string InputImagesDirectoryFullPath => + Path.Combine(SolutionDirectoryFullPath, InputImagesRelativePath); + + /// + /// Gets the correct full path to the Actual Output directory. (To be written to by the test cases.) + /// + internal static string ActualOutputDirectoryFullPath => Path.Combine( + SolutionDirectoryFullPath, + ActualOutputDirectoryRelativePath); + + /// + /// Gets the correct full path to the Expected Output directory. (To compare the test results to.) + /// + internal static string ReferenceOutputDirectoryFullPath => Path.Combine( + SolutionDirectoryFullPath, + ReferenceOutputDirectoryRelativePath); + + internal static string GetReferenceOutputFileName(string actualOutputFileName) => + actualOutputFileName.Replace("ActualOutput", @"External\ReferenceOutput"); + + internal static IImageDecoder GetReferenceDecoder(string filePath) + { + IImageFormat format = GetImageFormat(filePath); + return Configuration.FindDecoder(format); + } + + internal static IImageEncoder GetReferenceEncoder(string filePath) + { + IImageFormat format = GetImageFormat(filePath); + return Configuration.FindEncoder(format); + } + + internal static IImageFormat GetImageFormat(string filePath) + { + string extension = Path.GetExtension(filePath).ToLower(); + if (extension[0] == '.') extension = extension.Substring(1); + IImageFormat format = Configuration.FindFormatByFileExtension(extension); + return format; + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index bb97daaa47..42ee89f744 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -1,17 +1,18 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reflection; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; - using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; +using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; +namespace SixLabors.ImageSharp.Tests +{ public static class TestImageExtensions { /// @@ -20,42 +21,169 @@ public static class TestImageExtensions /// The pixel format /// The image /// The image provider - /// The settings + /// Details to be concatenated to the test output file, describing the parameters of the test. /// The extension - public static Image DebugSave(this Image image, ITestImageProvider provider, object settings = null, string extension = "png") + /// A boolean indicating whether we should save a smaller in size. + /// A boolean indicating whether to append the pixel type to the output file name. + public static Image DebugSave( + this Image image, + ITestImageProvider provider, + object testOutputDetails = null, + string extension = "png", + bool appendPixelTypeToFileName = true) where TPixel : struct, IPixel { - if (bool.TryParse(Environment.GetEnvironmentVariable("CI"), out bool isCi) && isCi) + if (TestEnvironment.RunsOnCI) { return image; } // We are running locally then we want to save it out - string tag = null; - string s = settings as string; + provider.Utility.SaveTestOutputFile( + image, + extension, + testOutputDetails: testOutputDetails, + appendPixelTypeToFileName: appendPixelTypeToFileName); + return image; + } + + /// + /// Compares the image against the expected Reference output, throws an exception if the images are not similar enough. + /// The output file should be named identically to the output produced by . + /// + /// The pixel format + /// The image + /// The image provider + /// Details to be concatenated to the test output file, describing the parameters of the test. + /// The extension + /// A boolean indicating whether we should debug save + compare against a grayscale image, smaller in size. + /// A boolean indicating whether to append the pixel type to the output file name. + /// + public static Image CompareToReferenceOutput( + this Image image, + ITestImageProvider provider, + object testOutputDetails = null, + string extension = "png", + bool grayscale = false, + bool appendPixelTypeToFileName = true) + where TPixel : struct, IPixel + { + return CompareToReferenceOutput( + image, + provider, + ImageComparer.Tolerant(), + testOutputDetails, + extension, + grayscale, + appendPixelTypeToFileName); + } + + /// + /// Compares the image against the expected Reference output, throws an exception if the images are not similar enough. + /// The output file should be named identically to the output produced by . + /// + /// The pixel format + /// The image + /// The image provider + /// The to use + /// Details to be concatenated to the test output file, describing the parameters of the test. + /// The extension + /// A boolean indicating whether we should debug save + compare against a grayscale image, smaller in size. + /// A boolean indicating whether to append the pixel type to the output file name. + /// + public static Image CompareToReferenceOutput( + this Image image, + ITestImageProvider provider, + ImageComparer comparer, + object testOutputDetails = null, + string extension = "png", + bool grayscale = false, + bool appendPixelTypeToFileName = true) + where TPixel : struct, IPixel + { + using (Image referenceImage = GetReferenceOutputImage( + provider, + testOutputDetails, + extension, + appendPixelTypeToFileName)) + { + comparer.VerifySimilarity(referenceImage, image); + } + + return image; + } + + public static Image GetReferenceOutputImage(this ITestImageProvider provider, + object testOutputDetails = null, + string extension = "png", + bool appendPixelTypeToFileName = true) + where TPixel : struct, IPixel + { + string referenceOutputFile = provider.Utility.GetReferenceOutputFileName(extension, testOutputDetails, appendPixelTypeToFileName); + + if (!File.Exists(referenceOutputFile)) + { + throw new Exception("Reference output file missing: " + referenceOutputFile); + } - if (s != null) + return Image.Load(referenceOutputFile); + } + + public static IEnumerable GetReferenceOutputSimilarityReports( + this Image image, + ITestImageProvider provider, + ImageComparer comparer, + object testOutputDetails = null, + string extension = "png", + bool appendPixelTypeToFileName = true) + where TPixel : struct, IPixel + { + using (Image referenceImage = provider.GetReferenceOutputImage( + testOutputDetails, + extension, + appendPixelTypeToFileName)) { - tag = s; + return comparer.CompareImages(referenceImage, image); } - else if (settings != null) + } + + public static Image CompareToOriginal( + this Image image, + ITestImageProvider provider) + where TPixel : struct, IPixel + { + return CompareToOriginal(image, provider, ImageComparer.Tolerant()); + } + + public static Image CompareToOriginal( + this Image image, + ITestImageProvider provider, + ImageComparer comparer) + where TPixel : struct, IPixel + { + string path = TestImageProvider.GetFilePathOrNull(provider); + if (path == null) + { + throw new InvalidOperationException("CompareToOriginal() works only with file providers!"); + } + + var testFile = TestFile.Create(path); + + IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(path); + IImageFormat format = TestEnvironment.GetImageFormat(path); + IImageDecoder defaultDecoder = Configuration.Default.FindDecoder(format); + + if (referenceDecoder.GetType() == defaultDecoder.GetType()) + { + throw new InvalidOperationException($"Can't use CompareToOriginal(): no actual reference decoder registered for {format.Name}"); + } + + using (var original = Image.Load(testFile.Bytes, referenceDecoder)) { - Type type = settings.GetType(); - TypeInfo info = type.GetTypeInfo(); - if (info.IsPrimitive || info.IsEnum || type == typeof(decimal)) - { - tag = settings.ToString(); - } - else - { - IEnumerable properties = settings.GetType().GetRuntimeProperties(); - - tag = string.Join("_", properties.ToDictionary(x => x.Name, x => x.GetValue(settings)).Select(x => $"{x.Key}-{x.Value}")); - } + comparer.VerifySimilarity(original, image); } - provider.Utility.SaveTestOutputFile(image, extension, tag: tag); return image; } } -} +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/TestPixel.cs b/tests/ImageSharp.Tests/TestUtilities/TestPixel.cs index 852bc587d0..1eb0aafff0 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestPixel.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestPixel.cs @@ -1,10 +1,13 @@ -using System; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; using System.Collections.Generic; using System.Text; -using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; using Xunit.Abstractions; -namespace ImageSharp.Tests.TestUtilities +namespace SixLabors.ImageSharp.Tests.TestUtilities { public class TestPixel : IXunitSerializable where TPixel : struct, IPixel diff --git a/tests/ImageSharp.Tests/TestUtilities/TestType.cs b/tests/ImageSharp.Tests/TestUtilities/TestType.cs new file mode 100644 index 0000000000..788a0543ab --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/TestType.cs @@ -0,0 +1,31 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.Text; +using SixLabors.ImageSharp.PixelFormats; +using Xunit.Abstractions; + +namespace SixLabors.ImageSharp.Tests.TestUtilities +{ + public class TestType : IXunitSerializable + { + public TestType() + { + } + + public void Deserialize(IXunitSerializationInfo info) + { + } + + public void Serialize(IXunitSerializationInfo info) + { + } + + public override string ToString() + { + return $"Type<{typeof(T).Name}>"; + } + } +} diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs similarity index 83% rename from tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs rename to tests/ImageSharp.Tests/TestUtilities/TestUtils.cs index e42cbe1934..83997841a6 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs @@ -1,22 +1,19 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Collections.Generic; - using System.Globalization; - using System.Linq; - using System.Reflection; - - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Reflection; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Tests +{ /// - /// Extension methods for TestUtilities + /// Various utility and extension methods. /// - public static class TestUtilityExtensions + public static class TestUtils { private static readonly Dictionary ClrTypes2PixelTypes = new Dictionary(); @@ -28,7 +25,7 @@ public static class TestUtilityExtensions .Except(new[] { PixelTypes.Undefined, PixelTypes.All }) .ToArray(); - static TestUtilityExtensions() + static TestUtils() { // Add Rgba32 Our default. Type defaultPixelFormatType = typeof(Rgba32); @@ -103,7 +100,7 @@ public static string ToCsv(this IEnumerable items, string separator = ",") return string.Join(separator, items.Select(o => string.Format(CultureInfo.InvariantCulture, "{0}", o))); } - public static Type ToType(this PixelTypes pixelType) => PixelTypes2ClrTypes[pixelType]; + public static Type GetClrType(this PixelTypes pixelType) => PixelTypes2ClrTypes[pixelType]; /// /// Returns the enumerations for the given type. @@ -112,6 +109,8 @@ public static string ToCsv(this IEnumerable items, string separator = ",") /// public static PixelTypes GetPixelType(this Type colorStructClrType) => ClrTypes2PixelTypes[colorStructClrType]; + + public static IEnumerable> ExpandAllTypes(this PixelTypes pixelTypes) { if (pixelTypes == PixelTypes.Undefined) @@ -124,11 +123,20 @@ public static IEnumerable> ExpandAllTypes(this Pi return PixelTypes2ClrTypes; } - return AllConcretePixelTypes - .Where(pt => pixelTypes.HasFlag(pt)) - .Select(pt => new KeyValuePair(pt, pt.ToType())); + var result = new Dictionary(); + foreach (PixelTypes pt in AllConcretePixelTypes) + { + if (pixelTypes.HasAll(pt)) + { + result[pt] = pt.GetClrType(); + } + } + return result; } + internal static bool HasAll(this PixelTypes pixelTypes, PixelTypes flagsToCheck) => + (pixelTypes & flagsToCheck) == flagsToCheck; + /// /// Enumerate all available -s /// diff --git a/tests/ImageSharp.Tests/TestUtilities/TestVector4.cs b/tests/ImageSharp.Tests/TestUtilities/TestVector4.cs index beb3fcd970..3916f189cc 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestVector4.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestVector4.cs @@ -1,11 +1,14 @@ -using System; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; using System.Collections.Generic; using System.Numerics; using System.Text; -using ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; using Xunit.Abstractions; -namespace ImageSharp.Tests.TestUtilities +namespace SixLabors.ImageSharp.Tests.TestUtilities { public class TestVector4 : IXunitSerializable { diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs new file mode 100644 index 0000000000..0329b88f97 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs @@ -0,0 +1,184 @@ +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Tests +{ + using System.Collections.Generic; + using System.Linq; + + using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + + using Moq; + + using SixLabors.Primitives; + + using Xunit; + using Xunit.Abstractions; + + public class ImageComparerTests + { + public ImageComparerTests(ITestOutputHelper output) + { + this.Output = output; + } + + private ITestOutputHelper Output { get; } + + [Theory] + [WithTestPatternImages(100,100,PixelTypes.Rgba32, 0.0001f, 1)] + [WithTestPatternImages(100, 100, PixelTypes.Rgba32, 0, 0)] + public void TolerantImageComparer_ApprovesPerfectSimilarity( + TestImageProvider provider, + float imageTheshold, + int pixelThreshold) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + using (Image clone = image.Clone()) + { + var comparer = ImageComparer.Tolerant(imageTheshold, pixelThreshold); + comparer.VerifySimilarity(image, clone); + } + } + } + + [Theory] + [WithTestPatternImages(110, 110, PixelTypes.Rgba32)] + public void TolerantImageComparer_ApprovesSimilarityBelowTolerance(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + using (Image clone = image.Clone()) + { + ImagingTestCaseUtility.ModifyPixel(clone, 0, 0, 1); + + var comparer = ImageComparer.Tolerant(); + comparer.VerifySimilarity(image, clone); + } + } + } + + [Theory] + [WithTestPatternImages(100, 100, PixelTypes.Rgba32)] + public void TolerantImageComparer_DoesNotApproveSimilarityAboveTolerance(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + using (Image clone = image.Clone()) + { + ImagingTestCaseUtility.ModifyPixel(clone, 3, 1, 2); + + var comparer = ImageComparer.Tolerant(); + + ImagePixelsAreDifferentException ex = Assert.ThrowsAny( + () => + { + comparer.VerifySimilarity(image, clone); + }); + PixelDifference diff = ex.Reports.Single().Differences.Single(); + Assert.Equal(new Point(3, 1), diff.Position); + } + } + } + + [Theory] + [WithTestPatternImages(100, 100, PixelTypes.Rgba32)] + public void TolerantImageComparer_TestPerPixelThreshold(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + using (Image clone = image.Clone()) + { + ImagingTestCaseUtility.ModifyPixel(clone, 0, 0, 10); + ImagingTestCaseUtility.ModifyPixel(clone, 1, 0, 10); + ImagingTestCaseUtility.ModifyPixel(clone, 2, 0, 10); + + var comparer = ImageComparer.Tolerant(pixelThresholdInPixelByteSum: 42); + comparer.VerifySimilarity(image, clone); + } + } + } + + [Theory] + [WithTestPatternImages(100, 100, PixelTypes.Rgba32, 99, 100)] + [WithTestPatternImages(100, 100, PixelTypes.Rgba32, 100, 99)] + public void VerifySimilarity_ThrowsOnSizeMismatch(TestImageProvider provider, int w, int h) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + using (Image clone = image.Clone(ctx => ctx.Resize(w, h))) + { + ImageDimensionsMismatchException ex = Assert.ThrowsAny( + () => + { + ImageComparer comparer = Mock.Of(); + comparer.VerifySimilarity(image, clone); + }); + this.Output.WriteLine(ex.Message); + } + } + } + + + [Theory] + [WithFile(TestImages.Gif.Giphy, PixelTypes.Rgba32)] + public void VerifySimilarity_WhenAnImageFrameIsDifferent_Reports(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + using (Image clone = image.Clone()) + { + ImagingTestCaseUtility.ModifyPixel(clone.Frames[0], 42, 43, 1); + + IEnumerable reports = ImageComparer.Exact.CompareImages(image, clone); + + PixelDifference difference = reports.Single().Differences.Single(); + Assert.Equal(new Point(42, 43), difference.Position); + } + } + } + + + [Theory] + [WithTestPatternImages(100, 100, PixelTypes.Rgba32)] + public void ExactComparer_ApprovesExactEquality(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + using (Image clone = image.Clone()) + { + ExactImageComparer.Instance.CompareImages(image, clone); + } + } + } + + [Theory] + [WithTestPatternImages(100, 100, PixelTypes.Rgba32)] + public void ExactComparer_DoesNotTolerateAnyPixelDifference(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + using (Image clone = image.Clone()) + { + ImagingTestCaseUtility.ModifyPixel(clone, 42, 24, 1); + ImagingTestCaseUtility.ModifyPixel(clone, 7, 93, 1); + + IEnumerable reports = ExactImageComparer.Instance.CompareImages(image, clone); + + this.Output.WriteLine(reports.Single().ToString()); + PixelDifference[] differences = reports.Single().Differences; + Assert.Equal(2, differences.Length); + Assert.Contains(differences, d => d.Position == new Point(42, 24)); + Assert.Contains(differences, d => d.Position == new Point(7, 93)); + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs new file mode 100644 index 0000000000..8b7a828b6c --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs @@ -0,0 +1,72 @@ +namespace SixLabors.ImageSharp.Tests +{ + using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; + + using Xunit; + using Xunit.Abstractions; + + public class ReferenceCodecTests + { + private ITestOutputHelper Output { get; } + + public ReferenceCodecTests(ITestOutputHelper output) + { + this.Output = output; + } + + [Theory] + [WithTestPatternImages(20, 20, PixelTypes.Rgba32 | PixelTypes.Bgra32)] + public void ToSystemDrawingBitmap(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + using (System.Drawing.Bitmap sdBitmap = SystemDrawingBridge.ToSystemDrawingBitmap(image)) + { + string fileName = provider.Utility.GetTestOutputFileName("png"); + sdBitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); + } + } + } + + [Theory] + [WithBlankImages(1, 1, PixelTypes.Rgba32 | PixelTypes.Bgra32)] + public void FromSystemDrawingBitmap(TestImageProvider dummyProvider) + where TPixel : struct, IPixel + { + string path = TestFile.GetInputFileFullPath(TestImages.Png.Splash); + + using (var sdBitmap = new System.Drawing.Bitmap(path)) + { + using (Image image = SystemDrawingBridge.FromSystemDrawingBitmap(sdBitmap)) + { + image.DebugSave(dummyProvider); + } + } + } + + [Theory] + [WithBlankImages(1, 1, PixelTypes.Rgba32 | PixelTypes.Bgra32)] + public void OpenWithReferenceDecoder(TestImageProvider dummyProvider) + where TPixel : struct, IPixel + { + string path = TestFile.GetInputFileFullPath(TestImages.Png.Splash); + using (Image image = Image.Load(path, SystemDrawingReferenceDecoder.Instance)) + { + image.DebugSave(dummyProvider); + } + } + + [Theory] + [WithTestPatternImages(20, 20, PixelTypes.Rgba32 | PixelTypes.Argb32)] + public void SaveWithReferenceEncoder(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + provider.Utility.SaveTestOutputFile(image, "png", SystemDrawingReferenceEncoder.Png); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs new file mode 100644 index 0000000000..a6becdbd63 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs @@ -0,0 +1,84 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.IO; + +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; +using Xunit; +using Xunit.Abstractions; + +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Tests +{ + public class TestEnvironmentTests + { + public TestEnvironmentTests(ITestOutputHelper output) + { + this.Output = output; + } + + private ITestOutputHelper Output { get; } + + private void CheckPath(string path) + { + this.Output.WriteLine(path); + Assert.True(Directory.Exists(path)); + } + + [Fact] + public void SolutionDirectoryFullPath() + { + this.CheckPath(TestEnvironment.SolutionDirectoryFullPath); + } + + [Fact] + public void InputImagesDirectoryFullPath() + { + this.CheckPath(TestEnvironment.InputImagesDirectoryFullPath); + } + + [Fact] + public void ActualOutputDirectoryFullPath() + { + this.CheckPath(TestEnvironment.ActualOutputDirectoryFullPath); + } + + [Fact] + public void ExpectedOutputDirectoryFullPath() + { + this.CheckPath(TestEnvironment.ReferenceOutputDirectoryFullPath); + } + + [Fact] + public void GetReferenceOutputFileName() + { + string actual = Path.Combine(TestEnvironment.ActualOutputDirectoryFullPath, @"foo\bar\lol.jpeg"); + string expected = TestEnvironment.GetReferenceOutputFileName(actual); + + this.Output.WriteLine(expected); + Assert.Contains(TestEnvironment.ReferenceOutputDirectoryFullPath, expected); + } + + [Theory] + [InlineData("lol/foo.png", typeof(SystemDrawingReferenceEncoder))] + [InlineData("lol/Baz.JPG", typeof(JpegEncoder))] + [InlineData("lol/Baz.gif", typeof(GifEncoder))] + public void GetReferenceEncoder_ReturnsCorrectEncoders(string fileName, Type expectedEncoderType) + { + IImageEncoder encoder = TestEnvironment.GetReferenceEncoder(fileName); + Assert.IsType(expectedEncoderType, encoder); + } + + [Theory] + [InlineData("lol/foo.png", typeof(SystemDrawingReferenceDecoder))] + [InlineData("lol/Baz.JPG", typeof(JpegDecoder))] + [InlineData("lol/Baz.gif", typeof(GifDecoder))] + public void GetReferenceDecoder_ReturnsCorrectEncoders(string fileName, Type expectedDecoderType) + { + IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(fileName); + Assert.IsType(expectedDecoderType, decoder); + } + } +} diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageExtensionsTests.cs new file mode 100644 index 0000000000..34300c56e3 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageExtensionsTests.cs @@ -0,0 +1,109 @@ +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Tests +{ + using System; + + using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + + using Moq; + + using Xunit; + + public class TestImageExtensionsTests + { + [Theory] + [WithSolidFilledImages(10, 10, 0, 0, 255, PixelTypes.Rgba32)] + public void CompareToReferenceOutput_WhenReferenceOutputMatches_ShouldNotThrow( + TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.CompareToReferenceOutput(provider); + } + } + + [Theory] + [WithSolidFilledImages(10, 10, 0, 0, 255, PixelTypes.Rgba32)] + public void CompareToReferenceOutput_WhenReferenceOutputDoesNotMatch_Throws( + TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + Assert.ThrowsAny(() => image.CompareToReferenceOutput(provider)); + } + } + + [Theory] + [WithSolidFilledImages(10, 10, 0, 0, 255, PixelTypes.Rgba32)] + public void CompareToReferenceOutput_DoNotAppendPixelType( + TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.DebugSave(provider, appendPixelTypeToFileName: false); + image.CompareToReferenceOutput(provider, appendPixelTypeToFileName: false); + } + } + + [Theory] + [WithSolidFilledImages(10, 10, 0, 0, 255, PixelTypes.Rgba32)] + public void CompareToReferenceOutput_WhenReferenceFileMissing_Throws(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + Assert.ThrowsAny(() => image.CompareToReferenceOutput(provider)); + } + } + + [Theory] + [WithFile(TestImages.Png.CalliphoraPartial, PixelTypes.Rgba32)] + public void CompareToOriginal_WhenSimilar(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + using (Image clone = image.Clone()) + { + clone.CompareToOriginal(provider, ImageComparer.Exact); + } + } + } + + [Theory] + [WithFile(TestImages.Png.CalliphoraPartial, PixelTypes.Rgba32)] + public void CompareToOriginal_WhenDifferent_Throws(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + ImagingTestCaseUtility.ModifyPixel(image, 3, 1, 1); + + Assert.ThrowsAny( + () => + { + image.CompareToOriginal(provider, ImageComparer.Exact); + }); + } + } + + [Theory] + [WithBlankImages(10, 10, PixelTypes.Rgba32)] + public void CompareToOriginal_WhenInputIsNotFromFile_Throws(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + Assert.ThrowsAny( + () => + { + image.CompareToOriginal(provider, Mock.Of()); + }); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs index c01babb632..88d7fa2b86 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs @@ -1,17 +1,18 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; +using System; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +using Xunit.Abstractions; - using ImageSharp.PixelFormats; +using System.Collections.Concurrent; +using System.IO; - using Xunit; - using Xunit.Abstractions; +using SixLabors.ImageSharp.Formats; +namespace SixLabors.ImageSharp.Tests +{ public class TestImageProviderTests { public TestImageProviderTests(ITestOutputHelper output) @@ -50,25 +51,13 @@ public void Use_WithBlankImagesAttribute_WithAllPixelTypes( [Theory] [WithBlankImages(1, 1, PixelTypes.Rgba32, PixelTypes.Rgba32)] [WithBlankImages(1, 1, PixelTypes.Alpha8, PixelTypes.Alpha8)] - [WithBlankImages(1, 1, PixelTypes.Rgba32, PixelTypes.Rgba32)] + [WithBlankImages(1, 1, PixelTypes.Argb32, PixelTypes.Argb32)] public void PixelType_PropertyValueIsCorrect(TestImageProvider provider, PixelTypes expected) where TPixel : struct, IPixel { Assert.Equal(expected, provider.PixelType); } - - [Theory] - [WithBlankImages(1, 1, PixelTypes.Rgba32)] - [WithFile(TestImages.Bmp.F, PixelTypes.Rgba32)] - public void PixelTypes_ColorWithDefaultImageClass_TriggersCreatingTheNonGenericDerivedImageClass( - TestImageProvider provider) - where TPixel : struct, IPixel - { - Image img = provider.GetImage(); - - Assert.IsType>(img); - } - + [Theory] [WithFile(TestImages.Bmp.Car, PixelTypes.All, 88)] [WithFile(TestImages.Bmp.F, PixelTypes.All, 88)] @@ -85,6 +74,155 @@ public void Use_WithFileAttribute(TestImageProvider provider, in this.Output.WriteLine(fn); } + private class TestDecoder : IImageDecoder + { + public Image Decode(Configuration configuration, Stream stream) + where TPixel : struct, IPixel + { + invocationCounts[this.callerName]++; + return new Image(42, 42); + } + + // Couldn't make xUnit happy without this hackery: + + private static ConcurrentDictionary invocationCounts = new ConcurrentDictionary(); + + private string callerName = null; + + internal void InitCaller(string name) + { + this.callerName = name; + invocationCounts[name] = 0; + } + + internal static int GetInvocationCount(string callerName) => invocationCounts[callerName]; + + private static readonly object Monitor = new object(); + + public static void DoTestThreadSafe(Action action) + { + lock (Monitor) + { + action(); + } + } + } + + + [Theory] + [WithFile(TestImages.Bmp.F, PixelTypes.Rgba32)] + public void GetImage_WithCustomParameterlessDecoder_ShouldUtilizeCache(TestImageProvider provider) + where TPixel : struct, IPixel + { + Assert.NotNull(provider.Utility.SourceFileOrDescription); + + TestDecoder.DoTestThreadSafe( + () => + { + string testName = nameof(this.GetImage_WithCustomParameterlessDecoder_ShouldUtilizeCache); + + var decoder = new TestDecoder(); + decoder.InitCaller(testName); + + provider.GetImage(decoder); + Assert.Equal(1, TestDecoder.GetInvocationCount(testName)); + + provider.GetImage(decoder); + Assert.Equal(1, TestDecoder.GetInvocationCount(testName)); + }); + } + + private class TestDecoderWithParameters : IImageDecoder + { + public string Param1 { get; set; } + + public int Param2 { get; set; } + + public Image Decode(Configuration configuration, Stream stream) + where TPixel : struct, IPixel + { + invocationCounts[this.callerName]++; + return new Image(42, 42); + } + + private static ConcurrentDictionary invocationCounts = new ConcurrentDictionary(); + + private string callerName = null; + + internal void InitCaller(string name) + { + this.callerName = name; + invocationCounts[name] = 0; + } + + internal static int GetInvocationCount(string callerName) => invocationCounts[callerName]; + + private static readonly object Monitor = new object(); + + public static void DoTestThreadSafe(Action action) + { + lock (Monitor) + { + action(); + } + } + } + + [Theory] + [WithFile(TestImages.Bmp.F, PixelTypes.Rgba32)] + public void GetImage_WithCustomParametricDecoder_ShouldUtilizeCache_WhenParametersAreEqual(TestImageProvider provider) + where TPixel : struct, IPixel + { + Assert.NotNull(provider.Utility.SourceFileOrDescription); + + TestDecoderWithParameters.DoTestThreadSafe( + () => + { + string testName = + nameof(this.GetImage_WithCustomParametricDecoder_ShouldUtilizeCache_WhenParametersAreEqual); + + var decoder1 = new TestDecoderWithParameters() { Param1 = "Lol", Param2 = 666 }; + decoder1.InitCaller(testName); + + var decoder2 = new TestDecoderWithParameters() { Param1 = "Lol", Param2 = 666 }; + decoder2.InitCaller(testName); + + provider.GetImage(decoder1); + Assert.Equal(1, TestDecoderWithParameters.GetInvocationCount(testName)); + + provider.GetImage(decoder2); + Assert.Equal(1, TestDecoderWithParameters.GetInvocationCount(testName)); + }); + } + + [Theory] + [WithFile(TestImages.Bmp.F, PixelTypes.Rgba32)] + public void GetImage_WithCustomParametricDecoder_ShouldNotUtilizeCache_WhenParametersAreNotEqual(TestImageProvider provider) + where TPixel : struct, IPixel + { + Assert.NotNull(provider.Utility.SourceFileOrDescription); + + TestDecoderWithParameters.DoTestThreadSafe( + () => + { + string testName = + nameof(this.GetImage_WithCustomParametricDecoder_ShouldNotUtilizeCache_WhenParametersAreNotEqual); + + var decoder1 = new TestDecoderWithParameters() { Param1 = "Lol", Param2 = 42 }; + decoder1.InitCaller(testName); + + var decoder2 = new TestDecoderWithParameters() { Param1 = "LoL", Param2 = 42 }; + decoder2.InitCaller(testName); + + provider.GetImage(decoder1); + Assert.Equal(1, TestDecoderWithParameters.GetInvocationCount(testName)); + + provider.GetImage(decoder2); + Assert.Equal(2, TestDecoderWithParameters.GetInvocationCount(testName)); + }); + } + + public static string[] AllBmpFiles => TestImages.Bmp.All; [Theory] @@ -96,7 +234,7 @@ public void Use_WithFileCollection(TestImageProvider provider) Image image = provider.GetImage(); provider.Utility.SaveTestOutputFile(image, "png"); } - + [Theory] [WithSolidFilledImages(10, 20, 255, 100, 50, 200, PixelTypes.Rgba32 | PixelTypes.Argb32)] public void Use_WithSolidFilledImagesAttribute(TestImageProvider provider) @@ -131,10 +269,10 @@ public void Use_WithSolidFilledImagesAttribute(TestImageProvider /// /// /// - public static Image CreateTestImage(GenericFactory factory) + public static Image CreateTestImage() where TPixel : struct, IPixel { - return factory.CreateImage(3, 3); + return new Image(3, 3); } [Theory] @@ -152,12 +290,12 @@ public void Use_WithMemberFactoryAttribute(TestImageProvider pro } public static readonly TheoryData BasicData = new TheoryData() - { - TestImageProvider.Blank(10, 20), - TestImageProvider.Blank( - 10, - 20), - }; + { + TestImageProvider.Blank(10, 20), + TestImageProvider.Blank( + 10, + 20), + }; [Theory] [MemberData(nameof(BasicData))] @@ -170,12 +308,10 @@ public void Blank_MemberData(TestImageProvider provider) } public static readonly TheoryData FileData = new TheoryData() - { - TestImageProvider.File( - TestImages.Bmp.Car), - TestImageProvider.File( - TestImages.Bmp.F) - }; + { + TestImageProvider.File(TestImages.Bmp.Car), + TestImageProvider.File(TestImages.Bmp.F) + }; [Theory] [MemberData(nameof(FileData))] @@ -190,4 +326,4 @@ public void File_MemberData(TestImageProvider provider) Assert.True(img.Width * img.Height > 0); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index 437c295b9c..fe5af24d26 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -1,21 +1,17 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Tests -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Numerics; - using System.Reflection; - - using ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; - using Xunit; - using Xunit.Abstractions; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +using Xunit.Abstractions; +namespace SixLabors.ImageSharp.Tests +{ public class TestUtilityExtensionsTests { public TestUtilityExtensionsTests(ITestOutputHelper output) @@ -25,10 +21,10 @@ public TestUtilityExtensionsTests(ITestOutputHelper output) private ITestOutputHelper Output { get; } - public static Image CreateTestImage(GenericFactory factory) + public static Image CreateTestImage() where TPixel : struct, IPixel { - Image image = factory.CreateImage(10, 10); + var image = new Image(10, 10); using (PixelAccessor pixels = image.Lock()) { @@ -36,10 +32,10 @@ public static Image CreateTestImage(GenericFactory facto { for (int j = 0; j < 10; j++) { - Vector4 v = new Vector4(i, j, 0, 1); + var v = new Vector4(i, j, 0, 1); v /= 10; - TPixel color = default(TPixel); + var color = default(TPixel); color.PackFromVector4(v); pixels[i, j] = color; @@ -50,16 +46,6 @@ public static Image CreateTestImage(GenericFactory facto return image; } - [Fact] - public void Baz() - { - Type type = typeof(Rgba32).GetTypeInfo().Assembly.GetType("ImageSharp.Rgba32"); - this.Output.WriteLine(type.ToString()); - - Type fake = typeof(Rgba32).GetTypeInfo().Assembly.GetType("ImageSharp.dsaada_DASqewrr"); - Assert.Null(fake); - } - [Theory] [WithFile(TestImages.Bmp.Car, PixelTypes.Rgba32, true)] [WithFile(TestImages.Bmp.Car, PixelTypes.Rgba32, false)] @@ -67,8 +53,7 @@ public void IsEquivalentTo_WhenFalse(TestImageProvider provider, where TPixel : struct, IPixel { Image a = provider.GetImage(); - Image b = provider.GetImage(); - b = b.OilPaint(3, 2); + Image b = provider.GetImage(x=>x.OilPaint(3, 2)); Assert.False(a.IsEquivalentTo(b, compareAlpha)); } @@ -89,10 +74,9 @@ public void IsEquivalentTo_WhenTrue(TestImageProvider provider, [InlineData(PixelTypes.Rgba32, typeof(Rgba32))] [InlineData(PixelTypes.Argb32, typeof(Argb32))] [InlineData(PixelTypes.HalfVector4, typeof(HalfVector4))] - [InlineData(PixelTypes.Rgba32, typeof(Rgba32))] public void ToType(PixelTypes pt, Type expectedType) { - Assert.Equal(pt.ToType(), expectedType); + Assert.Equal(pt.GetClrType(), expectedType); } [Theory] @@ -112,7 +96,7 @@ private static void AssertContainsPixelType( } [Fact] - public void ToTypes() + public void ExpandAllTypes_1() { PixelTypes pixelTypes = PixelTypes.Alpha8 | PixelTypes.Bgr565 | PixelTypes.HalfVector2 | PixelTypes.Rgba32; @@ -126,12 +110,26 @@ public void ToTypes() AssertContainsPixelType(PixelTypes.Rgba32, expanded); } + [Fact] + public void ExpandAllTypes_2() + { + PixelTypes pixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector; + + IEnumerable> expanded = pixelTypes.ExpandAllTypes(); + + Assert.Equal(3, expanded.Count()); + + AssertContainsPixelType(PixelTypes.Rgba32, expanded); + AssertContainsPixelType(PixelTypes.Bgra32, expanded); + AssertContainsPixelType(PixelTypes.RgbaVector, expanded); + } + [Fact] public void ToTypes_All() { KeyValuePair[] expanded = PixelTypes.All.ExpandAllTypes().ToArray(); - Assert.True(expanded.Length >= TestUtilityExtensions.GetAllPixelTypes().Length - 2); + Assert.True(expanded.Length >= TestUtils.GetAllPixelTypes().Length - 2); AssertContainsPixelType(PixelTypes.Rgba32, expanded); AssertContainsPixelType(PixelTypes.Rgba32, expanded); } diff --git a/tests/ImageSharp.Tests/VectorAssert.cs b/tests/ImageSharp.Tests/VectorAssert.cs index ad26963d43..402d066555 100644 --- a/tests/ImageSharp.Tests/VectorAssert.cs +++ b/tests/ImageSharp.Tests/VectorAssert.cs @@ -1,18 +1,16 @@ -// -// Copyright (c) James Jackson-South and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// + +using System; +using System.Collections.Generic; +using System.Numerics; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; // ReSharper disable MemberHidesStaticFromOuterClass -namespace ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests { - using System; - using System.Collections.Generic; - using System.Numerics; - using ImageSharp; - using ImageSharp.PixelFormats; - using Xunit; - /// /// Class to perform simple image comparisons. /// diff --git a/tests/ImageSharp.Tests/xunit.runner.json b/tests/ImageSharp.Tests/xunit.runner.json index df1c3d50d0..cbaa8f4325 100644 --- a/tests/ImageSharp.Tests/xunit.runner.json +++ b/tests/ImageSharp.Tests/xunit.runner.json @@ -1,3 +1,4 @@ { - "methodDisplay": "method" + "methodDisplay": "method", + "diagnosticMessages": true } \ No newline at end of file diff --git a/tests/Images/External b/tests/Images/External new file mode 160000 index 0000000000..5029858a87 --- /dev/null +++ b/tests/Images/External @@ -0,0 +1 @@ +Subproject commit 5029858a874a7e5127d516f0875b1e9df82d01b6 diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp b/tests/Images/Input/Bmp/Car.bmp similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp rename to tests/Images/Input/Bmp/Car.bmp diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Bmp/F.bmp b/tests/Images/Input/Bmp/F.bmp similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Bmp/F.bmp rename to tests/Images/Input/Bmp/F.bmp diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Bmp/neg_height.bmp b/tests/Images/Input/Bmp/neg_height.bmp similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Bmp/neg_height.bmp rename to tests/Images/Input/Bmp/neg_height.bmp diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Gif/cheers.gif b/tests/Images/Input/Gif/cheers.gif similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Gif/cheers.gif rename to tests/Images/Input/Gif/cheers.gif diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Gif/giphy.gif b/tests/Images/Input/Gif/giphy.gif similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Gif/giphy.gif rename to tests/Images/Input/Gif/giphy.gif diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Gif/rings.gif b/tests/Images/Input/Gif/rings.gif similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Gif/rings.gif rename to tests/Images/Input/Gif/rings.gif diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Gif/trans.gif b/tests/Images/Input/Gif/trans.gif similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Gif/trans.gif rename to tests/Images/Input/Gif/trans.gif diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/Calliphora.jpg b/tests/Images/Input/Jpg/baseline/Calliphora.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/Calliphora.jpg rename to tests/Images/Input/Jpg/baseline/Calliphora.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/ExifUndefType.jpg b/tests/Images/Input/Jpg/baseline/ExifUndefType.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/ExifUndefType.jpg rename to tests/Images/Input/Jpg/baseline/ExifUndefType.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/Floorplan.jpg b/tests/Images/Input/Jpg/baseline/Floorplan.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/Floorplan.jpg rename to tests/Images/Input/Jpg/baseline/Floorplan.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/Hiyamugi.jpg b/tests/Images/Input/Jpg/baseline/Hiyamugi.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/Hiyamugi.jpg rename to tests/Images/Input/Jpg/baseline/Hiyamugi.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/Lake.jpg b/tests/Images/Input/Jpg/baseline/Lake.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/Lake.jpg rename to tests/Images/Input/Jpg/baseline/Lake.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/Snake.jpg b/tests/Images/Input/Jpg/baseline/Snake.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/Snake.jpg rename to tests/Images/Input/Jpg/baseline/Snake.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/badeof.jpg b/tests/Images/Input/Jpg/baseline/badeof.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/badeof.jpg rename to tests/Images/Input/Jpg/baseline/badeof.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/cmyk.jpg b/tests/Images/Input/Jpg/baseline/cmyk.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/cmyk.jpg rename to tests/Images/Input/Jpg/baseline/cmyk.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/exif.jpg b/tests/Images/Input/Jpg/baseline/exif.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/exif.jpg rename to tests/Images/Input/Jpg/baseline/exif.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/gamma_dalai_lama_gray.jpg b/tests/Images/Input/Jpg/baseline/gamma_dalai_lama_gray.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/gamma_dalai_lama_gray.jpg rename to tests/Images/Input/Jpg/baseline/gamma_dalai_lama_gray.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg400jfif.jpg b/tests/Images/Input/Jpg/baseline/jpeg400jfif.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg400jfif.jpg rename to tests/Images/Input/Jpg/baseline/jpeg400jfif.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg420exif.jpg b/tests/Images/Input/Jpg/baseline/jpeg420exif.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg420exif.jpg rename to tests/Images/Input/Jpg/baseline/jpeg420exif.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg444.jpg b/tests/Images/Input/Jpg/baseline/jpeg444.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg444.jpg rename to tests/Images/Input/Jpg/baseline/jpeg444.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/testimgint.jpg b/tests/Images/Input/Jpg/baseline/testimgint.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/testimgint.jpg rename to tests/Images/Input/Jpg/baseline/testimgint.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/testorig.jpg b/tests/Images/Input/Jpg/baseline/testorig.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/testorig.jpg rename to tests/Images/Input/Jpg/baseline/testorig.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/turtle.jpg b/tests/Images/Input/Jpg/baseline/turtle.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/baseline/turtle.jpg rename to tests/Images/Input/Jpg/baseline/turtle.jpg diff --git a/tests/Images/Input/Jpg/baseline/ycck.jpg b/tests/Images/Input/Jpg/baseline/ycck.jpg new file mode 100644 index 0000000000..30e88773ed Binary files /dev/null and b/tests/Images/Input/Jpg/baseline/ycck.jpg differ diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/progressive/BadEofProgressive.jpg b/tests/Images/Input/Jpg/progressive/BadEofProgressive.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/progressive/BadEofProgressive.jpg rename to tests/Images/Input/Jpg/progressive/BadEofProgressive.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/progressive/Festzug.jpg b/tests/Images/Input/Jpg/progressive/Festzug.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/progressive/Festzug.jpg rename to tests/Images/Input/Jpg/progressive/Festzug.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/progressive/fb.jpg b/tests/Images/Input/Jpg/progressive/fb.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/progressive/fb.jpg rename to tests/Images/Input/Jpg/progressive/fb.jpg diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Jpg/progressive/progress.jpg b/tests/Images/Input/Jpg/progressive/progress.jpg similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Jpg/progressive/progress.jpg rename to tests/Images/Input/Jpg/progressive/progress.jpg diff --git a/tests/Images/Input/Png/Bike.png b/tests/Images/Input/Png/Bike.png new file mode 100644 index 0000000000..71f1969232 Binary files /dev/null and b/tests/Images/Input/Png/Bike.png differ diff --git a/tests/Images/Input/Png/BikeGrayscale.png b/tests/Images/Input/Png/BikeGrayscale.png new file mode 100644 index 0000000000..4af618d886 Binary files /dev/null and b/tests/Images/Input/Png/BikeGrayscale.png differ diff --git a/tests/Images/Input/Png/CalliphoraPartial.png b/tests/Images/Input/Png/CalliphoraPartial.png new file mode 100644 index 0000000000..e05ad0469d Binary files /dev/null and b/tests/Images/Input/Png/CalliphoraPartial.png differ diff --git a/tests/Images/Input/Png/CalliphoraPartialGrayscale.png b/tests/Images/Input/Png/CalliphoraPartialGrayscale.png new file mode 100644 index 0000000000..237148dcc4 Binary files /dev/null and b/tests/Images/Input/Png/CalliphoraPartialGrayscale.png differ diff --git a/tests/Images/Input/Png/SnakeGame.png b/tests/Images/Input/Png/SnakeGame.png new file mode 100644 index 0000000000..96d72b38aa Binary files /dev/null and b/tests/Images/Input/Png/SnakeGame.png differ diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/blur.png b/tests/Images/Input/Png/blur.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/blur.png rename to tests/Images/Input/Png/blur.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/chunklength1.png b/tests/Images/Input/Png/chunklength1.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/chunklength1.png rename to tests/Images/Input/Png/chunklength1.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/chunklength2.png b/tests/Images/Input/Png/chunklength2.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/chunklength2.png rename to tests/Images/Input/Png/chunklength2.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/cross.png b/tests/Images/Input/Png/cross.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/cross.png rename to tests/Images/Input/Png/cross.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/filter0.png b/tests/Images/Input/Png/filter0.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/filter0.png rename to tests/Images/Input/Png/filter0.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/filter1.png b/tests/Images/Input/Png/filter1.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/filter1.png rename to tests/Images/Input/Png/filter1.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/filter2.png b/tests/Images/Input/Png/filter2.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/filter2.png rename to tests/Images/Input/Png/filter2.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/filter3.png b/tests/Images/Input/Png/filter3.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/filter3.png rename to tests/Images/Input/Png/filter3.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/filter4.png b/tests/Images/Input/Png/filter4.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/filter4.png rename to tests/Images/Input/Png/filter4.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/filterVar.png b/tests/Images/Input/Png/filterVar.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/filterVar.png rename to tests/Images/Input/Png/filterVar.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/indexed.png b/tests/Images/Input/Png/indexed.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/indexed.png rename to tests/Images/Input/Png/indexed.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/interlaced.png b/tests/Images/Input/Png/interlaced.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/interlaced.png rename to tests/Images/Input/Png/interlaced.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/pd.png b/tests/Images/Input/Png/pd.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/pd.png rename to tests/Images/Input/Png/pd.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/pl.png b/tests/Images/Input/Png/pl.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/pl.png rename to tests/Images/Input/Png/pl.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/pp.png b/tests/Images/Input/Png/pp.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/pp.png rename to tests/Images/Input/Png/pp.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/rgb-48bpp-interlaced.png b/tests/Images/Input/Png/rgb-48bpp-interlaced.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/rgb-48bpp-interlaced.png rename to tests/Images/Input/Png/rgb-48bpp-interlaced.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/rgb-48bpp.png b/tests/Images/Input/Png/rgb-48bpp.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/rgb-48bpp.png rename to tests/Images/Input/Png/rgb-48bpp.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/splash-interlaced.png b/tests/Images/Input/Png/splash-interlaced.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/splash-interlaced.png rename to tests/Images/Input/Png/splash-interlaced.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/splash.png b/tests/Images/Input/Png/splash.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/splash.png rename to tests/Images/Input/Png/splash.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/versioning-1_1.png b/tests/Images/Input/Png/versioning-1_1.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/versioning-1_1.png rename to tests/Images/Input/Png/versioning-1_1.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/versioning-1_2.png b/tests/Images/Input/Png/versioning-1_2.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/versioning-1_2.png rename to tests/Images/Input/Png/versioning-1_2.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/vim16x16_1.png b/tests/Images/Input/Png/vim16x16_1.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/vim16x16_1.png rename to tests/Images/Input/Png/vim16x16_1.png diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/vim16x16_2.png b/tests/Images/Input/Png/vim16x16_2.png similarity index 100% rename from tests/ImageSharp.Tests/TestImages/Formats/Png/vim16x16_2.png rename to tests/Images/Input/Png/vim16x16_2.png